mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-11 02:29:48 -04:00
fix(workspace.read-manifest): allow null or empty manifest (#7310)
close #7307
This commit is contained in:
6
.changeset/fifty-rabbits-sleep.md
Normal file
6
.changeset/fifty-rabbits-sleep.md
Normal 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).
|
||||
@@ -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}`)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
Reference in New Issue
Block a user