|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google Inc. All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.io/license |
| 7 | + */ |
| 8 | +import { Rule } from '@angular-devkit/schematics'; |
| 9 | +import { |
| 10 | + addPackageJsonDependency, |
| 11 | + getPackageJsonDependency, |
| 12 | +} from '../../utility/dependencies'; |
| 13 | +import { latestVersions } from '../../utility/latest-versions'; |
| 14 | + |
| 15 | +export default function (): Rule { |
| 16 | + return (host, context) => { |
| 17 | + const dependenciesToUpdate: Record<string, string> = { |
| 18 | + 'karma': '~5.0.0', |
| 19 | + 'ng-packagr': latestVersions.ngPackagr, |
| 20 | + }; |
| 21 | + |
| 22 | + for (const [name, version] of Object.entries(dependenciesToUpdate)) { |
| 23 | + const current = getPackageJsonDependency(host, name); |
| 24 | + if (!current || current.version === version) { |
| 25 | + continue; |
| 26 | + } |
| 27 | + |
| 28 | + addPackageJsonDependency(host, { |
| 29 | + type: current.type, |
| 30 | + name, |
| 31 | + version, |
| 32 | + overwrite: true, |
| 33 | + }); |
| 34 | + } |
| 35 | + |
| 36 | + // Check for @angular-devkit/schematics and @angular-devkit/core |
| 37 | + for (const name of ['@angular-devkit/schematics', '@angular-devkit/core']) { |
| 38 | + const current = getPackageJsonDependency(host, name); |
| 39 | + if (current) { |
| 40 | + context.logger.info( |
| 41 | + `Package "${name}" found in the workspace package.json. ` + |
| 42 | + 'This package typically does not need to be installed manually. ' + |
| 43 | + 'If it is not being used by project code, it can be removed from the package.json.', |
| 44 | + ); |
| 45 | + } |
| 46 | + } |
| 47 | + }; |
| 48 | +} |
0 commit comments