fix(workspace.read-manifest): allow null or empty manifest (#7310)

close #7307
This commit is contained in:
JasonMan34
2023-11-14 11:47:28 +02:00
committed by GitHub
parent 2143a9388a
commit e2a0c72720
4 changed files with 20 additions and 6 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/workspace.read-manifest": patch
"pnpm": patch
---
Don't fail on an empty `pnpm-workspace.yaml` file [#7307](https://github.com/pnpm/pnpm/issues/7307).

View File

@@ -32,15 +32,11 @@ async function readManifestRaw (dir: string): Promise<unknown> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function validateWorkspaceManifest (manifest: any): manifest is WorkspaceManifest | undefined {
if (manifest === undefined) {
// Empty manifest is ok
if (manifest === undefined || manifest === null) {
// Empty or null manifest is ok
return true
}
if (manifest === null) {
throw new InvalidWorkspaceManifestError('Expected object but found - null')
}
if (typeof manifest !== 'object') {
throw new InvalidWorkspaceManifestError(`Expected object but found - ${typeof manifest}`)
}

View File

@@ -49,4 +49,16 @@ test('readWorkspaceManifest() works when no workspace file is present', async ()
const manifest = await readWorkspaceManifest(path.join(__dirname, '__fixtures__/no-workspace-file'))
expect(manifest).toBeUndefined()
})
test('readWorkspaceManifest() works when workspace file is empty', async () => {
const manifest = await readWorkspaceManifest(path.join(__dirname, '__fixtures__/empty'))
expect(manifest).toBeUndefined()
})
test('readWorkspaceManifest() works when workspace file is null', async () => {
const manifest = await readWorkspaceManifest(path.join(__dirname, '__fixtures__/null'))
expect(manifest).toBeNull()
})