UNPKG

5.22 kBJavaScriptView Raw
1"use strict";
2/*
3 Copyright 2018 Google LLC
4
5 Use of this source code is governed by an MIT-style
6 license that can be found in the LICENSE file or at
7 https://opensource.org/licenses/MIT.
8*/
9Object.defineProperty(exports, "__esModule", { value: true });
10exports.getManifest = void 0;
11const get_file_manifest_entries_1 = require("./lib/get-file-manifest-entries");
12const validate_options_1 = require("./lib/validate-options");
13// eslint-disable-next-line jsdoc/newline-after-description
14/**
15 * This method returns a list of URLs to precache, referred to as a "precache
16 * manifest", along with details about the number of entries and their size,
17 * based on the options you provide.
18 *
19 * @param {Object} config The configuration to use.
20 *
21 * @param {string} config.globDirectory The local directory you wish to match
22 * `globPatterns` against. The path is relative to the current directory.
23 *
24 * @param {Array<module:workbox-build.ManifestEntry>} [config.additionalManifestEntries]
25 * A list of entries to be precached, in addition to any entries that are
26 * generated as part of the build configuration.
27 *
28 * @param {RegExp} [config.dontCacheBustURLsMatching] Assets that match this will be
29 * assumed to be uniquely versioned via their URL, and exempted from the normal
30 * HTTP cache-busting that's done when populating the precache. While not
31 * required, it's recommended that if your existing build process already
32 * inserts a `[hash]` value into each filename, you provide a RegExp that will
33 * detect that, as it will reduce the bandwidth consumed when precaching.
34 *
35 * @param {boolean} [config.globFollow=true] Determines whether or not symlinks
36 * are followed when generating the precache manifest. For more information, see
37 * the definition of `follow` in the `glob`
38 * [documentation](https://github.com/isaacs/node-glob#options).
39 *
40 * @param {Array<string>} [config.globIgnores=['node_modules/**']]
41 * A set of patterns matching files to always exclude when generating the
42 * precache manifest. For more information, see the definition of `ignore` in the `glob`
43 * [documentation](https://github.com/isaacs/node-glob#options).
44 *
45 * @param {Array<string>} [config.globPatterns=['**.{js,css,html}']]
46 * Files matching any of these patterns will be included in the precache
47 * manifest. For more information, see the
48 * [`glob` primer](https://github.com/isaacs/node-glob#glob-primer).
49 *
50 * @param {boolean} [config.globStrict=true] If true, an error reading a directory when
51 * generating a precache manifest will cause the build to fail. If false, the
52 * problematic directory will be skipped. For more information, see the
53 * definition of `strict` in the `glob`
54 * [documentation](https://github.com/isaacs/node-glob#options).
55 *
56 * @param {Array<module:workbox-build.ManifestTransform>} [config.manifestTransforms] One or more
57 * functions which will be applied sequentially against the generated manifest.
58 * If `modifyURLPrefix` or `dontCacheBustURLsMatching` are also specified, their
59 * corresponding transformations will be applied first.
60 *
61 * @param {number} [config.maximumFileSizeToCacheInBytes=2097152] This value can be
62 * used to determine the maximum size of files that will be precached. This
63 * prevents you from inadvertently precaching very large files that might have
64 * accidentally matched one of your patterns.
65 *
66 * @param {object<string, string>} [config.modifyURLPrefix] A mapping of prefixes
67 * that, if present in an entry in the precache manifest, will be replaced with
68 * the corresponding value. This can be used to, for example, remove or add a
69 * path prefix from a manifest entry if your web hosting setup doesn't match
70 * your local filesystem setup. As an alternative with more flexibility, you can
71 * use the `manifestTransforms` option and provide a function that modifies the
72 * entries in the manifest using whatever logic you provide.
73 *
74 * @param {Object} [config.templatedURLs] If a URL is rendered based on some
75 * server-side logic, its contents may depend on multiple files or on some other
76 * unique string value. The keys in this object are server-rendered URLs. If the
77 * values are an array of strings, they will be interpreted as `glob` patterns,
78 * and the contents of any files matching the patterns will be used to uniquely
79 * version the URL. If used with a single string, it will be interpreted as
80 * unique versioning information that you've generated for a given URL.
81 *
82 * @return {Promise<{count: number, manifestEntries: Array<module:workbox-build.ManifestEntry>, size: number, warnings: Array<string>}>}
83 * A promise that resolves once the precache manifest (available in the
84 * `manifestEntries` property) has been determined. The `size` property
85 * contains the aggregate size of all the precached entries, in bytes, and the
86 * `count` property contains the total number of precached entries. Any
87 * non-fatal warning messages will be returned via `warnings`.
88 *
89 * @memberof module:workbox-build
90 */
91async function getManifest(config) {
92 const options = validate_options_1.validateGetManifestOptions(config);
93 return await get_file_manifest_entries_1.getFileManifestEntries(options);
94}
95exports.getManifest = getManifest;