1
1
import {
2
2
addRange ,
3
3
AffectedFileResult ,
4
+ append ,
4
5
arrayFrom ,
5
6
arrayToMap ,
6
7
BuilderProgram ,
@@ -990,10 +991,13 @@ export type ProgramBuildInfoRootStartEnd = [start: ProgramBuildInfoFileId, end:
990
991
*/
991
992
export type ProgramBuildInfoRoot = ProgramBuildInfoRootStartEnd | ProgramBuildInfoFileId ;
992
993
/** @internal */
994
+ export type ProgramBuildInfoResolvedRoot = [ resolved : ProgramBuildInfoFileId , root : ProgramBuildInfoFileId ] ;
995
+ /** @internal */
993
996
export interface ProgramMultiFileEmitBuildInfo {
994
997
fileNames : readonly string [ ] ;
995
998
fileInfos : readonly ProgramMultiFileEmitBuildInfoFileInfo [ ] ;
996
999
root : readonly ProgramBuildInfoRoot [ ] ;
1000
+ resolvedRoot : readonly ProgramBuildInfoResolvedRoot [ ] | undefined ;
997
1001
options : CompilerOptions | undefined ;
998
1002
fileIdsList : readonly ( readonly ProgramBuildInfoFileId [ ] ) [ ] | undefined ;
999
1003
referencedMap : ProgramBuildInfoReferencedMap | undefined ;
@@ -1023,6 +1027,7 @@ export interface ProgramBundleEmitBuildInfo {
1023
1027
fileNames : readonly string [ ] ;
1024
1028
fileInfos : readonly ProgramBundleEmitBuildInfoFileInfo [ ] ;
1025
1029
root : readonly ProgramBuildInfoRoot [ ] ;
1030
+ resolvedRoot : readonly ProgramBuildInfoResolvedRoot [ ] | undefined ;
1026
1031
options : CompilerOptions | undefined ;
1027
1032
outSignature : EmitSignature | undefined ;
1028
1033
latestChangedDtsFile : string | undefined ;
@@ -1047,6 +1052,7 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
1047
1052
const latestChangedDtsFile = state . latestChangedDtsFile ? relativeToBuildInfoEnsuringAbsolutePath ( state . latestChangedDtsFile ) : undefined ;
1048
1053
const fileNames : string [ ] = [ ] ;
1049
1054
const fileNameToFileId = new Map < string , ProgramBuildInfoFileId > ( ) ;
1055
+ const rootFileNames = new Set ( state . program ! . getRootFileNames ( ) . map ( f => toPath ( f , currentDirectory , state . program ! . getCanonicalFileName ) ) ) ;
1050
1056
const root : ProgramBuildInfoRoot [ ] = [ ] ;
1051
1057
if ( state . compilerOptions . outFile ) {
1052
1058
// Copy all fileInfo, version and impliedFormat
@@ -1063,6 +1069,7 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
1063
1069
fileNames,
1064
1070
fileInfos,
1065
1071
root,
1072
+ resolvedRoot : toResolvedRoot ( ) ,
1066
1073
options : convertToProgramBuildInfoCompilerOptions ( state . compilerOptions ) ,
1067
1074
outSignature : state . outSignature ,
1068
1075
latestChangedDtsFile,
@@ -1090,7 +1097,8 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
1090
1097
if ( ! isJsonSourceFile ( file ) && sourceFileMayBeEmitted ( file , state . program ! ) ) {
1091
1098
const emitSignature = state . emitSignatures ?. get ( key ) ;
1092
1099
if ( emitSignature !== actualSignature ) {
1093
- ( emitSignatures ||= [ ] ) . push (
1100
+ emitSignatures = append (
1101
+ emitSignatures ,
1094
1102
emitSignature === undefined ?
1095
1103
fileId : // There is no emit, encode as false
1096
1104
// fileId, signature: emptyArray if signature only differs in dtsMap option than our own compilerOptions otherwise EmitSignature
@@ -1133,7 +1141,8 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
1133
1141
const file = state . program ! . getSourceFileByPath ( path ) ;
1134
1142
if ( ! file || ! sourceFileMayBeEmitted ( file , state . program ! ) ) continue ;
1135
1143
const fileId = toFileId ( path ) , pendingEmit = state . affectedFilesPendingEmit . get ( path ) ! ;
1136
- ( affectedFilesPendingEmit ||= [ ] ) . push (
1144
+ affectedFilesPendingEmit = append (
1145
+ affectedFilesPendingEmit ,
1137
1146
pendingEmit === fullEmitForOptions ?
1138
1147
fileId : // Pending full emit per options
1139
1148
pendingEmit === BuilderFileEmit . Dts ?
@@ -1147,14 +1156,15 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
1147
1156
let changeFileSet : ProgramBuildInfoFileId [ ] | undefined ;
1148
1157
if ( state . changedFilesSet . size ) {
1149
1158
for ( const path of arrayFrom ( state . changedFilesSet . keys ( ) ) . sort ( compareStringsCaseSensitive ) ) {
1150
- ( changeFileSet ||= [ ] ) . push ( toFileId ( path ) ) ;
1159
+ changeFileSet = append ( changeFileSet , toFileId ( path ) ) ;
1151
1160
}
1152
1161
}
1153
1162
const emitDiagnosticsPerFile = convertToProgramBuildInfoDiagnostics ( state . emitDiagnosticsPerFile ) ;
1154
1163
const program : ProgramMultiFileEmitBuildInfo = {
1155
1164
fileNames,
1156
1165
fileInfos,
1157
1166
root,
1167
+ resolvedRoot : toResolvedRoot ( ) ,
1158
1168
options : convertToProgramBuildInfoCompilerOptions ( state . compilerOptions ) ,
1159
1169
fileIdsList,
1160
1170
referencedMap,
@@ -1189,8 +1199,8 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
1189
1199
const key = fileIds . join ( ) ;
1190
1200
let fileIdListId = fileNamesToFileIdListId ?. get ( key ) ;
1191
1201
if ( fileIdListId === undefined ) {
1192
- ( fileIdsList ||= [ ] ) . push ( fileIds ) ;
1193
- ( fileNamesToFileIdListId || = new Map ( ) ) . set ( key , fileIdListId = fileIdsList . length as ProgramBuildInfoFileIdListId ) ;
1202
+ fileIdsList = append ( fileIdsList , fileIds ) ;
1203
+ ( fileNamesToFileIdListId ?? = new Map ( ) ) . set ( key , fileIdListId = fileIdsList . length as ProgramBuildInfoFileIdListId ) ;
1194
1204
}
1195
1205
return fileIdListId ;
1196
1206
}
@@ -1214,6 +1224,17 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
1214
1224
return root . length = root . length - 1 ;
1215
1225
}
1216
1226
1227
+ function toResolvedRoot ( ) : ProgramBuildInfoResolvedRoot [ ] | undefined {
1228
+ let result : ProgramBuildInfoResolvedRoot [ ] | undefined ;
1229
+ rootFileNames . forEach ( path => {
1230
+ const file = state . program ! . getSourceFileByPath ( path ) ;
1231
+ if ( file && path !== file . resolvedPath ) {
1232
+ result = append ( result , [ toFileId ( file . resolvedPath ) , toFileId ( path ) ] ) ;
1233
+ }
1234
+ } ) ;
1235
+ return result ;
1236
+ }
1237
+
1217
1238
/**
1218
1239
* @param optionKey key of CommandLineOption to use to determine if the option should be serialized in tsbuildinfo
1219
1240
*/
@@ -1253,7 +1274,8 @@ function getBuildInfo(state: BuilderProgramState): BuildInfo {
1253
1274
if ( diagnostics ) {
1254
1275
for ( const key of arrayFrom ( diagnostics . keys ( ) ) . sort ( compareStringsCaseSensitive ) ) {
1255
1276
const value = diagnostics . get ( key ) ! ;
1256
- ( result ||= [ ] ) . push (
1277
+ result = append (
1278
+ result ,
1257
1279
value . length ?
1258
1280
[
1259
1281
toFileId ( key ) ,
@@ -1909,7 +1931,9 @@ export function getBuildInfoFileVersionMap(
1909
1931
const getCanonicalFileName = createGetCanonicalFileName ( host . useCaseSensitiveFileNames ( ) ) ;
1910
1932
const fileInfos = new Map < Path , string > ( ) ;
1911
1933
let rootIndex = 0 ;
1912
- const roots : Path [ ] = [ ] ;
1934
+ // Root name to resolved
1935
+ const roots = new Map < Path , Path | undefined > ( ) ;
1936
+ const resolvedRoots = new Map ( program . resolvedRoot ) ;
1913
1937
program . fileInfos . forEach ( ( fileInfo , index ) => {
1914
1938
const path = toPath ( program . fileNames [ index ] , buildInfoDirectory , getCanonicalFileName ) ;
1915
1939
const version = isString ( fileInfo ) ? fileInfo : fileInfo . version ;
@@ -1919,17 +1943,27 @@ export function getBuildInfoFileVersionMap(
1919
1943
const fileId = ( index + 1 ) as ProgramBuildInfoFileId ;
1920
1944
if ( isArray ( current ) ) {
1921
1945
if ( current [ 0 ] <= fileId && fileId <= current [ 1 ] ) {
1922
- roots . push ( path ) ;
1946
+ addRoot ( fileId , path ) ;
1923
1947
if ( current [ 1 ] === fileId ) rootIndex ++ ;
1924
1948
}
1925
1949
}
1926
1950
else if ( current === fileId ) {
1927
- roots . push ( path ) ;
1951
+ addRoot ( fileId , path ) ;
1928
1952
rootIndex ++ ;
1929
1953
}
1930
1954
}
1931
1955
} ) ;
1932
1956
return { fileInfos, roots } ;
1957
+
1958
+ function addRoot ( fileId : ProgramBuildInfoFileId , path : Path ) {
1959
+ const root = resolvedRoots . get ( fileId ) ;
1960
+ if ( root ) {
1961
+ roots . set ( toPath ( program . fileNames [ root - 1 ] , buildInfoDirectory , getCanonicalFileName ) , path ) ;
1962
+ }
1963
+ else {
1964
+ roots . set ( path , undefined ) ;
1965
+ }
1966
+ }
1933
1967
}
1934
1968
1935
1969
/** @internal */
0 commit comments