Skip to content

Commit

Permalink
fix(core): sort objects when hashing them instead
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Aug 30, 2023
1 parent 7e50274 commit 72e8f99
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 1 addition & 6 deletions e2e/nx-run/src/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,7 @@ describe('cache', () => {
'read the output from the cache'
);

if (process.platform != 'linux') {
// TODO(vsavkin): This should be always be matched output once you fix output watching on linux
expectMatchedOutput(outputWithBuildApp2Cached, [myapp2]);
} else {
expectCached(outputWithBuildApp2Cached, [myapp2]);
}
expectCached(outputWithBuildApp2Cached, [myapp2]);

// touch package.json
// --------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions packages/nx/src/hasher/file-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ export function hashArray(content: string[]): string {
const { hashArray } = require('../native');
return hashArray(content);
}

export function hashObject(obj: object): string {
const { hashArray } = require('../native');
const parts: string[] = [];

for (const key of Object.keys(obj).sort()) {
parts.push(key);
parts.push(JSON.stringify(obj[key]));
}

return hashArray(parts);
}
4 changes: 2 additions & 2 deletions packages/nx/src/hasher/task-hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { hashTsConfig } from '../plugins/js/hasher/hasher';
import { DaemonClient } from '../daemon/client/client';
import { createProjectRootMappings } from '../project-graph/utils/find-project-for-path';
import { findMatchingProjects } from '../utils/find-matching-projects';
import { FileHasher, hashArray } from './file-hasher';
import { FileHasher, hashArray, hashObject } from './file-hasher';
import { getOutputsForTargetAndConfiguration } from '../tasks-runner/utils';
import { getHashEnv } from './set-hash-env';
import { workspaceRoot } from '../utils/workspace-root';
Expand Down Expand Up @@ -539,7 +539,7 @@ class TaskHasherImpl {
if (this.allExternalDependenciesHash) {
return this.allExternalDependenciesHash;
} else {
hash = hashArray([JSON.stringify(this.projectGraph.externalNodes)]);
hash = hashObject(this.projectGraph.externalNodes);
this.allExternalDependenciesHash = {
value: hash,
details: {
Expand Down

0 comments on commit 72e8f99

Please sign in to comment.