Skip to content

esm: remove check for trailing slash during resolve #57773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cyyynthia
Copy link

The check was incorrectly altered in #54408, passing the bindings as argument for this instead of the path string. This check not working having no significant impact on Node.js as far as I can tell, this changes removes it altogether to avoid undesired overhead.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Apr 6, 2025
Copy link

codecov bot commented Apr 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.23%. Comparing base (8456a12) to head (743dba0).
Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #57773   +/-   ##
=======================================
  Coverage   90.23%   90.23%           
=======================================
  Files         630      630           
  Lines      185245   185242    -3     
  Branches    36301    36302    +1     
=======================================
+ Hits       167154   167162    +8     
- Misses      11006    11013    +7     
+ Partials     7085     7067   -18     
Files with missing lines Coverage Δ
lib/internal/modules/esm/resolve.js 96.26% <100.00%> (+0.08%) ⬆️

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cyyynthia cyyynthia force-pushed the fix/esm-resolve-stat-ends-with branch from a12da10 to 743dba0 Compare April 6, 2025 15:05
@mcollina mcollina requested a review from ljharb April 7, 2025 14:50
@mcollina
Copy link
Member

mcollina commented Apr 7, 2025

Can you please add a test?

@cyyynthia
Copy link
Author

I'm unsure what I should be testing specifically; could you perhaps give me some directions to help me get started on that?

internalFsBinding,
StringPrototypeEndsWith(internalFsBinding, path, '/') ? StringPrototypeSlice(path, -1) : path,
);
const stats = internalFsBinding.internalModuleStat(internalFsBinding, path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failing to strip off the slash seems like it would cause issues on some systems. i'd definitely want to see lots of tests before making such a potentially fundamental change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I didn't consider the case of other platforms than linux (now that you mention that it is kind of obvious that this is a potential issue).

My PR comes from the fact the check is in a broken state in all v23 releases and in v22.10+, and it doesn't seem to have been a major issue so far. But you're probably right it is best to be cautious and restore the check than to outright get rid of it.

Looking at the history, it appears this check was originally introduced in #34744, for reasons I can't quite grasp. It doesn't come with additional tests for the new code branch either, as far as I can tell.

If it's deemed better to fix and keep the check, I can do that for this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chesterton's Fence says that before removing anything, one must understand why it's there :-) i think adding test cases would help reveal what purpose it serves.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it seems I'm not familiar enough with the codebase to confidently navigate around, so I've opted for the alternative option of simply fixing the check, but keeping it there 😅

The check was incorrectly altered in nodejs#54408, passing the bindings as
argument for `this` instead of the path string.

Signed-off-by: Cynthia Rey <[email protected]>
@cyyynthia cyyynthia force-pushed the fix/esm-resolve-stat-ends-with branch from 743dba0 to 48c9e3c Compare April 11, 2025 08:34
@@ -249,7 +249,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) {

const stats = internalFsBinding.internalModuleStat(
internalFsBinding,
StringPrototypeEndsWith(internalFsBinding, path, '/') ? StringPrototypeSlice(path, -1) : path,
StringPrototypeEndsWith(path, '/') ? StringPrototypeSlice(path, -1) : path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this definitely seems like a correct change, because string ends with only takes two arguments, the receiver and the substring - but i still think it needs a test (that would have failed without the fix)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants