mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
switch to execSync to ensure that no install orders are interleaved (#12259)
This commit is contained in:
parent
6846ea3f88
commit
3a094e7e73
@ -61,17 +61,12 @@ namespace ts.server.typingsInstaller {
|
||||
return combinePaths(normalizeSlashes(globalTypingsCacheLocation), `node_modules/${TypesRegistryPackageName}/index.json`);
|
||||
}
|
||||
|
||||
|
||||
type Exec = {
|
||||
(command: string, options: { cwd: string }, callback?: (error: Error, stdout: string, stderr: string) => void): any
|
||||
}
|
||||
|
||||
type ExecSync = {
|
||||
(command: string, options: { cwd: string, stdio: "ignore" }): any
|
||||
(command: string, options: { cwd: string, stdio?: "ignore" }): any
|
||||
}
|
||||
|
||||
export class NodeTypingsInstaller extends TypingsInstaller {
|
||||
private readonly exec: Exec;
|
||||
private readonly execSync: ExecSync;
|
||||
private readonly npmPath: string;
|
||||
readonly typesRegistry: Map<void>;
|
||||
|
||||
@ -87,8 +82,7 @@ namespace ts.server.typingsInstaller {
|
||||
this.log.writeLine(`Process id: ${process.pid}`);
|
||||
}
|
||||
this.npmPath = getNPMLocation(process.argv[0]);
|
||||
let execSync: ExecSync;
|
||||
({ exec: this.exec, execSync } = require("child_process"));
|
||||
({ execSync: this.execSync } = require("child_process"));
|
||||
|
||||
this.ensurePackageDirectoryExists(globalTypingsCacheLocation);
|
||||
|
||||
@ -96,7 +90,7 @@ namespace ts.server.typingsInstaller {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`Updating ${TypesRegistryPackageName} npm package...`);
|
||||
}
|
||||
execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
|
||||
this.execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
|
||||
}
|
||||
catch (e) {
|
||||
if (this.log.isEnabled()) {
|
||||
@ -135,13 +129,21 @@ namespace ts.server.typingsInstaller {
|
||||
}
|
||||
const command = `${this.npmPath} install ${args.join(" ")} --save-dev`;
|
||||
const start = Date.now();
|
||||
this.exec(command, { cwd }, (err, stdout, stderr) => {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`);
|
||||
}
|
||||
// treat absence of error as success
|
||||
onRequestCompleted(!err);
|
||||
});
|
||||
let stdout: Buffer;
|
||||
let stderr: Buffer;
|
||||
let hasError = false;
|
||||
try {
|
||||
stdout = this.execSync(command, { cwd });
|
||||
}
|
||||
catch (e) {
|
||||
stdout = e.stdout;
|
||||
stderr = e.stderr;
|
||||
hasError = true;
|
||||
}
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout && stdout.toString()}${sys.newLine}stderr: ${stderr && stderr.toString()}`);
|
||||
}
|
||||
onRequestCompleted(!hasError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user