Skip to content

Commit f230cf6

Browse files
Copilotdmichon-msft
andcommitted
Fix non-portable hash computation by relativizing outFolderName paths and using base64url encoding
Co-authored-by: dmichon-msft <26827560+dmichon-msft@users.noreply.github.com>
1 parent 9f8e639 commit f230cf6

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

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

Lines changed: 10 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,15 @@ 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[] | Record<string, never> =
157+
this._configuration.additionalModuleKindsToEmit?.map((emitKind) => ({
158+
...emitKind,
159+
outFolderName: path.relative(this._configuration.buildFolderPath, emitKind.outFolderName)
160+
})) || {};
161+
162+
configHash.update(JSON.stringify(normalizedConfig));
163+
const serializedConfigHash: string = configHash.digest('base64url').slice(0, 8);
161164

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

0 commit comments

Comments
 (0)