Skip to content

Commit b9fc44e

Browse files
committed
Bundle info paths as relative to tsbuildinfo file
1 parent 9446fc0 commit b9fc44e

File tree

92 files changed

+1334
-1309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1334
-1309
lines changed

src/compiler/emitter.ts

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,16 @@ namespace ts {
249249
};
250250

251251
function emitSourceFileOrBundle({ jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath }: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle | undefined) {
252+
let buildInfoDirectory: string | undefined;
252253
if (buildInfoPath && sourceFileOrBundle && isBundle(sourceFileOrBundle)) {
254+
buildInfoDirectory = getDirectoryPath(buildInfoPath);
253255
bundleBuildInfo = {
254-
commonSourceDirectory: host.getCommonSourceDirectory(),
255-
sourceFiles: sourceFileOrBundle.sourceFiles.map(file => file.fileName)
256+
commonSourceDirectory: relativeToBuildInfo(host.getCommonSourceDirectory()),
257+
sourceFiles: sourceFileOrBundle.sourceFiles.map(file => relativeToBuildInfo(file.fileName))
256258
};
257259
}
258-
emitJsFileOrBundle(sourceFileOrBundle, jsFilePath, sourceMapFilePath);
259-
emitDeclarationFileOrBundle(sourceFileOrBundle, declarationFilePath, declarationMapPath);
260+
emitJsFileOrBundle(sourceFileOrBundle, jsFilePath, sourceMapFilePath, relativeToBuildInfo);
261+
emitDeclarationFileOrBundle(sourceFileOrBundle, declarationFilePath, declarationMapPath, relativeToBuildInfo);
260262
emitBuildInfo(bundleBuildInfo, buildInfoPath);
261263

262264
if (!emitSkipped && emittedFilesList) {
@@ -278,6 +280,10 @@ namespace ts {
278280
emittedFilesList.push(declarationMapPath);
279281
}
280282
}
283+
284+
function relativeToBuildInfo(path: string) {
285+
return ensurePathIsNonModuleName(getRelativePathFromDirectory(buildInfoDirectory!, path, host.getCanonicalFileName));
286+
}
281287
}
282288

283289
function emitBuildInfo(bundle: BundleBuildInfo | undefined, buildInfoPath: string | undefined) {
@@ -291,7 +297,11 @@ namespace ts {
291297
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program, version }), /*writeByteOrderMark*/ false);
292298
}
293299

