Skip to content

Commit

Permalink
fix(core): store relative file name in hash details
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed May 23, 2022
1 parent 664df0e commit 5692722
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
5 changes: 5 additions & 0 deletions packages/nx/src/hasher/hasher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This must come before the Hasher import
import { DependencyType } from '../config/project-graph';
import { defaultFileHasher } from '../hasher/file-hasher';

jest.doMock('../utils/app-root', () => {
return {
Expand Down Expand Up @@ -56,6 +57,10 @@ describe('Hasher', () => {
}

beforeAll(() => {
jest
.spyOn(defaultFileHasher, 'hashFile')
.mockImplementation((p) => hashes[p]);

fs.readFileSync = (file) => {
if (file === 'workspace.json') {
return JSON.stringify(workSpaceJson);
Expand Down
21 changes: 6 additions & 15 deletions packages/nx/src/hasher/hasher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { resolveNewFormatWithInlineProjects } from '../config/workspaces';
import { exec } from 'child_process';
import { existsSync } from 'fs';
import * as minimatch from 'minimatch';
import { join } from 'path';
import { join, sep as pathSep } from 'path';
import { performance } from 'perf_hooks';
import { getRootTsConfigFileName } from '../utils/typescript';
import { workspaceRoot } from '../utils/app-root';
Expand All @@ -13,6 +13,7 @@ import { NxJsonConfiguration } from '../config/nx-json';
import { Task } from '../config/task-graph';
import { readJsonFile } from '../utils/fileutils';
import { WorkspaceJsonConfiguration } from '../config/workspace-json-project-json';
import { defaultFileHasher } from './file-hasher';

/**
* A data structure returned by the default hasher.
Expand Down Expand Up @@ -213,6 +214,9 @@ export class Hasher {

performance.mark('hasher:implicit deps hash:start');

const fileHasher = defaultFileHasher;
await fileHasher.ensureInitialized();

this.implicitDependencies = new Promise((res) => {
const implicitDeps = Object.keys(this.nxJson.implicitDependencies ?? {});
const filesWithoutPatterns = implicitDeps.filter(
Expand Down Expand Up @@ -244,20 +248,7 @@ export class Hasher {
];

const fileHashes = [
...fileNames
.map((maybeRelativePath) => {
// Normalize the path to always be absolute and starting with workspaceRoot so we can check it exists
if (!maybeRelativePath.startsWith(workspaceRoot)) {
return join(workspaceRoot, maybeRelativePath);
}
return maybeRelativePath;
})
.filter((file) => existsSync(file))
.map((file) => {
// we should use default file hasher here
const hash = this.hashing.hashFile(file);
return { file, hash };
}),
...fileNames.map((file) => ({ file, hash: fileHasher.hashFile(file) })),
...this.hashNxJson(),
];

Expand Down

0 comments on commit 5692722

Please sign in to comment.