- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 246
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: respect noExternal option with Tsup node #720
fix: respect noExternal option with Tsup node #720
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@VladimirGrenaderov here is a factored version of the code however I am not sure if it's an improvement, you may want a callback as tiny as possible because it will be called many times. Factored version just in case, but again I am not a big fan: build.onResolve({ filter: /.*/ }, (args) => {
// Respect explicit options for specific packages
if (match(args.path, noExternal)) {
return
}
if (match(args.path, external)) {
return { external: true }
}
if (skipNodeModulesBundle) {
const resolvePatterns = tsconfigPathsToRegExp(
tsconfigResolvePaths || {}
)
// Resolve `paths` from tsconfig
if (match(args.path, resolvePatterns)) {
return
}
// every other import that looks like a node_modules is external
if (NON_NODE_MODULE_RE.test(args.path)) {
return {
path: args.path,
external: true,
}
}
}
}) |
@eric-burel I meant that 'match(...)' call is not free (regexps as so slow, you know), and we shall not repeat similar calls im multiple callbacks. It's ok for me to have atomic callbacks, but not at the cost of an obvious performance degradation. Sure, as 'one line fix' this PR is good and much more safer. And it's only package maintainers decision. |
@VladimirGrenaderov You are totally I right I misunderstood you're initial comment. I've committed a new version that will register only one callback depending on the scenario. So the initial logic was correct, except for a minor priority issue: anything looking like a node_module was treated as external before the code reached the "noExternal" condition when the skip option was true. This PR aims to fix that and has a more explicit if/else. Thanks for your help! |
🎉 This PR is included in version 6.3.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Co-authored-by: EGOIST <hi@egoist.dev>
Fixes #718
/!\ I haven't tested if it still builds (but I only touched 2 lines of code) + this might be a slight breaking change if some people use
tsup-node
and accidentally had a "noExternal" option set (before this PR, the noExternal would be ignored, after this PR, it is correctly considered thus bundling more packages).