refactor: error message on out of date lockfile

This commit is contained in:
Zoltan Kochan
2024-10-07 17:49:48 +02:00
parent d994f5178b
commit a943fc9741
3 changed files with 9 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/core": patch
---
When the lockfile is not up to date make it clear what `package.json` is out of sync.

View File

@@ -441,7 +441,7 @@ Note that in CI environments, this setting is enabled by default.`,
throw new PnpmError('OUTDATED_LOCKFILE',
`Cannot install with "frozen-lockfile" because ${WANTED_LOCKFILE} is not up to date with ` +
path.relative(opts.lockfileDir, path.join(rootDir, 'package.json')), {
path.join('<ROOT>', path.relative(opts.lockfileDir, path.join(rootDir, 'package.json'))), {
hint: `Note that in CI environments this setting is true by default. If you still need to run install in such cases, use "pnpm install --no-frozen-lockfile"
Failure reason:

View File

@@ -28,7 +28,7 @@ test(`frozen-lockfile: installation fails if specs in package.json don't match t
'is-positive': '^3.1.0',
},
}, testDefaults({ frozenLockfile: true }))
).rejects.toThrow(`Cannot install with "frozen-lockfile" because ${WANTED_LOCKFILE} is not up to date with package.json`)
).rejects.toThrow(`Cannot install with "frozen-lockfile" because ${WANTED_LOCKFILE} is not up to date with ${path.join('<ROOT>', 'package.json')}`)
})
test(`frozen-lockfile+hoistPattern: installation fails if specs in package.json don't match the ones in ${WANTED_LOCKFILE}`, async () => {
@@ -46,7 +46,7 @@ test(`frozen-lockfile+hoistPattern: installation fails if specs in package.json
'is-positive': '^3.1.0',
},
}, testDefaults({ frozenLockfile: true, hoistPattern: '*' }))
).rejects.toThrow(`Cannot install with "frozen-lockfile" because ${WANTED_LOCKFILE} is not up to date with package.json`)
).rejects.toThrow(`Cannot install with "frozen-lockfile" because ${WANTED_LOCKFILE} is not up to date with ${path.join('<ROOT>', 'package.json')}`)
})
test(`frozen-lockfile: fail on a shared ${WANTED_LOCKFILE} that does not satisfy one of the package.json files`, async () => {
@@ -97,7 +97,7 @@ test(`frozen-lockfile: fail on a shared ${WANTED_LOCKFILE} that does not satisfy
await expect(
mutateModules(projects, testDefaults({ frozenLockfile: true, allProjects: [project1, project2] }))
).rejects.toThrow(`Cannot install with "frozen-lockfile" because ${WANTED_LOCKFILE} is not up to date with p1${path.sep}package.json`)
).rejects.toThrow(`Cannot install with "frozen-lockfile" because ${WANTED_LOCKFILE} is not up to date with ${path.join('<ROOT>', 'p1/package.json')}`)
})
test(`frozen-lockfile: should successfully install when ${WANTED_LOCKFILE} is available`, async () => {