Skip to content

Commit

Permalink
feat(core): memoize project source hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Feb 26, 2020
1 parent 2c7d6a1 commit 65ac855
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
30 changes: 21 additions & 9 deletions packages/workspace/src/tasks-runner/hasher.ts
Expand Up @@ -53,29 +53,41 @@ export class Hasher {
}

export class ProjectHashes {
private sourceHashes: { [projectName: string]: Promise<string> } = {};

constructor(
private readonly projectGraph: ProjectGraph,
private readonly fileHashes: FileHashes
) {}

async hashProject(projectName: string, visited: string[]) {
return Promise.resolve().then(async () => {
const deps = (this.projectGraph.dependencies[projectName] || []).map(t =>
visited.indexOf(t.target) > -1
? ''
: this.hashProject(t.target, [t.target, ...visited])
const deps = (this.projectGraph.dependencies[projectName] || []).map(
t => {
if (visited.indexOf(t.target) > -1) {
return '';
} else {
visited.push(t.target);
return this.hashProject(t.target, visited);
}
}
);
const sources = this.hashProjectNodeSource(projectName);
return hasha(await Promise.all([...deps, sources]));
});
}

private async hashProjectNodeSource(projectName: string) {
const p = this.projectGraph.nodes[projectName];
const values = await Promise.all(
p.data.files.map(f => this.fileHashes.hashFile(f.file))
);
return hasha(values, { algorithm: 'sha256' });
if (!this.sourceHashes[projectName]) {
this.sourceHashes[projectName] = new Promise(async res => {
const p = this.projectGraph.nodes[projectName];
const values = await Promise.all(
p.data.files.map(f => this.fileHashes.hashFile(f.file))
);
res(hasha(values, { algorithm: 'sha256' }));
});
}
return this.sourceHashes[projectName];
}
}

Expand Down
3 changes: 0 additions & 3 deletions scripts/e2e-ci1.sh
Expand Up @@ -6,12 +6,9 @@ rm -rf tmp
mkdir -p tmp/angular
mkdir -p tmp/nx

# Please keep this in alphabetical order
# This should be every file under e2e except for utils.js up to next.test.ts
export SELECTED_CLI=$1
jest --maxWorkers=1 ./build/e2e/new.test.js &&
jest --maxWorkers=1 ./build/e2e/affected.test.js &&
jest --maxWorkers=1 ./build/e2e/affected-git.test.js &&
# jest --maxWorkers=1 ./build/e2e/bazel.test.js &&
jest --maxWorkers=1 ./build/e2e/command-line.test.js &&
jest --maxWorkers=1 ./build/e2e/cypress.test.js
2 changes: 0 additions & 2 deletions scripts/e2e-ci2.sh
Expand Up @@ -6,8 +6,6 @@ rm -rf tmp
mkdir -p tmp/angular
mkdir -p tmp/nx

# Please keep this in alphabetical order
# This should be every file under e2e except for utils.js after ng-add.test.ts
export SELECTED_CLI=$1
jest --maxWorkers=1 ./build/e2e/help.test.js &&
jest --maxWorkers=1 ./build/e2e/jest.test.js &&
Expand Down
2 changes: 0 additions & 2 deletions scripts/e2e-ci3.sh
Expand Up @@ -6,8 +6,6 @@ rm -rf tmp
mkdir -p tmp/angular
mkdir -p tmp/nx

# Please keep this in alphabetical order
# This should be every file under e2e except for utils.js after ng-add.test.ts
export SELECTED_CLI=$1
jest --maxWorkers=1 ./build/e2e/run-many.test.js &&
jest --maxWorkers=1 ./build/e2e/storybook.test.js &&
Expand Down
2 changes: 0 additions & 2 deletions scripts/e2e-ci4.sh
Expand Up @@ -6,8 +6,6 @@ rm -rf tmp
mkdir -p tmp/angular
mkdir -p tmp/nx

# Please keep this in alphabetical order
# This should be every file under e2e except for utils.js after ng-add.test.ts
export SELECTED_CLI=$1
jest --maxWorkers=1 ./build/e2e/ng-add.test.js &&
jest --maxWorkers=1 ./build/e2e/node.test.js &&
Expand Down

0 comments on commit 65ac855

Please sign in to comment.