@serwist/webpack-plugin 9.5.7 → 9.5.8

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.
Files changed (51) hide show
  1. package/dist/chunks/relative-to-output-path-Gvhd54pA.js +49 -0
  2. package/dist/chunks/relative-to-output-path-Gvhd54pA.js.map +1 -0
  3. package/dist/chunks/schema-CpgCa1bB.js +51 -0
  4. package/dist/chunks/schema-CpgCa1bB.js.map +1 -0
  5. package/dist/index.d.mts +137 -0
  6. package/dist/index.d.mts.map +1 -0
  7. package/dist/index.internal.d.mts +44 -0
  8. package/dist/index.internal.d.mts.map +1 -0
  9. package/dist/index.internal.mjs +31 -0
  10. package/dist/index.internal.mjs.map +1 -0
  11. package/dist/index.mjs +345 -0
  12. package/dist/index.mjs.map +1 -0
  13. package/dist/index.schema.d.mts +90 -0
  14. package/dist/index.schema.d.mts.map +1 -0
  15. package/dist/index.schema.mjs +2 -0
  16. package/package.json +19 -20
  17. package/dist/chunks/relative-to-output-path.js +0 -34
  18. package/dist/chunks/schema.js +0 -37
  19. package/dist/index.d.ts +0 -6
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/index.internal.d.ts +0 -4
  22. package/dist/index.internal.d.ts.map +0 -1
  23. package/dist/index.internal.js +0 -21
  24. package/dist/index.js +0 -281
  25. package/dist/index.schema.d.ts +0 -3
  26. package/dist/index.schema.d.ts.map +0 -1
  27. package/dist/index.schema.js +0 -3
  28. package/dist/inject-manifest.d.ts +0 -72
  29. package/dist/inject-manifest.d.ts.map +0 -1
  30. package/dist/lib/child-compilation-plugin.d.ts +0 -24
  31. package/dist/lib/child-compilation-plugin.d.ts.map +0 -1
  32. package/dist/lib/get-asset-hash.d.ts +0 -9
  33. package/dist/lib/get-asset-hash.d.ts.map +0 -1
  34. package/dist/lib/get-manifest-entries-from-compilation.d.ts +0 -8
  35. package/dist/lib/get-manifest-entries-from-compilation.d.ts.map +0 -1
  36. package/dist/lib/get-script-files-for-chunks.d.ts +0 -3
  37. package/dist/lib/get-script-files-for-chunks.d.ts.map +0 -1
  38. package/dist/lib/get-sourcemap-asset-name.d.ts +0 -20
  39. package/dist/lib/get-sourcemap-asset-name.d.ts.map +0 -1
  40. package/dist/lib/perform-child-compilation.d.ts +0 -16
  41. package/dist/lib/perform-child-compilation.d.ts.map +0 -1
  42. package/dist/lib/relative-to-output-path.d.ts +0 -12
  43. package/dist/lib/relative-to-output-path.d.ts.map +0 -1
  44. package/dist/lib/resolve-webpack-url.d.ts +0 -13
  45. package/dist/lib/resolve-webpack-url.d.ts.map +0 -1
  46. package/dist/lib/schema.d.ts +0 -86
  47. package/dist/lib/schema.d.ts.map +0 -1
  48. package/dist/lib/types.d.ts +0 -61
  49. package/dist/lib/types.d.ts.map +0 -1
  50. package/dist/lib/validator.d.ts +0 -3
  51. package/dist/lib/validator.d.ts.map +0 -1
