Skip to content

Commit 9faafe5

Browse files
authored
fix(js): normalize paths correctly in @nx/js/typescript plugin (#30216)
## Current Behavior The tsconfig files cache contains invalid relative paths when run on Windows. Failure logs (Windows): https://github.com/nrwl/nx-console/actions/runs/13573129754/job/37942898562?pr=2415#step:11:29 ## Expected Behavior The tsconfig files cache should contain valid Unix-based paths. Success logs (Windows): https://github.com/nrwl/nx-console/actions/runs/13586015039/job/37981054104#step:11:49 (the job failed but due to a separate thing, note the project graph was computed correctly) ## Related Issue(s) Fixes #
1 parent 30f5a52 commit 9faafe5

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

packages/js/src/plugins/typescript/plugin.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ function isExternalProjectReference(
10321032
workspaceRoot: string,
10331033
projectRoot: string
10341034
): boolean {
1035-
const relativePath = posix.relative(workspaceRoot, refTsConfigPath);
1035+
const relativePath = posixRelative(workspaceRoot, refTsConfigPath);
10361036
if (cache.isExternalProjectReference[relativePath] !== undefined) {
10371037
return cache.isExternalProjectReference[relativePath];
10381038
}
@@ -1074,7 +1074,7 @@ function retrieveTsConfigFromCache(
10741074
tsConfigPath: string,
10751075
workspaceRoot: string
10761076
): ParsedTsconfigData {
1077-
const relativePath = posix.relative(workspaceRoot, tsConfigPath);
1077+
const relativePath = posixRelative(workspaceRoot, tsConfigPath);
10781078

10791079
// we don't need to check the hash if it's in the cache, because we've already
10801080
// checked it when we initially populated the cache
@@ -1103,7 +1103,7 @@ function readTsConfigAndCache(
11031103
tsConfigPath: string,
11041104
workspaceRoot: string
11051105
): ParsedTsconfigData {
1106-
const relativePath = posix.relative(workspaceRoot, tsConfigPath);
1106+
const relativePath = posixRelative(workspaceRoot, tsConfigPath);
11071107
const hash = getFileHash(tsConfigPath, workspaceRoot);
11081108

11091109
let extendedFilesHash: string;
@@ -1261,7 +1261,7 @@ function resolveExtendedTsConfigPath(
12611261
}
12621262

12631263
function getFileHash(filePath: string, workspaceRoot: string): string {
1264-
const relativePath = posix.relative(workspaceRoot, filePath);
1264+
const relativePath = posixRelative(workspaceRoot, filePath);
12651265
if (!cache.fileHashes[relativePath]) {
12661266
const content = readFile(filePath, workspaceRoot);
12671267
cache.fileHashes[relativePath] = hashArray([content]);
@@ -1271,7 +1271,7 @@ function getFileHash(filePath: string, workspaceRoot: string): string {
12711271
}
12721272

12731273
function readFile(filePath: string, workspaceRoot: string): string {
1274-
const relativePath = posix.relative(workspaceRoot, filePath);
1274+
const relativePath = posixRelative(workspaceRoot, filePath);
12751275
if (!cache.rawFiles[relativePath]) {
12761276
const content = readFileSync(filePath, 'utf8');
12771277
cache.rawFiles[relativePath] = content;
@@ -1353,41 +1353,48 @@ function toRelativePaths(
13531353
hash,
13541354
};
13551355
if (data.options.rootDir) {
1356-
updatedCache[key].data.options.rootDir = posix.relative(
1356+
updatedCache[key].data.options.rootDir = posixRelative(
13571357
workspaceRoot,
13581358
data.options.rootDir
13591359
);
13601360
}
13611361
if (data.options.outDir) {
1362-
updatedCache[key].data.options.outDir = posix.relative(
1362+
updatedCache[key].data.options.outDir = posixRelative(
13631363
workspaceRoot,
13641364
data.options.outDir
13651365
);
13661366
}
13671367
if (data.options.outFile) {
1368-
updatedCache[key].data.options.outFile = posix.relative(
1368+
updatedCache[key].data.options.outFile = posixRelative(
13691369
workspaceRoot,
13701370
data.options.outFile
13711371
);
13721372
}
13731373
if (data.options.tsBuildInfoFile) {
1374-
updatedCache[key].data.options.tsBuildInfoFile = posix.relative(
1374+
updatedCache[key].data.options.tsBuildInfoFile = posixRelative(
13751375
workspaceRoot,
13761376
data.options.tsBuildInfoFile
13771377
);
13781378
}
13791379
if (data.extendedConfigFile?.filePath) {
1380-
updatedCache[key].data.extendedConfigFile.filePath = posix.relative(
1380+
updatedCache[key].data.extendedConfigFile.filePath = posixRelative(
13811381
workspaceRoot,
13821382
data.extendedConfigFile.filePath
13831383
);
13841384
}
13851385
if (data.projectReferences) {
13861386
updatedCache[key].data.projectReferences = data.projectReferences.map(
1387-
(ref) => ({ ...ref, path: posix.relative(workspaceRoot, ref.path) })
1387+
(ref) => ({
1388+
...ref,
1389+
path: posixRelative(workspaceRoot, ref.path),
1390+
})
13881391
);
13891392
}
13901393
}
13911394

13921395
return updatedCache;
13931396
}
1397+
1398+
function posixRelative(workspaceRoot: string, path: string): string {
1399+
return posix.normalize(relative(workspaceRoot, path));
1400+
}

0 commit comments

Comments
 (0)