@serwist/build 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.
package/dist/index.js CHANGED
@@ -4,7 +4,6 @@ import crypto from 'crypto';
4
4
  import { glob } from 'glob';
5
5
  import upath from 'upath';
6
6
  import fse from 'fs-extra';
7
- import prettyBytes from 'pretty-bytes';
8
7
  import { betterAjvErrors } from '@apideck/better-ajv-errors';
9
8
  import Ajv from 'ajv';
10
9
  import stringify from 'fast-json-stable-stringify';
@@ -231,6 +230,110 @@ function additionalPrecacheEntriesTransform(additionalPrecacheEntries) {
231
230
  };
232
231
  }
233
232
 
233
+ const BYTE_UNITS = [
234
+ 'B',
235
+ 'kB',
236
+ 'MB',
237
+ 'GB',
238
+ 'TB',
239
+ 'PB',
240
+ 'EB',
241
+ 'ZB',
242
+ 'YB'
243
+ ];
244
+ const BIBYTE_UNITS = [
245
+ 'B',
246
+ 'KiB',
247
+ 'MiB',
248
+ 'GiB',
249
+ 'TiB',
250
+ 'PiB',
251
+ 'EiB',
252
+ 'ZiB',
253
+ 'YiB'
254
+ ];
255
+ const BIT_UNITS = [
256
+ 'b',
257
+ 'kbit',
258
+ 'Mbit',
259
+ 'Gbit',
260
+ 'Tbit',
261
+ 'Pbit',
262
+ 'Ebit',
263
+ 'Zbit',
264
+ 'Ybit'
265
+ ];
266
+ const BIBIT_UNITS = [
267
+ 'b',
268
+ 'kibit',
269
+ 'Mibit',
270
+ 'Gibit',
271
+ 'Tibit',
272
+ 'Pibit',
273
+ 'Eibit',
274
+ 'Zibit',
275
+ 'Yibit'
276
+ ];
277
+ /*
278
+ Formats the given number using `Number#toLocaleString`.
279
+ - If locale is a string, the value is expected to be a locale-key (for example: `de`).
280
+ - If locale is true, the system default locale is used for translation.
281
+ - If no value for locale is specified, the number is returned unmodified.
282
+ */ const toLocaleString = (number, locale, options)=>{
283
+ let result = number;
284
+ if (typeof locale === 'string' || Array.isArray(locale)) {
285
+ result = number.toLocaleString(locale, options);
286
+ } else if (locale === true || options !== undefined) {
287
+ result = number.toLocaleString(undefined, options);
288
+ }
289
+ return result;
290
+ };
291
+ function prettyBytes(number, options) {
292
+ if (!Number.isFinite(number)) {
293
+ throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
294
+ }
295
+ options = {
296
+ bits: false,
297
+ binary: false,
298
+ space: true,
299
+ ...options
300
+ };
301
+ const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
302
+ const separator = options.space ? ' ' : '';
303
+ if (options.signed && number === 0) {
304
+ return ` 0${separator}${UNITS[0]}`;
305
+ }
306
+ const isNegative = number < 0;
307
+ const prefix = isNegative ? '-' : options.signed ? '+' : '';
308
+ if (isNegative) {
309
+ number = -number;
310
+ }
311
+ let localeOptions;
312
+ if (options.minimumFractionDigits !== undefined) {
313
+ localeOptions = {
314
+ minimumFractionDigits: options.minimumFractionDigits
315
+ };
316
+ }
317
+ if (options.maximumFractionDigits !== undefined) {
318
+ localeOptions = {
319
+ maximumFractionDigits: options.maximumFractionDigits,
320
+ ...localeOptions
321
+ };
322
+ }
323
+ if (number < 1) {
324
+ const numberString = toLocaleString(number, options.locale, localeOptions);
325
+ return prefix + numberString + separator + UNITS[0];
326
+ }
327
+ const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
328
+ number /= (options.binary ? 1024 : 1000) ** exponent;
329
+ if (!localeOptions) {
330
+ number = number.toPrecision(3);
331
+ }
332
+ const numberString = toLocaleString(Number(number), options.locale, localeOptions);
333
+ const unit = UNITS[exponent];
334
+ return prefix + numberString + separator + unit;
335
+ }
336
+
234
337
  function maximumSizeTransform(maximumFileSizeToCacheInBytes) {
235
338
  return (originalManifest)=>{
236
339
  const warnings = [];
@@ -6,7 +6,6 @@ var crypto = require('crypto');
6
6
  var glob = require('glob');
7
7
  var upath = require('upath');
8
8
  var fse = require('fs-extra');
9
- var prettyBytes = require('pretty-bytes');
10
9
  var betterAjvErrors = require('@apideck/better-ajv-errors');
11
10
  var Ajv = require('ajv');
12
11
  var stringify = require('fast-json-stable-stringify');
@@ -233,6 +232,110 @@ function additionalPrecacheEntriesTransform(additionalPrecacheEntries) {
233
232
  };
234
233
  }
235
234
 
235
+ const BYTE_UNITS = [
236
+ 'B',
237
+ 'kB',
238
+ 'MB',
239
+ 'GB',
240
+ 'TB',
241
+ 'PB',
242
+ 'EB',
243
+ 'ZB',
244
+ 'YB'
245
+ ];
246
+ const BIBYTE_UNITS = [
247
+ 'B',
248
+ 'KiB',
249
+ 'MiB',
250
+ 'GiB',
251
+ 'TiB',
252
+ 'PiB',
253
+ 'EiB',
254
+ 'ZiB',
255
+ 'YiB'
256
+ ];
257
+ const BIT_UNITS = [
258
+ 'b',
259
+ 'kbit',
260
+ 'Mbit',
261
+ 'Gbit',
262
+ 'Tbit',
263
+ 'Pbit',
264
+ 'Ebit',
265
+ 'Zbit',
266
+ 'Ybit'
267
+ ];
268
+ const BIBIT_UNITS = [
269
+ 'b',
270
+ 'kibit',
271
+ 'Mibit',
272
+ 'Gibit',
273
+ 'Tibit',
274
+ 'Pibit',
275
+ 'Eibit',
276
+ 'Zibit',
277
+ 'Yibit'
278
+ ];
279
+ /*
280
+ Formats the given number using `Number#toLocaleString`.
281
+ - If locale is a string, the value is expected to be a locale-key (for example: `de`).
282
+ - If locale is true, the system default locale is used for translation.
283
+ - If no value for locale is specified, the number is returned unmodified.
284
+ */ const toLocaleString = (number, locale, options)=>{
285
+ let result = number;
286
+ if (typeof locale === 'string' || Array.isArray(locale)) {
287
+ result = number.toLocaleString(locale, options);
288
+ } else if (locale === true || options !== undefined) {
289
+ result = number.toLocaleString(undefined, options);
290
+ }
291
+ return result;
292
+ };
293
+ function prettyBytes(number, options) {
294
+ if (!Number.isFinite(number)) {
295
+ throw new TypeError(`Expected a finite number, got ${typeof number}: ${number}`);
296
+ }
297
+ options = {
298
+ bits: false,
299
+ binary: false,
300
+ space: true,
301
+ ...options
302
+ };
303
+ const UNITS = options.bits ? options.binary ? BIBIT_UNITS : BIT_UNITS : options.binary ? BIBYTE_UNITS : BYTE_UNITS;
304
+ const separator = options.space ? ' ' : '';
305
+ if (options.signed && number === 0) {
306
+ return ` 0${separator}${UNITS[0]}`;
307
+ }
308
+ const isNegative = number < 0;
309
+ const prefix = isNegative ? '-' : options.signed ? '+' : '';
310
+ if (isNegative) {
311
+ number = -number;
312
+ }
313
+ let localeOptions;
314
+ if (options.minimumFractionDigits !== undefined) {
315
+ localeOptions = {
316
+ minimumFractionDigits: options.minimumFractionDigits
317
+ };
318
+ }
319
+ if (options.maximumFractionDigits !== undefined) {
320
+ localeOptions = {
321
+ maximumFractionDigits: options.maximumFractionDigits,
322
+ ...localeOptions
323
+ };
324
+ }
325
+ if (number < 1) {
326
+ const numberString = toLocaleString(number, options.locale, localeOptions);
327
+ return prefix + numberString + separator + UNITS[0];
328
+ }
329
+ const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
330
+ number /= (options.binary ? 1024 : 1000) ** exponent;
331
+ if (!localeOptions) {
332
+ number = number.toPrecision(3);
333
+ }
334
+ const numberString = toLocaleString(Number(number), options.locale, localeOptions);
335
+ const unit = UNITS[exponent];
336
+ return prefix + numberString + separator + unit;
337
+ }
338
+
236
339
  function maximumSizeTransform(maximumFileSizeToCacheInBytes) {
237
340
  return (originalManifest)=>{
238
341
  const warnings = [];
@@ -0,0 +1,9 @@
1
+ import { getManifest } from "./get-manifest.js";
2
+ import { injectManifest } from "./inject-manifest.js";
3
+ import { escapeRegExp } from "./lib/escape-regexp.js";
4
+ import { getSourceMapURL } from "./lib/get-source-map-url.js";
5
+ import { replaceAndUpdateSourceMap } from "./lib/replace-and-update-source-map.js";
6
+ import { transformManifest } from "./lib/transform-manifest.js";
7
+ import { validateWebpackInjectManifestOptions } from "./lib/validate-options.js";
8
+ export { escapeRegExp, getManifest, getSourceMapURL, injectManifest, replaceAndUpdateSourceMap, transformManifest, validateWebpackInjectManifestOptions, };
9
+ export * from "./types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/build",
3
- "version": "8.0.2",
3
+ "version": "8.0.4",
4
4
  "type": "module",
5
5
  "description": "A module that integrates into your build process, helping you generate a manifest of local files that should be precached.",
6
6
  "files": [
@@ -29,9 +29,14 @@
29
29
  "types": "./dist/index.d.ts",
30
30
  "exports": {
31
31
  ".": {
32
- "import": "./dist/index.js",
33
- "require": "./dist/index.old.cjs",
34
- "types": "./dist/index.d.ts"
32
+ "import": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "require": {
37
+ "types": "./dist/index.old.d.cts",
38
+ "default": "./dist/index.old.cjs"
39
+ }
35
40
  },
36
41
  "./package.json": "./package.json"
37
42
  },
@@ -40,32 +45,31 @@
40
45
  "ajv": "8.12.0",
41
46
  "common-tags": "1.8.2",
42
47
  "fast-json-stable-stringify": "2.1.0",
43
- "fs-extra": "11.1.1",
44
- "fsevents": "2.3.3",
48
+ "fs-extra": "11.2.0",
45
49
  "glob": "10.3.10",
46
- "pretty-bytes": "6.1.1",
47
50
  "rollup": "3.28.1",
48
51
  "source-map": "0.8.0-beta.0",
49
52
  "stringify-object": "5.0.0",
50
53
  "strip-comments": "2.0.1",
51
54
  "upath": "2.0.1",
52
- "@serwist/background-sync": "8.0.2",
53
- "@serwist/broadcast-update": "8.0.2",
54
- "@serwist/cacheable-response": "8.0.2",
55
- "@serwist/core": "8.0.2",
56
- "@serwist/expiration": "8.0.2",
57
- "@serwist/google-analytics": "8.0.2",
58
- "@serwist/precaching": "8.0.2",
59
- "@serwist/routing": "8.0.2"
55
+ "@serwist/background-sync": "8.0.4",
56
+ "@serwist/broadcast-update": "8.0.4",
57
+ "@serwist/cacheable-response": "8.0.4",
58
+ "@serwist/core": "8.0.4",
59
+ "@serwist/expiration": "8.0.4",
60
+ "@serwist/google-analytics": "8.0.4",
61
+ "@serwist/precaching": "8.0.4",
62
+ "@serwist/routing": "8.0.4"
60
63
  },
61
64
  "devDependencies": {
62
- "@types/common-tags": "1.8.3",
63
- "@types/fs-extra": "11.0.2",
64
- "@types/node": "20.8.7",
65
- "@types/stringify-object": "4.0.3",
66
- "@types/strip-comments": "2.0.3",
67
- "type-fest": "4.4.0",
68
- "@serwist/constants": "8.0.2"
65
+ "@types/common-tags": "1.8.4",
66
+ "@types/fs-extra": "11.0.4",
67
+ "@types/node": "20.10.4",
68
+ "@types/stringify-object": "4.0.5",
69
+ "@types/strip-comments": "2.0.4",
70
+ "pretty-bytes": "6.1.1",
71
+ "type-fest": "4.8.3",
72
+ "@serwist/constants": "8.0.4"
69
73
  },
70
74
  "scripts": {
71
75
  "build": "rimraf dist && cross-env NODE_OPTIONS='--max-old-space-size=4096' NODE_ENV=production rollup --config rollup.config.js",