@serwist/webpack-plugin 8.0.2 → 8.0.4

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.
@@ -0,0 +1,2 @@
1
+ import { ChildCompilationPlugin } from "./lib/child-compilation-plugin.js";
2
+ export { ChildCompilationPlugin };
package/dist/index.js CHANGED
@@ -1,11 +1,114 @@
1
1
  import path from 'node:path';
2
2
  import { transformManifest, getSourceMapURL, validateWebpackInjectManifestOptions, escapeRegExp, replaceAndUpdateSourceMap } from '@serwist/build';
3
3
  import stringify from 'fast-json-stable-stringify';
4
- import prettyBytes from 'pretty-bytes';
5
4
  import upath from 'upath';
6
5
  import webpack from 'webpack';
7
6
  import crypto from 'crypto';
8
7
 
8
+ const BYTE_UNITS = [
9
+ 'B',
10
+ 'kB',
11
+ 'MB',
12
+ 'GB',
13
+ 'TB',
14
+ 'PB',
15
+ 'EB',
16
+ 'ZB',
17
+ 'YB'
18
+ ];
19
+ const BIBYTE_UNITS = [
20
+ 'B',
21
+ 'KiB',
22
+ 'MiB',
23
+ 'GiB',
24
+ 'TiB',
25
+ 'PiB',
26
+ 'EiB',
27
+ 'ZiB',
28
+ 'YiB'
29
+ ];
30
+ const BIT_UNITS = [
31
+ 'b',
32
+ 'kbit',
33
+ 'Mbit',
34
+ 'Gbit',
35
+ 'Tbit',
36
+ 'Pbit',
37
+ 'Ebit',
38
+ 'Zbit',
39
+ 'Ybit'
40
+ ];
41
+ const BIBIT_UNITS = [
42
+ 'b',
43
+ 'kibit',
44
+ 'Mibit',
45
+ 'Gibit',
46
+ 'Tibit',
47
+ 'Pibit',
48
+ 'Eibit',
49
+ 'Zibit',
50
+ 'Yibit'
51
+ ];
52
+ /*
53
+ Formats the given number using `Number#toLocaleString`.
54
+ - If locale is a string, the value is expected to be a locale-key (for example: `de`).
55
+ - If locale is true, the system default locale is used for translation.
56
+ - If no value for locale is specified, the number is returned unmodified.
57
+ */ const toLocaleString = (number, locale, options)=>{
58
+ let result = number;
59
+ if (typeof locale === 'string' || Array.isArray(locale)) {
60
+ result = number.toLocaleString(locale, options);
61
+ } else if (locale === true || options !== undefined) {
62
+ result = number.toLocaleString(undefined, options);
63
+ }
64
+ return result;
65
+ };
66
+ function prettyBytes(number, options) {
67
+ if (!Number.isFinite(number)) {
68
+ throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
69
+ }
70
+ options = {
71
+ bits: false,
72
+ binary: false,
73
+ space: true,
74
+ ...options
75
+ };
76
+ const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
77
+ const separator = options.space ? ' ' : '';
78
+ if (options.signed && number === 0) {
79
+ return ` 0${separator}${UNITS[0]}`;
80
+ }
81
+ const isNegative = number < 0;
82
+ const prefix = isNegative ? '-' : options.signed ? '+' : '';
83
+ if (isNegative) {
84
+ number = -number;
85
+ }
86
+ let localeOptions;
87
+ if (options.minimumFractionDigits !== undefined) {
88
+ localeOptions = {
89
+ minimumFractionDigits: options.minimumFractionDigits
90
+ };
91
+ }
92
+ if (options.maximumFractionDigits !== undefined) {
93
+ localeOptions = {
94
+ maximumFractionDigits: options.maximumFractionDigits,
95
+ ...localeOptions
96
+ };
97
+ }
98
+ if (number < 1) {
99
+ const numberString = toLocaleString(number, options.locale, localeOptions);
100
+ return prefix + numberString + separator + UNITS[0];
101
+ }
102
+ const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
103
+ number /= (options.binary ? 1024 : 1000) ** exponent;
104
+ if (!localeOptions) {
105
+ number = number.toPrecision(3);
106
+ }
107
+ const numberString = toLocaleString(Number(number), options.locale, localeOptions);
108
+ const unit = UNITS[exponent];
109
+ return prefix + numberString + separator + unit;
110
+ }
111
+
9
112
  /**
10
113
  * @param asset
11
114
  * @returns The MD5 hash of the asset's source.
@@ -3,11 +3,114 @@
3
3
  var path = require('node:path');
4
4
  var build = require('@serwist/build');
5
5
  var stringify = require('fast-json-stable-stringify');
6
- var prettyBytes = require('pretty-bytes');
7
6
  var upath = require('upath');
8
7
  var webpack = require('webpack');
9
8
  var crypto = require('crypto');
10
9
 
10
+ const BYTE_UNITS = [
11
+ 'B',
12
+ 'kB',
13
+ 'MB',
14
+ 'GB',
15
+ 'TB',
16
+ 'PB',
17
+ 'EB',
18
+ 'ZB',
19
+ 'YB'
20
+ ];
21
+ const BIBYTE_UNITS = [
22
+ 'B',
23
+ 'KiB',
24
+ 'MiB',
25
+ 'GiB',
26
+ 'TiB',
27
+ 'PiB',
28
+ 'EiB',
29
+ 'ZiB',
30
+ 'YiB'
31
+ ];
32
+ const BIT_UNITS = [
33
+ 'b',
34
+ 'kbit',
35
+ 'Mbit',
36
+ 'Gbit',
37
+ 'Tbit',
38
+ 'Pbit',
39
+ 'Ebit',
40
+ 'Zbit',
41
+ 'Ybit'
42
+ ];
43
+ const BIBIT_UNITS = [
44
+ 'b',
45
+ 'kibit',
46
+ 'Mibit',
47
+ 'Gibit',
48
+ 'Tibit',
49
+ 'Pibit',
50
+ 'Eibit',
51
+ 'Zibit',
52
+ 'Yibit'
53
+ ];
54
+ /*
55
+ Formats the given number using `Number#toLocaleString`.
56
+ - If locale is a string, the value is expected to be a locale-key (for example: `de`).
57
+ - If locale is true, the system default locale is used for translation.
58
+ - If no value for locale is specified, the number is returned unmodified.
59
+ */ const toLocaleString = (number, locale, options)=>{
60
+ let result = number;
61
+ if (typeof locale === 'string' || Array.isArray(locale)) {
62
+ result = number.toLocaleString(locale, options);
63
+ } else if (locale === true || options !== undefined) {
64
+ result = number.toLocaleString(undefined, options);
65
+ }
66
+ return result;
67
+ };
68
+ function prettyBytes(number, options) {
69
+ if (!Number.isFinite(number)) {
70
+ throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
71
+ }
72
+ options = {
73
+ bits: false,
74
+ binary: false,
75
+ space: true,
76
+ ...options
77
+ };
78
+ const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
79
+ const separator = options.space ? ' ' : '';
80
+ if (options.signed && number === 0) {
81
+ return ` 0${separator}${UNITS[0]}`;
82
+ }
83
+ const isNegative = number < 0;
84
+ const prefix = isNegative ? '-' : options.signed ? '+' : '';
85
+ if (isNegative) {
86
+ number = -number;
87
+ }
88
+ let localeOptions;
89
+ if (options.minimumFractionDigits !== undefined) {
90
+ localeOptions = {
91
+ minimumFractionDigits: options.minimumFractionDigits
92
+ };
93
+ }
94
+ if (options.maximumFractionDigits !== undefined) {
95
+ localeOptions = {
96
+ maximumFractionDigits: options.maximumFractionDigits,
97
+ ...localeOptions
98
+ };
99
+ }
100
+ if (number < 1) {
101
+ const numberString = toLocaleString(number, options.locale, localeOptions);
102
+ return prefix + numberString + separator + UNITS[0];
103
+ }
104
+ const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
105
+ number /= (options.binary ? 1024 : 1000) ** exponent;
106
+ if (!localeOptions) {
107
+ number = number.toPrecision(3);
108
+ }
109
+ const numberString = toLocaleString(Number(number), options.locale, localeOptions);
110
+ const unit = UNITS[exponent];
111
+ return prefix + numberString + separator + unit;
112
+ }
113
+
11
114
  /**
12
115
  * @param asset
13
116
  * @returns The MD5 hash of the asset's source.
@@ -0,0 +1,2 @@
1
+ import { InjectManifest } from "./inject-manifest.js";
2
+ export { InjectManifest };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/webpack-plugin",
3
- "version": "8.0.2",
3
+ "version": "8.0.4",
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": [
@@ -37,31 +37,41 @@
37
37
  },
38
38
  "exports": {
39
39
  ".": {
40
- "import": "./dist/index.js",
41
- "require": "./dist/index.old.cjs",
42
- "types": "./dist/index.d.ts"
40
+ "import": {
41
+ "types": "./dist/index.d.ts",
42
+ "default": "./dist/index.js"
43
+ },
44
+ "require": {
45
+ "types": "./dist/index.old.d.cts",
46
+ "default": "./dist/index.old.cjs"
47
+ }
43
48
  },
44
49
  "./internal": {
45
- "import": "./dist/index.internal.js",
46
- "require": "./dist/index.internal.old.cjs",
47
- "types": "./dist/index.internal.d.ts"
50
+ "import": {
51
+ "types": "./dist/index.internal.d.ts",
52
+ "default": "./dist/index.internal.js"
53
+ },
54
+ "require": {
55
+ "types": "./dist/index.internal.old.d.cts",
56
+ "default": "./dist/index.internal.old.cjs"
57
+ }
48
58
  },
49
59
  "./package.json": "./package.json"
50
60
  },
51
61
  "dependencies": {
52
62
  "fast-json-stable-stringify": "2.1.0",
53
- "pretty-bytes": "6.1.1",
54
63
  "rollup": "3.28.1",
55
64
  "upath": "2.0.1",
56
- "@serwist/build": "8.0.2"
65
+ "@serwist/build": "8.0.4"
57
66
  },
58
67
  "peerDependencies": {
59
68
  "webpack": "4.4.0 || ^5.9.0"
60
69
  },
61
70
  "devDependencies": {
62
- "@types/node": "20.8.7",
63
- "@types/webpack": "5.28.3",
64
- "@serwist/constants": "8.0.2"
71
+ "@types/node": "20.10.4",
72
+ "@types/webpack": "5.28.5",
73
+ "pretty-bytes": "6.1.1",
74
+ "@serwist/constants": "8.0.4"
65
75
  },
66
76
  "scripts": {
67
77
  "build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",