package/dist/index.mjs ADDED
@@ -0,0 +1,345 @@
1
+ import { n as performChildCompilation, t as relativeToOutputPath } from "./chunks/relative-to-output-path-Gvhd54pA.js";
2
+ import path from "node:path";
3
+ import { escapeRegExp, getSourceMapURL, replaceAndUpdateSourceMap, transformManifest } from "@serwist/build";
4
+ import { toUnix } from "@serwist/utils";
5
+ import prettyBytes from "pretty-bytes";
6
+ import crypto from "node:crypto";
7
+ import { SerwistConfigError, validationErrorMap } from "@serwist/build/schema";
8
+ //#region src/lib/get-asset-hash.ts
9
+ /**
10
+ * @param asset
11
+ * @returns The MD5 hash of the asset's source.
12
+ *
13
+ * @private
14
+ */
15
+ const getAssetHash = (asset) => {
16
+ if (asset.info?.immutable) return null;
17
+ return crypto.createHash("md5").update(asset.source.source()).digest("hex");
18
+ };
19
+ //#endregion
20
+ //#region src/lib/resolve-webpack-url.ts
21
+ /**
22
+ * Resolves a url in the way that webpack would (with string concatenation)
23
+ *
24
+ * Use publicPath + filePath instead of url.resolve(publicPath, filePath) see:
25
+ * https://webpack.js.org/configuration/output/#output-publicpath
26
+ *
27
+ * @param publicPath The publicPath value from webpack's compilation.
28
+ * @param paths File paths to join
29
+ * @returns Joined file path
30
+ * @private
31
+ */
32
+ const resolveWebpackURL = (publicPath, ...paths) => {
33
+ if (publicPath === "auto") return paths.join("");
34
+ return [publicPath, ...paths].join("");
35
+ };
36
+ //#endregion
37
+ //#region src/lib/get-manifest-entries-from-compilation.ts
38
+ /**
39
+ * For a given asset, checks whether at least one of the conditions matches.
40
+ *
41
+ * @param asset The webpack asset in question. This will be passed
42
+ * to any functions that are listed as conditions.
43
+ * @param compilation The webpack compilation. This will be passed
44
+ * to any functions that are listed as conditions.
45
+ * @param conditions
46
+ * @returns Whether or not at least one condition matches.
47
+ * @private
48
+ */
49
+ const checkConditions = (asset, compilation, conditions = []) => {
50
+ const matchPart = compilation.compiler.webpack.ModuleFilenameHelpers.matchPart;
51
+ for (const condition of conditions) if (typeof condition === "function") {
52
+ if (condition({
53
+ asset,
54
+ compilation
55
+ })) return true;
56
+ } else if (matchPart(asset.name, condition)) return true;
57
+ return false;
58
+ };
59
+ /**
60
+ * Returns the names of all the assets in all the chunks in a chunk group,
61
+ * if provided a chunk group name.
62
+ * Otherwise, if provided a chunk name, return all the assets in that chunk.
63
+ * Otherwise, if there isn't a chunk group or chunk with that name, return null.
64
+ *
65
+ * @param compilation
66
+ * @param chunkOrGroup
67
+ * @returns
68
+ * @private
69
+ */
70
+ const getNamesOfAssetsInChunkOrGroup = (compilation, chunkOrGroup) => {
71
+ const chunkGroup = compilation.namedChunkGroups?.get(chunkOrGroup);
72
+ if (chunkGroup) {
73
+ const assetNames = [];
74
+ for (const chunk of chunkGroup.chunks) assetNames.push(...getNamesOfAssetsInChunk(chunk));
75
+ return assetNames;
76
+ }
77
+ const chunk = compilation.namedChunks?.get(chunkOrGroup);
78
+ if (chunk) return getNamesOfAssetsInChunk(chunk);
79
+ return null;
80
+ };
81
+ /**
82
+ * Returns the names of all the assets in a chunk.
83
+ *
84
+ * @param chunk
85
+ * @returns
86
+ * @private
87
+ */
88
+ const getNamesOfAssetsInChunk = (chunk) => {
89
+ const assetNames = [];
90
+ assetNames.push(...chunk.files);
91
+ if (chunk.auxiliaryFiles) assetNames.push(...chunk.auxiliaryFiles);
92
+ return assetNames;
93
+ };
94
+ /**
95
+ * Filters the set of assets out, based on the configuration options provided:
96
+ * - chunks and excludeChunks, for chunkName-based criteria.
97
+ * - include and exclude, for more general criteria.
98
+ *
99
+ * @param compilation The webpack compilation.
100
+ * @param config The validated configuration, obtained from the plugin.
101
+ * @returns The assets that should be included in the manifest,
102
+ * based on the criteria provided.
103
+ * @private
104
+ */
105
+ const filterAssets = (compilation, config) => {
106
+ const filteredAssets = /* @__PURE__ */ new Set();
107
+ const assets = compilation.getAssets();
108
+ const allowedAssetNames = /* @__PURE__ */ new Set();
109
+ if (Array.isArray(config.chunks)) for (const name of config.chunks) {
110
+ const assetsInChunkOrGroup = getNamesOfAssetsInChunkOrGroup(compilation, name);
111
+ if (assetsInChunkOrGroup) for (const assetName of assetsInChunkOrGroup) allowedAssetNames.add(assetName);
112
+ else compilation.warnings.push(/* @__PURE__ */ new Error(`The chunk '${name}' was provided in your Serwist chunks config, but was not found in the compilation.`));
113
+ }
114
+ const deniedAssetNames = /* @__PURE__ */ new Set();
115
+ if (Array.isArray(config.excludeChunks)) for (const name of config.excludeChunks) {
116
+ const assetsInChunkOrGroup = getNamesOfAssetsInChunkOrGroup(compilation, name);
117
+ if (assetsInChunkOrGroup) for (const assetName of assetsInChunkOrGroup) deniedAssetNames.add(assetName);
118
+ }
119
+ for (const asset of assets) {
120
+ if (deniedAssetNames.has(asset.name)) continue;
121
+ if (Array.isArray(config.chunks) && !allowedAssetNames.has(asset.name)) continue;
122
+ if (checkConditions(asset, compilation, config.exclude)) continue;
123
+ if (!(!Array.isArray(config.include) || checkConditions(asset, compilation, config.include))) continue;
124
+ filteredAssets.add(asset);
125
+ }
126
+ return filteredAssets;
127
+ };
128
+ const getManifestEntriesFromCompilation = async (compilation, config) => {
129
+ const filteredAssets = filterAssets(compilation, config);
130
+ const { publicPath } = compilation.options.output;
131
+ const { manifestEntries, size, warnings } = await transformManifest({
132
+ fileDetails: Array.from(filteredAssets).map((asset) => {
133
+ return {
134
+ file: resolveWebpackURL(publicPath, asset.name),
135
+ hash: getAssetHash(asset),
136
+ size: asset.source.size() || 0
137
+ };
138
+ }),
139
+ additionalPrecacheEntries: config.additionalPrecacheEntries,
140
+ dontCacheBustURLsMatching: config.dontCacheBustURLsMatching,
141
+ manifestTransforms: config.manifestTransforms,
142
+ maximumFileSizeToCacheInBytes: config.maximumFileSizeToCacheInBytes,
143
+ modifyURLPrefix: config.modifyURLPrefix,
144
+ transformParam: compilation,
145
+ disablePrecacheManifest: config.disablePrecacheManifest
146
+ });
147
+ for (const warning of warnings) compilation.warnings.push(new Error(warning));
148
+ return {
149
+ size,
150
+ sortedEntries: manifestEntries?.sort((a, b) => a.url === b.url ? 0 : a.url > b.url ? 1 : -1)
151
+ };
152
+ };
153
+ //#endregion
154
+ //#region src/lib/get-sourcemap-asset-name.ts
155
+ /**
156
+ * If our bundled swDest file contains a sourcemap, we would invalidate that
157
+ * mapping if we just replaced injectionPoint with the stringified manifest.
158
+ * Instead, we need to update the swDest contents as well as the sourcemap
159
+ * at the same time.
160
+ *
161
+ * See https://github.com/GoogleChrome/workbox/issues/2235
162
+ *
163
+ * @param compilation The current webpack compilation.
164
+ * @param swContents The contents of the swSrc file, which may or
165
+ * may not include a valid sourcemap comment.
166
+ * @param swDest The configured swDest value.
167
+ * @returns If the swContents contains a valid sourcemap
168
+ * comment pointing to an asset present in the compilation, this will return the
169
+ * name of that asset. Otherwise, it will return undefined.
170
+ * @private
171
+ */
172
+ const getSourcemapAssetName = (compilation, swContents, swDest) => {
173
+ const url = getSourceMapURL(swContents);
174
+ if (url) {
175
+ const swAssetDirname = path.dirname(swDest);
176
+ const sourcemapURLAssetName = path.normalize(path.join(swAssetDirname, url));
177
+ if (compilation.getAsset(sourcemapURLAssetName)) return sourcemapURLAssetName;
178
+ }
179
+ };
180
+ //#endregion
181
+ //#region src/lib/validator.ts
182
+ const validateInjectManifestOptions = async (input) => {
183
+ const result = await (await import("./chunks/schema-CpgCa1bB.js").then((n) => n.r)).injectManifestOptions.spa(input, { error: validationErrorMap });
184
+ if (!result.success) throw new SerwistConfigError({
185
+ moduleName: "@serwist/webpack-plugin",
186
+ message: JSON.stringify(result.error.format(), null, 2)
187
+ });
188
+ return result.data;
189
+ };
190
+ //#endregion
191
+ //#region src/inject-manifest.ts
192
+ const _generatedAssetNames = /* @__PURE__ */ new Set();
193
+ /**
194
+ * This class supports compiling a service worker file provided via `swSrc`,
195
+ * and injecting into that service worker a list of URLs and revision
196
+ * information for precaching based on the webpack asset pipeline.
197
+ *
198
+ * Use an instance of `InjectManifest` in the
199
+ * [`plugins` array](https://webpack.js.org/concepts/plugins/#usage) of a
200
+ * webpack config.
201
+ *
202
+ * In addition to injecting the manifest, this plugin will perform a compilation
203
+ * of the `swSrc` file, using the options from the main webpack configuration.
204
+ *
205
+ * ```
206
+ * // The following lists some common options; see the rest of the documentation
207
+ * // for the full set of options and defaults.
208
+ * new InjectManifest({
209
+ * exclude: [/.../, '...'],
210
+ * maximumFileSizeToCacheInBytes: ...,
211
+ * swSrc: '...',
212
+ * });
213
+ * ```
214
+ */
215
+ var InjectManifest = class {
216
+ config;
217
+ alreadyCalled;
218
+ webpack;
219
+ /**
220
+ * Creates an instance of InjectManifest.
221
+ */
222
+ constructor(config) {
223
+ this.config = config;
224
+ this.alreadyCalled = false;
225
+ this.webpack = null;
226
+ }
227
+ /**
228
+ * @param compiler default compiler object passed from webpack
229
+ *
230
+ * @private
231
+ */
232
+ propagateWebpackConfig(compiler) {
233
+ this.webpack = compiler.webpack;
234
+ const parsedSwSrc = path.parse(this.config.swSrc);
235
+ this.config = {
236
+ swDest: `${parsedSwSrc.name}.js`,
237
+ ...this.config
238
+ };
239
+ }
240
+ /**
241
+ * `getManifestEntriesFromCompilation` with a few additional checks.
242
+ *
243
+ * @private
244
+ */
245
+ async getManifestEntries(compilation, config) {
246
+ if (config.disablePrecacheManifest) return {
247
+ size: 0,
248
+ sortedEntries: void 0,
249
+ manifestString: "undefined"
250
+ };
251
+ if (this.alreadyCalled) {
252
+ const warningMessage = `${this.constructor.name} has been called multiple times, perhaps due to running webpack in --watch mode. The precache manifest generated after the first call may be inaccurate! Please see https://github.com/GoogleChrome/workbox/issues/1790 for more information.`;
253
+ if (!compilation.warnings.some((warning) => warning instanceof Error && warning.message === warningMessage)) compilation.warnings.push(new Error(warningMessage));
254
+ } else this.alreadyCalled = true;
255
+ config.exclude.push(({ asset }) => _generatedAssetNames.has(asset.name));
256
+ const { size, sortedEntries } = await getManifestEntriesFromCompilation(compilation, config);
257
+ let manifestString = JSON.stringify(sortedEntries);
258
+ if (this.config.compileSrc && !(compilation.options?.devtool === "eval-cheap-source-map" && compilation.options.optimization?.minimize)) manifestString = manifestString.replace(/"/g, `'`);
259
+ return {
260
+ size,
261
+ sortedEntries,
262
+ manifestString
263
+ };
264
+ }
265
+ /**
266
+ * @param compiler default compiler object passed from webpack
267
+ *
268
+ * @private
269
+ */
270
+ apply(compiler) {
271
+ this.propagateWebpackConfig(compiler);
272
+ compiler.hooks.make.tapPromise(this.constructor.name, (compilation) => this.handleMake(compiler, compilation).catch((error) => {
273
+ compilation.errors.push(error);
274
+ }));
275
+ const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation;
276
+ compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
277
+ compilation.hooks.processAssets.tapPromise({
278
+ name: this.constructor.name,
279
+ stage: PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 10
280
+ }, () => this.addAssets(compilation).catch((error) => {
281
+ compilation.errors.push(error);
282
+ }));
283
+ });
284
+ }
285
+ /**
286
+ * @param compiler The webpack parent compiler.
287
+ * @param compilation The webpack compilation.
288
+ *
289
+ * @private
290
+ */
291
+ addSrcToAssets(compiler, compilation) {
292
+ const source = compiler.inputFileSystem.readFileSync(this.config.swSrc);
293
+ compilation.emitAsset(this.config.swDest, new this.webpack.sources.RawSource(source));
294
+ }
295
+ /**
296
+ * @param compiler The webpack parent compiler.
297
+ * @param compilation The webpack compilation.
298
+ *
299
+ * @private
300
+ */
301
+ async handleMake(compiler, compilation) {
302
+ this.config = await validateInjectManifestOptions(this.config);
303
+ this.config.swDest = relativeToOutputPath(compilation, this.config.swDest);
304
+ _generatedAssetNames.add(this.config.swDest);
305
+ if (this.config.compileSrc) await performChildCompilation(compiler, compilation, this.constructor.name, this.config.swSrc, this.config.swDest, this.config.webpackCompilationPlugins);
306
+ else {
307
+ this.addSrcToAssets(compiler, compilation);
308
+ if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) compilation.warnings.push(/* @__PURE__ */ new Error("'compileSrc' is 'false', so the 'webpackCompilationPlugins' option will be ignored."));
309
+ }
310
+ }
311
+ /**
312
+ * @param compilation The webpack compilation.
313
+ *
314
+ * @private
315
+ */
316
+ async addAssets(compilation) {
317
+ const config = Object.assign({}, this.config);
318
+ const { size, sortedEntries, manifestString } = await this.getManifestEntries(compilation, config);
319
+ compilation.fileDependencies.add(path.resolve(config.swSrc));
320
+ const swAssetString = compilation.getAsset(config.swDest).source.source().toString();
321
+ const globalRegexp = new RegExp(escapeRegExp(config.injectionPoint), "g");
322
+ const injectionResults = swAssetString.match(globalRegexp);
323
+ if (!injectionResults) throw new Error(`Can't find ${config.injectionPoint} in your SW source.`);
324
+ if (injectionResults.length !== 1) throw new Error(`Multiple instances of ${config.injectionPoint} were found in your SW source. Include it only once. For more info, see https://github.com/GoogleChrome/workbox/issues/2681`);
325
+ const sourcemapAssetName = getSourcemapAssetName(compilation, swAssetString, config.swDest);
326
+ if (sourcemapAssetName) {
327
+ _generatedAssetNames.add(sourcemapAssetName);
328
+ const sourcemapAsset = compilation.getAsset(sourcemapAssetName);
329
+ const { source, map } = await replaceAndUpdateSourceMap({
330
+ jsFilename: toUnix(config.swDest),
331
+ originalMap: JSON.parse(sourcemapAsset.source.source().toString()),
332
+ originalSource: swAssetString,
333
+ replaceString: manifestString,
334
+ searchString: config.injectionPoint
335
+ });
336
+ compilation.updateAsset(sourcemapAssetName, new this.webpack.sources.RawSource(map));
337
+ compilation.updateAsset(config.swDest, new this.webpack.sources.RawSource(source));
338
+ } else compilation.updateAsset(config.swDest, new this.webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString)));
339
+ if (compilation.getLogger) compilation.getLogger(this.constructor.name).info(`The service worker at ${config.swDest ?? ""} will precache ${sortedEntries?.length ?? 0} URLs, totaling ${prettyBytes(size)}.`);
340
+ }
341
+ };
342
+ //#endregion
343
+ export { InjectManifest, validateInjectManifestOptions };
344
+
345
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/lib/get-asset-hash.ts","../src/lib/resolve-webpack-url.ts","../src/lib/get-manifest-entries-from-compilation.ts","../src/lib/get-sourcemap-asset-name.ts","../src/lib/validator.ts","../src/inject-manifest.ts"],"sourcesContent":["/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport crypto from \"node:crypto\";\nimport type { Asset } from \"webpack\";\n\n/**\n * @param asset\n * @returns The MD5 hash of the asset's source.\n *\n * @private\n */\nexport const getAssetHash = (asset: Asset): string | null => {\n // If webpack has the asset marked as immutable, then we don't need to\n // use an out-of-band revision for it.\n // See https://github.com/webpack/webpack/issues/9038\n if (asset.info?.immutable) {\n return null;\n }\n\n return crypto.createHash(\"md5\").update(asset.source.source()).digest(\"hex\");\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\n/**\n * Resolves a url in the way that webpack would (with string concatenation)\n *\n * Use publicPath + filePath instead of url.resolve(publicPath, filePath) see:\n * https://webpack.js.org/configuration/output/#output-publicpath\n *\n * @param publicPath The publicPath value from webpack's compilation.\n * @param paths File paths to join\n * @returns Joined file path\n * @private\n */\nexport const resolveWebpackURL = (publicPath: string, ...paths: string[]): string => {\n // This is a change in webpack v5.\n // See https://github.com/jantimon/html-webpack-plugin/pull/1516\n if (publicPath === \"auto\") {\n return paths.join(\"\");\n }\n return [publicPath, ...paths].join(\"\");\n};\n","/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nimport type { FileDetails, ManifestEntry } from \"@serwist/build\";\nimport { transformManifest } from \"@serwist/build\";\nimport type { Asset, Chunk, Compilation, WebpackError } from \"webpack\";\n\nimport { getAssetHash } from \"./get-asset-hash.js\";\nimport { resolveWebpackURL } from \"./resolve-webpack-url.js\";\nimport type { InjectManifestOptions, InjectManifestOptionsComplete } from \"./types.js\";\n\n/**\n * For a given asset, checks whether at least one of the conditions matches.\n *\n * @param asset The webpack asset in question. This will be passed\n * to any functions that are listed as conditions.\n * @param compilation The webpack compilation. This will be passed\n * to any functions that are listed as conditions.\n * @param conditions\n * @returns Whether or not at least one condition matches.\n * @private\n */\nconst checkConditions = (asset: Asset, compilation: Compilation, conditions: Array<string | RegExp | ((arg0: any) => boolean)> = []): boolean => {\n const matchPart = compilation.compiler.webpack.ModuleFilenameHelpers.matchPart;\n\n for (const condition of conditions) {\n if (typeof condition === \"function\") {\n if (condition({ asset, compilation })) {\n return true;\n }\n } else if (matchPart(asset.name, condition)) {\n return true;\n }\n }\n\n // We'll only get here if none of the conditions applied.\n return false;\n};\n\n/**\n * Returns the names of all the assets in all the chunks in a chunk group,\n * if provided a chunk group name.\n * Otherwise, if provided a chunk name, return all the assets in that chunk.\n * Otherwise, if there isn't a chunk group or chunk with that name, return null.\n *\n * @param compilation\n * @param chunkOrGroup\n * @returns\n * @private\n */\nconst getNamesOfAssetsInChunkOrGroup = (compilation: Compilation, chunkOrGroup: string): string[] | null => {\n const chunkGroup = compilation.namedChunkGroups?.get(chunkOrGroup);\n if (chunkGroup) {\n const assetNames = [];\n for (const chunk of chunkGroup.chunks) {\n assetNames.push(...getNamesOfAssetsInChunk(chunk));\n }\n return assetNames;\n }\n const chunk = compilation.namedChunks?.get(chunkOrGroup);\n if (chunk) {\n return getNamesOfAssetsInChunk(chunk);\n }\n\n // If we get here, there's no chunkGroup or chunk with that name.\n return null;\n};\n\n/**\n * Returns the names of all the assets in a chunk.\n *\n * @param chunk\n * @returns\n * @private\n */\nconst getNamesOfAssetsInChunk = (chunk: Chunk): string[] => {\n const assetNames: string[] = [];\n\n assetNames.push(...chunk.files);\n\n // This only appears to be set in webpack v5.\n if (chunk.auxiliaryFiles) {\n assetNames.push(...chunk.auxiliaryFiles);\n }\n\n return assetNames;\n};\n\n/**\n * Filters the set of assets out, based on the configuration options provided:\n * - chunks and excludeChunks, for chunkName-based criteria.\n * - include and exclude, for more general criteria.\n *\n * @param compilation The webpack compilation.\n * @param config The validated configuration, obtained from the plugin.\n * @returns The assets that should be included in the manifest,\n * based on the criteria provided.\n * @private\n */\nconst filterAssets = (compilation: Compilation, config: InjectManifestOptions): Set<Asset> => {\n const filteredAssets = new Set<Asset>();\n const assets = compilation.getAssets();\n\n const allowedAssetNames = new Set<string>();\n // See https://github.com/GoogleChrome/workbox/issues/1287\n if (Array.isArray(config.chunks)) {\n for (const name of config.chunks) {\n // See https://github.com/GoogleChrome/workbox/issues/2717\n const assetsInChunkOrGroup = getNamesOfAssetsInChunkOrGroup(compilation, name);\n if (assetsInChunkOrGroup) {\n for (const assetName of assetsInChunkOrGroup) {\n allowedAssetNames.add(assetName);\n }\n } else {\n compilation.warnings.push(\n new Error(`The chunk '${name}' was provided in your Serwist chunks config, but was not found in the compilation.`) as WebpackError,\n );\n }\n }\n }\n\n const deniedAssetNames = new Set();\n if (Array.isArray(config.excludeChunks)) {\n for (const name of config.excludeChunks) {\n // See https://github.com/GoogleChrome/workbox/issues/2717\n const assetsInChunkOrGroup = getNamesOfAssetsInChunkOrGroup(compilation, name);\n if (assetsInChunkOrGroup) {\n for (const assetName of assetsInChunkOrGroup) {\n deniedAssetNames.add(assetName);\n }\n } // Don't warn if the chunk group isn't found.\n }\n }\n\n for (const asset of assets) {\n // chunk based filtering is funky because:\n // - Each asset might belong to one or more chunks.\n // - If *any* of those chunk names match our config.excludeChunks,\n // then we skip that asset.\n // - If the config.chunks is defined *and* there's no match\n // between at least one of the chunkNames and one entry, then\n // we skip that assets as well.\n\n if (deniedAssetNames.has(asset.name)) {\n continue;\n }\n\n if (Array.isArray(config.chunks) && !allowedAssetNames.has(asset.name)) {\n continue;\n }\n\n // Next, check asset-level checks via includes/excludes:\n const isExcluded = checkConditions(asset, compilation, config.exclude);\n if (isExcluded) {\n continue;\n }\n\n // Treat an empty config.includes as an implicit inclusion.\n const isIncluded = !Array.isArray(config.include) || checkConditions(asset, compilation, config.include);\n if (!isIncluded) {\n continue;\n }\n\n // If we've gotten this far, then add the asset.\n filteredAssets.add(asset);\n }\n\n return filteredAssets;\n};\n\nexport const getManifestEntriesFromCompilation = async (\n compilation: Compilation,\n config: InjectManifestOptionsComplete,\n): Promise<{ size: number; sortedEntries: ManifestEntry[] | undefined }> => {\n const filteredAssets = filterAssets(compilation, config);\n\n const { publicPath } = compilation.options.output;\n\n const fileDetails = Array.from(filteredAssets).map((asset) => {\n return {\n file: resolveWebpackURL(publicPath as string, asset.name),\n hash: getAssetHash(asset),\n size: asset.source.size() || 0,\n } satisfies FileDetails;\n });\n\n const { manifestEntries, size, warnings } = await transformManifest({\n fileDetails,\n additionalPrecacheEntries: config.additionalPrecacheEntries,\n dontCacheBustURLsMatching: config.dontCacheBustURLsMatching,\n manifestTransforms: config.manifestTransforms,\n maximumFileSizeToCacheInBytes: config.maximumFileSizeToCacheInBytes,\n modifyURLPrefix: config.modifyURLPrefix,\n transformParam: compilation,\n disablePrecacheManifest: config.disablePrecacheManifest,\n });\n\n // See https://github.com/GoogleChrome/workbox/issues/2790\n for (const warning of warnings) {\n compilation.warnings.push(new Error(warning) as WebpackError);\n }\n\n // Ensure that the entries are properly sorted by URL.\n const sortedEntries = manifestEntries?.sort((a, b) => (a.url === b.url ? 0 : a.url > b.url ? 1 : -1));\n\n return { size, sortedEntries };\n};\n","/*\n Copyright 2019 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\nimport path from \"node:path\";\nimport { getSourceMapURL } from \"@serwist/build\";\nimport type { Compilation } from \"webpack\";\n\n/**\n * If our bundled swDest file contains a sourcemap, we would invalidate that\n * mapping if we just replaced injectionPoint with the stringified manifest.\n * Instead, we need to update the swDest contents as well as the sourcemap\n * at the same time.\n *\n * See https://github.com/GoogleChrome/workbox/issues/2235\n *\n * @param compilation The current webpack compilation.\n * @param swContents The contents of the swSrc file, which may or\n * may not include a valid sourcemap comment.\n * @param swDest The configured swDest value.\n * @returns If the swContents contains a valid sourcemap\n * comment pointing to an asset present in the compilation, this will return the\n * name of that asset. Otherwise, it will return undefined.\n * @private\n */\nexport const getSourcemapAssetName = (compilation: Compilation, swContents: string, swDest: string): string | undefined => {\n const url = getSourceMapURL(swContents);\n if (url) {\n // Translate the relative URL to what the presumed name for the webpack\n // asset should be.\n // This *might* not be a valid asset if the sourcemap URL that was found\n // was added by another module incidentally.\n // See https://github.com/GoogleChrome/workbox/issues/2250\n const swAssetDirname = path.dirname(swDest);\n const sourcemapURLAssetName = path.normalize(path.join(swAssetDirname, url));\n // Not sure if there's a better way to check for asset existence?\n if (compilation.getAsset(sourcemapURLAssetName)) {\n return sourcemapURLAssetName;\n }\n }\n return undefined;\n};\n","import { SerwistConfigError, validationErrorMap } from \"@serwist/build/schema\";\nimport type { InjectManifestOptionsComplete } from \"./types.js\";\n\nexport const validateInjectManifestOptions = async (input: unknown): Promise<InjectManifestOptionsComplete> => {\n const result = await (await import(\"./schema.js\")).injectManifestOptions.spa(input, { error: validationErrorMap });\n if (!result.success) {\n throw new SerwistConfigError({ moduleName: \"@serwist/webpack-plugin\", message: JSON.stringify(result.error.format(), null, 2) });\n }\n return result.data;\n};\n","import path from \"node:path\";\nimport { escapeRegExp, replaceAndUpdateSourceMap } from \"@serwist/build\";\nimport { toUnix } from \"@serwist/utils\";\nimport prettyBytes from \"pretty-bytes\";\nimport type { Compilation, Compiler, default as Webpack, WebpackError } from \"webpack\";\nimport { getManifestEntriesFromCompilation } from \"./lib/get-manifest-entries-from-compilation.js\";\nimport { getSourcemapAssetName } from \"./lib/get-sourcemap-asset-name.js\";\nimport { performChildCompilation } from \"./lib/perform-child-compilation.js\";\nimport { relativeToOutputPath } from \"./lib/relative-to-output-path.js\";\nimport type { InjectManifestOptions, InjectManifestOptionsComplete } from \"./lib/types.js\";\nimport { validateInjectManifestOptions } from \"./lib/validator.js\";\n\n// Used to keep track of swDest files written by *any* instance of this plugin.\n// See https://github.com/GoogleChrome/workbox/issues/2181\nconst _generatedAssetNames = new Set<string>();\n\n/**\n * This class supports compiling a service worker file provided via `swSrc`,\n * and injecting into that service worker a list of URLs and revision\n * information for precaching based on the webpack asset pipeline.\n *\n * Use an instance of `InjectManifest` in the\n * [`plugins` array](https://webpack.js.org/concepts/plugins/#usage) of a\n * webpack config.\n *\n * In addition to injecting the manifest, this plugin will perform a compilation\n * of the `swSrc` file, using the options from the main webpack configuration.\n *\n * ```\n * // The following lists some common options; see the rest of the documentation\n * // for the full set of options and defaults.\n * new InjectManifest({\n * exclude: [/.../, '...'],\n * maximumFileSizeToCacheInBytes: ...,\n * swSrc: '...',\n * });\n * ```\n */\nexport class InjectManifest {\n protected config: InjectManifestOptionsComplete;\n private alreadyCalled: boolean;\n private webpack: typeof Webpack;\n\n /**\n * Creates an instance of InjectManifest.\n */\n constructor(config: InjectManifestOptions) {\n // We are essentially lying to TypeScript. When `handleMake`\n // is called, `this.config` will be replaced by a validated config.\n this.config = config as InjectManifestOptionsComplete;\n this.alreadyCalled = false;\n this.webpack = null!;\n }\n\n /**\n * @param compiler default compiler object passed from webpack\n *\n * @private\n */\n private propagateWebpackConfig(compiler: Compiler): void {\n this.webpack = compiler.webpack;\n\n const parsedSwSrc = path.parse(this.config.swSrc);\n // Because this.config is listed last, properties that are already set\n // there take precedence over derived properties from the compiler.\n this.config = {\n // Use swSrc with a hardcoded .js extension, in case swSrc is a .ts file.\n swDest: `${parsedSwSrc.name}.js`,\n ...this.config,\n };\n }\n\n /**\n * `getManifestEntriesFromCompilation` with a few additional checks.\n *\n * @private\n */\n private async getManifestEntries(compilation: Compilation, config: InjectManifestOptionsComplete) {\n if (config.disablePrecacheManifest) {\n return {\n size: 0,\n sortedEntries: undefined,\n manifestString: \"undefined\",\n };\n }\n\n // See https://github.com/GoogleChrome/workbox/issues/1790\n if (this.alreadyCalled) {\n const warningMessage = `${this.constructor.name} has been called multiple times, perhaps due to running webpack in --watch mode. The precache manifest generated after the first call may be inaccurate! Please see https://github.com/GoogleChrome/workbox/issues/1790 for more information.`;\n\n if (!compilation.warnings.some((warning) => warning instanceof Error && warning.message === warningMessage)) {\n compilation.warnings.push(new Error(warningMessage) as WebpackError);\n }\n } else {\n this.alreadyCalled = true;\n }\n\n // Ensure that we don't precache any of the assets generated by *any*\n // instance of this plugin.\n config.exclude.push(({ asset }) => _generatedAssetNames.has(asset.name));\n\n const { size, sortedEntries } = await getManifestEntriesFromCompilation(compilation, config);\n\n let manifestString = JSON.stringify(sortedEntries);\n if (\n this.config.compileSrc &&\n // See https://github.com/GoogleChrome/workbox/issues/2729\n !(compilation.options?.devtool === \"eval-cheap-source-map\" && compilation.options.optimization?.minimize)\n ) {\n // See https://github.com/GoogleChrome/workbox/issues/2263\n manifestString = manifestString.replace(/\"/g, `'`);\n }\n\n return { size, sortedEntries, manifestString };\n }\n\n /**\n * @param compiler default compiler object passed from webpack\n *\n * @private\n */\n apply(compiler: Compiler): void {\n this.propagateWebpackConfig(compiler);\n\n compiler.hooks.make.tapPromise(this.constructor.name, (compilation) =>\n this.handleMake(compiler, compilation).catch((error: WebpackError) => {\n compilation.errors.push(error);\n }),\n );\n\n // webpack should not be null at this point.\n const { PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER } = this.webpack.Compilation;\n // Specifically hook into thisCompilation, as per\n // https://github.com/webpack/webpack/issues/11425#issuecomment-690547848\n compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {\n compilation.hooks.processAssets.tapPromise(\n {\n name: this.constructor.name,\n // TODO(jeffposnick): This may need to change eventually.\n // See https://github.com/webpack/webpack/issues/11822#issuecomment-726184972\n stage: PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER - 10,\n },\n () =>\n this.addAssets(compilation).catch((error: WebpackError) => {\n compilation.errors.push(error);\n }),\n );\n });\n }\n\n /**\n * @param compiler The webpack parent compiler.\n * @param compilation The webpack compilation.\n *\n * @private\n */\n private addSrcToAssets(compiler: Compiler, compilation: Compilation): void {\n const source = compiler.inputFileSystem!.readFileSync!(this.config.swSrc);\n compilation.emitAsset(this.config.swDest!, new this.webpack.sources.RawSource(source));\n }\n\n /**\n * @param compiler The webpack parent compiler.\n * @param compilation The webpack compilation.\n *\n * @private\n */\n private async handleMake(compiler: Compiler, compilation: Compilation): Promise<void> {\n this.config = await validateInjectManifestOptions(this.config);\n this.config.swDest = relativeToOutputPath(compilation, this.config.swDest!);\n _generatedAssetNames.add(this.config.swDest);\n\n if (this.config.compileSrc) {\n await performChildCompilation(\n compiler,\n compilation,\n this.constructor.name,\n this.config.swSrc,\n this.config.swDest,\n this.config.webpackCompilationPlugins,\n );\n } else {\n this.addSrcToAssets(compiler, compilation);\n // This used to be a fatal error, but just warn at runtime because we\n // can't validate it easily.\n if (Array.isArray(this.config.webpackCompilationPlugins) && this.config.webpackCompilationPlugins.length > 0) {\n compilation.warnings.push(new Error(\"'compileSrc' is 'false', so the 'webpackCompilationPlugins' option will be ignored.\") as WebpackError);\n }\n }\n }\n\n /**\n * @param compilation The webpack compilation.\n *\n * @private\n */\n private async addAssets(compilation: Compilation): Promise<void> {\n const config = Object.assign({}, this.config);\n\n const { size, sortedEntries, manifestString } = await this.getManifestEntries(compilation, config);\n\n // See https://webpack.js.org/contribute/plugin-patterns/#monitoring-the-watch-graph\n compilation.fileDependencies.add(path.resolve(config.swSrc));\n\n const swAsset = compilation.getAsset(config.swDest!);\n\n const swAssetString = swAsset!.source.source().toString();\n\n const globalRegexp = new RegExp(escapeRegExp(config.injectionPoint), \"g\");\n const injectionResults = swAssetString.match(globalRegexp);\n\n if (!injectionResults) {\n throw new Error(`Can't find ${config.injectionPoint} in your SW source.`);\n }\n if (injectionResults.length !== 1) {\n throw new Error(\n `Multiple instances of ${config.injectionPoint} were found in your SW source. Include it only once. For more info, see https://github.com/GoogleChrome/workbox/issues/2681`,\n );\n }\n\n const sourcemapAssetName = getSourcemapAssetName(compilation, swAssetString, config.swDest!);\n\n if (sourcemapAssetName) {\n _generatedAssetNames.add(sourcemapAssetName);\n const sourcemapAsset = compilation.getAsset(sourcemapAssetName);\n const { source, map } = await replaceAndUpdateSourceMap({\n jsFilename: toUnix(config.swDest!),\n originalMap: JSON.parse(sourcemapAsset!.source.source().toString()),\n originalSource: swAssetString,\n replaceString: manifestString,\n searchString: config.injectionPoint,\n });\n compilation.updateAsset(sourcemapAssetName, new this.webpack.sources.RawSource(map));\n compilation.updateAsset(config.swDest!, new this.webpack.sources.RawSource(source));\n } else {\n // If there's no sourcemap associated with swDest, a simple string\n // replacement will suffice.\n compilation.updateAsset(config.swDest!, new this.webpack.sources.RawSource(swAssetString.replace(config.injectionPoint, manifestString)));\n }\n\n if (compilation.getLogger) {\n const logger = compilation.getLogger(this.constructor.name);\n logger.info(`The service worker at ${config.swDest ?? \"\"} will precache ${sortedEntries?.length ?? 0} URLs, totaling ${prettyBytes(size)}.`);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAa,gBAAgB,UAAgC;AAI3D,KAAI,MAAM,MAAM,UACd,QAAO;AAGT,QAAO,OAAO,WAAW,MAAM,CAAC,OAAO,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,eAAgB,OAAO,QAAQ,CAAC,UAAU,CAAC;IACnE,gBAAgB;IAChB,eAAe;IACf,cAAc,OAAO;IACtB,CAAC;AACF,eAAY,YAAY,oBAAoB,IAAI,KAAK,QAAQ,QAAQ,UAAU,IAAI,CAAC;AACpF,eAAY,YAAY,OAAO,QAAS,IAAI,KAAK,QAAQ,QAAQ,UAAU,OAAO,CAAC;QAInF,aAAY,YAAY,OAAO,QAAS,IAAI,KAAK,QAAQ,QAAQ,UAAU,cAAc,QAAQ,OAAO,gBAAgB,eAAe,CAAC,CAAC;AAG3I,MAAI,YAAY,UACC,aAAY,UAAU,KAAK,YAAY,KAChD,CAAC,KAAK,yBAAyB,OAAO,UAAU,GAAG,iBAAiB,eAAe,UAAU,EAAE,kBAAkB,YAAY,KAAK,CAAC,GAAG"}
@@ -0,0 +1,90 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/lib/schema.d.ts
4
+ declare const webpackPartial: z.ZodObject<{
5
+ chunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
6
+ exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
7
+ excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
+ include: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
9
+ }, z.core.$strict>;
10
+ declare const injectPartial: z.ZodObject<{
11
+ compileSrc: z.ZodDefault<z.ZodBoolean>;
12
+ swDest: z.ZodOptional<z.ZodString>;
13
+ webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny>>;
14
+ }, z.core.$strict>;
15
+ declare const injectManifestOptions: z.ZodObject<{
16
+ compileSrc: z.ZodDefault<z.ZodBoolean>;
17
+ swDest: z.ZodOptional<z.ZodString>;
18
+ webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny>>;
19
+ injectionPoint: z.ZodDefault<z.ZodString>;
20
+ swSrc: z.ZodString;
21
+ chunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
23
+ excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
+ include: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
25
+ additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
26
+ integrity: z.ZodOptional<z.ZodString>;
27
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
+ url: z.ZodString;
29
+ }, z.core.$strict>]>>>;
30
+ disablePrecacheManifest: z.ZodDefault<z.ZodBoolean>;
31
+ dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
32
+ manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
33
+ size: z.ZodNumber;
34
+ integrity: z.ZodOptional<z.ZodString>;
35
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
36
+ url: z.ZodString;
37
+ }, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
38
+ manifest: z.ZodArray<z.ZodObject<{
39
+ size: z.ZodNumber;
40
+ integrity: z.ZodOptional<z.ZodString>;
41
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
42
+ url: z.ZodString;
43
+ }, z.core.$strip>>;
44
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
45
+ }, z.core.$strict>>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
46
+ size: z.ZodNumber;
47
+ integrity: z.ZodOptional<z.ZodString>;
48
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
49
+ url: z.ZodString;
50
+ }, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
51
+ manifest: z.ZodArray<z.ZodObject<{
52
+ size: z.ZodNumber;
53
+ integrity: z.ZodOptional<z.ZodString>;
54
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
55
+ url: z.ZodString;
56
+ }, z.core.$strip>>;
57
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
58
+ }, z.core.$strict>>>, z.ZodTransform<z.core.$InferOuterFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
59
+ size: z.ZodNumber;
60
+ integrity: z.ZodOptional<z.ZodString>;
61
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
+ url: z.ZodString;
63
+ }, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
64
+ manifest: z.ZodArray<z.ZodObject<{
65
+ size: z.ZodNumber;
66
+ integrity: z.ZodOptional<z.ZodString>;
67
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
68
+ url: z.ZodString;
69
+ }, z.core.$strip>>;
70
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
71
+ }, z.core.$strict>>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
72
+ size: z.ZodNumber;
73
+ integrity: z.ZodOptional<z.ZodString>;
74
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
75
+ url: z.ZodString;
76
+ }, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
77
+ manifest: z.ZodArray<z.ZodObject<{
78
+ size: z.ZodNumber;
79
+ integrity: z.ZodOptional<z.ZodString>;
80
+ revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
81
+ url: z.ZodString;
82
+ }, z.core.$strip>>;
83
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
84
+ }, z.core.$strict>>>>>>;
85
+ maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
86
+ modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
87
+ }, z.core.$strict>;
88
+ //#endregion
89
+ export { injectManifestOptions, injectPartial as injectManifestPartial, webpackPartial };
90
+ //# sourceMappingURL=index.schema.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.schema.d.mts","names":[],"sources":["../src/lib/schema.ts"],"mappings":";;;cAUa,cAAA,EAAc,CAAA,CAAA,SAAA;;;;;;cAOd,aAAA,EAAa,CAAA,CAAA,SAAA;;;;;cAMb,qBAAA,EAAqB,CAAA,CAAA,SAAA"}
@@ -0,0 +1,2 @@
1
+ import { i as webpackPartial, n as injectPartial, t as injectManifestOptions } from "./chunks/schema-CpgCa1bB.js";
2
+ export { injectManifestOptions, injectPartial as injectManifestPartial, webpackPartial };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/webpack-plugin",
3
- "version": "9.5.7",
3
+ "version": "9.5.8",
4
4
  "type": "module",
