fix(deps): externalize unresolvable bare deps with skipNodeModulesBundle#1009
Open
m2na7 wants to merge 2 commits into
Open
fix(deps): externalize unresolvable bare deps with skipNodeModulesBundle#1009m2na7 wants to merge 2 commits into
m2na7 wants to merge 2 commits into
Conversation
✅ Deploy Preview for tsdown-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
tsdown
create-tsdown
@tsdown/css
@tsdown/exe
tsdown-migrate
commit: |
c654edb to
b367a20
Compare
When `deps.skipNodeModulesBundle` is enabled, a bare dependency that the resolver can't resolve was bundled instead of externalized. This happens for a package without an `exports` field on a non-`node` platform, where the legacy `main`/`types` fields aren't consulted, so resolution returns null. It is most visible in the dts build, where a types-only dependency gets inlined into the emitted `.d.ts` instead of kept as an external import. Externalize the bare specifier in that case too, since skipNodeModulesBundle should never bundle a node_modules import whether or not it resolves. Absolute paths and `#` subpath imports are left untouched. Fixes rolldown#993
b367a20 to
67dd034
Compare
Keep the existing externalization check untouched and add the unresolvable-bare-specifier case as a sibling guard, matching the flat early-return style of externalStrategy.
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.
Description
deps.skipNodeModulesBundle: trueis documented as "Skip bundling allnode_modulesdependencies", but a bare dependency the resolver can't resolve is bundled instead of externalized.This happens for a dependency published without an
exportsfield on a non-nodeplatform: the resolver doesn't fall back to the legacymain/typesfields, sothis.resolve(...)returnsnull. InexternalStrategy(src/features/deps.ts) theskipNodeModulesBundlebranch was gated onresolvedbeing truthy, so anullresolution fell through toreturn falseand the bare import got bundled.It's most visible in the dts build, where a types-only dependency ends up inlined into the emitted
.d.tsinstead of being kept as an external import:Before
After
The fix externalizes the bare specifier in this case too —
skipNodeModulesBundleshould never bundle anode_modulesimport whether or not it resolves. Absolute paths and#subpath imports are left untouched, and the change is fully scoped toskipNodeModulesBundle, so default resolution and the existing "Module not found" path (without this option) are unaffected.Added a regression test in
tests/e2e.test.ts(types-only dep +dts: true+platform: 'neutral'+skipNodeModulesBundle: true) that fails without the change and passes with it.pnpm test(full suite),tsc --noEmit,eslint --max-warnings 0, andprettier --checkall pass.Linked Issues
fixes #993
Additional context
The bug reproduces only with the combination in the test: a non-
nodeplatform + a dependency lacking anexportsfield (so the resolver returnsnull). On anodeplatform the same dependency resolves viamain, soskipNodeModulesBundlealready externalizes it correctly.