Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions @commitlint/config-pnpm-scopes/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ 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 () => {
const { "scope-enum": fn } = config.rules;
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 () => {
Expand All @@ -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"]);
});
19 changes: 10 additions & 9 deletions @commitlint/config-pnpm-scopes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}