-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check that sequentialPrepare is not enabled on cyclic projects
- Loading branch information
1 parent
299748a
commit 68c1198
Showing
5 changed files
with
205 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Detect if there is a cyclic dependency tree between the packages | ||
* @param {Array<Package>} pkgs Array of package object | ||
* @returns {boolean} True if there are a cyclic dependency | ||
*/ | ||
const isCyclicProject = (pkgs) => { | ||
return pkgs.some((pkg) => | ||
pkg.localDeps.some((dep) => dep.localDeps.some((nestedDep) => nestedDep.name === pkg.name)) | ||
); | ||
}; | ||
|
||
module.exports = isCyclicProject; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const isCyclicProject = require("../../lib/isCyclicProject"); | ||
|
||
// Tests. | ||
describe("isCyclicProject()", () => { | ||
const pkgA = { | ||
name: "pkgA", | ||
localDeps: [], | ||
}; | ||
|
||
const pkgB = { | ||
name: "pkgB", | ||
localDeps: [], | ||
}; | ||
|
||
const pkgC = { | ||
name: "pkgC", | ||
localDeps: [pkgB], | ||
}; | ||
|
||
const pkgE = { | ||
name: "pkgD", | ||
localDeps: [], | ||
}; | ||
|
||
const pkgD = { | ||
name: "pkgD", | ||
localDeps: [pkgE], | ||
}; | ||
|
||
pkgE.localDeps = [pkgD]; | ||
|
||
test("With independent packages", () => { | ||
expect(isCyclicProject([pkgA, pkgB])).toBeFalsy(); | ||
}); | ||
test("With simple chain", () => { | ||
expect(isCyclicProject([pkgB, pkgC])).toBeFalsy(); | ||
}); | ||
|
||
test("With cyclic dependency", () => { | ||
expect(isCyclicProject([pkgD, pkgD])).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters