Skip to content

Commit

Permalink
chore(core): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jul 27, 2023
1 parent 4a2985f commit 0d69592
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
10 changes: 6 additions & 4 deletions packages/nx/src/hasher/__snapshots__/task-hasher.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
`;

Expand Down
10 changes: 3 additions & 7 deletions packages/nx/src/hasher/file-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
46 changes: 34 additions & 12 deletions packages/nx/src/hasher/task-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand All @@ -614,8 +616,7 @@ class TaskHasherImpl {
}

private async hashProjectInputs(
projectInputs: { input: string; projects: string[] }[],
visited: string[]
projectInputs: { input: string; projects: string[] }[]
): Promise<PartialHash[]> {
const partialHashes: Promise<PartialHash[]>[] = [];
for (const input of projectInputs) {
Expand Down Expand Up @@ -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[]
Expand All @@ -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 },
Expand Down

0 comments on commit 0d69592

Please sign in to comment.