Install packages separately

This commit is contained in:
Jason Ramsay 2016-08-30 13:41:24 -07:00
parent 199e533059
commit 24ef426fbb
2 changed files with 31 additions and 16 deletions

View file

@ -312,7 +312,7 @@ namespace ts.server {
// - newProgram is different from the old program and structure of the old program was not reused.
if (!oldProgram || (this.program !== oldProgram && !oldProgram.structureIsReused)) {
hasChanges = true;
this.projectService.typingsCache.invalidateCachedTypingsForProject(this);
//this.projectService.typingsCache.invalidateCachedTypingsForProject(this);
if (oldProgram) {
for (const f of oldProgram.getSourceFiles()) {
if (this.program.getSourceFileByPath(f.path)) {
@ -405,16 +405,25 @@ namespace ts.server {
const added: string[] = [];
const removed: string[] = [];
let invalidateTypings = false;
for (const id in currentFiles) {
if (hasProperty(currentFiles, id) && !hasProperty(lastReportedFileNames, id)) {
added.push(id);
if (this.typingFiles.indexOf(id) < 0) {
invalidateTypings = true;
break;
}
}
}
for (const id in lastReportedFileNames) {
if (hasProperty(lastReportedFileNames, id) && !hasProperty(currentFiles, id)) {
removed.push(id);
invalidateTypings = true;
}
}
if (invalidateTypings) {
this.projectService.typingsCache.invalidateCachedTypingsForProject(this);
}
this.lastReportedFileNames = currentFiles;
this.lastReportedFileNames = currentFiles;

View file

@ -114,23 +114,29 @@ namespace ts.server.typingsInstaller {
protected runInstall(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void {
const id = this.installRunCount;
this.installRunCount++;
const command = `npm install ${typingsToInstall.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) => {
let installCount = 0;
const installedTypings: string[] = [];
const expr = /^.*(@types\/\w+)\S*\s*$/gm;
let match: RegExpExecArray;
for (const typing of typingsToInstall) {
const command = `npm install @types/${typing} --save-dev`;
if (this.log.isEnabled()) {
this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`);
this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`);
this.log.writeLine(`Running npm install @types ${id}, command '${command}'. cache path '${cachePath}'`);
}
const installedTypings: string[] = [];
const expr = /^.*(node_modules)\\(@types)\\(\S+)\s*$/gm;
let match: RegExpExecArray;
while (match = expr.exec(stdout)) {
installedTypings.push(`${match[1]}/${match[2]}/${match[3]}`);
}
postInstallAction(installedTypings);
});
this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => {
installCount++;
if (this.log.isEnabled()) {
this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`);
this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`);
}
while (match = expr.exec(stdout)) {
installedTypings.push(`node_modules/${match[1]}`);
}
if (installCount >= typingsToInstall.length) {
postInstallAction(installedTypings);
}
});
}
}
}