@serwist/webpack-plugin 8.1.1 → 8.3.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.
@@ -5,6 +5,7 @@ var stringify = require('fast-json-stable-stringify');
5
5
  var upath = require('upath');
6
6
  var webpack = require('webpack');
7
7
  var crypto = require('crypto');
8
+ var relativeToOutputPath = require('./relative-to-output-path.cjs');
8
9
 
9
10
  const BYTE_UNITS = [
10
11
  'B',
@@ -115,7 +116,7 @@ function prettyBytes(number, options) {
115
116
  * @returns The MD5 hash of the asset's source.
116
117
  *
117
118
  * @private
118
- */ function getAssetHash(asset) {
119
+ */ const getAssetHash = (asset)=>{
119
120
  // If webpack has the asset marked as immutable, then we don't need to
120
121
  // use an out-of-band revision for it.
121
122
  // See https://github.com/webpack/webpack/issues/9038
@@ -123,7 +124,7 @@ function prettyBytes(number, options) {
123
124
  return null;
124
125
  }
125
126
  return crypto.createHash("md5").update(Buffer.from(asset.source.source())).digest("hex");
126
- }
127
+ };
127
128
 
128
129
  /*
129
130
  Copyright 2018 Google LLC
@@ -316,7 +317,7 @@ async function getManifestEntriesFromCompilation(compilation, config) {
316
317
  compilation.warnings.push(new Error(warning));
317
318
  }
318
319
  // Ensure that the entries are properly sorted by URL.
319
- const sortedEntries = manifestEntries.sort((a, b)=>a.url === b.url ? 0 : a.url > b.url ? 1 : -1);
320
+ const sortedEntries = manifestEntries?.sort((a, b)=>a.url === b.url ? 0 : a.url > b.url ? 1 : -1);
320
321
  return {
321
322
  size,
322
323
  sortedEntries
@@ -357,23 +358,6 @@ async function getManifestEntriesFromCompilation(compilation, config) {
357
358
  return undefined;
358
359
  }
359
360
 
360
- /**
361
- * @param compilation The webpack compilation.
362
- * @param swDest The original swDest value.
363
- *
364
- * @returns If swDest was not absolute, the returns swDest as-is.
365
- * Otherwise, returns swDest relative to the compilation's output path.
366
- *
367
- * @private
368
- */ function relativeToOutputPath(compilation, swDest) {
369
- // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
370
- if (upath.resolve(swDest) === upath.normalize(swDest)) {
371
- return upath.relative(compilation.options.output.path, swDest);
372
- }
373
- // Otherwise, return swDest as-is.
374
- return swDest;
375
- }
376
-
377
361
  // Used to keep track of swDest files written by *any* instance of this plugin.
378
362
  // See https://github.com/GoogleChrome/workbox/issues/2181
379
363
  const _generatedAssetNames = new Set();
@@ -429,7 +413,7 @@ const _generatedAssetNames = new Set();
429
413
  if (config.disablePrecacheManifest) {
430
414
  return {
431
415
  size: 0,
432
- sortedEntries: [],
416
+ sortedEntries: undefined,
433
417
  manifestString: "undefined"
434
418
  };
435
419
  }
@@ -536,7 +520,7 @@ const _generatedAssetNames = new Set();
536
520
  throw new Error(`Please check your ${this.constructor.name} plugin ` + `configuration:\n${error.message}`);
537
521
  }
538
522
  }
539
- this.config.swDest = relativeToOutputPath(compilation, this.config.swDest);
523
+ this.config.swDest = relativeToOutputPath.relativeToOutputPath(compilation, this.config.swDest);
540
524
  _generatedAssetNames.add(this.config.swDest);
541
525
  if (this.config.compileSrc) {
542
526
  await this.performChildCompilation(compilation, parentCompiler);
@@ -590,7 +574,7 @@ const _generatedAssetNames = new Set();
590
574
  }
591
575
  if (compilation.getLogger) {
592
576
  const logger = compilation.getLogger(this.constructor.name);
593
- logger.info(`The service worker at ${config.swDest ?? ""} will precache ${sortedEntries.length} URLs, totaling ${prettyBytes(size)}.`);
577
+ logger.info(`The service worker at ${config.swDest ?? ""} will precache ${sortedEntries?.length ?? 0} URLs, totaling ${prettyBytes(size)}.`);
594
578
  }
595
579
  }
596
580
  }
