diff --git a/packages/nx/src/core/hasher/file-hasher-base.ts b/packages/nx/src/core/hasher/file-hasher-base.ts index 59609de064aeb9..4db6e3bedd062c 100644 --- a/packages/nx/src/core/hasher/file-hasher-base.ts +++ b/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; @@ -61,16 +61,19 @@ 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 normalizedWorkspaceRoot = normalizePath(workspaceRoot); + const relativePath = normalizePath( + path.startsWith(normalizedWorkspaceRoot) + ? path.substring(normalizedWorkspaceRoot.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(normalizedWorkspaceRoot, relativePath) ); } catch { return ''; diff --git a/packages/nx/src/core/hasher/node-based-file-hasher.ts b/packages/nx/src/core/hasher/node-based-file-hasher.ts index c8cea4161ecdcc..0740bb7e937fe3 100644 --- a/packages/nx/src/core/hasher/node-based-file-hasher.ts +++ b/packages/nx/src/core/hasher/node-based-file-hasher.ts @@ -6,6 +6,7 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'fs'; import { FileHasherBase } from './file-hasher-base'; import { stripIndents } from '../../utils/strip-indents'; import ignore from 'ignore'; +import { normalizePath } from 'nx/src/utils/path'; export class NodeBasedFileHasher extends FileHasherBase { ignoredGlobs = getIgnoredGlobs(); @@ -43,7 +44,7 @@ export class NodeBasedFileHasher extends FileHasherBase { try { readdirSync(absoluteDirName).forEach((c) => { const absoluteChild = join(absoluteDirName, c); - const relChild = relative(appRootPath, absoluteChild); + const relChild = normalizePath(relative(appRootPath, absoluteChild)); if (this.ignoredGlobs.ignores(relChild)) { return; }