Skip to content

Commit 8211512

Browse files
authored
fix: remove all remaining lodash usage (#4207)
1 parent 8889a42 commit 8211512

File tree

6 files changed

+85
-27
lines changed

6 files changed

+85
-27
lines changed

libs/core/src/lib/cycles/merge-overlapping-cycles.spec.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,42 @@ describe("mergeOverlappingCycles", () => {
1818
["package-z", "package-zz", "package-zzz", "package-zzzz"],
1919
]);
2020
});
21+
22+
it("should handle empty cycles", () => {
23+
expect(mergeOverlappingCycles([])).toEqual([]);
24+
});
25+
26+
it("should handle single cycle", () => {
27+
const cycles = [["package-a", "package-b", "package-c"]];
28+
expect(mergeOverlappingCycles(cycles)).toEqual([["package-a", "package-b", "package-c"]]);
29+
});
30+
31+
it("should handle cycles with no overlaps", () => {
32+
const cycles = [
33+
["package-a", "package-b"],
34+
["package-c", "package-d"],
35+
["package-e", "package-f"],
36+
];
37+
expect(mergeOverlappingCycles(cycles)).toEqual([
38+
["package-a", "package-b"],
39+
["package-c", "package-d"],
40+
["package-e", "package-f"],
41+
]);
42+
});
43+
44+
it("should handle cycles with complete overlap", () => {
45+
const cycles = [
46+
["package-a", "package-b", "package-c"],
47+
["package-a", "package-b", "package-c"],
48+
];
49+
expect(mergeOverlappingCycles(cycles)).toEqual([["package-a", "package-b", "package-c"]]);
50+
});
51+
52+
it("should handle cycles with partial overlap", () => {
53+
const cycles = [
54+
["package-a", "package-b"],
55+
["package-b", "package-c"],
56+
];
57+
expect(mergeOverlappingCycles(cycles)).toEqual([["package-a", "package-b", "package-c"]]);
58+
});
2159
});

libs/core/src/lib/cycles/merge-overlapping-cycles.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import { difference, intersection } from "lodash";
1+
/**
2+
* Returns an array of elements that are present in both input arrays
3+
*/
4+
function intersection<T>(arr1: T[], arr2: T[]): T[] {
5+
return arr1.filter((item) => arr2.includes(item));
6+
}
7+
8+
/**
9+
* Returns an array of elements from the first array that are not present in the second array
10+
*/
11+
function difference<T>(arr1: T[], arr2: T[]): T[] {
12+
return arr1.filter((item) => !arr2.includes(item));
13+
}
214

315
/**
416
* Merges all cycles that share nodes into a single cycle, then returns all merged cycles. This allows all cycle nodes to be traversed without repeating any nodes.

package-lock.json

Lines changed: 33 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"@types/jest": "29.5.14",
5858
"@types/js-yaml": "^4.0.9",
5959
"@types/libnpmpublish": "^9.0.0",
60-
"@types/lodash": "^4.17.5",
6160
"@types/node": "18.19.10",
6261
"@types/node-fetch": "^2.6.11",
6362
"@types/normalize-path": "^3.0.2",
@@ -83,7 +82,6 @@
8382
"js-yaml": "^4.1.0",
8483
"jsonc-eslint-parser": "^2.4.0",
8584
"lerna": "file:packages/lerna",
86-
"lodash": "^4.17.21",
8785
"normalize-newline": "^3.0.0",
8886
"normalize-path": "^3.0.0",
8987
"nx": "20.7.2",
@@ -98,6 +96,5 @@
9896
"typescript": "5.8.3",
9997
"typescript-eslint": "^8.38.0",
10098
"verdaccio": "6.1.5"
101-
},
102-
"dependencies": {}
99+
}
103100
}

packages/legacy-structure/commands/create/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"js-yaml": "4.1.0",
6464
"libnpmpublish": "9.0.9",
6565
"load-json-file": "6.2.0",
66-
"lodash": "^4.17.21",
6766
"make-dir": "4.0.0",
6867
"minimatch": "3.0.5",
6968
"multimatch": "5.0.0",

packages/lerna/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
"libnpmaccess": "8.0.6",
7878
"libnpmpublish": "9.0.9",
7979
"load-json-file": "6.2.0",
80-
"lodash": "^4.17.21",
8180
"make-dir": "4.0.0",
8281
"minimatch": "3.0.5",
8382
"multimatch": "5.0.0",

0 commit comments

Comments
 (0)