Skip to content

Commit

Permalink
fix(core): normalize file path for node-hasher
Browse files Browse the repository at this point in the history
Node hasher paths need to be normalized, since on windows they return with '\' instead of '/' and don't match keys in workspace configuration.

Fixes #9584
Fixes #9581
  • Loading branch information
AgentEnder committed Mar 29, 2022
1 parent 0ad3eb3 commit 07ad60e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/nx/src/core/hasher/file-hasher-base.ts
@@ -1,8 +1,8 @@
import { appRootPath } from 'nx/src/utils/app-root';
import { workspaceRoot } from 'nx/src/utils/app-root';
import { performance } from 'perf_hooks';
import { defaultHashing } from './hashing-impl';
import { FileData } from 'nx/src/shared/project-graph';
import { joinPathFragments } from 'nx/src/utils/path';
import { joinPathFragments, normalizePath } from 'nx/src/utils/path';

export abstract class FileHasherBase {
protected fileHashes: Map<string, string>;
Expand Down Expand Up @@ -61,16 +61,18 @@ export abstract class FileHasherBase {
if (!this.fileHashes) {
throw new Error('FileHasher is invoked before being initialized');
}
const relativePath = path.startsWith(appRootPath)
? path.substr(appRootPath.length + 1)
: path;
const relativePath = normalizePath(
path.startsWith(workspaceRoot)
? path.substring(workspaceRoot.length + 1)
: path
);
if (this.fileHashes.has(relativePath)) {
return this.fileHashes.get(relativePath);
} else {
try {
// this has to be absolute to avoid issues with cwd
return defaultHashing.hashFile(
joinPathFragments(appRootPath, relativePath)
joinPathFragments(workspaceRoot, relativePath)
);
} catch {
return '';
Expand Down

0 comments on commit 07ad60e

Please sign in to comment.