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 ee5e8e3

Browse filesBrowse files
Benjamin Lichtmanuniqueiniquity
authored andcommitted
Ensure proper JSON writing behavior of timestamps
1 parent 9d298a1 commit ee5e8e3
Copy full SHA for ee5e8e3

1 file changed

+13-13Lines changed: 13 additions & 13 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
+13-13Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace ts.server.typingsInstaller {
4545
entries: MapLike<number>;
4646
}
4747

48-
function loadTypeDeclarationTimestampFile(typeDeclarationTimestampFilePath: string, host: InstallTypingHost, log: Log): Map<number> {
48+
function loadTypeDeclarationTimestampFile(typeDeclarationTimestampFilePath: string, host: InstallTypingHost, log: Log): MapLike<number> {
4949
const fileExists = host.fileExists(typeDeclarationTimestampFilePath);
5050
if (!fileExists) {
5151
if (log.isEnabled()) {
@@ -55,21 +55,21 @@ namespace ts.server.typingsInstaller {
5555
try {
5656
if (fileExists) {
5757
const content = <TypeDeclarationTimestampFile>JSON.parse(host.readFile(typeDeclarationTimestampFilePath));
58-
return createMapFromTemplate(content.entries);
58+
return content.entries;
5959
}
6060
else {
6161
host.writeFile(typeDeclarationTimestampFilePath, "{}");
6262
if (log.isEnabled()) {
6363
log.writeLine("Type declaration timestamp file was created.");
6464
}
65-
return createMap<number>();
65+
return {};
6666
}
6767
}
6868
catch (e) {
6969
if (log.isEnabled()) {
7070
log.writeLine(`Error when loading type declaration timestamp file '${typeDeclarationTimestampFilePath}': ${(<Error>e).message}, ${(<Error>e).stack}`);
7171
}
72-
return createMap<number>();
72+
return {};
7373
}
7474
}
7575

@@ -108,7 +108,7 @@ namespace ts.server.typingsInstaller {
108108
private readonly projectWatchers: Map<FileWatcher[]> = createMap<FileWatcher[]>();
109109
private safeList: JsTyping.SafeList | undefined;
110110
readonly pendingRunRequests: PendingRequest[] = [];
111-
private typeDeclarationTimestamps: Map<number> = createMap<number>();
111+
private typeDeclarationTimestamps: MapLike<number> = {};
112112

113113
private installRunCount = 1;
114114
private inFlightRequestCount = 0;
@@ -258,14 +258,14 @@ namespace ts.server.typingsInstaller {
258258
if (this.log.isEnabled()) {
259259
this.log.writeLine(`Adding entry into typings cache: '${packageName}' => '${typingFile}'`);
260260
}
261-
if (this.typeDeclarationTimestamps.get(key) === undefined) {
261+
if (getProperty(this.typeDeclarationTimestamps, key) === undefined) {
262262
// getModifiedTime is only undefined if we were to use the ChakraHost, but we never do in this scenario
263263
// defaults to old behavior of never updating if we ever use a host without getModifiedTime in the future
264264
const timestamp = this.installTypingHost.getModifiedTime === undefined ? Date.now() : this.installTypingHost.getModifiedTime(typingFile).getTime();
265-
this.typeDeclarationTimestamps.set(key, timestamp);
265+
this.typeDeclarationTimestamps[key] = timestamp;
266266
}
267267
// timestamp guaranteed to not be undefined by above check
268-
const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, timestamp: this.typeDeclarationTimestamps.get(key) };
268+
const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, timestamp: getProperty(this.typeDeclarationTimestamps, key) };
269269
this.packageNameToTypingLocation.set(packageName, newTyping);
270270
}
271271
}
@@ -365,11 +365,11 @@ namespace ts.server.typingsInstaller {
365365
this.missingTypingsSet.set(packageName, true);
366366
continue;
367367
}
368-
if (!this.packageNameToTypingLocation.has(packageName)) {
369-
const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, timestamp: Date.now() };
370-
this.packageNameToTypingLocation.set(packageName, newTyping);
371-
this.typeDeclarationTimestamps.set(packageName, Date.now());
372-
}
368+
369+
const newTimestamp = Date.now();
370+
const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, timestamp: newTimestamp };
371+
this.packageNameToTypingLocation.set(packageName, newTyping);
372+
this.typeDeclarationTimestamps[packageName] = newTimestamp;
373373
installedTypingFiles.push(typingFile);
374374
}
375375
if (this.log.isEnabled()) {

0 commit comments

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