workbox-build
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,2 @@ | ||
'use strict'; | ||
// This will be the logic that powers both module and CLI | ||
@@ -2,0 +3,0 @@ const generateSW = require('./lib/generate-sw'); |
module.exports = { | ||
// Max File Size: 2MB | ||
maximumFileSize: 2 * 1024 * 1024, | ||
defaultGlobPatterns: [ | ||
'**/*.{js,css,html}', | ||
], | ||
defaultGlobIgnores: [ | ||
@@ -5,0 +8,0 @@ 'node_modules/**/*', |
@@ -36,2 +36,4 @@ module.exports = { | ||
'a path as a string.', | ||
'invalid-dont-cache-bust': 'The supplied dontCacheBustUrlsMatching ' + | ||
'parameter must be a RegExp.', | ||
'invalid-exclude-files': 'The excluded files should be an array of strings.', | ||
@@ -57,4 +59,4 @@ 'invalid-get-manifest-entries-input': 'The input to ' + | ||
`array string glob patterns.`, | ||
'modify-url-prefix-bad-url': `modifyUrlPrefix helper was given a bad URL ` + | ||
`for input. This is likely an error with workbox-build.`, | ||
'manifest-entry-bad-url': `The generated manifest contains an entry ` + | ||
`without a URL string. This is likely an error with workbox-build.`, | ||
'modify-url-prefix-bad-prefixes': `The 'modifyUrlPrefix' parameter must be ` + | ||
@@ -86,2 +88,4 @@ `an object with string key value pairs.`, | ||
runtimeCaching.`, | ||
'bad-manifest-transforms': `The 'manifestTransforms' value should be an ` + | ||
`array of functions.`, | ||
}; |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const getFileManifestEntries = require('./get-file-manifest-entries'); | ||
@@ -41,2 +43,6 @@ const writeFileManifest = require('./utils/write-file-manifest'); | ||
* is useful for assets that have revisioning details in the filename. | ||
* @param {Array<ManifestTransform>} [input.manifestTransforms] A list of | ||
* manifest transformations, which will be applied sequentially against the | ||
* generated manifest. If `modifyUrlPrefix` or `dontCacheBustUrlsMatching` are | ||
* also specified, their corresponding transformations will be applied first. | ||
* @return {Promise} The returned promise resolves once the manifest file has | ||
@@ -43,0 +49,0 @@ * been generated. |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
@@ -13,3 +15,3 @@ const copyWorkboxSW = require('./utils/copy-workbox-sw'); | ||
* @param {Object} input | ||
* @param {String} input.swDest The file path and name you wish to writh the | ||
* @param {String} input.swDest The file path and name you wish to write the | ||
* service worker file to. | ||
@@ -20,2 +22,4 @@ * @param {String} input.globDirectory The directory you wish to run the | ||
* these glob patterns will be included in the file manifest. | ||
* | ||
* Defaults to ['**\/*.{js,css}'] | ||
* @param {String|Array<String>} [input.globIgnores] Files matching against any | ||
@@ -73,2 +77,6 @@ * of these glob patterns will be excluded from the file manifest, even if the | ||
* is useful for assets that have revisioning details in the filename. | ||
* @param {Array<ManifestTransform>} [input.manifestTransforms] A list of | ||
* manifest transformations, which will be applied sequentially against the | ||
* generated manifest. If `modifyUrlPrefix` or `dontCacheBustUrlsMatching` are | ||
* also specified, their corresponding transformations will be applied first. | ||
* @return {Promise} Resolves once the service worker has been generated | ||
@@ -75,0 +83,0 @@ * with a precache list. |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const errors = require('./errors'); | ||
@@ -26,2 +28,4 @@ const filterFiles = require('./utils/filter-files'); | ||
* these glob patterns will be included in the file manifest. | ||
* | ||
* Defaults to ['**\/*.{js,css}'] | ||
* @param {String|Array<String>} [input.globIgnores] Files matching against any | ||
@@ -45,2 +49,6 @@ * of these glob patterns will be excluded from the file manifest, even if the | ||
* regex. Useful if you have assets with file revisions in the URL. | ||
* @param {Array<ManifestTransform>} [input.manifestTransforms] A list of | ||
* manifest transformations, which will be applied sequentially against the | ||
* generated manifest. If `modifyUrlPrefix` or `dontCacheBustUrlsMatching` are | ||
* also specified, their corresponding transformations will be applied first. | ||
* @return {Promise<Array<ManifestEntry>>} | ||
@@ -62,4 +70,9 @@ * An array of {@link module:workbox-build#ManifestEntry|ManifestEntries} | ||
} | ||
const globPatterns = input.globPatterns || input.staticFileGlobs; | ||
let globPatterns = input.globPatterns || input.staticFileGlobs; | ||
if (typeof input.globPatterns === 'undefined' && | ||
typeof input.staticFileGlobs === 'undefined') { | ||
globPatterns = constants.defaultGlobPatterns; | ||
} | ||
const globIgnores = input.globIgnores || constants.defaultGlobIgnores; | ||
@@ -66,0 +79,0 @@ const globDirectory = input.globDirectory; |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
@@ -23,2 +25,4 @@ const mkdirp = require('mkdirp'); | ||
* these glob patterns will be included in the file manifest. | ||
* | ||
* Defaults to ['**\/*.{js,css}'] | ||
* @param {String|Array<String>} [input.globIgnores] Files matching against any | ||
@@ -41,2 +45,6 @@ * of these glob patterns will be excluded from the file manifest, even if the | ||
* regex. Useful if you have assets with file revisions in the URL. | ||
* @param {Array<ManifestTransform>} [input.manifestTransforms] A list of | ||
* manifest transformations, which will be applied sequentially against the | ||
* generated manifest. If `modifyUrlPrefix` or `dontCacheBustUrlsMatching` are | ||
* also specified, their corresponding transformations will be applied first. | ||
* @return {Promise} Resolves once the service worker has been written | ||
@@ -43,0 +51,0 @@ * with the injected precache list. |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
/** | ||
@@ -2,0 +4,0 @@ * Copyright 2016 Google Inc. |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const errors = require('../errors'); | ||
@@ -9,3 +11,6 @@ const fse = require('fs-extra'); | ||
path.basename(workboxSWSrcPath)); | ||
return fse.copy(workboxSWSrcPath, workboxSWDestPath) | ||
return Promise.all([ | ||
fse.copy(workboxSWSrcPath, workboxSWDestPath), | ||
fse.copy(`${workboxSWSrcPath}.map`, `${workboxSWDestPath}.map`), | ||
]) | ||
.then(() => workboxSWDestPath) | ||
@@ -12,0 +17,0 @@ .catch((error) => { |
@@ -1,7 +0,55 @@ | ||
const path = require('path'); | ||
'use strict'; | ||
const constants = require('../constants'); | ||
const errors = require('../errors'); | ||
const logHelper = require('../log-helper'); | ||
const constants = require('../constants'); | ||
const modifyUrlPrefixes = require('./modify-url-prefix'); | ||
const modifyUrlPrefixTranform = require('./modify-url-prefix-transform'); | ||
const noRevisionForUrlsMatchingTransform = | ||
require('./no-revision-for-urls-matching-transform'); | ||
const path = require('path'); | ||
/** | ||
* A `ManifestTransform` function can be used to modify the modify the `url` or | ||
* `revision` properties of some or all of the | ||
* {@link module:workbox-build#ManifestEntry|ManifestEntries} in the manifest. | ||
* | ||
* Deleting the `revision` property of an entry will cause | ||
* the corresponding `url` to be precached without cache-busting parameters | ||
* applied, which is to say, it implies that the URL itself contains | ||
* proper versioning info. If the `revision` property is present, it must be | ||
* set to a string. | ||
* | ||
* @example <caption>A transformation that prepended the origin of a CDN for any | ||
* URL starting with '/assets/' could be implemented as:</caption> | ||
* | ||
* const cdnTransform = (manifestEntries) => manifestEntries.map(entry => { | ||
* const cdnOrigin = 'https://example.com'; | ||
* if (entry.url.startsWith('/assets/')) { | ||
* entry.url = cdnOrigin + entry.url; | ||
* } | ||
* return entry; | ||
* }); | ||
* | ||
* @example <caption>A transformation that removes the revision field when the | ||
* URL contains an 8-character hash surrounded by '.', indicating that it | ||
* already contains revision information:</caption> | ||
* | ||
* const removeRevisionTransform = (manifestEntries) => { | ||
* return manifestEntries.map(entry => { | ||
* const hashRegExp = /\.\w{8}\./; | ||
* if (entry.url.match(hashRegExp)) { | ||
* delete entry.revision; | ||
* } | ||
* return entry; | ||
* }); | ||
* }; | ||
* | ||
* @callback ManifestTransform | ||
* @param {Array<ManifestEntry>} manifestEntries The full array of entries, | ||
* prior to the current transformation. | ||
* @return {Array<ManifestEntry>} The array of entries with the transformation | ||
* applied. | ||
* @memberof module:workbox-build | ||
*/ | ||
module.exports = (fileDetails, options) => { | ||
@@ -11,3 +59,3 @@ const maximumFileSize = options.maximumFileSizeToCacheInBytes || | ||
const filteredFileDetails = fileDetails.filter((fileDetails) => { | ||
// Filter oversize files. | ||
// Remove oversized files. | ||
if (fileDetails.size > maximumFileSize) { | ||
@@ -23,21 +71,34 @@ logHelper.warn(`Skipping file '${fileDetails.file}' due to size. ` + | ||
// Convert to manifest format | ||
return filteredFileDetails.map((fileDetails) => { | ||
let url = fileDetails.file.replace(path.sep, '/'); | ||
// Take the array of fileDetail objects and convert it into an array of | ||
// {url, revision} objects, with path.sep replaced with /. | ||
const normalizedManifest = filteredFileDetails.map((fileDetails) => { | ||
return { | ||
url: fileDetails.file.replace(path.sep, '/'), | ||
revision: fileDetails.hash, | ||
}; | ||
}); | ||
// Modify URL Prefix | ||
if (options && options.modifyUrlPrefix) { | ||
url = modifyUrlPrefixes(url, options.modifyUrlPrefix); | ||
} | ||
const manifestTransforms = []; | ||
if (options.dontCacheBustUrlsMatching && | ||
url.match(options.dontCacheBustUrlsMatching)) { | ||
return url; | ||
if (options.modifyUrlPrefix) { | ||
manifestTransforms.push(modifyUrlPrefixTranform(options.modifyUrlPrefix)); | ||
} | ||
if (options.dontCacheBustUrlsMatching) { | ||
manifestTransforms.push( | ||
noRevisionForUrlsMatchingTransform(options.dontCacheBustUrlsMatching)); | ||
} | ||
if (options.manifestTransforms) { | ||
if (Array.isArray(options.manifestTransforms)) { | ||
manifestTransforms.concat(options.manifestTransforms); | ||
} else { | ||
throw new Error(errors['bad-manifest-transforms']); | ||
} | ||
} | ||
return { | ||
url: url, | ||
revision: fileDetails.hash, | ||
}; | ||
}); | ||
// Apply the transformations sequentially, and return the result. | ||
return manifestTransforms.reduce( | ||
(previousManifest, transform) => transform(previousManifest), | ||
normalizedManifest); | ||
}; |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const crypto = require('crypto'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const fs = require('fs'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const getStringhash = require('./get-string-hash'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const crypto = require('crypto'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const errors = require('../errors'); | ||
@@ -2,0 +4,0 @@ |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const mkdirp = require('mkdirp'); | ||
@@ -2,0 +4,0 @@ const path = require('path'); |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const errors = require('./errors'); | ||
@@ -2,0 +4,0 @@ const fs = require('fs'); |
{ | ||
"name": "workbox-build", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A module that integrates into your build process, helping you generate a manifest of local files that workbox-sw should precache.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63942
27
1244