@angular/service-worker 21.0.0-next.8 → 21.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v21.0.0-next.8
2
+ * @license Angular v21.0.0-rc.0
3
3
  * (c) 2010-2025 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
@@ -7,236 +7,218 @@
7
7
  const PARSE_TO_PAIRS = /([0-9]+[^0-9]+)/g;
8
8
  const PAIR_SPLIT = /^([0-9]+)([dhmsu]+)$/;
9
9
  function parseDurationToMs(duration) {
10
- const matches = [];
11
- let array;
12
- while ((array = PARSE_TO_PAIRS.exec(duration)) !== null) {
13
- matches.push(array[0]);
10
+ const matches = [];
11
+ let array;
12
+ while ((array = PARSE_TO_PAIRS.exec(duration)) !== null) {
13
+ matches.push(array[0]);
14
+ }
15
+ return matches.map(match => {
16
+ const res = PAIR_SPLIT.exec(match);
17
+ if (res === null) {
18
+ throw new Error(`Not a valid duration: ${match}`);
14
19
  }
15
- return matches
16
- .map((match) => {
17
- const res = PAIR_SPLIT.exec(match);
18
- if (res === null) {
19
- throw new Error(`Not a valid duration: ${match}`);
20
- }
21
- let factor = 0;
22
- switch (res[2]) {
23
- case 'd':
24
- factor = 86400000;
25
- break;
26
- case 'h':
27
- factor = 3600000;
28
- break;
29
- case 'm':
30
- factor = 60000;
31
- break;
32
- case 's':
33
- factor = 1000;
34
- break;
35
- case 'u':
36
- factor = 1;
37
- break;
38
- default:
39
- throw new Error(`Not a valid duration unit: ${res[2]}`);
40
- }
41
- return parseInt(res[1]) * factor;
42
- })
43
- .reduce((total, value) => total + value, 0);
20
+ let factor = 0;
21
+ switch (res[2]) {
22
+ case 'd':
23
+ factor = 86400000;
24
+ break;
25
+ case 'h':
26
+ factor = 3600000;
27
+ break;
28
+ case 'm':
29
+ factor = 60000;
30
+ break;
31
+ case 's':
32
+ factor = 1000;
33
+ break;
34
+ case 'u':
35
+ factor = 1;
36
+ break;
37
+ default:
38
+ throw new Error(`Not a valid duration unit: ${res[2]}`);
39
+ }
40
+ return parseInt(res[1]) * factor;
41
+ }).reduce((total, value) => total + value, 0);
44
42
  }
45
43
 
46
44
  const QUESTION_MARK = '[^/]';
47
45
  const WILD_SINGLE = '[^/]*';
48
46
  const WILD_OPEN = '(?:.+\\/)?';
49
- const TO_ESCAPE_BASE = [
50
- { replace: /\./g, with: '\\.' },
51
- { replace: /\+/g, with: '\\+' },
52
- { replace: /\*/g, with: WILD_SINGLE },
53
- ];
54
- const TO_ESCAPE_WILDCARD_QM = [...TO_ESCAPE_BASE, { replace: /\?/g, with: QUESTION_MARK }];
55
- const TO_ESCAPE_LITERAL_QM = [...TO_ESCAPE_BASE, { replace: /\?/g, with: '\\?' }];
47
+ const TO_ESCAPE_BASE = [{
48
+ replace: /\./g,
49
+ with: '\\.'
50
+ }, {
51
+ replace: /\+/g,
52
+ with: '\\+'
53
+ }, {
54
+ replace: /\*/g,
55
+ with: WILD_SINGLE
56
+ }];
57
+ const TO_ESCAPE_WILDCARD_QM = [...TO_ESCAPE_BASE, {
58
+ replace: /\?/g,
59
+ with: QUESTION_MARK
60
+ }];
61
+ const TO_ESCAPE_LITERAL_QM = [...TO_ESCAPE_BASE, {
62
+ replace: /\?/g,
63
+ with: '\\?'
64
+ }];
56
65
  function globToRegex(glob, literalQuestionMark = false) {
57
- const toEscape = literalQuestionMark ? TO_ESCAPE_LITERAL_QM : TO_ESCAPE_WILDCARD_QM;
58
- const segments = glob.split('/').reverse();
59
- let regex = '';
60
- while (segments.length > 0) {
61
- const segment = segments.pop();
62
- if (segment === '**') {
63
- if (segments.length > 0) {
64
- regex += WILD_OPEN;
65
- }
66
- else {
67
- regex += '.*';
68
- }
69
- }
70
- else {
71
- const processed = toEscape.reduce((segment, escape) => segment.replace(escape.replace, escape.with), segment);
72
- regex += processed;
73
- if (segments.length > 0) {
74
- regex += '\\/';
75
- }
76
- }
66
+ const toEscape = literalQuestionMark ? TO_ESCAPE_LITERAL_QM : TO_ESCAPE_WILDCARD_QM;
67
+ const segments = glob.split('/').reverse();
68
+ let regex = '';
69
+ while (segments.length > 0) {
70
+ const segment = segments.pop();
71
+ if (segment === '**') {
72
+ if (segments.length > 0) {
73
+ regex += WILD_OPEN;
74
+ } else {
75
+ regex += '.*';
76
+ }
77
+ } else {
78
+ const processed = toEscape.reduce((segment, escape) => segment.replace(escape.replace, escape.with), segment);
79
+ regex += processed;
80
+ if (segments.length > 0) {
81
+ regex += '\\/';
82
+ }
77
83
  }
78
- return regex;
84
+ }
85
+ return regex;
79
86
  }
80
87
 
81
- const DEFAULT_NAVIGATION_URLS = [
82
- '/**', // Include all URLs.
83
- '!/**/*.*', // Exclude URLs to files (containing a file extension in the last segment).
84
- '!/**/*__*', // Exclude URLs containing `__` in the last segment.
85
- '!/**/*__*/**', // Exclude URLs containing `__` in any other segment.
86
- ];
87
- /**
88
- * Consumes service worker configuration files and processes them into control files.
89
- *
90
- * @publicApi
91
- */
88
+ const DEFAULT_NAVIGATION_URLS = ['/**', '!/**/*.*', '!/**/*__*', '!/**/*__*/**'];
92
89
  class Generator {
93
- fs;
94
- baseHref;
95
- constructor(fs, baseHref) {
96
- this.fs = fs;
97
- this.baseHref = baseHref;
98
- }
99
- async process(config) {
100
- const unorderedHashTable = {};
101
- const assetGroups = await this.processAssetGroups(config, unorderedHashTable);
102
- return {
103
- configVersion: 1,
104
- timestamp: Date.now(),
105
- appData: config.appData,
106
- index: joinUrls(this.baseHref, config.index),
107
- assetGroups,
108
- dataGroups: this.processDataGroups(config),
109
- hashTable: withOrderedKeys(unorderedHashTable),
110
- navigationUrls: processNavigationUrls(this.baseHref, config.navigationUrls),
111
- navigationRequestStrategy: config.navigationRequestStrategy ?? 'performance',
112
- applicationMaxAge: config.applicationMaxAge
113
- ? parseDurationToMs(config.applicationMaxAge)
114
- : undefined,
115
- };
116
- }
117
- async processAssetGroups(config, hashTable) {
118
- // Retrieve all files of the build.
119
- const allFiles = await this.fs.list('/');
120
- const seenMap = new Set();
121
- const filesPerGroup = new Map();
122
- // Computed which files belong to each asset-group.
123
- for (const group of config.assetGroups || []) {
124
- if (group.resources.versionedFiles) {
125
- throw new Error(`Asset-group '${group.name}' in 'ngsw-config.json' uses the 'versionedFiles' option, ` +
126
- "which is no longer supported. Use 'files' instead.");
127
- }
128
- const fileMatcher = globListToMatcher(group.resources.files || []);
129
- const matchedFiles = allFiles
130
- .filter(fileMatcher)
131
- .filter((file) => !seenMap.has(file))
132
- .sort();
133
- matchedFiles.forEach((file) => seenMap.add(file));
134
- filesPerGroup.set(group, matchedFiles);
135
- }
136
- // Compute hashes for all matched files and add them to the hash-table.
137
- const allMatchedFiles = [].concat(...Array.from(filesPerGroup.values())).sort();
138
- const allMatchedHashes = await processInBatches(allMatchedFiles, 500, (file) => this.fs.hash(file));
139
- allMatchedFiles.forEach((file, idx) => {
140
- hashTable[joinUrls(this.baseHref, file)] = allMatchedHashes[idx];
141
- });
142
- // Generate and return the processed asset-groups.
143
- return Array.from(filesPerGroup.entries()).map(([group, matchedFiles]) => ({
144
- name: group.name,
145
- installMode: group.installMode || 'prefetch',
146
- updateMode: group.updateMode || group.installMode || 'prefetch',
147
- cacheQueryOptions: buildCacheQueryOptions(group.cacheQueryOptions),
148
- urls: matchedFiles.map((url) => joinUrls(this.baseHref, url)),
149
- patterns: (group.resources.urls || []).map((url) => urlToRegex(url, this.baseHref, true)),
150
- }));
151
- }
152
- processDataGroups(config) {
153
- return (config.dataGroups || []).map((group) => {
154
- return {
155
- name: group.name,
156
- patterns: group.urls.map((url) => urlToRegex(url, this.baseHref, true)),
157
- strategy: group.cacheConfig.strategy || 'performance',
158
- maxSize: group.cacheConfig.maxSize,
159
- maxAge: parseDurationToMs(group.cacheConfig.maxAge),
160
- timeoutMs: group.cacheConfig.timeout && parseDurationToMs(group.cacheConfig.timeout),
161
- refreshAheadMs: group.cacheConfig.refreshAhead && parseDurationToMs(group.cacheConfig.refreshAhead),
162
- cacheOpaqueResponses: group.cacheConfig.cacheOpaqueResponses,
163
- cacheQueryOptions: buildCacheQueryOptions(group.cacheQueryOptions),
164
- version: group.version !== undefined ? group.version : 1,
165
- };
166
- });
90
+ fs;
91
+ baseHref;
92
+ constructor(fs, baseHref) {
93
+ this.fs = fs;
94
+ this.baseHref = baseHref;
95
+ }
96
+ async process(config) {
97
+ const unorderedHashTable = {};
98
+ const assetGroups = await this.processAssetGroups(config, unorderedHashTable);
99
+ return {
100
+ configVersion: 1,
101
+ timestamp: Date.now(),
102
+ appData: config.appData,
103
+ index: joinUrls(this.baseHref, config.index),
104
+ assetGroups,
105
+ dataGroups: this.processDataGroups(config),
106
+ hashTable: withOrderedKeys(unorderedHashTable),
107
+ navigationUrls: processNavigationUrls(this.baseHref, config.navigationUrls),
108
+ navigationRequestStrategy: config.navigationRequestStrategy ?? 'performance',
109
+ applicationMaxAge: config.applicationMaxAge ? parseDurationToMs(config.applicationMaxAge) : undefined
110
+ };
111
+ }
112
+ async processAssetGroups(config, hashTable) {
113
+ const allFiles = await this.fs.list('/');
114
+ const seenMap = new Set();
115
+ const filesPerGroup = new Map();
116
+ for (const group of config.assetGroups || []) {
117
+ if (group.resources.versionedFiles) {
118
+ throw new Error(`Asset-group '${group.name}' in 'ngsw-config.json' uses the 'versionedFiles' option, ` + "which is no longer supported. Use 'files' instead.");
119
+ }
120
+ const fileMatcher = globListToMatcher(group.resources.files || []);
121
+ const matchedFiles = allFiles.filter(fileMatcher).filter(file => !seenMap.has(file)).sort();
122
+ matchedFiles.forEach(file => seenMap.add(file));
123
+ filesPerGroup.set(group, matchedFiles);
167
124
  }
125
+ const allMatchedFiles = [].concat(...Array.from(filesPerGroup.values())).sort();
126
+ const allMatchedHashes = await processInBatches(allMatchedFiles, 500, file => this.fs.hash(file));
127
+ allMatchedFiles.forEach((file, idx) => {
128
+ hashTable[joinUrls(this.baseHref, file)] = allMatchedHashes[idx];
129
+ });
130
+ return Array.from(filesPerGroup.entries()).map(([group, matchedFiles]) => ({
131
+ name: group.name,
132
+ installMode: group.installMode || 'prefetch',
133
+ updateMode: group.updateMode || group.installMode || 'prefetch',
134
+ cacheQueryOptions: buildCacheQueryOptions(group.cacheQueryOptions),
135
+ urls: matchedFiles.map(url => joinUrls(this.baseHref, url)),
136
+ patterns: (group.resources.urls || []).map(url => urlToRegex(url, this.baseHref, true))
137
+ }));
138
+ }
139
+ processDataGroups(config) {
140
+ return (config.dataGroups || []).map(group => {
141
+ return {
142
+ name: group.name,
143
+ patterns: group.urls.map(url => urlToRegex(url, this.baseHref, true)),
144
+ strategy: group.cacheConfig.strategy || 'performance',
145
+ maxSize: group.cacheConfig.maxSize,
146
+ maxAge: parseDurationToMs(group.cacheConfig.maxAge),
147
+ timeoutMs: group.cacheConfig.timeout && parseDurationToMs(group.cacheConfig.timeout),
148
+ refreshAheadMs: group.cacheConfig.refreshAhead && parseDurationToMs(group.cacheConfig.refreshAhead),
149
+ cacheOpaqueResponses: group.cacheConfig.cacheOpaqueResponses,
150
+ cacheQueryOptions: buildCacheQueryOptions(group.cacheQueryOptions),
151
+ version: group.version !== undefined ? group.version : 1
152
+ };
153
+ });
154
+ }
168
155
  }
169
156
  function processNavigationUrls(baseHref, urls = DEFAULT_NAVIGATION_URLS) {
170
- return urls.map((url) => {
171
- const positive = !url.startsWith('!');
172
- url = positive ? url : url.slice(1);
173
- return { positive, regex: `^${urlToRegex(url, baseHref)}$` };
174
- });
157
+ return urls.map(url => {
158
+ const positive = !url.startsWith('!');
159
+ url = positive ? url : url.slice(1);
160
+ return {
161
+ positive,
162
+ regex: `^${urlToRegex(url, baseHref)}$`
163
+ };
164
+ });
175
165
  }
176
166
  async function processInBatches(items, batchSize, processFn) {
177
- const batches = [];
178
- for (let i = 0; i < items.length; i += batchSize) {
179
- batches.push(items.slice(i, i + batchSize));
180
- }
181
- return batches.reduce(async (prev, batch) => (await prev).concat(await Promise.all(batch.map((item) => processFn(item)))), Promise.resolve([]));
167
+ const batches = [];
168
+ for (let i = 0; i < items.length; i += batchSize) {
169
+ batches.push(items.slice(i, i + batchSize));
170
+ }
171
+ return batches.reduce(async (prev, batch) => (await prev).concat(await Promise.all(batch.map(item => processFn(item)))), Promise.resolve([]));
182
172
  }
183
173
  function globListToMatcher(globs) {
184
- const patterns = globs.map((pattern) => {
185
- if (pattern.startsWith('!')) {
186
- return {
187
- positive: false,
188
- regex: new RegExp('^' + globToRegex(pattern.slice(1)) + '$'),
189
- };
190
- }
191
- else {
192
- return {
193
- positive: true,
194
- regex: new RegExp('^' + globToRegex(pattern) + '$'),
195
- };
196
- }
197
- });
198
- return (file) => matches(file, patterns);
174
+ const patterns = globs.map(pattern => {
175
+ if (pattern.startsWith('!')) {
176
+ return {
177
+ positive: false,
178
+ regex: new RegExp('^' + globToRegex(pattern.slice(1)) + '$')
179
+ };
180
+ } else {
181
+ return {
182
+ positive: true,
183
+ regex: new RegExp('^' + globToRegex(pattern) + '$')
184
+ };
185
+ }
186
+ });
187
+ return file => matches(file, patterns);
199
188
  }
200
189
  function matches(file, patterns) {
201
- return patterns.reduce((isMatch, pattern) => {
202
- if (pattern.positive) {
203
- return isMatch || pattern.regex.test(file);
204
- }
205
- else {
206
- return isMatch && !pattern.regex.test(file);
207
- }
208
- }, false);
190
+ return patterns.reduce((isMatch, pattern) => {
191
+ if (pattern.positive) {
192
+ return isMatch || pattern.regex.test(file);
193
+ } else {
194
+ return isMatch && !pattern.regex.test(file);
195
+ }
196
+ }, false);
209
197
  }
210
198
  function urlToRegex(url, baseHref, literalQuestionMark) {
211
- if (!url.startsWith('/') && url.indexOf('://') === -1) {
212
- // Prefix relative URLs with `baseHref`.
213
- // Strip a leading `.` from a relative `baseHref` (e.g. `./foo/`), since it would result in an
214
- // incorrect regex (matching a literal `.`).
215
- url = joinUrls(baseHref.replace(/^\.(?=\/)/, ''), url);
216
- }
217
- return globToRegex(url, literalQuestionMark);
199
+ if (!url.startsWith('/') && url.indexOf('://') === -1) {
200
+ url = joinUrls(baseHref.replace(/^\.(?=\/)/, ''), url);
201
+ }
202
+ return globToRegex(url, literalQuestionMark);
218
203
  }
219
204
  function joinUrls(a, b) {
220
- if (a.endsWith('/') && b.startsWith('/')) {
221
- return a + b.slice(1);
222
- }
223
- else if (!a.endsWith('/') && !b.startsWith('/')) {
224
- return a + '/' + b;
225
- }
226
- return a + b;
205
+ if (a.endsWith('/') && b.startsWith('/')) {
206
+ return a + b.slice(1);
207
+ } else if (!a.endsWith('/') && !b.startsWith('/')) {
208
+ return a + '/' + b;
209
+ }
210
+ return a + b;
227
211
  }
228
212
  function withOrderedKeys(unorderedObj) {
229
- const orderedObj = {};
230
- Object.keys(unorderedObj)
231
- .sort()
232
- .forEach((key) => (orderedObj[key] = unorderedObj[key]));
233
- return orderedObj;
213
+ const orderedObj = {};
214
+ Object.keys(unorderedObj).sort().forEach(key => orderedObj[key] = unorderedObj[key]);
215
+ return orderedObj;
234
216
  }
235
217
  function buildCacheQueryOptions(inOptions) {
236
- return {
237
- ignoreVary: true,
238
- ...inOptions,
239
- };
218
+ return {
219
+ ignoreVary: true,
220
+ ...inOptions
221
+ };
240
222
  }
241
223
 
242
224
  export { Generator };
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","sources":["../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/packages/service-worker/config/src/duration.ts","../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/packages/service-worker/config/src/glob.ts","../../../../../k8-fastbuild-ST-199a4f3c4e20/bin/packages/service-worker/config/src/generator.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nconst PARSE_TO_PAIRS = /([0-9]+[^0-9]+)/g;\nconst PAIR_SPLIT = /^([0-9]+)([dhmsu]+)$/;\n\nexport function parseDurationToMs(duration: string): number {\n const matches: string[] = [];\n\n let array: RegExpExecArray | null;\n while ((array = PARSE_TO_PAIRS.exec(duration)) !== null) {\n matches.push(array[0]);\n }\n return matches\n .map((match) => {\n const res = PAIR_SPLIT.exec(match);\n if (res === null) {\n throw new Error(`Not a valid duration: ${match}`);\n }\n let factor: number = 0;\n switch (res[2]) {\n case 'd':\n factor = 86400000;\n break;\n case 'h':\n factor = 3600000;\n break;\n case 'm':\n factor = 60000;\n break;\n case 's':\n factor = 1000;\n break;\n case 'u':\n factor = 1;\n break;\n default:\n throw new Error(`Not a valid duration unit: ${res[2]}`);\n }\n return parseInt(res[1]) * factor;\n })\n .reduce((total, value) => total + value, 0);\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nconst QUESTION_MARK = '[^/]';\nconst WILD_SINGLE = '[^/]*';\nconst WILD_OPEN = '(?:.+\\\\/)?';\n\nconst TO_ESCAPE_BASE = [\n {replace: /\\./g, with: '\\\\.'},\n {replace: /\\+/g, with: '\\\\+'},\n {replace: /\\*/g, with: WILD_SINGLE},\n];\nconst TO_ESCAPE_WILDCARD_QM = [...TO_ESCAPE_BASE, {replace: /\\?/g, with: QUESTION_MARK}];\nconst TO_ESCAPE_LITERAL_QM = [...TO_ESCAPE_BASE, {replace: /\\?/g, with: '\\\\?'}];\n\nexport function globToRegex(glob: string, literalQuestionMark = false): string {\n const toEscape = literalQuestionMark ? TO_ESCAPE_LITERAL_QM : TO_ESCAPE_WILDCARD_QM;\n const segments = glob.split('/').reverse();\n let regex: string = '';\n while (segments.length > 0) {\n const segment = segments.pop()!;\n if (segment === '**') {\n if (segments.length > 0) {\n regex += WILD_OPEN;\n } else {\n regex += '.*';\n }\n } else {\n const processed = toEscape.reduce(\n (segment, escape) => segment.replace(escape.replace, escape.with),\n segment,\n );\n regex += processed;\n if (segments.length > 0) {\n regex += '\\\\/';\n }\n }\n }\n return regex;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {parseDurationToMs} from './duration';\nimport {Filesystem} from './filesystem';\nimport {globToRegex} from './glob';\nimport {AssetGroup, Config} from './in';\n\nconst DEFAULT_NAVIGATION_URLS = [\n '/**', // Include all URLs.\n '!/**/*.*', // Exclude URLs to files (containing a file extension in the last segment).\n '!/**/*__*', // Exclude URLs containing `__` in the last segment.\n '!/**/*__*/**', // Exclude URLs containing `__` in any other segment.\n];\n\n/**\n * Consumes service worker configuration files and processes them into control files.\n *\n * @publicApi\n */\nexport class Generator {\n constructor(\n readonly fs: Filesystem,\n private baseHref: string,\n ) {}\n\n async process(config: Config): Promise<Object> {\n const unorderedHashTable = {};\n const assetGroups = await this.processAssetGroups(config, unorderedHashTable);\n\n return {\n configVersion: 1,\n timestamp: Date.now(),\n appData: config.appData,\n index: joinUrls(this.baseHref, config.index),\n assetGroups,\n dataGroups: this.processDataGroups(config),\n hashTable: withOrderedKeys(unorderedHashTable),\n navigationUrls: processNavigationUrls(this.baseHref, config.navigationUrls),\n navigationRequestStrategy: config.navigationRequestStrategy ?? 'performance',\n applicationMaxAge: config.applicationMaxAge\n ? parseDurationToMs(config.applicationMaxAge)\n : undefined,\n };\n }\n\n private async processAssetGroups(\n config: Config,\n hashTable: {[file: string]: string | undefined},\n ): Promise<Object[]> {\n // Retrieve all files of the build.\n const allFiles = await this.fs.list('/');\n const seenMap = new Set<string>();\n const filesPerGroup = new Map<AssetGroup, string[]>();\n\n // Computed which files belong to each asset-group.\n for (const group of config.assetGroups || []) {\n if ((group.resources as any).versionedFiles) {\n throw new Error(\n `Asset-group '${group.name}' in 'ngsw-config.json' uses the 'versionedFiles' option, ` +\n \"which is no longer supported. Use 'files' instead.\",\n );\n }\n\n const fileMatcher = globListToMatcher(group.resources.files || []);\n const matchedFiles = allFiles\n .filter(fileMatcher)\n .filter((file) => !seenMap.has(file))\n .sort();\n\n matchedFiles.forEach((file) => seenMap.add(file));\n filesPerGroup.set(group, matchedFiles);\n }\n\n // Compute hashes for all matched files and add them to the hash-table.\n const allMatchedFiles = ([] as string[]).concat(...Array.from(filesPerGroup.values())).sort();\n const allMatchedHashes = await processInBatches(allMatchedFiles, 500, (file) =>\n this.fs.hash(file),\n );\n allMatchedFiles.forEach((file, idx) => {\n hashTable[joinUrls(this.baseHref, file)] = allMatchedHashes[idx];\n });\n\n // Generate and return the processed asset-groups.\n return Array.from(filesPerGroup.entries()).map(([group, matchedFiles]) => ({\n name: group.name,\n installMode: group.installMode || 'prefetch',\n updateMode: group.updateMode || group.installMode || 'prefetch',\n cacheQueryOptions: buildCacheQueryOptions(group.cacheQueryOptions),\n urls: matchedFiles.map((url) => joinUrls(this.baseHref, url)),\n patterns: (group.resources.urls || []).map((url) => urlToRegex(url, this.baseHref, true)),\n }));\n }\n\n private processDataGroups(config: Config): Object[] {\n return (config.dataGroups || []).map((group) => {\n return {\n name: group.name,\n patterns: group.urls.map((url) => urlToRegex(url, this.baseHref, true)),\n strategy: group.cacheConfig.strategy || 'performance',\n maxSize: group.cacheConfig.maxSize,\n maxAge: parseDurationToMs(group.cacheConfig.maxAge),\n timeoutMs: group.cacheConfig.timeout && parseDurationToMs(group.cacheConfig.timeout),\n refreshAheadMs:\n group.cacheConfig.refreshAhead && parseDurationToMs(group.cacheConfig.refreshAhead),\n cacheOpaqueResponses: group.cacheConfig.cacheOpaqueResponses,\n cacheQueryOptions: buildCacheQueryOptions(group.cacheQueryOptions),\n version: group.version !== undefined ? group.version : 1,\n };\n });\n }\n}\n\nexport function processNavigationUrls(\n baseHref: string,\n urls = DEFAULT_NAVIGATION_URLS,\n): {positive: boolean; regex: string}[] {\n return urls.map((url) => {\n const positive = !url.startsWith('!');\n url = positive ? url : url.slice(1);\n return {positive, regex: `^${urlToRegex(url, baseHref)}$`};\n });\n}\n\nasync function processInBatches<I, O>(\n items: I[],\n batchSize: number,\n processFn: (item: I) => O | Promise<O>,\n): Promise<O[]> {\n const batches = [];\n\n for (let i = 0; i < items.length; i += batchSize) {\n batches.push(items.slice(i, i + batchSize));\n }\n\n return batches.reduce(\n async (prev, batch) =>\n (await prev).concat(await Promise.all(batch.map((item) => processFn(item)))),\n Promise.resolve<O[]>([]),\n );\n}\n\nfunction globListToMatcher(globs: string[]): (file: string) => boolean {\n const patterns = globs.map((pattern) => {\n if (pattern.startsWith('!')) {\n return {\n positive: false,\n regex: new RegExp('^' + globToRegex(pattern.slice(1)) + '$'),\n };\n } else {\n return {\n positive: true,\n regex: new RegExp('^' + globToRegex(pattern) + '$'),\n };\n }\n });\n return (file: string) => matches(file, patterns);\n}\n\nfunction matches(file: string, patterns: {positive: boolean; regex: RegExp}[]): boolean {\n return patterns.reduce((isMatch, pattern) => {\n if (pattern.positive) {\n return isMatch || pattern.regex.test(file);\n } else {\n return isMatch && !pattern.regex.test(file);\n }\n }, false);\n}\n\nfunction urlToRegex(url: string, baseHref: string, literalQuestionMark?: boolean): string {\n if (!url.startsWith('/') && url.indexOf('://') === -1) {\n // Prefix relative URLs with `baseHref`.\n // Strip a leading `.` from a relative `baseHref` (e.g. `./foo/`), since it would result in an\n // incorrect regex (matching a literal `.`).\n url = joinUrls(baseHref.replace(/^\\.(?=\\/)/, ''), url);\n }\n\n return globToRegex(url, literalQuestionMark);\n}\n\nfunction joinUrls(a: string, b: string): string {\n if (a.endsWith('/') && b.startsWith('/')) {\n return a + b.slice(1);\n } else if (!a.endsWith('/') && !b.startsWith('/')) {\n return a + '/' + b;\n }\n return a + b;\n}\n\nfunction withOrderedKeys<T extends {[key: string]: any}>(unorderedObj: T): T {\n const orderedObj = {} as {[key: string]: any};\n Object.keys(unorderedObj)\n .sort()\n .forEach((key) => (orderedObj[key] = unorderedObj[key]));\n return orderedObj as T;\n}\n\nfunction buildCacheQueryOptions(\n inOptions?: Pick<CacheQueryOptions, 'ignoreSearch'>,\n): CacheQueryOptions {\n return {\n ignoreVary: true,\n ...inOptions,\n };\n}\n"],"names":[],"mappings":";;;;;;AAQA,MAAM,cAAc,GAAG,kBAAkB;AACzC,M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I,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE;;;;AAIrD,QAAA,GAAG,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC;;AAGxD,IAAA,OAAO,WAAW,CAAC,GAAG,EAAE,mBAAmB,CAAC;AAC9C;AAEA,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS,EAAA;AACpC,IAAA,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;;AAChB,SAAA,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;AACjD,QAAA,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC;;IAEpB,OAAO,CAAC,GAAG,CAAC;AACd;AAEA,SAAS,eAAe,CAAiC,YAAe,EAAA;IACtE,MAAM,UAAU,GAAG,EAA0B;AAC7C,IAAA,MAAM,CAAC,IAAI,CAAC,YAAY;AACrB,SAAA,IAAI;AACJ,SAAA,OAAO,CAAC,CAAC,GAAG,MAAM,UAAU,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1D,IAAA,OAAO,UAAe;AACxB;AAEA,SAAS,sBAAsB,CAC7B,SAAmD,EAAA;IAEnD,OAAO;AACL,QAAA,UAAU,EAAE,IAAI;AAChB,QAAA,GAAG,SAAS;KACb;AACH;;;;"}
1
+ {"version":3,"file":"config.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/packages/service-worker/config/src/duration.ts","../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/packages/service-worker/config/src/glob.ts","../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/packages/service-worker/config/src/generator.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nconst PARSE_TO_PAIRS = /([0-9]+[^0-9]+)/g;\nconst PAIR_SPLIT = /^([0-9]+)([dhmsu]+)$/;\n\nexport function parseDurationToMs(duration: string): number {\n const matches: string[] = [];\n\n let array: RegExpExecArray | null;\n while ((array = PARSE_TO_PAIRS.exec(duration)) !== null) {\n matches.push(array[0]);\n }\n return matches\n .map((match) => {\n const res = PAIR_SPLIT.exec(match);\n if (res === null) {\n throw new Error(`Not a valid duration: ${match}`);\n }\n let factor: number = 0;\n switch (res[2]) {\n case 'd':\n factor = 86400000;\n break;\n case 'h':\n factor = 3600000;\n break;\n case 'm':\n factor = 60000;\n break;\n case 's':\n factor = 1000;\n break;\n case 'u':\n factor = 1;\n break;\n default:\n throw new Error(`Not a valid duration unit: ${res[2]}`);\n }\n return parseInt(res[1]) * factor;\n })\n .reduce((total, value) => total + value, 0);\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nconst QUESTION_MARK = '[^/]';\nconst WILD_SINGLE = '[^/]*';\nconst WILD_OPEN = '(?:.+\\\\/)?';\n\nconst TO_ESCAPE_BASE = [\n {replace: /\\./g, with: '\\\\.'},\n {replace: /\\+/g, with: '\\\\+'},\n {replace: /\\*/g, with: WILD_SINGLE},\n];\nconst TO_ESCAPE_WILDCARD_QM = [...TO_ESCAPE_BASE, {replace: /\\?/g, with: QUESTION_MARK}];\nconst TO_ESCAPE_LITERAL_QM = [...TO_ESCAPE_BASE, {replace: /\\?/g, with: '\\\\?'}];\n\nexport function globToRegex(glob: string, literalQuestionMark = false): string {\n const toEscape = literalQuestionMark ? TO_ESCAPE_LITERAL_QM : TO_ESCAPE_WILDCARD_QM;\n const segments = glob.split('/').reverse();\n let regex: string = '';\n while (segments.length > 0) {\n const segment = segments.pop()!;\n if (segment === '**') {\n if (segments.length > 0) {\n regex += WILD_OPEN;\n } else {\n regex += '.*';\n }\n } else {\n const processed = toEscape.reduce(\n (segment, escape) => segment.replace(escape.replace, escape.with),\n segment,\n );\n regex += processed;\n if (segments.length > 0) {\n regex += '\\\\/';\n }\n }\n }\n return regex;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {parseDurationToMs} from './duration';\nimport {Filesystem} from './filesystem';\nimport {globToRegex} from './glob';\nimport {AssetGroup, Config} from './in';\n\nconst DEFAULT_NAVIGATION_URLS = [\n '/**', // Include all URLs.\n '!/**/*.*', // Exclude URLs to files (containing a file extension in the last segment).\n '!/**/*__*', // Exclude URLs containing `__` in the last segment.\n '!/**/*__*/**', // Exclude URLs containing `__` in any other segment.\n];\n\n/**\n * Consumes service worker configuration files and processes them into control files.\n *\n * @publicApi\n */\nexport class Generator {\n constructor(\n readonly fs: Filesystem,\n private baseHref: string,\n ) {}\n\n async process(config: Config): Promise<Object> {\n const unorderedHashTable = {};\n const assetGroups = await this.processAssetGroups(config, unorderedHashTable);\n\n return {\n configVersion: 1,\n timestamp: Date.now(),\n appData: config.appData,\n index: joinUrls(this.baseHref, config.index),\n assetGroups,\n dataGroups: this.processDataGroups(config),\n hashTable: withOrderedKeys(unorderedHashTable),\n navigationUrls: processNavigationUrls(this.baseHref, config.navigationUrls),\n navigationRequestStrategy: config.navigationRequestStrategy ?? 'performance',\n applicationMaxAge: config.applicationMaxAge\n ? parseDurationToMs(config.applicationMaxAge)\n : undefined,\n };\n }\n\n private async processAssetGroups(\n config: Config,\n hashTable: {[file: string]: string | undefined},\n ): Promise<Object[]> {\n // Retrieve all files of the build.\n const allFiles = await this.fs.list('/');\n const seenMap = new Set<string>();\n const filesPerGroup = new Map<AssetGroup, string[]>();\n\n // Computed which files belong to each asset-group.\n for (const group of config.assetGroups || []) {\n if ((group.resources as any).versionedFiles) {\n throw new Error(\n `Asset-group '${group.name}' in 'ngsw-config.json' uses the 'versionedFiles' option, ` +\n \"which is no longer supported. Use 'files' instead.\",\n );\n }\n\n const fileMatcher = globListToMatcher(group.resources.files || []);\n const matchedFiles = allFiles\n .filter(fileMatcher)\n .filter((file) => !seenMap.has(file))\n .sort();\n\n matchedFiles.forEach((file) => seenMap.add(file));\n filesPerGroup.set(group, matchedFiles);\n }\n\n // Compute hashes for all matched files and add them to the hash-table.\n const allMatchedFiles = ([] as string[]).concat(...Array.from(filesPerGroup.values())).sort();\n const allMatchedHashes = await processInBatches(allMatchedFiles, 500, (file) =>\n this.fs.hash(file),\n );\n allMatchedFiles.forEach((file, idx) => {\n hashTable[joinUrls(this.baseHref, file)] = allMatchedHashes[idx];\n });\n\n // Generate and return the processed asset-groups.\n return Array.from(filesPerGroup.entries()).map(([group, matchedFiles]) => ({\n name: group.name,\n installMode: group.installMode || 'prefetch',\n updateMode: group.updateMode || group.installMode || 'prefetch',\n cacheQueryOptions: buildCacheQueryOptions(group.cacheQueryOptions),\n urls: matchedFiles.map((url) => joinUrls(this.baseHref, url)),\n patterns: (group.resources.urls || []).map((url) => urlToRegex(url, this.baseHref, true)),\n }));\n }\n\n private processDataGroups(config: Config): Object[] {\n return (config.dataGroups || []).map((group) => {\n return {\n name: group.name,\n patterns: group.urls.map((url) => urlToRegex(url, this.baseHref, true)),\n strategy: group.cacheConfig.strategy || 'performance',\n maxSize: group.cacheConfig.maxSize,\n maxAge: parseDurationToMs(group.cacheConfig.maxAge),\n timeoutMs: group.cacheConfig.timeout && parseDurationToMs(group.cacheConfig.timeout),\n refreshAheadMs:\n group.cacheConfig.refreshAhead && parseDurationToMs(group.cacheConfig.refreshAhead),\n cacheOpaqueResponses: group.cacheConfig.cacheOpaqueResponses,\n cacheQueryOptions: buildCacheQueryOptions(group.cacheQueryOptions),\n version: group.version !== undefined ? group.version : 1,\n };\n });\n }\n}\n\nexport function processNavigationUrls(\n baseHref: string,\n urls = DEFAULT_NAVIGATION_URLS,\n): {positive: boolean; regex: string}[] {\n return urls.map((url) => {\n const positive = !url.startsWith('!');\n url = positive ? url : url.slice(1);\n return {positive, regex: `^${urlToRegex(url, baseHref)}$`};\n });\n}\n\nasync function processInBatches<I, O>(\n items: I[],\n batchSize: number,\n processFn: (item: I) => O | Promise<O>,\n): Promise<O[]> {\n const batches = [];\n\n for (let i = 0; i < items.length; i += batchSize) {\n batches.push(items.slice(i, i + batchSize));\n }\n\n return batches.reduce(\n async (prev, batch) =>\n (await prev).concat(await Promise.all(batch.map((item) => processFn(item)))),\n Promise.resolve<O[]>([]),\n );\n}\n\nfunction globListToMatcher(globs: string[]): (file: string) => boolean {\n const patterns = globs.map((pattern) => {\n if (pattern.startsWith('!')) {\n return {\n positive: false,\n regex: new RegExp('^' + globToRegex(pattern.slice(1)) + '$'),\n };\n } else {\n return {\n positive: true,\n regex: new RegExp('^' + globToRegex(pattern) + '$'),\n };\n }\n });\n return (file: string) => matches(file, patterns);\n}\n\nfunction matches(file: string, patterns: {positive: boolean; regex: RegExp}[]): boolean {\n return patterns.reduce((isMatch, pattern) => {\n if (pattern.positive) {\n return isMatch || pattern.regex.test(file);\n } else {\n return isMatch && !pattern.regex.test(file);\n }\n }, false);\n}\n\nfunction urlToRegex(url: string, baseHref: string, literalQuestionMark?: boolean): string {\n if (!url.startsWith('/') && url.indexOf('://') === -1) {\n // Prefix relative URLs with `baseHref`.\n // Strip a leading `.` from a relative `baseHref` (e.g. `./foo/`), since it would result in an\n // incorrect regex (matching a literal `.`).\n url = joinUrls(baseHref.replace(/^\\.(?=\\/)/, ''), url);\n }\n\n return globToRegex(url, literalQuestionMark);\n}\n\nfunction joinUrls(a: string, b: string): string {\n if (a.endsWith('/') && b.startsWith('/')) {\n return a + b.slice(1);\n } else if (!a.endsWith('/') && !b.startsWith('/')) {\n return a + '/' + b;\n }\n return a + b;\n}\n\nfunction withOrderedKeys<T extends {[key: string]: any}>(unorderedObj: T): T {\n const orderedObj = {} as {[key: string]: any};\n Object.keys(unorderedObj)\n .sort()\n .forEach((key) => (orderedObj[key] = unorderedObj[key]));\n return orderedObj as T;\n}\n\nfunction buildCacheQueryOptions(\n inOptions?: Pick<CacheQueryOptions, 'ignoreSearch'>,\n): CacheQueryOptions {\n return {\n ignoreVary: true,\n ...inOptions,\n };\n}\n"],"names":["PARSE_TO_PAIRS","matches","map","match","res","PAIR_SPLIT","Error","factor","QUESTION_MARK","replace","with","WILD_SINGLE","TO_ESCAPE_WILDCARD_QM","TO_ESCAPE_BASE","TO_ESCAPE_LITERAL_QM","globToRegex","glob","literalQuestionMark","segments","split","regex","length","segment","pop","WILD_OPEN","toEscape","process","config","unorderedHashTable","assetGroups","processAssetGroups","configVersion","timestamp","Date","now","appData","joinUrls","baseHref","index","processDataGroups","hashTable","withOrderedKeys","processNavigationUrls","navigationUrls","navigationRequestStrategy","applicationMaxAge","parseDurationToMs","allFiles","fs","list","Set","Map","group","versionedFiles","name","fileMatcher","globListToMatcher","resources","files","filter","file","seenMap","has","sort","forEach","add","concat","Array","from","filesPerGroup","values","processInBatches","allMatchedFiles","hash","idx","allMatchedHashes","entries","matchedFiles","installMode","updateMode","cacheQueryOptions","buildCacheQueryOptions","patterns","urls","url","urlToRegex","dataGroups","strategy","cacheConfig","maxSize","maxAge","timeoutMs","timeout","refreshAheadMs","refreshAhead","cacheOpaqueResponses","version","undefined","DEFAULT_NAVIGATION_URLS","startsWith","positive","items","processFn","i","batchSize","slice","globs","pattern","RegExp","reduce","isMatch","test"],"mappings":";;;;;;AAQA,MAAAA,cAAA,GAAA,kBAAA;;;;;;;AAUE;AACG,EAAA,OAAAC,OAAU,CAETC,GAAA,CAAAC,KAAO,IAAA;AACL,IAAA,MAAAC,GAAA,GAAgBC;WAEI,KAAA,IAAA,EAAA;AACtB,MAAA,MAAA,IAAWC,KAAA,CAAKH,CAAAA,sBAAAA,EAAA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