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 { JsonParseMode , isJsonObject , parseJson } from '@angular-devkit/core' ;
98import {
109 MergeStrategy ,
1110 Rule ,
@@ -19,6 +18,7 @@ import {
1918} from '@angular-devkit/schematics' ;
2019import { createHash } from 'crypto' ;
2120import * as ts from '../../third_party/github.com/Microsoft/TypeScript/lib/typescript' ;
21+ import { getWorkspace } from '../../utility/workspace' ;
2222
2323const toDrop : { [ importName : string ] : true } = {
2424 'core-js/es6/symbol' : true ,
@@ -146,42 +146,26 @@ function dropES2015PolyfillsFromFile(polyfillPath: string): Rule {
146146 * Drop ES2015 polyfills from all application projects
147147 */
148148export function dropES2015Polyfills ( ) : Rule {
149- return ( tree ) => {
150- // Simple. Take the ast of polyfills (if it exists) and find the import metadata. Remove it.
151- const angularConfigContent = tree . read ( 'angular.json' ) || tree . read ( '.angular.json' ) ;
152- const rules : Rule [ ] = [ ] ;
153-
154- if ( ! angularConfigContent ) {
155- // Is this even an angular project?
156- return ;
157- }
158-
159- const angularJson = parseJson ( angularConfigContent . toString ( ) , JsonParseMode . Loose ) ;
160-
161- if ( ! isJsonObject ( angularJson ) || ! isJsonObject ( angularJson . projects ) ) {
162- // If that field isn't there, no use...
149+ return async ( tree ) => {
150+ let workspace ;
151+ try {
152+ workspace = await getWorkspace ( tree ) ;
153+ } catch {
163154 return ;
164155 }
165156
166- // For all projects
167- for ( const projectName of Object . keys ( angularJson . projects ) ) {
168- const project = angularJson . projects [ projectName ] ;
169- if ( ! isJsonObject ( project ) ) {
170- continue ;
171- }
172- if ( project . projectType !== 'application' ) {
157+ const rules = [ ] ;
158+ for ( const [ , project ] of workspace . projects ) {
159+ if ( project . extensions . projectType !== 'application' ) {
173160 continue ;
174161 }
175162
176- const architect = project . architect ;
177- if ( ! isJsonObject ( architect )
178- || ! isJsonObject ( architect . build )
179- || ! isJsonObject ( architect . build . options )
180- || typeof architect . build . options . polyfills !== 'string' ) {
181- continue ;
182- }
163+ const buildTarget = project . targets . get ( 'build' ) ;
164+ const polyfills = buildTarget ?. options ?. polyfills ;
183165
184- rules . push ( dropES2015PolyfillsFromFile ( architect . build . options . polyfills ) ) ;
166+ if ( polyfills && typeof polyfills === 'string' ) {
167+ rules . push ( dropES2015PolyfillsFromFile ( polyfills ) ) ;
168+ }
185169 }
186170
187171 return chain ( rules ) ;
0 commit comments