From 2cf08fcdf4867dc2c1664178e2c2276b4f231a89 Mon Sep 17 00:00:00 2001 From: Alan Date: Fri, 23 Aug 2019 08:11:51 +0200 Subject: [PATCH] feat(@schematics/angular): add migration for dependencies --- .../angular/migrations/update-9/index.ts | 9 +++++ .../update-9/update-dependencies.ts | 39 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 packages/schematics/angular/migrations/update-9/update-dependencies.ts diff --git a/packages/schematics/angular/migrations/update-9/index.ts b/packages/schematics/angular/migrations/update-9/index.ts index c3429411ffc8..aaca4a6004ed 100644 --- a/packages/schematics/angular/migrations/update-9/index.ts +++ b/packages/schematics/angular/migrations/update-9/index.ts @@ -7,7 +7,9 @@ */ import { Rule, chain } from '@angular-devkit/schematics'; +import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; import { UpdateLibraries } from './ivy-libraries'; +import { updateDependencies } from './update-dependencies'; import { UpdateWorkspaceConfig } from './update-workspace-config'; export default function(): Rule { @@ -15,6 +17,13 @@ export default function(): Rule { return chain([ UpdateWorkspaceConfig(), UpdateLibraries(), + updateDependencies(), + (tree, context) => { + const packageChanges = tree.actions.some(a => a.path.endsWith('/package.json')); + if (packageChanges) { + context.addTask(new NodePackageInstallTask()); + } + }, ]); }; } diff --git a/packages/schematics/angular/migrations/update-9/update-dependencies.ts b/packages/schematics/angular/migrations/update-9/update-dependencies.ts new file mode 100644 index 000000000000..00b891ab4718 --- /dev/null +++ b/packages/schematics/angular/migrations/update-9/update-dependencies.ts @@ -0,0 +1,39 @@ +/** + * @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 { Tree } from '@angular-devkit/schematics'; +import { addPackageJsonDependency, getPackageJsonDependency } from '../../utility/dependencies'; +import { latestVersions } from '../../utility/latest-versions'; + +export function updateDependencies() { + return (host: Tree) => { + const dependenciesToUpdate: Record = { + '@angular/pwa': latestVersions.AngularPWA, + '@angular-devkit/build-angular': latestVersions.DevkitBuildAngular, + '@angular-devkit/build-ng-packagr': latestVersions.DevkitBuildNgPackagr, + '@angular-devkit/build-webpack': latestVersions.DevkitBuildWebpack, + 'zone.js': latestVersions.ZoneJs, + tsickle: latestVersions.tsickle, + 'ng-packagr': latestVersions.ngPackagr, + 'web-animations-js': '^2.3.2', + }; + + for (const [name, version] of Object.entries(dependenciesToUpdate)) { + const current = getPackageJsonDependency(host, name); + if (!current || current.version === version) { + continue; + } + + addPackageJsonDependency(host, { + type: current.type, + name, + version, + overwrite: true, + }); + } + }; +}