Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(optimizer): use correct default install state path for yarn PnP #19119

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
34 changes: 24 additions & 10 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -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()
Expand Down
Loading