@@ -558,14 +558,17 @@ namespace ts {
558
558
if ( sourceMapFilePath ) {
559
559
const sourceMap = sourceMapGenerator . toString ( ) ;
560
560
writeFile ( host , emitterDiagnostics , sourceMapFilePath , sourceMap , /*writeByteOrderMark*/ false , sourceFiles ) ;
561
+ if ( printer . bundleFileInfo ) printer . bundleFileInfo . mapHash = BuilderState . computeSignature ( sourceMap , maybeBind ( host , host . createHash ) ) ;
561
562
}
562
563
}
563
564
else {
564
565
writer . writeLine ( ) ;
565
566
}
566
567
567
568
// 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 ) ) ;
569
572
570
573
// Reset state
571
574
writer . clear ( ) ;
@@ -712,6 +715,7 @@ namespace ts {
712
715
getNewLine ( ) : string ;
713
716
createHash ?( data : string ) : string ;
714
717
now ?( ) : Date ;
718
+ getBuildInfo ?( fileName : string , configFilePath : string | undefined ) : BuildInfo | undefined ;
715
719
}
716
720
717
721
function createSourceFilesFromBundleBuildInfo ( bundle : BundleBuildInfo , buildInfoDirectory : string , host : EmitUsingBuildInfoHost ) : readonly SourceFile [ ] {
@@ -748,23 +752,38 @@ namespace ts {
748
752
getCommandLine : ( ref : ProjectReference ) => ParsedCommandLine | undefined ,
749
753
customTransformers ?: CustomTransformers
750
754
) : EmitUsingBuildInfoResult {
755
+ const createHash = maybeBind ( host , host . createHash ) ;
751
756
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
+
754
770
const jsFileText = host . readFile ( Debug . checkDefined ( jsFilePath ) ) ;
755
771
if ( ! jsFileText ) return jsFilePath ! ;
772
+ if ( BuilderState . computeSignature ( jsFileText , createHash ) !== buildInfo . bundle . js . hash ) return jsFilePath ! ;
756
773
const sourceMapText = sourceMapFilePath && host . readFile ( sourceMapFilePath ) ;
757
774
// error if no source map or for now if inline sourcemap
758
775
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
+
759
778
// read declaration text
760
779
const declarationText = declarationFilePath && host . readFile ( declarationFilePath ) ;
761
780
if ( declarationFilePath && ! declarationText ) return declarationFilePath ;
781
+ if ( declarationFilePath && BuilderState . computeSignature ( declarationText ! , createHash ) !== buildInfo . bundle . dts ! . hash ) return declarationFilePath ;
762
782
const declarationMapText = declarationMapPath && host . readFile ( declarationMapPath ) ;
763
783
// error if no source map or for now if inline sourcemap
764
784
if ( ( declarationMapPath && ! declarationMapText ) || config . options . inlineSourceMap ) return declarationMapPath || "inline sourcemap decoding" ;
785
+ if ( declarationMapPath && BuilderState . computeSignature ( declarationMapText ! , createHash ) !== buildInfo . bundle . dts ! . mapHash ) return declarationMapPath ;
765
786
766
- const buildInfo = getBuildInfo ( buildInfoText ) ;
767
- if ( ! buildInfo . bundle || ! buildInfo . bundle . js || ( declarationText && ! buildInfo . bundle . dts ) ) return buildInfoPath ! ;
768
787
const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath ! , host . getCurrentDirectory ( ) ) ) ;
769
788
const ownPrependInput = createInputFiles (
770
789
jsFileText ,
@@ -812,7 +831,7 @@ namespace ts {
812
831
newBuildInfo . program = buildInfo . program ;
813
832
if ( newBuildInfo . program && changedDtsText !== undefined && config . options . composite ) {
814
833
// Update the output signature
815
- newBuildInfo . program . outSignature = computeSignature ( changedDtsText , changedDtsData , maybeBind ( host , host . createHash ) ) ;
834
+ newBuildInfo . program . outSignature = computeSignature ( changedDtsText , changedDtsData , createHash ) ;
816
835
newBuildInfo . program . dtsChangeTime = getCurrentTime ( host ) . getTime ( ) ;
817
836
}
818
837
// Update sourceFileInfo
@@ -845,6 +864,7 @@ namespace ts {
845
864
getSourceFileFromReference : returnUndefined ,
846
865
redirectTargetsMap : createMultiMap ( ) ,
847
866
getFileIncludeReasons : notImplemented ,
867
+ createHash,
848
868
} ;
849
869
emitFiles (
850
870
notImplementedResolver ,
0 commit comments