-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): add support for ng-add packages that should not b…
…e saved as `dependencies` 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
- Loading branch information
1 parent
750baf9
commit d133ba6
Showing
7 changed files
with
123 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* @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.'); | ||
} | ||
}, | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { join } from 'path'; | ||
import { expectFileToExist, expectFileToMatch, rimraf, readFile } from '../../../utils/fs'; | ||
import { ng } from '../../../utils/process'; | ||
|
||
export default async function () { | ||
// forcibly remove in case another test doesn't clean itself up | ||
await rimraf('node_modules/@angular/pwa'); | ||
|
||
await ng('add', '@angular/pwa'); | ||
|
||
await expectFileToExist(join(process.cwd(), 'src/manifest.webmanifest')); | ||
|
||
// Angular PWA doesn't install as a dependency | ||
const { dependencies, devDependencies } = JSON.parse(await readFile(join(process.cwd(), 'package.json'))); | ||
const hasPWADep = Object.keys({ ...dependencies, ...devDependencies }) | ||
.some(d => d === '@angular/pwa'); | ||
if (hasPWADep) { | ||
throw new Error(`Expected 'package.json' not to contain a dependency on '@angular/pwa'.`); | ||
} | ||
} |