Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /