-
-
Notifications
You must be signed in to change notification settings - Fork 269
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(all): add types to exports for node16/nodenext module resolution #2094
Open
bgotink
wants to merge
1
commit into
modernweb-dev:master
Choose a base branch
from
bgotink:fix/node16-resolution
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+302
−67
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
'@web/browser-logs': patch | ||
'@web/config-loader': patch | ||
'@web/dev-server': patch | ||
'@web/dev-server-core': patch | ||
'@web/dev-server-esbuild': patch | ||
'@web/dev-server-hmr': patch | ||
'@web/dev-server-import-maps': patch | ||
'@web/dev-server-legacy': patch | ||
'@web/dev-server-rollup': patch | ||
'@web/dev-server-storybook': patch | ||
'@web/parse5-utils': patch | ||
'@web/polyfills-loader': patch | ||
'@web/rollup-plugin-copy': patch | ||
'@web/rollup-plugin-html': patch | ||
'@web/rollup-plugin-import-meta-assets': patch | ||
'@web/rollup-plugin-polyfills-loader': patch | ||
'rollup-plugin-workbox': patch | ||
'@web/test-runner-browserstack': patch | ||
'@web/test-runner-chrome': patch | ||
'@web/test-runner-cli': patch | ||
'@web/test-runner-commands': patch | ||
'@web/test-runner-core': patch | ||
'@web/test-runner-coverage-v8': patch | ||
'@web/test-runner-junit-reporter': patch | ||
'@web/test-runner-playwright': patch | ||
'@web/test-runner-puppeteer': patch | ||
'@web/test-runner-saucelabs': patch | ||
'@web/test-runner-selenium': patch | ||
'@web/test-runner-visual-regression': patch | ||
'@web/test-runner-webdriver': patch | ||
--- | ||
|
||
Add explicit types export to work with node16 module resolution (typescript ≥ 4.7) |
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
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
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
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.
These files should be named
index.d.mts
... and if they are named correctly and siblings of the files they describe, then they don't actually need to be in the package exports. See some discussion here and some docs hereThere 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.
That would work for me, but it would break all packages in typescript when not using node16/nodenext module resolution, because in that mode typescript only looks for
.d.ts
files.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.
That shouldn't be true. My understanding, reiterated in the issue I liked to, is that TypeScript only looks for
.d.mts
declarations files for.mjs
files, and.d.cts
declaration files for.cjs
files. IOW, the declaration file must be named after the file its describing always, and there wasn't event a version of TypeScript that even supported.mjs
files with.d.ts
declarations.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.
You're correct, but that doesn't stop it from being broken. If typescript isn't configured to use Node16/NodeNext resolution, typescript looks for the
d.ts
file extension but it doesn't look for.d.mts
or.d.cts
file extensions. That makes sense as Node doesn't autocomplete the.cjs
or.mjs
extensions either.The
@web/dev-server-core
package has an export./test-helpers
. To support this export in non-Node16/NodeNext resolutions the package must have a./test-helpers.d.ts
file.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.
You’re referring to resolution in the TypeScript mode called
node
, which in 5.0 has been renamed tonode10
to reflect what it really is. Node 10 will fail at runtime on an import of"@web/dev-server-core/test-helpers"
, so putting a.d.ts
file at./test-helpers.d.ts
to make TypeScript think it will resolve is strictly wrong. Users who are running on a Node version newer than v10 should not be using that setting anymore.Of course, taking my pedant hat off, users are still using that setting even though the vast majority of them are no longer using Node 10. It’s up to you to decide how and if you want to protect those users from their own misconfiguration. Placing the phantom
.d.ts
file there works. Other strategies are demonstrated at https://github.com/andrewbranch/example-subpath-exports-ts-compat. Particularly interesting is that you can usetypesVersions
to affect TypeScriptnode10
resolution almost exactly the same way thatexports
affects the modern TypeScript resolution modes.Whatever strategy you decide to go with, you can use https://arethetypeswrong.github.io to test it. I can confirm that the issue pointed out here by @justinfagnani is indeed a problem that will be recognized by this tool.