fix(node-protocol): respect alias and tsconfig paths when stripping node: prefix#773
fix(node-protocol): respect alias and tsconfig paths when stripping node: prefix#773sxzz merged 4 commits intorolldown:mainfrom
Conversation
✅ Deploy Preview for tsdown-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
tsdown
create-tsdown
tsdown-migrate
commit: |
|
Using Idk, why |
|
@lazuee Your alias: {
"crypto": "./src/crypto-polyfill.ts",
},// src/index.ts
import 'crypto'
// rewrite to
import './src/crypto-polyfill.ts' // which redirect to src/src/crypto-polyfill.tsYou can use absolute path or change it to |
|
@sxzz It works, but why does the relative path on the rolldown#resolve.alias it seems it based on the root directory. |
|
It's by design in Rolldown. resolve.alias will not call resolveId hooks of other plugin. If you want to call resolveId hooks of other plugin, use viteAliasPlugin from rolldown/experimental instead. You could find more discussion in this issue |
|
I see, thanks for the info! |
Description
When
nodeProtocol: "strip"is configured, theNodeProtocolPluginruns withorder: 'pre'and immediately marks strippednode:imports asexternal: true. This short-circuits the entire resolution chain, soaliasand tsconfigpathsconfigurations that map the stripped module name (e.g.,crypto) to a polyfill are never consulted.The fix changes the
striphandler to callthis.resolve()with the stripped ID before marking it as external. If another resolver (alias, tsconfig paths) resolves it to a non-external module, that resolution is used instead.Linked Issues
Fixes #772
Additional context
The test covers both resolution methods in a single case:
alias:node:path→ stripped topath→ resolved viaaliasto a polyfilltsconfig paths:node:crypto→ stripped tocrypto→ resolved viapathsto a polyfill