Skip to content

Commit

Permalink
fix: do not append version query param when scanning for dependencies (
Browse files Browse the repository at this point in the history
  • Loading branch information
shYkiSto authored Feb 19, 2023
1 parent a873af5 commit 575bcf6
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
const ensureVersionQuery = (resolved: string): string => {
if (
!options.isBuild &&
!options.scan &&
depsOptimizer &&
!(
resolved === normalizedClientEntry ||
Expand Down
6 changes: 6 additions & 0 deletions playground/optimize-deps/__tests__/optimize-deps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ test('import aliased package with colon', async () => {
expect(await page.textContent('.url')).toBe('vitejs.dev')
})

test('import aliased package using absolute path', async () => {
expect(await page.textContent('.alias-using-absolute-path')).toBe(
'From dep-alias-using-absolute-path',
)
})

test('variable names are reused in different scripts', async () => {
expect(await page.textContent('.reused-variable-names')).toBe('reused')
})
Expand Down
13 changes: 13 additions & 0 deletions playground/optimize-deps/dep-alias-using-absolute-path/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Importing a shared dependency used by other modules,
// so dependency optimizer creates a common chunk.
// This is used to setup a test scenario, where dep scanner
// could not determine all of the used dependencies on first
// pass, e.g., a dependency that is aliased using an absolute
// path, in which case it used to trigger unnecessary "full
// reloads" invalidating all modules in a module graph.
const cloneDeep = require('lodash/cloneDeep')

// no-op, using imported module for sake of completeness
module.exports = cloneDeep({
message: 'From dep-alias-using-absolute-path',
}).message
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@vitejs/test-dep-alias-using-absolute-path",
"private": true,
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"lodash": "^4.17.21"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This is used to setup a test scenario, where dep scanner
// could not determine all of the used dependencies on first
// pass, e.g., a dependency that is aliased using an absolute
// path, in which case it used to trigger unnecessary "full
// reloads" invalidating all modules in a module graph.
export { default } from '@vitejs/test-dep-alias-using-absolute-path'
7 changes: 7 additions & 0 deletions playground/optimize-deps/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ <h2>Nested include</h2>
<h2>Alias with colon</h2>
<div>URL: <span class="url"></span></div>

<h2>Alias using absolute path</h2>
<div class="alias-using-absolute-path"></div>

<h2>Reused variable names</h2>
<div>This should show reused: <span class="reused-variable-names"></span></div>

Expand Down Expand Up @@ -153,6 +156,10 @@ <h2>Non Optimized Module isn't duplicated</h2>
import { parse } from 'node:url'
text('.url', parse('https://vitejs.dev').hostname)

import('./dynamic-use-dep-alias-using-absolute-path.js').then((mod) =>
text('.alias-using-absolute-path', mod.default),
)

import './index.astro'

// All these imports should end up resolved to the same URL (same ?v= injected on them)
Expand Down
1 change: 1 addition & 0 deletions playground/optimize-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"dependencies": {
"axios": "^0.27.2",
"clipboard": "^2.0.11",
"@vitejs/test-dep-alias-using-absolute-path": "file:./dep-alias-using-absolute-path",
"@vitejs/test-dep-cjs-browser-field-bare": "file:./dep-cjs-browser-field-bare",
"@vitejs/test-dep-cjs-compiled-from-cjs": "file:./dep-cjs-compiled-from-cjs",
"@vitejs/test-dep-cjs-compiled-from-esm": "file:./dep-cjs-compiled-from-esm",
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion playground/optimize-deps/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module.exports = {
dedupe: ['react'],
alias: {
'node:url': 'url',
'@vitejs/test-dep-alias-using-absolute-path': require.resolve(
'@vitejs/test-dep-alias-using-absolute-path',
),
},
},
optimizeDeps: {
Expand Down Expand Up @@ -38,7 +41,7 @@ module.exports = {
},
],
},
entries: ['entry.js'],
entries: ['index.html', 'unused-split-entry.js'],
},

build: {
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 575bcf6

Please sign in to comment.