5
5
  "description": "A plugin for your webpack build process, helping you generate a manifest of local files that should be precached.",
6
6
  "files": [
@@ -30,46 +30,45 @@
30
30
  "repository": "https://github.com/serwist/serwist",
31
31
  "bugs": "https://github.com/serwist/serwist/issues",
32
32
  "homepage": "https://serwist.pages.dev",
33
- "main": "./dist/index.js",
34
- "types": "./dist/index.d.ts",
33
+ "main": "./dist/index.mjs",
34
+ "types": "./dist/index.d.mts",
35
35
  "typesVersions": {
36
36
  "*": {
37
37
  "internal": [
38
- "./dist/index.internal.d.ts"
38
+ "./dist/index.internal.d.mts"
39
39
  ],
40
40
  "schema": [
41
- "./dist/index.schema.d.ts"
41
+ "./dist/index.schema.d.mts"
42
42
  ]
43
43
  }
44
44
  },
45
45
  "exports": {
46
46
  ".": {
47
- "types": "./dist/index.d.ts",
48
- "default": "./dist/index.js"
47
+ "types": "./dist/index.d.mts",
48
+ "default": "./dist/index.mjs"
49
49
  },
50
50
  "./internal": {
51
- "types": "./dist/index.internal.d.ts",
52
- "default": "./dist/index.internal.js"
51
+ "types": "./dist/index.internal.d.mts",
52
+ "default": "./dist/index.internal.mjs"
53
53
  },
54
54
  "./schema": {
55
- "types": "./dist/index.schema.d.ts",
56
- "default": "./dist/index.schema.js"
55
+ "types": "./dist/index.schema.d.mts",
56
+ "default": "./dist/index.schema.mjs"
57
57
  },
58
58
  "./package.json": "./package.json"
59
59
  },
60
60
  "dependencies": {
61
61
  "pretty-bytes": "6.1.1",
62
62
  "zod": "4.3.6",
63
- "@serwist/build": "9.5.7",
64
- "@serwist/utils": "9.5.7"
63
+ "@serwist/build": "9.5.8",
64
+ "@serwist/utils": "9.5.8"
65
65
  },
66
66
  "devDependencies": {
67
- "@types/node": "25.5.0",
67
+ "@types/node": "25.6.0",
68
68
  "@types/webpack": "5.28.5",
69
- "rollup": "4.59.0",
70
- "typescript": "5.9.3",
71
- "webpack": "5.105.4",
72
- "@serwist/configs": "9.5.7"
69
+ "tsdown": "0.21.10",
70
+ "typescript": "6.0.3",
71
+ "webpack": "5.106.2"
73
72
  },
74
73
  "peerDependencies": {
75
74
  "typescript": ">=5.0.0",
@@ -84,8 +83,8 @@
84
83
  }
85
84
  },
