Fixing unit tests, lint errors & addressing CR feedback
This commit is contained in:
parent
511b3cd69b
commit
798232c975
|
@ -4,7 +4,8 @@
|
|||
|
||||
namespace ts.projectSystem {
|
||||
describe("typings installer", () => {
|
||||
it("configured projects (tsd installed) 1", () => {
|
||||
it("configured projects (typings installed) 1", () => {
|
||||
debugger;
|
||||
const file1 = {
|
||||
path: "/a/b/app.js",
|
||||
content: ""
|
||||
|
@ -31,7 +32,7 @@ namespace ts.projectSystem {
|
|||
};
|
||||
|
||||
const jquery = {
|
||||
path: "/a/data/typings/jquery/jquery.d.ts",
|
||||
path: "/a/data/node_modules/@types/jquery/index.d.ts",
|
||||
content: "declare const $: { x: number }"
|
||||
};
|
||||
|
||||
|
@ -44,18 +45,18 @@ namespace ts.projectSystem {
|
|||
const p = projectService.configuredProjects[0];
|
||||
checkProjectActualFiles(p, [file1.path]);
|
||||
|
||||
assert(host.fileExists(combinePaths(installer.globalTypingsCacheLocation, "tsd.json")));
|
||||
assert(host.fileExists(combinePaths(installer.globalTypingsCacheLocation, "package.json")));
|
||||
|
||||
installer.runPostInstallActions(t => {
|
||||
assert.deepEqual(t, ["jquery"]);
|
||||
host.createFileOrFolder(jquery, /*createParentDirectory*/ true);
|
||||
return ["jquery/jquery.d.ts"];
|
||||
return ["@types/jquery"];
|
||||
});
|
||||
checkNumberOfProjects(projectService, { configuredProjects: 1 });
|
||||
checkProjectActualFiles(p, [file1.path, jquery.path]);
|
||||
});
|
||||
|
||||
it("inferred project (tsd installed)", () => {
|
||||
it("inferred project (typings installed)", () => {
|
||||
const file1 = {
|
||||
path: "/a/b/app.js",
|
||||
content: ""
|
||||
|
@ -71,7 +72,7 @@ namespace ts.projectSystem {
|
|||
};
|
||||
|
||||
const jquery = {
|
||||
path: "/a/data/typings/jquery/jquery.d.ts",
|
||||
path: "/a/data/node_modules/@types/jquery/index.d.ts",
|
||||
content: "declare const $: { x: number }"
|
||||
};
|
||||
const host = createServerHost([file1, packageJson]);
|
||||
|
@ -84,12 +85,12 @@ namespace ts.projectSystem {
|
|||
const p = projectService.inferredProjects[0];
|
||||
checkProjectActualFiles(p, [file1.path]);
|
||||
|
||||
assert(host.fileExists(combinePaths(installer.globalTypingsCacheLocation, "tsd.json")));
|
||||
assert(host.fileExists(combinePaths(installer.globalTypingsCacheLocation, "package.json")));
|
||||
|
||||
installer.runPostInstallActions(t => {
|
||||
assert.deepEqual(t, ["jquery"]);
|
||||
host.createFileOrFolder(jquery, /*createParentDirectory*/ true);
|
||||
return ["jquery/jquery.d.ts"];
|
||||
return ["@types/jquery"];
|
||||
});
|
||||
checkNumberOfProjects(projectService, { inferredProjects: 1 });
|
||||
checkProjectActualFiles(p, [file1.path, jquery.path]);
|
||||
|
@ -166,7 +167,7 @@ namespace ts.projectSystem {
|
|||
enqueueIsCalled = true;
|
||||
super.enqueueInstallTypingsRequest(project, typingOptions);
|
||||
}
|
||||
runTsd(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void {
|
||||
runInstall(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void {
|
||||
assert.deepEqual(typingsToInstall, ["node"]);
|
||||
runInstallIsCalled = true;
|
||||
super.runInstall(cachePath, typingsToInstall, postInstallAction);
|
||||
|
|
|
@ -93,58 +93,58 @@ namespace ts.server.typingsInstaller {
|
|||
const id = this.installRunCount;
|
||||
this.installRunCount++;
|
||||
let execInstallCmdCount = 0;
|
||||
let filteredTypings: string[] = [];
|
||||
const filteredTypings: string[] = [];
|
||||
for (const typing of typingsToInstall) {
|
||||
const command = `npm view @types/${typing} --silent name`;
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Running npm view @types ${id}, command '${command}'.`);
|
||||
}
|
||||
this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => {
|
||||
execInstallCmdCount++;
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`);
|
||||
this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`);
|
||||
}
|
||||
if (stdout !== "") {
|
||||
this.execAsync("npm view", command, cachePath, id, (err, stdout, stderr) => {
|
||||
if (stdout) {
|
||||
filteredTypings.push(typing);
|
||||
}
|
||||
if (execInstallCmdCount >= typingsToInstall.length) {
|
||||
const command = `npm install ${filteredTypings.map(t => "@types/" + t).join(" ")} --save-dev`;
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Running npm install @types ${id}, command '${command}'. cache path '${cachePath}'`);
|
||||
}
|
||||
this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`);
|
||||
this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`);
|
||||
}
|
||||
if (stdout === "") {
|
||||
return;
|
||||
}
|
||||
const command = "npm ls -json";
|
||||
this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm ls -json ${id} stdout: ${stdout}`);
|
||||
this.log.writeLine(`npm ls -json ${id} stderr: ${stderr}`);
|
||||
}
|
||||
const installedTypings: string[] = [];
|
||||
try {
|
||||
const response = JSON.parse(stdout);
|
||||
if (response.dependencies) {
|
||||
for (const typing in response.dependencies) {
|
||||
installedTypings.push(typing);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
this.log.writeLine(`Error parsing installed @types dependencies. Error details: ${e.message}`);
|
||||
}
|
||||
postInstallAction(installedTypings);
|
||||
});
|
||||
});
|
||||
execInstallCmdCount++;
|
||||
if (execInstallCmdCount === typingsToInstall.length) {
|
||||
installFilteredTypings(this, filteredTypings);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function installFilteredTypings(self: NodeTypingsInstaller, filteredTypings: string[]) {
|
||||
const command = `npm install ${filteredTypings.map(t => "@types/" + t).join(" ")} --save-dev`;
|
||||
self.execAsync("npm install", command, cachePath, id, (err, stdout, stderr) => {
|
||||
if (stdout) {
|
||||
reportInstalledTypings(self);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function reportInstalledTypings(self: NodeTypingsInstaller) {
|
||||
const command = "npm ls -json";
|
||||
self.execAsync("npm ls", command, cachePath, id, (err, stdout, stderr) => {
|
||||
let installedTypings: string[];
|
||||
try {
|
||||
const response = JSON.parse(stdout);
|
||||
if (response.dependencies) {
|
||||
installedTypings = getOwnKeys(response.dependencies);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
self.log.writeLine(`Error parsing installed @types dependencies. Error details: ${e.message}`);
|
||||
}
|
||||
postInstallAction(installedTypings || []);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private execAsync(prefix: string, command: string, cwd: string, requestId: number, cb: (err: Error, stdout: string, stderr: string) => void) {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`#${requestId} running command '${command}'.`);
|
||||
}
|
||||
this.exec(command, { cwd }, (err, stdout, stderr) => {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`${prefix} #${requestId} stdout: ${stdout}`);
|
||||
this.log.writeLine(`${prefix} #${requestId} stderr: ${stderr}`);
|
||||
}
|
||||
cb(err, stdout, stderr);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ namespace ts.server.typingsInstaller {
|
|||
if (!packageName) {
|
||||
continue;
|
||||
}
|
||||
var typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost);
|
||||
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost);
|
||||
if (!typingFile) {
|
||||
continue;
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ namespace ts.server.typingsInstaller {
|
|||
continue;
|
||||
}
|
||||
installedPackages[packageName] = true;
|
||||
var typingFile = typingToFileName(cachePath, packageName, this.installTypingHost);
|
||||
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost);
|
||||
if (!typingFile) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue