Skip to content

Commit c859fcb

Browse files
clydinfilipesilva
authored andcommitted
refactor(@schematics/angular): use new workspace helpers in ngsw-config migration
1 parent 39fd968 commit c859fcb

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

packages/schematics/angular/migrations/update-9/ngsw-config.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,30 @@
77
*/
88
import { Rule } from '@angular-devkit/schematics';
99
import { JSONFile } from '../../utility/json-file';
10-
import { findPropertyInAstObject } from '../../utility/json-utils';
10+
import { allTargetOptions, allWorkspaceTargets, getWorkspace } from '../../utility/workspace';
1111
import { Builders } from '../../utility/workspace-models';
12-
import { getAllOptions, getTargets, getWorkspace } from './utils';
13-
1412

1513
/**
1614
* Update ngsw-config.json to fix issue https://github.com/angular/angular-cli/pull/15277
1715
*/
1816
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+
}
2124

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') {
2628
continue;
2729
}
2830

29-
const path = ngswConfigPath.value;
3031
let ngswConfigJson;
3132
try {
32-
ngswConfigJson = new JSONFile(tree, path);
33+
ngswConfigJson = new JSONFile(tree, ngswConfigPath);
3334
} catch {
3435
logger.warn(`Cannot find file: ${ngswConfigPath}`);
3536
continue;
@@ -54,8 +55,9 @@ export function updateNGSWConfig(): Rule {
5455
continue;
5556
}
5657

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+
);
5961
if (hasManifest) {
6062
continue;
6163
}
@@ -64,7 +66,5 @@ export function updateNGSWConfig(): Rule {
6466
ngswConfigJson.modify([...filesPath, -1], '/manifest.webmanifest');
6567
}
6668
}
67-
68-
return tree;
6969
};
7070
}

0 commit comments

Comments
 (0)