Skip to content

Commit 1c4d4eb

Browse files
committed
feat: add include package selection
Add the include configuration option and version --include flag using the existing ignore semantics for packages outside the selection.
1 parent c73949b commit 1c4d4eb

17 files changed

Lines changed: 840 additions & 110 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@changesets/cli": minor
3+
"@changesets/config": minor
4+
"@changesets/types": minor
5+
---
6+
7+
Add an `include` configuration option and a `changeset version --include` flag to select packages while treating all other packages as ignored. Preserve excluded changesets and reject mixed included/excluded changesets without partial consumption.

‎packages/cli/src/cli.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,24 @@ const tests: CommandTest[] = [
139139
ignore: ["pkg-a", "pkg-b"],
140140
},
141141
},
142+
{
143+
args: ["--include", "pkg-a", "--include", "pkg-b"],
144+
options: {
145+
include: ["pkg-a", "pkg-b"],
146+
},
147+
},
148+
{
149+
args: ["--include", " pkg-a , , pkg-b , "],
150+
options: {
151+
include: ["pkg-a", "pkg-b"],
152+
},
153+
},
154+
{
155+
args: ["--include", " , "],
156+
options: {
157+
include: [],
158+
},
159+
},
142160
{
143161
args: ["--snapshot"],
144162
options: {

‎packages/cli/src/cli.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,28 @@ cli
105105
.example(" $ changeset version")
106106
.example(" $ changeset version --snapshot 'pr#123'")
107107
.option("--ignore <pkg>", "Packages to ignore")
108+
.option("--include <pkg>", "Packages to include (all others are ignored)")
108109
.option("--snapshot [name]", "Create a snapshot prerelease")
109110
.option(
110111
"--snapshot-prerelease-template <template>",
111112
"Template for snapshot prerelease",
112113
)
113114
.action(async (options) => {
114-
normalizeOptions(options, { array: ["ignore"] });
115+
// CAC coerces empty values to 0, so check include input in the raw arguments.
116+
const args = cli.rawArgs.slice(2);
117+
const endOfOptions = args.indexOf("--");
118+
const optionArgs = endOfOptions === -1 ? args : args.slice(0, endOfOptions);
119+
if (
120+
optionArgs.some((arg, index) =>
121+
arg === "--include"
122+
? optionArgs[index + 1]?.trim() === ""
123+
: /^--include=\s*$/.test(arg),
124+
)
125+
) {
126+
log.error("The `--include` option requires a nonempty package name.");
127+
throw new ExitError(1);
128+
}
129+
normalizeOptions(options, { array: ["ignore", "include"] });
115130
const { version } = await import("./commands/version/index.ts");
116131
await version(options);
117132
});

‎packages/cli/src/commands/add/__tests__/add.test.ts‎

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -456,41 +456,44 @@ describe("Add command", () => {
456456
);
457457
});
458458

459-
it("should not include ignored packages in the prompt", async () => {
460-
const cwd = await testdir({
461-
"package.json": JSON.stringify({
462-
private: true,
463-
name: "root-pkg",
464-
workspaces: ["packages/*"],
465-
}),
466-
"package-lock.json": "",
467-
"packages/pkg-a/package.json": JSON.stringify({
468-
name: "pkg-a",
469-
version: "1.0.3",
470-
}),
471-
"packages/pkg-b/package.json": JSON.stringify({
472-
name: "pkg-b",
473-
version: "1.2.0",
474-
}),
475-
"packages/pkg-c/package.json": JSON.stringify({
476-
name: "pkg-c",
477-
version: "2.0.0",
478-
}),
479-
".changeset/config.json": JSON.stringify({
480-
...defaultConfig,
481-
ignore: ["pkg-b"],
482-
}),
483-
});
459+
it.each([{ ignore: ["pkg-b"] }, { include: ["pkg-a", "pkg-c"] }])(
460+
"omits skipped packages from the prompt with %j",
461+
async (selection) => {
462+
const cwd = await testdir({
463+
"package.json": JSON.stringify({
464+
private: true,
465+
name: "root-pkg",
466+
workspaces: ["packages/*"],
467+
}),
468+
"package-lock.json": "",
469+
"packages/pkg-a/package.json": JSON.stringify({
470+
name: "pkg-a",
471+
version: "1.0.3",
472+
}),
473+
"packages/pkg-b/package.json": JSON.stringify({
474+
name: "pkg-b",
475+
version: "1.2.0",
476+
}),
477+
"packages/pkg-c/package.json": JSON.stringify({
478+
name: "pkg-c",
479+
version: "2.0.0",
480+
}),
481+
".changeset/config.json": JSON.stringify({
482+
...defaultConfig,
483+
...selection,
484+
}),
485+
});
484486

485-
mockUserResponses({ releases: { "pkg-a": "patch" } });
486-
await addChangeset({ cwd });
487-
const choices =
488-
mockedUtils.askMultiselect.mock.calls[0][1]["unchanged packages"];
489-
expect(choices).toMatchObject([
490-
{ label: "pkg-a", value: "pkg-a" },
491-
{ label: "pkg-c", value: "pkg-c" },
492-
]);
493-
});
487+
mockUserResponses({ releases: { "pkg-a": "patch" } });
488+
await addChangeset({ cwd });
489+
const choices =
490+
mockedUtils.askMultiselect.mock.calls[0][1]["unchanged packages"];
491+
expect(choices).toStrictEqual([
492+
{ label: "pkg-a", value: "pkg-a" },
493+
{ label: "pkg-c", value: "pkg-c" },
494+
]);
495+
},
496+
);
494497

495498
it("should not include private packages without a version in the prompt", async () => {
496499
const cwd = await testdir({

‎packages/cli/src/commands/git-tag/__tests__/index.test.ts‎

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,38 @@ describe("git-tag command", () => {
4242
expect(mockedGit.tag.mock.calls[1][0]).toEqual("[email protected]");
4343
});
4444

45-
it("does not tag ignored packages", async () => {
46-
const cwd = await testdir({
47-
"package.json": JSON.stringify({
48-
private: true,
49-
workspaces: ["packages/*"],
50-
}),
51-
"package-lock.json": "",
52-
"packages/pkg-a/package.json": JSON.stringify({
53-
name: "pkg-a",
54-
version: "1.0.0",
55-
}),
56-
"packages/pkg-b/package.json": JSON.stringify({
57-
name: "pkg-b",
58-
version: "1.0.0",
59-
}),
60-
".changeset/config.json": JSON.stringify({
61-
ignore: ["pkg-a"],
62-
}),
63-
});
45+
it.each([{ ignore: ["pkg-a"] }, { include: ["pkg-b"] }])(
46+
"does not tag skipped packages with %j",
47+
async (selection) => {
48+
const cwd = await testdir({
49+
"package.json": JSON.stringify({
50+
private: true,
51+
workspaces: ["packages/*"],
52+
}),
53+
"package-lock.json": "",
54+
"packages/pkg-a/package.json": JSON.stringify({
55+
name: "pkg-a",
56+
version: "1.0.0",
57+
}),
58+
"packages/pkg-b/package.json": JSON.stringify({
59+
name: "pkg-b",
60+
version: "1.0.0",
61+
}),
62+
".changeset/config.json": JSON.stringify({
63+
...selection,
64+
}),
65+
});
6466

65-
mockedGit.getAllTags.mockResolvedValueOnce(new Set());
67+
mockedGit.getAllTags.mockResolvedValueOnce(new Set());
6668

67-
await gitTag({ cwd });
69+
await gitTag({ cwd });
6870

69-
expect(mockedGit.tag).toHaveBeenCalledExactlyOnceWith("[email protected]", cwd);
70-
});
71+
expect(mockedGit.tag).toHaveBeenCalledExactlyOnceWith(
72+
73+
cwd,
74+
);
75+
},
76+
);
7177

7278
it("writes tag events when output path is provided", async () => {
7379
const cwd = await testdir({

‎packages/cli/src/commands/publish-plan/__tests__/index.test.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,52 @@ describe("publish-plan", () => {
8181
`);
8282
});
8383

84+
it("includes only selected public releases and private tags", async () => {
85+
const cwd = await testdir({
86+
"package.json": JSON.stringify({
87+
name: "repo",
88+
private: true,
89+
workspaces: ["packages/*"],
90+
}),
91+
"package-lock.json": "",
92+
".changeset/config.json": JSON.stringify({
93+
include: ["pkg-a", "pkg-b"],
94+
privatePackages: { version: true, tag: true },
95+
}),
96+
"packages/pkg-a/package.json": JSON.stringify({
97+
name: "pkg-a",
98+
version: "1.0.0",
99+
}),
100+
"packages/pkg-b/package.json": JSON.stringify({
101+
name: "pkg-b",
102+
version: "1.0.0",
103+
private: true,
104+
}),
105+
"packages/pkg-c/package.json": JSON.stringify({
106+
name: "pkg-c",
107+
version: "1.0.0",
108+
}),
109+
"packages/pkg-d/package.json": JSON.stringify({
110+
name: "pkg-d",
111+
version: "1.0.0",
112+
private: true,
113+
}),
114+
});
115+
mockedInfo.mockResolvedValue({ published: false });
116+
mockedGit.getAllTags.mockResolvedValue(new Set());
117+
mockedGit.remoteTagExists.mockResolvedValue(false);
118+
119+
const result = await publishPlan({ cwd });
120+
121+
expect(result.flat()).toEqual([
122+
expect.objectContaining({ name: "pkg-a", kind: "publish" }),
123+
expect.objectContaining({ name: "pkg-b", kind: "tag-only" }),
124+
]);
125+
expect(
126+
mockedInfo.mock.calls.map(([{ pkg }]) => pkg.packageJson.name),
127+
).toEqual(["pkg-a"]);
128+
});
129+
84130
it("returns empty arrays when there is nothing to publish or tag", async () => {
85131
const cwd = await testdir({
86132
"package.json": JSON.stringify({

‎packages/cli/src/commands/status/__tests__/status.test.ts‎

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -490,51 +490,54 @@ describe("status", { tags: ["slow"] }, () => {
490490
`);
491491
});
492492

493-
it("should not exit early with a non-zero error code when only changed packages are ignored", async () => {
494-
const cwd = await gitdir({
495-
"package.json": JSON.stringify({
496-
private: true,
497-
name: "root-pkg",
498-
workspaces: ["packages/*"],
499-
}),
500-
"package-lock.json": "",
501-
"packages/pkg-a/package.json": JSON.stringify({
502-
name: "pkg-a",
503-
version: "1.0.0",
504-
}),
505-
"packages/pkg-a/src/a.js": 'export default "a"',
506-
"packages/pkg-b/package.json": JSON.stringify({
507-
name: "pkg-b",
508-
version: "1.0.0",
509-
}),
510-
"packages/pkg-b/src/b.js": 'export default "b"',
511-
".changeset/config.json": JSON.stringify({
512-
ignore: ["pkg-b"],
513-
}),
514-
});
515-
516-
vi.spyOn(process, "exit").mockImplementation((() => {}) as never);
517-
518-
await exec("git", ["checkout", "-b", "new-branch"], {
519-
nodeOptions: { cwd },
520-
});
521-
522-
await outputFile(
523-
path.join(cwd, "packages/pkg-b/b.js"),
524-
'export default "updated b"',
525-
);
526-
await git.add(".", cwd);
527-
await git.commit("updated b", cwd);
528-
529-
const releaseObj = await status({ cwd, since: "main" });
530-
531-
expect(process.exit).not.toHaveBeenCalled();
532-
expect(releaseObj).toEqual({
533-
changesets: [],
534-
releases: [],
535-
preState: undefined,
536-
});
537-
});
493+
it.each([{ ignore: ["pkg-b"] }, { include: ["pkg-a"] }])(
494+
"returns an empty plan when changed packages are skipped with %j",
495+
async (selection) => {
496+
const cwd = await gitdir({
497+
"package.json": JSON.stringify({
498+
private: true,
499+
name: "root-pkg",
500+
workspaces: ["packages/*"],
501+
}),
502+
"package-lock.json": "",
503+
"packages/pkg-a/package.json": JSON.stringify({
504+
name: "pkg-a",
505+
version: "1.0.0",
506+
}),
507+
"packages/pkg-a/src/a.js": 'export default "a"',
508+
"packages/pkg-b/package.json": JSON.stringify({
509+
name: "pkg-b",
510+
version: "1.0.0",
511+
}),
512+
"packages/pkg-b/src/b.js": 'export default "b"',
513+
".changeset/config.json": JSON.stringify({
514+
...selection,
515+
}),
516+
});
517+
518+
vi.spyOn(process, "exit").mockImplementation((() => {}) as never);
519+
520+
await exec("git", ["checkout", "-b", "new-branch"], {
521+
nodeOptions: { cwd },
522+
});
523+
524+
await outputFile(
525+
path.join(cwd, "packages/pkg-b/b.js"),
526+
'export default "updated b"',
527+
);
528+
await git.add(".", cwd);
529+
await git.commit("updated b", cwd);
530+
531+
const releaseObj = await status({ cwd, since: "main" });
532+
533+
expect(process.exit).not.toHaveBeenCalled();
534+
expect(releaseObj).toEqual({
535+
changesets: [],
536+
releases: [],
537+
preState: undefined,
538+
});
539+
},
540+
);
538541

539542
it("should not exit early with a non-zero error code when only changed packages are private and versioning for private packages is turned off", async () => {
540543
const cwd = await gitdir({

0 commit comments

Comments
 (0)