diff --git a/@commitlint/config-pnpm-scopes/index.test.ts b/@commitlint/config-pnpm-scopes/index.test.ts index 5b28bf7d1e..8fd934b3e6 100644 --- a/@commitlint/config-pnpm-scopes/index.test.ts +++ b/@commitlint/config-pnpm-scopes/index.test.ts @@ -51,11 +51,11 @@ test("scope-enum has expected modifier", async () => { expect(modifier).toBe("always"); }); -test("returns empty value for empty pnpm repository", async () => { +test("returns global scope for empty pnpm repository", async () => { const { "scope-enum": fn } = config.rules; const cwd = await npm.bootstrap("fixtures/empty", __dirname); const [, , value] = await fn({ cwd }); - expect(value).toEqual([]); + expect(value).toEqual(["global"]); }); test("returns expected value for basic pnpm repository", async () => { @@ -63,7 +63,7 @@ test("returns expected value for basic pnpm repository", async () => { const cwd = await npm.bootstrap("fixtures/basic", __dirname); const [, , value] = await fn({ cwd }); - expect(value).toEqual(["a", "b"]); + expect(value).toEqual(["a", "b", "global"]); }); test("returns expected value for scoped pnpm repository", async () => { @@ -72,5 +72,5 @@ test("returns expected value for scoped pnpm repository", async () => { const [, , value] = await fn({ cwd }); - expect(value).toEqual(["a", "b"]); + expect(value).toEqual(["a", "b", "global"]); }); diff --git a/@commitlint/config-pnpm-scopes/index.ts b/@commitlint/config-pnpm-scopes/index.ts index 57283cc30a..10dde7a74c 100644 --- a/@commitlint/config-pnpm-scopes/index.ts +++ b/@commitlint/config-pnpm-scopes/index.ts @@ -69,16 +69,17 @@ function getProjects(context: any) { const cwd = ctx.cwd || process.cwd(); return findWorkspacePackages(cwd).then((projects: any) => { - return projects - .reduce((projects: any, project: any) => { - const name = project.name; + const scopes = projects.reduce((acc: any, project: any) => { + const name = project.name; - if (name) { - projects.push(name.charAt(0) === "@" ? name.split("/")[1] : name); - } + if (name) { + acc.add(name.charAt(0) === "@" ? name.split("/")[1] : name); + } + + return acc; + }, new Set()); + scopes.add("global"); - return projects; - }, []) - .sort(); + return Array.from(scopes).sort(); }); }