Skip to content

Commit 4af9a8a

Browse files
clydinvikerman
authored andcommitted
fix(@angular/cli): only show add/update package install output on errors
Closes #16014 Closes #16027
1 parent 37a6d4d commit 4af9a8a

File tree

1 file changed

+27
-38
lines changed

1 file changed

+27
-38
lines changed

packages/angular/cli/tasks/install-package.ts

+27-38
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88

99
import { logging } from '@angular-devkit/core';
1010
import { spawnSync } from 'child_process';
11-
import {
12-
existsSync,
13-
mkdtempSync,
14-
readFileSync,
15-
realpathSync,
16-
} from 'fs';
11+
import { existsSync, mkdtempSync, readFileSync, realpathSync } from 'fs';
1712
import { tmpdir } from 'os';
1813
import { join, resolve } from 'path';
1914
import * as rimraf from 'rimraf';
@@ -53,21 +48,18 @@ export function installPackage(
5348
installArgs.push(packageManagerArgs.saveDev);
5449
}
5550

56-
const { status } = spawnSync(
57-
packageManager,
58-
[
59-
...installArgs,
60-
...extraArgs,
61-
],
62-
{
63-
stdio: 'inherit',
64-
shell: true,
65-
cwd,
66-
},
67-
);
51+
const { status, stderr } = spawnSync(packageManager, [...installArgs, ...extraArgs], {
52+
stdio: 'pipe',
53+
encoding: 'utf8',
54+
cwd,
55+
});
6856

6957
if (status !== 0) {
70-
throw new Error('Package install failed, see above.');
58+
let errors = stderr.trim();
59+
if (errors.length) {
60+
errors += '\n';
61+
}
62+
throw new Error(errors + `Package install failed${errors.length ? ', see above' : ''}.`);
7163
}
7264

7365
logger.info(colors.green(`Installed packages for tooling via ${packageManager}.`));
@@ -84,7 +76,7 @@ export function installTempPackage(
8476
process.on('exit', () => {
8577
try {
8678
rimraf.sync(tempPath);
87-
} catch { }
79+
} catch {}
8880
});
8981

9082
// setup prefix/global modules path
@@ -134,10 +126,7 @@ export function runTempPackageBin(
134126
throw new Error(`Cannot locate bin for temporary package: ${packageNameNoVersion}.`);
135127
}
136128

137-
const argv = [
138-
binPath,
139-
...args,
140-
];
129+
const argv = [binPath, ...args];
141130

142131
const { status, error } = spawnSync('node', argv, {
143132
stdio: 'inherit',
@@ -159,19 +148,19 @@ export function runTempPackageBin(
159148
function getPackageManagerArguments(packageManager: PackageManager): PackageManagerOptions {
160149
return packageManager === PackageManager.Yarn
161150
? {
162-
silent: '--silent',
163-
saveDev: '--dev',
164-
install: 'add',
165-
prefix: '--modules-folder',
166-
noBinLinks: '--no-bin-links',
167-
noLockfile: '--no-lockfile',
168-
}
151+
silent: '--silent',
152+
saveDev: '--dev',
153+
install: 'add',
154+
prefix: '--modules-folder',
155+
noBinLinks: '--no-bin-links',
156+
noLockfile: '--no-lockfile',
157+
}
169158
: {
170-
silent: '--quiet',
171-
saveDev: '--save-dev',
172-
install: 'install',
173-
prefix: '--prefix',
174-
noBinLinks: '--no-bin-links',
175-
noLockfile: '--no-package-lock',
176-
};
159+
silent: '--quiet',
160+
saveDev: '--save-dev',
161+
install: 'install',
162+
prefix: '--prefix',
163+
noBinLinks: '--no-bin-links',
164+
noLockfile: '--no-package-lock',
165+
};
177166
}

0 commit comments

Comments
 (0)