Skip to content

Commit 7a663e9

Browse files
committed
switch to execSync to ensure that no install orders are interleaved (#12259)
1 parent 18db87c commit 7a663e9

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/compiler/core.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
/* @internal */
55
namespace ts {
66

7-
export const version = "2.0.9";
7+
/** The version of the TypeScript compiler release */
8+
9+
export const version = "2.2.0";
810

911
/**
1012
* Ternary values are defined such that

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,12 @@ namespace ts.server.typingsInstaller {
6161
return combinePaths(normalizeSlashes(globalTypingsCacheLocation), `node_modules/${TypesRegistryPackageName}/index.json`);
6262
}
6363

64-
65-
type Exec = {
66-
(command: string, options: { cwd: string }, callback?: (error: Error, stdout: string, stderr: string) => void): any
67-
};
68-
6964
type ExecSync = {
70-
(command: string, options: { cwd: string, stdio: "ignore" }): any
71-
};
65+
(command: string, options: { cwd: string, stdio?: "ignore" }): any
66+
}
7267

7368
export class NodeTypingsInstaller extends TypingsInstaller {
74-
private readonly exec: Exec;
69+
private readonly execSync: ExecSync;
7570
private readonly npmPath: string;
7671
readonly typesRegistry: Map<void>;
7772

@@ -87,16 +82,15 @@ namespace ts.server.typingsInstaller {
8782
this.log.writeLine(`Process id: ${process.pid}`);
8883
}
8984
this.npmPath = getNPMLocation(process.argv[0]);
90-
let execSync: ExecSync;
91-
({ exec: this.exec, execSync } = require("child_process"));
85+
({ execSync: this.execSync } = require("child_process"));
9286

9387
this.ensurePackageDirectoryExists(globalTypingsCacheLocation);
9488

9589
try {
9690
if (this.log.isEnabled()) {
9791
this.log.writeLine(`Updating ${TypesRegistryPackageName} npm package...`);
9892
}
99-
execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
93+
this.execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
10094
}
10195
catch (e) {
10296
if (this.log.isEnabled()) {
@@ -135,13 +129,21 @@ namespace ts.server.typingsInstaller {
135129
}
136130
const command = `${this.npmPath} install ${args.join(" ")} --save-dev`;
137131
const start = Date.now();
138-
this.exec(command, { cwd }, (err, stdout, stderr) => {
139-
if (this.log.isEnabled()) {
140-
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`);
141-
}
142-
// treat absence of error as success
143-
onRequestCompleted(!err);
144-
});
132+
let stdout: Buffer;
133+
let stderr: Buffer;
134+
let hasError = false;
135+
try {
136+
stdout = this.execSync(command, { cwd });
137+
}
138+
catch (e) {
139+
stdout = e.stdout;
140+
stderr = e.stderr;
141+
hasError = true;
142+
}
143+
if (this.log.isEnabled()) {
144+
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout && stdout.toString()}${sys.newLine}stderr: ${stderr && stderr.toString()}`);
145+
}
146+
onRequestCompleted(!hasError);
145147
}
146148
}
147149

0 commit comments

Comments
 (0)