@@ -249,14 +249,16 @@ namespace ts {
249
249
} ;
250
250
251
251
function emitSourceFileOrBundle ( { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath } : EmitFileNames , sourceFileOrBundle : SourceFile | Bundle | undefined ) {
252
+ let buildInfoDirectory : string | undefined ;
252
253
if ( buildInfoPath && sourceFileOrBundle && isBundle ( sourceFileOrBundle ) ) {
254
+ buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
253
255
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 ( getNormalizedAbsolutePath ( file . fileName , host . getCurrentDirectory ( ) ) ) )
256
258
} ;
257
259
}
258
- emitJsFileOrBundle ( sourceFileOrBundle , jsFilePath , sourceMapFilePath ) ;
259
- emitDeclarationFileOrBundle ( sourceFileOrBundle , declarationFilePath , declarationMapPath ) ;
260
+ emitJsFileOrBundle ( sourceFileOrBundle , jsFilePath , sourceMapFilePath , relativeToBuildInfo ) ;
261
+ emitDeclarationFileOrBundle ( sourceFileOrBundle , declarationFilePath , declarationMapPath , relativeToBuildInfo ) ;
260
262
emitBuildInfo ( bundleBuildInfo , buildInfoPath ) ;
261
263
262
264
if ( ! emitSkipped && emittedFilesList ) {
@@ -278,6 +280,10 @@ namespace ts {
278
280
emittedFilesList . push ( declarationMapPath ) ;
279
281
}
280
282
}
283
+
284
+ function relativeToBuildInfo ( path : string ) {
285
+ return ensurePathIsNonModuleName ( getRelativePathFromDirectory ( buildInfoDirectory ! , path , host . getCanonicalFileName ) ) ;
286
+ }
281
287
}
282
288
283
289
function emitBuildInfo ( bundle : BundleBuildInfo | undefined , buildInfoPath : string | undefined ) {
@@ -291,7 +297,11 @@ namespace ts {
291
297
writeFile ( host , emitterDiagnostics , buildInfoPath , getBuildInfoText ( { bundle, program, version } ) , /*writeByteOrderMark*/ false ) ;
292
298
}
293
299
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 ) {
295
305
if ( ! sourceFileOrBundle || emitOnlyDtsFiles || ! jsFilePath ) {
296
306
return ;
297
307
}
@@ -314,7 +324,8 @@ namespace ts {
314
324
inlineSourceMap : compilerOptions . inlineSourceMap ,
315
325
inlineSources : compilerOptions . inlineSources ,
316
326
extendedDiagnostics : compilerOptions . extendedDiagnostics ,
317
- writeBundleFileInfo : ! ! bundleBuildInfo
327
+ writeBundleFileInfo : ! ! bundleBuildInfo ,
328
+ relativeToBuildInfo
318
329
} ;
319
330
320
331
// Create a printer to print the nodes
@@ -335,7 +346,11 @@ namespace ts {
335
346
if ( bundleBuildInfo ) bundleBuildInfo . js = printer . bundleFileInfo ;
336
347
}
337
348
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 ) {
339
354
if ( ! sourceFileOrBundle || ! ( declarationFilePath && ! isInJSFile ( sourceFileOrBundle ) ) ) {
340
355
return ;
341
356
}
@@ -366,7 +381,8 @@ namespace ts {
366
381
extendedDiagnostics : compilerOptions . extendedDiagnostics ,
367
382
onlyPrintJsDocStyle : true ,
368
383
writeBundleFileInfo : ! ! bundleBuildInfo ,
369
- recordInternalSection : ! ! bundleBuildInfo
384
+ recordInternalSection : ! ! bundleBuildInfo ,
385
+ relativeToBuildInfo
370
386
} ;
371
387
372
388
const declarationPrinter = createPrinter ( printerOptions , {
@@ -613,10 +629,14 @@ namespace ts {
613
629
getNewLine ( ) : string ;
614
630
}
615
631
616
- function createSourceFilesFromBundleBuildInfo ( bundle : BundleBuildInfo ) : ReadonlyArray < SourceFile > {
632
+ function createSourceFilesFromBundleBuildInfo ( bundle : BundleBuildInfo , buildInfoDirectory : string , host : EmitUsingBuildInfoHost ) : ReadonlyArray < SourceFile > {
617
633
const sourceFiles = bundle . sourceFiles . map ( fileName => {
618
634
const sourceFile = createNode ( SyntaxKind . SourceFile , 0 , 0 ) as SourceFile ;
619
- sourceFile . fileName = fileName ;
635
+ sourceFile . fileName = getRelativePathFromDirectory (
636
+ host . getCurrentDirectory ( ) ,
637
+ getNormalizedAbsolutePath ( fileName , buildInfoDirectory ) ,
638
+ ! host . useCaseSensitiveFileNames ( )
639
+ ) ;
620
640
sourceFile . text = "" ;
621
641
sourceFile . statements = createNodeArray ( ) ;
622
642
return sourceFile ;
@@ -660,6 +680,7 @@ namespace ts {
660
680
661
681
const buildInfo = getBuildInfo ( buildInfoText ) ;
662
682
if ( ! buildInfo . bundle || ! buildInfo . bundle . js || ( declarationText && ! buildInfo . bundle . dts ) ) return buildInfoPath ! ;
683
+ const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath ! , host . getCurrentDirectory ( ) ) ) ;
663
684
const ownPrependInput = createInputFiles (
664
685
jsFileText ,
665
686
declarationText ! ,
@@ -675,11 +696,11 @@ namespace ts {
675
696
) ;
676
697
const outputFiles : OutputFile [ ] = [ ] ;
677
698
const prependNodes = createPrependNodes ( config . projectReferences , getCommandLine , f => host . readFile ( f ) ) ;
678
- const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo ( buildInfo . bundle ) ;
699
+ const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo ( buildInfo . bundle , buildInfoDirectory , host ) ;
679
700
const emitHost : EmitHost = {
680
701
getPrependNodes : memoize ( ( ) => [ ...prependNodes , ownPrependInput ] ) ,
681
702
getCanonicalFileName : host . getCanonicalFileName ,
682
- getCommonSourceDirectory : ( ) => buildInfo . bundle ! . commonSourceDirectory ,
703
+ getCommonSourceDirectory : ( ) => getNormalizedAbsolutePath ( buildInfo . bundle ! . commonSourceDirectory , buildInfoDirectory ) ,
683
704
getCompilerOptions : ( ) => config . options ,
684
705
getCurrentDirectory : ( ) => host . getCurrentDirectory ( ) ,
685
706
getNewLine : ( ) => host . getNewLine ( ) ,
@@ -775,6 +796,7 @@ namespace ts {
775
796
let write = writeBase ;
776
797
let isOwnFileEmit : boolean ;
777
798
const bundleFileInfo = printerOptions . writeBundleFileInfo ? { sections : [ ] } as BundleFileInfo : undefined ;
799
+ const relativeToBuildInfo = bundleFileInfo ? Debug . assertDefined ( printerOptions . relativeToBuildInfo ) : undefined ;
778
800
const recordInternalSection = printerOptions . recordInternalSection ;
779
801
let sourceFileTextPos = 0 ;
780
802
let sourceFileTextKind : BundleFileTextLikeKind = BundleFileSectionKind . Text ;
@@ -943,7 +965,13 @@ namespace ts {
943
965
if ( prepend . oldFileOfCurrentEmit ) bundleFileInfo . sections . push ( ...newSections ) ;
944
966
else {
945
967
newSections . forEach ( section => Debug . assert ( isBundleFileTextLike ( section ) ) ) ;
946
- bundleFileInfo . sections . push ( { pos, end : writer . getTextPos ( ) , kind : BundleFileSectionKind . Prepend , data : ( prepend as UnparsedSource ) . fileName , texts : newSections as BundleFileTextLike [ ] } ) ;
968
+ bundleFileInfo . sections . push ( {
969
+ pos,
970
+ end : writer . getTextPos ( ) ,
971
+ kind : BundleFileSectionKind . Prepend ,
972
+ data : relativeToBuildInfo ! ( ( prepend as UnparsedSource ) . fileName ) ,
973
+ texts : newSections as BundleFileTextLike [ ]
974
+ } ) ;
947
975
}
948
976
}
949
977
}
0 commit comments