mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
With this change the CLI offers a way for a package authors to specify if during `ng add` the package should be saved as a `dependencies`, `devDependencies` or not saved at all. Such config needs to be specified in `package.json` Example: ```json "ng-add": { "save": false } ``` Possible values are; - false - Don't add the package to `package.json` - true - Add the package to the `dependencies` - `dependencies` - Add the package to the `dependencies` - `devDependencies` - Add the package to the `devDependencies` Closes #12003 , closes #15764 and closes #13237
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import { logging } from '@angular-devkit/core';
|
|
import { spawn } from 'child_process';
|
|
import { colors } from '../utilities/color';
|
|
|
|
export default async function(
|
|
packageName: string,
|
|
logger: logging.Logger,
|
|
packageManager: string,
|
|
) {
|
|
const installArgs: string[] = [];
|
|
switch (packageManager) {
|
|
case 'cnpm':
|
|
case 'pnpm':
|
|
case 'npm':
|
|
installArgs.push('uninstall');
|
|
break;
|
|
|
|
case 'yarn':
|
|
installArgs.push('remove');
|
|
break;
|
|
|
|
default:
|
|
packageManager = 'npm';
|
|
installArgs.push('uninstall');
|
|
break;
|
|
}
|
|
|
|
installArgs.push(packageName, '--quiet');
|
|
|
|
logger.info(colors.green(`Uninstalling packages for tooling via ${packageManager}.`));
|
|
|
|
await new Promise((resolve, reject) => {
|
|
spawn(packageManager, installArgs, { stdio: 'inherit', shell: true }).on(
|
|
'close',
|
|
(code: number) => {
|
|
if (code === 0) {
|
|
logger.info(colors.green(`Uninstalling packages for tooling via ${packageManager}.`));
|
|
resolve();
|
|
} else {
|
|
reject('Package uninstallation failed, see above.');
|
|
}
|
|
},
|
|
);
|
|
});
|
|
}
|