Skip to content

Commit

Permalink
feat(@schematics/angular): add migration to remove deprecated options…
Browse files Browse the repository at this point in the history
… from 'angular.json'
  • Loading branch information
alan-agius4 authored and clydin committed Feb 9, 2021
1 parent 4773e13 commit f424529
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
"version": "11.0.0",
"factory": "./update-11/update-dependencies",
"description": "Update workspace dependencies to match a new v11 project."
},
"update-angular-config-v12": {
"version": "12.0.0-next.0",
"factory": "./update-12/update-angular-config",
"description": "Remove deprecated options from 'angular.json' that are no longer present in v12."
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @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 { updateWorkspace } from '../../utility/workspace';

export default function (): Rule {
return updateWorkspace(workspace => {
const optionsToRemove: Record<string, undefined> = {
experimentalRollupPass: undefined,
};

for (const [, project] of workspace.projects) {
for (const [, target] of project.targets) {
// Only interested in Angular Devkit builders
if (!target?.builder.startsWith('@angular-devkit/build-angular')) {
continue;
}

// Check options
if (target.options) {
target.options = {
...optionsToRemove,
};
}

// Go through each configuration entry
if (!target.configurations) {
continue;
}

for (const configurationName of Object.keys(target.configurations)) {
target.configurations[configurationName] = {
...optionsToRemove,
};
}
}
}
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* @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 { JsonObject } from '@angular-devkit/core';
import { EmptyTree } from '@angular-devkit/schematics';
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import { BuilderTarget, Builders, ProjectType, WorkspaceSchema } from '../../utility/workspace-models';

function getBuildTarget(tree: UnitTestTree): BuilderTarget<Builders.Browser, JsonObject> {
return JSON.parse(tree.readContent('/angular.json')).projects.app.architect.build;
}

function createWorkSpaceConfig(tree: UnitTestTree) {
const angularConfig: WorkspaceSchema = {
version: 1,
projects: {
app: {
root: '',
sourceRoot: 'src',
projectType: ProjectType.Application,
prefix: 'app',
architect: {
build: {
builder: Builders.Browser,
options: {
scripts: [
{ lazy: true, name: 'bundle-1.js' },
],
experimentalRollupPass: false,
sourceMaps: true,
buildOptimizer: false,
// tslint:disable-next-line:no-any
} as any,
configurations: {
one: {
aot: true,
scripts: [
{ lazy: true, name: 'bundle-1.js' },
{ lazy: false, name: 'bundle-2.js' },
{ inject: true, name: 'bundle-3.js' },
'bundle-4.js',
],
styles: [
{ lazy: true, name: 'bundle-1.css' },
{ lazy: false, name: 'bundle-2.css' },
{ inject: true, name: 'bundle-3.css' },
'bundle-3.css',
],
},
two: {
experimentalRollupPass: true,
aot: true,
},
// tslint:disable-next-line:no-any
} as any,
},
},
},
},
};

tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
}

const schematicName = 'update-angular-config-v12';

describe(`Migration to update 'angular.json'. ${schematicName}`, () => {
const schematicRunner = new SchematicTestRunner(
'migrations',
require.resolve('../migration-collection.json'),
);

let tree: UnitTestTree;
beforeEach(() => {
tree = new UnitTestTree(new EmptyTree());
createWorkSpaceConfig(tree);
});

it(`should remove 'experimentalRollupPass'`, async () => {
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
const { options, configurations } = getBuildTarget(newTree);

expect(options.experimentalRollupPass).toBeUndefined();
expect(configurations).toBeDefined();
expect(configurations?.one.experimentalRollupPass).toBeUndefined();
expect(configurations?.two.experimentalRollupPass).toBeUndefined();
});
});

0 comments on commit f424529

Please sign in to comment.