@serwist/build 8.2.0 → 8.4.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.
package/README.md CHANGED
@@ -1 +1 @@
1
- This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-build
1
+ This module's documentation can be found at https://serwist.pages.dev/docs/build
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var stringify = require('fast-json-stable-stringify');
3
4
  var assert = require('assert');
4
5
  var commonTags = require('common-tags');
5
6
  var crypto = require('crypto');
@@ -8,8 +9,9 @@ var upath = require('upath');
8
9
  var fse = require('fs-extra');
9
10
  var betterAjvErrors = require('@apideck/better-ajv-errors');
10
11
  var Ajv = require('ajv');
11
- var stringify = require('fast-json-stable-stringify');
12
12
  var sourceMap = require('source-map');
13
+ var objectStringify = require('stringify-object');
14
+ var stripComments = require('strip-comments');
13
15
 
14
16
  const errors = {
15
17
  "unable-to-get-rootdir": `Unable to get the root directory of your web app.`,
@@ -488,6 +490,14 @@ async function transformManifest({ additionalPrecacheEntries, dontCacheBustURLsM
488
490
  }
489
491
 
490
492
  async function getFileManifestEntries({ additionalPrecacheEntries, dontCacheBustURLsMatching, globDirectory, globFollow, globIgnores, globPatterns = [], globStrict, manifestTransforms, maximumFileSizeToCacheInBytes, modifyURLPrefix, templatedURLs, disablePrecacheManifest }) {
493
+ if (disablePrecacheManifest) {
494
+ return {
495
+ count: 0,
496
+ size: 0,
497
+ manifestEntries: undefined,
498
+ warnings: []
499
+ };
500
+ }
491
501
  const warnings = [];
492
502
  const allFileDetails = new Map();
493
503
  try {
@@ -561,6 +571,177 @@ async function getFileManifestEntries({ additionalPrecacheEntries, dontCacheBust
561
571
  return transformedManifest;
562
572
  }
563
573
 
574
+ var additionalProperties$3 = false;
575
+ var type$3 = "object";
576
+ var properties$3 = {
577
+ additionalPrecacheEntries: {
578
+ description: "A list of entries to be precached, in addition to any entries that are\ngenerated as part of the build configuration.",
579
+ type: "array",
580
+ items: {
581
+ anyOf: [
582
+ {
583
+ $ref: "#/definitions/ManifestEntry"
584
+ },
585
+ {
586
+ type: "string"
587
+ }
588
+ ]
589
+ }
590
+ },
591
+ dontCacheBustURLsMatching: {
592
+ description: "Assets that match this will be assumed to be uniquely versioned via their\nURL, and exempted from the normal HTTP cache-busting that's done when\npopulating the precache. While not required, it's recommended that if your\nexisting build process already inserts a `[hash]` value into each filename,\nyou provide a RegExp that will detect that, as it will reduce the bandwidth\nconsumed when precaching.",
593
+ $ref: "#/definitions/RegExp"
594
+ },
595
+ manifestTransforms: {
596
+ description: "One or more functions which will be applied sequentially against the\ngenerated manifest. If `modifyURLPrefix` or `dontCacheBustURLsMatching` are\nalso specified, their corresponding transformations will be applied first.",
597
+ type: "array",
598
+ items: {}
599
+ },
600
+ maximumFileSizeToCacheInBytes: {
601
+ description: "This value can be used to determine the maximum size of files that will be\nprecached. This prevents you from inadvertently precaching very large files\nthat might have accidentally matched one of your patterns.",
602
+ "default": 2097152,
603
+ type: "number"
604
+ },
605
+ modifyURLPrefix: {
606
+ description: "An object mapping string prefixes to replacement string values. This can be\nused to, e.g., remove or add a path prefix from a manifest entry if your\nweb hosting setup doesn't match your local filesystem setup. As an\nalternative with more flexibility, you can use the `manifestTransforms`\noption and provide a function that modifies the entries in the manifest\nusing whatever logic you provide.\n\nExample usage:\n\n```\n// Replace a '/dist/' prefix with '/', and also prepend\n// '/static' to every URL.\nmodifyURLPrefix: {\n '/dist/': '/',\n '': '/static',\n}\n```",
607
+ type: "object",
608
+ additionalProperties: {
609
+ type: "string"
610
+ }
611
+ },
612
+ globFollow: {
613
+ description: "Determines whether or not symlinks are followed when generating the\nprecache manifest. For more information, see the definition of `follow` in\nthe `glob` [documentation](https://github.com/isaacs/node-glob#options).",
614
+ "default": true,
615
+ type: "boolean"
616
+ },
617
+ globIgnores: {
618
+ description: "A set of patterns matching files to always exclude when generating the\nprecache manifest. For more information, see the definition of `ignore` in\nthe `glob` [documentation](https://github.com/isaacs/node-glob#options).",
619
+ "default": [
620
+ "**/node_modules/**/*"
621
+ ],
622
+ type: "array",
623
+ items: {
624
+ type: "string"
625
+ }
626
+ },
627
+ globPatterns: {
628
+ description: "Files matching any of these patterns will be included in the precache\nmanifest. For more information, see the\n[`glob` primer](https://github.com/isaacs/node-glob#glob-primer).",
629
+ "default": [
630
+ "**/*.{js,css,html}"
631
+ ],
632
+ type: "array",
633
+ items: {
634
+ type: "string"
635
+ }
636
+ },
637
+ globStrict: {
638
+ description: "If true, an error reading a directory when generating a precache manifest\nwill cause the build to fail. If false, the problematic directory will be\nskipped. For more information, see the definition of `strict` in the `glob`\n[documentation](https://github.com/isaacs/node-glob#options).",
639
+ "default": true,
640
+ type: "boolean"
641
+ },
642
+ templatedURLs: {
643
+ description: "If a URL is rendered based on some server-side logic, its contents may\ndepend on multiple files or on some other unique string value. The keys in\nthis object are server-rendered URLs. If the values are an array of\nstrings, they will be interpreted as `glob` patterns, and the contents of\nany files matching the patterns will be used to uniquely version the URL.\nIf used with a single string, it will be interpreted as unique versioning\ninformation that you've generated for a given URL.",
644
+ type: "object",
645
+ additionalProperties: {
646
+ anyOf: [
647
+ {
648
+ type: "array",
649
+ items: {
650
+ type: "string"
651
+ }
652
+ },
653
+ {
654
+ type: "string"
655
+ }
656
+ ]
657
+ }
658
+ },
659
+ globDirectory: {
660
+ description: "The local directory you wish to match `globPatterns` against. The path is\nrelative to the current directory.",
661
+ type: "string"
662
+ }
663
+ };
664
+ var required$3 = [
665
+ "globDirectory"
666
+ ];
667
+ var definitions$3 = {
668
+ ManifestEntry: {
669
+ type: "object",
670
+ properties: {
671
+ integrity: {
672
+ type: "string"
673
+ },
674
+ revision: {
675
+ type: [
676
+ "null",
677
+ "string"
678
+ ]
679
+ },
680
+ url: {
681
+ type: "string"
682
+ }
683
+ },
684
+ additionalProperties: false,
685
+ required: [
686
+ "revision",
687
+ "url"
688
+ ]
689
+ },
690
+ "RegExp": {
691
+ type: "object",
692
+ properties: {
693
+ source: {
694
+ type: "string"
695
+ },
696
+ global: {
697
+ type: "boolean"
698
+ },
699
+ ignoreCase: {
700
+ type: "boolean"
701
+ },
702
+ multiline: {
703
+ type: "boolean"
704
+ },
705
+ lastIndex: {
706
+ type: "number"
707
+ },
708
+ flags: {
709
+ type: "string"
710
+ },
711
+ sticky: {
712
+ type: "boolean"
713
+ },
714
+ unicode: {
715
+ type: "boolean"
716
+ },
717
+ dotAll: {
718
+ type: "boolean"
719
+ }
720
+ },
721
+ additionalProperties: false,
722
+ required: [
723
+ "dotAll",
724
+ "flags",
725
+ "global",
726
+ "ignoreCase",
727
+ "lastIndex",
728
+ "multiline",
729
+ "source",
730
+ "sticky",
731
+ "unicode"
732
+ ]
733
+ }
734
+ };
735
+ var $schema$3 = "http://json-schema.org/draft-07/schema#";
736
+ var getManifestOptionsSchema = {
737
+ additionalProperties: additionalProperties$3,
738
+ type: type$3,
739
+ properties: properties$3,
740
+ required: required$3,
741
+ definitions: definitions$3,
742
+ $schema: $schema$3
743
+ };
744
+
564
745
  var additionalProperties$2 = false;
565
746
  var type$2 = "object";
566
747
  var properties$2 = {
@@ -646,13 +827,33 @@ var properties$2 = {
646
827
  ]
647
828
  }
648
829
  },
830
+ injectionPoint: {
831
+ description: "The string to find inside of the `swSrc` file. Once found, it will be\nreplaced by the generated precache manifest.",
832
+ "default": "self.__SW_MANIFEST",
833
+ type: "string"
834
+ },
835
+ swSrc: {
836
+ description: "The path and filename of the service worker file that will be read during\nthe build process, relative to the current working directory.",
837
+ type: "string"
838
+ },
839
+ swDest: {
840
+ description: "The path and filename of the service worker file that will be created by\nthe build process, relative to the current working directory. It must end\nin '.js'.",
841
+ type: "string"
842
+ },
649
843
  globDirectory: {
650
844
  description: "The local directory you wish to match `globPatterns` against. The path is\nrelative to the current directory.",
651
845
  type: "string"
846
+ },
847
+ disablePrecacheManifest: {
848
+ description: "Whether the precache manifest should be set to `undefined`.",
849
+ "default": false,
850
+ type: "boolean"
652
851
  }
653
852
  };
654
853
  var required$2 = [
655
- "globDirectory"
854
+ "globDirectory",
855
+ "swDest",
856
+ "swSrc"
656
857
  ];
657
858
  var definitions$2 = {
658
859
  ManifestEntry: {
@@ -723,7 +924,7 @@ var definitions$2 = {
723
924
  }
724
925
  };
725
926
  var $schema$2 = "http://json-schema.org/draft-07/schema#";
726
- var getManifestOptionsSchema = {
927
+ var injectManifestOptionsSchema = {
727
928
  additionalProperties: additionalProperties$2,
728
929
  type: type$2,
729
930
  properties: properties$2,
@@ -914,7 +1115,7 @@ var definitions$1 = {
914
1115
  }
915
1116
  };
916
1117
  var $schema$1 = "http://json-schema.org/draft-07/schema#";
917
- var injectManifestOptionsSchema = {
1118
+ var viteInjectManifestOptionsSchema = {
918
1119
  additionalProperties: additionalProperties$1,
919
1120
  type: type$1,
920
1121
  properties: properties$1,
@@ -1105,7 +1306,8 @@ var webpackInjectManifestOptionsSchema = {
1105
1306
  const optionsSchemas = {
1106
1307
  GetManifest: getManifestOptionsSchema,
1107
1308
  InjectManifest: injectManifestOptionsSchema,
1108
- WebpackInjectManifest: webpackInjectManifestOptionsSchema
1309
+ WebpackInjectManifest: webpackInjectManifestOptionsSchema,
1310
+ ViteInjectManifest: viteInjectManifestOptionsSchema
1109
1311
  };
1110
1312
 
1111
1313
  const ajv = new Ajv({
@@ -1169,6 +1371,10 @@ function validateWebpackInjectManifestOptions(input) {
1169
1371
  const [validatedOptions] = validate(inputWithExcludeDefault, "WebpackInjectManifest");
1170
1372
  return validatedOptions;
1171
1373
  }
1374
+ const validateViteInjectManifestOptions = (input)=>{
1375
+ const [validatedOptions] = validate(input, "ViteInjectManifest");
1376
+ return validatedOptions;
1377
+ };
1172
1378
 
1173
1379
  /**
1174
1380
  * This method returns a list of URLs to precache, referred to as a "precache
@@ -1362,7 +1568,7 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
1362
1568
  throw new Error(`${errors["injection-point-not-found"]} ${injectionPoint}`);
1363
1569
  }
1364
1570
  assert(injectionResults.length === 1, `${errors["multiple-injection-points"]} ${injectionPoint}`);
1365
- const manifestString = stringify(manifestEntries);
1571
+ const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
1366
1572
  const filesToWrite = {};
1367
1573
  const url = getSourceMapURL(swFileContents);
1368
1574
  // See https://github.com/GoogleChrome/workbox/issues/2957
@@ -1411,10 +1617,31 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
1411
1617
  };
1412
1618
  }
1413
1619
 
1620
+ function stringifyWithoutComments(obj) {
1621
+ return objectStringify(obj, {
1622
+ // See https://github.com/yeoman/stringify-object#transformobject-property-originalresult
1623
+ transform: (_obj, _prop, str)=>{
1624
+ if (typeof _prop !== "symbol" && typeof _obj[_prop] === "function") {
1625
+ // Can't typify correctly stripComments
1626
+ return stripComments(str); // eslint-disable-line
1627
+ }
1628
+ return str;
1629
+ }
1630
+ });
1631
+ }
1632
+
1633
+ exports.stringify = stringify;
1634
+ exports.errors = errors;
1414
1635
  exports.escapeRegExp = escapeRegExp;
1636
+ exports.getFileManifestEntries = getFileManifestEntries;
1415
1637
  exports.getManifest = getManifest;
1416
1638
  exports.getSourceMapURL = getSourceMapURL;
1417
1639
  exports.injectManifest = injectManifest;
1640
+ exports.rebasePath = rebasePath;
1418
1641
  exports.replaceAndUpdateSourceMap = replaceAndUpdateSourceMap;
1642
+ exports.stringifyWithoutComments = stringifyWithoutComments;
1419
1643
  exports.transformManifest = transformManifest;
1644
+ exports.translateURLToSourcemapPaths = translateURLToSourcemapPaths;
1645
+ exports.validateInjectManifestOptions = validateInjectManifestOptions;
1646
+ exports.validateViteInjectManifestOptions = validateViteInjectManifestOptions;
1420
1647
  exports.validateWebpackInjectManifestOptions = validateWebpackInjectManifestOptions;
package/dist/index.d.cts CHANGED
@@ -1,9 +1,15 @@
1
+ import stringify from "fast-json-stable-stringify";
1
2
  import { getManifest } from "./get-manifest.js";
2
3
  import { injectManifest } from "./inject-manifest.js";
4
+ import { errors } from "./lib/errors.js";
3
5
  import { escapeRegExp } from "./lib/escape-regexp.js";
6
+ import { getFileManifestEntries } from "./lib/get-file-manifest-entries.js";
4
7
  import { getSourceMapURL } from "./lib/get-source-map-url.js";
8
+ import { rebasePath } from "./lib/rebase-path.js";
5
9
  import { replaceAndUpdateSourceMap } from "./lib/replace-and-update-source-map.js";
10
+ import { stringifyWithoutComments } from "./lib/stringify-without-comments.js";
6
11
  import { transformManifest } from "./lib/transform-manifest.js";
7
- import { validateWebpackInjectManifestOptions } from "./lib/validate-options.js";
8
- export { escapeRegExp, getManifest, getSourceMapURL, injectManifest, replaceAndUpdateSourceMap, transformManifest, validateWebpackInjectManifestOptions, };
12
+ import { translateURLToSourcemapPaths } from "./lib/translate-url-to-sourcemap-paths.js";
13
+ import { validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions } from "./lib/validate-options.js";
14
+ export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, stringify, stringifyWithoutComments, transformManifest, translateURLToSourcemapPaths, validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions, };
9
15
  export * from "./types.js";
package/dist/index.d.ts CHANGED
@@ -1,9 +1,15 @@
1
+ import stringify from "fast-json-stable-stringify";
1
2
  import { getManifest } from "./get-manifest.js";
2
3
  import { injectManifest } from "./inject-manifest.js";
4
+ import { errors } from "./lib/errors.js";
3
5
  import { escapeRegExp } from "./lib/escape-regexp.js";
6
+ import { getFileManifestEntries } from "./lib/get-file-manifest-entries.js";
4
7
  import { getSourceMapURL } from "./lib/get-source-map-url.js";
8
+ import { rebasePath } from "./lib/rebase-path.js";
5
9
  import { replaceAndUpdateSourceMap } from "./lib/replace-and-update-source-map.js";
10
+ import { stringifyWithoutComments } from "./lib/stringify-without-comments.js";
6
11
  import { transformManifest } from "./lib/transform-manifest.js";
7
- import { validateWebpackInjectManifestOptions } from "./lib/validate-options.js";
8
- export { escapeRegExp, getManifest, getSourceMapURL, injectManifest, replaceAndUpdateSourceMap, transformManifest, validateWebpackInjectManifestOptions, };
12
+ import { translateURLToSourcemapPaths } from "./lib/translate-url-to-sourcemap-paths.js";
13
+ import { validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions } from "./lib/validate-options.js";
14
+ export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, stringify, stringifyWithoutComments, transformManifest, translateURLToSourcemapPaths, validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions, };
9
15
  export * from "./types.js";
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ import stringify from 'fast-json-stable-stringify';
2
+ export { default as stringify } from 'fast-json-stable-stringify';
1
3
  import assert from 'assert';
2
4
  import { oneLine } from 'common-tags';
3
5
  import crypto from 'crypto';
@@ -6,8 +8,9 @@ import upath from 'upath';
6
8
  import fse from 'fs-extra';
7
9
  import { betterAjvErrors } from '@apideck/better-ajv-errors';
8
10
  import Ajv from 'ajv';
9
- import stringify from 'fast-json-stable-stringify';
10
11
  import { SourceMapGenerator, SourceMapConsumer } from 'source-map';
12
+ import objectStringify from 'stringify-object';
13
+ import stripComments from 'strip-comments';
11
14
 
12
15
  const errors = {
13
16
  "unable-to-get-rootdir": `Unable to get the root directory of your web app.`,
@@ -486,6 +489,14 @@ async function transformManifest({ additionalPrecacheEntries, dontCacheBustURLsM
486
489
  }
487
490
 
488
491
  async function getFileManifestEntries({ additionalPrecacheEntries, dontCacheBustURLsMatching, globDirectory, globFollow, globIgnores, globPatterns = [], globStrict, manifestTransforms, maximumFileSizeToCacheInBytes, modifyURLPrefix, templatedURLs, disablePrecacheManifest }) {
492
+ if (disablePrecacheManifest) {
493
+ return {
494
+ count: 0,
495
+ size: 0,
496
+ manifestEntries: undefined,
497
+ warnings: []
498
+ };
499
+ }
489
500
  const warnings = [];
490
501
  const allFileDetails = new Map();
491
502
  try {
@@ -559,6 +570,177 @@ async function getFileManifestEntries({ additionalPrecacheEntries, dontCacheBust
559
570
  return transformedManifest;
560
571
  }
561
572
 
573
+ var additionalProperties$3 = false;
574
+ var type$3 = "object";
575
+ var properties$3 = {
576
+ additionalPrecacheEntries: {
577
+ description: "A list of entries to be precached, in addition to any entries that are\ngenerated as part of the build configuration.",
578
+ type: "array",
579
+ items: {
580
+ anyOf: [
581
+ {
582
+ $ref: "#/definitions/ManifestEntry"
583
+ },
584
+ {
585
+ type: "string"
586
+ }
587
+ ]
588
+ }
589
+ },
590
+ dontCacheBustURLsMatching: {
591
+ description: "Assets that match this will be assumed to be uniquely versioned via their\nURL, and exempted from the normal HTTP cache-busting that's done when\npopulating the precache. While not required, it's recommended that if your\nexisting build process already inserts a `[hash]` value into each filename,\nyou provide a RegExp that will detect that, as it will reduce the bandwidth\nconsumed when precaching.",
592
+ $ref: "#/definitions/RegExp"
593
+ },
594
+ manifestTransforms: {
595
+ description: "One or more functions which will be applied sequentially against the\ngenerated manifest. If `modifyURLPrefix` or `dontCacheBustURLsMatching` are\nalso specified, their corresponding transformations will be applied first.",
596
+ type: "array",
597
+ items: {}
598
+ },
599
+ maximumFileSizeToCacheInBytes: {
600
+ description: "This value can be used to determine the maximum size of files that will be\nprecached. This prevents you from inadvertently precaching very large files\nthat might have accidentally matched one of your patterns.",
601
+ "default": 2097152,
602
+ type: "number"
603
+ },
604
+ modifyURLPrefix: {
605
+ description: "An object mapping string prefixes to replacement string values. This can be\nused to, e.g., remove or add a path prefix from a manifest entry if your\nweb hosting setup doesn't match your local filesystem setup. As an\nalternative with more flexibility, you can use the `manifestTransforms`\noption and provide a function that modifies the entries in the manifest\nusing whatever logic you provide.\n\nExample usage:\n\n```\n// Replace a '/dist/' prefix with '/', and also prepend\n// '/static' to every URL.\nmodifyURLPrefix: {\n '/dist/': '/',\n '': '/static',\n}\n```",
606
+ type: "object",
607
+ additionalProperties: {
608
+ type: "string"
609
+ }
610
+ },
611
+ globFollow: {
612
+ description: "Determines whether or not symlinks are followed when generating the\nprecache manifest. For more information, see the definition of `follow` in\nthe `glob` [documentation](https://github.com/isaacs/node-glob#options).",
613
+ "default": true,
614
+ type: "boolean"
615
+ },
616
+ globIgnores: {
617
+ description: "A set of patterns matching files to always exclude when generating the\nprecache manifest. For more information, see the definition of `ignore` in\nthe `glob` [documentation](https://github.com/isaacs/node-glob#options).",
618
+ "default": [
619
+ "**/node_modules/**/*"
620
+ ],
621
+ type: "array",
622
+ items: {
623
+ type: "string"
624
+ }
625
+ },
626
+ globPatterns: {
627
+ description: "Files matching any of these patterns will be included in the precache\nmanifest. For more information, see the\n[`glob` primer](https://github.com/isaacs/node-glob#glob-primer).",
628
+ "default": [
629
+ "**/*.{js,css,html}"
630
+ ],
631
+ type: "array",
632
+ items: {
633
+ type: "string"
634
+ }
635
+ },
636
+ globStrict: {
637
+ description: "If true, an error reading a directory when generating a precache manifest\nwill cause the build to fail. If false, the problematic directory will be\nskipped. For more information, see the definition of `strict` in the `glob`\n[documentation](https://github.com/isaacs/node-glob#options).",
638
+ "default": true,
639
+ type: "boolean"
640
+ },
641
+ templatedURLs: {
642
+ description: "If a URL is rendered based on some server-side logic, its contents may\ndepend on multiple files or on some other unique string value. The keys in\nthis object are server-rendered URLs. If the values are an array of\nstrings, they will be interpreted as `glob` patterns, and the contents of\nany files matching the patterns will be used to uniquely version the URL.\nIf used with a single string, it will be interpreted as unique versioning\ninformation that you've generated for a given URL.",
643
+ type: "object",
644
+ additionalProperties: {
645
+ anyOf: [
646
+ {
647
+ type: "array",
648
+ items: {
649
+ type: "string"
650
+ }
651
+ },
652
+ {
653
+ type: "string"
654
+ }
655
+ ]
656
+ }
657
+ },
658
+ globDirectory: {
659
+ description: "The local directory you wish to match `globPatterns` against. The path is\nrelative to the current directory.",
660
+ type: "string"
661
+ }
662
+ };
663
+ var required$3 = [
664
+ "globDirectory"
665
+ ];
666
+ var definitions$3 = {
667
+ ManifestEntry: {
668
+ type: "object",
669
+ properties: {
670
+ integrity: {
671
+ type: "string"
672
+ },
673
+ revision: {
674
+ type: [
675
+ "null",
676
+ "string"
677
+ ]
678
+ },
679
+ url: {
680
+ type: "string"
681
+ }
682
+ },
683
+ additionalProperties: false,
684
+ required: [
685
+ "revision",
686
+ "url"
687
+ ]
688
+ },
689
+ "RegExp": {
690
+ type: "object",
691
+ properties: {
692
+ source: {
693
+ type: "string"
694
+ },
695
+ global: {
696
+ type: "boolean"
697
+ },
698
+ ignoreCase: {
699
+ type: "boolean"
700
+ },
701
+ multiline: {
702
+ type: "boolean"
703
+ },
704
+ lastIndex: {
705
+ type: "number"
706
+ },
707
+ flags: {
708
+ type: "string"
709
+ },
710
+ sticky: {
711
+ type: "boolean"
712
+ },
713
+ unicode: {
714
+ type: "boolean"
715
+ },
716
+ dotAll: {
717
+ type: "boolean"
718
+ }
719
+ },
720
+ additionalProperties: false,
721
+ required: [
722
+ "dotAll",
723
+ "flags",
724
+ "global",
725
+ "ignoreCase",
726
+ "lastIndex",
727
+ "multiline",
728
+ "source",
729
+ "sticky",
730
+ "unicode"
731
+ ]
732
+ }
733
+ };
734
+ var $schema$3 = "http://json-schema.org/draft-07/schema#";
735
+ var getManifestOptionsSchema = {
736
+ additionalProperties: additionalProperties$3,
737
+ type: type$3,
738
+ properties: properties$3,
739
+ required: required$3,
740
+ definitions: definitions$3,
741
+ $schema: $schema$3
742
+ };
743
+
562
744
  var additionalProperties$2 = false;
563
745
  var type$2 = "object";
564
746
  var properties$2 = {
@@ -644,13 +826,33 @@ var properties$2 = {
644
826
  ]
645
827
  }
646
828
  },
829
+ injectionPoint: {
830
+ description: "The string to find inside of the `swSrc` file. Once found, it will be\nreplaced by the generated precache manifest.",
831
+ "default": "self.__SW_MANIFEST",
832
+ type: "string"
833
+ },
834
+ swSrc: {
835
+ description: "The path and filename of the service worker file that will be read during\nthe build process, relative to the current working directory.",
836
+ type: "string"
837
+ },
838
+ swDest: {
839
+ description: "The path and filename of the service worker file that will be created by\nthe build process, relative to the current working directory. It must end\nin '.js'.",
840
+ type: "string"
841
+ },
647
842
  globDirectory: {
648
843
  description: "The local directory you wish to match `globPatterns` against. The path is\nrelative to the current directory.",
649
844
  type: "string"
845
+ },
846
+ disablePrecacheManifest: {
847
+ description: "Whether the precache manifest should be set to `undefined`.",
848
+ "default": false,
849
+ type: "boolean"
650
850
  }
651
851
  };
652
852
  var required$2 = [
653
- "globDirectory"
853
+ "globDirectory",
854
+ "swDest",
855
+ "swSrc"
654
856
  ];
655
857
  var definitions$2 = {
656
858
  ManifestEntry: {
@@ -721,7 +923,7 @@ var definitions$2 = {
721
923
  }
722
924
  };
723
925
  var $schema$2 = "http://json-schema.org/draft-07/schema#";
724
- var getManifestOptionsSchema = {
926
+ var injectManifestOptionsSchema = {
725
927
  additionalProperties: additionalProperties$2,
726
928
  type: type$2,
727
929
  properties: properties$2,
@@ -912,7 +1114,7 @@ var definitions$1 = {
912
1114
  }
913
1115
  };
914
1116
  var $schema$1 = "http://json-schema.org/draft-07/schema#";
915
- var injectManifestOptionsSchema = {
1117
+ var viteInjectManifestOptionsSchema = {
916
1118
  additionalProperties: additionalProperties$1,
917
1119
  type: type$1,
918
1120
  properties: properties$1,
@@ -1103,7 +1305,8 @@ var webpackInjectManifestOptionsSchema = {
1103
1305
  const optionsSchemas = {
1104
1306
  GetManifest: getManifestOptionsSchema,
1105
1307
  InjectManifest: injectManifestOptionsSchema,
1106
- WebpackInjectManifest: webpackInjectManifestOptionsSchema
1308
+ WebpackInjectManifest: webpackInjectManifestOptionsSchema,
1309
+ ViteInjectManifest: viteInjectManifestOptionsSchema
1107
1310
  };
1108
1311
 
1109
1312
  const ajv = new Ajv({
@@ -1167,6 +1370,10 @@ function validateWebpackInjectManifestOptions(input) {
1167
1370
  const [validatedOptions] = validate(inputWithExcludeDefault, "WebpackInjectManifest");
1168
1371
  return validatedOptions;
1169
1372
  }
1373
+ const validateViteInjectManifestOptions = (input)=>{
1374
+ const [validatedOptions] = validate(input, "ViteInjectManifest");
1375
+ return validatedOptions;
1376
+ };
1170
1377
 
1171
1378
  /**
1172
1379
  * This method returns a list of URLs to precache, referred to as a "precache
@@ -1360,7 +1567,7 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
1360
1567
  throw new Error(`${errors["injection-point-not-found"]} ${injectionPoint}`);
1361
1568
  }
1362
1569
  assert(injectionResults.length === 1, `${errors["multiple-injection-points"]} ${injectionPoint}`);
1363
- const manifestString = stringify(manifestEntries);
1570
+ const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
1364
1571
  const filesToWrite = {};
1365
1572
  const url = getSourceMapURL(swFileContents);
1366
1573
  // See https://github.com/GoogleChrome/workbox/issues/2957
@@ -1409,4 +1616,17 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
1409
1616
  };
1410
1617
  }
1411
1618
 
1412
- export { escapeRegExp, getManifest, getSourceMapURL, injectManifest, replaceAndUpdateSourceMap, transformManifest, validateWebpackInjectManifestOptions };
1619
+ function stringifyWithoutComments(obj) {
1620
+ return objectStringify(obj, {
1621
+ // See https://github.com/yeoman/stringify-object#transformobject-property-originalresult
1622
+ transform: (_obj, _prop, str)=>{
1623
+ if (typeof _prop !== "symbol" && typeof _obj[_prop] === "function") {
1624
+ // Can't typify correctly stripComments
1625
+ return stripComments(str); // eslint-disable-line
1626
+ }
1627
+ return str;
1628
+ }
1629
+ });
1630
+ }
1631
+
1632
+ export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, stringifyWithoutComments, transformManifest, translateURLToSourcemapPaths, validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions };
@@ -1,7 +1,8 @@
1
- import type { GetManifestOptions, InjectManifestOptions, WebpackInjectManifestOptions } from "../types.js";
1
+ import type { GetManifestOptions, InjectManifestOptions, ViteInjectManifestOptions, WebpackInjectManifestOptions } from "../types.js";
2
2
  export declare class SerwistConfigError extends Error {
3
3
  constructor(message?: string);
4
4
  }
5
5
  export declare function validateGetManifestOptions(input: unknown): GetManifestOptions;
6
6
  export declare function validateInjectManifestOptions(input: unknown): InjectManifestOptions;
7
7
  export declare function validateWebpackInjectManifestOptions(input: unknown): WebpackInjectManifestOptions;
8
+ export declare const validateViteInjectManifestOptions: (input: unknown) => ViteInjectManifestOptions;
@@ -445,4 +445,161 @@ export declare const optionsSchemas: {
445
445
  };
446
446
  $schema: string;
447
447
  };
448
+ ViteInjectManifest: {
449
+ additionalProperties: boolean;
450
+ type: string;
451
+ properties: {
452
+ additionalPrecacheEntries: {
453
+ description: string;
454
+ type: string;
455
+ items: {
456
+ anyOf: ({
457
+ $ref: string;
458
+ type?: undefined;
459
+ } | {
460
+ type: string;
461
+ $ref?: undefined;
462
+ })[];
463
+ };
464
+ };
465
+ dontCacheBustURLsMatching: {
466
+ description: string;
467
+ $ref: string;
468
+ };
469
+ manifestTransforms: {
470
+ description: string;
471
+ type: string;
472
+ items: {};
473
+ };
474
+ maximumFileSizeToCacheInBytes: {
475
+ description: string;
476
+ default: number;
477
+ type: string;
478
+ };
479
+ modifyURLPrefix: {
480
+ description: string;
481
+ type: string;
482
+ additionalProperties: {
483
+ type: string;
484
+ };
485
+ };
486
+ globFollow: {
487
+ description: string;
488
+ default: boolean;
489
+ type: string;
490
+ };
491
+ globIgnores: {
492
+ description: string;
493
+ default: string[];
494
+ type: string;
495
+ items: {
496
+ type: string;
497
+ };
498
+ };
499
+ globPatterns: {
500
+ description: string;
501
+ default: string[];
502
+ type: string;
503
+ items: {
504
+ type: string;
505
+ };
506
+ };
507
+ globStrict: {
508
+ description: string;
509
+ default: boolean;
510
+ type: string;
511
+ };
512
+ templatedURLs: {
513
+ description: string;
514
+ type: string;
515
+ additionalProperties: {
516
+ anyOf: ({
517
+ type: string;
518
+ items: {
519
+ type: string;
520
+ };
521
+ } | {
522
+ type: string;
523
+ items?: undefined;
524
+ })[];
525
+ };
526
+ };
527
+ injectionPoint: {
528
+ description: string;
529
+ default: string;
530
+ type: string;
531
+ };
532
+ swSrc: {
533
+ description: string;
534
+ type: string;
535
+ };
536
+ swDest: {
537
+ description: string;
538
+ type: string;
539
+ };
540
+ globDirectory: {
541
+ description: string;
542
+ type: string;
543
+ };
544
+ disablePrecacheManifest: {
545
+ description: string;
546
+ default: boolean;
547
+ type: string;
548
+ };
549
+ };
550
+ required: string[];
551
+ definitions: {
552
+ ManifestEntry: {
553
+ type: string;
554
+ properties: {
555
+ integrity: {
556
+ type: string;
557
+ };
558
+ revision: {
559
+ type: string[];
560
+ };
561
+ url: {
562
+ type: string;
563
+ };
564
+ };
565
+ additionalProperties: boolean;
566
+ required: string[];
567
+ };
568
+ RegExp: {
569
+ type: string;
570
+ properties: {
571
+ source: {
572
+ type: string;
573
+ };
574
+ global: {
575
+ type: string;
576
+ };
577
+ ignoreCase: {
578
+ type: string;
579
+ };
580
+ multiline: {
581
+ type: string;
582
+ };
583
+ lastIndex: {
584
+ type: string;
585
+ };
586
+ flags: {
587
+ type: string;
588
+ };
589
+ sticky: {
590
+ type: string;
591
+ };
592
+ unicode: {
593
+ type: string;
594
+ };
595
+ dotAll: {
596
+ type: string;
597
+ };
598
+ };
599
+ additionalProperties: boolean;
600
+ required: string[];
601
+ };
602
+ };
603
+ $schema: string;
604
+ };
448
605
  };
package/dist/types.d.ts CHANGED
@@ -131,7 +131,8 @@ export interface BasePartial {
131
131
  */
132
132
  additionalPrecacheEntries?: Array<string | ManifestEntry>;
133
133
  /**
134
- * Whether the precache manifest should be set to `undefined`.
134
+ * Whether the precache manifest should be set to `undefined`. Essentially whether `@serwist/build` should
135
+ * be disabled. Mostly useful when you want it to only check if the provided options are valid.
135
136
  * @default false
136
137
  */
137
138
  disablePrecacheManifest?: boolean;
@@ -198,29 +199,35 @@ export interface GlobPartial {
198
199
  /**
199
200
  * Determines whether or not symlinks are followed when generating the
200
201
  * precache manifest. For more information, see the definition of `follow` in
201
- * the `glob` [documentation](https://github.com/isaacs/node-glob#options).
202
+ * [glob's documentation](https://github.com/isaacs/node-glob#options).
202
203
  * @default true
203
204
  */
204
205
  globFollow?: boolean;
205
206
  /**
206
207
  * A set of patterns matching files to always exclude when generating the
207
208
  * precache manifest. For more information, see the definition of `ignore` in
208
- * the `glob` [documentation](https://github.com/isaacs/node-glob#options).
209
- * @default ["**\/node_modules\/**\/*"]
209
+ * [glob's documentation](https://github.com/isaacs/node-glob#options).
210
+ * @default
211
+ * ```
212
+ * ["**\/node_modules\/**\/*"]
213
+ * ```
210
214
  */
211
215
  globIgnores?: Array<string>;
212
216
  /**
213
217
  * Files matching any of these patterns will be included in the precache
214
- * manifest. For more information, see the
215
- * [`glob` primer](https://github.com/isaacs/node-glob#glob-primer).
216
- * @default ["**\/*.{js,css,html}"]
218
+ * manifest. For more information, see
219
+ * [glob's Glob Primer](https://github.com/isaacs/node-glob#glob-primer).
220
+ * @default
221
+ * ```
222
+ * ["**\/*.{js,css,html}"]
223
+ * ```
217
224
  */
218
225
  globPatterns?: Array<string>;
219
226
  /**
220
227
  * If true, an error reading a directory when generating a precache manifest
221
228
  * will cause the build to fail. If false, the problematic directory will be
222
- * skipped. For more information, see the definition of `strict` in the `glob`
223
- * [documentation](https://github.com/isaacs/node-glob#options).
229
+ * skipped. For more information, see the definition of `strict` in
230
+ * [glob's documentation](https://github.com/isaacs/node-glob#options).
224
231
  * @default true
225
232
  */
226
233
  globStrict?: boolean;
@@ -316,6 +323,7 @@ export interface WebpackInjectManifestPartial {
316
323
  export type GetManifestOptions = BasePartial & GlobPartial & RequiredGlobDirectoryPartial;
317
324
  export type InjectManifestOptions = BasePartial & GlobPartial & InjectPartial & RequiredSWDestPartial & RequiredGlobDirectoryPartial;
318
325
  export type WebpackInjectManifestOptions = BasePartial & WebpackPartial & InjectPartial & WebpackInjectManifestPartial;
326
+ export type ViteInjectManifestOptions = BasePartial & GlobPartial & InjectPartial & RequiredSWDestPartial & RequiredGlobDirectoryPartial;
319
327
  export interface GetManifestResult {
320
328
  count: number;
321
329
  manifestEntries: Array<ManifestEntry> | undefined;
@@ -344,7 +352,7 @@ export type SerwistPackageJSON = PackageJson;
344
352
  /**
345
353
  * @private
346
354
  */
347
- export type MethodNames = "GetManifest" | "InjectManifest" | "WebpackInjectManifest";
355
+ export type MethodNames = "GetManifest" | "InjectManifest" | "WebpackInjectManifest" | "ViteInjectManifest";
348
356
  /**
349
357
  * @private
350
358
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/build",
3
- "version": "8.2.0",
3
+ "version": "8.4.0",
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": [
@@ -23,7 +23,7 @@
23
23
  "license": "MIT",
24
24
  "repository": "serwist/serwist",
25
25
  "bugs": "https://github.com/serwist/serwist/issues",
26
- "homepage": "https://serwist.vercel.app",
26
+ "homepage": "https://serwist.pages.dev",
27
27
  "module": "./dist/index.js",
28
28
  "main": "./dist/index.cjs",
29
29
  "types": "./dist/index.d.ts",
@@ -52,14 +52,14 @@
52
52
  "stringify-object": "5.0.0",
53
53
  "strip-comments": "2.0.1",
54
54
  "upath": "2.0.1",
55
- "@serwist/background-sync": "8.2.0",
56
- "@serwist/broadcast-update": "8.2.0",
57
- "@serwist/cacheable-response": "8.2.0",
58
- "@serwist/core": "8.2.0",
59
- "@serwist/expiration": "8.2.0",
60
- "@serwist/google-analytics": "8.2.0",
61
- "@serwist/precaching": "8.2.0",
62
- "@serwist/routing": "8.2.0"
55
+ "@serwist/background-sync": "8.4.0",
56
+ "@serwist/broadcast-update": "8.4.0",
57
+ "@serwist/cacheable-response": "8.4.0",
58
+ "@serwist/core": "8.4.0",
59
+ "@serwist/expiration": "8.4.0",
60
+ "@serwist/google-analytics": "8.4.0",
61
+ "@serwist/precaching": "8.4.0",
62
+ "@serwist/routing": "8.4.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/common-tags": "1.8.4",
@@ -69,10 +69,11 @@
69
69
  "@types/strip-comments": "2.0.4",
70
70
  "pretty-bytes": "6.1.1",
71
71
  "type-fest": "4.8.3",
72
- "@serwist/constants": "8.2.0"
72
+ "@serwist/constants": "8.4.0"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "rimraf dist && cross-env NODE_OPTIONS='--max-old-space-size=4096' NODE_ENV=production rollup --config rollup.config.js",
76
+ "dev": "rollup --config rollup.config.js --watch",
76
77
  "lint": "eslint src --ext ts,tsx,js,jsx,cjs,mjs",
77
78
  "typecheck": "tsc"
78
79
  }