86
85
  "scripts": {
87
- "build": "rimraf dist && NODE_ENV=production rollup --config rollup.config.js",
88
- "dev": "rollup --config rollup.config.js --watch",
86
+ "build": "rimraf dist && NODE_ENV=production tsdown",
87
+ "dev": "tsdown --watch",
89
88
  "lint": "biome lint ./src",
90
89
  "typecheck": "tsc"
91
90
  }
@@ -1,34 +0,0 @@
1
- import path from 'node:path';
2
- import { toUnix } from '@serwist/utils';
3
-
4
- const performChildCompilation = async (compiler, compilation, name, src, dest, plugins)=>{
5
- const childCompiler = compilation.createChildCompiler(name, {
6
- filename: dest
7
- }, plugins);
8
- new compiler.webpack.webworker.WebWorkerTemplatePlugin().apply(childCompiler);
9
- new compiler.webpack.EntryPlugin(compiler.context, src, name).apply(childCompiler);
10
- await new Promise((resolve, reject)=>{
11
- childCompiler.runAsChild((error, _entries, childCompilation)=>{
12
- if (error) {
13
- reject(error);
14
- } else {
15
- if (childCompilation?.warnings) {
16
- compilation.warnings.push(...childCompilation.warnings);
17
- }
18
- if (childCompilation?.errors) {
19
- compilation.errors.push(...childCompilation.errors);
20
- }
21
- resolve();
22
- }
23
- });
24
- });
25
- };
26
-
27
- const relativeToOutputPath = (compilation, originalPath)=>{
28
- if (path.resolve(originalPath) === path.normalize(originalPath)) {
29
- return toUnix(path.relative(compilation.options.output.path, originalPath));
30
- }
31
- return originalPath;
32
- };
33
-
34
- export { performChildCompilation as p, relativeToOutputPath as r };
@@ -1,37 +0,0 @@
1
- import { fn, optionalSwDestPartial, injectPartial as injectPartial$1, basePartial } from '@serwist/build/schema';
2
- import { z } from 'zod';
3
-
4
- const webpackConditionCallback = fn({
5
- input: [
6
- z.any()
7
- ],
8
- output: z.boolean()
9
- });
10
- const webpackCondition = z.union([
11
- z.string(),
12
- z.instanceof(RegExp),
13
- webpackConditionCallback
14
- ]);
15
- const webpackPartial = z.strictObject({
16
- chunks: z.array(z.string()).optional(),
17
- exclude: z.array(webpackCondition).default([
18
- /\.map$/,
19
- /^manifest.*\.js$/
20
- ]),
21
- excludeChunks: z.array(z.string()).optional(),
22
- include: z.array(webpackCondition).optional()
23
- });
24
- const injectPartial = z.strictObject({
25
- compileSrc: z.boolean().default(true),
26
- swDest: z.string().optional(),
27
- webpackCompilationPlugins: z.array(z.any()).optional()
28
- });
29
- const injectManifestOptions = z.strictObject({
30
- ...basePartial.shape,
31
- ...webpackPartial.shape,
32
- ...injectPartial$1.shape,
33
- ...optionalSwDestPartial.shape,
34
- ...injectPartial.shape
35
- });
36
-
37
- export { injectManifestOptions, injectPartial, webpackPartial };