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 590af2b
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.replace('\\', '/')
const lockfileFormat = lockfileFormats.find((f) =>
normalizedLockfilePath.endsWith(f.path),
)!
if (checkPatches) {
if (lockfileFormat.checkPatches) {

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/__tests__/environment.spec.ts > custom environment conditions > dev noExternal

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ Object.defaultCreateClientDevEnvironment [as createEnvironment] packages/vite/src/node/config.ts:213:10 ❯ _createServer packages/vite/src/node/server/index.ts:489:55 ❯ packages/vite/src/node/__tests__/environment.spec.ts:95:20

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/__tests__/environment.spec.ts > custom environment conditions > dev external

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ Object.defaultCreateClientDevEnvironment [as createEnvironment] packages/vite/src/node/config.ts:213:10 ❯ _createServer packages/vite/src/node/server/index.ts:489:55 ❯ packages/vite/src/node/__tests__/environment.spec.ts:120:20

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/__tests__/environment.spec.ts > custom environment conditions > css

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ Object.defaultCreateClientDevEnvironment [as createEnvironment] packages/vite/src/node/config.ts:213:10 ❯ _createServer packages/vite/src/node/server/index.ts:489:55 ❯ packages/vite/src/node/__tests__/environment.spec.ts:147:20

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/__tests__/resolve.spec.ts > import and resolveId > import first

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ Object.defaultCreateClientDevEnvironment [as createEnvironment] packages/vite/src/node/config.ts:213:10 ❯ _createServer packages/vite/src/node/server/index.ts:489:55 ❯ createTestServer packages/vite/src/node/__tests__/resolve.spec.ts:10:20 ❯ packages/vite/src/node/__tests__/resolve.spec.ts:29:32

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/__tests__/resolve.spec.ts > import and resolveId > resolveId first

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ Object.defaultCreateClientDevEnvironment [as createEnvironment] packages/vite/src/node/config.ts:213:10 ❯ _createServer packages/vite/src/node/server/index.ts:489:55 ❯ createTestServer packages/vite/src/node/__tests__/resolve.spec.ts:10:20 ❯ packages/vite/src/node/__tests__/resolve.spec.ts:43:32

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/__tests__/resolve.spec.ts > file url > dev

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ Object.defaultCreateClientDevEnvironment [as createEnvironment] packages/vite/src/node/config.ts:213:10 ❯ _createServer packages/vite/src/node/server/index.ts:489:55 ❯ packages/vite/src/node/__tests__/resolve.spec.ts:96:20

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/server/__tests__/pluginContainer.spec.ts > plugin container > getModuleInfo > can pass metadata between hooks

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ getDevEnvironment packages/vite/src/node/server/__tests__/pluginContainer.spec.ts:229:23 ❯ packages/vite/src/node/server/__tests__/pluginContainer.spec.ts:46:27

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/server/__tests__/pluginContainer.spec.ts > plugin container > getModuleInfo > can pass metadata between plugins

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ getDevEnvironment packages/vite/src/node/server/__tests__/pluginContainer.spec.ts:229:23 ❯ packages/vite/src/node/server/__tests__/pluginContainer.spec.ts:88:27

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/server/__tests__/pluginContainer.spec.ts > plugin container > getModuleInfo > can pass custom resolve opts between plugins

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ getDevEnvironment packages/vite/src/node/server/__tests__/pluginContainer.spec.ts:229:23 ❯ packages/vite/src/node/server/__tests__/pluginContainer.spec.ts:134:27

Check failure on line 1231 in packages/vite/src/node/optimizer/index.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, windows-latest

packages/vite/src/node/server/__tests__/pluginContainer.spec.ts > plugin container > load > can resolve a secondary module

TypeError: Cannot read properties of undefined (reading 'checkPatches') ❯ getLockfileHash packages/vite/src/node/optimizer/index.ts:1231:24 ❯ getDepHash packages/vite/src/node/optimizer/index.ts:1249:24 ❯ initDepsOptimizerMetadata packages/vite/src/node/optimizer/index.ts:315:46 ❯ createDepsOptimizer packages/vite/src/node/optimizer/optimizer.ts:54:43 ❯ new DevEnvironment packages/vite/src/node/server/environment.ts:152:13 ❯ getDevEnvironment packages/vite/src/node/server/__tests__/pluginContainer.spec.ts:229:23 ❯ packages/vite/src/node/server/__tests__/pluginContainer.spec.ts:169:27
// 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 590af2b

Please sign in to comment.