Skip to content

Commit

Permalink
fix(bootstrap): reject-cycles when using workspaces (#3168)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkloht committed Oct 9, 2022
1 parent 31e4c98 commit 8a47a6d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workspaces-experimental true
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"version": "1.0.0",
"npmClient": "yarn",
"useWorkspaces": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "root",
"private": true,
"workspaces": [
"workspaces/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "package-1",
"version": "1.0.0",
"dependencies": {
"foo": "^1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "package-2",
"version": "1.0.0",
"dependencies": {
"package-2": "^1.0.0"
}
}
6 changes: 6 additions & 0 deletions commands/bootstrap/__tests__/bootstrap-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ describe("BootstrapCommand", () => {
const testDir = await initFixture("toposort");
const command = lernaBootstrap(testDir)("--reject-cycles");

await expect(command).rejects.toThrow("Dependency cycles detected, you should fix these!");
});
it("should throw an error with --reject-cycles when using yarn-workspaces", async () => {
const testDir = await initFixture("yarn-workspaces-cyclic");
const command = lernaBootstrap(testDir)("--reject-cycles");

await expect(command).rejects.toThrow("Dependency cycles detected, you should fix these!");
});
});
Expand Down
3 changes: 3 additions & 0 deletions commands/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ class BootstrapCommand extends Command {

execute() {
if (this.options.useWorkspaces || this.rootHasLocalFileDependencies()) {
if (this.options.rejectCycles) {
this.packageGraph.collapseCycles({ rejectCycles: this.options.rejectCycles });
}
return this.installRootPackageOnly();
}

Expand Down

0 comments on commit 8a47a6d

Please sign in to comment.