+16
-1
@@ -5,3 +5,18 @@ { | ||
| { | ||
| "date": "Tue, 13 Apr 2021 06:46:44 GMT", | ||
| "date": "Tue, 26 Oct 2021 07:11:58 GMT", | ||
| "tag": "p-graph_v1.1.2", | ||
| "version": "1.1.2", | ||
| "comments": { | ||
| "patch": [ | ||
| { | ||
| "comment": "update cyclic dependancy error to inlude the cycle", | ||
| "author": "cheruiyotbryan@gmail.com", | ||
| "commit": "1e42bb7ba4d295a25c0f17ce97aba9f8f189daa6", | ||
| "package": "p-graph" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "date": "Tue, 13 Apr 2021 06:46:49 GMT", | ||
| "tag": "p-graph_v1.1.1", | ||
@@ -8,0 +23,0 @@ "version": "1.1.1", |
+10
-2
| # Change Log - p-graph | ||
| This log was last generated on Tue, 13 Apr 2021 06:46:44 GMT and should not be manually modified. | ||
| This log was last generated on Tue, 26 Oct 2021 07:11:58 GMT and should not be manually modified. | ||
| <!-- Start content --> | ||
| ## 1.1.2 | ||
| Tue, 26 Oct 2021 07:11:58 GMT | ||
| ### Patches | ||
| - update cyclic dependancy error to inlude the cycle (cheruiyotbryan@gmail.com) | ||
| ## 1.1.1 | ||
| Tue, 13 Apr 2021 06:46:44 GMT | ||
| Tue, 13 Apr 2021 06:46:49 GMT | ||
@@ -11,0 +19,0 @@ ### Patches |
@@ -137,5 +137,36 @@ "use strict"; | ||
| ]; | ||
| const expectedErrorMessage = "The dependency graph has a cycle at B which depends on A,D and is depended on by C"; | ||
| const expectedErrorMessage = `A cycle has been detected including the following nodes: | ||
| B | ||
| C | ||
| D`; | ||
| expect(() => index_1.default(nodeMap, dependencies)).toThrow(expectedErrorMessage); | ||
| }); | ||
| it("throws an exception in the first instance of a cycle that has been detected when there are overlapped cycles", async () => { | ||
| // This is almost the same as the last test, except the root node is not a part of the cycle | ||
| const nodeMap = new Map([ | ||
| ["A", { run: () => Promise.resolve() }], | ||
| ["B", { run: () => Promise.resolve() }], | ||
| ["C", { run: () => Promise.resolve() }], | ||
| ["D", { run: () => Promise.resolve() }], | ||
| ["E", { run: () => Promise.resolve() }], | ||
| ["F", { run: () => Promise.resolve() }], | ||
| ]); | ||
| // B -> C -> E -> F -> D is the first cycle detected | ||
| const dependencies = [ | ||
| ["A", "B"], | ||
| ["B", "C"], | ||
| ["C", "D"], | ||
| ["D", "B"], | ||
| ["C", "E"], | ||
| ["E", "F"], | ||
| ["F", "D"], | ||
| ]; | ||
| const expectedErrorMessage = `A cycle has been detected including the following nodes: | ||
| B | ||
| C | ||
| E | ||
| F | ||
| D`; | ||
| expect(() => index_1.default(nodeMap, dependencies)).toThrow(expectedErrorMessage); | ||
| }); | ||
| it("resolves an empty dependnecy graph", async () => { | ||
@@ -142,0 +173,0 @@ const nodeMap = new Map(); |
| import { PGraphNodeWithCyclicDependency, PGraphNodeWithNoCyclicDependency, PGraphNodeWithDependencies } from "./types"; | ||
| /** | ||
| * Checks for any cycles in the dependency graph, returning `{ hasCycle: false }` if no cycles were detected. | ||
| * Otherwise it returns the details of where the cycle was detected. | ||
| * Otherwise it returns the chain of nodes where the cycle was detected. | ||
| */ | ||
| export declare function graphHasCycles(pGraphDependencyMap: Map<string, PGraphNodeWithDependencies>): PGraphNodeWithCyclicDependency | PGraphNodeWithNoCyclicDependency; |
+11
-16
@@ -5,3 +5,3 @@ "use strict"; | ||
| * Checks for any cycles in the dependency graph, returning `{ hasCycle: false }` if no cycles were detected. | ||
| * Otherwise it returns the details of where the cycle was detected. | ||
| * Otherwise it returns the chain of nodes where the cycle was detected. | ||
| */ | ||
@@ -16,3 +16,3 @@ function graphHasCycles(pGraphDependencyMap) { | ||
| const visitMap = new Map(); | ||
| for (const [nodeId, nodes] of pGraphDependencyMap.entries()) { | ||
| for (const [nodeId] of pGraphDependencyMap.entries()) { | ||
| /** | ||
@@ -25,11 +25,5 @@ * Test whether this node has already been visited or not. | ||
| */ | ||
| if (hasCycleDFS(pGraphDependencyMap, visitMap, nodeId)) { | ||
| return { | ||
| hasCycle: true, | ||
| details: { | ||
| nodeId, | ||
| dependsOn: Array.from(nodes.dependsOn), | ||
| dependedOnBy: Array.from(nodes.dependedOnBy) | ||
| } | ||
| }; | ||
| const cycle = searchForCycleDFS(pGraphDependencyMap, visitMap, nodeId); | ||
| if (cycle.length) { | ||
| return { hasCycle: true, cycle }; | ||
| } | ||
@@ -41,3 +35,3 @@ } | ||
| exports.graphHasCycles = graphHasCycles; | ||
| const hasCycleDFS = (graph, visitMap, nodeId) => { | ||
| const searchForCycleDFS = (graph, visitMap, nodeId) => { | ||
| const stack = [{ node: nodeId, traversing: false }]; | ||
@@ -53,3 +47,4 @@ while (stack.length > 0) { | ||
| */ | ||
| return true; | ||
| const listOfCycle = stack.filter(i => i.traversing).map(a => a.node); | ||
| return listOfCycle.slice(listOfCycle.indexOf(current.node)); | ||
| } | ||
@@ -77,5 +72,5 @@ else { | ||
| /** | ||
| * Add the current node's dependencies to the stack | ||
| * Add the current node's dependents to the stack | ||
| */ | ||
| stack.push(...[...node.dependsOn].map((n) => ({ node: n, traversing: false }))); | ||
| stack.push(...[...node.dependedOnBy].map((n) => ({ node: n, traversing: false }))); | ||
| } | ||
@@ -90,3 +85,3 @@ else { | ||
| } | ||
| return false; | ||
| return []; | ||
| }; |
+3
-4
@@ -28,6 +28,5 @@ "use strict"; | ||
| } | ||
| const hasCycles = graphHasCycles_1.graphHasCycles(this.pGraphDependencyMap); | ||
| if (hasCycles.hasCycle) { | ||
| const { nodeId, dependsOn, dependedOnBy } = hasCycles.details; | ||
| throw new Error(`The dependency graph has a cycle at ${nodeId} which depends on ${dependsOn} and is depended on by ${dependedOnBy}`); | ||
| const graph = graphHasCycles_1.graphHasCycles(this.pGraphDependencyMap); | ||
| if (graph.hasCycle) { | ||
| throw new Error(`A cycle has been detected including the following nodes:\n${graph.cycle.join("\n")}`); | ||
| } | ||
@@ -34,0 +33,0 @@ } |
+2
-15
@@ -59,18 +59,5 @@ /** | ||
| /** | ||
| * Details on where the cyclic dependency was detected. | ||
| * Chain of node where the cyclic dependency was detected. | ||
| */ | ||
| details: { | ||
| /** | ||
| * The identifier of this node, where the cyclic dependency was detected | ||
| */ | ||
| nodeId: string; | ||
| /** | ||
| * The set of nodes that this node depends on. | ||
| */ | ||
| dependsOn: string[]; | ||
| /** | ||
| * The set of nodes that depend on this node. | ||
| */ | ||
| dependedOnBy: string[]; | ||
| }; | ||
| cycle: string[]; | ||
| } |
+1
-1
| { | ||
| "name": "p-graph", | ||
| "version": "1.1.1", | ||
| "version": "1.1.2", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
58302
1.92%1136
2.43%