7
7
*/
8
8
import { Rule } from '@angular-devkit/schematics' ;
9
9
import { JSONFile } from '../../utility/json-file' ;
10
- import { findPropertyInAstObject } from '../../utility/json-utils ' ;
10
+ import { allTargetOptions , allWorkspaceTargets , getWorkspace } from '../../utility/workspace ' ;
11
11
import { Builders } from '../../utility/workspace-models' ;
12
- import { getAllOptions , getTargets , getWorkspace } from './utils' ;
13
-
14
12
15
13
/**
16
14
* Update ngsw-config.json to fix issue https://github.com/angular/angular-cli/pull/15277
17
15
*/
18
16
export function updateNGSWConfig ( ) : Rule {
19
- return ( tree , { logger } ) => {
20
- const workspace = getWorkspace ( tree ) ;
17
+ return async ( tree , { logger } ) => {
18
+ const workspace = await getWorkspace ( tree ) ;
19
+
20
+ for ( const [ targetName , target ] of allWorkspaceTargets ( workspace ) ) {
21
+ if ( targetName !== 'build' || target . builder !== Builders . Browser ) {
22
+ continue ;
23
+ }
21
24
22
- for ( const { target } of getTargets ( workspace , 'build' , Builders . Browser ) ) {
23
- for ( const options of getAllOptions ( target ) ) {
24
- const ngswConfigPath = findPropertyInAstObject ( options , 'ngswConfigPath' ) ;
25
- if ( ! ngswConfigPath || ngswConfigPath . kind !== 'string' ) {
25
+ for ( const [ , options ] of allTargetOptions ( target ) ) {
26
+ const ngswConfigPath = options . ngswConfigPath ;
27
+ if ( ! ngswConfigPath || typeof ngswConfigPath !== 'string' ) {
26
28
continue ;
27
29
}
28
30
29
- const path = ngswConfigPath . value ;
30
31
let ngswConfigJson ;
31
32
try {
32
- ngswConfigJson = new JSONFile ( tree , path ) ;
33
+ ngswConfigJson = new JSONFile ( tree , ngswConfigPath ) ;
33
34
} catch {
34
35
logger . warn ( `Cannot find file: ${ ngswConfigPath } ` ) ;
35
36
continue ;
@@ -54,8 +55,9 @@ export function updateNGSWConfig(): Rule {
54
55
continue ;
55
56
}
56
57
57
- const hasManifest = files
58
- . some ( ( value ) => typeof value === 'string' && value . endsWith ( 'manifest.webmanifest' ) ) ;
58
+ const hasManifest = files . some (
59
+ ( value ) => typeof value === 'string' && value . endsWith ( 'manifest.webmanifest' ) ,
60
+ ) ;
59
61
if ( hasManifest ) {
60
62
continue ;
61
63
}
@@ -64,7 +66,5 @@ export function updateNGSWConfig(): Rule {
64
66
ngswConfigJson . modify ( [ ...filesPath , - 1 ] , '/manifest.webmanifest' ) ;
65
67
}
66
68
}
67
-
68
- return tree ;
69
69
} ;
70
70
}
0 commit comments