From 65ac855536d182aadbd02f587cb2c6e2aaf088ab Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Wed, 26 Feb 2020 11:17:08 -0500 Subject: [PATCH] feat(core): memoize project source hashing --- packages/workspace/src/tasks-runner/hasher.ts | 30 +++++++++++++------ scripts/e2e-ci1.sh | 3 -- scripts/e2e-ci2.sh | 2 -- scripts/e2e-ci3.sh | 2 -- scripts/e2e-ci4.sh | 2 -- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/packages/workspace/src/tasks-runner/hasher.ts b/packages/workspace/src/tasks-runner/hasher.ts index ddc71ab617eb8..6ac8665139098 100644 --- a/packages/workspace/src/tasks-runner/hasher.ts +++ b/packages/workspace/src/tasks-runner/hasher.ts @@ -53,6 +53,8 @@ export class Hasher { } export class ProjectHashes { + private sourceHashes: { [projectName: string]: Promise } = {}; + constructor( private readonly projectGraph: ProjectGraph, private readonly fileHashes: FileHashes @@ -60,10 +62,15 @@ export class ProjectHashes { 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])); @@ -71,11 +78,16 @@ export class ProjectHashes { } 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]; } } diff --git a/scripts/e2e-ci1.sh b/scripts/e2e-ci1.sh index 7784768c628c4..0dbc0edfead4a 100755 --- a/scripts/e2e-ci1.sh +++ b/scripts/e2e-ci1.sh @@ -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 diff --git a/scripts/e2e-ci2.sh b/scripts/e2e-ci2.sh index 902c6ccb7b950..9b3b530b8d1bc 100755 --- a/scripts/e2e-ci2.sh +++ b/scripts/e2e-ci2.sh @@ -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 && diff --git a/scripts/e2e-ci3.sh b/scripts/e2e-ci3.sh index 6879b686a2bfc..23d9ed1fe8624 100755 --- a/scripts/e2e-ci3.sh +++ b/scripts/e2e-ci3.sh @@ -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 && diff --git a/scripts/e2e-ci4.sh b/scripts/e2e-ci4.sh index af83d0cfc38a8..22abc155e7723 100755 --- a/scripts/e2e-ci4.sh +++ b/scripts/e2e-ci4.sh @@ -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 &&