mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Merge pull request #23374 from Microsoft/npmInstallCommandTooLong
Handle command too long failure in typings installer
This commit is contained in:
commit
a9ffabbe51
File diff suppressed because one or more lines are too long
@ -184,9 +184,8 @@ namespace ts.server.typingsInstaller {
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`#${requestId} with arguments'${JSON.stringify(packageNames)}'.`);
|
||||
}
|
||||
const command = `${this.npmPath} install --ignore-scripts ${packageNames.join(" ")} --save-dev --user-agent="typesInstaller/${version}"`;
|
||||
const start = Date.now();
|
||||
const hasError = this.execSyncAndLog(command, { cwd });
|
||||
const hasError = installNpmPackages(this.npmPath, version, packageNames, command => this.execSyncAndLog(command, { cwd }));
|
||||
if (this.log.isEnabled()) {
|
||||
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms`);
|
||||
}
|
||||
|
||||
@ -30,6 +30,31 @@ namespace ts.server.typingsInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export function installNpmPackages(npmPath: string, tsVersion: string, packageNames: string[], install: (command: string) => boolean) {
|
||||
let hasError = false;
|
||||
for (let remaining = packageNames.length; remaining > 0;) {
|
||||
const result = getNpmCommandForInstallation(npmPath, tsVersion, packageNames, remaining);
|
||||
remaining = result.remaining;
|
||||
hasError = install(result.command) || hasError;
|
||||
}
|
||||
return hasError;
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export function getNpmCommandForInstallation(npmPath: string, tsVersion: string, packageNames: string[], remaining: number) {
|
||||
const sliceStart = packageNames.length - remaining;
|
||||
let command: string, toSlice = remaining;
|
||||
while (true) {
|
||||
command = `${npmPath} install --ignore-scripts ${(toSlice === packageNames.length ? packageNames : packageNames.slice(sliceStart, sliceStart + toSlice)).join(" ")} --save-dev --user-agent="typesInstaller/${tsVersion}"`;
|
||||
if (command.length < 8000) {
|
||||
break;
|
||||
}
|
||||
|
||||
toSlice = toSlice - Math.floor(toSlice / 2);
|
||||
}
|
||||
return { command, remaining: remaining - toSlice };
|
||||
}
|
||||
|
||||
export type RequestCompletedAction = (success: boolean) => void;
|
||||
interface PendingRequest {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user