diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index 1e528190f85b7d..1ea15cd165e6d3 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1172,34 +1172,45 @@ function isSingleDefaultExport(exports: readonly string[]) { const lockfileFormats = [ { path: 'node_modules/.package-lock.json', - checkPatches: true, + checkPatchesDir: 'patches', manager: 'npm', }, { // Yarn non-PnP path: 'node_modules/.yarn-state.yml', - checkPatches: false, + checkPatchesDir: false, manager: 'yarn', }, { - // Yarn PnP - path: '.yarn/install-state', - checkPatches: false, + // Yarn v3+ PnP + path: '.pnp.cjs', + checkPatchesDir: '.yarn/patches', + manager: 'yarn', + }, + { + // Yarn v2 PnP + path: '.pnp.js', + checkPatchesDir: '.yarn/patches', manager: 'yarn', }, { // yarn 1 path: 'node_modules/.yarn-integrity', - checkPatches: true, + checkPatchesDir: 'patches', manager: 'yarn', }, { path: 'node_modules/.pnpm/lock.yaml', // Included in lockfile - checkPatches: false, + checkPatchesDir: false, manager: 'pnpm', }, - { name: 'bun.lockb', path: 'bun.lockb', checkPatches: true, manager: 'bun' }, + { + name: 'bun.lockb', + path: 'bun.lockb', + checkPatchesDir: 'patches', + manager: 'bun', + }, ].sort((_, { manager }) => { return process.env.npm_config_user_agent?.startsWith(manager) ? 1 : -1 }) @@ -1250,10 +1261,13 @@ function getLockfileHash(environment: Environment): string { const lockfileFormat = lockfileFormats.find((f) => normalizedLockfilePath.endsWith(f.path), )! - if (lockfileFormat.checkPatches) { + if (lockfileFormat.checkPatchesDir) { // Default of https://github.com/ds300/patch-package const baseDir = lockfilePath.slice(0, -lockfileFormat.path.length) - const fullPath = path.join(baseDir, 'patches') + const fullPath = path.join( + baseDir, + lockfileFormat.checkPatchesDir as string, + ) const stat = tryStatSync(fullPath) if (stat?.isDirectory()) { content += stat.mtimeMs.toString()