fix: reject null named catalogs in workspace manifest reader (#11231)

This commit is contained in:
Dami Oyeniyi
2026-04-28 00:53:31 +01:00
committed by Zoltan Kochan
parent 16b347620b
commit f543b77006
4 changed files with 25 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/workspace.workspace-manifest-reader": patch
"pnpm": patch
---
Reject `null` named catalogs in workspace manifests with `InvalidWorkspaceManifestError` instead of crashing with a raw `TypeError`.

View File

@@ -46,6 +46,10 @@ export function assertValidWorkspaceManifestCatalogs (manifest: { packages?: rea
throw new InvalidWorkspaceManifestError(`Expected named catalog ${catalogName} to be an object, but found - array`)
}
if (catalog === null) {
throw new InvalidWorkspaceManifestError(`Expected named catalog ${catalogName} to be an object, but found - null`)
}
if (typeof catalog !== 'object') {
throw new InvalidWorkspaceManifestError(`Expected named catalog ${catalogName} to be an object, but found - ${typeof catalog}`)
}

View File

@@ -0,0 +1,6 @@
packages:
- "packages/**"
- "types"
catalogs:
foo: null

View File

@@ -133,6 +133,15 @@ describe('readWorkspaceManifest() catalogs field', () => {
).rejects.toThrow('Expected named catalog foo to be an object, but found - number')
})
test('throws on null named catalog', async () => {
await expect(
readWorkspaceManifest(path.join(import.meta.dirname, '__fixtures__/catalogs-invalid-named-catalog-null'))
).rejects.toMatchObject({
code: 'ERR_PNPM_INVALID_WORKSPACE_CONFIGURATION',
message: expect.stringContaining('Expected named catalog foo to be an object, but found - null'),
})
})
test('throws on invalid named catalog specifier', async () => {
await expect(
readWorkspaceManifest(path.join(import.meta.dirname, '__fixtures__/catalogs-invalid-named-catalog-specifier'))