Repository navigation
Conversation
Confidence Score: 5/5
[Medium impact] The PR appears safe to merge. Reviews (1) · Last reviewed commit: "fix(commonjs): support default imports w..." · Reviewed by Greptile |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Rollup Plugin Name:
@rollup/plugin-commonjsThis PR contains:
Are tests included?
Breaking Changes?
If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.
List any relevant issue numbers:
#1860 (this fixes only
commonjs; same approach as #2028 forvirtual)Description
With
moduleResolution: node16ornodenext, an ES module consumer gets the CommonJS-formattypes/index.d.tsfor theimportcondition, which actually resolves todist/es/index.js. So the documented usage doesn't type-check, even though it runs fine:The workaround TypeScript suggests,
commonjs.default(), type-checks but throwsTypeError: commonjs.default is not a functionat runtime.This does the same as #2028 did for
@rollup/plugin-virtual: a newtypes/index.d.mtsreuses the existing function type and re-exports the option types, andexportsgets per-conditiontypesforimportandrequire. The runtime entries, the CJS.d.ts, the top-leveltypesand thedefaultfallback don't change.test/types.test.js(copied fromvirtual) type-checks ESM, CJS and legacy fixtures under Node16 and NodeNext. The two ESM cases fail without the change; all 5 pass with it. The one difference fromvirtual's test is that there's no explicitliblist, because this package uses TypeScript 4.8, which has noesnext.disposablelib.Checked:
pnpm build,pnpm test(304),pnpm test:earliest,pnpm test:tsandpnpm lint(no new warnings) pass.attwon the packed tarball reports no problems. A realrollup.config.mtsusingcommonjs()type-checks and builds with TypeScript 5.9 under nodenext, bundler and node10.node-resolve,json,replace,babel,terser,inject,typescriptandurlhave the same problem. I can send the same change for them, one PR each, if this approach is fine.