From 58769603e999a049ecd0b28de4041a5dd368e454 Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 2 Apr 2023 21:24:15 +0800 Subject: [PATCH 1/2] fix(optimizer): load the correct lock file --- packages/vite/src/node/optimizer/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index d2079064004c69..c19cc1a87f622f 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1233,16 +1233,19 @@ function isSingleDefaultExport(exports: readonly string[]) { } const lockfileFormats = [ - { 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 }, -] + { name: 'package-lock.json', checkPatches: true, manager: 'npm' }, + { name: 'yarn.lock', checkPatches: true, manager: 'yarn' }, // Included in lockfile for v2+ + { name: 'pnpm-lock.yaml', checkPatches: false, manager: 'pnpm' }, // Included in lockfile + { name: 'bun.lockb', checkPatches: true, manager: 'bun' }, +].sort((_, { manager }) => { + return process.env.npm_config_user_agent?.startsWith(manager) ? 1 : -1 +}) const lockfileNames = lockfileFormats.map((l) => l.name) export function getDepHash(config: ResolvedConfig, ssr: boolean): string { const lockfilePath = lookupFile(config.root, lockfileNames) let content = lockfilePath ? fs.readFileSync(lockfilePath, 'utf-8') : '' + if (lockfilePath) { const lockfileName = path.basename(lockfilePath) const { checkPatches } = lockfileFormats.find( From e1398fa610d3b145d29cf1f6d2a68a092c63561b Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 2 Apr 2023 21:31:23 +0800 Subject: [PATCH 2/2] chore: remove useless line --- packages/vite/src/node/optimizer/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts index c19cc1a87f622f..6c323fd746585c 100644 --- a/packages/vite/src/node/optimizer/index.ts +++ b/packages/vite/src/node/optimizer/index.ts @@ -1245,7 +1245,6 @@ const lockfileNames = lockfileFormats.map((l) => l.name) export function getDepHash(config: ResolvedConfig, ssr: boolean): string { const lockfilePath = lookupFile(config.root, lockfileNames) let content = lockfilePath ? fs.readFileSync(lockfilePath, 'utf-8') : '' - if (lockfilePath) { const lockfileName = path.basename(lockfilePath) const { checkPatches } = lockfileFormats.find(