Skip to content

Commit

Permalink
Fixed an issue with changeset status executed without since argum…
Browse files Browse the repository at this point in the history
…ent (#1357)
  • Loading branch information
Andarist committed May 20, 2024
1 parent 4b60580 commit 18c966a
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-feet-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Fixed an issue with `changeset status` executed without `since` argument. It should now correctly use the configured base branch as the default value.
108 changes: 92 additions & 16 deletions packages/cli/src/commands/status/__tests__/status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultConfig, read } from "@changesets/config";
import { read } from "@changesets/config";
import * as git from "@changesets/git";
import { gitdir, silenceLogsInBlock } from "@changesets/test-utils";
import { ReleasePlan } from "@changesets/types";
Expand Down Expand Up @@ -76,7 +76,77 @@ describe("status", () => {
await git.add(".", cwd);
await git.commit("updated a", cwd);

const releaseObj = await status(cwd, { since: "main" }, defaultConfig);
const releaseObj = await status(
cwd,
{ since: "main" },
await readConfig(cwd)
);
expect(replaceHumanIds(releaseObj)).toMatchInlineSnapshot(`
{
"changesets": [
{
"id": "~changeset-1~",
"releases": [
{
"name": "pkg-a",
"type": "minor",
},
],
"summary": "This is a summary",
},
],
"preState": undefined,
"releases": [
{
"changesets": [
"~changeset-1~",
],
"name": "pkg-a",
"newVersion": "1.1.0",
"oldVersion": "1.0.0",
"type": "minor",
},
],
}
`);
});

it("should get the status comparing to the base branch with undefined since", async () => {
const cwd = await gitdir({
"package.json": JSON.stringify({
private: true,
workspaces: ["packages/*"],
}),
"packages/pkg-a/package.json": JSON.stringify({
name: "pkg-a",
version: "1.0.0",
}),
".changeset/config.json": JSON.stringify({
baseBranch: "main",
}),
});

await spawn("git", ["checkout", "-b", "new-branch"], { cwd });

await fs.outputFile(
path.join(cwd, "packages/pkg-a/a.js"),
'export default "updated a"'
);
await writeChangeset(
{
summary: "This is a summary",
releases: [{ name: "pkg-a", type: "minor" }],
},
cwd
);
await git.add(".", cwd);
await git.commit("updated a", cwd);

const releaseObj = await status(
cwd,
{ since: undefined },
await readConfig(cwd)
);
expect(replaceHumanIds(releaseObj)).toMatchInlineSnapshot(`
{
"changesets": [
Expand Down Expand Up @@ -133,7 +203,7 @@ describe("status", () => {
await git.add(".", cwd);
await git.commit("updated a", cwd);

await status(cwd, { since: "main" }, defaultConfig);
await status(cwd, { since: "main" }, await readConfig(cwd));

expect(process.exit).toHaveBeenCalledWith(1);
});
Expand All @@ -156,7 +226,11 @@ describe("status", () => {

await spawn("git", ["checkout", "-b", "new-branch"], { cwd });

const releaseObj = await status(cwd, { since: "main" }, defaultConfig);
const releaseObj = await status(
cwd,
{ since: "main" },
await readConfig(cwd)
);

expect(process.exit).not.toHaveBeenCalled();
expect(releaseObj).toEqual({
Expand Down Expand Up @@ -199,7 +273,7 @@ describe("status", () => {
await git.add(".", cwd);
await git.commit("updated a", cwd);

await status(cwd, { since: "main" }, defaultConfig);
await status(cwd, { since: "main" }, await readConfig(cwd));

expect(process.exit).not.toHaveBeenCalled();
});
Expand Down Expand Up @@ -242,7 +316,7 @@ describe("status", () => {
const probsUndefined = await status(
cwd,
{ since: "main", output },
defaultConfig
await readConfig(cwd)
);

const releaseObj = await fs.readFile(path.join(cwd, output), "utf-8");
Expand Down Expand Up @@ -287,7 +361,9 @@ describe("status", () => {
name: "pkg-a",
version: "1.0.0",
}),
".changeset/config.json": JSON.stringify({}),
".changeset/config.json": JSON.stringify({
changedFilePatterns: ["src/**"],
}),
});

// @ts-ignore
Expand All @@ -306,7 +382,7 @@ describe("status", () => {
const releaseObj = await status(
cwd,
{ since: "main" },
{ ...defaultConfig, changedFilePatterns: ["src/**"] }
await readConfig(cwd)
);

expect(process.exit).not.toHaveBeenCalled();
Expand All @@ -328,7 +404,9 @@ describe("status", () => {
version: "1.0.0",
}),
"packages/pkg-a/src/a.js": 'export default "a"',
".changeset/config.json": JSON.stringify({}),
".changeset/config.json": JSON.stringify({
changedFilePatterns: ["src/**"],
}),
});

// @ts-ignore
Expand All @@ -344,11 +422,7 @@ describe("status", () => {
await git.add(".", cwd);
await git.commit("updated a", cwd);

await status(
cwd,
{ since: "main" },
{ ...defaultConfig, changedFilePatterns: ["src/**"] }
);
await status(cwd, { since: "main" }, await readConfig(cwd));

expect(process.exit).toHaveBeenCalledWith(1);
});
Expand All @@ -364,7 +438,9 @@ describe("status", () => {
version: "1.0.0",
}),
"packages/pkg-a/src/a.js": 'export default "a"',
".changeset/config.json": JSON.stringify({}),
".changeset/config.json": JSON.stringify({
changedFilePatterns: ["src/**"],
}),
});

await spawn("git", ["checkout", "-b", "new-branch"], { cwd });
Expand All @@ -386,7 +462,7 @@ describe("status", () => {
const releaseObj = await status(
cwd,
{ since: "main" },
{ ...defaultConfig, changedFilePatterns: ["src/**"] }
await readConfig(cwd)
);
expect(replaceHumanIds(releaseObj)).toMatchInlineSnapshot(`
{
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/utils/versionablePackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ export function filterVersionablePackages(config: Config, packages: Package[]) {

export async function getVersionableChangedPackages(
config: Config,
options: {
{
cwd,
ref,
}: {
cwd: string;
ref?: string;
}
) {
const changedPackages = await getChangedPackagesSinceRef({
ref: config.baseBranch,
ref: ref ?? config.baseBranch,
changedFilePatterns: config.changedFilePatterns,
...options,
cwd,
});
return filterVersionablePackages(config, changedPackages);
}

0 comments on commit 18c966a

Please sign in to comment.