Skip to content

Commit a21f73f

Browse files
Remove timestamp checking and move registry check into jstyping
1 parent e72ea6f commit a21f73f

File tree

5 files changed

+46
-123
lines changed

5 files changed

+46
-123
lines changed

src/harness/unittests/typingsInstaller.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,16 +1081,6 @@ namespace ts.projectSystem {
10811081
}
10821082
})
10831083
};
1084-
const date = new Date();
1085-
date.setFullYear(date.getFullYear() - 1);
1086-
const timestamps = {
1087-
path: "/a/data/timestamps.json",
1088-
content: JSON.stringify({
1089-
entries: {
1090-
"@types/jquery": date.getTime()
1091-
}
1092-
})
1093-
};
10941084
const jquery = {
10951085
path: "/a/data/node_modules/@types/jquery/index.d.ts",
10961086
content: "declare const $: { x: number }"
@@ -1102,11 +1092,21 @@ namespace ts.projectSystem {
11021092
"types-registry": "^0.1.317"
11031093
},
11041094
devDependencies: {
1105-
"@types/jquery": "^3.2.16"
1095+
"@types/jquery": "^1.0.0"
1096+
}
1097+
})
1098+
};
1099+
const cacheLockConfig = {
1100+
path: "/a/data/package-lock.json",
1101+
content: JSON.stringify({
1102+
dependencies: {
1103+
"@types/jquery": {
1104+
version: "1.0.0"
1105+
}
11061106
}
11071107
})
11081108
};
1109-
const host = createServerHost([file1, packageJson, jquery, timestamps, cacheConfig]);
1109+
const host = createServerHost([file1, packageJson, jquery, cacheConfig, cacheLockConfig]);
11101110
const installer = new (class extends Installer {
11111111
constructor() {
11121112
super(host, { typesRegistry: createTypesRegistry("jquery") });
@@ -1129,7 +1129,6 @@ namespace ts.projectSystem {
11291129

11301130
checkNumberOfProjects(projectService, { inferredProjects: 1 });
11311131
checkProjectActualFiles(p, [file1.path, jquery.path]);
1132-
assert(host.readFile(timestamps.path) !== JSON.stringify({ entries: { "@types/jquery": date.getTime() } }), "timestamps content should be updated");
11331132
});
11341133

11351134
it("non-expired cache entry (inferred project, should not install typings)", () => {
@@ -1282,7 +1281,7 @@ namespace ts.projectSystem {
12821281

12831282
const host = createServerHost([app, jquery, chroma]);
12841283
const logger = trackingLogger();
1285-
const result = JsTyping.discoverTypings(host, logger.log, [app.path, jquery.path, chroma.path], getDirectoryPath(<Path>app.path), safeList, emptyMap, { enable: true }, emptyArray);
1284+
const result = JsTyping.discoverTypings(host, logger.log, [app.path, jquery.path, chroma.path], getDirectoryPath(<Path>app.path), safeList, emptyMap, { enable: true }, emptyArray, emptyMap);
12861285
const finish = logger.finish();
12871286
assert.deepEqual(finish, [
12881287
'Inferred typings from file names: ["jquery","chroma-js"]',
@@ -1302,7 +1301,7 @@ namespace ts.projectSystem {
13021301

13031302
for (const name of JsTyping.nodeCoreModuleList) {
13041303
const logger = trackingLogger();
1305-
const result = JsTyping.discoverTypings(host, logger.log, [f.path], getDirectoryPath(<Path>f.path), emptySafeList, cache, { enable: true }, [name, "somename"]);
1304+
const result = JsTyping.discoverTypings(host, logger.log, [f.path], getDirectoryPath(<Path>f.path), emptySafeList, cache, { enable: true }, [name, "somename"], emptyMap);
13061305
assert.deepEqual(logger.finish(), [
13071306
'Inferred typings from unresolved imports: ["node","somename"]',
13081307
'Result: {"cachedTypingPaths":[],"newTypingNames":["node","somename"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}',
@@ -1321,9 +1320,10 @@ namespace ts.projectSystem {
13211320
content: ""
13221321
};
13231322
const host = createServerHost([f, node]);
1324-
const cache = createMapFromTemplate<JsTyping.CachedTyping>({ node: { typingLocation: node.path, timestamp: Date.now(), version: new Semver(1, 0, 0, /*isPrerelease*/ false) } });
1323+
const cache = createMapFromTemplate<JsTyping.CachedTyping>({ node: { typingLocation: node.path, version: new Semver(1, 3, 0, /*isPrerelease*/ false) } });
1324+
const registry = createTypesRegistry("node");
13251325
const logger = trackingLogger();
1326-
const result = JsTyping.discoverTypings(host, logger.log, [f.path], getDirectoryPath(<Path>f.path), emptySafeList, cache, { enable: true }, ["fs", "bar"]);
1326+
const result = JsTyping.discoverTypings(host, logger.log, [f.path], getDirectoryPath(<Path>f.path), emptySafeList, cache, { enable: true }, ["fs", "bar"], registry);
13271327
assert.deepEqual(logger.finish(), [
13281328
'Inferred typings from unresolved imports: ["node","bar"]',
13291329
'Result: {"cachedTypingPaths":["/a/b/node.d.ts"],"newTypingNames":["bar"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}',
@@ -1348,7 +1348,7 @@ namespace ts.projectSystem {
13481348
const host = createServerHost([app, a, b]);
13491349
const cache = createMap<JsTyping.CachedTyping>();
13501350
const logger = trackingLogger();
1351-
const result = JsTyping.discoverTypings(host, logger.log, [app.path], getDirectoryPath(<Path>app.path), emptySafeList, cache, { enable: true }, /*unresolvedImports*/ []);
1351+
const result = JsTyping.discoverTypings(host, logger.log, [app.path], getDirectoryPath(<Path>app.path), emptySafeList, cache, { enable: true }, /*unresolvedImports*/ [], emptyMap);
13521352
assert.deepEqual(logger.finish(), [
13531353
'Searching for typing names in /node_modules; all files: ["/node_modules/a/package.json"]',
13541354
' Found package names: ["a"]',
@@ -1363,9 +1363,6 @@ namespace ts.projectSystem {
13631363
});
13641364

13651365
it("should install expired typings", () => {
1366-
const date = new Date();
1367-
date.setFullYear(date.getFullYear() - 1);
1368-
13691366
const app = {
13701367
path: "/a/app.js",
13711368
content: ""
@@ -1381,11 +1378,12 @@ namespace ts.projectSystem {
13811378
};
13821379
const host = createServerHost([app]);
13831380
const cache = createMapFromTemplate<JsTyping.CachedTyping>({
1384-
node: { typingLocation: node.path, timestamp: Date.now(), version: new Semver(1, 0, 0, /*isPrerelease*/ false) },
1385-
commander: { typingLocation: commander.path, timestamp: date.getTime(), version: new Semver(1, 0, 0, /*isPrerelease*/ false) }
1381+
node: { typingLocation: node.path, version: new Semver(1, 3, 0, /*isPrerelease*/ false) },
1382+
commander: { typingLocation: commander.path, version: new Semver(1, 0, 0, /*isPrerelease*/ false) }
13861383
});
1384+
const registry = createTypesRegistry("node", "commander");
13871385
const logger = trackingLogger();
1388-
const result = JsTyping.discoverTypings(host, logger.log, [app.path], getDirectoryPath(<Path>app.path), emptySafeList, cache, { enable: true }, ["http", "commander"]);
1386+
const result = JsTyping.discoverTypings(host, logger.log, [app.path], getDirectoryPath(<Path>app.path), emptySafeList, cache, { enable: true }, ["http", "commander"], registry);
13891387
assert.deepEqual(logger.finish(), [
13901388
'Inferred typings from unresolved imports: ["node","commander"]',
13911389
'Result: {"cachedTypingPaths":["/a/cache/node_modules/@types/node/index.d.ts"],"newTypingNames":["commander"],"filesToWatch":["/a/bower_components","/a/node_modules"]}',

src/server/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,5 @@ declare namespace ts.server {
128128
writeFile(path: string, content: string): void;
129129
createDirectory(path: string): void;
130130
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
131-
getModifiedTime?(path: string): Date;
132131
}
133132
}

0 commit comments

Comments
 (0)