Skip to content

Commit 3029033

Browse files
authored
fix: remove usage of lodash flatten (lerna#4205)
1 parent 45e00ce commit 3029033

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

libs/core/src/lib/add-dependents.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import { flatten } from "lodash";
21
import { ProjectGraphProjectNodeWithPackage, ProjectGraphWithPackages } from "./project-graph-with-packages";
32

43
export function addDependents(
54
projects: ProjectGraphProjectNodeWithPackage[],
65
projectGraph: ProjectGraphWithPackages
76
): ProjectGraphProjectNodeWithPackage[] {
87
const projectsLookup = new Set(projects.map((p) => p.name));
9-
const dependents: Record<string, string[]> = flatten(
10-
Object.values(projectGraph.localPackageDependencies)
11-
).reduce(
12-
(prev, next) => ({
13-
...prev,
14-
[next.target]: [...(prev[next.target] || []), next.source],
15-
}),
16-
{} as Record<string, string[]>
17-
);
8+
const dependents: Record<string, string[]> = Object.values(projectGraph.localPackageDependencies)
9+
.flat()
10+
.reduce(
11+
(prev, next) => ({
12+
...prev,
13+
[next.target]: [...(prev[next.target] || []), next.source],
14+
}),
15+
{} as Record<string, string[]>
16+
);
1817

1918
const collected = new Set<ProjectGraphProjectNodeWithPackage>();
2019

libs/core/src/lib/collect-updates/collect-project-updates.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ExecOptions } from "child_process";
2-
import { flatten } from "lodash";
32
import { describeRefSync } from "../describe-ref";
43
import { getPackagesForOption } from "../get-packages-for-option";
54
import log from "../npmlog";
@@ -178,15 +177,15 @@ export function collectDependents(
178177
nodes: Record<string, ProjectGraphProjectNodeWithPackage>,
179178
projectGraph: ProjectGraphWithPackages
180179
): Set<ProjectGraphProjectNodeWithPackage> {
181-
const dependents: Record<string, string[]> = flatten(
182-
Object.values(projectGraph.localPackageDependencies)
183-
).reduce(
184-
(prev, next) => ({
185-
...prev,
186-
[next.target]: [...(prev[next.target] || []), next.source],
187-
}),
188-
{} as Record<string, string[]>
189-
);
180+
const dependents: Record<string, string[]> = Object.values(projectGraph.localPackageDependencies)
181+
.flat()
182+
.reduce(
183+
(prev, next) => ({
184+
...prev,
185+
[next.target]: [...(prev[next.target] || []), next.source],
186+
}),
187+
{} as Record<string, string[]>
188+
);
190189

191190
const collected = new Set<ProjectGraphProjectNodeWithPackage>();
192191

libs/core/src/lib/run-projects-topologically.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { flatten } from "lodash";
21
import PQueue from "p-queue";
32
import { getCycles, mergeOverlappingCycles, reportCycles } from "./cycles";
43
import { ProjectGraphProjectNodeWithPackage, ProjectGraphWithPackages } from "./project-graph-with-packages";
@@ -24,7 +23,7 @@ export async function runProjectsTopologically<T>(
2423

2524
const projectsMap = new Map(projects.map((p) => [p.name, p]));
2625
const localDependencies = projectGraph.localPackageDependencies;
27-
const flattenedLocalDependencies = flatten(Object.values(localDependencies));
26+
const flattenedLocalDependencies = Object.values(localDependencies).flat();
2827

2928
const getProject = (name: string) => {
3029
const project = projectsMap.get(name);

libs/core/src/lib/toposort-projects.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { flatten } from "lodash";
21
import { getCycles, mergeOverlappingCycles, reportCycles } from "./cycles";
32
import { ProjectGraphProjectNodeWithPackage, ProjectGraphWithPackages } from "./project-graph-with-packages";
43

@@ -9,7 +8,7 @@ export function toposortProjects(
98
): ProjectGraphProjectNodeWithPackage[] {
109
const projectsMap = new Map(projects.map((p) => [p.name, p]));
1110
const localDependencies = projectGraph.localPackageDependencies;
12-
const flattenedLocalDependencies = flatten(Object.values(localDependencies));
11+
const flattenedLocalDependencies = Object.values(localDependencies).flat();
1312

1413
const getProject = (name: string) => {
1514
const project = projectsMap.get(name);

0 commit comments

Comments
 (0)