@@ -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 ( getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
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 ( getNormalizedAbsolutePath ( file . fileName , host . getCurrentDirectory ( ) ) ) )
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,14 @@ namespace ts {
613629 getNewLine ( ) : string ;
614630 }
615631
616- function createSourceFilesFromBundleBuildInfo ( bundle : BundleBuildInfo ) : ReadonlyArray < SourceFile > {
632+ function createSourceFilesFromBundleBuildInfo ( bundle : BundleBuildInfo , buildInfoDirectory : string , host : EmitUsingBuildInfoHost ) : 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 = getRelativePathFromDirectory (
636+ host . getCurrentDirectory ( ) ,
637+ getNormalizedAbsolutePath ( fileName , buildInfoDirectory ) ,
638+ ! host . useCaseSensitiveFileNames ( )
639+ ) ;
620640 sourceFile . text = "" ;
621641 sourceFile . statements = createNodeArray ( ) ;
622642 return sourceFile ;
@@ -660,6 +680,7 @@ namespace ts {
660680
661681 const buildInfo = getBuildInfo ( buildInfoText ) ;
662682 if ( ! buildInfo . bundle || ! buildInfo . bundle . js || ( declarationText && ! buildInfo . bundle . dts ) ) return buildInfoPath ! ;
683+ const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath ! , host . getCurrentDirectory ( ) ) ) ;
663684 const ownPrependInput = createInputFiles (
664685 jsFileText ,
665686 declarationText ! ,
@@ -675,11 +696,11 @@ namespace ts {
675696 ) ;
676697 const outputFiles : OutputFile [ ] = [ ] ;
677698 const prependNodes = createPrependNodes ( config . projectReferences , getCommandLine , f => host . readFile ( f ) ) ;
678- const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo ( buildInfo . bundle ) ;
699+ const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo ( buildInfo . bundle , buildInfoDirectory , host ) ;
679700 const emitHost : EmitHost = {
680701 getPrependNodes : memoize ( ( ) => [ ...prependNodes , ownPrependInput ] ) ,
681702 getCanonicalFileName : host . getCanonicalFileName ,
682- getCommonSourceDirectory : ( ) => buildInfo . bundle ! . commonSourceDirectory ,
703+ getCommonSourceDirectory : ( ) => getNormalizedAbsolutePath ( buildInfo . bundle ! . commonSourceDirectory , buildInfoDirectory ) ,
683704 getCompilerOptions : ( ) => config . options ,
684705 getCurrentDirectory : ( ) => host . getCurrentDirectory ( ) ,
685706 getNewLine : ( ) => host . getNewLine ( ) ,
@@ -775,6 +796,7 @@ namespace ts {
775796 let write = writeBase ;
776797 let isOwnFileEmit : boolean ;
777798 const bundleFileInfo = printerOptions . writeBundleFileInfo ? { sections : [ ] } as BundleFileInfo : undefined ;
799+ const relativeToBuildInfo = bundleFileInfo ? Debug . assertDefined ( printerOptions . relativeToBuildInfo ) : undefined ;
778800 const recordInternalSection = printerOptions . recordInternalSection ;
779801 let sourceFileTextPos = 0 ;
780802 let sourceFileTextKind : BundleFileTextLikeKind = BundleFileSectionKind . Text ;
@@ -943,7 +965,13 @@ namespace ts {
943965 if ( prepend . oldFileOfCurrentEmit ) bundleFileInfo . sections . push ( ...newSections ) ;
944966 else {
945967 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+ } ) ;
947975 }
948976 }
949977 }
0 commit comments