Skip to content

Commit 5855c14

Browse files
alan-agius4mgechev
authored andcommittedApr 27, 2020
feat(@schematics/angular): add migration for evalSourceMap, vendorSourceMap profile and skipAppShell options.
1 parent 8fb7e58 commit 5855c14

File tree

5 files changed

+239
-9
lines changed

5 files changed

+239
-9
lines changed
 

‎packages/schematics/angular/migrations/migration-collection.json

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979
"version": "10.0.0-beta.2",
8080
"factory": "./update-9/schematic-options",
8181
"description": "Replace deprecated 'styleext' and 'spec' Angular schematic options."
82+
},
83+
"update-angular-config": {
84+
"version": "10.0.0-beta.3",
85+
"factory": "./update-10/update-angular-config",
86+
"description": "Remove deprecated 'evalSourceMap', `profile`, 'skipAppShell' and 'vendorSourceMap' from 'angular.json'."
8287
}
8388
}
8489
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
9+
import { workspaces } from '@angular-devkit/core';
10+
import { Rule } from '@angular-devkit/schematics';
11+
import { updateWorkspace } from '../../utility/workspace';
12+
import { ProjectType } from '../../utility/workspace-models';
13+
14+
export default function (): Rule {
15+
return updateWorkspace(workspace => {
16+
for (const [, project] of workspace.projects) {
17+
if (project.extensions.projectType !== ProjectType.Application) {
18+
// Only interested in application projects since these changes only effects application builders
19+
continue;
20+
}
21+
22+
for (const [, target] of project.targets) {
23+
// Only interested in Angular Devkit builders
24+
if (!target?.builder.startsWith('@angular-devkit/build-angular')) {
25+
continue;
26+
}
27+
28+
// Check options
29+
if (target.options) {
30+
target.options = {
31+
...updateVendorSourceMap(target.options),
32+
evalSourceMap: undefined,
33+
skipAppShell: undefined,
34+
profile: undefined,
35+
};
36+
}
37+
38+
// Go through each configuration entry
39+
if (!target.configurations) {
40+
continue;
41+
}
42+
43+
for (const configurationName of Object.keys(target.configurations)) {
44+
target.configurations[configurationName] = {
45+
...updateVendorSourceMap(target.configurations[configurationName]),
46+
evalSourceMap: undefined,
47+
skipAppShell: undefined,
48+
profile: undefined,
49+
};
50+
}
51+
}
52+
}
53+
});
54+
}
55+
56+
type TargetOptions = workspaces.TargetDefinition['options'];
57+
58+
function updateVendorSourceMap(options: TargetOptions): TargetOptions {
59+
if (!options) {
60+
return {};
61+
}
62+
63+
const { vendorSourceMap: vendor, sourceMap = true } = options;
64+
65+
if (vendor === undefined) {
66+
return options;
67+
}
68+
69+
if (sourceMap === true) {
70+
return {
71+
...options,
72+
sourceMap: {
73+
styles: true,
74+
scripts: true,
75+
vendor,
76+
},
77+
vendorSourceMap: undefined,
78+
};
79+
}
80+
81+
if (typeof sourceMap === 'object') {
82+
return {
83+
...options,
84+
sourceMap: {
85+
...sourceMap,
86+
vendor,
87+
},
88+
vendorSourceMap: undefined,
89+
};
90+
}
91+
92+
return {
93+
...options,
94+
vendorSourceMap: undefined,
95+
};
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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 { JsonObject } from '@angular-devkit/core';
9+
import { EmptyTree } from '@angular-devkit/schematics';
10+
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
11+
import { BuilderTarget, Builders, ProjectType, WorkspaceSchema } from '../../utility/workspace-models';
12+
13+
function getBuildTarget(tree: UnitTestTree): BuilderTarget<Builders.Browser, JsonObject> {
14+
return JSON.parse(tree.readContent('/angular.json')).projects.app.architect.build;
15+
}
16+
17+
function createWorkSpaceConfig(tree: UnitTestTree) {
18+
const angularConfig: WorkspaceSchema = {
19+
version: 1,
20+
projects: {
21+
app: {
22+
root: '',
23+
sourceRoot: 'src',
24+
projectType: ProjectType.Application,
25+
prefix: 'app',
26+
architect: {
27+
build: {
28+
builder: Builders.Browser,
29+
options: {
30+
skipAppShell: true,
31+
sourceMap: true,
32+
vendorSourceMap: true,
33+
evalSourceMap: false,
34+
buildOptimizer: true,
35+
// tslint:disable-next-line:no-any
36+
} as any,
37+
configurations: {
38+
one: {
39+
sourceMap: false,
40+
vendorSourceMap: false,
41+
skipAppShell: false,
42+
evalSourceMap: true,
43+
buildOptimizer: false,
44+
},
45+
two: {
46+
sourceMap: {
47+
styles: false,
48+
scripts: true,
49+
},
50+
evalSourceMap: true,
51+
vendorSourceMap: false,
52+
skipAppShell: true,
53+
buildOptimizer: true,
54+
},
55+
// tslint:disable-next-line:no-any
56+
} as any,
57+
},
58+
},
59+
},
60+
},
61+
};
62+
63+
tree.create('/angular.json', JSON.stringify(angularConfig, undefined, 2));
64+
}
65+
66+
describe(`Migration to update 'angular.json'`, () => {
67+
const schematicName = 'update-angular-config';
68+
69+
const schematicRunner = new SchematicTestRunner(
70+
'migrations',
71+
require.resolve('../migration-collection.json'),
72+
);
73+
74+
let tree: UnitTestTree;
75+
beforeEach(() => {
76+
tree = new UnitTestTree(new EmptyTree());
77+
createWorkSpaceConfig(tree);
78+
});
79+
80+
it(`should remove 'skipAppShell'`, async () => {
81+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
82+
const { options, configurations } = getBuildTarget(newTree);
83+
84+
expect(options.skipAppShell).toBeUndefined();
85+
expect(configurations).toBeDefined();
86+
expect(configurations?.one.skipAppShell).toBeUndefined();
87+
expect(configurations?.two.skipAppShell).toBeUndefined();
88+
});
89+
90+
it(`should remove 'evalSourceMap'`, async () => {
91+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
92+
const { options, configurations } = getBuildTarget(newTree);
93+
94+
expect(options.evalSourceMap).toBeUndefined();
95+
expect(configurations).toBeDefined();
96+
expect(configurations?.one.evalSourceMap).toBeUndefined();
97+
expect(configurations?.two.evalSourceMap).toBeUndefined();
98+
});
99+
100+
it(`should remove 'vendorSourceMap' and set 'vendor' option in 'sourceMap'`, async () => {
101+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
102+
const { options, configurations } = getBuildTarget(newTree);
103+
104+
expect(options.vendorSourceMap).toBeUndefined();
105+
expect(options.sourceMap).toEqual({
106+
vendor: true,
107+
scripts: true,
108+
styles: true,
109+
});
110+
expect(options.vendorSourceMap).toBeUndefined();
111+
112+
expect(configurations).toBeDefined();
113+
expect(configurations?.one.vendorSourceMap).toBeUndefined();
114+
expect(configurations?.one.sourceMap).toBe(false);
115+
116+
expect(configurations?.two.vendorSourceMap).toBeUndefined();
117+
expect(configurations?.two.sourceMap).toEqual({
118+
vendor: false,
119+
scripts: true,
120+
styles: false,
121+
});
122+
});
123+
});

‎packages/schematics/angular/migrations/update-10/update-dependencies.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function (): Rule {
1616
return (host, context) => {
1717
const dependenciesToUpdate: Record<string, string> = {
1818
'karma': '~5.0.0',
19+
'protractor': '~5.4.4',
1920
'ng-packagr': latestVersions.ngPackagr,
2021
};
2122

‎packages/schematics/angular/utility/workspace-models.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,20 @@ export interface LibraryBuilderOptions {
7474
}
7575

7676
export interface ServerBuilderOptions {
77-
outputPath: string;
78-
tsConfig: string;
79-
main: string;
80-
fileReplacements?: FileReplacements[];
81-
optimization?: {
82-
scripts?: boolean;
83-
styles?: boolean;
84-
};
85-
sourceMap?: boolean;
77+
outputPath: string;
78+
tsConfig: string;
79+
main: string;
80+
fileReplacements?: FileReplacements[];
81+
optimization?: {
82+
scripts?: boolean;
83+
styles?: boolean;
84+
};
85+
sourceMap?: boolean | {
86+
scripts?: boolean;
87+
styles?: boolean;
88+
hidden?: boolean;
89+
vendor?: boolean;
90+
};
8691
}
8792

8893
export interface AppShellBuilderOptions {

0 commit comments

Comments
 (0)
Please sign in to comment.