Skip to content

Commit 34edc26

Browse files
Copilotdmichon-msfticlanton
authored
Relativize outFolderName paths in TypeScript cache hash computation (#5533)
* Initial plan * Fix non-portable hash computation by relativizing outFolderName paths and using base64url encoding Co-authored-by: dmichon-msft <[email protected]> * Fix: Use empty array instead of empty object as fallback for normalizedConfig Co-authored-by: dmichon-msft <[email protected]> * Normalize path separators to forward slashes in hash computation Co-authored-by: dmichon-msft <[email protected]> * Add changelog entry for cache hash portability fix Co-authored-by: iclanton <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: dmichon-msft <[email protected]> Co-authored-by: iclanton <[email protected]>
1 parent f4a4076 commit 34edc26

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-typescript-plugin",
5+
"comment": "Fix TypeScript build cache hash computation to use relative paths with normalized separators for portability across machines and platforms",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-typescript-plugin",
10+
"email": "[email protected]"
11+
}

heft-plugins/heft-typescript-plugin/src/TypeScriptBuilder.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {
1717
IExtendedSolutionBuilder,
1818
ITypeScriptNodeSystem
1919
} from './internalTypings/TypeScriptInternals';
20-
import type { ITypeScriptConfigurationJson } from './TypeScriptPlugin';
20+
import type { ITypeScriptConfigurationJson, IEmitModuleKind } from './TypeScriptPlugin';
2121
import type { PerformanceMeasurer } from './Performance';
2222
import type {
2323
ICachedEmitModuleKind,
@@ -152,12 +152,17 @@ export class TypeScriptBuilder {
152152
// We only need to hash our additional Heft configuration.
153153
const configHash: crypto.Hash = crypto.createHash('sha1');
154154

155-
configHash.update(JSON.stringify(this._configuration.additionalModuleKindsToEmit || {}));
156-
const serializedConfigHash: string = configHash
157-
.digest('base64')
158-
.slice(0, 8)
159-
.replace(/\+/g, '-')
160-
.replace(/\//g, '_');
155+
// Relativize the outFolderName paths before hashing to ensure portability across different machines
156+
const normalizedConfig: IEmitModuleKind[] =
157+
this._configuration.additionalModuleKindsToEmit?.map((emitKind) => ({
158+
...emitKind,
159+
outFolderName: Path.convertToSlashes(
160+
path.relative(this._configuration.buildFolderPath, emitKind.outFolderName)
161+
)
162+
})) || [];
163+
164+
configHash.update(JSON.stringify(normalizedConfig));
165+
const serializedConfigHash: string = configHash.digest('base64url').slice(0, 8);
161166

162167
// This conversion is theoretically redundant, but it is here to make absolutely sure that the path is formatted
163168
// using only '/' as the directory separator so that incremental builds don't break on Windows.

0 commit comments

Comments
 (0)