fix(deps): resolve subpath extensions for packages without exports field#863
Merged
fix(deps): resolve subpath extensions for packages without exports field#863
Conversation
When a dependency has no `exports` field in its package.json, subpath imports like `source-map-support/register` need to be resolved to their actual file path (e.g. `source-map-support/register.js`) for valid ESM output. Refactors DepsPlugin (renamed from DepPlugin) to resolve dependency paths upfront and return custom resolved IDs when the package lacks an exports field. Also switches tsconfig to bundler module resolution and removes @publint/pack dev dependency.
✅ 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: |
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
When a dependency has no
exportsfield in itspackage.json, subpath imports likesource-map-support/registerneed to be resolved to their actual file path (e.g.source-map-support/register.js) for valid ESM output.Key changes in
src/features/deps.ts:DepPlugin→DepsPluginfor consistency with the module name (deps.ts)this.resolve()and pass theResolvedIdtoexternalStrategy, avoiding redundant resolution inskipNodeModulesBundleresolveDepPath(): when a dependency subpath import (e.g.foo/bar) resolves to a package without anexportsfield, rewrite the import to include the file extension (e.g.foo/bar.js)externalStrategycan now return[true, resolvedId]to indicate external with a rewritten import pathparseDepPath()as a shared utility used by bothparseBundledDepandresolveDepPathshouldExternalis not explicitly set butresolvedexists, forward the resolved result withmoduleSideEffectsOther changes:
src/features/rolldown.tsandsrc/plugins.tsto useDepsPlugin@publint/packdev dependency frompackage.json,pnpm-workspace.yaml, andtsdown.config.tsLinked Issues
Closes #854
Additional context
The
resolveDepPathfunction works by:packageJsonPath(from Rolldown's resolver)package.jsonto check for anexportsfieldexportsfield exists, using the actual resolved file path to construct the correct import specifier with extension