Skip to content

Commit

Permalink
fix(optimizer): use correct default install state path for yarn PnP (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
smeng9 authored Jan 10, 2025
1 parent ad75c56 commit e690d8b
Showing 1 changed file with 24 additions and 10 deletions.
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

0 comments on commit e690d8b

Please sign in to comment.