Skip to content

Commit 24ef426

Browse files
committed
Install packages separately
1 parent 199e533 commit 24ef426

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

src/server/project.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ namespace ts.server {
312312
// - newProgram is different from the old program and structure of the old program was not reused.
313313
if (!oldProgram || (this.program !== oldProgram && !oldProgram.structureIsReused)) {
314314
hasChanges = true;
315-
this.projectService.typingsCache.invalidateCachedTypingsForProject(this);
315+
//this.projectService.typingsCache.invalidateCachedTypingsForProject(this);
316316
if (oldProgram) {
317317
for (const f of oldProgram.getSourceFiles()) {
318318
if (this.program.getSourceFileByPath(f.path)) {
@@ -405,16 +405,25 @@ namespace ts.server {
405405

406406
const added: string[] = [];
407407
const removed: string[] = [];
408+
let invalidateTypings = false;
408409
for (const id in currentFiles) {
409410
if (hasProperty(currentFiles, id) && !hasProperty(lastReportedFileNames, id)) {
410411
added.push(id);
412+
if (this.typingFiles.indexOf(id) < 0) {
413+
invalidateTypings = true;
414+
break;
415+
}
411416
}
412417
}
413418
for (const id in lastReportedFileNames) {
414419
if (hasProperty(lastReportedFileNames, id) && !hasProperty(currentFiles, id)) {
415420
removed.push(id);
421+
invalidateTypings = true;
416422
}
417423
}
424+
if (invalidateTypings) {
425+
this.projectService.typingsCache.invalidateCachedTypingsForProject(this);
426+
}
418427
this.lastReportedFileNames = currentFiles;
419428

420429
this.lastReportedFileNames = currentFiles;

src/server/typingsInstaller/nodeTypingsInstaller.ts

+21-15
Original file line numberDiff line numberDiff line change
@@ -114,23 +114,29 @@ namespace ts.server.typingsInstaller {
114114
protected runInstall(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void {
115115
const id = this.installRunCount;
116116
this.installRunCount++;
117-
const command = `npm install ${typingsToInstall.map(t => "@types/" + t).join(" ")} --save-dev`;
118-
if (this.log.isEnabled()) {
119-
this.log.writeLine(`Running npm install @types ${id}, command '${command}'. cache path '${cachePath}'`);
120-
}
121-
this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => {
117+
let installCount = 0;
118+
const installedTypings: string[] = [];
119+
const expr = /^.*(@types\/\w+)\S*\s*$/gm;
120+
let match: RegExpExecArray;
121+
for (const typing of typingsToInstall) {
122+
const command = `npm install @types/${typing} --save-dev`;
122123
if (this.log.isEnabled()) {
123-
this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`);
124-
this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`);
125-
}
126-
const installedTypings: string[] = [];
127-
const expr = /^.*(node_modules)\\(@types)\\(\S+)\s*$/gm;
128-
let match: RegExpExecArray;
129-
while (match = expr.exec(stdout)) {
130-
installedTypings.push(`${match[1]}/${match[2]}/${match[3]}`);
124+
this.log.writeLine(`Running npm install @types ${id}, command '${command}'. cache path '${cachePath}'`);
131125
}
132-
postInstallAction(installedTypings);
133-
});
126+
this.exec(command, { cwd: cachePath }, (err, stdout, stderr) => {
127+
installCount++;
128+
if (this.log.isEnabled()) {
129+
this.log.writeLine(`npm install @types ${id} stdout: ${stdout}`);
130+
this.log.writeLine(`npm install @types ${id} stderr: ${stderr}`);
131+
}
132+
while (match = expr.exec(stdout)) {
133+
installedTypings.push(`node_modules/${match[1]}`);
134+
}
135+
if (installCount >= typingsToInstall.length) {
136+
postInstallAction(installedTypings);
137+
}
138+
});
139+
}
134140
}
135141
}
136142

0 commit comments

Comments
 (0)