@@ -558,14 +558,17 @@ namespace ts {
558558 if ( sourceMapFilePath ) {
559559 const sourceMap = sourceMapGenerator . toString ( ) ;
560560 writeFile ( host , emitterDiagnostics , sourceMapFilePath , sourceMap , /*writeByteOrderMark*/ false , sourceFiles ) ;
561+ if ( printer . bundleFileInfo ) printer . bundleFileInfo . mapHash = BuilderState . computeSignature ( sourceMap , maybeBind ( host , host . createHash ) ) ;
561562 }
562563 }
563564 else {
564565 writer . writeLine ( ) ;
565566 }
566567
567568 // Write the output file
568- writeFile ( host , emitterDiagnostics , jsFilePath , writer . getText ( ) , ! ! compilerOptions . emitBOM , sourceFiles , { sourceMapUrlPos } ) ;
569+ const text = writer . getText ( ) ;
570+ writeFile ( host , emitterDiagnostics , jsFilePath , text , ! ! compilerOptions . emitBOM , sourceFiles , { sourceMapUrlPos } ) ;
571+ if ( printer . bundleFileInfo ) printer . bundleFileInfo . hash = BuilderState . computeSignature ( text , maybeBind ( host , host . createHash ) ) ;
569572
570573 // Reset state
571574 writer . clear ( ) ;
@@ -712,6 +715,7 @@ namespace ts {
712715 getNewLine ( ) : string ;
713716 createHash ?( data : string ) : string ;
714717 now ?( ) : Date ;
718+ getBuildInfo ?( fileName : string , configFilePath : string | undefined ) : BuildInfo | undefined ;
715719 }
716720
717721 function createSourceFilesFromBundleBuildInfo ( bundle : BundleBuildInfo , buildInfoDirectory : string , host : EmitUsingBuildInfoHost ) : readonly SourceFile [ ] {
@@ -748,23 +752,38 @@ namespace ts {
748752 getCommandLine : ( ref : ProjectReference ) => ParsedCommandLine | undefined ,
749753 customTransformers ?: CustomTransformers
750754 ) : EmitUsingBuildInfoResult {
755+ const createHash = maybeBind ( host , host . createHash ) ;
751756 const { buildInfoPath, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath } = getOutputPathsForBundle ( config . options , /*forceDtsPaths*/ false ) ;
752- const buildInfoText = host . readFile ( Debug . checkDefined ( buildInfoPath ) ) ;
753- if ( ! buildInfoText ) return buildInfoPath ! ;
757+ let buildInfo : BuildInfo ;
758+ if ( host . getBuildInfo ) {
759+ const hostBuildInfo = host . getBuildInfo ( buildInfoPath ! , config . options . configFilePath ) ;
760+ if ( ! hostBuildInfo ) return buildInfoPath ! ;
761+ buildInfo = hostBuildInfo ;
762+ }
763+ else {
764+ const buildInfoText = host . readFile ( buildInfoPath ! ) ;
765+ if ( ! buildInfoText ) return buildInfoPath ! ;
766+ buildInfo = getBuildInfo ( buildInfoText ) ;
767+ }
768+ if ( ! buildInfo . bundle || ! buildInfo . bundle . js || ( declarationFilePath && ! buildInfo . bundle . dts ) ) return buildInfoPath ! ;
769+
754770 const jsFileText = host . readFile ( Debug . checkDefined ( jsFilePath ) ) ;
755771 if ( ! jsFileText ) return jsFilePath ! ;
772+ if ( BuilderState . computeSignature ( jsFileText , createHash ) !== buildInfo . bundle . js . hash ) return jsFilePath ! ;
756773 const sourceMapText = sourceMapFilePath && host . readFile ( sourceMapFilePath ) ;
757774 // error if no source map or for now if inline sourcemap
758775 if ( ( sourceMapFilePath && ! sourceMapText ) || config . options . inlineSourceMap ) return sourceMapFilePath || "inline sourcemap decoding" ;
776+ if ( sourceMapFilePath && BuilderState . computeSignature ( sourceMapText ! , createHash ) !== buildInfo . bundle . js . mapHash ) return sourceMapFilePath ;
777+
759778 // read declaration text
760779 const declarationText = declarationFilePath && host . readFile ( declarationFilePath ) ;
761780 if ( declarationFilePath && ! declarationText ) return declarationFilePath ;
781+ if ( declarationFilePath && BuilderState . computeSignature ( declarationText ! , createHash ) !== buildInfo . bundle . dts ! . hash ) return declarationFilePath ;
762782 const declarationMapText = declarationMapPath && host . readFile ( declarationMapPath ) ;
763783 // error if no source map or for now if inline sourcemap
764784 if ( ( declarationMapPath && ! declarationMapText ) || config . options . inlineSourceMap ) return declarationMapPath || "inline sourcemap decoding" ;
785+ if ( declarationMapPath && BuilderState . computeSignature ( declarationMapText ! , createHash ) !== buildInfo . bundle . dts ! . mapHash ) return declarationMapPath ;
765786
766- const buildInfo = getBuildInfo ( buildInfoText ) ;
767- if ( ! buildInfo . bundle || ! buildInfo . bundle . js || ( declarationText && ! buildInfo . bundle . dts ) ) return buildInfoPath ! ;
768787 const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath ! , host . getCurrentDirectory ( ) ) ) ;
769788 const ownPrependInput = createInputFiles (
770789 jsFileText ,
@@ -812,7 +831,7 @@ namespace ts {
812831 newBuildInfo . program = buildInfo . program ;
813832 if ( newBuildInfo . program && changedDtsText !== undefined && config . options . composite ) {
814833 // Update the output signature
815- newBuildInfo . program . outSignature = computeSignature ( changedDtsText , changedDtsData , maybeBind ( host , host . createHash ) ) ;
834+ newBuildInfo . program . outSignature = computeSignature ( changedDtsText , changedDtsData , createHash ) ;
816835 newBuildInfo . program . dtsChangeTime = getCurrentTime ( host ) . getTime ( ) ;
817836 }
818837 // Update sourceFileInfo
@@ -845,6 +864,7 @@ namespace ts {
845864 getSourceFileFromReference : returnUndefined ,
846865 redirectTargetsMap : createMultiMap ( ) ,
847866 getFileIncludeReasons : notImplemented ,
867+ createHash,
848868 } ;
849869 emitFiles (
850870 notImplementedResolver ,
0 commit comments