From 65bcccfe9fa2f637962f6fc595375fbca3409adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Barr=C3=A9?= Date: Sun, 4 Dec 2022 10:51:18 +0100 Subject: [PATCH] fix: don't check .yarn/patches for computing dependencies hash (#11168) --- packages/vite/src/node/optimizer/index.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index ff8de17f9b6685..0b4b80def7853d 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1043,10 +1043,10 @@ function isSingleDefaultExport(exports: readonly string[]) { } const lockfileFormats = [ - { name: 'package-lock.json', patchesDirs: ['patches'] }, // Default of https://github.com/ds300/patch-package - { name: 'yarn.lock', patchesDirs: ['patches', '.yarn/patches'] }, // .yarn/patches for v2+ - { name: 'pnpm-lock.yaml', patchesDirs: [] }, // Included in lockfile - { name: 'bun.lockb', patchesDirs: ['patches'] }, + { name: 'package-lock.json', checkPatches: true }, + { name: 'yarn.lock', checkPatches: true }, // Included in lockfile for v2+ + { name: 'pnpm-lock.yaml', checkPatches: false }, // Included in lockfile + { name: 'bun.lockb', checkPatches: true }, ] export function getDepHash(config: ResolvedConfig, ssr: boolean): string { @@ -1058,17 +1058,16 @@ export function getDepHash(config: ResolvedConfig, ssr: boolean): string { let content = lockfilePath ? fs.readFileSync(lockfilePath, 'utf-8') : '' if (lockfilePath) { const lockfileName = path.basename(lockfilePath) - const { patchesDirs } = lockfileFormats.find( + const { checkPatches } = lockfileFormats.find( (f) => f.name === lockfileName, )! - const dependenciesRoot = path.dirname(lockfilePath) - for (const patchesDir of patchesDirs) { - const fullPath = path.join(dependenciesRoot, patchesDir) + if (checkPatches) { + // Default of https://github.com/ds300/patch-package + const fullPath = path.join(path.dirname(lockfilePath), 'patches') if (fs.existsSync(fullPath)) { const stats = fs.statSync(fullPath) if (stats.isDirectory()) { content += stats.mtimeMs.toString() - break } } }