Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 684b2bb

Browse files
committedFeb 26, 2020
feat(core): memoize project source hashing
1 parent 4327ca9 commit 684b2bb

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed
 

‎packages/workspace/src/tasks-runner/hasher.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,41 @@ export class Hasher {
5353
}
5454

5555
export class ProjectHashes {
56+
private sourceHashes: { [projectName: string]: Promise<string> } = {};
57+
5658
constructor(
5759
private readonly projectGraph: ProjectGraph,
5860
private readonly fileHashes: FileHashes
5961
) {}
6062

6163
async hashProject(projectName: string, visited: string[]) {
6264
return Promise.resolve().then(async () => {
63-
const deps = (this.projectGraph.dependencies[projectName] || []).map(t =>
64-
visited.indexOf(t.target) > -1
65-
? ''
66-
: this.hashProject(t.target, [t.target, ...visited])
65+
const deps = (this.projectGraph.dependencies[projectName] || []).map(
66+
t => {
67+
if (visited.indexOf(t.target) > -1) {
68+
return '';
69+
} else {
70+
visited.push(t.target);
71+
return this.hashProject(t.target, visited);
72+
}
73+
}
6774
);
6875
const sources = this.hashProjectNodeSource(projectName);
6976
return hasha(await Promise.all([...deps, sources]));
7077
});
7178
}
7279

7380
private async hashProjectNodeSource(projectName: string) {
74-
const p = this.projectGraph.nodes[projectName];
75-
const values = await Promise.all(
76-
p.data.files.map(f => this.fileHashes.hashFile(f.file))
77-
);
78-
return hasha(values, { algorithm: 'sha256' });
81+
if (!this.sourceHashes[projectName]) {
82+
this.sourceHashes[projectName] = new Promise(async res => {
83+
const p = this.projectGraph.nodes[projectName];
84+
const values = await Promise.all(
85+
p.data.files.map(f => this.fileHashes.hashFile(f.file))
86+
);
87+
res(hasha(values, { algorithm: 'sha256' }));
88+
});
89+
}
90+
return this.sourceHashes[projectName];
7991
}
8092
}
8193

‎scripts/e2e-ci2.sh

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ rm -rf tmp
66
mkdir -p tmp/angular
77
mkdir -p tmp/nx
88

9-
# Please keep this in alphabetical order
10-
# This should be every file under e2e except for utils.js after ng-add.test.ts
119
export SELECTED_CLI=$1
1210
jest --maxWorkers=1 ./build/e2e/ng-add.test.js &&
1311
jest --maxWorkers=1 ./build/e2e/ngrx.test.js &&

‎scripts/e2e-ci3.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
./scripts/link.sh
4+
5+
rm -rf tmp
6+
mkdir -p tmp/angular
7+
mkdir -p tmp/nx
8+
9+
export SELECTED_CLI=$1
10+
jest --maxWorkers=1 ./build/e2e/run-many.test.js &&
11+
jest --maxWorkers=1 ./build/e2e/storybook.test.js &&
12+
jest --maxWorkers=1 ./build/e2e/upgrade-module.test.js &&
13+
jest --maxWorkers=1 ./build/e2e/web.test.js &&
14+
jest --maxWorkers=1 ./build/e2e/tasks-runner-v2.test.js &&
15+
jest --maxWorkers=1 ./build/e2e/angular-package.test.js &&
16+
jest --maxWorkers=1 ./build/e2e/react-package.test.js &&
17+
jest --maxWorkers=1 ./build/e2e/ngrx.test.js

‎scripts/e2e-ci4.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
./scripts/link.sh
4+
5+
rm -rf tmp
6+
mkdir -p tmp/angular
7+
mkdir -p tmp/nx
8+
9+
export SELECTED_CLI=$1
10+
jest --maxWorkers=1 ./build/e2e/ng-add.test.js &&
11+
jest --maxWorkers=1 ./build/e2e/node.test.js &&
12+
jest --maxWorkers=1 ./build/e2e/nx-plugin.test.js &&
13+
jest --maxWorkers=1 ./build/e2e/print-affected.test.js &&
14+
jest --maxWorkers=1 ./build/e2e/react.test.js &&
15+
jest --maxWorkers=1 ./build/e2e/report.test.js

0 commit comments

Comments
 (0)
Please sign in to comment.