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