Skip to content

Commit 1aa8890

Browse files
Report a package in multiple fixed or linked groups only once
`noDuplicateFixedPackages` and `noDuplicateLinkedPackages` in packages/config/src/rules.ts push an error for every name accumulated in `duplicatedNames` inside the loop over the groups, so once a name lands in that set every later group pushes the same message again. A config with `fixed: [["pkg-a"], ["pkg-a"], ["pkg-b"]]` prints the "pkg-a is defined in multiple groups of fixed packages" error twice, and one more time for each additional group. Two groups happened to be the only shape covered by the tests, and that shape hides the bug because nothing follows the duplicate. The push now happens after the loop, so each duplicated package produces exactly one error no matter how many groups follow it.
1 parent d7e4a2d commit 1aa8890

3 files changed

Lines changed: 59 additions & 14 deletions

File tree

‎.changeset/soft-books-invent.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/config": patch
3+
---
4+
5+
Report a package that is defined in multiple `fixed` or `linked` groups only once, instead of once for every group that follows the duplicate.

‎packages/config/src/parse.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,44 @@ describe("validateConfig", () => {
624624

625625
// any tests that don't fit nicely into the cases above
626626
describe("rules", () => {
627+
describe("noDuplicateFixedPackages", () => {
628+
it("should report a duplicated package once when more groups follow it", async () => {
629+
const config = { fixed: [["pkg-a"], ["pkg-a"], ["pkg-b"]] };
630+
631+
const cwd = await testdir({
632+
".changeset/config.json": JSON.stringify(config),
633+
"package.json": JSON.stringify(rootManifest),
634+
});
635+
const packages = withPackages(cwd, ["pkg-a", "pkg-b"]);
636+
637+
const result = validateConfig(config, packages);
638+
639+
expect(result.errors).toHaveLength(1);
640+
expect(result.errors![0]).toContain(
641+
'fixed: Invalid group: The package or glob "pkg-a" is defined in multiple groups',
642+
);
643+
});
644+
});
645+
646+
describe("noDuplicateLinkedPackages", () => {
647+
it("should report a duplicated package once when more groups follow it", async () => {
648+
const config = { linked: [["pkg-a"], ["pkg-a"], ["pkg-b"]] };
649+
650+
const cwd = await testdir({
651+
".changeset/config.json": JSON.stringify(config),
652+
"package.json": JSON.stringify(rootManifest),
653+
});
654+
const packages = withPackages(cwd, ["pkg-a", "pkg-b"]);
655+
656+
const result = validateConfig(config, packages);
657+
658+
expect(result.errors).toHaveLength(1);
659+
expect(result.errors![0]).toContain(
660+
'linked: Invalid group: The package or glob "pkg-a" is defined in multiple groups',
661+
);
662+
});
663+
});
664+
627665
describe("alsoSkipDependentsOfSkipped", () => {
628666
it("should error when a not-skipped package depends on a skipped package", async () => {
629667
const pkgA = {

‎packages/config/src/rules.ts‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,15 @@ const noDuplicateFixedPackages: Rule = ({ config, errors }) => {
4949
}
5050
foundNames.add(name);
5151
}
52-
errors.push(
53-
...Array.from(
54-
duplicatedNames,
55-
(pkgOrGlob) =>
56-
`fixed: Invalid group: The package or glob "${pkgOrGlob}" is defined in multiple groups of fixed packages. Packages can only be belong to a single group. ${picomatchNote}`,
57-
),
58-
);
5952
}
53+
54+
errors.push(
55+
...Array.from(
56+
duplicatedNames,
57+
(pkgOrGlob) =>
58+
`fixed: Invalid group: The package or glob "${pkgOrGlob}" is defined in multiple groups of fixed packages. Packages can only be belong to a single group. ${picomatchNote}`,
59+
),
60+
);
6061
};
6162

6263
const linkedGroupsExist: Rule = ({
@@ -89,14 +90,15 @@ const noDuplicateLinkedPackages: Rule = ({ config, errors }) => {
8990
}
9091
foundNames.add(name);
9192
}
92-
errors.push(
93-
...Array.from(
94-
duplicatedNames,
95-
(pkgOrGlob) =>
96-
`linked: Invalid group: The package or glob "${pkgOrGlob}" is defined in multiple groups of linked packages. Packages can only be belong to a single group. ${picomatchNote}`,
97-
),
98-
);
9993
}
94+
95+
errors.push(
96+
...Array.from(
97+
duplicatedNames,
98+
(pkgOrGlob) =>
99+
`linked: Invalid group: The package or glob "${pkgOrGlob}" is defined in multiple groups of linked packages. Packages can only be belong to a single group. ${picomatchNote}`,
100+
),
101+
);
100102
};
101103

102104
const noFixedAndLinkedPackages: Rule = ({ config, errors }) => {

0 commit comments

Comments
 (0)