@@ -762,13 +762,19 @@ namespace ts {
762
762
}
763
763
764
764
export interface ProgramBundleEmitBuildInfo {
765
+ fileNames : readonly string [ ] ;
766
+ fileInfos : readonly string [ ] ;
765
767
options : CompilerOptions | undefined ;
766
768
outSignature ?: string ;
767
769
dtsChangeTime ?: number ;
768
770
}
769
771
770
772
export type ProgramBuildInfo = ProgramMultiFileEmitBuildInfo | ProgramBundleEmitBuildInfo ;
771
773
774
+ export function isProgramBundleEmitBuildInfo ( info : ProgramBuildInfo ) : info is ProgramBundleEmitBuildInfo {
775
+ return ! ! outFile ( info . options || { } ) ;
776
+ }
777
+
772
778
/**
773
779
* Gets the program information to be emitted in buildInfo so that we can use it to create new program
774
780
*/
@@ -779,7 +785,17 @@ namespace ts {
779
785
const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( getTsBuildInfoEmitOutputFilePath ( state . compilerOptions ) ! , currentDirectory ) ) ;
780
786
state . dtsChangeTime = state . hasChangedEmitSignature ? getCurrentTime ( host ) . getTime ( ) : state . dtsChangeTime ;
781
787
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
+ } ) ;
782
796
const result : ProgramBundleEmitBuildInfo = {
797
+ fileNames,
798
+ fileInfos,
783
799
options : convertToProgramBuildInfoCompilerOptions ( state . compilerOptions , "affectsBundleEmitBuildInfo" ) ,
784
800
outSignature : state . outSignature ,
785
801
dtsChangeTime : state . dtsChangeTime ,
@@ -1370,40 +1386,52 @@ namespace ts {
1370
1386
{ version : fileInfo . version , signature : fileInfo . signature === false ? undefined : fileInfo . version , affectsGlobalScope : fileInfo . affectsGlobalScope , impliedFormat : fileInfo . impliedFormat } ;
1371
1387
}
1372
1388
1373
- export function createBuilderProgramUsingProgramBuildInfo ( programFromBuildInfo : ProgramBuildInfo , buildInfoPath : string , host : ReadBuildProgramHost ) : EmitAndSemanticDiagnosticsBuilderProgram {
1389
+ export function createBuilderProgramUsingProgramBuildInfo ( program : ProgramBuildInfo , buildInfoPath : string , host : ReadBuildProgramHost ) : EmitAndSemanticDiagnosticsBuilderProgram {
1374
1390
const buildInfoDirectory = getDirectoryPath ( getNormalizedAbsolutePath ( buildInfoPath , host . getCurrentDirectory ( ) ) ) ;
1375
1391
const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ( ) ) ;
1376
1392
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
+
1407
1435
return {
1408
1436
getState : ( ) => state ,
1409
1437
backupEmitState : noop ,
@@ -1438,7 +1466,7 @@ namespace ts {
1438
1466
}
1439
1467
1440
1468
function toFilePath ( fileId : ProgramBuildInfoFileId ) {
1441
- return filePaths [ fileId - 1 ] ;
1469
+ return filePaths ! [ fileId - 1 ] ;
1442
1470
}
1443
1471
1444
1472
function toFilePathsSet ( fileIdsListId : ProgramBuildInfoFileIdListId ) {
@@ -1458,6 +1486,22 @@ namespace ts {
1458
1486
}
1459
1487
}
1460
1488
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
+
1461
1505
export function createRedirectedBuilderProgram ( getState : ( ) => { program ?: Program | undefined ; compilerOptions : CompilerOptions ; } , configFileParsingDiagnostics : readonly Diagnostic [ ] ) : BuilderProgram {
1462
1506
return {
1463
1507
getState : notImplemented ,
0 commit comments