File without changes
@@ -1,24 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  var webpack = require('webpack');
4
- var upath = require('upath');
5
-
6
- /**
7
- * @param compilation The webpack compilation.
8
- * @param swDest The original swDest value.
9
- *
10
- * @returns If swDest was not absolute, the returns swDest as-is.
11
- * Otherwise, returns swDest relative to the compilation's output path.
12
- *
13
- * @private
14
- */ function relativeToOutputPath(compilation, swDest) {
15
- // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
16
- if (upath.resolve(swDest) === upath.normalize(swDest)) {
17
- return upath.relative(compilation.options.output.path, swDest);
18
- }
19
- // Otherwise, return swDest as-is.
20
- return swDest;
21
- }
4
+ var relativeToOutputPath = require('./relative-to-output-path.cjs');
5
+ require('upath');
22
6
 
23
7
  /**
24
8
  * Compile a file by creating a child of the hooked compiler.
@@ -39,7 +23,7 @@ var upath = require('upath');
39
23
  }));
40
24
  }
41
25
  async performChildCompilation(compilation, parentCompiler) {
42
- const resolvedDest = relativeToOutputPath(compilation, this.dest);
26
+ const resolvedDest = relativeToOutputPath.relativeToOutputPath(compilation, this.dest);
43
27
  const outputOptions = {
44
28
  filename: resolvedDest
45
29
  };
@@ -1,22 +1,6 @@
1
1
  import webpack from 'webpack';
2
- import upath from 'upath';
3
-
4
- /**
5
- * @param compilation The webpack compilation.
6
- * @param swDest The original swDest value.
7
- *
8
- * @returns If swDest was not absolute, the returns swDest as-is.
9
- * Otherwise, returns swDest relative to the compilation's output path.
10
- *
11
- * @private
12
- */ function relativeToOutputPath(compilation, swDest) {
13
- // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
14
- if (upath.resolve(swDest) === upath.normalize(swDest)) {
15
- return upath.relative(compilation.options.output.path, swDest);
16
- }
17
- // Otherwise, return swDest as-is.
18
- return swDest;
19
- }
2
+ import { r as relativeToOutputPath } from './relative-to-output-path.js';
3
+ import 'upath';
20
4
 
21
5
  /**
22
6
  * Compile a file by creating a child of the hooked compiler.
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import stringify from 'fast-json-stable-stringify';
3
3
  import upath from 'upath';
4
4
  import webpack from 'webpack';
5
5
  import crypto from 'crypto';
6
+ import { r as relativeToOutputPath } from './relative-to-output-path.js';
6
7
 
7
8
  const BYTE_UNITS = [
8
9
  'B',
@@ -113,7 +114,7 @@ function prettyBytes(number, options) {
113
114
  * @returns The MD5 hash of the asset's source.
114
115
  *
115
116
  * @private
116
- */ function getAssetHash(asset) {
117
+ */ const getAssetHash = (asset)=>{
117
118
  // If webpack has the asset marked as immutable, then we don't need to
118
119
  // use an out-of-band revision for it.
119
120
  // See https://github.com/webpack/webpack/issues/9038
@@ -121,7 +122,7 @@ function prettyBytes(number, options) {
121
122
  return null;
122
123
  }
123
124
  return crypto.createHash("md5").update(Buffer.from(asset.source.source())).digest("hex");
124
- }
125
+ };
125
126
 
126
127
  /*
127
128
  Copyright 2018 Google LLC
@@ -314,7 +315,7 @@ async function getManifestEntriesFromCompilation(compilation, config) {
314
315
  compilation.warnings.push(new Error(warning));
315
316
  }
316
317
  // Ensure that the entries are properly sorted by URL.
317
- const sortedEntries = manifestEntries.sort((a, b)=>a.url === b.url ? 0 : a.url > b.url ? 1 : -1);
318
+ const sortedEntries = manifestEntries?.sort((a, b)=>a.url === b.url ? 0 : a.url > b.url ? 1 : -1);
318
319
  return {
319
320
  size,
320
321
  sortedEntries
@@ -355,23 +356,6 @@ async function getManifestEntriesFromCompilation(compilation, config) {
355
356
  return undefined;
356
357
  }
357
358
 
358
- /**
359
- * @param compilation The webpack compilation.
360
- * @param swDest The original swDest value.
361
- *
362
- * @returns If swDest was not absolute, the returns swDest as-is.
363
- * Otherwise, returns swDest relative to the compilation's output path.
364
- *
365
- * @private
366
- */ function relativeToOutputPath(compilation, swDest) {
367
- // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
368
- if (upath.resolve(swDest) === upath.normalize(swDest)) {
369
- return upath.relative(compilation.options.output.path, swDest);
370
- }
371
- // Otherwise, return swDest as-is.
372
- return swDest;
373
- }
374
-
375
359
  // Used to keep track of swDest files written by *any* instance of this plugin.
