Skip to content

Commit e571970

Browse files
authored
feat(config-pnpm-scopes): allow global scope (#4553)
1 parent 407be6c commit e571970

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

@commitlint/config-pnpm-scopes/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ test("scope-enum has expected modifier", async () => {
5151
expect(modifier).toBe("always");
5252
});
5353

54-
test("returns empty value for empty pnpm repository", async () => {
54+
test("returns global scope for empty pnpm repository", async () => {
5555
const { "scope-enum": fn } = config.rules;
5656
const cwd = await npm.bootstrap("fixtures/empty", __dirname);
5757
const [, , value] = await fn({ cwd });
58-
expect(value).toEqual([]);
58+
expect(value).toEqual(["global"]);
5959
});
6060

6161
test("returns expected value for basic pnpm repository", async () => {
6262
const { "scope-enum": fn } = config.rules;
6363
const cwd = await npm.bootstrap("fixtures/basic", __dirname);
6464

6565
const [, , value] = await fn({ cwd });
66-
expect(value).toEqual(["a", "b"]);
66+
expect(value).toEqual(["a", "b", "global"]);
6767
});
6868

6969
test("returns expected value for scoped pnpm repository", async () => {
@@ -72,5 +72,5 @@ test("returns expected value for scoped pnpm repository", async () => {
7272

7373
const [, , value] = await fn({ cwd });
7474

75-
expect(value).toEqual(["a", "b"]);
75+
expect(value).toEqual(["a", "b", "global"]);
7676
});

@commitlint/config-pnpm-scopes/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,17 @@ function getProjects(context: any) {
6969
const cwd = ctx.cwd || process.cwd();
7070

7171
return findWorkspacePackages(cwd).then((projects: any) => {
72-
return projects
73-
.reduce((projects: any, project: any) => {
74-
const name = project.name;
72+
const scopes = projects.reduce((acc: any, project: any) => {
73+
const name = project.name;
7574

76-
if (name) {
77-
projects.push(name.charAt(0) === "@" ? name.split("/")[1] : name);
78-
}
75+
if (name) {
76+
acc.add(name.charAt(0) === "@" ? name.split("/")[1] : name);
77+
}
78+
79+
return acc;
80+
}, new Set());
81+
scopes.add("global");
7982

80-
return projects;
81-
}, [])
82-
.sort();
83+
return Array.from(scopes).sort();
8384
});
8485
}

0 commit comments

Comments
 (0)