workbox-build
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -58,3 +58,3 @@ // This will be the logic that powers both module and CLI | ||
* globIgnores: ['service-worker.js','admin.html'], | ||
* mainfestDest: './build/scripts/manifest.js', | ||
* manifestDest: './build/scripts/manifest.js', | ||
* templatedUrls: { | ||
@@ -61,0 +61,0 @@ * '/shell': ['shell.hbs', 'main.css', 'shell.css'], |
module.exports = { | ||
// Max File Size: 2MB | ||
maximumFileSize: 2 * 1024 * 1024, | ||
defaultGlobIgnores: [ | ||
'node_modules/**/*', | ||
], | ||
}; |
@@ -28,2 +28,4 @@ module.exports = { | ||
'sw-write-failure': 'Unable to write the service worker file.', | ||
'sw-write-failure-directory': 'Unable to write the service worker file; ' + | ||
'swDest should be a full path to the file, not a path to a directory.', | ||
'unable-to-copy-workbox-sw': 'workbox-sw is needed by the service worker ' + | ||
@@ -79,2 +81,6 @@ 'and could not be copied over to your new site.', | ||
`dynamicUrlToDependencies are set. Please fully migrate to templatedUrls.`, | ||
'urlPattern-is-required': `The urlPattern option is required when using | ||
runtimeCaching.`, | ||
'handler-is-required': `The handler option is required when using | ||
runtimeCaching.`, | ||
}; |
@@ -6,2 +6,3 @@ const path = require('path'); | ||
const errors = require('./errors'); | ||
const constants = require('./constants'); | ||
@@ -21,3 +22,4 @@ /** | ||
* of these glob patterns will be excluded from the file manifest, even if the | ||
* file matches against a `globPatterns` pattern. | ||
* file matches against a `globPatterns` pattern. Defaults to ignoring | ||
* 'node_modules'. | ||
* @param {Object<String,Array|String>} [input.templatedUrls] | ||
@@ -99,2 +101,5 @@ * If a URL is rendered with templates on the server, its contents may | ||
// Type check input so that defaults can be used if appropriate. | ||
if (typeof input.globIgnores === 'string') { | ||
input.globIgnores = [input.globIgnores]; | ||
} | ||
if (input.globIgnores && !(Array.isArray(input.globIgnores))) { | ||
@@ -122,3 +127,3 @@ return Promise.reject( | ||
const globDirectory = input.globDirectory; | ||
input.globIgnores = input.globIgnores || []; | ||
input.globIgnores = input.globIgnores || constants.defaultGlobIgnores; | ||
const swDest = input.swDest; | ||
@@ -125,0 +130,0 @@ |
@@ -6,2 +6,3 @@ const errors = require('./errors'); | ||
const getStringDetails = require('./utils/get-string-details'); | ||
const constants = require('./constants'); | ||
@@ -28,3 +29,4 @@ /** | ||
* of these glob patterns will be excluded from the file manifest, even if the | ||
* file matches against a `globPatterns` pattern. | ||
* file matches against a `globPatterns` pattern. Defaults to ignoring | ||
* 'node_modules'. | ||
* @param {Object<String,Array|String>} [input.templatedUrls] | ||
@@ -44,3 +46,3 @@ * If a URL is rendered with templates on the server, its contents may | ||
* regex. Useful if you have assets with file revisions in the URL. | ||
* @return {Array<ManifestEntry>} | ||
* @return {Promise<Array<ManifestEntry>>} | ||
* An array of {@link module:workbox-build#ManifestEntry|ManifestEntries} | ||
@@ -52,3 +54,4 @@ * which will include a url and revision parameter. | ||
if (!input || typeof input !== 'object' || Array.isArray(input)) { | ||
throw new Error(errors['invalid-get-manifest-entries-input']); | ||
return Promise.reject( | ||
new Error(errors['invalid-get-manifest-entries-input'])); | ||
} | ||
@@ -58,7 +61,8 @@ | ||
if (input.globPatterns && input.staticFileGlobs) { | ||
throw new Error(errors['both-glob-patterns-static-file-globs']); | ||
return Promise.reject( | ||
new Error(errors['both-glob-patterns-static-file-globs'])); | ||
} | ||
const globPatterns = input.globPatterns || input.staticFileGlobs; | ||
const globIgnores = input.globIgnores ? input.globIgnores : []; | ||
const globIgnores = input.globIgnores || constants.defaultGlobIgnores; | ||
const globDirectory = input.globDirectory; | ||
@@ -68,3 +72,4 @@ | ||
if (input.templatedUrls && input.dynamicUrlToDependencies) { | ||
throw new Error(errors['both-templated-urls-dynamic-urls']); | ||
return Promise.reject( | ||
new Error(errors['both-templated-urls-dynamic-urls'])); | ||
} | ||
@@ -131,16 +136,20 @@ const templatedUrls = input.templatedUrls || input.dynamicUrlToDependencies; | ||
if (Array.isArray(dependencies)) { | ||
const dependencyDetails = dependencies.reduce((previous, pattern) => { | ||
try { | ||
const globbedFileDetails = getFileDetails( | ||
globDirectory, pattern, globIgnores); | ||
return previous.concat(globbedFileDetails); | ||
} catch (err) { | ||
const debugObj = {}; | ||
debugObj[url] = dependencies; | ||
throw new Error(`${errors['bad-template-urls-asset']} ` + | ||
`'${pattern}' in templateUrl '${JSON.stringify(debugObj)}' ` + | ||
`could not be found.`); | ||
} | ||
}, []); | ||
fileDetails.push(getCompositeDetails(url, dependencyDetails)); | ||
try { | ||
const dependencyDetails = dependencies.reduce((previous, pattern) => { | ||
try { | ||
const globbedFileDetails = getFileDetails( | ||
globDirectory, pattern, globIgnores); | ||
return previous.concat(globbedFileDetails); | ||
} catch (err) { | ||
const debugObj = {}; | ||
debugObj[url] = dependencies; | ||
throw new Error(`${errors['bad-template-urls-asset']} ` + | ||
`'${pattern}' in templateUrl '${JSON.stringify(debugObj)}' ` + | ||
`could not be found.`); | ||
} | ||
}, []); | ||
fileDetails.push(getCompositeDetails(url, dependencyDetails)); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} else if (typeof dependencies === 'string') { | ||
@@ -147,0 +156,0 @@ fileDetails.push(getStringDetails(url, dependencies)); |
@@ -25,5 +25,2 @@ const path = require('path'); | ||
let url = fileDetails.file.replace(path.sep, '/'); | ||
if (!url.startsWith('/')) { | ||
url = '/' + url; | ||
} | ||
@@ -30,0 +27,0 @@ // Modify URL Prefix |
@@ -0,13 +1,13 @@ | ||
const errors = require('./errors'); | ||
const fs = require('fs'); | ||
const mkdirp = require('mkdirp'); | ||
const path = require('path'); | ||
const mkdirp = require('mkdirp'); | ||
const fs = require('fs'); | ||
const runtimeCachingConverter = require('./utils/runtime-caching-converter'); | ||
const template = require('lodash.template'); | ||
const errors = require('./errors'); | ||
module.exports = | ||
(swSrc, manifestEntries, workboxSWImportPath, globDirectory, options) => { | ||
(swDest, manifestEntries, workboxSWImportPath, globDirectory, options) => { | ||
options = options || {}; | ||
try { | ||
mkdirp.sync(path.dirname(swSrc)); | ||
mkdirp.sync(path.dirname(swDest)); | ||
} catch (err) { | ||
@@ -53,26 +53,5 @@ return Promise.reject( | ||
} | ||
let runtimeCaching = []; | ||
if (options.runtimeCaching) { | ||
options.runtimeCaching.forEach((cachingEntry) => { | ||
if (typeof cachingEntry.handler === 'string') { | ||
let handlerName = cachingEntry.handler === 'fastest' ? | ||
'staleWhileRevalidate' : cachingEntry.handler; | ||
let optionsString = cachingEntry.options ? | ||
JSON.stringify(cachingEntry.options, null, 2) : ''; | ||
let stratString = | ||
`workboxSW.strategies.${handlerName}(${optionsString})`; | ||
runtimeCaching.push( | ||
`workboxSW.router.registerRoute(${cachingEntry.urlPattern}, ` + | ||
`${stratString});` | ||
); | ||
} else if (typeof cachingEntry.handler === 'function') { | ||
let handlerString = cachingEntry.handler.toString(); | ||
runtimeCaching.push( | ||
`workboxSW.router.registerRoute(${cachingEntry.urlPattern}, ` + | ||
`${handlerString});` | ||
); | ||
} | ||
}); | ||
} | ||
const runtimeCaching = runtimeCachingConverter(options.runtimeCaching); | ||
try { | ||
@@ -105,7 +84,10 @@ let workboxSWOptionsString = ''; | ||
return new Promise((resolve, reject) => { | ||
fs.writeFile(swSrc, populatedTemplate, (err) => { | ||
if (err) { | ||
return reject( | ||
new Error(`${errors['sw-write-failure']}. '${err.message}'`) | ||
); | ||
fs.writeFile(swDest, populatedTemplate, (error) => { | ||
if (error) { | ||
if (error.code === 'EISDIR') { | ||
// See https://github.com/GoogleChrome/workbox/issues/612 | ||
return reject(new Error(errors['sw-write-failure-directory'])); | ||
} | ||
return reject(new Error( | ||
`${errors['sw-write-failure']}. '${error.message}'`)); | ||
} | ||
@@ -112,0 +94,0 @@ |
{ | ||
"name": "workbox-build", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A module that integrates into your build process, helping you generate a manifest of local files that workbox-sw should precache.", | ||
@@ -35,4 +35,4 @@ "keywords": [ | ||
"mkdirp": "^0.5.1", | ||
"workbox-sw": "^1.0.1" | ||
"workbox-sw": "^1.1.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
58821
26
1113
Updatedworkbox-sw@^1.1.0