@serwist/build 8.3.0 → 8.4.1
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 +1 -1
- package/dist/index.cjs +219 -16
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +215 -17
- package/dist/lib/validate-options.d.ts +2 -1
- package/dist/schema/index.d.ts +157 -0
- package/dist/types.d.ts +18 -10
- package/package.json +13 -15
- package/dist/lib/stringify-without-comments.d.ts +0 -3
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
This module's documentation can be found at https://
|
|
1
|
+
This module's documentation can be found at https://serwist.pages.dev/docs/build
|
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var stringify = require('fast-json-stable-stringify');
|
|
4
4
|
var assert = require('assert');
|
|
5
|
+
var commonTags = require('common-tags');
|
|
5
6
|
var crypto = require('crypto');
|
|
6
7
|
var glob = require('glob');
|
|
7
8
|
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
13
|
|
|
14
14
|
const errors = {
|
|
15
|
-
"unable-to-get-rootdir":
|
|
15
|
+
"unable-to-get-rootdir": "Unable to get the root directory of your web app.",
|
|
16
16
|
"no-extension": commonTags.oneLine`Unable to detect a usable extension for a file in your web
|
|
17
17
|
app directory.`,
|
|
18
18
|
"invalid-file-manifest-name": commonTags.oneLine`The File Manifest Name must have at least one
|
|
@@ -133,7 +133,7 @@ function getFileHash(file) {
|
|
|
133
133
|
const buffer = fse.readFileSync(file);
|
|
134
134
|
return getStringHash(buffer);
|
|
135
135
|
} catch (err) {
|
|
136
|
-
throw new Error(errors["unable-to-get-file-hash"]
|
|
136
|
+
throw new Error(`${errors["unable-to-get-file-hash"]} '${err instanceof Error && err.message ? err.message : ""}'`);
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
@@ -145,7 +145,7 @@ function getFileSize(file) {
|
|
|
145
145
|
}
|
|
146
146
|
return stat.size;
|
|
147
147
|
} catch (err) {
|
|
148
|
-
throw new Error(errors["unable-to-get-file-size"]
|
|
148
|
+
throw new Error(`${errors["unable-to-get-file-size"]} '${err instanceof Error && err.message ? err.message : ""}'`);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -159,14 +159,14 @@ function getFileDetails({ globDirectory, globFollow, globIgnores, globPattern })
|
|
|
159
159
|
ignore: globIgnores
|
|
160
160
|
});
|
|
161
161
|
} catch (err) {
|
|
162
|
-
throw new Error(errors["unable-to-glob-files"]
|
|
162
|
+
throw new Error(`${errors["unable-to-glob-files"]} '${err instanceof Error && err.message ? err.message : ""}'`);
|
|
163
163
|
}
|
|
164
164
|
if (globbedFiles.length === 0) {
|
|
165
|
-
warning = errors["useless-glob-pattern"]
|
|
165
|
+
warning = `${errors["useless-glob-pattern"]} ${JSON.stringify({
|
|
166
166
|
globDirectory,
|
|
167
167
|
globPattern,
|
|
168
168
|
globIgnores
|
|
169
|
-
}, null, 2)
|
|
169
|
+
}, null, 2)}`;
|
|
170
170
|
}
|
|
171
171
|
const globbedFileDetails = [];
|
|
172
172
|
for (const file of globbedFiles){
|
|
@@ -343,7 +343,7 @@ function maximumSizeTransform(maximumFileSizeToCacheInBytes) {
|
|
|
343
343
|
if (entry.size <= maximumFileSizeToCacheInBytes) {
|
|
344
344
|
return true;
|
|
345
345
|
}
|
|
346
|
-
warnings.push(`${entry.url} is ${prettyBytes(entry.size)}, and won't
|
|
346
|
+
warnings.push(`${entry.url} is ${prettyBytes(entry.size)}, and won't be precached. Configure maximumFileSizeToCacheInBytes to change this limit.`);
|
|
347
347
|
return false;
|
|
348
348
|
});
|
|
349
349
|
return {
|
|
@@ -477,6 +477,7 @@ async function transformManifest({ additionalPrecacheEntries, dontCacheBustURLsM
|
|
|
477
477
|
let size = 0;
|
|
478
478
|
for (const manifestEntry of transformedManifest){
|
|
479
479
|
size += manifestEntry.size || 0;
|
|
480
|
+
// biome-ignore lint/performance/noDelete: I don't understand this part yet.
|
|
480
481
|
delete manifestEntry.size;
|
|
481
482
|
}
|
|
482
483
|
return {
|
|
@@ -569,6 +570,177 @@ async function getFileManifestEntries({ additionalPrecacheEntries, dontCacheBust
|
|
|
569
570
|
return transformedManifest;
|
|
570
571
|
}
|
|
571
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
|
+
|
|
572
744
|
var additionalProperties$2 = false;
|
|
573
745
|
var type$2 = "object";
|
|
574
746
|
var properties$2 = {
|
|
@@ -654,13 +826,33 @@ var properties$2 = {
|
|
|
654
826
|
]
|
|
655
827
|
}
|
|
656
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
|
+
},
|
|
657
842
|
globDirectory: {
|
|
658
843
|
description: "The local directory you wish to match `globPatterns` against. The path is\nrelative to the current directory.",
|
|
659
844
|
type: "string"
|
|
845
|
+
},
|
|
846
|
+
disablePrecacheManifest: {
|
|
847
|
+
description: "Whether the precache manifest should be set to `undefined`.",
|
|
848
|
+
"default": false,
|
|
849
|
+
type: "boolean"
|
|
660
850
|
}
|
|
661
851
|
};
|
|
662
852
|
var required$2 = [
|
|
663
|
-
"globDirectory"
|
|
853
|
+
"globDirectory",
|
|
854
|
+
"swDest",
|
|
855
|
+
"swSrc"
|
|
664
856
|
];
|
|
665
857
|
var definitions$2 = {
|
|
666
858
|
ManifestEntry: {
|
|
@@ -731,7 +923,7 @@ var definitions$2 = {
|
|
|
731
923
|
}
|
|
732
924
|
};
|
|
733
925
|
var $schema$2 = "http://json-schema.org/draft-07/schema#";
|
|
734
|
-
var
|
|
926
|
+
var injectManifestOptionsSchema = {
|
|
735
927
|
additionalProperties: additionalProperties$2,
|
|
736
928
|
type: type$2,
|
|
737
929
|
properties: properties$2,
|
|
@@ -922,7 +1114,7 @@ var definitions$1 = {
|
|
|
922
1114
|
}
|
|
923
1115
|
};
|
|
924
1116
|
var $schema$1 = "http://json-schema.org/draft-07/schema#";
|
|
925
|
-
var
|
|
1117
|
+
var viteInjectManifestOptionsSchema = {
|
|
926
1118
|
additionalProperties: additionalProperties$1,
|
|
927
1119
|
type: type$1,
|
|
928
1120
|
properties: properties$1,
|
|
@@ -1113,7 +1305,8 @@ var webpackInjectManifestOptionsSchema = {
|
|
|
1113
1305
|
const optionsSchemas = {
|
|
1114
1306
|
GetManifest: getManifestOptionsSchema,
|
|
1115
1307
|
InjectManifest: injectManifestOptionsSchema,
|
|
1116
|
-
WebpackInjectManifest: webpackInjectManifestOptionsSchema
|
|
1308
|
+
WebpackInjectManifest: webpackInjectManifestOptionsSchema,
|
|
1309
|
+
ViteInjectManifest: viteInjectManifestOptionsSchema
|
|
1117
1310
|
};
|
|
1118
1311
|
|
|
1119
1312
|
const ajv = new Ajv({
|
|
@@ -1177,6 +1370,10 @@ function validateWebpackInjectManifestOptions(input) {
|
|
|
1177
1370
|
const [validatedOptions] = validate(inputWithExcludeDefault, "WebpackInjectManifest");
|
|
1178
1371
|
return validatedOptions;
|
|
1179
1372
|
}
|
|
1373
|
+
const validateViteInjectManifestOptions = (input)=>{
|
|
1374
|
+
const [validatedOptions] = validate(input, "ViteInjectManifest");
|
|
1375
|
+
return validatedOptions;
|
|
1376
|
+
};
|
|
1180
1377
|
|
|
1181
1378
|
/**
|
|
1182
1379
|
* This method returns a list of URLs to precache, referred to as a "precache
|
|
@@ -1207,7 +1404,7 @@ function validateWebpackInjectManifestOptions(input) {
|
|
|
1207
1404
|
*/ // Adapted from https://github.com/lydell/source-map-url/blob/master/source-map-url.js
|
|
1208
1405
|
// See https://github.com/GoogleChrome/workbox/issues/3019
|
|
1209
1406
|
const innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/;
|
|
1210
|
-
const regex = RegExp(
|
|
1407
|
+
const regex = RegExp(`(?:/\\*(?:\\s*\r?\n(?://)?)?(?:${innerRegex.source})\\s*\\*/|//(?:${innerRegex.source}))\\s*`);
|
|
1211
1408
|
function getSourceMapURL(srcContents) {
|
|
1212
1409
|
const match = srcContents.match(regex);
|
|
1213
1410
|
return match ? match[1] || match[2] || "" : null;
|
|
@@ -1370,7 +1567,7 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
|
|
|
1370
1567
|
throw new Error(`${errors["injection-point-not-found"]} ${injectionPoint}`);
|
|
1371
1568
|
}
|
|
1372
1569
|
assert(injectionResults.length === 1, `${errors["multiple-injection-points"]} ${injectionPoint}`);
|
|
1373
|
-
const manifestString = stringify(manifestEntries);
|
|
1570
|
+
const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
|
|
1374
1571
|
const filesToWrite = {};
|
|
1375
1572
|
const url = getSourceMapURL(swFileContents);
|
|
1376
1573
|
// See https://github.com/GoogleChrome/workbox/issues/2957
|
|
@@ -1406,7 +1603,7 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
|
|
|
1406
1603
|
try {
|
|
1407
1604
|
await fse.mkdirp(upath.dirname(file));
|
|
1408
1605
|
} catch (error) {
|
|
1409
|
-
throw new Error(errors["unable-to-make-sw-directory"]
|
|
1606
|
+
throw new Error(`${errors["unable-to-make-sw-directory"]} '${error instanceof Error && error.message ? error.message : ""}'`);
|
|
1410
1607
|
}
|
|
1411
1608
|
await fse.writeFile(file, contents);
|
|
1412
1609
|
}
|
|
@@ -1419,11 +1616,17 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
|
|
|
1419
1616
|
};
|
|
1420
1617
|
}
|
|
1421
1618
|
|
|
1619
|
+
exports.stringify = stringify;
|
|
1422
1620
|
exports.errors = errors;
|
|
1423
1621
|
exports.escapeRegExp = escapeRegExp;
|
|
1622
|
+
exports.getFileManifestEntries = getFileManifestEntries;
|
|
1424
1623
|
exports.getManifest = getManifest;
|
|
1425
1624
|
exports.getSourceMapURL = getSourceMapURL;
|
|
1426
1625
|
exports.injectManifest = injectManifest;
|
|
1626
|
+
exports.rebasePath = rebasePath;
|
|
1427
1627
|
exports.replaceAndUpdateSourceMap = replaceAndUpdateSourceMap;
|
|
1428
1628
|
exports.transformManifest = transformManifest;
|
|
1629
|
+
exports.translateURLToSourcemapPaths = translateURLToSourcemapPaths;
|
|
1630
|
+
exports.validateInjectManifestOptions = validateInjectManifestOptions;
|
|
1631
|
+
exports.validateViteInjectManifestOptions = validateViteInjectManifestOptions;
|
|
1429
1632
|
exports.validateWebpackInjectManifestOptions = validateWebpackInjectManifestOptions;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import stringify from "fast-json-stable-stringify";
|
|
2
2
|
import { getManifest } from "./get-manifest.js";
|
|
3
3
|
import { injectManifest } from "./inject-manifest.js";
|
|
4
|
+
import { errors } from "./lib/errors.js";
|
|
4
5
|
import { escapeRegExp } from "./lib/escape-regexp.js";
|
|
6
|
+
import { getFileManifestEntries } from "./lib/get-file-manifest-entries.js";
|
|
5
7
|
import { getSourceMapURL } from "./lib/get-source-map-url.js";
|
|
8
|
+
import { rebasePath } from "./lib/rebase-path.js";
|
|
6
9
|
import { replaceAndUpdateSourceMap } from "./lib/replace-and-update-source-map.js";
|
|
7
10
|
import { transformManifest } from "./lib/transform-manifest.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
11
|
+
import { translateURLToSourcemapPaths } from "./lib/translate-url-to-sourcemap-paths.js";
|
|
12
|
+
import { validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions } from "./lib/validate-options.js";
|
|
13
|
+
export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, stringify, transformManifest, translateURLToSourcemapPaths, validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions, };
|
|
10
14
|
export * from "./types.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import stringify from "fast-json-stable-stringify";
|
|
2
2
|
import { getManifest } from "./get-manifest.js";
|
|
3
3
|
import { injectManifest } from "./inject-manifest.js";
|
|
4
|
+
import { errors } from "./lib/errors.js";
|
|
4
5
|
import { escapeRegExp } from "./lib/escape-regexp.js";
|
|
6
|
+
import { getFileManifestEntries } from "./lib/get-file-manifest-entries.js";
|
|
5
7
|
import { getSourceMapURL } from "./lib/get-source-map-url.js";
|
|
8
|
+
import { rebasePath } from "./lib/rebase-path.js";
|
|
6
9
|
import { replaceAndUpdateSourceMap } from "./lib/replace-and-update-source-map.js";
|
|
7
10
|
import { transformManifest } from "./lib/transform-manifest.js";
|
|
8
|
-
import {
|
|
9
|
-
|
|
11
|
+
import { translateURLToSourcemapPaths } from "./lib/translate-url-to-sourcemap-paths.js";
|
|
12
|
+
import { validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions } from "./lib/validate-options.js";
|
|
13
|
+
export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, stringify, transformManifest, translateURLToSourcemapPaths, validateInjectManifestOptions, validateViteInjectManifestOptions, validateWebpackInjectManifestOptions, };
|
|
10
14
|
export * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import stringify from 'fast-json-stable-stringify';
|
|
2
|
+
export { default as stringify } from 'fast-json-stable-stringify';
|
|
2
3
|
import assert from 'assert';
|
|
4
|
+
import { oneLine } from 'common-tags';
|
|
3
5
|
import crypto from 'crypto';
|
|
4
6
|
import { glob } from 'glob';
|
|
5
7
|
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';
|
|
11
12
|
|
|
12
13
|
const errors = {
|
|
13
|
-
"unable-to-get-rootdir":
|
|
14
|
+
"unable-to-get-rootdir": "Unable to get the root directory of your web app.",
|
|
14
15
|
"no-extension": oneLine`Unable to detect a usable extension for a file in your web
|
|
15
16
|
app directory.`,
|
|
16
17
|
"invalid-file-manifest-name": oneLine`The File Manifest Name must have at least one
|
|
@@ -131,7 +132,7 @@ function getFileHash(file) {
|
|
|
131
132
|
const buffer = fse.readFileSync(file);
|
|
132
133
|
return getStringHash(buffer);
|
|
133
134
|
} catch (err) {
|
|
134
|
-
throw new Error(errors["unable-to-get-file-hash"]
|
|
135
|
+
throw new Error(`${errors["unable-to-get-file-hash"]} '${err instanceof Error && err.message ? err.message : ""}'`);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
|
|
@@ -143,7 +144,7 @@ function getFileSize(file) {
|
|
|
143
144
|
}
|
|
144
145
|
return stat.size;
|
|
145
146
|
} catch (err) {
|
|
146
|
-
throw new Error(errors["unable-to-get-file-size"]
|
|
147
|
+
throw new Error(`${errors["unable-to-get-file-size"]} '${err instanceof Error && err.message ? err.message : ""}'`);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
|
|
@@ -157,14 +158,14 @@ function getFileDetails({ globDirectory, globFollow, globIgnores, globPattern })
|
|
|
157
158
|
ignore: globIgnores
|
|
158
159
|
});
|
|
159
160
|
} catch (err) {
|
|
160
|
-
throw new Error(errors["unable-to-glob-files"]
|
|
161
|
+
throw new Error(`${errors["unable-to-glob-files"]} '${err instanceof Error && err.message ? err.message : ""}'`);
|
|
161
162
|
}
|
|
162
163
|
if (globbedFiles.length === 0) {
|
|
163
|
-
warning = errors["useless-glob-pattern"]
|
|
164
|
+
warning = `${errors["useless-glob-pattern"]} ${JSON.stringify({
|
|
164
165
|
globDirectory,
|
|
165
166
|
globPattern,
|
|
166
167
|
globIgnores
|
|
167
|
-
}, null, 2)
|
|
168
|
+
}, null, 2)}`;
|
|
168
169
|
}
|
|
169
170
|
const globbedFileDetails = [];
|
|
170
171
|
for (const file of globbedFiles){
|
|
@@ -341,7 +342,7 @@ function maximumSizeTransform(maximumFileSizeToCacheInBytes) {
|
|
|
341
342
|
if (entry.size <= maximumFileSizeToCacheInBytes) {
|
|
342
343
|
return true;
|
|
343
344
|
}
|
|
344
|
-
warnings.push(`${entry.url} is ${prettyBytes(entry.size)}, and won't
|
|
345
|
+
warnings.push(`${entry.url} is ${prettyBytes(entry.size)}, and won't be precached. Configure maximumFileSizeToCacheInBytes to change this limit.`);
|
|
345
346
|
return false;
|
|
346
347
|
});
|
|
347
348
|
return {
|
|
@@ -475,6 +476,7 @@ async function transformManifest({ additionalPrecacheEntries, dontCacheBustURLsM
|
|
|
475
476
|
let size = 0;
|
|
476
477
|
for (const manifestEntry of transformedManifest){
|
|
477
478
|
size += manifestEntry.size || 0;
|
|
479
|
+
// biome-ignore lint/performance/noDelete: I don't understand this part yet.
|
|
478
480
|
delete manifestEntry.size;
|
|
479
481
|
}
|
|
480
482
|
return {
|
|
@@ -567,6 +569,177 @@ async function getFileManifestEntries({ additionalPrecacheEntries, dontCacheBust
|
|
|
567
569
|
return transformedManifest;
|
|
568
570
|
}
|
|
569
571
|
|
|
572
|
+
var additionalProperties$3 = false;
|
|
573
|
+
var type$3 = "object";
|
|
574
|
+
var properties$3 = {
|
|
575
|
+
additionalPrecacheEntries: {
|
|
576
|
+
description: "A list of entries to be precached, in addition to any entries that are\ngenerated as part of the build configuration.",
|
|
577
|
+
type: "array",
|
|
578
|
+
items: {
|
|
579
|
+
anyOf: [
|
|
580
|
+
{
|
|
581
|
+
$ref: "#/definitions/ManifestEntry"
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
type: "string"
|
|
585
|
+
}
|
|
586
|
+
]
|
|
587
|
+
}
|
|
588
|
+
},
|
|
589
|
+
dontCacheBustURLsMatching: {
|
|
590
|
+
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.",
|
|
591
|
+
$ref: "#/definitions/RegExp"
|
|
592
|
+
},
|
|
593
|
+
manifestTransforms: {
|
|
594
|
+
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.",
|
|
595
|
+
type: "array",
|
|
596
|
+
items: {}
|
|
597
|
+
},
|
|
598
|
+
maximumFileSizeToCacheInBytes: {
|
|
599
|
+
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.",
|
|
600
|
+
"default": 2097152,
|
|
601
|
+
type: "number"
|
|
602
|
+
},
|
|
603
|
+
modifyURLPrefix: {
|
|
604
|
+
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```",
|
|
605
|
+
type: "object",
|
|
606
|
+
additionalProperties: {
|
|
607
|
+
type: "string"
|
|
608
|
+
}
|
|
609
|
+
},
|
|
610
|
+
globFollow: {
|
|
611
|
+
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).",
|
|
612
|
+
"default": true,
|
|
613
|
+
type: "boolean"
|
|
614
|
+
},
|
|
615
|
+
globIgnores: {
|
|
616
|
+
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).",
|
|
617
|
+
"default": [
|
|
618
|
+
"**/node_modules/**/*"
|
|
619
|
+
],
|
|
620
|
+
type: "array",
|
|
621
|
+
items: {
|
|
622
|
+
type: "string"
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
globPatterns: {
|
|
626
|
+
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).",
|
|
627
|
+
"default": [
|
|
628
|
+
"**/*.{js,css,html}"
|
|
629
|
+
],
|
|
630
|
+
type: "array",
|
|
631
|
+
items: {
|
|
632
|
+
type: "string"
|
|
633
|
+
}
|
|
634
|
+
},
|
|
635
|
+
globStrict: {
|
|
636
|
+
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).",
|
|
637
|
+
"default": true,
|
|
638
|
+
type: "boolean"
|
|
639
|
+
},
|
|
640
|
+
templatedURLs: {
|
|
641
|
+
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.",
|
|
642
|
+
type: "object",
|
|
643
|
+
additionalProperties: {
|
|
644
|
+
anyOf: [
|
|
645
|
+
{
|
|
646
|
+
type: "array",
|
|
647
|
+
items: {
|
|
648
|
+
type: "string"
|
|
649
|
+
}
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
type: "string"
|
|
653
|
+
}
|
|
654
|
+
]
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
globDirectory: {
|
|
658
|
+
description: "The local directory you wish to match `globPatterns` against. The path is\nrelative to the current directory.",
|
|
659
|
+
type: "string"
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
var required$3 = [
|
|
663
|
+
"globDirectory"
|
|
664
|
+
];
|
|
665
|
+
var definitions$3 = {
|
|
666
|
+
ManifestEntry: {
|
|
667
|
+
type: "object",
|
|
668
|
+
properties: {
|
|
669
|
+
integrity: {
|
|
670
|
+
type: "string"
|
|
671
|
+
},
|
|
672
|
+
revision: {
|
|
673
|
+
type: [
|
|
674
|
+
"null",
|
|
675
|
+
"string"
|
|
676
|
+
]
|
|
677
|
+
},
|
|
678
|
+
url: {
|
|
679
|
+
type: "string"
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
additionalProperties: false,
|
|
683
|
+
required: [
|
|
684
|
+
"revision",
|
|
685
|
+
"url"
|
|
686
|
+
]
|
|
687
|
+
},
|
|
688
|
+
"RegExp": {
|
|
689
|
+
type: "object",
|
|
690
|
+
properties: {
|
|
691
|
+
source: {
|
|
692
|
+
type: "string"
|
|
693
|
+
},
|
|
694
|
+
global: {
|
|
695
|
+
type: "boolean"
|
|
696
|
+
},
|
|
697
|
+
ignoreCase: {
|
|
698
|
+
type: "boolean"
|
|
699
|
+
},
|
|
700
|
+
multiline: {
|
|
701
|
+
type: "boolean"
|
|
702
|
+
},
|
|
703
|
+
lastIndex: {
|
|
704
|
+
type: "number"
|
|
705
|
+
},
|
|
706
|
+
flags: {
|
|
707
|
+
type: "string"
|
|
708
|
+
},
|
|
709
|
+
sticky: {
|
|
710
|
+
type: "boolean"
|
|
711
|
+
},
|
|
712
|
+
unicode: {
|
|
713
|
+
type: "boolean"
|
|
714
|
+
},
|
|
715
|
+
dotAll: {
|
|
716
|
+
type: "boolean"
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
additionalProperties: false,
|
|
720
|
+
required: [
|
|
721
|
+
"dotAll",
|
|
722
|
+
"flags",
|
|
723
|
+
"global",
|
|
724
|
+
"ignoreCase",
|
|
725
|
+
"lastIndex",
|
|
726
|
+
"multiline",
|
|
727
|
+
"source",
|
|
728
|
+
"sticky",
|
|
729
|
+
"unicode"
|
|
730
|
+
]
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
var $schema$3 = "http://json-schema.org/draft-07/schema#";
|
|
734
|
+
var getManifestOptionsSchema = {
|
|
735
|
+
additionalProperties: additionalProperties$3,
|
|
736
|
+
type: type$3,
|
|
737
|
+
properties: properties$3,
|
|
738
|
+
required: required$3,
|
|
739
|
+
definitions: definitions$3,
|
|
740
|
+
$schema: $schema$3
|
|
741
|
+
};
|
|
742
|
+
|
|
570
743
|
var additionalProperties$2 = false;
|
|
571
744
|
var type$2 = "object";
|
|
572
745
|
var properties$2 = {
|
|
@@ -652,13 +825,33 @@ var properties$2 = {
|
|
|
652
825
|
]
|
|
653
826
|
}
|
|
654
827
|
},
|
|
828
|
+
injectionPoint: {
|
|
829
|
+
description: "The string to find inside of the `swSrc` file. Once found, it will be\nreplaced by the generated precache manifest.",
|
|
830
|
+
"default": "self.__SW_MANIFEST",
|
|
831
|
+
type: "string"
|
|
832
|
+
},
|
|
833
|
+
swSrc: {
|
|
834
|
+
description: "The path and filename of the service worker file that will be read during\nthe build process, relative to the current working directory.",
|
|
835
|
+
type: "string"
|
|
836
|
+
},
|
|
837
|
+
swDest: {
|
|
838
|
+
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'.",
|
|
839
|
+
type: "string"
|
|
840
|
+
},
|
|
655
841
|
globDirectory: {
|
|
656
842
|
description: "The local directory you wish to match `globPatterns` against. The path is\nrelative to the current directory.",
|
|
657
843
|
type: "string"
|
|
844
|
+
},
|
|
845
|
+
disablePrecacheManifest: {
|
|
846
|
+
description: "Whether the precache manifest should be set to `undefined`.",
|
|
847
|
+
"default": false,
|
|
848
|
+
type: "boolean"
|
|
658
849
|
}
|
|
659
850
|
};
|
|
660
851
|
var required$2 = [
|
|
661
|
-
"globDirectory"
|
|
852
|
+
"globDirectory",
|
|
853
|
+
"swDest",
|
|
854
|
+
"swSrc"
|
|
662
855
|
];
|
|
663
856
|
var definitions$2 = {
|
|
664
857
|
ManifestEntry: {
|
|
@@ -729,7 +922,7 @@ var definitions$2 = {
|
|
|
729
922
|
}
|
|
730
923
|
};
|
|
731
924
|
var $schema$2 = "http://json-schema.org/draft-07/schema#";
|
|
732
|
-
var
|
|
925
|
+
var injectManifestOptionsSchema = {
|
|
733
926
|
additionalProperties: additionalProperties$2,
|
|
734
927
|
type: type$2,
|
|
735
928
|
properties: properties$2,
|
|
@@ -920,7 +1113,7 @@ var definitions$1 = {
|
|
|
920
1113
|
}
|
|
921
1114
|
};
|
|
922
1115
|
var $schema$1 = "http://json-schema.org/draft-07/schema#";
|
|
923
|
-
var
|
|
1116
|
+
var viteInjectManifestOptionsSchema = {
|
|
924
1117
|
additionalProperties: additionalProperties$1,
|
|
925
1118
|
type: type$1,
|
|
926
1119
|
properties: properties$1,
|
|
@@ -1111,7 +1304,8 @@ var webpackInjectManifestOptionsSchema = {
|
|
|
1111
1304
|
const optionsSchemas = {
|
|
1112
1305
|
GetManifest: getManifestOptionsSchema,
|
|
1113
1306
|
InjectManifest: injectManifestOptionsSchema,
|
|
1114
|
-
WebpackInjectManifest: webpackInjectManifestOptionsSchema
|
|
1307
|
+
WebpackInjectManifest: webpackInjectManifestOptionsSchema,
|
|
1308
|
+
ViteInjectManifest: viteInjectManifestOptionsSchema
|
|
1115
1309
|
};
|
|
1116
1310
|
|
|
1117
1311
|
const ajv = new Ajv({
|
|
@@ -1175,6 +1369,10 @@ function validateWebpackInjectManifestOptions(input) {
|
|
|
1175
1369
|
const [validatedOptions] = validate(inputWithExcludeDefault, "WebpackInjectManifest");
|
|
1176
1370
|
return validatedOptions;
|
|
1177
1371
|
}
|
|
1372
|
+
const validateViteInjectManifestOptions = (input)=>{
|
|
1373
|
+
const [validatedOptions] = validate(input, "ViteInjectManifest");
|
|
1374
|
+
return validatedOptions;
|
|
1375
|
+
};
|
|
1178
1376
|
|
|
1179
1377
|
/**
|
|
1180
1378
|
* This method returns a list of URLs to precache, referred to as a "precache
|
|
@@ -1205,7 +1403,7 @@ function validateWebpackInjectManifestOptions(input) {
|
|
|
1205
1403
|
*/ // Adapted from https://github.com/lydell/source-map-url/blob/master/source-map-url.js
|
|
1206
1404
|
// See https://github.com/GoogleChrome/workbox/issues/3019
|
|
1207
1405
|
const innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/;
|
|
1208
|
-
const regex = RegExp(
|
|
1406
|
+
const regex = RegExp(`(?:/\\*(?:\\s*\r?\n(?://)?)?(?:${innerRegex.source})\\s*\\*/|//(?:${innerRegex.source}))\\s*`);
|
|
1209
1407
|
function getSourceMapURL(srcContents) {
|
|
1210
1408
|
const match = srcContents.match(regex);
|
|
1211
1409
|
return match ? match[1] || match[2] || "" : null;
|
|
@@ -1368,7 +1566,7 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
|
|
|
1368
1566
|
throw new Error(`${errors["injection-point-not-found"]} ${injectionPoint}`);
|
|
1369
1567
|
}
|
|
1370
1568
|
assert(injectionResults.length === 1, `${errors["multiple-injection-points"]} ${injectionPoint}`);
|
|
1371
|
-
const manifestString = stringify(manifestEntries);
|
|
1569
|
+
const manifestString = manifestEntries === undefined ? "undefined" : stringify(manifestEntries);
|
|
1372
1570
|
const filesToWrite = {};
|
|
1373
1571
|
const url = getSourceMapURL(swFileContents);
|
|
1374
1572
|
// See https://github.com/GoogleChrome/workbox/issues/2957
|
|
@@ -1404,7 +1602,7 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
|
|
|
1404
1602
|
try {
|
|
1405
1603
|
await fse.mkdirp(upath.dirname(file));
|
|
1406
1604
|
} catch (error) {
|
|
1407
|
-
throw new Error(errors["unable-to-make-sw-directory"]
|
|
1605
|
+
throw new Error(`${errors["unable-to-make-sw-directory"]} '${error instanceof Error && error.message ? error.message : ""}'`);
|
|
1408
1606
|
}
|
|
1409
1607
|
await fse.writeFile(file, contents);
|
|
1410
1608
|
}
|
|
@@ -1417,4 +1615,4 @@ function translateURLToSourcemapPaths(url, swSrc, swDest) {
|
|
|
1417
1615
|
};
|
|
1418
1616
|
}
|
|
1419
1617
|
|
|
1420
|
-
export { errors, escapeRegExp, getManifest, getSourceMapURL, injectManifest, replaceAndUpdateSourceMap, transformManifest, validateWebpackInjectManifestOptions };
|
|
1618
|
+
export { errors, escapeRegExp, getFileManifestEntries, getManifest, getSourceMapURL, injectManifest, rebasePath, replaceAndUpdateSourceMap, 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;
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
209
|
-
* @default
|
|
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
|
|
215
|
-
* [
|
|
216
|
-
* @default
|
|
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
|
|
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.
|
|
3
|
+
"version": "8.4.1",
|
|
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.
|
|
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",
|
|
@@ -49,31 +49,29 @@
|
|
|
49
49
|
"glob": "10.3.10",
|
|
50
50
|
"rollup": "4.9.1",
|
|
51
51
|
"source-map": "0.8.0-beta.0",
|
|
52
|
-
"stringify-object": "5.0.0",
|
|
53
|
-
"strip-comments": "2.0.1",
|
|
54
52
|
"upath": "2.0.1",
|
|
55
|
-
"@serwist/background-sync": "8.
|
|
56
|
-
"@serwist/broadcast-update": "8.
|
|
57
|
-
"@serwist/cacheable-response": "8.
|
|
58
|
-
"@serwist/core": "8.
|
|
59
|
-
"@serwist/expiration": "8.
|
|
60
|
-
"@serwist/google-analytics": "8.
|
|
61
|
-
"@serwist/precaching": "8.
|
|
62
|
-
"@serwist/routing": "8.
|
|
53
|
+
"@serwist/background-sync": "8.4.1",
|
|
54
|
+
"@serwist/broadcast-update": "8.4.1",
|
|
55
|
+
"@serwist/cacheable-response": "8.4.1",
|
|
56
|
+
"@serwist/core": "8.4.1",
|
|
57
|
+
"@serwist/expiration": "8.4.1",
|
|
58
|
+
"@serwist/google-analytics": "8.4.1",
|
|
59
|
+
"@serwist/precaching": "8.4.1",
|
|
60
|
+
"@serwist/routing": "8.4.1"
|
|
63
61
|
},
|
|
64
62
|
"devDependencies": {
|
|
65
63
|
"@types/common-tags": "1.8.4",
|
|
66
64
|
"@types/fs-extra": "11.0.4",
|
|
67
65
|
"@types/node": "20.10.5",
|
|
68
66
|
"@types/stringify-object": "4.0.5",
|
|
69
|
-
"@types/strip-comments": "2.0.4",
|
|
70
67
|
"pretty-bytes": "6.1.1",
|
|
71
68
|
"type-fest": "4.8.3",
|
|
72
|
-
"@serwist/constants": "8.
|
|
69
|
+
"@serwist/constants": "8.4.1"
|
|
73
70
|
},
|
|
74
71
|
"scripts": {
|
|
75
72
|
"build": "rimraf dist && cross-env NODE_OPTIONS='--max-old-space-size=4096' NODE_ENV=production rollup --config rollup.config.js",
|
|
76
|
-
"
|
|
73
|
+
"dev": "rollup --config rollup.config.js --watch",
|
|
74
|
+
"lint": "biome lint ./src",
|
|
77
75
|
"typecheck": "tsc"
|
|
78
76
|
}
|
|
79
77
|
}
|