mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix(lockfile): better lockfile stringify error
This commit is contained in:
5
.changeset/popular-bugs-laugh.md
Normal file
5
.changeset/popular-bugs-laugh.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/lockfile-file": patch
|
||||
---
|
||||
|
||||
Print a better error message when stringifying a lockfile object fails.
|
||||
@@ -63,14 +63,12 @@ function writeLockfile (
|
||||
}
|
||||
|
||||
function yamlStringify (lockfile: Lockfile, forceSharedFormat: boolean) {
|
||||
const normalizedLockfile = normalizeLockfile(lockfile, forceSharedFormat)
|
||||
try {
|
||||
return yaml.safeDump(
|
||||
normalizeLockfile(lockfile, forceSharedFormat),
|
||||
LOCKFILE_YAML_FORMAT
|
||||
)
|
||||
return yaml.safeDump(normalizedLockfile, LOCKFILE_YAML_FORMAT)
|
||||
} catch (err) {
|
||||
if (err.message.includes('[object Undefined]')) {
|
||||
const brokenValuePath = findBrokenRecord(lockfile)
|
||||
const brokenValuePath = findBrokenRecord(normalizedLockfile)
|
||||
if (brokenValuePath) {
|
||||
throw new PnpmError('LOCKFILE_STRINGIFY', `Failed to stringify the lockfile object. Undefined value at: ${brokenValuePath}`)
|
||||
}
|
||||
@@ -127,7 +125,7 @@ function normalizeLockfile (lockfile: Lockfile, forceSharedFormat: boolean) {
|
||||
importers: R.keys(lockfile.importers).reduce((acc, alias) => {
|
||||
const importer = lockfile.importers[alias]
|
||||
const normalizedImporter = {
|
||||
specifiers: importer.specifiers,
|
||||
specifiers: importer.specifiers ?? {},
|
||||
}
|
||||
for (const depType of DEPENDENCIES_FIELDS) {
|
||||
if (!R.isEmpty(importer[depType] ?? {})) {
|
||||
|
||||
@@ -149,16 +149,17 @@ test('writeLockfiles() fails with meaningful error, when an invalid lockfile obj
|
||||
'is-negative': '1.0.0',
|
||||
'is-positive': '1.0.0',
|
||||
},
|
||||
// eslint-disable-next-line
|
||||
specifiers: undefined as any,
|
||||
specifiers: {
|
||||
'is-negative': '^1.0.0',
|
||||
'is-positive': '^1.0.0',
|
||||
},
|
||||
},
|
||||
},
|
||||
lockfileVersion: LOCKFILE_VERSION,
|
||||
packages: {
|
||||
'/is-negative/1.0.0': {
|
||||
dependencies: {
|
||||
'is-positive': '2.0.0',
|
||||
},
|
||||
// eslint-disable-next-line
|
||||
dependencies: undefined as any,
|
||||
resolution: {
|
||||
integrity: 'sha1-ChbBDewTLAqLCzb793Fo5VDvg/g=',
|
||||
},
|
||||
@@ -180,5 +181,5 @@ test('writeLockfiles() fails with meaningful error, when an invalid lockfile obj
|
||||
currentLockfileDir: projectPath,
|
||||
wantedLockfile,
|
||||
wantedLockfileDir: projectPath,
|
||||
})).toThrow(new PnpmError('LOCKFILE_STRINGIFY', 'Failed to stringify the lockfile object. Undefined value at: importers[.].specifiers'))
|
||||
})).toThrow(new PnpmError('LOCKFILE_STRINGIFY', 'Failed to stringify the lockfile object. Undefined value at: packages./is-negative/1.0.0.dependencies'))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user