From e2a0c7272015304270a46f585afdf94085cba7ec Mon Sep 17 00:00:00 2001 From: JasonMan34 Date: Tue, 14 Nov 2023 11:47:28 +0200 Subject: [PATCH] fix(workspace.read-manifest): allow null or empty manifest (#7310) close #7307 --- .changeset/fifty-rabbits-sleep.md | 6 ++++++ workspace/read-manifest/src/index.ts | 8 ++------ .../test/__fixtures__/empty/pnpm-workspace.yaml | 0 workspace/read-manifest/test/index.ts | 12 ++++++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 .changeset/fifty-rabbits-sleep.md create mode 100644 workspace/read-manifest/test/__fixtures__/empty/pnpm-workspace.yaml diff --git a/.changeset/fifty-rabbits-sleep.md b/.changeset/fifty-rabbits-sleep.md new file mode 100644 index 0000000000..3125b473fb --- /dev/null +++ b/.changeset/fifty-rabbits-sleep.md @@ -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). diff --git a/workspace/read-manifest/src/index.ts b/workspace/read-manifest/src/index.ts index ab7d00256d..9ed257dd0b 100644 --- a/workspace/read-manifest/src/index.ts +++ b/workspace/read-manifest/src/index.ts @@ -32,15 +32,11 @@ async function readManifestRaw (dir: string): Promise { // 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}`) } diff --git a/workspace/read-manifest/test/__fixtures__/empty/pnpm-workspace.yaml b/workspace/read-manifest/test/__fixtures__/empty/pnpm-workspace.yaml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/workspace/read-manifest/test/index.ts b/workspace/read-manifest/test/index.ts index 57043e43c0..ccd022049a 100644 --- a/workspace/read-manifest/test/index.ts +++ b/workspace/read-manifest/test/index.ts @@ -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() }) \ No newline at end of file