Skip to content

Commit

Permalink
fix(deps-optimization): resolve patches relative to base dir (#17336)
Browse files Browse the repository at this point in the history
  • Loading branch information
DreierF committed Nov 17, 2024
1 parent a3fec97 commit 5f72747
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,34 +1151,29 @@ function isSingleDefaultExport(exports: readonly string[]) {

const lockfileFormats = [
{
name: '.package-lock.json',
path: 'node_modules/.package-lock.json',
checkPatches: true,
manager: 'npm',
},
{
// Yarn non-PnP
name: '.yarn-state.yml',
path: 'node_modules/.yarn-state.yml',
checkPatches: false,
manager: 'yarn',
},
{
// Yarn PnP
name: 'install-state',
path: '.yarn/install-state',
checkPatches: false,
manager: 'yarn',
},
{
// yarn 1
name: '.yarn-integrity',
path: 'node_modules/.yarn-integrity',
checkPatches: true,
manager: 'yarn',
},
{
name: 'lock.yaml',
path: 'node_modules/.pnpm/lock.yaml',
// Included in lockfile
checkPatches: false,
Expand Down Expand Up @@ -1229,13 +1224,14 @@ function getLockfileHash(environment: Environment): string {
const lockfilePath = lookupFile(environment.config.root, lockfilePaths)
let content = lockfilePath ? fs.readFileSync(lockfilePath, 'utf-8') : ''
if (lockfilePath) {
const lockfileName = path.basename(lockfilePath)
const { checkPatches } = lockfileFormats.find(
(f) => f.name === lockfileName,
const normalizedLockfilePath = lockfilePath.replaceAll('\\', '/')
const lockfileFormat = lockfileFormats.find((f) =>
normalizedLockfilePath.endsWith(f.path),
)!
if (checkPatches) {
if (lockfileFormat.checkPatches) {
// Default of https://github.com/ds300/patch-package
const fullPath = path.join(path.dirname(lockfilePath), 'patches')
const baseDir = lockfilePath.slice(0, -lockfileFormat.path.length)
const fullPath = path.join(baseDir, 'patches')
const stat = tryStatSync(fullPath)
if (stat?.isDirectory()) {
content += stat.mtimeMs.toString()
Expand Down

0 comments on commit 5f72747

Please sign in to comment.