angular-cli/packages/schematics/angular/migrations/update-11/replace-ng-packagr-builder.ts
Alan Agius e6dbcfdce5 feat(@schematics/angular): add migration to replace deprecated library builder
In 10.1, `@angular-devkit/build-ng-packagr` was deprecated in favor of `@angular-devkit/build-angular`. This migration updates the library build target to use the non deprecated builder.
2020-08-27 21:53:16 +01:00

37 lines
1.2 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 { Rule, chain } from '@angular-devkit/schematics';
import { NodeDependencyType, addPackageJsonDependency, removePackageJsonDependency } from '../../utility/dependencies';
import { latestVersions } from '../../utility/latest-versions';
import { updateWorkspace } from '../../utility/workspace';
import { Builders } from '../../utility/workspace-models';
export default function (): Rule {
return chain([
updateWorkspace(workspace => {
for (const [, project] of workspace.projects) {
for (const [, target] of project.targets) {
if (target.builder === Builders.DeprecatedNgPackagr) {
target.builder = Builders.NgPackagr;
}
}
}
}),
host => {
removePackageJsonDependency(host, '@angular-devkit/build-ng-packagr');
addPackageJsonDependency(host, {
type: NodeDependencyType.Dev,
name: '@angular-devkit/build-angular',
version: latestVersions.DevkitBuildAngular,
overwrite: false,
});
},
]);
}