From 884bfe85247787342f2ea90f1fae921bda246892 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Sep 2025 11:38:31 +0000 Subject: [PATCH 1/4] Initial plan From 491e1c58194816000ca2973524740512778c2265 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Sep 2025 11:49:54 +0000 Subject: [PATCH 2/4] Add lockFilePath configuration for dependency optimizer Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- docs/config/dep-optimization-options.md | 19 ++++++++++++++ packages/vite/src/node/optimizer/index.ts | 32 ++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/config/dep-optimization-options.md b/docs/config/dep-optimization-options.md index 2021d3292f8712..2648ee2b81716b 100644 --- a/docs/config/dep-optimization-options.md +++ b/docs/config/dep-optimization-options.md @@ -78,6 +78,25 @@ Certain options are omitted since changing them would not be compatible with Vit Set to `true` to force dependency pre-bundling, ignoring previously cached optimized dependencies. +## optimizeDeps.lockFilePath + +- **Experimental** +- **Type:** `string` + +Path to a custom lockfile to use for dependency optimization hash calculation. When specified, Vite will use this lockfile instead of searching for standard lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml, etc.). + +This is useful for monorepo tools like Rush.js that place lockfiles in non-standard locations such as `.rush/temp/shrinkwrap-deps.json`. + +```js twoslash +import { defineConfig } from 'vite' +// ---cut--- +export default defineConfig({ + optimizeDeps: { + lockFilePath: '.rush/temp/shrinkwrap-deps.json', + }, +}) +``` + ## optimizeDeps.noDiscovery - **Type:** `boolean` diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index db698b8c3b722c..5e4b952b55b22f 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -82,6 +82,15 @@ export interface DepOptimizationConfig { * @experimental */ needsInterop?: string[] + /** + * Path to a custom lockfile to use for dependency optimization hash calculation. + * When specified, Vite will use this lockfile instead of searching for standard + * lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml, etc.). + * This is useful for monorepo tools like Rush.js that place lockfiles in + * non-standard locations. + * @experimental + */ + lockFilePath?: string /** * Options to pass to esbuild during the dep scanning and optimization * @@ -1249,6 +1258,12 @@ const lockfileFormats = [ checkPatchesDir: 'patches', manager: 'bun', }, + { + path: '.rush/temp/shrinkwrap-deps.json', + // Included in lockfile + checkPatchesDir: false, + manager: 'pnpm', + }, ].sort((_, { manager }) => { return process.env.npm_config_user_agent?.startsWith(manager) ? 1 : -1 }) @@ -1292,7 +1307,22 @@ function getConfigHash(environment: Environment): string { } function getLockfileHash(environment: Environment): string { - const lockfilePath = lookupFile(environment.config.root, lockfilePaths) + const { config } = environment + const customLockFilePath = config.optimizeDeps.lockFilePath + + let lockfilePath: string | undefined + + if (customLockFilePath) { + // Use custom lockfile path if specified + const fullCustomPath = path.resolve(config.root, customLockFilePath) + lockfilePath = tryStatSync(fullCustomPath)?.isFile() + ? fullCustomPath + : undefined + } else { + // Use standard lockfile detection + lockfilePath = lookupFile(config.root, lockfilePaths) + } + let content = lockfilePath ? fs.readFileSync(lockfilePath, 'utf-8') : '' if (lockfilePath) { const normalizedLockfilePath = lockfilePath.replaceAll('\\', '/') From 719231cf1cbc415a4132fafacbd71f7cd88084b9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Sep 2025 11:58:31 +0000 Subject: [PATCH 3/4] Remove all changes except Rush.js lockfile format support Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- docs/config/dep-optimization-options.md | 19 ----------------- packages/vite/src/node/optimizer/index.ts | 26 +---------------------- 2 files changed, 1 insertion(+), 44 deletions(-) diff --git a/docs/config/dep-optimization-options.md b/docs/config/dep-optimization-options.md index 2648ee2b81716b..2021d3292f8712 100644 --- a/docs/config/dep-optimization-options.md +++ b/docs/config/dep-optimization-options.md @@ -78,25 +78,6 @@ Certain options are omitted since changing them would not be compatible with Vit Set to `true` to force dependency pre-bundling, ignoring previously cached optimized dependencies. -## optimizeDeps.lockFilePath - -- **Experimental** -- **Type:** `string` - -Path to a custom lockfile to use for dependency optimization hash calculation. When specified, Vite will use this lockfile instead of searching for standard lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml, etc.). - -This is useful for monorepo tools like Rush.js that place lockfiles in non-standard locations such as `.rush/temp/shrinkwrap-deps.json`. - -```js twoslash -import { defineConfig } from 'vite' -// ---cut--- -export default defineConfig({ - optimizeDeps: { - lockFilePath: '.rush/temp/shrinkwrap-deps.json', - }, -}) -``` - ## optimizeDeps.noDiscovery - **Type:** `boolean` diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 5e4b952b55b22f..bf5fe21c23a400 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -82,15 +82,6 @@ export interface DepOptimizationConfig { * @experimental */ needsInterop?: string[] - /** - * Path to a custom lockfile to use for dependency optimization hash calculation. - * When specified, Vite will use this lockfile instead of searching for standard - * lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml, etc.). - * This is useful for monorepo tools like Rush.js that place lockfiles in - * non-standard locations. - * @experimental - */ - lockFilePath?: string /** * Options to pass to esbuild during the dep scanning and optimization * @@ -1307,22 +1298,7 @@ function getConfigHash(environment: Environment): string { } function getLockfileHash(environment: Environment): string { - const { config } = environment - const customLockFilePath = config.optimizeDeps.lockFilePath - - let lockfilePath: string | undefined - - if (customLockFilePath) { - // Use custom lockfile path if specified - const fullCustomPath = path.resolve(config.root, customLockFilePath) - lockfilePath = tryStatSync(fullCustomPath)?.isFile() - ? fullCustomPath - : undefined - } else { - // Use standard lockfile detection - lockfilePath = lookupFile(config.root, lockfilePaths) - } - + const lockfilePath = lookupFile(environment.config.root, lockfilePaths) let content = lockfilePath ? fs.readFileSync(lockfilePath, 'utf-8') : '' if (lockfilePath) { const normalizedLockfilePath = lockfilePath.replaceAll('\\', '/') From 7102283a03633ce208c952a5ad5afb0d0875d13e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 24 Sep 2025 12:36:10 +0000 Subject: [PATCH 4/4] Move Rush.js lockfile entry to be right after pnpm lockfile Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- packages/vite/src/node/optimizer/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index bf5fe21c23a400..e0779127054451 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1239,6 +1239,12 @@ const lockfileFormats = [ checkPatchesDir: false, manager: 'pnpm', }, + { + path: '.rush/temp/shrinkwrap-deps.json', + // Included in lockfile + checkPatchesDir: false, + manager: 'pnpm', + }, { path: 'bun.lock', checkPatchesDir: 'patches', @@ -1249,12 +1255,6 @@ const lockfileFormats = [ checkPatchesDir: 'patches', manager: 'bun', }, - { - path: '.rush/temp/shrinkwrap-deps.json', - // Included in lockfile - checkPatchesDir: false, - manager: 'pnpm', - }, ].sort((_, { manager }) => { return process.env.npm_config_user_agent?.startsWith(manager) ? 1 : -1 })