@serwist/webpack-plugin
Advanced tools
Comparing version 8.0.3 to 8.0.4
import path from 'node:path'; | ||
import { transformManifest, getSourceMapURL, validateWebpackInjectManifestOptions, escapeRegExp, replaceAndUpdateSourceMap } from '@serwist/build'; | ||
import stringify from 'fast-json-stable-stringify'; | ||
import prettyBytes from 'pretty-bytes'; | ||
import upath from 'upath'; | ||
@@ -9,2 +8,106 @@ import webpack from 'webpack'; | ||
const BYTE_UNITS = [ | ||
'B', | ||
'kB', | ||
'MB', | ||
'GB', | ||
'TB', | ||
'PB', | ||
'EB', | ||
'ZB', | ||
'YB' | ||
]; | ||
const BIBYTE_UNITS = [ | ||
'B', | ||
'KiB', | ||
'MiB', | ||
'GiB', | ||
'TiB', | ||
'PiB', | ||
'EiB', | ||
'ZiB', | ||
'YiB' | ||
]; | ||
const BIT_UNITS = [ | ||
'b', | ||
'kbit', | ||
'Mbit', | ||
'Gbit', | ||
'Tbit', | ||
'Pbit', | ||
'Ebit', | ||
'Zbit', | ||
'Ybit' | ||
]; | ||
const BIBIT_UNITS = [ | ||
'b', | ||
'kibit', | ||
'Mibit', | ||
'Gibit', | ||
'Tibit', | ||
'Pibit', | ||
'Eibit', | ||
'Zibit', | ||
'Yibit' | ||
]; | ||
/* | ||
Formats the given number using `Number#toLocaleString`. | ||
- If locale is a string, the value is expected to be a locale-key (for example: `de`). | ||
- If locale is true, the system default locale is used for translation. | ||
- If no value for locale is specified, the number is returned unmodified. | ||
*/ const toLocaleString = (number, locale, options)=>{ | ||
let result = number; | ||
if (typeof locale === 'string' || Array.isArray(locale)) { | ||
result = number.toLocaleString(locale, options); | ||
} else if (locale === true || options !== undefined) { | ||
result = number.toLocaleString(undefined, options); | ||
} | ||
return result; | ||
}; | ||
function prettyBytes(number, options) { | ||
if (!Number.isFinite(number)) { | ||
throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`); | ||
} | ||
options = { | ||
bits: false, | ||
binary: false, | ||
space: true, | ||
...options | ||
}; | ||
const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS; | ||
const separator = options.space ? ' ' : ''; | ||
if (options.signed && number === 0) { | ||
return ` 0${separator}${UNITS[0]}`; | ||
} | ||
const isNegative = number < 0; | ||
const prefix = isNegative ? '-' : options.signed ? '+' : ''; | ||
if (isNegative) { | ||
number = -number; | ||
} | ||
let localeOptions; | ||
if (options.minimumFractionDigits !== undefined) { | ||
localeOptions = { | ||
minimumFractionDigits: options.minimumFractionDigits | ||
}; | ||
} | ||
if (options.maximumFractionDigits !== undefined) { | ||
localeOptions = { | ||
maximumFractionDigits: options.maximumFractionDigits, | ||
...localeOptions | ||
}; | ||
} | ||
if (number < 1) { | ||
const numberString = toLocaleString(number, options.locale, localeOptions); | ||
return prefix + numberString + separator + UNITS[0]; | ||
} | ||
const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1); | ||
number /= (options.binary ? 1024 : 1000) ** exponent; | ||
if (!localeOptions) { | ||
number = number.toPrecision(3); | ||
} | ||
const numberString = toLocaleString(Number(number), options.locale, localeOptions); | ||
const unit = UNITS[exponent]; | ||
return prefix + numberString + separator + unit; | ||
} | ||
/** | ||
@@ -11,0 +114,0 @@ * @param asset |
{ | ||
"name": "@serwist/webpack-plugin", | ||
"version": "8.0.3", | ||
"version": "8.0.4", | ||
"type": "module", | ||
@@ -40,10 +40,20 @@ "description": "A plugin for your Webpack build process, helping you generate a manifest of local files that should be precached.", | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.old.cjs", | ||
"types": "./dist/index.d.ts" | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.old.d.cts", | ||
"default": "./dist/index.old.cjs" | ||
} | ||
}, | ||
"./internal": { | ||
"import": "./dist/index.internal.js", | ||
"require": "./dist/index.internal.old.cjs", | ||
"types": "./dist/index.internal.d.ts" | ||
"import": { | ||
"types": "./dist/index.internal.d.ts", | ||
"default": "./dist/index.internal.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.internal.old.d.cts", | ||
"default": "./dist/index.internal.old.cjs" | ||
} | ||
}, | ||
@@ -54,6 +64,5 @@ "./package.json": "./package.json" | ||
"fast-json-stable-stringify": "2.1.0", | ||
"pretty-bytes": "6.1.1", | ||
"rollup": "3.28.1", | ||
"upath": "2.0.1", | ||
"@serwist/build": "8.0.3" | ||
"@serwist/build": "8.0.4" | ||
}, | ||
@@ -64,5 +73,6 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@types/node": "20.8.7", | ||
"@types/webpack": "5.28.3", | ||
"@serwist/constants": "8.0.3" | ||
"@types/node": "20.10.4", | ||
"@types/webpack": "5.28.5", | ||
"pretty-bytes": "6.1.1", | ||
"@serwist/constants": "8.0.4" | ||
}, | ||
@@ -69,0 +79,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
62422
5
19
0
100
1474
4
+ Added@serwist/background-sync@8.0.4(transitive)
+ Added@serwist/broadcast-update@8.0.4(transitive)
+ Added@serwist/build@8.0.4(transitive)
+ Added@serwist/cacheable-response@8.0.4(transitive)
+ Added@serwist/core@8.0.4(transitive)
+ Added@serwist/expiration@8.0.4(transitive)
+ Added@serwist/google-analytics@8.0.4(transitive)
+ Added@serwist/precaching@8.0.4(transitive)
+ Added@serwist/routing@8.0.4(transitive)
+ Added@serwist/strategies@8.0.4(transitive)
+ Addedfs-extra@11.2.0(transitive)
+ Addedidb@8.0.0(transitive)
- Removedpretty-bytes@6.1.1
- Removed@serwist/background-sync@8.0.3(transitive)
- Removed@serwist/broadcast-update@8.0.3(transitive)
- Removed@serwist/build@8.0.3(transitive)
- Removed@serwist/cacheable-response@8.0.3(transitive)
- Removed@serwist/core@8.0.3(transitive)
- Removed@serwist/expiration@8.0.3(transitive)
- Removed@serwist/google-analytics@8.0.3(transitive)
- Removed@serwist/precaching@8.0.3(transitive)
- Removed@serwist/routing@8.0.3(transitive)
- Removed@serwist/strategies@8.0.3(transitive)
- Removedfs-extra@11.1.1(transitive)
- Removedidb@7.1.1(transitive)
- Removedpretty-bytes@6.1.1(transitive)
Updated@serwist/build@8.0.4