-
-
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
fix: ensure version query for direct node_modules imports #9848
Conversation
vite-ecosystem-ci run against this PR. This is also testing the new 3.1-beta.0 PRs (object hooks and parse5 for HTML). There are two fails, but looks unrelated to the PR:
|
SvelteKit includes this in HTML: <script type="module">
import { start } from '/node_modules/@sveltejs/kit/src/runtime/client/start.js';
// ...
</script> Nothing else needs to import that file, but that file contains an import (which doesn't get import { error } from '../../index/index.js'; ...that is also exported from the package, hence the double imports: import { error } from '@sveltejs/kit'; If this fix results in the imports inside |
It looks like what's breaking is this line within a custom plugin we wrote to process mdx:
Which we borrowed heavily from vite-plugin-mdx: https://github.com/brillout/vite-plugin-mdx/blob/ee4a732f19bd8ee072dc5257b96c3012f2cd6d75/src/index.ts#L58-L63 It looks like this might be due to rollup/rollup#4600. But it looks like that wasn't intended to be breaking. So, I'm not sure if there's something I need to change on my side (and alert @brillout to for his plugin as well), or if this is a bug in the rollup types. |
I've tested this branch with a reproduction of sveltejs/kit#5952, and it works perfectly! Thanks so much @patak-dev, this is excellent news |
It seems it's a real regression of this PR. It does not happen with 3.1.0-beta.0. When using this branch with
|
@sapphi-red I couldn't reproduce the issue with your instructions on MacOS, but I think vitejs/vite@ |
vite-setup-catalogue is now green 🎉 |
LGTM. ( |
Ummm, I wonder why it didn't reproduce on macOS as ecosystem-ci runs on linux. |
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.
The changes LGTM! But would be great to have tests 😬
@bluwy added tests in: Also, good call, there was a bug with importing using a relative path. |
// as if they would have been imported through a bare import | ||
// Use the original id to do the check as the resolved id may be the real | ||
// file path after symlinks resolution | ||
const isNodeModule = !!normalizePath(id).match(nodeModulesInPathRE) |
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.
It looks like most of the codebase simply checks by includes('node_modules')
. I think we can probably do the same for consistency even if there might be false positives. But I don't feel strongly otherwise if we don't change this too.
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.
We have a good mix now, other places tests for includes('/node_modules/')
. Let's merge this as I think we should be more strict on this check, and we could update places only checking for 'node_modules'
in future PRs.
Fixes #7621
Fixes #2503 (with a different approach after reverting #2848)
Closes #9730
Potentially unblocks SvelteKit, as it will fix the issue described in #9828 if the direct node_modules import is in a JS source instead of a script tag. We aren't resolving the URL in script tags AFAICS, I'll check if this is something we should start doing. @Rich-Harris @benmccann would you confirm that this is something needed by SvelteKit, or it is just an artifact of how the reproduction was built (I'm assuming it is the later, and this PR may also then fix #9828)
Description
We mark non-optimized node_modules imports with a
?v={browserHash}
query hereThis allows us to cache npm dependencies (even if they aren't optimized). See here
We need the version query because once we re-optimize, we need to resend also the non-optimized node_modules files as they may have imported optimized modules so their imports needs to be rewritten to the new cached files.
Before this PR, we only added the version query to bare imports, and after #2848, also to relative imports of node_modules. After this PR, we are ensuring the version query also for all other ways to direct import a file in node_modules.
What is the purpose of this pull request?