-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix(test runner): align with typescript behaviour for resolving index.js
and package.json
through path mapping
#32078
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like TypeScript:
exports
field frompackage.json
after the type mapping;index.js
andmain
field frompackage.json
after the type mapping as explained here: https://www.typescriptlang.org/docs/handbook/modules/reference.html#directory-modules-index-file-resolution. Note that bothindex.js
andmain
are ignored for ESM, as explained here: https://nodejs.org/dist/latest-v20.x/docs/api/modules.html#folders-as-modules.The docs above match my manual testing as well. I think we should follow TS and implement the same logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a test to ensure we follow your first observation in 9a80386.
For the second one, isn't that exactly the behaviour we have right now? If there's a
package.json
file, then we let Node.js deal with resolving to eitherindex.js
ormain
, depending on the ESM mode.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exports
field, it looks like the code will defer to Node.js (when not in ESM), and Node will honor theexports
. Is that not the case?main
field, TypeScript also checks various extensions (e.g.ts
) after following it, and we currently do not, because we leave it to Node.js. That's a minor thing, but it would be ideal to mirror TypeScript there as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.ts
extension is covered by https://github.com/Skn0tt/playwright/blob/9a80386c7d057027499609aa4d648549482474fa/tests/playwright-test/resolver.spec.ts#L572-L607. What other extensions should we cover?Both of these are about the path mapping case. Are you referring to the case where there's no path mapping?
In 62ff3fd, i've added a test to ensure that
main
is ignored in ESM mode, and updated the comments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, the tests look like they cover all the cases. I guess for the item 1, Node.js does not look at
exports
either, which works for us. Thank you for following through!