Skip to content

Commit

Permalink
Fixed a crash when root workspace has dependents (#1400)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored Jul 1, 2024
1 parent d108fa6 commit dd6e5bb
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-radios-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/config": patch
---

Fixed a crash when validating `ignore` while parsing the config in a scenario when a workspace depends on the root workspace
5 changes: 5 additions & 0 deletions .changeset/shiny-kings-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/get-dependents-graph": patch
---

Fixed a crash in `getDependentsGraph` in a scenario when a workspace depends on the root workspace
5 changes: 5 additions & 0 deletions .changeset/wise-years-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@changesets/cli": patch
---

Fixed a crash that prevented the CLI from running in a scenario when a workspace depends on the root workspace
2 changes: 1 addition & 1 deletion packages/cli/src/commands/add/__tests__/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const mockUserResponses = (mockResponses) => {
});
};

describe("Changesets", () => {
describe("Add command", () => {
silenceLogsInBlock();

it("should generate changeset to patch a single package", async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"devDependencies": {
"@changesets/test-utils": "*",
"@types/micromatch": "^4.0.1",
"jest-in-case": "^1.0.2"
"jest-in-case": "^1.0.2",
"outdent": "^0.5.0"
}
}
35 changes: 34 additions & 1 deletion packages/config/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { read, parse } from "./";
import jestInCase from "jest-in-case";
import * as logger from "@changesets/logger";
import { Config, WrittenConfig } from "@changesets/types";
import { Packages } from "@manypkg/get-packages";
import { Packages, getPackages } from "@manypkg/get-packages";
import { testdir } from "@changesets/test-utils";
import outdent from "outdent";

jest.mock("@changesets/logger");

Expand Down Expand Up @@ -64,6 +65,38 @@ test("read reads the config", async () => {
});
});

it("should not fail when validating ignored packages when some package depends on the root workspace", async () => {
const cwd = await testdir({
".changeset/config.json": JSON.stringify({
ignore: ["other-example"],
}),
"package.json": JSON.stringify({
name: "zod-to-fields",
version: "0.1.2",
}),
"pnpm-workspace.yaml": outdent`
packages:
- examples/*
`,
"examples/react/package.json": JSON.stringify({
name: "react-example",
private: true,
version: "0.0.0",
dependencies: {
"zod-to-fields": "workspace:*",
},
}),
"examples/other/package.json": JSON.stringify({
name: "other-example",
private: true,
version: "0.0.0",
}),
});

const packages = await getPackages(cwd);
expect(() => read(cwd, packages)).not.toThrow();
});

let defaults: Config = {
fixed: [],
linked: [],
Expand Down
7 changes: 6 additions & 1 deletion packages/get-dependents-graph/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ export function getDependentsGraph(

const dependentsLookup: {
[key: string]: { pkg: Package; dependents: Array<string> };
} = {};
} = {
[packages.root.packageJson.name]: {
pkg: packages.root,
dependents: [],
},
};

packages.packages.forEach((pkg) => {
dependentsLookup[pkg.packageJson.name] = {
Expand Down

0 comments on commit dd6e5bb

Please sign in to comment.