Skip to content

Commit 74c799a

Browse files
clydinalexeagle
authored andcommitted
fix(@schematics/angular): avoid using 6.2+ only features in migrations
1 parent 6e7f4d9 commit 74c799a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

packages/schematics/angular/migrations/update-7/polyfill-metadata.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { json } from '@angular-devkit/core';
8+
import { JsonObject, JsonParseMode, JsonValue, parseJson } from '@angular-devkit/core';
99
import { Rule, Tree, chain, noop } from '@angular-devkit/schematics';
1010
import * as ts from 'typescript';
1111

12+
function isJsonObject(value: JsonValue): value is JsonObject {
13+
return value != null && typeof value === 'object' && !Array.isArray(value);
14+
}
1215

1316
/**
1417
* Remove the Reflect import from a polyfill file.
@@ -52,10 +55,10 @@ function _removeReflectFromPolyfills(tree: Tree, path: string) {
5255
* @param targetObject The target information.
5356
* @private
5457
*/
55-
function _updateProjectTarget(targetObject: json.JsonObject): Rule {
58+
function _updateProjectTarget(targetObject: JsonObject): Rule {
5659
// Make sure we're using the correct builder.
5760
if (targetObject.builder !== '@angular-devkit/build-angular:browser'
58-
|| !json.isJsonObject(targetObject.options)) {
61+
|| !isJsonObject(targetObject.options)) {
5962
return noop();
6063
}
6164
const options = targetObject.options;
@@ -65,12 +68,12 @@ function _updateProjectTarget(targetObject: json.JsonObject): Rule {
6568

6669
const polyfillsToUpdate = [options.polyfills];
6770
const configurations = targetObject.configurations;
68-
if (json.isJsonObject(configurations)) {
71+
if (isJsonObject(configurations)) {
6972
for (const configName of Object.keys(configurations)) {
7073
const config = configurations[configName];
7174

7275
// Just in case, only do non-AOT configurations.
73-
if (json.isJsonObject(config)
76+
if (isJsonObject(config)
7477
&& typeof config.polyfills == 'string'
7578
&& config.aot !== true) {
7679
polyfillsToUpdate.push(config.polyfills);
@@ -100,31 +103,31 @@ export function polyfillMetadataRule(): Rule {
100103
return;
101104
}
102105

103-
const angularJson = json.parseJson(angularConfigContent.toString(), json.JsonParseMode.Loose);
106+
const angularJson = parseJson(angularConfigContent.toString(), JsonParseMode.Loose);
104107

105-
if (!json.isJsonObject(angularJson) || !json.isJsonObject(angularJson.projects)) {
108+
if (!isJsonObject(angularJson) || !isJsonObject(angularJson.projects)) {
106109
// If that field isn't there, no use...
107110
return;
108111
}
109112

110113
// For all projects, for all targets, read the polyfill field, and read the environment.
111114
for (const projectName of Object.keys(angularJson.projects)) {
112115
const project = angularJson.projects[projectName];
113-
if (!json.isJsonObject(project)) {
116+
if (!isJsonObject(project)) {
114117
continue;
115118
}
116119
if (typeof project.root != 'string') {
117120
continue;
118121
}
119122

120123
const targets = project.targets || project.architect;
121-
if (!json.isJsonObject(targets)) {
124+
if (!isJsonObject(targets)) {
122125
continue;
123126
}
124127

125128
for (const targetName of Object.keys(targets)) {
126129
const target = targets[targetName];
127-
if (json.isJsonObject(target)) {
130+
if (isJsonObject(target)) {
128131
rules.push(_updateProjectTarget(target));
129132
}
130133
}

0 commit comments

Comments
 (0)