From 0d695922c71b414c7b74dfc5dbe7b982e6c95d35 Mon Sep 17 00:00:00 2001 From: FrozenPandaz Date: Wed, 26 Jul 2023 18:38:07 -0400 Subject: [PATCH] chore(core): wip --- .../__snapshots__/task-hasher.spec.ts.snap | 10 ++-- packages/nx/src/hasher/file-hasher.ts | 10 ++-- packages/nx/src/hasher/task-hasher.ts | 46 ++++++++++++++----- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/packages/nx/src/hasher/__snapshots__/task-hasher.spec.ts.snap b/packages/nx/src/hasher/__snapshots__/task-hasher.spec.ts.snap index c96439446f5794..c2a32809f4273b 100644 --- a/packages/nx/src/hasher/__snapshots__/task-hasher.spec.ts.snap +++ b/packages/nx/src/hasher/__snapshots__/task-hasher.spec.ts.snap @@ -162,21 +162,23 @@ exports[`TaskHasher should create task hash 1`] = ` "command": "4062279404379299270", "implicitDeps": {}, "nodes": { + "ProjectConfiguration": "4875698716044094030", + "TsConfig": "11890780659593595785", "env:NONEXISTENTENV": "3244421341483603138", "env:TESTENV": "6544740722075256274", - "parent:{projectRoot}/**/*": "631071291822994098", + "parent:{projectRoot}/**/*": "13399504445655626779", "runtime:echo runtime123": "runtime123", "runtime:echo runtime456": "runtime456", - "tagged:{projectRoot}/**/*": "17111161286736679711", + "tagged:{projectRoot}/**/*": "3244421341483603138", "target": "nx:run-commands", - "unrelated:{projectRoot}/**/*": "8969690012466582257", + "unrelated:{projectRoot}/**/*": "6381484071003365310", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "3344547189263615580", + "value": "11780781306264278688", } `; diff --git a/packages/nx/src/hasher/file-hasher.ts b/packages/nx/src/hasher/file-hasher.ts index ffe8224b67cbd8..561ab06e6aa786 100644 --- a/packages/nx/src/hasher/file-hasher.ts +++ b/packages/nx/src/hasher/file-hasher.ts @@ -25,13 +25,9 @@ export class FileHasher { hashFile(path: string): string { // Import as needed. There is also an issue running unit tests in Nx repo if this is a top-level import. const { hashFile } = require('../native'); - return hashFile(path).hash; - } - - hashFilesMatchingGlobs(path: string, globs: string[]): string { - // Import as needed. There is also an issue running unit tests in Nx repo if this is a top-level import. - const { hashFilesMatchingGlobs } = require('../native'); - return hashFilesMatchingGlobs(path, globs); + const res = hashFile(path).hash; + console.log(path, 'hash:', res); + return res; } clear(): void { diff --git a/packages/nx/src/hasher/task-hasher.ts b/packages/nx/src/hasher/task-hasher.ts index b6a60f7bd003f9..ad1bc46c592af9 100644 --- a/packages/nx/src/hasher/task-hasher.ts +++ b/packages/nx/src/hasher/task-hasher.ts @@ -285,7 +285,7 @@ class TaskHasherImpl { visited ); const depsOut = await this.hashDepsOutputs(task, depsOutputs); - const projects = await this.hashProjectInputs(projectInputs, visited); + const projects = await this.hashProjectInputs(projectInputs); let details = {}; for (const s of self) { @@ -603,6 +603,8 @@ class TaskHasherImpl { const notFilesets = inputs.filter((r) => !r['fileset']); return Promise.all([ this.hashProjectFileset(projectName, projectFilesets), + this.hashProjectConfig(projectName), + this.hashTsConfig(projectName), ...[ ...workspaceFilesets, ...this.legacyFilesetInputs.map((r) => r.fileset), @@ -614,8 +616,7 @@ class TaskHasherImpl { } private async hashProjectInputs( - projectInputs: { input: string; projects: string[] }[], - visited: string[] + projectInputs: { input: string; projects: string[] }[] ): Promise { const partialHashes: Promise[] = []; for (const input of projectInputs) { @@ -668,6 +669,33 @@ class TaskHasherImpl { return this.filesetHashes[mapKey]; } + private hashProjectConfig(projectName: string): PartialHash { + const p = this.projectGraph.nodes[projectName]; + const projectConfig = hashArray([ + JSON.stringify({ ...p.data, files: undefined }), + ]); + + return { + value: projectConfig, + details: { + ProjectConfiguration: projectConfig, + }, + }; + } + + private hashTsConfig(projectName: string): PartialHash { + const p = this.projectGraph.nodes[projectName]; + const tsConfig = hashArray([ + hashTsConfig(p, this.projectRootMappings, this.options), + ]); + return { + value: tsConfig, + details: { + TsConfig: tsConfig, + }, + }; + } + private async hashProjectFileset( projectName: string, filesetPatterns: string[] @@ -681,15 +709,9 @@ class TaskHasherImpl { this.projectFileMap[projectName] || [], filesetPatterns ); - const fileNames = filteredFiles.map((f) => f.file); - const values = filteredFiles.map((f) => f.hash); - - const value = hashArray([ - ...fileNames, - ...values, - JSON.stringify({ ...p.data, files: undefined }), - hashTsConfig(p, this.projectRootMappings, this.options), - ]); + const fileHashes = filteredFiles.map((f) => f.hash); + + const value = hashArray(fileHashes); res({ value, details: { [mapKey]: value },