mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +08:00
fix(@schematics/angular): update @angular-devkit/build-ng-packagr
when migrating
Closes #12642
This commit is contained in:
parent
eef66f0f65
commit
58ca30b1e7
@ -24,6 +24,11 @@
|
||||
"version": "7.0.4",
|
||||
"factory": "./update-7",
|
||||
"description": "Update an Angular CLI project to version 7."
|
||||
},
|
||||
"migration-06": {
|
||||
"version": "7.0.3",
|
||||
"factory": "./update-7/index#updateDevkitBuildNgPackagr",
|
||||
"description": "Update an Angular CLI project to version 7."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @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 } from '@angular-devkit/schematics';
|
||||
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
|
||||
import { addPackageJsonDependency, getPackageJsonDependency } from '../../utility/dependencies';
|
||||
import { latestVersions } from '../../utility/latest-versions';
|
||||
|
||||
export function updateDevkitBuildNgPackagr(): Rule {
|
||||
return (tree, context) => {
|
||||
const existing = getPackageJsonDependency(tree, '@angular-devkit/build-ng-packagr');
|
||||
|
||||
if (!existing) {
|
||||
return;
|
||||
}
|
||||
|
||||
addPackageJsonDependency(
|
||||
tree,
|
||||
{
|
||||
type: existing.type,
|
||||
name: '@angular-devkit/build-ng-packagr',
|
||||
version: latestVersions.DevkitBuildNgPackagr,
|
||||
overwrite: true,
|
||||
},
|
||||
);
|
||||
|
||||
context.addTask(new NodePackageInstallTask());
|
||||
};
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* @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 { EmptyTree } from '@angular-devkit/schematics';
|
||||
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
|
||||
import { latestVersions } from '../../utility/latest-versions';
|
||||
|
||||
const oldPkg = `
|
||||
{
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "0.0.0",
|
||||
"@angular-devkit/build-ng-packagr": "0.0.0"
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
describe('updateDevkitBuildNgPackagr', () => {
|
||||
const schematicRunner = new SchematicTestRunner(
|
||||
'migrations',
|
||||
require.resolve('../migration-collection.json'),
|
||||
);
|
||||
|
||||
let tree: UnitTestTree;
|
||||
|
||||
beforeEach(async () => {
|
||||
tree = new UnitTestTree(new EmptyTree());
|
||||
tree = await schematicRunner.runExternalSchematicAsync(
|
||||
require.resolve('../../collection.json'), 'ng-new',
|
||||
{
|
||||
name: 'migration-test',
|
||||
version: '1.2.3',
|
||||
directory: '.',
|
||||
},
|
||||
tree,
|
||||
).toPromise();
|
||||
});
|
||||
|
||||
it('should work as expected', async () => {
|
||||
tree.overwrite('/package.json', oldPkg);
|
||||
const tree2 = await schematicRunner.runSchematicAsync('migration-06', {}, tree.branch())
|
||||
.toPromise();
|
||||
|
||||
const content = tree2.readContent('/package.json');
|
||||
const pkg = JSON.parse(content);
|
||||
expect(pkg.devDependencies['@angular-devkit/build-ng-packagr'])
|
||||
.toBe(latestVersions.DevkitBuildNgPackagr);
|
||||
});
|
||||
});
|
@ -16,6 +16,7 @@ import { latestVersions } from '../../utility/latest-versions';
|
||||
|
||||
export { polyfillMetadataRule } from './polyfill-metadata';
|
||||
export { typeScriptHelpersRule } from './typescript-helpers';
|
||||
export { updateDevkitBuildNgPackagr } from './devkit-ng-packagr';
|
||||
|
||||
export default function(): Rule {
|
||||
return (tree, context) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user