Skip to content

Commit

Permalink
fix: don't check .yarn/patches for computing dependencies hash (#11168)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBarre authored Dec 4, 2022
1 parent 5170e44 commit 65bcccf
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 65bcccf

Please sign in to comment.