workbox-build
Advanced tools
Comparing version 3.0.0-beta.0 to 3.0.0-beta.1
@@ -5,3 +5,3 @@ { | ||
"releasesDir": "releases", | ||
"latestVersion": "3.0.0-beta.0" | ||
"latestVersion": "3.0.0-beta.1" | ||
} |
@@ -21,4 +21,6 @@ 'use strict'; | ||
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#generateswstring_mode). | ||
* @return {Promise<String>} A populated service worker template, based on the | ||
* other configuration options provided. | ||
* @return {Promise<{swString: String, warnings: Array<String>}>} A promise that | ||
* resolves once the service worker template is populated. The `swString` | ||
* property contains a string representation of the full service worker code. | ||
* Any non-fatal warning messages will be returned via `warnings`. | ||
* | ||
@@ -29,3 +31,3 @@ * @memberof module:workbox-build | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) { | ||
var options, _ref2, manifestEntries; | ||
var options, _ref2, manifestEntries, warnings, swString; | ||
@@ -43,7 +45,13 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
manifestEntries = _ref2.manifestEntries; | ||
return _context.abrupt('return', populateSWTemplate((0, _assign2.default)({ | ||
warnings = _ref2.warnings; | ||
_context.next = 8; | ||
return populateSWTemplate((0, _assign2.default)({ | ||
manifestEntries | ||
}, options))); | ||
}, options)); | ||
case 6: | ||
case 8: | ||
swString = _context.sent; | ||
return _context.abrupt('return', { swString, warnings }); | ||
case 10: | ||
case 'end': | ||
@@ -50,0 +58,0 @@ return _context.stop(); |
@@ -27,6 +27,8 @@ 'use strict'; | ||
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config). | ||
* @return {Promise<{count: Number, size: Number}>} A promise that resolves once | ||
* the service worker file has been written to `swDest`. The `size` property | ||
* contains the aggregate size of all the precached entries, in bytes, and the | ||
* `count` property contains the total number of precached entries. | ||
* @return {Promise<{count: Number, size: Number, warnings: Array<String>}>} | ||
* A promise that resolves once the service worker file has been written to | ||
* `swDest`. The `size` property contains the aggregate size of all the | ||
* precached entries, in bytes, and the `count` property contains the total | ||
* number of precached entries. Any non-fatal warning messages will be returned | ||
* via `warnings`. | ||
* | ||
@@ -37,3 +39,3 @@ * @memberof module:workbox-build | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) { | ||
var options, destDirectory, cdnUrl, workboxDirectoryName, workboxSWPkg, workboxSWFilename, _ref2, count, size, manifestEntries; | ||
var options, destDirectory, cdnUrl, workboxDirectoryName, workboxSWPkg, workboxSWFilename, _ref2, count, size, manifestEntries, warnings; | ||
@@ -55,6 +57,4 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
cdnUrl = cdnUtils.getModuleUrl('workbox-sw'); | ||
// importScripts may or may not already be an array containing other URLs. | ||
// Either way, list cdnUrl first. | ||
options.importScripts = [cdnUrl].concat(options.importScripts || []); | ||
options.workboxSWImport = cdnUrl; | ||
_context.next = 16; | ||
@@ -83,7 +83,4 @@ break; | ||
// importScripts may or may not already be an array containing other URLs. | ||
// Either way, list workboxSWFilename first. | ||
options.importScripts = [`${workboxDirectoryName}/${workboxSWFilename}`].concat(options.importScripts || []); | ||
options.workboxSWImport = `${workboxDirectoryName}/${workboxSWFilename}`; | ||
options.modulePathPrefix = workboxDirectoryName; | ||
@@ -100,3 +97,4 @@ | ||
manifestEntries = _ref2.manifestEntries; | ||
_context.next = 24; | ||
warnings = _ref2.warnings; | ||
_context.next = 25; | ||
return writeServiceWorkerUsingDefaultTemplate((0, _assign2.default)({ | ||
@@ -106,6 +104,6 @@ manifestEntries | ||
case 24: | ||
return _context.abrupt('return', { count, size }); | ||
case 25: | ||
return _context.abrupt('return', { count, size, warnings }); | ||
case 25: | ||
case 26: | ||
case 'end': | ||
@@ -112,0 +110,0 @@ return _context.stop(); |
@@ -19,7 +19,8 @@ 'use strict'; | ||
* @return {Promise<{manifestEntries: Array<ManifestEntry>, | ||
* count: Number, size: Number}>} A promise that resolves once the precache | ||
* manifest is determined. The `size` property contains the aggregate size of | ||
* all the precached entries, in bytes, the `count` property contains the total | ||
* number of precached entries, and the `manifestEntries` property contains all | ||
* the `ManifestEntry` items. | ||
* count: Number, size: Number, warnings: Array<String>}>} A promise that | ||
* resolves once the precache manifest is determined. The `size` property | ||
* contains the aggregate size of all the precached entries, in bytes, the | ||
* `count` property contains the total number of precached entries, and the | ||
* `manifestEntries` property contains all the `ManifestEntry` items. Any | ||
* non-fatal warning messages will be returned via `warnings`. | ||
* | ||
@@ -30,3 +31,3 @@ * @memberof module:workbox-build | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) { | ||
var options, _ref2, manifestEntries, count, size; | ||
var options, _ref2, manifestEntries, count, size, warnings; | ||
@@ -46,5 +47,6 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
size = _ref2.size; | ||
return _context.abrupt('return', { manifestEntries, count, size }); | ||
warnings = _ref2.warnings; | ||
return _context.abrupt('return', { manifestEntries, count, size, warnings }); | ||
case 8: | ||
case 9: | ||
case 'end': | ||
@@ -51,0 +53,0 @@ return _context.stop(); |
@@ -27,6 +27,8 @@ 'use strict'; | ||
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_injectmanifest_config). | ||
* @return {Promise<{count: Number, size: Number}>} A promise that resolves once | ||
* the service worker file has been written to `swDest`. The `size` property | ||
* contains the aggregate size of all the precached entries, in bytes, and the | ||
* `count` property contains the total number of precached entries. | ||
* @return {Promise<{count: Number, size: Number, warnings: Array<String>}>} | ||
* A promise that resolves once the service worker file has been written to | ||
* `swDest`. The `size` property contains the aggregate size of all the | ||
* precached entries, in bytes, and the `count` property contains the total | ||
* number of precached entries. Any non-fatal warning messages will be returned | ||
* via `warnings`. | ||
* | ||
@@ -37,3 +39,3 @@ * @memberof module:workbox-build | ||
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) { | ||
var options, globalRegexp, _ref2, count, size, manifestEntries, swFileContents, injectionResults, entriesString; | ||
var options, globalRegexp, _ref2, count, size, manifestEntries, warnings, swFileContents, injectionResults, entriesString; | ||
@@ -63,18 +65,19 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
manifestEntries = _ref2.manifestEntries; | ||
warnings = _ref2.warnings; | ||
swFileContents = void 0; | ||
_context.prev = 11; | ||
_context.next = 14; | ||
_context.prev = 12; | ||
_context.next = 15; | ||
return fse.readFile(config.swSrc, 'utf8'); | ||
case 14: | ||
case 15: | ||
swFileContents = _context.sent; | ||
_context.next = 20; | ||
_context.next = 21; | ||
break; | ||
case 17: | ||
_context.prev = 17; | ||
_context.t0 = _context['catch'](11); | ||
case 18: | ||
_context.prev = 18; | ||
_context.t0 = _context['catch'](12); | ||
throw new Error(`${errors['invalid-sw-src']} ${_context.t0.message}`); | ||
case 20: | ||
case 21: | ||
injectionResults = swFileContents.match(globalRegexp); | ||
@@ -94,23 +97,23 @@ | ||
_context.prev = 25; | ||
_context.next = 28; | ||
_context.prev = 26; | ||
_context.next = 29; | ||
return fse.mkdirp(path.dirname(options.swDest)); | ||
case 28: | ||
_context.next = 33; | ||
case 29: | ||
_context.next = 34; | ||
break; | ||
case 30: | ||
_context.prev = 30; | ||
_context.t1 = _context['catch'](25); | ||
case 31: | ||
_context.prev = 31; | ||
_context.t1 = _context['catch'](26); | ||
throw new Error(errors['unable-to-make-injection-directory'] + ` '${_context.t1.message}'`); | ||
case 33: | ||
_context.next = 35; | ||
case 34: | ||
_context.next = 36; | ||
return fse.writeFile(config.swDest, swFileContents); | ||
case 35: | ||
return _context.abrupt('return', { count, size }); | ||
case 36: | ||
return _context.abrupt('return', { count, size, warnings }); | ||
case 36: | ||
case 37: | ||
case 'end': | ||
@@ -120,3 +123,3 @@ return _context.stop(); | ||
} | ||
}, _callee, this, [[11, 17], [25, 30]]); | ||
}, _callee, this, [[12, 18], [26, 31]]); | ||
})); | ||
@@ -123,0 +126,0 @@ |
@@ -42,3 +42,3 @@ 'use strict'; | ||
}), | ||
broadcastCacheUpdate: joi.object().keys({ | ||
broadcastUpdate: joi.object().keys({ | ||
channelName: joi.string().required(), | ||
@@ -45,0 +45,0 @@ options: joi.object() |
@@ -27,3 +27,4 @@ 'use strict'; | ||
importScripts: joi.array().items(joi.string()).required(), | ||
modulePathPrefix: joi.string() | ||
modulePathPrefix: joi.string(), | ||
workboxSWImport: joi.string() | ||
}); |
@@ -25,3 +25,3 @@ 'use strict'; | ||
module.exports = baseSchema.keys({ | ||
globDirectory: joi.string().required() | ||
globDirectory: joi.string() | ||
}); |
@@ -43,9 +43,12 @@ 'use strict'; | ||
* | ||
* const cdnTransform = (manifestEntries) => manifestEntries.map(entry => { | ||
* const cdnOrigin = 'https://example.com'; | ||
* if (entry.url.startsWith('/assets/')) { | ||
* entry.url = cdnOrigin + entry.url; | ||
* } | ||
* return entry; | ||
* }); | ||
* const cdnTransform = (manifestEntries) => { | ||
* const manifest = manifestEntries.map(entry => { | ||
* const cdnOrigin = 'https://example.com'; | ||
* if (entry.url.startsWith('/assets/')) { | ||
* entry.url = cdnOrigin + entry.url; | ||
* } | ||
* return entry; | ||
* }); | ||
* return {manifest, warnings: []}; | ||
* }; | ||
* | ||
@@ -57,3 +60,3 @@ * @example <caption>A transformation that removes the revision field when the | ||
* const removeRevisionTransform = (manifestEntries) => { | ||
* return manifestEntries.map(entry => { | ||
* const manifest = manifestEntries.map(entry => { | ||
* const hashRegExp = /\.\w{8}\./; | ||
@@ -65,2 +68,3 @@ * if (entry.url.match(hashRegExp)) { | ||
* }); | ||
* return {manifest, warnings: []}; | ||
* }; | ||
@@ -71,4 +75,5 @@ * | ||
* prior to the current transformation. | ||
* @return {Array<ManifestEntry>} The array of entries with the transformation | ||
* applied. | ||
* @return {{manifest: Array<ManifestEntry>, warnings: Array<String>|undefined}} | ||
* The array of entries with the transformation applied, and optionally, any | ||
* warnings that should be reported back to the build tool. | ||
* | ||
@@ -85,2 +90,4 @@ * @memberof module:workbox-build | ||
var allWarnings = []; | ||
// Take the array of fileDetail objects and convert it into an array of | ||
@@ -113,11 +120,3 @@ // {url, revision, size} objects, with \ replaced with /. | ||
// Apply the transformations sequentially. | ||
var transformedManifest = transformsToApply.reduce(function (previousManifest, transform) { | ||
return transform(previousManifest); | ||
}, normalizedManifest); | ||
// Generate some metadata about the manifest before we clear out the size | ||
// properties from each entry. | ||
var count = transformedManifest.length; | ||
var size = 0; | ||
var transformedManifest = normalizedManifest; | ||
var _iteratorNormalCompletion = true; | ||
@@ -128,8 +127,15 @@ var _didIteratorError = false; | ||
try { | ||
for (var _iterator = (0, _getIterator3.default)(transformedManifest), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var manifestEntry = _step.value; | ||
for (var _iterator = (0, _getIterator3.default)(transformsToApply), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var transform = _step.value; | ||
size += manifestEntry.size; | ||
delete manifestEntry.size; | ||
var _transform = transform(transformedManifest), | ||
manifest = _transform.manifest, | ||
warnings = _transform.warnings; | ||
transformedManifest = manifest; | ||
allWarnings = allWarnings.concat(warnings || []); | ||
} | ||
// Generate some metadata about the manifest before we clear out the size | ||
// properties from each entry. | ||
} catch (err) { | ||
@@ -150,7 +156,36 @@ _didIteratorError = true; | ||
var count = transformedManifest.length; | ||
var size = 0; | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
try { | ||
for (var _iterator2 = (0, _getIterator3.default)(transformedManifest), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var manifestEntry = _step2.value; | ||
size += manifestEntry.size; | ||
delete manifestEntry.size; | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2.return) { | ||
_iterator2.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
return { | ||
count, | ||
size, | ||
manifestEntries: transformedManifest | ||
manifestEntries: transformedManifest, | ||
warnings: allWarnings | ||
}; | ||
}; |
@@ -52,3 +52,3 @@ 'use strict'; | ||
if (globbedFiles.length === 0) { | ||
throw new Error(errors['useless-glob-pattern'] + (0, _stringify2.default)({ globDirectory, globPattern, globIgnores }, null, 2)); | ||
throw new Error(errors['useless-glob-pattern'] + ' ' + (0, _stringify2.default)({ globDirectory, globPattern, globIgnores }, null, 2)); | ||
} | ||
@@ -55,0 +55,0 @@ |
@@ -68,3 +68,3 @@ 'use strict'; | ||
var fileDetails, fileSet, _loop, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, url; | ||
var warnings, fileDetails, fileSet, _loop, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, url, filteredFiles, _filteredFiles$warnin; | ||
@@ -75,4 +75,6 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
case 0: | ||
warnings = []; | ||
// Initialize to an empty array so that we can still pass something to | ||
// filterFiles() and get a normalized output. | ||
fileDetails = []; | ||
@@ -88,25 +90,31 @@ fileSet = new _set2.default(); | ||
fileDetails = globPatterns.reduce(function (accumulated, globPattern) { | ||
var globbedFileDetails = getFileDetails({ | ||
globDirectory, | ||
globFollow, | ||
globIgnores, | ||
globPattern, | ||
globStrict | ||
}); | ||
try { | ||
fileDetails = globPatterns.reduce(function (accumulated, globPattern) { | ||
var globbedFileDetails = getFileDetails({ | ||
globDirectory, | ||
globFollow, | ||
globIgnores, | ||
globPattern, | ||
globStrict | ||
}); | ||
globbedFileDetails.forEach(function (fileDetails) { | ||
if (fileSet.has(fileDetails.file)) { | ||
return; | ||
} | ||
globbedFileDetails.forEach(function (fileDetails) { | ||
if (fileSet.has(fileDetails.file)) { | ||
return; | ||
} | ||
fileSet.add(fileDetails.file); | ||
accumulated.push(fileDetails); | ||
}); | ||
return accumulated; | ||
}, []); | ||
fileSet.add(fileDetails.file); | ||
accumulated.push(fileDetails); | ||
}); | ||
return accumulated; | ||
}, []); | ||
} catch (error) { | ||
// If there's an exception thrown while globbing, then report | ||
// it back as a warning, and don't consider it fatal. | ||
warnings.push(error.message); | ||
} | ||
} | ||
if (!templatedUrls) { | ||
_context.next = 24; | ||
_context.next = 25; | ||
break; | ||
@@ -145,3 +153,3 @@ } | ||
_iteratorError = undefined; | ||
_context.prev = 8; | ||
_context.prev = 9; | ||
@@ -153,14 +161,14 @@ for (_iterator = (0, _getIterator3.default)((0, _keys2.default)(templatedUrls)); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
} | ||
_context.next = 16; | ||
_context.next = 17; | ||
break; | ||
case 12: | ||
_context.prev = 12; | ||
_context.t0 = _context['catch'](8); | ||
case 13: | ||
_context.prev = 13; | ||
_context.t0 = _context['catch'](9); | ||
_didIteratorError = true; | ||
_iteratorError = _context.t0; | ||
case 16: | ||
_context.prev = 16; | ||
case 17: | ||
_context.prev = 17; | ||
_context.prev = 18; | ||
@@ -171,7 +179,7 @@ if (!_iteratorNormalCompletion && _iterator.return) { | ||
case 19: | ||
_context.prev = 19; | ||
case 20: | ||
_context.prev = 20; | ||
if (!_didIteratorError) { | ||
_context.next = 22; | ||
_context.next = 23; | ||
break; | ||
@@ -182,13 +190,21 @@ } | ||
case 22: | ||
return _context.finish(19); | ||
case 23: | ||
return _context.finish(16); | ||
return _context.finish(20); | ||
case 24: | ||
return _context.abrupt('return', filterFiles({ fileDetails, maximumFileSizeToCacheInBytes, | ||
modifyUrlPrefix, dontCacheBustUrlsMatching, manifestTransforms })); | ||
return _context.finish(17); | ||
case 25: | ||
filteredFiles = filterFiles({ fileDetails, | ||
maximumFileSizeToCacheInBytes, modifyUrlPrefix, dontCacheBustUrlsMatching, | ||
manifestTransforms }); | ||
if (warnings.length > 0) { | ||
(_filteredFiles$warnin = filteredFiles.warnings).push.apply(_filteredFiles$warnin, warnings); | ||
} | ||
return _context.abrupt('return', filteredFiles); | ||
case 28: | ||
case 'end': | ||
@@ -198,3 +214,3 @@ return _context.stop(); | ||
} | ||
}, _callee, undefined, [[8, 12, 16, 24], [17,, 19, 23]]); | ||
}, _callee, undefined, [[9, 13, 17, 25], [18,, 20, 24]]); | ||
})); | ||
@@ -201,0 +217,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -19,8 +19,18 @@ /* | ||
var prettyBytes = require('pretty-bytes'); | ||
module.exports = function (maximumFileSizeToCacheInBytes) { | ||
return function (manifest) { | ||
return manifest.filter(function (entry) { | ||
return entry.size <= maximumFileSizeToCacheInBytes; | ||
return function (originalManifest) { | ||
var warnings = []; | ||
var manifest = originalManifest.filter(function (entry) { | ||
if (entry.size <= maximumFileSizeToCacheInBytes) { | ||
return true; | ||
} | ||
warnings.push(`${entry.url} is ${prettyBytes(entry.size)}, and won't ` + `be precached. Configure maximumFileSizeToCacheInBytes to change ` + `this limit.`); | ||
return false; | ||
}); | ||
return { manifest, warnings }; | ||
}; | ||
}; |
@@ -71,4 +71,4 @@ 'use strict'; | ||
return function (manifest) { | ||
return manifest.map(function (entry) { | ||
return function (originalManifest) { | ||
var manifest = originalManifest.map(function (entry) { | ||
if (typeof entry.url !== 'string') { | ||
@@ -84,3 +84,5 @@ throw new Error(errors['manifest-entry-bad-url']); | ||
}); | ||
return { manifest }; | ||
}; | ||
}; |
@@ -26,4 +26,4 @@ 'use strict'; | ||
return function (manifest) { | ||
return manifest.map(function (entry) { | ||
return function (originalManifest) { | ||
var manifest = originalManifest.map(function (entry) { | ||
if (typeof entry.url !== 'string') { | ||
@@ -36,5 +36,8 @@ throw new Error(errors['manifest-entry-bad-url']); | ||
} | ||
return entry; | ||
}); | ||
return { manifest }; | ||
}; | ||
}; |
@@ -43,3 +43,4 @@ 'use strict'; | ||
runtimeCaching = _ref.runtimeCaching, | ||
skipWaiting = _ref.skipWaiting; | ||
skipWaiting = _ref.skipWaiting, | ||
workboxSWImport = _ref.workboxSWImport; | ||
@@ -71,3 +72,4 @@ // These are all options that can be passed to the precacheAndRoute() method. | ||
skipWaiting, | ||
runtimeCaching: runtimeCachingConverter(runtimeCaching) | ||
runtimeCaching: runtimeCachingConverter(runtimeCaching), | ||
workboxSWImport | ||
}); | ||
@@ -74,0 +76,0 @@ |
@@ -77,3 +77,3 @@ 'use strict'; | ||
backgroundSync: 'workbox.backgroundSync.Plugin', | ||
broadcastCacheUpdate: 'workbox.broadcastCacheUpdate.Plugin', | ||
broadcastUpdate: 'workbox.broadcastUpdate.Plugin', | ||
expiration: 'workbox.expiration.Plugin', | ||
@@ -80,0 +80,0 @@ cacheableResponse: 'workbox.cacheableResponse.Plugin' |
@@ -50,3 +50,4 @@ 'use strict'; | ||
skipWaiting = _ref.skipWaiting, | ||
swDest = _ref.swDest; | ||
swDest = _ref.swDest, | ||
workboxSWImport = _ref.workboxSWImport; | ||
var populatedTemplate; | ||
@@ -84,3 +85,4 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
runtimeCaching, | ||
skipWaiting | ||
skipWaiting, | ||
workboxSWImport | ||
}); | ||
@@ -87,0 +89,0 @@ _context.prev = 9; |
@@ -29,5 +29,9 @@ "use strict"; | ||
* and re-run your build process. | ||
* See https://goo.gl/YYPcyY | ||
* See https://goo.gl/2aRDsh | ||
*/ | ||
<% if (workboxSWImport) { %> | ||
importScripts(<%= JSON.stringify(workboxSWImport) %>); | ||
<% if (modulePathPrefix) { %>workbox.setConfig({modulePathPrefix: <%= JSON.stringify(modulePathPrefix) %>});<% } %> | ||
<% } %> | ||
<% if (importScripts) { %> | ||
@@ -39,3 +43,2 @@ importScripts( | ||
<% if (modulePathPrefix) { %>workbox.setConfig({modulePathPrefix: <%= JSON.stringify(modulePathPrefix) %>});<% } %> | ||
<% if (cacheId) { %>workbox.core.setCacheNameDetails({prefix: <%= JSON.stringify(cacheId) %>});<% } %> | ||
@@ -42,0 +45,0 @@ |
{ | ||
"name": "workbox-build", | ||
"version": "3.0.0-beta.0", | ||
"version": "3.0.0-beta.1", | ||
"description": "A module that integrates into your build process, helping you generate a manifest of local files that workbox-sw should precache.", | ||
@@ -29,12 +29,13 @@ "keywords": [ | ||
"lodash.template": "^4.4.0", | ||
"workbox-background-sync": "^3.0.0-beta.0", | ||
"workbox-broadcast-cache-update": "^3.0.0-beta.0", | ||
"workbox-cache-expiration": "^3.0.0-beta.0", | ||
"workbox-cacheable-response": "^3.0.0-beta.0", | ||
"workbox-core": "^3.0.0-beta.0", | ||
"workbox-google-analytics": "^3.0.0-beta.0", | ||
"workbox-precaching": "^3.0.0-beta.0", | ||
"workbox-routing": "^3.0.0-beta.0", | ||
"workbox-strategies": "^3.0.0-beta.0", | ||
"workbox-sw": "^3.0.0-beta.0" | ||
"pretty-bytes": "^4.0.2", | ||
"workbox-background-sync": "^3.0.0-beta.1", | ||
"workbox-broadcast-cache-update": "^3.0.0-beta.1", | ||
"workbox-cache-expiration": "^3.0.0-beta.1", | ||
"workbox-cacheable-response": "^3.0.0-beta.1", | ||
"workbox-core": "^3.0.0-beta.1", | ||
"workbox-google-analytics": "^3.0.0-beta.1", | ||
"workbox-precaching": "^3.0.0-beta.1", | ||
"workbox-routing": "^3.0.0-beta.1", | ||
"workbox-strategies": "^3.0.0-beta.1", | ||
"workbox-sw": "^3.0.0-beta.1" | ||
}, | ||
@@ -41,0 +42,0 @@ "main": "build/index.js", |
@@ -5,3 +5,3 @@ { | ||
"releasesDir": "releases", | ||
"latestVersion": "3.0.0-beta.0" | ||
"latestVersion": "3.0.0-beta.1" | ||
} |
@@ -28,4 +28,6 @@ /* | ||
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#generateswstring_mode). | ||
* @return {Promise<String>} A populated service worker template, based on the | ||
* other configuration options provided. | ||
* @return {Promise<{swString: String, warnings: Array<String>}>} A promise that | ||
* resolves once the service worker template is populated. The `swString` | ||
* property contains a string representation of the full service worker code. | ||
* Any non-fatal warning messages will be returned via `warnings`. | ||
* | ||
@@ -37,9 +39,11 @@ * @memberof module:workbox-build | ||
const {manifestEntries} = await getFileManifestEntries(options); | ||
const {manifestEntries, warnings} = await getFileManifestEntries(options); | ||
return populateSWTemplate(Object.assign({ | ||
const swString = await populateSWTemplate(Object.assign({ | ||
manifestEntries, | ||
}, options)); | ||
return {swString, warnings}; | ||
} | ||
module.exports = generateSWString; |
@@ -39,6 +39,8 @@ /* | ||
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config). | ||
* @return {Promise<{count: Number, size: Number}>} A promise that resolves once | ||
* the service worker file has been written to `swDest`. The `size` property | ||
* contains the aggregate size of all the precached entries, in bytes, and the | ||
* `count` property contains the total number of precached entries. | ||
* @return {Promise<{count: Number, size: Number, warnings: Array<String>}>} | ||
* A promise that resolves once the service worker file has been written to | ||
* `swDest`. The `size` property contains the aggregate size of all the | ||
* precached entries, in bytes, and the `count` property contains the total | ||
* number of precached entries. Any non-fatal warning messages will be returned | ||
* via `warnings`. | ||
* | ||
@@ -55,5 +57,3 @@ * @memberof module:workbox-build | ||
const cdnUrl = cdnUtils.getModuleUrl('workbox-sw'); | ||
// importScripts may or may not already be an array containing other URLs. | ||
// Either way, list cdnUrl first. | ||
options.importScripts = [cdnUrl].concat(options.importScripts || []); | ||
options.workboxSWImport = cdnUrl; | ||
} else if (options.importWorkboxFrom === 'local') { | ||
@@ -72,12 +72,8 @@ // Copy over the dev + prod version of all of the core libraries. | ||
// importScripts may or may not already be an array containing other URLs. | ||
// Either way, list workboxSWFilename first. | ||
options.importScripts = [ | ||
`${workboxDirectoryName}/${workboxSWFilename}`, | ||
].concat(options.importScripts || []); | ||
options.workboxSWImport = `${workboxDirectoryName}/${workboxSWFilename}`; | ||
options.modulePathPrefix = workboxDirectoryName; | ||
} | ||
const {count, size, manifestEntries} = await getFileManifestEntries(options); | ||
const {count, size, manifestEntries, warnings} = | ||
await getFileManifestEntries(options); | ||
@@ -88,5 +84,5 @@ await writeServiceWorkerUsingDefaultTemplate(Object.assign({ | ||
return {count, size}; | ||
return {count, size, warnings}; | ||
} | ||
module.exports = generateSW; |
@@ -29,7 +29,8 @@ /* | ||
* @return {Promise<{manifestEntries: Array<ManifestEntry>, | ||
* count: Number, size: Number}>} A promise that resolves once the precache | ||
* manifest is determined. The `size` property contains the aggregate size of | ||
* all the precached entries, in bytes, the `count` property contains the total | ||
* number of precached entries, and the `manifestEntries` property contains all | ||
* the `ManifestEntry` items. | ||
* count: Number, size: Number, warnings: Array<String>}>} A promise that | ||
* resolves once the precache manifest is determined. The `size` property | ||
* contains the aggregate size of all the precached entries, in bytes, the | ||
* `count` property contains the total number of precached entries, and the | ||
* `manifestEntries` property contains all the `ManifestEntry` items. Any | ||
* non-fatal warning messages will be returned via `warnings`. | ||
* | ||
@@ -41,6 +42,7 @@ * @memberof module:workbox-build | ||
const {manifestEntries, count, size} = await getFileManifestEntries(options); | ||
return {manifestEntries, count, size}; | ||
const {manifestEntries, count, size, warnings} = | ||
await getFileManifestEntries(options); | ||
return {manifestEntries, count, size, warnings}; | ||
} | ||
module.exports = getManifest; |
@@ -39,6 +39,8 @@ /* | ||
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_injectmanifest_config). | ||
* @return {Promise<{count: Number, size: Number}>} A promise that resolves once | ||
* the service worker file has been written to `swDest`. The `size` property | ||
* contains the aggregate size of all the precached entries, in bytes, and the | ||
* `count` property contains the total number of precached entries. | ||
* @return {Promise<{count: Number, size: Number, warnings: Array<String>}>} | ||
* A promise that resolves once the service worker file has been written to | ||
* `swDest`. The `size` property contains the aggregate size of all the | ||
* precached entries, in bytes, and the `count` property contains the total | ||
* number of precached entries. Any non-fatal warning messages will be returned | ||
* via `warnings`. | ||
* | ||
@@ -56,3 +58,4 @@ * @memberof module:workbox-build | ||
const {count, size, manifestEntries} = await getFileManifestEntries(options); | ||
const {count, size, manifestEntries, warnings} = | ||
await getFileManifestEntries(options); | ||
let swFileContents; | ||
@@ -89,5 +92,5 @@ try { | ||
return {count, size}; | ||
return {count, size, warnings}; | ||
} | ||
module.exports = injectManifest; |
@@ -46,3 +46,3 @@ /* | ||
}), | ||
broadcastCacheUpdate: joi.object().keys({ | ||
broadcastUpdate: joi.object().keys({ | ||
channelName: joi.string().required(), | ||
@@ -49,0 +49,0 @@ options: joi.object(), |
@@ -26,2 +26,3 @@ /* | ||
modulePathPrefix: joi.string(), | ||
workboxSWImport: joi.string(), | ||
}); |
@@ -23,3 +23,3 @@ /* | ||
module.exports = baseSchema.keys({ | ||
globDirectory: joi.string().required(), | ||
globDirectory: joi.string(), | ||
}); |
@@ -36,9 +36,12 @@ /* | ||
* | ||
* const cdnTransform = (manifestEntries) => manifestEntries.map(entry => { | ||
* const cdnOrigin = 'https://example.com'; | ||
* if (entry.url.startsWith('/assets/')) { | ||
* entry.url = cdnOrigin + entry.url; | ||
* } | ||
* return entry; | ||
* }); | ||
* const cdnTransform = (manifestEntries) => { | ||
* const manifest = manifestEntries.map(entry => { | ||
* const cdnOrigin = 'https://example.com'; | ||
* if (entry.url.startsWith('/assets/')) { | ||
* entry.url = cdnOrigin + entry.url; | ||
* } | ||
* return entry; | ||
* }); | ||
* return {manifest, warnings: []}; | ||
* }; | ||
* | ||
@@ -50,3 +53,3 @@ * @example <caption>A transformation that removes the revision field when the | ||
* const removeRevisionTransform = (manifestEntries) => { | ||
* return manifestEntries.map(entry => { | ||
* const manifest = manifestEntries.map(entry => { | ||
* const hashRegExp = /\.\w{8}\./; | ||
@@ -58,2 +61,3 @@ * if (entry.url.match(hashRegExp)) { | ||
* }); | ||
* return {manifest, warnings: []}; | ||
* }; | ||
@@ -64,4 +68,5 @@ * | ||
* prior to the current transformation. | ||
* @return {Array<ManifestEntry>} The array of entries with the transformation | ||
* applied. | ||
* @return {{manifest: Array<ManifestEntry>, warnings: Array<String>|undefined}} | ||
* The array of entries with the transformation applied, and optionally, any | ||
* warnings that should be reported back to the build tool. | ||
* | ||
@@ -78,2 +83,4 @@ * @memberof module:workbox-build | ||
}) => { | ||
let allWarnings = []; | ||
// Take the array of fileDetail objects and convert it into an array of | ||
@@ -107,6 +114,8 @@ // {url, revision, size} objects, with \ replaced with /. | ||
// Apply the transformations sequentially. | ||
const transformedManifest = transformsToApply.reduce( | ||
(previousManifest, transform) => transform(previousManifest), | ||
normalizedManifest); | ||
let transformedManifest = normalizedManifest; | ||
for (const transform of transformsToApply) { | ||
const {manifest, warnings} = transform(transformedManifest); | ||
transformedManifest = manifest; | ||
allWarnings = allWarnings.concat(warnings || []); | ||
} | ||
@@ -126,3 +135,4 @@ // Generate some metadata about the manifest before we clear out the size | ||
manifestEntries: transformedManifest, | ||
warnings: allWarnings, | ||
}; | ||
}; |
@@ -45,3 +45,3 @@ /* | ||
if (globbedFiles.length === 0) { | ||
throw new Error(errors['useless-glob-pattern'] + | ||
throw new Error(errors['useless-glob-pattern'] + ' ' + | ||
JSON.stringify({globDirectory, globPattern, globIgnores}, null, 2)); | ||
@@ -48,0 +48,0 @@ } |
@@ -39,2 +39,3 @@ /* | ||
}) => { | ||
const warnings = []; | ||
// Initialize to an empty array so that we can still pass something to | ||
@@ -51,21 +52,27 @@ // filterFiles() and get a normalized output. | ||
fileDetails = globPatterns.reduce((accumulated, globPattern) => { | ||
const globbedFileDetails = getFileDetails({ | ||
globDirectory, | ||
globFollow, | ||
globIgnores, | ||
globPattern, | ||
globStrict, | ||
}); | ||
try { | ||
fileDetails = globPatterns.reduce((accumulated, globPattern) => { | ||
const globbedFileDetails = getFileDetails({ | ||
globDirectory, | ||
globFollow, | ||
globIgnores, | ||
globPattern, | ||
globStrict, | ||
}); | ||
globbedFileDetails.forEach((fileDetails) => { | ||
if (fileSet.has(fileDetails.file)) { | ||
return; | ||
} | ||
globbedFileDetails.forEach((fileDetails) => { | ||
if (fileSet.has(fileDetails.file)) { | ||
return; | ||
} | ||
fileSet.add(fileDetails.file); | ||
accumulated.push(fileDetails); | ||
}); | ||
return accumulated; | ||
}, []); | ||
fileSet.add(fileDetails.file); | ||
accumulated.push(fileDetails); | ||
}); | ||
return accumulated; | ||
}, []); | ||
} catch (error) { | ||
// If there's an exception thrown while globbing, then report | ||
// it back as a warning, and don't consider it fatal. | ||
warnings.push(error.message); | ||
} | ||
} | ||
@@ -104,4 +111,11 @@ | ||
return filterFiles({fileDetails, maximumFileSizeToCacheInBytes, | ||
modifyUrlPrefix, dontCacheBustUrlsMatching, manifestTransforms}); | ||
const filteredFiles = filterFiles({fileDetails, | ||
maximumFileSizeToCacheInBytes, modifyUrlPrefix, dontCacheBustUrlsMatching, | ||
manifestTransforms}); | ||
if (warnings.length > 0) { | ||
filteredFiles.warnings.push(...warnings); | ||
} | ||
return filteredFiles; | ||
}; |
@@ -17,6 +17,20 @@ /* | ||
const prettyBytes = require('pretty-bytes'); | ||
module.exports = (maximumFileSizeToCacheInBytes) => { | ||
return (manifest) => manifest.filter((entry) => { | ||
return entry.size <= maximumFileSizeToCacheInBytes; | ||
}); | ||
return (originalManifest) => { | ||
const warnings = []; | ||
const manifest = originalManifest.filter((entry) => { | ||
if (entry.size <= maximumFileSizeToCacheInBytes) { | ||
return true; | ||
} | ||
warnings.push(`${entry.url} is ${prettyBytes(entry.size)}, and won't ` + | ||
`be precached. Configure maximumFileSizeToCacheInBytes to change ` + | ||
`this limit.`); | ||
return false; | ||
}); | ||
return {manifest, warnings}; | ||
}; | ||
}; |
@@ -63,13 +63,17 @@ /* | ||
return (manifest) => manifest.map((entry) => { | ||
if (typeof entry.url !== 'string') { | ||
throw new Error(errors['manifest-entry-bad-url']); | ||
} | ||
return (originalManifest) => { | ||
const manifest = originalManifest.map((entry) => { | ||
if (typeof entry.url !== 'string') { | ||
throw new Error(errors['manifest-entry-bad-url']); | ||
} | ||
entry.url = entry.url.replace(modifyRegex, (match) => { | ||
return modifyUrlPrefix[match]; | ||
entry.url = entry.url.replace(modifyRegex, (match) => { | ||
return modifyUrlPrefix[match]; | ||
}); | ||
return entry; | ||
}); | ||
return entry; | ||
}); | ||
return {manifest}; | ||
}; | ||
}; |
@@ -24,12 +24,17 @@ /* | ||
return (manifest) => manifest.map((entry) => { | ||
if (typeof entry.url !== 'string') { | ||
throw new Error(errors['manifest-entry-bad-url']); | ||
} | ||
return (originalManifest) => { | ||
const manifest = originalManifest.map((entry) => { | ||
if (typeof entry.url !== 'string') { | ||
throw new Error(errors['manifest-entry-bad-url']); | ||
} | ||
if (entry.url.match(regexp)) { | ||
delete entry.revision; | ||
} | ||
return entry; | ||
}); | ||
if (entry.url.match(regexp)) { | ||
delete entry.revision; | ||
} | ||
return entry; | ||
}); | ||
return {manifest}; | ||
}; | ||
}; |
@@ -36,2 +36,3 @@ /* | ||
skipWaiting, | ||
workboxSWImport, | ||
}) => { | ||
@@ -70,2 +71,3 @@ // These are all options that can be passed to the precacheAndRoute() method. | ||
runtimeCaching: runtimeCachingConverter(runtimeCaching), | ||
workboxSWImport, | ||
}); | ||
@@ -72,0 +74,0 @@ |
@@ -47,3 +47,3 @@ /* | ||
backgroundSync: 'workbox.backgroundSync.Plugin', | ||
broadcastCacheUpdate: 'workbox.broadcastCacheUpdate.Plugin', | ||
broadcastUpdate: 'workbox.broadcastUpdate.Plugin', | ||
expiration: 'workbox.expiration.Plugin', | ||
@@ -50,0 +50,0 @@ cacheableResponse: 'workbox.cacheableResponse.Plugin', |
@@ -38,2 +38,3 @@ /* | ||
swDest, | ||
workboxSWImport, | ||
}) => { | ||
@@ -61,2 +62,3 @@ try { | ||
skipWaiting, | ||
workboxSWImport, | ||
}); | ||
@@ -63,0 +65,0 @@ |
@@ -27,5 +27,9 @@ /* | ||
* and re-run your build process. | ||
* See https://goo.gl/YYPcyY | ||
* See https://goo.gl/2aRDsh | ||
*/ | ||
<% if (workboxSWImport) { %> | ||
importScripts(<%= JSON.stringify(workboxSWImport) %>); | ||
<% if (modulePathPrefix) { %>workbox.setConfig({modulePathPrefix: <%= JSON.stringify(modulePathPrefix) %>});<% } %> | ||
<% } %> | ||
<% if (importScripts) { %> | ||
@@ -37,3 +41,2 @@ importScripts( | ||
<% if (modulePathPrefix) { %>workbox.setConfig({modulePathPrefix: <%= JSON.stringify(modulePathPrefix) %>});<% } %> | ||
<% if (cacheId) { %>workbox.core.setCacheNameDetails({prefix: <%= JSON.stringify(cacheId) %>});<% } %> | ||
@@ -40,0 +43,0 @@ |
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
155586
3570
17
+ Addedpretty-bytes@^4.0.2
+ Addedpretty-bytes@4.0.2(transitive)
Updatedworkbox-core@^3.0.0-beta.1
Updatedworkbox-sw@^3.0.0-beta.1