@@ -82,12 +82,20 @@ type TsconfigCacheData = {
82
82
hash : string ;
83
83
extendedFilesHash : string ;
84
84
} ;
85
+ type TsconfigCache = {
86
+ version : number ;
87
+ data : Record < string , TsconfigCacheData > ;
88
+ } ;
85
89
86
90
let ts : typeof import ( 'typescript' ) ;
87
91
const pmc = getPackageManagerCommand ( ) ;
88
92
89
- let tsConfigCache : Record < string , TsconfigCacheData > ;
90
- const tsConfigCachePath = join ( workspaceDataDirectory , 'tsconfig-files.hash' ) ;
93
+ const TSCONFIG_CACHE_VERSION = 1 ;
94
+ const TS_CONFIG_CACHE_PATH = join (
95
+ workspaceDataDirectory ,
96
+ 'tsconfig-files.hash'
97
+ ) ;
98
+ let tsConfigCacheData : Record < string , TsconfigCacheData > ;
91
99
let cache : {
92
100
fileHashes : Record < string , string > ;
93
101
rawFiles : Record < string , string > ;
@@ -103,10 +111,25 @@ function readFromCache<T extends object>(cachePath: string): T {
103
111
return { } as T ;
104
112
}
105
113
}
114
+ function readTsConfigCacheData ( ) : Record < string , TsconfigCacheData > {
115
+ const cache = readFromCache < TsconfigCache > ( TS_CONFIG_CACHE_PATH ) ;
116
+
117
+ if ( cache . version !== TSCONFIG_CACHE_VERSION ) {
118
+ return { } ;
119
+ }
120
+
121
+ return cache . data ;
122
+ }
106
123
107
124
function writeToCache < T extends object > ( cachePath : string , data : T ) {
108
125
writeJsonFile ( cachePath , data , { spaces : 0 } ) ;
109
126
}
127
+ function writeTsConfigCache ( data : Record < string , TsconfigCacheData > ) {
128
+ writeToCache ( TS_CONFIG_CACHE_PATH , {
129
+ version : TSCONFIG_CACHE_VERSION ,
130
+ data,
131
+ } ) ;
132
+ }
110
133
111
134
/**
112
135
* @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.
@@ -175,9 +198,8 @@ export const createNodesV2: CreateNodesV2<TscPluginOptions> = [
175
198
) ;
176
199
} finally {
177
200
writeToCache ( targetsCachePath , targetsCache ) ;
178
- writeToCache (
179
- tsConfigCachePath ,
180
- toRelativePaths ( tsConfigCache , context . workspaceRoot )
201
+ writeTsConfigCache (
202
+ toRelativePaths ( tsConfigCacheData , context . workspaceRoot )
181
203
) ;
182
204
}
183
205
} ,
@@ -208,9 +230,8 @@ export const createNodes: CreateNodes<TscPluginOptions> = [
208
230
context
209
231
) ;
210
232
211
- writeToCache (
212
- tsConfigCachePath ,
213
- toRelativePaths ( tsConfigCache , context . workspaceRoot )
233
+ writeTsConfigCache (
234
+ toRelativePaths ( tsConfigCacheData , context . workspaceRoot )
214
235
) ;
215
236
216
237
return {
@@ -1097,19 +1118,16 @@ function retrieveTsConfigFromCache(
1097
1118
1098
1119
// we don't need to check the hash if it's in the cache, because we've already
1099
1120
// checked it when we initially populated the cache
1100
- return tsConfigCache [ relativePath ]
1101
- ? tsConfigCache [ relativePath ] . data
1121
+ return tsConfigCacheData [ relativePath ]
1122
+ ? tsConfigCacheData [ relativePath ] . data
1102
1123
: readTsConfigAndCache ( tsConfigPath , workspaceRoot ) ;
1103
1124
}
1104
1125
1105
1126
function initializeTsConfigCache (
1106
1127
configFilePaths : readonly string [ ] ,
1107
1128
workspaceRoot : string
1108
1129
) : void {
1109
- tsConfigCache = toAbsolutePaths (
1110
- readFromCache < Record < string , TsconfigCacheData > > ( tsConfigCachePath ) ,
1111
- workspaceRoot
1112
- ) ;
1130
+ tsConfigCacheData = toAbsolutePaths ( readTsConfigCacheData ( ) , workspaceRoot ) ;
1113
1131
1114
1132
// ensure hashes are checked and the cache is invalidated and populated as needed
1115
1133
for ( const configFilePath of configFilePaths ) {
@@ -1127,15 +1145,17 @@ function readTsConfigAndCache(
1127
1145
1128
1146
let extendedFilesHash : string ;
1129
1147
if (
1130
- tsConfigCache [ relativePath ] &&
1131
- tsConfigCache [ relativePath ] . hash === hash
1148
+ tsConfigCacheData [ relativePath ] &&
1149
+ tsConfigCacheData [ relativePath ] . hash === hash
1132
1150
) {
1133
1151
extendedFilesHash = getExtendedFilesHash (
1134
- tsConfigCache [ relativePath ] . data . extendedConfigFiles ,
1152
+ tsConfigCacheData [ relativePath ] . data . extendedConfigFiles ,
1135
1153
workspaceRoot
1136
1154
) ;
1137
- if ( tsConfigCache [ relativePath ] . extendedFilesHash === extendedFilesHash ) {
1138
- return tsConfigCache [ relativePath ] . data ;
1155
+ if (
1156
+ tsConfigCacheData [ relativePath ] . extendedFilesHash === extendedFilesHash
1157
+ ) {
1158
+ return tsConfigCacheData [ relativePath ] . data ;
1139
1159
}
1140
1160
}
1141
1161
@@ -1161,7 +1181,7 @@ function readTsConfigAndCache(
1161
1181
workspaceRoot
1162
1182
) ;
1163
1183
1164
- tsConfigCache [ relativePath ] = {
1184
+ tsConfigCacheData [ relativePath ] = {
1165
1185
data : {
1166
1186
options : tsConfig . options ,
1167
1187
projectReferences : tsConfig . projectReferences ,
@@ -1172,7 +1192,7 @@ function readTsConfigAndCache(
1172
1192
extendedFilesHash,
1173
1193
} ;
1174
1194
1175
- return tsConfigCache [ relativePath ] . data ;
1195
+ return tsConfigCacheData [ relativePath ] . data ;
1176
1196
}
1177
1197
1178
1198
function getExtendedFilesHash (
0 commit comments