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): detect npm / yarn / pnpm dependency changes correctly (#17336) #18560

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions packages/vite/src/node/optimizer/index.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to update how we check for the patches directory too if checkPatches is true. For example if we found lockFilePath to be <project>/node_modules/.package-lock.json, we should be checking <project>/patches/

Original file line number Diff line number Diff line change
Expand Up @@ -1145,14 +1145,45 @@ function isSingleDefaultExport(exports: readonly string[]) {
}

const lockfileFormats = [
{ name: 'package-lock.json', checkPatches: true, manager: 'npm' },
{ name: 'yarn.lock', checkPatches: true, manager: 'yarn' }, // Included in lockfile for v2+
{ name: 'pnpm-lock.yaml', checkPatches: false, manager: 'pnpm' }, // Included in lockfile
{ name: 'bun.lockb', checkPatches: true, manager: 'bun' },
{
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,
manager: 'pnpm',
},
{ name: 'bun.lockb', path: 'bun.lockb', checkPatches: true, manager: 'bun' },
].sort((_, { manager }) => {
return process.env.npm_config_user_agent?.startsWith(manager) ? 1 : -1
})
const lockfileNames = lockfileFormats.map((l) => l.name)
const lockfilePaths = lockfileFormats.map((l) => l.path)

function getConfigHash(environment: Environment): string {
// Take config into account
Expand Down Expand Up @@ -1190,7 +1221,7 @@ function getConfigHash(environment: Environment): string {
}

function getLockfileHash(environment: Environment): string {
const lockfilePath = lookupFile(environment.config.root, lockfileNames)
const lockfilePath = lookupFile(environment.config.root, lockfilePaths)
let content = lockfilePath ? fs.readFileSync(lockfilePath, 'utf-8') : ''
if (lockfilePath) {
const lockfileName = path.basename(lockfilePath)
Expand Down