-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
refactor: simplify resolveSSRExternal
#5210
Conversation
- add `collectExternals` function for recursive tracing - apply `config.ssr` just once, after all externals are collected - support packages with deep imports but no main entry - remove `knownImports` argument
This argument is necessary to ensure transient dependencies in node_modules are marked as external.
Okay, I realized why |
const { root } = config | ||
for (const dep of knownImports) { | ||
// assume external if not yet seen | ||
if (!seen.has(dep)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, the project root and any linked packages have had their dependencies checked, so we can safely mark any knownImports
not yet seen as external. They are guaranteed to be dependencies of packages in node_modules
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should your comment here perhaps be a code comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this and confirmed it fixes #4425
} | ||
// check if the entry is cjs | ||
} | ||
// externalize js entries with commonjs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there changes are conflicting with the changes in https://github.com/vitejs/vite/pull/5197/files#diff-a6d6596967a09b96fa100c4b77480490b5ef95df88987ecbfa00ba1c868e4f53R97
rebased version is here: #5544
if you'd prefer to update this PR, I'm happy to close mine
collectExternals
function for recursive tracingconfig.ssr
just once, after all externals are collectedTo clarify #3, a package might allow imports like
foo/bar
but notfoo
alone. Before this PR, packages like this were never marked external (unless done so explicitly in user config), because the call totryNodeResolve
would throw. As a workaround, you can add the package's name tossr.external
or add an emptyindex.js
module to the package.