Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6a16cfe

Browse filesBrowse files
Use existing map to hold representations of timestamp files
1 parent 7b6be11 commit 6a16cfe
Copy full SHA for 6a16cfe

1 file changed

+15-16Lines changed: 15 additions & 16 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/server/typingsInstaller/typingsInstaller.ts‎

Copy file name to clipboardExpand all lines: src/server/typingsInstaller/typingsInstaller.ts
+15-16Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ namespace ts.server.typingsInstaller {
1919
writeLine: noop
2020
};
2121

22-
const timestampsFileName = "timestamps.json";
23-
2422
function typingToFileName(cachePath: string, packageName: string, installTypingHost: InstallTypingHost, log: Log): string {
2523
try {
2624
const result = resolveModuleName(packageName, combinePaths(cachePath, "index.d.ts"), { moduleResolution: ModuleResolutionKind.NodeJs }, installTypingHost);
@@ -43,12 +41,14 @@ namespace ts.server.typingsInstaller {
4341
onRequestCompleted: RequestCompletedAction;
4442
}
4543

44+
const timestampsFileName = "timestamps.json";
45+
type TypingsTimestamps = MapLike<number>;
4646
interface TypeDeclarationTimestampFile {
4747
// entries maps from package names (e.g. "@types/node") to timestamp values (as produced by Date#getTime)
48-
entries: MapLike<number>;
48+
entries: TypingsTimestamps;
4949
}
5050

51-
function loadTypeDeclarationTimestampFile(typeDeclarationTimestampFilePath: string, host: InstallTypingHost, log: Log): MapLike<number> {
51+
function loadTypeDeclarationTimestampFile(typeDeclarationTimestampFilePath: string, host: InstallTypingHost, log: Log): TypingsTimestamps {
5252
try {
5353
if (log.isEnabled()) {
5454
log.writeLine("Loading type declaration timestamp file.");
@@ -82,11 +82,10 @@ namespace ts.server.typingsInstaller {
8282
export abstract class TypingsInstaller {
8383
private readonly packageNameToTypingLocation: Map<JsTyping.CachedTyping> = createMap<JsTyping.CachedTyping>();
8484
private readonly missingTypingsSet: Map<true> = createMap<true>();
85-
private readonly knownCachesSet: Map<true> = createMap<true>();
85+
private readonly knownCacheToTimestamps: Map<TypingsTimestamps> = createMap<TypingsTimestamps>();
8686
private readonly projectWatchers: Map<FileWatcher[]> = createMap<FileWatcher[]>();
8787
private safeList: JsTyping.SafeList | undefined;
8888
readonly pendingRunRequests: PendingRequest[] = [];
89-
private globalTypeDeclarationTimestamps: MapLike<number> = {};
9089

9190
private installRunCount = 1;
9291
private inFlightRequestCount = 0;
@@ -103,7 +102,7 @@ namespace ts.server.typingsInstaller {
103102
if (this.log.isEnabled()) {
104103
this.log.writeLine(`Global cache location '${globalCachePath}', safe file path '${safeListPath}', types map path ${typesMapLocation}`);
105104
}
106-
this.globalTypeDeclarationTimestamps = this.processCacheLocation(this.globalCachePath);
105+
this.processCacheLocation(this.globalCachePath);
107106
}
108107

109108
closeProject(req: CloseProject) {
@@ -139,12 +138,11 @@ namespace ts.server.typingsInstaller {
139138

140139
// load existing typing information from the cache
141140
const timestampsFilePath = combinePaths(req.cachePath || this.globalCachePath, timestampsFileName);
142-
let localTimestamps: MapLike<number>;
143141
if (req.cachePath) {
144142
if (this.log.isEnabled()) {
145143
this.log.writeLine(`Request specifies cache path '${req.cachePath}', loading cached information...`);
146144
}
147-
localTimestamps = this.processCacheLocation(req.cachePath, timestampsFilePath);
145+
this.processCacheLocation(req.cachePath, timestampsFilePath);
148146
}
149147

150148
if (this.safeList === undefined) {
@@ -169,7 +167,7 @@ namespace ts.server.typingsInstaller {
169167

170168
// install typings
171169
if (discoverTypingsResult.newTypingNames.length) {
172-
this.installTypings(req, req.cachePath || this.globalCachePath, discoverTypingsResult.cachedTypingPaths, discoverTypingsResult.newTypingNames, timestampsFilePath, localTimestamps || this.globalTypeDeclarationTimestamps);
170+
this.installTypings(req, req.cachePath || this.globalCachePath, discoverTypingsResult.cachedTypingPaths, discoverTypingsResult.newTypingNames, timestampsFilePath);
173171
}
174172
else {
175173
this.sendResponse(this.createSetTypings(req, discoverTypingsResult.cachedTypingPaths));
@@ -193,17 +191,17 @@ namespace ts.server.typingsInstaller {
193191
this.safeList = JsTyping.loadSafeList(this.installTypingHost, this.safeListPath);
194192
}
195193

196-
private processCacheLocation(cacheLocation: string, timestampsFilePath?: string): MapLike<number> {
194+
private processCacheLocation(cacheLocation: string, timestampsFilePath?: string) {
197195
if (this.log.isEnabled()) {
198196
this.log.writeLine(`Processing cache location '${cacheLocation}'`);
199197
}
200-
if (this.knownCachesSet.get(cacheLocation)) {
198+
if (this.knownCacheToTimestamps.has(cacheLocation)) {
201199
if (this.log.isEnabled()) {
202200
this.log.writeLine(`Cache location was already processed...`);
203201
}
204202
return;
205203
}
206-
const typeDeclarationTimestamps: MapLike<number> = loadTypeDeclarationTimestampFile(timestampsFilePath || combinePaths(cacheLocation, timestampsFileName), this.installTypingHost, this.log);
204+
const typeDeclarationTimestamps = loadTypeDeclarationTimestampFile(timestampsFilePath || combinePaths(cacheLocation, timestampsFileName), this.installTypingHost, this.log);
207205
const packageJson = combinePaths(cacheLocation, "package.json");
208206
if (this.log.isEnabled()) {
209207
this.log.writeLine(`Trying to find '${packageJson}'...`);
@@ -256,8 +254,7 @@ namespace ts.server.typingsInstaller {
256254
if (this.log.isEnabled()) {
257255
this.log.writeLine(`Finished processing cache location '${cacheLocation}'`);
258256
}
259-
this.knownCachesSet.set(cacheLocation, true);
260-
return typeDeclarationTimestamps;
257+
this.knownCacheToTimestamps.set(cacheLocation, typeDeclarationTimestamps);
261258
}
262259

263260
private filterTypings(typingsToInstall: ReadonlyArray<string>): ReadonlyArray<string> {
@@ -299,7 +296,7 @@ namespace ts.server.typingsInstaller {
299296
}
300297
}
301298

302-
private installTypings(req: DiscoverTypings, cachePath: string, currentlyCachedTypings: string[], typingsToInstall: string[], timestampsFilePath: string, typeDeclarationTimestamps: MapLike<number>) {
299+
private installTypings(req: DiscoverTypings, cachePath: string, currentlyCachedTypings: string[], typingsToInstall: string[], timestampsFilePath: string) {
303300
if (this.log.isEnabled()) {
304301
this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`);
305302
}
@@ -342,6 +339,7 @@ namespace ts.server.typingsInstaller {
342339
if (this.log.isEnabled()) {
343340
this.log.writeLine(`Installed typings ${JSON.stringify(scopedTypings)}`);
344341
}
342+
const typeDeclarationTimestamps = this.knownCacheToTimestamps.get(cachePath);
345343
const installedTypingFiles: string[] = [];
346344
const typesPackageName = (packageName: string) => `@types/${packageName}`;
347345
for (const packageName of filteredTypings) {
@@ -363,6 +361,7 @@ namespace ts.server.typingsInstaller {
363361

364362
const newFileContents: TypeDeclarationTimestampFile = { entries: typeDeclarationTimestamps };
365363
writeTypeDeclarationTimestampFile(timestampsFilePath, newFileContents, this.installTypingHost, this.log);
364+
this.knownCacheToTimestamps.set(cachePath, typeDeclarationTimestamps);
366365

367366
this.sendResponse(this.createSetTypings(req, currentlyCachedTypings.concat(installedTypingFiles)));
368367
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.