Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ desc("Runs the tests using the built run.js file like 'jake runtests'. Syntax is
task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFileInBrowserTest], function () {
cleanTestDirs();
host = "node";
browser = process.env.browser || process.env.b || "IE";
browser = process.env.browser || process.env.b || (os.platform() === "linux" ? "chrome" : "IE");
tests = process.env.test || process.env.tests || process.env.t;
var light = process.env.light || false;
var testConfigFile = 'test.config';
Expand Down
50 changes: 49 additions & 1 deletion src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ namespace ts.projectSystem {
content: JSON.stringify({ compilerOptions: { allowJs: true }, exclude: ["node_modules"] })
};
const host = createServerHost([f1, barjs, barTypings, config]);
const projectService = createProjectService(host, { typingsInstaller: new TestTypingsInstaller(typingsCacheLocation, host) });
const projectService = createProjectService(host, { typingsInstaller: new TestTypingsInstaller(typingsCacheLocation, /*throttleLimit*/ 5, host) });

projectService.openClientFile(f1.path);
projectService.checkNumberOfProjects({ configuredProjects: 1 });
Expand Down Expand Up @@ -1987,4 +1987,52 @@ namespace ts.projectSystem {
assert.deepEqual(s3, newPerFileSettings, "file settings should still be the same with per-file settings");
});
});

describe("watching @types", () => {
it("works correctly when typings are added or removed", () => {
const f1 = {
path: "/a/b/app.ts",
content: "let x = 1;"
};
const t1 = {
path: "/a/b/node_modules/@types/lib1/index.d.ts",
content: "export let a: number"
};
const t2 = {
path: "/a/b/node_modules/@types/lib2/index.d.ts",
content: "export let b: number"
};
const tsconfig = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({
compilerOptions: {},
exclude: ["node_modules"]
})
};
const host = createServerHost([f1, t1, tsconfig]);
const projectService = createProjectService(host);

projectService.openClientFile(f1.path);
projectService.checkNumberOfProjects({ configuredProjects: 1 });
checkProjectActualFiles(projectService.configuredProjects[0], [f1.path, t1.path]);

// delete t1
host.reloadFS([f1, tsconfig]);
host.triggerDirectoryWatcherCallback("/a/b/node_modules/@types", "lib1");
// run throttled operation
host.runQueuedTimeoutCallbacks();

projectService.checkNumberOfProjects({ configuredProjects: 1 });
checkProjectActualFiles(projectService.configuredProjects[0], [f1.path]);

// create t2
host.reloadFS([f1, tsconfig, t2]);
host.triggerDirectoryWatcherCallback("/a/b/node_modules/@types", "lib2");
// run throttled operation
host.runQueuedTimeoutCallbacks();

projectService.checkNumberOfProjects({ configuredProjects: 1 });
checkProjectActualFiles(projectService.configuredProjects[0], [f1.path, t2.path]);
});
});
}
14 changes: 7 additions & 7 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3154,6 +3154,13 @@ namespace ts {
}
}

const typeRootsVersion = host.getTypeRootsVersion ? host.getTypeRootsVersion() : 0;
if (lastTypesRootVersion !== typeRootsVersion) {
log("TypeRoots version has changed; provide new program");
program = undefined;
lastTypesRootVersion = typeRootsVersion;
}

// Get a fresh cache of the host information
let hostCache = new HostCache(host, getCanonicalFileName);

Expand Down Expand Up @@ -3221,13 +3228,6 @@ namespace ts {
};
}

const typeRootsVersion = host.getTypeRootsVersion ? host.getTypeRootsVersion() : 0;
if (lastTypesRootVersion !== typeRootsVersion) {
log("TypeRoots version has changed; provide new program");
program = undefined;
lastTypesRootVersion = typeRootsVersion;
}

const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
const newProgram = createProgram(hostCache.getRootFileNames(), newSettings, compilerHost, program);

Expand Down