Skip to content

Commit 15fe24e

Browse files
committed
Pass through buildInfo so we dont have to parse it back
1 parent 2f2e370 commit 15fe24e

File tree

4 files changed

+24
-23
lines changed

4 files changed

+24
-23
lines changed

src/compiler/builderStatePublic.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ namespace ts {
1010
name: string;
1111
writeByteOrderMark: boolean;
1212
text: string;
13+
/* @internal */ buildInfo?: BuildInfo
1314
}
1415
}

src/compiler/emitter.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ namespace ts {
366366
return;
367367
}
368368
const version = ts.version; // Extracted into a const so the form is stable between namespace and module
369-
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program, version }), /*writeByteOrderMark*/ false);
369+
const buildInfo: BuildInfo = { bundle, program, version };
370+
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText(buildInfo), /*writeByteOrderMark*/ false, /*sourceFiles*/ undefined, { buildInfo });
370371
}
371372

372373
function emitJsFileOrBundle(
@@ -794,7 +795,7 @@ namespace ts {
794795
getResolvedProjectReferenceToRedirect: returnUndefined,
795796
getProjectReferenceRedirect: returnUndefined,
796797
isSourceOfProjectReferenceRedirect: returnFalse,
797-
writeFile: (name, text, writeByteOrderMark) => {
798+
writeFile: (name, text, writeByteOrderMark, _onError, _sourceFiles, data) => {
798799
switch (name) {
799800
case jsFilePath:
800801
if (jsFileText === text) return;
@@ -803,7 +804,7 @@ namespace ts {
803804
if (sourceMapText === text) return;
804805
break;
805806
case buildInfoPath:
806-
const newBuildInfo = getBuildInfo(text);
807+
const newBuildInfo = data!.buildInfo!;
807808
newBuildInfo.program = buildInfo.program;
808809
// Update sourceFileInfo
809810
const { js, dts, sourceFiles } = buildInfo.bundle!;
@@ -812,7 +813,7 @@ namespace ts {
812813
newBuildInfo.bundle!.dts!.sources = dts.sources;
813814
}
814815
newBuildInfo.bundle!.sourceFiles = sourceFiles;
815-
outputFiles.push({ name, text: getBuildInfoText(newBuildInfo), writeByteOrderMark });
816+
outputFiles.push({ name, text: getBuildInfoText(newBuildInfo), writeByteOrderMark, buildInfo: newBuildInfo });
816817
return;
817818
case declarationFilePath:
818819
if (declarationText === text) return;

src/compiler/tsbuildPublic.ts

+17-19
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ namespace ts {
220220

221221
interface BuildInfoCacheEntry {
222222
path: Path;
223-
buildInfo: BuildInfo | false | string;
223+
buildInfo: BuildInfo | false;
224224
modifiedTime: Date;
225225
}
226226

@@ -956,7 +956,7 @@ namespace ts {
956956
reportDeclarationDiagnostics,
957957
/*write*/ undefined,
958958
/*reportSummary*/ undefined,
959-
(name, text, writeByteOrderMark) => outputFiles.push({ name, text, writeByteOrderMark }),
959+
(name, text, writeByteOrderMark, _onError, _sourceFiles, data) => outputFiles.push({ name, text, writeByteOrderMark, buildInfo: data?.buildInfo }),
960960
cancellationToken,
961961
/*emitOnlyDts*/ false,
962962
customTransformers || state.host.getCustomTransformers?.(project)
@@ -985,8 +985,8 @@ namespace ts {
985985
let newestDeclarationFileContentChangedTime: Date | undefined;
986986
const emitterDiagnostics = createDiagnosticCollection();
987987
const emittedOutputs = new Map<Path, string>();
988-
const buildInfo = state.buildInfoCache.get(projectPath);
989-
outputFiles.forEach(({ name, text, writeByteOrderMark }) => {
988+
const buildInfoEntry = state.buildInfoCache.get(projectPath);
989+
outputFiles.forEach(({ name, text, writeByteOrderMark, buildInfo }) => {
990990
if (resultFlags === BuildResultFlags.DeclarationOutputUnchanged && isDeclarationFileName(name)) {
991991
// Check for unchanged .d.ts files
992992
if (state.readFileWithCache(name) === text) {
@@ -1001,9 +1001,9 @@ namespace ts {
10011001

10021002
const path = toPath(state, name);
10031003
emittedOutputs.set(path, name);
1004-
if (buildInfo?.path === path) {
1005-
buildInfo.buildInfo = text;
1006-
buildInfo.modifiedTime = getCurrentTime(state);
1004+
if (buildInfoEntry?.path === path) {
1005+
buildInfoEntry.buildInfo = buildInfo!;
1006+
buildInfoEntry.modifiedTime = getCurrentTime(state);
10071007
}
10081008
writeFile(writeFileCallback ? { writeFile: writeFileCallback } : compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
10091009
});
@@ -1021,15 +1021,15 @@ namespace ts {
10211021
function emitBuildInfo(writeFileCallback?: WriteFileCallback, cancellationToken?: CancellationToken): EmitResult {
10221022
Debug.assertIsDefined(program);
10231023
Debug.assert(step === BuildStep.EmitBuildInfo);
1024-
const emitResult = program.emitBuildInfo((name, data, writeByteOrderMark, onError, sourceFiles) => {
1024+
const emitResult = program.emitBuildInfo((name, text, writeByteOrderMark, onError, sourceFiles, data) => {
10251025
const path = toPath(state, name);
10261026
const buildInfo = state.buildInfoCache.get(projectPath);
10271027
if (buildInfo?.path === path) {
1028-
buildInfo.buildInfo = data;
1028+
buildInfo.buildInfo = data!.buildInfo!;
10291029
buildInfo.modifiedTime = getCurrentTime(state);
10301030
}
1031-
if (writeFileCallback) writeFileCallback(name, data, writeByteOrderMark, onError, sourceFiles);
1032-
else state.compilerHost.writeFile(name, data, writeByteOrderMark, onError, sourceFiles);
1031+
if (writeFileCallback) writeFileCallback(name, text, writeByteOrderMark, onError, sourceFiles, data);
1032+
else state.compilerHost.writeFile(name, text, writeByteOrderMark, onError, sourceFiles, data);
10331033
}, cancellationToken);
10341034
if (emitResult.diagnostics.length) {
10351035
reportErrors(state, emitResult.diagnostics);
@@ -1127,13 +1127,13 @@ namespace ts {
11271127
Debug.assert(!!outputFiles.length);
11281128
const emitterDiagnostics = createDiagnosticCollection();
11291129
const emittedOutputs = new Map<Path, string>();
1130-
const buildInfo = state.buildInfoCache.get(projectPath);
1131-
outputFiles.forEach(({ name, text, writeByteOrderMark }) => {
1130+
const buildInfoEntry = state.buildInfoCache.get(projectPath);
1131+
outputFiles.forEach(({ name, text, writeByteOrderMark, buildInfo }) => {
11321132
const path = toPath(state, name);
11331133
emittedOutputs.set(path, name);
1134-
if (buildInfo?.path === path) {
1135-
buildInfo.buildInfo = text;
1136-
buildInfo.modifiedTime = getCurrentTime(state);
1134+
if (buildInfoEntry?.path === path) {
1135+
buildInfoEntry.buildInfo = buildInfo!;
1136+
buildInfoEntry.modifiedTime = getCurrentTime(state);
11371137
}
11381138
writeFile(writeFileCallback ? { writeFile: writeFileCallback } : compilerHost, emitterDiagnostics, name, text, writeByteOrderMark);
11391139
});
@@ -1433,9 +1433,7 @@ namespace ts {
14331433
const path = toPath(state, buildInfoPath);
14341434
const existing = state.buildInfoCache.get(resolvedConfigPath);
14351435
if (existing !== undefined && existing.path === path) {
1436-
return isString(existing.buildInfo) ?
1437-
existing.buildInfo = ts.getBuildInfo(existing.buildInfo) :
1438-
existing.buildInfo || undefined;
1436+
return existing.buildInfo || undefined;
14391437
}
14401438
const value = state.readFileWithCache(buildInfoPath);
14411439
const buildInfo = value ? ts.getBuildInfo(value) : undefined;

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3858,6 +3858,7 @@ namespace ts {
38583858

38593859
export interface WriteFileCallbackData {
38603860
/*@internal*/ sourceMapUrlPos?: number;
3861+
/*@internal*/ buildInfo?: BuildInfo;
38613862
}
38623863
export type WriteFileCallback = (
38633864
fileName: string,

0 commit comments

Comments
 (0)