source: trip-planner-front/node_modules/@schematics/angular/migrations/update-9/ngsw-config.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.updateNGSWConfig = void 0;
11const json_file_1 = require("../../utility/json-file");
12const workspace_1 = require("../../utility/workspace");
13const workspace_models_1 = require("../../utility/workspace-models");
14/**
15 * Update ngsw-config.json to fix issue https://github.com/angular/angular-cli/pull/15277
16 */
17function updateNGSWConfig() {
18 return async (tree, { logger }) => {
19 const workspace = await workspace_1.getWorkspace(tree);
20 for (const [targetName, target] of workspace_1.allWorkspaceTargets(workspace)) {
21 if (targetName !== 'build' || target.builder !== workspace_models_1.Builders.Browser) {
22 continue;
23 }
24 for (const [, options] of workspace_1.allTargetOptions(target)) {
25 const ngswConfigPath = options.ngswConfigPath;
26 if (!ngswConfigPath || typeof ngswConfigPath !== 'string') {
27 continue;
28 }
29 let ngswConfigJson;
30 try {
31 ngswConfigJson = new json_file_1.JSONFile(tree, ngswConfigPath);
32 }
33 catch {
34 logger.warn(`Cannot find file: ${ngswConfigPath}`);
35 continue;
36 }
37 const assetGroups = ngswConfigJson.get(['assetGroups']);
38 if (!assetGroups || !Array.isArray(assetGroups)) {
39 continue;
40 }
41 const prefetchElementIndex = assetGroups.findIndex((element) => (element === null || element === void 0 ? void 0 : element.installMode) === 'prefetch');
42 if (prefetchElementIndex === -1) {
43 continue;
44 }
45 const filesPath = ['assetGroups', prefetchElementIndex, 'resources', 'files'];
46 const files = ngswConfigJson.get(filesPath);
47 if (!files || !Array.isArray(files)) {
48 continue;
49 }
50 const hasManifest = files.some((value) => typeof value === 'string' && value.endsWith('manifest.webmanifest'));
51 if (hasManifest) {
52 continue;
53 }
54 // Append to files array
55 ngswConfigJson.modify([...filesPath, -1], '/manifest.webmanifest');
56 }
57 }
58 };
59}
60exports.updateNGSWConfig = updateNGSWConfig;
Note: See TracBrowser for help on using the repository browser.