source: frontend/node_modules/workbox-build/src/lib/get-file-manifest-entries.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 Copyright 2021 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8
9import assert from 'assert';
10
11import {GetManifestResult, FileDetails, GetManifestOptions} from '../types';
12import {errors} from './errors';
13import {getCompositeDetails} from './get-composite-details';
14import {getFileDetails} from './get-file-details';
15import {getStringDetails} from './get-string-details';
16import {transformManifest} from './transform-manifest';
17
18export async function getFileManifestEntries({
19 additionalManifestEntries,
20 dontCacheBustURLsMatching,
21 globDirectory,
22 globFollow,
23 globIgnores,
24 globPatterns = [],
25 globStrict,
26 manifestTransforms,
27 maximumFileSizeToCacheInBytes,
28 modifyURLPrefix,
29 templatedURLs,
30}: GetManifestOptions): Promise<GetManifestResult> {
31 const warnings: Array<string> = [];
32 const allFileDetails = new Map<string, FileDetails>();
33
34 try {
35 for (const globPattern of globPatterns) {
36 const {globbedFileDetails, warning} = getFileDetails({
37 globDirectory,
38 globFollow,
39 globIgnores,
40 globPattern,
41 globStrict,
42 });
43
44 if (warning) {
45 warnings.push(warning);
46 }
47
48 for (const details of globbedFileDetails) {
49 if (details && !allFileDetails.has(details.file)) {
50 allFileDetails.set(details.file, details);
51 }
52 }
53 }
54 } catch (error) {
55 // If there's an exception thrown while globbing, then report
56 // it back as a warning, and don't consider it fatal.
57 if (error instanceof Error && error.message) {
58 warnings.push(error.message);
59 }
60 }
61
62 if (templatedURLs) {
63 for (const url of Object.keys(templatedURLs)) {
64 assert(!allFileDetails.has(url), errors['templated-url-matches-glob']);
65
66 const dependencies = templatedURLs[url];
67 if (Array.isArray(dependencies)) {
68 const details = dependencies.reduce<Array<FileDetails>>(
69 (previous, globPattern) => {
70 try {
71 const {globbedFileDetails, warning} = getFileDetails({
72 globDirectory,
73 globFollow,
74 globIgnores,
75 globPattern,
76 globStrict,
77 });
78
79 if (warning) {
80 warnings.push(warning);
81 }
82
83 return previous.concat(globbedFileDetails);
84 } catch (error) {
85 const debugObj: {[key: string]: Array<string>} = {};
86 debugObj[url] = dependencies;
87 throw new Error(
88 `${errors['bad-template-urls-asset']} ` +
89 `'${globPattern}' from '${JSON.stringify(debugObj)}':\n` +
90 `${error instanceof Error ? error.toString() : ''}`,
91 );
92 }
93 },
94 [],
95 );
96 if (details.length === 0) {
97 throw new Error(
98 `${errors['bad-template-urls-asset']} The glob ` +
99 `pattern '${dependencies.toString()}' did not match anything.`,
100 );
101 }
102 allFileDetails.set(url, getCompositeDetails(url, details));
103 } else if (typeof dependencies === 'string') {
104 allFileDetails.set(url, getStringDetails(url, dependencies));
105 }
106 }
107 }
108
109 const transformedManifest = await transformManifest({
110 additionalManifestEntries,
111 dontCacheBustURLsMatching,
112 manifestTransforms,
113 maximumFileSizeToCacheInBytes,
114 modifyURLPrefix,
115 fileDetails: Array.from(allFileDetails.values()),
116 });
117
118 transformedManifest.warnings.push(...warnings);
119
120 return transformedManifest;
121}
Note: See TracBrowser for help on using the repository browser.