376
360
  // See https://github.com/GoogleChrome/workbox/issues/2181
377
361
  const _generatedAssetNames = new Set();
@@ -427,7 +411,7 @@ const _generatedAssetNames = new Set();
427
411
  if (config.disablePrecacheManifest) {
428
412
  return {
429
413
  size: 0,
430
- sortedEntries: [],
414
+ sortedEntries: undefined,
431
415
  manifestString: "undefined"
432
416
  };
433
417
  }
@@ -588,7 +572,7 @@ const _generatedAssetNames = new Set();
588
572
  }
589
573
  if (compilation.getLogger) {
590
574
  const logger = compilation.getLogger(this.constructor.name);
591
- logger.info(`The service worker at ${config.swDest ?? ""} will precache ${sortedEntries.length} URLs, totaling ${prettyBytes(size)}.`);
575
+ logger.info(`The service worker at ${config.swDest ?? ""} will precache ${sortedEntries?.length ?? 0} URLs, totaling ${prettyBytes(size)}.`);
592
576
  }
593
577
  }
594
578
  }
File without changes
@@ -42,7 +42,7 @@ declare class InjectManifest {
42
42
  */
43
43
  getManifestEntries(compilation: webpack.Compilation, config: WebpackInjectManifestOptions): Promise<{
44
44
  size: number;
45
- sortedEntries: import("@serwist/build").ManifestEntry[];
45
+ sortedEntries: import("@serwist/build").ManifestEntry[] | undefined;
46
46
  manifestString: string;
47
47
  }>;
48
48
  /**
@@ -0,0 +1,20 @@
1
+ import type { WebpackPluginInstance } from "webpack";
2
+ import webpack from "webpack";
3
+ export interface ChildCompilationPluginOptions {
4
+ src: string;
5
+ dest: string;
6
+ plugins?: WebpackPluginInstance[];
7
+ }
8
+ /**
9
+ * Compile a file by creating a child of the hooked compiler.
10
+ *
11
+ * @private
12
+ */
13
+ export declare class ChildCompilationPlugin implements WebpackPluginInstance {
14
+ src: string;
15
+ dest: string;
16
+ plugins: WebpackPluginInstance[] | undefined;
17
+ constructor({ src, dest, plugins }: ChildCompilationPluginOptions);
18
+ apply(compiler: webpack.Compiler): void;
19
+ performChildCompilation(compilation: webpack.Compilation, parentCompiler: webpack.Compiler): Promise<void>;
20
+ }
@@ -0,0 +1,8 @@
1
+ import type { Asset } from "webpack";
2
+ /**
3
+ * @param asset
4
+ * @returns The MD5 hash of the asset's source.
5
+ *
6
+ * @private
7
+ */
8
+ export declare const getAssetHash: (asset: Asset) => string | null;
@@ -5,4 +5,4 @@ import type { Asset } from "webpack";
5
5
  *
6
6
  * @private
7
7
  */
8
- export declare function getAssetHash(asset: Asset): string | null;
8
+ export declare const getAssetHash: (asset: Asset) => string | null;
@@ -0,0 +1,6 @@
1
+ import type { ManifestEntry, WebpackInjectManifestOptions } from "@serwist/build";
2
+ import type { Compilation } from "webpack";
3
+ export declare function getManifestEntriesFromCompilation(compilation: Compilation, config: WebpackInjectManifestOptions): Promise<{
4
+ size: number;
5
+ sortedEntries: ManifestEntry[] | undefined;
6
+ }>;
@@ -2,5 +2,5 @@ import type { ManifestEntry, WebpackInjectManifestOptions } from "@serwist/build
2
2
  import type { Compilation } from "webpack";
3
3
  export declare function getManifestEntriesFromCompilation(compilation: Compilation, config: WebpackInjectManifestOptions): Promise<{
4
4
  size: number;
5
- sortedEntries: ManifestEntry[];
5
+ sortedEntries: ManifestEntry[] | undefined;
6
6
  }>;
File without changes
File without changes
@@ -0,0 +1,11 @@
1
+ import type { Compilation } from "webpack";
2
+ /**
3
+ * @param compilation The webpack compilation.
4
+ * @param swDest The original swDest value.
5
+ *
6
+ * @returns If swDest was not absolute, the returns swDest as-is.
7
+ * Otherwise, returns swDest relative to the compilation's output path.
8
+ *
9
+ * @private
10
+ */
11
+ export declare function relativeToOutputPath(compilation: Compilation, swDest: string): string;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Resolves a url in the way that webpack would (with string concatenation)
3
+ *
4
+ * Use publicPath + filePath instead of url.resolve(publicPath, filePath) see:
5
+ * https://webpack.js.org/configuration/output/#output-publicpath
6
+ *
7
+ * @param publicPath The publicPath value from webpack's compilation.
8
+ * @param paths File paths to join
9
+ * @returns Joined file path
10
+ * @private
11
+ */
12
+ export declare function resolveWebpackURL(publicPath: string, ...paths: Array<string>): string;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var upath = require('upath');
4
+
5
+ /**
6
+ * @param compilation The webpack compilation.
7
+ * @param swDest The original swDest value.
8
+ *
9
+ * @returns If swDest was not absolute, the returns swDest as-is.
10
+ * Otherwise, returns swDest relative to the compilation's output path.
11
+ *
12
+ * @private
13
+ */ function relativeToOutputPath(compilation, swDest) {
14
+ // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
15
+ if (upath.resolve(swDest) === upath.normalize(swDest)) {
16
+ return upath.relative(compilation.options.output.path, swDest);
17
+ }
18
+ // Otherwise, return swDest as-is.
19
+ return swDest;
20
+ }
21
+
22
+ exports.relativeToOutputPath = relativeToOutputPath;
@@ -0,0 +1,20 @@
1
+ import upath from 'upath';
2
+
3
+ /**
4
+ * @param compilation The webpack compilation.
5
+ * @param swDest The original swDest value.
6
+ *
7
+ * @returns If swDest was not absolute, the returns swDest as-is.
8
+ * Otherwise, returns swDest relative to the compilation's output path.
9
+ *
10
+ * @private
11
+ */ function relativeToOutputPath(compilation, swDest) {
12
+ // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38
13
+ if (upath.resolve(swDest) === upath.normalize(swDest)) {
14
+ return upath.relative(compilation.options.output.path, swDest);
15
+ }
16
+ // Otherwise, return swDest as-is.
17
+ return swDest;
18
+ }
19
+
20
+ export { relativeToOutputPath as r };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/webpack-plugin",
3
- "version": "8.1.1",
3
+ "version": "8.3.0",
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": [
@@ -24,9 +24,9 @@
24
24
  "license": "MIT",
25
25
  "repository": "serwist/serwist",
26
26
  "bugs": "https://github.com/serwist/serwist/issues",
27
- "homepage": "https://ducanh-next-pwa.vercel.app",
27
+ "homepage": "https://serwist.vercel.app",
28
28
  "module": "./dist/index.js",
29
- "main": "./dist/index.old.cjs",
29
+ "main": "./dist/index.cjs",
30
30
  "types": "./dist/index.d.ts",
31
31
  "typesVersions": {
32
32
  "*": {
@@ -42,8 +42,8 @@
42
42
  "default": "./dist/index.js"
43
43
  },
44
44
  "require": {
45
- "types": "./dist/index.old.d.cts",
46
- "default": "./dist/index.old.cjs"
45
+ "types": "./dist/index.d.cts",
46
+ "default": "./dist/index.cjs"
47
47
  }
48
48
  },
49
49
  "./internal": {
@@ -52,17 +52,16 @@
52
52
  "default": "./dist/index.internal.js"
53
53
  },
54
54
  "require": {
55
- "types": "./dist/index.internal.old.d.cts",
56
- "default": "./dist/index.internal.old.cjs"
55
+ "types": "./dist/index.internal.d.cts",
56
+ "default": "./dist/index.internal.cjs"
57
57
  }
58
58
  },
59
59
  "./package.json": "./package.json"
60
60
  },
61
61
  "dependencies": {
62
62
  "fast-json-stable-stringify": "2.1.0",
63
- "rollup": "4.9.1",
64
63
  "upath": "2.0.1",
65
- "@serwist/build": "8.1.1"
64
+ "@serwist/build": "8.3.0"
66
65
  },
67
66
  "peerDependencies": {
68
67
  "webpack": "4.4.0 || ^5.9.0"
@@ -71,7 +70,8 @@
71
70
  "@types/node": "20.10.5",
72
71
  "@types/webpack": "5.28.5",
73
72
  "pretty-bytes": "6.1.1",
74
- "@serwist/constants": "8.1.1"
73
+ "rollup": "4.9.1",
74
+ "@serwist/constants": "8.3.0"
75
75
  },
76
76
  "scripts": {
77
77
  "build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
@@ -1,2 +0,0 @@
1
- import { InjectManifest } from "./inject-manifest.js";
2
- export { InjectManifest };