@@ -762,13 +762,19 @@ namespace ts {
762762 }
763763
764764 export interface ProgramBundleEmitBuildInfo {
765+ fileNames : readonly string [ ] ;
766+ fileInfos : readonly string [ ] ;
765767 options : CompilerOptions | undefined ;
766768 outSignature ?: string ;
767769 dtsChangeTime ?: number ;
768770 }
769771
770772 export type ProgramBuildInfo = ProgramMultiFileEmitBuildInfo | ProgramBundleEmitBuildInfo ;
771773
774+ export function isProgramBundleEmitBuildInfo ( info : ProgramBuildInfo ) : info is ProgramBundleEmitBuildInfo {
775+ return ! ! outFile ( info . options || { } ) ;
776+ }
777+
772778 /**
773779 * Gets the program information to be emitted in buildInfo so that we can use it to create new program
774780 */
@@ -779,7 +785,17 @@ namespace ts {
779785 const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( getTsBuildInfoEmitOutputFilePath ( state . compilerOptions ) ! , currentDirectory ) ) ;
780786 state . dtsChangeTime = state . hasChangedEmitSignature ? getCurrentTime ( host ) . getTime ( ) : state . dtsChangeTime ;
781787 if ( outFilePath ) {
788+ const fileNames : string [ ] = [ ] ;
789+ const fileInfos : string [ ] = [ ] ;
790+ state . program ! . getRootFileNames ( ) . forEach ( f => {
791+ const sourceFile = state . program ! . getSourceFile ( f ) ;
792+ if ( ! sourceFile ) return ;
793+ fileNames . push ( relativeToBuildInfo ( sourceFile . resolvedPath ) ) ;
794+ fileInfos . push ( sourceFile . version ) ;
795+ } ) ;
782796 const result : ProgramBundleEmitBuildInfo = {
797+ fileNames,
798+ fileInfos,
783799 options : convertToProgramBuildInfoCompilerOptions ( state . compilerOptions , "affectsBundleEmitBuildInfo" ) ,
784800 outSignature : state . outSignature ,
785801 dtsChangeTime : state . dtsChangeTime ,
@@ -1370,40 +1386,52 @@ namespace ts {
13701386 { version : fileInfo . version , signature : fileInfo . signature === false ? undefined : fileInfo . version , affectsGlobalScope : fileInfo . affectsGlobalScope , impliedFormat : fileInfo . impliedFormat } ;
13711387 }
13721388
1373- export function createBuilderProgramUsingProgramBuildInfo ( programFromBuildInfo : ProgramBuildInfo , buildInfoPath : string , host : ReadBuildProgramHost ) : EmitAndSemanticDiagnosticsBuilderProgram {
1389+ export function createBuilderProgramUsingProgramBuildInfo ( program : ProgramBuildInfo , buildInfoPath : string , host : ReadBuildProgramHost ) : EmitAndSemanticDiagnosticsBuilderProgram {
13741390 const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
13751391 const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ( ) ) ;
13761392
1377- const program = programFromBuildInfo as ProgramMultiFileEmitBuildInfo & ProgramBundleEmitBuildInfo ;
1378- const filePaths = program . fileNames ?. map ( toPath ) ;
1379- const filePathsSetList = program . fileIdsList ?. map ( fileIds => new Set ( fileIds . map ( toFilePath ) ) ) ;
1380- const fileInfos = new Map < Path , BuilderState . FileInfo > ( ) ;
1381- const emitSignatures = program . options ?. composite && ! outFile ( program . options ) ? new Map < Path , string > ( ) : undefined ;
1382- program . fileInfos ?. forEach ( ( fileInfo , index ) => {
1383- const path = toFilePath ( index + 1 as ProgramBuildInfoFileId ) ;
1384- const stateFileInfo = toBuilderStateFileInfo ( fileInfo ) ;
1385- fileInfos . set ( path , stateFileInfo ) ;
1386- if ( emitSignatures && stateFileInfo . signature ) emitSignatures . set ( path , stateFileInfo . signature ) ;
1387- } ) ;
1388- program . emitSignatures ?. forEach ( value => {
1389- if ( isNumber ( value ) ) emitSignatures ! . delete ( toFilePath ( value ) ) ;
1390- else emitSignatures ! . set ( toFilePath ( value [ 0 ] ) , value [ 1 ] ) ;
1391- } ) ;
1392- const state : ReusableBuilderProgramState = {
1393- fileInfos,
1394- compilerOptions : program . options ? convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) : { } ,
1395- referencedMap : toManyToManyPathMap ( program . referencedMap ) ,
1396- exportedModulesMap : toManyToManyPathMap ( program . exportedModulesMap ) ,
1397- semanticDiagnosticsPerFile : program . semanticDiagnosticsPerFile && arrayToMap ( program . semanticDiagnosticsPerFile , value => toFilePath ( isNumber ( value ) ? value : value [ 0 ] ) , value => isNumber ( value ) ? emptyArray : value [ 1 ] ) ,
1398- hasReusableDiagnostic : true ,
1399- affectedFilesPendingEmit : map ( program . affectedFilesPendingEmit , value => toFilePath ( value [ 0 ] ) ) ,
1400- affectedFilesPendingEmitKind : program . affectedFilesPendingEmit && arrayToMap ( program . affectedFilesPendingEmit , value => toFilePath ( value [ 0 ] ) , value => value [ 1 ] ) ,
1401- affectedFilesPendingEmitIndex : program . affectedFilesPendingEmit && 0 ,
1402- changedFilesSet : new Set ( map ( program . changeFileSet , toFilePath ) ) ,
1403- dtsChangeTime : program . dtsChangeTime ,
1404- emitSignatures : emitSignatures ?. size ? emitSignatures : undefined ,
1405- outSignature : program . outSignature ,
1406- } ;
1393+ let state : ReusableBuilderProgramState ;
1394+ let filePaths : Path [ ] | undefined ;
1395+ let filePathsSetList : Set < Path > [ ] | undefined ;
1396+ if ( isProgramBundleEmitBuildInfo ( program ) ) {
1397+ state = {
1398+ fileInfos : new Map ( ) ,
1399+ compilerOptions : program . options ? convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) : { } ,
1400+ dtsChangeTime : program . dtsChangeTime ,
1401+ outSignature : program . outSignature ,
1402+ } ;
1403+ }
1404+ else {
1405+ filePaths = program . fileNames ?. map ( toPath ) ;
1406+ filePathsSetList = program . fileIdsList ?. map ( fileIds => new Set ( fileIds . map ( toFilePath ) ) ) ;
1407+ const fileInfos = new Map < Path , BuilderState . FileInfo > ( ) ;
1408+ const emitSignatures = program . options ?. composite && ! outFile ( program . options ) ? new Map < Path , string > ( ) : undefined ;
1409+ program . fileInfos . forEach ( ( fileInfo , index ) => {
1410+ const path = toFilePath ( index + 1 as ProgramBuildInfoFileId ) ;
1411+ const stateFileInfo = toBuilderStateFileInfo ( fileInfo ) ;
1412+ fileInfos . set ( path , stateFileInfo ) ;
1413+ if ( emitSignatures && stateFileInfo . signature ) emitSignatures . set ( path , stateFileInfo . signature ) ;
1414+ } ) ;
1415+ program . emitSignatures ?. forEach ( value => {
1416+ if ( isNumber ( value ) ) emitSignatures ! . delete ( toFilePath ( value ) ) ;
1417+ else emitSignatures ! . set ( toFilePath ( value [ 0 ] ) , value [ 1 ] ) ;
1418+ } ) ;
1419+ state = {
1420+ fileInfos,
1421+ compilerOptions : program . options ? convertToOptionsWithAbsolutePaths ( program . options , toAbsolutePath ) : { } ,
1422+ referencedMap : toManyToManyPathMap ( program . referencedMap ) ,
1423+ exportedModulesMap : toManyToManyPathMap ( program . exportedModulesMap ) ,
1424+ semanticDiagnosticsPerFile : program . semanticDiagnosticsPerFile && arrayToMap ( program . semanticDiagnosticsPerFile , value => toFilePath ( isNumber ( value ) ? value : value [ 0 ] ) , value => isNumber ( value ) ? emptyArray : value [ 1 ] ) ,
1425+ hasReusableDiagnostic : true ,
1426+ affectedFilesPendingEmit : map ( program . affectedFilesPendingEmit , value => toFilePath ( value [ 0 ] ) ) ,
1427+ affectedFilesPendingEmitKind : program . affectedFilesPendingEmit && arrayToMap ( program . affectedFilesPendingEmit , value => toFilePath ( value [ 0 ] ) , value => value [ 1 ] ) ,
1428+ affectedFilesPendingEmitIndex : program . affectedFilesPendingEmit && 0 ,
1429+ changedFilesSet : new Set ( map ( program . changeFileSet , toFilePath ) ) ,
1430+ dtsChangeTime : program . dtsChangeTime ,
1431+ emitSignatures : emitSignatures ?. size ? emitSignatures : undefined ,
1432+ } ;
1433+ }
1434+
14071435 return {
14081436 getState : ( ) => state ,
14091437 backupEmitState : noop ,
@@ -1438,7 +1466,7 @@ namespace ts {
14381466 }
14391467
14401468 function toFilePath ( fileId : ProgramBuildInfoFileId ) {
1441- return filePaths [ fileId - 1 ] ;
1469+ return filePaths ! [ fileId - 1 ] ;
14421470 }
14431471
14441472 function toFilePathsSet ( fileIdsListId : ProgramBuildInfoFileIdListId ) {
@@ -1458,6 +1486,22 @@ namespace ts {
14581486 }
14591487 }
14601488
1489+ export function getBuildInfoFileVersionMap (
1490+ program : ProgramBuildInfo ,
1491+ buildInfoPath : string ,
1492+ host : Pick < ReadBuildProgramHost , "useCaseSensitiveFileNames" | "getCurrentDirectory" >
1493+ ) : ESMap < Path , string > {
1494+ const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
1495+ const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ( ) ) ;
1496+ const fileInfos = new Map < Path , string > ( ) ;
1497+ program . fileInfos . forEach ( ( fileInfo , index ) => {
1498+ const path = toPath ( program . fileNames [ index ] , buildInfoDirectory , getCanonicalFileName ) ;
1499+ const version = isString ( fileInfo ) ? fileInfo : ( fileInfo as ProgramBuildInfoBuilderStateFileInfo ) . version ;
1500+ fileInfos . set ( path , version ) ;
1501+ } ) ;
1502+ return fileInfos ;
1503+ }
1504+
14611505 export function createRedirectedBuilderProgram ( getState : ( ) => { program ?: Program | undefined ; compilerOptions : CompilerOptions ; } , configFileParsingDiagnostics : readonly Diagnostic [ ] ) : BuilderProgram {
14621506 return {
14631507 getState : notImplemented ,
0 commit comments