From ec090643602f16155bf3654031395abbf177cb27 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 | 160 +++++++++++------- packages/nx/src/hasher/file-hasher.ts | 6 - packages/nx/src/hasher/task-hasher.spec.ts | 3 +- packages/nx/src/hasher/task-hasher.ts | 58 +++++-- packages/nx/src/plugins/js/hasher/hasher.ts | 4 +- 5 files changed, 146 insertions(+), 85 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..07a0892d22b3f1 100644 --- a/packages/nx/src/hasher/__snapshots__/task-hasher.spec.ts.snap +++ b/packages/nx/src/hasher/__snapshots__/task-hasher.spec.ts.snap @@ -6,17 +6,19 @@ exports[`TaskHasher dependentTasksOutputFiles should depend on dependent tasks o "command": "4062279404379299270", "implicitDeps": {}, "nodes": { + "ProjectConfiguration": "12802727827024321009", + "TsConfig": "8767608672024750088", "dist/libs/child/index.d.ts": "3244421341483603138", "dist/libs/grandchild/index.d.ts": "3244421341483603138", - "parent:!{projectRoot}/**/*.spec.ts": "5565329748974231692", - "target": "nx:run-commands", + "parent:!{projectRoot}/**/*.spec.ts": "17962802443644575456", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "13050024388944273054", + "value": "17939200785615949974", } `; @@ -26,17 +28,19 @@ exports[`TaskHasher dependentTasksOutputFiles should work with dependent tasks w "command": "4062279404379299270", "implicitDeps": {}, "nodes": { + "ProjectConfiguration": "12802727827024321009", + "TsConfig": "8767608672024750088", "dist/libs/child/index.d.ts": "3244421341483603138", "dist/libs/grandchild/index.d.ts": "3244421341483603138", - "parent:!{projectRoot}/**/*.spec.ts": "5565329748974231692", - "target": "nx:run-commands", + "parent:!{projectRoot}/**/*.spec.ts": "17962802443644575456", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "13050024388944273054", + "value": "17939200785615949974", } `; @@ -46,15 +50,17 @@ exports[`TaskHasher hashTarget should hash entire subtree of dependencies 1`] = "command": "14389236043839781668", "implicitDeps": {}, "nodes": { - "app:{projectRoot}/**/*": "3487729839153061713", - "target": "@nx/webpack:webpack", + "ProjectConfiguration": "12026883044296863450", + "TsConfig": "8767608672024750088", + "app:{projectRoot}/**/*": "3244421341483603138", + "target": "3789300870433976270", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "10939456376142768975", + "value": "11829832011053499600", } `; @@ -64,15 +70,17 @@ exports[`TaskHasher hashTarget should hash executor dependencies of @nx packages "command": "14389236043839781668", "implicitDeps": {}, "nodes": { - "app:{projectRoot}/**/*": "3487729839153061713", - "target": "@nx/webpack:webpack", + "ProjectConfiguration": "12026883044296863450", + "TsConfig": "8767608672024750088", + "app:{projectRoot}/**/*": "3244421341483603138", + "target": "1274004356858584726", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "16749739796062259876", + "value": "15096054768893599383", } `; @@ -82,16 +90,18 @@ exports[`TaskHasher hashTarget should use externalDependencies to override nx:ru "command": "14389236043839781668", "implicitDeps": {}, "nodes": { - "app:{projectRoot}/**/*": "6954787296030520675", + "ProjectConfiguration": "17956886683554891195", + "TsConfig": "8767608672024750088", + "app:{projectRoot}/**/*": "3244421341483603138", "env:undefined": "3244421341483603138", - "target": "nx:run-commands", + "target": "7688798210438770308", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "10722281392353641974", + "value": "18142315317355318287", } `; @@ -101,16 +111,18 @@ exports[`TaskHasher hashTarget should use externalDependencies with empty array "command": "14389236043839781668", "implicitDeps": {}, "nodes": { - "app:{projectRoot}/**/*": "10888929985620786238", + "ProjectConfiguration": "9179552940021403596", + "TsConfig": "8767608672024750088", + "app:{projectRoot}/**/*": "3244421341483603138", "env:undefined": "3244421341483603138", - "target": "nx:run-commands", + "target": "3244421341483603138", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "9711139740831088556", + "value": "13520777692097937224", } `; @@ -120,10 +132,12 @@ exports[`TaskHasher should be able to handle multiple filesets per project 1`] = "command": "13785966310271077209", "implicitDeps": {}, "nodes": { - "child:!{projectRoot}/**/*.spec.ts": "13192523093445129776", + "ProjectConfiguration": "17211930887387929067", + "TsConfig": "8767608672024750088", + "child:!{projectRoot}/**/*.spec.ts": "17508782620731849000", "env:MY_TEST_HASH_ENV": "17357374746554314488", - "parent:{projectRoot}/**/*": "1629399803746755886", - "target": "nx:run-commands", + "parent:{projectRoot}/**/*": "7263479247245830838", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/global1": "3052102066027208710", @@ -132,7 +146,7 @@ exports[`TaskHasher should be able to handle multiple filesets per project 1`] = }, "runtime": {}, }, - "value": "12260754209046637944", + "value": "2881231822394274502", } `; @@ -142,17 +156,19 @@ exports[`TaskHasher should be able to include only a part of the base tsconfig 1 "command": "4062279404379299270", "implicitDeps": {}, "nodes": { - "parent:{projectRoot}/**/*": "16516751231904189589", + "ProjectConfiguration": "18166168584521190546", + "TsConfig": "4035819825874039301", + "parent:{projectRoot}/**/*": "8263681721738113012", "runtime:echo runtime123": "runtime123", "runtime:echo runtime456": "runtime456", - "target": "nx:run-commands", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "2948361542445522019", + "value": "9968611270204908917", } `; @@ -162,21 +178,23 @@ exports[`TaskHasher should create task hash 1`] = ` "command": "4062279404379299270", "implicitDeps": {}, "nodes": { + "ProjectConfiguration": "4875698716044094030", + "TsConfig": "8767608672024750088", "env:NONEXISTENTENV": "3244421341483603138", "env:TESTENV": "6544740722075256274", - "parent:{projectRoot}/**/*": "631071291822994098", + "parent:{projectRoot}/**/*": "8263681721738113012", "runtime:echo runtime123": "runtime123", "runtime:echo runtime456": "runtime456", - "tagged:{projectRoot}/**/*": "17111161286736679711", - "target": "nx:run-commands", - "unrelated:{projectRoot}/**/*": "8969690012466582257", + "tagged:{projectRoot}/**/*": "3244421341483603138", + "target": "1389868326933519382", + "unrelated:{projectRoot}/**/*": "10091615118977982257", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "3344547189263615580", + "value": "11412486534571442418", } `; @@ -186,15 +204,17 @@ exports[`TaskHasher should hash multiple filesets of a project 1`] = ` "command": "13785966310271077209", "implicitDeps": {}, "nodes": { - "parent:{projectRoot}/**/*": "17414698243987989547", - "target": "nx:run-commands", + "ProjectConfiguration": "10499856664466672714", + "TsConfig": "8767608672024750088", + "parent:{projectRoot}/**/*": "7263479247245830838", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "16502280644049848992", + "value": "14016847448680534278", } `; @@ -204,15 +224,17 @@ exports[`TaskHasher should hash multiple filesets of a project 2`] = ` "command": "4062279404379299270", "implicitDeps": {}, "nodes": { - "parent:!{projectRoot}/**/*.spec.ts": "7424658468918726082", - "target": "nx:run-commands", + "ProjectConfiguration": "10499856664466672714", + "TsConfig": "8767608672024750088", + "parent:!{projectRoot}/**/*.spec.ts": "17962802443644575456", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "6969083987792918940", + "value": "10694393160053318712", } `; @@ -222,16 +244,18 @@ exports[`TaskHasher should hash non-default filesets 1`] = ` "command": "4062279404379299270", "implicitDeps": {}, "nodes": { - "child:{projectRoot}/**/*": "10025338539010063012", - "parent:!{projectRoot}/**/*.spec.ts": "5593646567034593596", - "target": "nx:run-commands", + "ProjectConfiguration": "8196293273405506196", + "TsConfig": "8767608672024750088", + "child:{projectRoot}/**/*": "2300207741412661544", + "parent:!{projectRoot}/**/*.spec.ts": "17962802443644575456", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "10748517083069163130", + "value": "15803865862737990375", } `; @@ -241,16 +265,18 @@ exports[`TaskHasher should hash npm project versions 1`] = ` "command": "14389236043839781668", "implicitDeps": {}, "nodes": { - "app:{projectRoot}/**/*": "6028445962839227139", + "ProjectConfiguration": "8128657069648957137", + "TsConfig": "8767608672024750088", + "app:{projectRoot}/**/*": "9104199730100321982", "npm:react": "4468841026152585217", - "target": "nx:run-commands", + "target": "14358315432887000841", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "4145517376831960669", + "value": "3668827038634092448", } `; @@ -260,16 +286,18 @@ exports[`TaskHasher should hash task where the project has dependencies 1`] = ` "command": "4062279404379299270", "implicitDeps": {}, "nodes": { - "child:{projectRoot}/**/*": "17112515743513902619", - "parent:{projectRoot}/**/*": "8668996094612916300", - "target": "unknown", + "ProjectConfiguration": "8876282510060012181", + "TsConfig": "8767608672024750088", + "child:{projectRoot}/**/*": "5484012818475684626", + "parent:{projectRoot}/**/*": "14822394489351823627", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "9463228934259887792", + "value": "16888277333405079717", } `; @@ -279,16 +307,18 @@ exports[`TaskHasher should hash tasks where the project graph has circular depen "command": "4062279404379299270", "implicitDeps": {}, "nodes": { - "child:{projectRoot}/**/*": "13387017594662756393", - "parent:{projectRoot}/**/*": "3042098164316823883", - "target": "nx:run-commands", + "ProjectConfiguration": "9892649345820140726", + "TsConfig": "8767608672024750088", + "child:{projectRoot}/**/*": "8973015561538144423", + "parent:{projectRoot}/**/*": "9104199730100321982", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "17851309464404299797", + "value": "16567132351487630958", } `; @@ -298,16 +328,18 @@ exports[`TaskHasher should hash tasks where the project graph has circular depen "command": "7833005669885463868", "implicitDeps": {}, "nodes": { - "child:{projectRoot}/**/*": "13387017594662756393", - "parent:{projectRoot}/**/*": "3042098164316823883", - "target": "nx:run-commands", + "ProjectConfiguration": "18166168584521190546", + "TsConfig": "8767608672024750088", + "child:{projectRoot}/**/*": "8973015561538144423", + "parent:{projectRoot}/**/*": "9104199730100321982", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "4621307928388816676", + "value": "13014058586283814178", } `; @@ -317,8 +349,10 @@ exports[`TaskHasher should use targetDefaults from nx.json 1`] = ` "command": "6958627266354933907", "implicitDeps": {}, "nodes": { - "child:{projectRoot}/**/*": "9791796197297932260", - "target": "nx:run-commands", + "ProjectConfiguration": "17211930887387929067", + "TsConfig": "8767608672024750088", + "child:{projectRoot}/**/*": "2300207741412661544", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/global1": "3052102066027208710", @@ -326,7 +360,7 @@ exports[`TaskHasher should use targetDefaults from nx.json 1`] = ` }, "runtime": {}, }, - "value": "1795731262495053190", + "value": "3952879073081711415", } `; @@ -336,15 +370,17 @@ exports[`TaskHasher should use targetDefaults from nx.json 2`] = ` "command": "4062279404379299270", "implicitDeps": {}, "nodes": { - "child:!{projectRoot}/**/*.spec.ts": "6347155939449237455", - "parent:!{projectRoot}/**/*.spec.ts": "8912386769891259211", - "target": "nx:run-commands", + "ProjectConfiguration": "9892649345820140726", + "TsConfig": "8767608672024750088", + "child:!{projectRoot}/**/*.spec.ts": "17508782620731849000", + "parent:!{projectRoot}/**/*.spec.ts": "17962802443644575456", + "target": "1389868326933519382", "{workspaceRoot}/.gitignore": "3244421341483603138", "{workspaceRoot}/.nxignore": "3244421341483603138", "{workspaceRoot}/nx.json": "8942239360311677987", }, "runtime": {}, }, - "value": "16490883615640042532", + "value": "2743377369761868812", } `; diff --git a/packages/nx/src/hasher/file-hasher.ts b/packages/nx/src/hasher/file-hasher.ts index ffe8224b67cbd8..8c5a8936e5fd0d 100644 --- a/packages/nx/src/hasher/file-hasher.ts +++ b/packages/nx/src/hasher/file-hasher.ts @@ -28,12 +28,6 @@ export class FileHasher { 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); - } - clear(): void { this.fileHashes = new Map(); this.isInitialized = false; diff --git a/packages/nx/src/hasher/task-hasher.spec.ts b/packages/nx/src/hasher/task-hasher.spec.ts index e917b2f8533efc..b265f3c8f80746 100644 --- a/packages/nx/src/hasher/task-hasher.spec.ts +++ b/packages/nx/src/hasher/task-hasher.spec.ts @@ -1184,8 +1184,7 @@ describe('TaskHasher', () => { overrides: { prop: 'prop-value' }, }); - expect(hash.value).not.toContain('|16.0.0|'); - expect(hash.details.nodes['target']).toEqual('nx:run-commands'); + expect(hash.details.nodes['target']).toEqual('13019111166724682201'); }); it('should use externalDependencies to override nx:run-commands', async () => { diff --git a/packages/nx/src/hasher/task-hasher.ts b/packages/nx/src/hasher/task-hasher.ts index b6a60f7bd003f9..4c2ab697c2b38a 100644 --- a/packages/nx/src/hasher/task-hasher.ts +++ b/packages/nx/src/hasher/task-hasher.ts @@ -160,6 +160,13 @@ export class InProcessTaskHasher implements TaskHasher { sortedOverrides[k] = overrides[k]; } + console.log([ + task.target.project ?? '', + task.target.target ?? '', + task.target.configuration ?? '', + JSON.stringify(sortedOverrides), + ]); + return hashArray([ task.target.project ?? '', task.target.target ?? '', @@ -285,7 +292,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) { @@ -536,7 +543,7 @@ class TaskHasherImpl { return { value: hash, details: { - target: target.executor, + target: hash, }, }; } @@ -603,6 +610,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 +623,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 +676,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 +716,12 @@ 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 files: string[] = []; + for (const { file, hash } of filteredFiles) { + files.push(file, hash); + } + + const value = hashArray(files); res({ value, details: { [mapKey]: value }, diff --git a/packages/nx/src/plugins/js/hasher/hasher.ts b/packages/nx/src/plugins/js/hasher/hasher.ts index 3d443290280fc8..57f03aa939d86d 100644 --- a/packages/nx/src/plugins/js/hasher/hasher.ts +++ b/packages/nx/src/plugins/js/hasher/hasher.ts @@ -1,6 +1,6 @@ import { ProjectGraphProjectNode } from '../../../config/project-graph'; import { readJsonFile } from '../../../utils/fileutils'; -import { getRootTsConfigFileName } from '../utils/typescript'; +import { getRootTsConfigPath } from '../utils/typescript'; import { findProjectForPath, ProjectRootMappings, @@ -16,7 +16,7 @@ interface TsconfigJsonConfiguration { function readTsConfigJson(): TsconfigJsonConfiguration { try { - const res = readJsonFile(getRootTsConfigFileName()); + const res = readJsonFile(getRootTsConfigPath()); res.compilerOptions.paths ??= {}; return res; } catch {