294-
function emitJsFileOrBundle(sourceFileOrBundle: SourceFile | Bundle | undefined, jsFilePath: string | undefined, sourceMapFilePath: string | undefined) {
300+
function emitJsFileOrBundle(
301+
sourceFileOrBundle: SourceFile | Bundle | undefined,
302+
jsFilePath: string | undefined,
303+
sourceMapFilePath: string | undefined,
304+
relativeToBuildInfo: (path: string) => string) {
295305
if (!sourceFileOrBundle || emitOnlyDtsFiles || !jsFilePath) {
296306
return;
297307
}
@@ -314,7 +324,8 @@ namespace ts {
314324
inlineSourceMap: compilerOptions.inlineSourceMap,
315325
inlineSources: compilerOptions.inlineSources,
316326
extendedDiagnostics: compilerOptions.extendedDiagnostics,
317-
writeBundleFileInfo: !!bundleBuildInfo
327+
writeBundleFileInfo: !!bundleBuildInfo,
328+
relativeToBuildInfo
318329
};
319330

320331
// Create a printer to print the nodes
@@ -335,7 +346,11 @@ namespace ts {
335346
if (bundleBuildInfo) bundleBuildInfo.js = printer.bundleFileInfo;
336347
}
337348

338-
function emitDeclarationFileOrBundle(sourceFileOrBundle: SourceFile | Bundle | undefined, declarationFilePath: string | undefined, declarationMapPath: string | undefined) {
349+
function emitDeclarationFileOrBundle(
350+
sourceFileOrBundle: SourceFile | Bundle | undefined,
351+
declarationFilePath: string | undefined,
352+
declarationMapPath: string | undefined,
353+
relativeToBuildInfo: (path: string) => string) {
339354
if (!sourceFileOrBundle || !(declarationFilePath && !isInJSFile(sourceFileOrBundle))) {
340355
return;
341356
}
@@ -366,7 +381,8 @@ namespace ts {
366381
extendedDiagnostics: compilerOptions.extendedDiagnostics,
367382
onlyPrintJsDocStyle: true,
368383
writeBundleFileInfo: !!bundleBuildInfo,
369-
recordInternalSection: !!bundleBuildInfo
384+
recordInternalSection: !!bundleBuildInfo,
385+
relativeToBuildInfo
370386
};
371387

372388
const declarationPrinter = createPrinter(printerOptions, {
@@ -613,10 +629,10 @@ namespace ts {
613629
getNewLine(): string;
614630
}
615631

616-
function createSourceFilesFromBundleBuildInfo(bundle: BundleBuildInfo): ReadonlyArray<SourceFile> {
632+
function createSourceFilesFromBundleBuildInfo(bundle: BundleBuildInfo, buildInfoDirectory: string): ReadonlyArray<SourceFile> {
617633
const sourceFiles = bundle.sourceFiles.map(fileName => {
618634
const sourceFile = createNode(SyntaxKind.SourceFile, 0, 0) as SourceFile;
619-
sourceFile.fileName = fileName;
635+
sourceFile.fileName = getNormalizedAbsolutePath(fileName, buildInfoDirectory);
620636
sourceFile.text = "";
621637
sourceFile.statements = createNodeArray();
622638
return sourceFile;
@@ -660,6 +676,7 @@ namespace ts {
660676

661677
const buildInfo = getBuildInfo(buildInfoText);
662678
if (!buildInfo.bundle || !buildInfo.bundle.js || (declarationText && !buildInfo.bundle.dts)) return buildInfoPath!;
679+
const buildInfoDirectory = getDirectoryPath(buildInfoPath!);
663680
const ownPrependInput = createInputFiles(
664681
jsFileText,
665682
declarationText!,
@@ -675,11 +692,11 @@ namespace ts {
675692
);
676693
const outputFiles: OutputFile[] = [];
677694
const prependNodes = createPrependNodes(config.projectReferences, getCommandLine, f => host.readFile(f));
678-
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo(buildInfo.bundle);
695+
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo(buildInfo.bundle, buildInfoDirectory);
679696
const emitHost: EmitHost = {
680697
getPrependNodes: memoize(() => [...prependNodes, ownPrependInput]),
681698
getCanonicalFileName: host.getCanonicalFileName,
682-
getCommonSourceDirectory: () => buildInfo.bundle!.commonSourceDirectory,
699+
getCommonSourceDirectory: () => getNormalizedAbsolutePath(buildInfo.bundle!.commonSourceDirectory, buildInfoDirectory),
683700
getCompilerOptions: () => config.options,
684701
getCurrentDirectory: () => host.getCurrentDirectory(),
685702
getNewLine: () => host.getNewLine(),
@@ -774,6 +791,7 @@ namespace ts {
774791
let write = writeBase;
775792
let isOwnFileEmit: boolean;
776793
const bundleFileInfo = printerOptions.writeBundleFileInfo ? { sections: [] } as BundleFileInfo : undefined;
794+
const relativeToBuildInfo = bundleFileInfo ? Debug.assertDefined(printerOptions.relativeToBuildInfo) : undefined;
777795
const recordInternalSection = printerOptions.recordInternalSection;
778796
let sourceFileTextPos = 0;
779797
let sourceFileTextKind: BundleFileTextLikeKind = BundleFileSectionKind.Text;
@@ -942,7 +960,13 @@ namespace ts {
942960
if (prepend.oldFileOfCurrentEmit) bundleFileInfo.sections.push(...newSections);
943961
else {
944962
newSections.forEach(section => Debug.assert(isBundleFileTextLike(section)));
945-
bundleFileInfo.sections.push({ pos, end: writer.getTextPos(), kind: BundleFileSectionKind.Prepend, data: (prepend as UnparsedSource).fileName, texts: newSections as BundleFileTextLike[] });
963+
bundleFileInfo.sections.push({
964+
pos,
965+
end: writer.getTextPos(),
966+
kind: BundleFileSectionKind.Prepend,
967+
data: relativeToBuildInfo!((prepend as UnparsedSource).fileName),
968+
texts: newSections as BundleFileTextLike[]
969+
});
946970
}
947971
}
948972
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5726,6 +5726,7 @@ namespace ts {
57265726
/*@internal*/ writeBundleFileInfo?: boolean;
57275727
/*@internal*/ recordInternalSection?: boolean;
57285728
/*@internal*/ stripInternal?: boolean;
5729+
/*@internal*/ relativeToBuildInfo?: (path: string) => string;
57295730
}
57305731

57315732
/* @internal */

src/testRunner/unittests/tscWatch/incremental.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ namespace ts.tscWatch {
322322
path: `${project}/out.tsbuildinfo`,
323323
content: getBuildInfoText({
324324
bundle: {
325-
commonSourceDirectory: `${project}/`,
326-
sourceFiles: [file1.path, file2.path],
325+
commonSourceDirectory: relativeToBuildInfo(`${project}/out.tsbuildinfo`, `${project}/`),
326+
sourceFiles: [file1Path, file2Path],
327327
js: {
328328
sections: [
329329
{ pos: 0, end: outFile.content.length, kind: BundleFileSectionKind.Text }
@@ -550,8 +550,8 @@ namespace ts.tscWatch {
550550
path: `${project}/out.tsbuildinfo`,
551551
content: getBuildInfoText({
552552
bundle: {
553-
commonSourceDirectory: `${project}/`,
554-
sourceFiles: [file1.path, file2.path],
553+
commonSourceDirectory: relativeToBuildInfo(`${project}/out.tsbuildinfo`, `${project}/`),
554+
sourceFiles: [file1Path, file2Path],
555555
js: {
556556
sections: [
557557
{ pos: 0, end: outFile.content.length, kind: BundleFileSectionKind.Text }

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/modules-and-globals-mixed-in-amd.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,18 +221,18 @@ sourceFile:file4.ts
221221
//// [/src/app/module.tsbuildinfo]
222222
{
223223
"bundle": {
224-
"commonSourceDirectory": "/src/app/",
224+
"commonSourceDirectory": "./",
225225
"sourceFiles": [
226-
"/src/app/file3.ts",
227-
"/src/app/file4.ts"
226+
"./file3.ts",
227+
"./file4.ts"
228228
],
229229
"js": {
230230
"sections": [
231231
{
232232
"pos": 0,
233233
"end": 438,
234234
"kind": "prepend",
235-
"data": "/src/lib/module.js",
235+
"data": "../lib/module.js",
236236
"texts": [
237237
{
238238
"pos": 0,
@@ -254,7 +254,7 @@ sourceFile:file4.ts
254254
"pos": 0,
255255
"end": 171,
256256
"kind": "prepend",
257-
"data": "/src/lib/module.d.ts",
257+
"data": "../lib/module.d.ts",
258258
"texts": [
259259
{
260260
"pos": 0,
@@ -278,7 +278,7 @@ sourceFile:file4.ts
278278
======================================================================
279279
File:: /src/app/module.js
280280
----------------------------------------------------------------------
281-
prepend: (0-438):: /src/lib/module.js texts:: 1
281+
prepend: (0-438):: ../lib/module.js texts:: 1
282282
>>--------------------------------------------------------------------
283283
text: (0-438)
284284
var myGlob = 20;
@@ -308,7 +308,7 @@ var myVar = 30;
308308
======================================================================
309309
File:: /src/app/module.d.ts
310310
----------------------------------------------------------------------
311-
prepend: (0-171):: /src/lib/module.d.ts texts:: 1
311+
prepend: (0-171):: ../lib/module.d.ts texts:: 1
312312
>>--------------------------------------------------------------------
313313
text: (0-171)
314314
declare const myGlob = 20;
@@ -496,12 +496,12 @@ sourceFile:global.ts
496496
//// [/src/lib/module.tsbuildinfo]
497497
{
498498
"bundle": {
499-
"commonSourceDirectory": "/src/lib/",
499+
"commonSourceDirectory": "./",
500500
"sourceFiles": [
501-
"/src/lib/file0.ts",
502-
"/src/lib/file1.ts",
503-
"/src/lib/file2.ts",
504-
"/src/lib/global.ts"
501+
"./file0.ts",
502+
"./file1.ts",
503+
"./file2.ts",
504+
"./global.ts"
505505
],
506506
"js": {
507507
"sections": [

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/multiple-emitHelpers-in-all-projects.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,10 @@ sourceFile:file4.ts
593593
//// [/src/app/module.tsbuildinfo]
594594
{
595595
"bundle": {
596-
"commonSourceDirectory": "/src/app/",
596+
"commonSourceDirectory": "./",
597597
"sourceFiles": [
598-
"/src/app/file3.ts",
599-
"/src/app/file4.ts"
598+
"./file3.ts",
599+
"./file4.ts"
600600
],
601601
"js": {
602602
"sections": [
@@ -622,7 +622,7 @@ sourceFile:file4.ts
622622
"pos": 1180,
623623
"end": 1935,
624624
"kind": "prepend",
625-
"data": "/src/lib/module.js",
625+
"data": "../lib/module.js",
626626
"texts": [
627627
{
628628
"pos": 1180,
@@ -651,7 +651,7 @@ sourceFile:file4.ts
651651
"pos": 0,
652652
"end": 227,
653653
"kind": "prepend",
654-
"data": "/src/lib/module.d.ts",
654+
"data": "../lib/module.d.ts",
655655
"texts": [
656656
{
657657
"pos": 0,
@@ -712,7 +712,7 @@ var __rest = (this && this.__rest) || function (s, e) {
712712
return t;
713713
};
714714
----------------------------------------------------------------------
715-
prepend: (1180-1935):: /src/lib/module.js texts:: 1
715+
prepend: (1180-1935):: ../lib/module.js texts:: 1
716716
>>--------------------------------------------------------------------
717717
text: (1180-1935)
718718
var myGlob = 20;
@@ -762,7 +762,7 @@ appfile4Spread.apply(void 0, __spread([10, 20, 30]));
762762
======================================================================
763763
File:: /src/app/module.d.ts
764764
----------------------------------------------------------------------
765-
prepend: (0-227):: /src/lib/module.d.ts texts:: 1
765+
prepend: (0-227):: ../lib/module.d.ts texts:: 1
766766
>>--------------------------------------------------------------------
767767
text: (0-227)
768768
declare const myGlob = 20;
@@ -1171,12 +1171,12 @@ sourceFile:global.ts
11711171
//// [/src/lib/module.tsbuildinfo]
11721172
{
11731173
"bundle": {
1174-
"commonSourceDirectory": "/src/lib/",
1174+
"commonSourceDirectory": "./",
11751175
"sourceFiles": [
1176-
"/src/lib/file0.ts",
1177-
"/src/lib/file1.ts",
1178-
"/src/lib/file2.ts",
1179-
"/src/lib/global.ts"
1176+
"./file0.ts",
1177+
"./file1.ts",
1178+
"./file2.ts",
1179+
"./global.ts"
11801180
],
11811181
"js": {
11821182
"sections": [

tests/baselines/reference/tsbuild/amdModulesWithOut/incremental-declaration-doesnt-change/multiple-prologues-in-all-projects.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ sourceFile:file4.ts
305305
//// [/src/app/module.tsbuildinfo]
306306
{
307307
"bundle": {
308-
"commonSourceDirectory": "/src/app/",
308+
"commonSourceDirectory": "./",
309309
"sourceFiles": [
310-
"/src/app/file3.ts",
311-
"/src/app/file4.ts"
310+
"./file3.ts",
311+
"./file4.ts"
312312
],
313313
"js": {
314314
"sections": [
@@ -340,7 +340,7 @@ sourceFile:file4.ts
340340
"pos": 62,
341341
"end": 523,
342342
"kind": "prepend",
343-
"data": "/src/lib/module.js",
343+
"data": "../lib/module.js",
344344
"texts": [
345345
{
346346
"pos": 62,
@@ -390,7 +390,7 @@ sourceFile:file4.ts
390390
"pos": 0,
391391
"end": 171,
392392
"kind": "prepend",
393-
"data": "/src/lib/module.d.ts",
393+
"data": "../lib/module.d.ts",
394394
"texts": [
395395
{
396396
"pos": 0,
@@ -426,7 +426,7 @@ prologue: (30-44):: myPrologue3
426426
prologue: (46-60):: myPrologue2
427427
"myPrologue2";
428428
----------------------------------------------------------------------
429-
prepend: (62-523):: /src/lib/module.js texts:: 1
429+
prepend: (62-523):: ../lib/module.js texts:: 1
430430
>>--------------------------------------------------------------------
431431
text: (62-523)
432432
var myGlob = 20;
@@ -458,7 +458,7 @@ var myVar = 30;
458458
======================================================================
459459
File:: /src/app/module.d.ts
460460
----------------------------------------------------------------------
461-
prepend: (0-171):: /src/lib/module.d.ts texts:: 1
461+
prepend: (0-171):: ../lib/module.d.ts texts:: 1
462462
>>--------------------------------------------------------------------
463463
text: (0-171)
464464
declare const myGlob = 20;
@@ -698,12 +698,12 @@ sourceFile:global.ts
698698
//// [/src/lib/module.tsbuildinfo]
699699
{
700700
"bundle": {
701-
"commonSourceDirectory": "/src/lib/",
701+
"commonSourceDirectory": "./",
702702
"sourceFiles": [
703-
"/src/lib/file0.ts",
704-
"/src/lib/file1.ts",
705-
"/src/lib/file2.ts",
706-
"/src/lib/global.ts"
703+
"./file0.ts",
704+
"./file1.ts",
705+
"./file2.ts",
706+
"./global.ts"
707707
],
708708
"js": {
709709
"sections": [

0 commit comments

Comments
 (0)