Skip to content

Commit

Permalink
Move from importWorkboxFromCDN to importWorkboxFrom (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffposnick committed Dec 15, 2017
1 parent 7b82238 commit 7103d7b
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions packages/workbox-build/src/entry-points/generate-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ async function generateSW(config) {

const destDirectory = path.dirname(options.swDest);

if (options.importWorkboxFromCDN) {
// Do nothing if importWorkboxFrom is set to 'disabled'. Otherwise, check:
if (options.importWorkboxFrom === 'cdn') {
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 || []);
} else {
// If we're not importing the Workbox scripts from the CDN, then copy
// over the dev + prod version of all of the core libraries.
} else if (options.importWorkboxFrom === 'local') {
// Copy over the dev + prod version of all of the core libraries.
const workboxDirectoryName = await copyWorkboxLibraries(destDirectory);

// The Workbox library files should not be precached, since they're cached
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ module.exports = {
clientsClaim: false,
navigateFallback: undefined,
skipWaiting: false,
importWorkboxFromCDN: true,
importWorkboxFrom: 'cdn',
injectionPointRegexp: /(\.precacheAndRoute\()\s*\[\s*\]\s*(\))/,
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const defaults = require('./defaults');
module.exports = commonGenerateSchema.keys({
globDirectory: joi.string().required(),
importScripts: joi.array().items(joi.string()),
importWorkboxFromCDN: joi.boolean().default(defaults.importWorkboxFromCDN),
importWorkboxFrom: joi.string().default(defaults.importWorkboxFrom).valid(
'cdn',
'local',
'disabled'
),
swDest: joi.string().required(),
});
2 changes: 1 addition & 1 deletion packages/workbox-build/src/lib/copy-workbox-libraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const BUILD_TYPES = [
* prefer not to use the CDN copies of Workbox. Developers using
* [generateSW()]{@link module:workbox-build.generateSW} don't need to
* explicitly call this method, as it's called automatically when
* `importWorkboxFromCDN` is set to `false`.
* `importWorkboxFrom` is set to `local`.
*
* @param {string} destDirectory The path to the parent directory under which
* the new directory of libraries will be created.
Expand Down
2 changes: 1 addition & 1 deletion test/workbox-build/node/entry-points/generate-sw-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe(`[workbox-build] entry-points/generate-sw-string.js (End to End)`, func
'templatedUrls',
].concat(REQUIRED_PARAMS);
const UNSUPPORTED_PARAMS = [
'importWorkboxFromCDN',
'importWorkboxFrom',
'injectionPointRegexp',
'swDest',
'swSrc',
Expand Down
8 changes: 4 additions & 4 deletions test/workbox-build/node/entry-points/generate-sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe(`[workbox-build] entry-points/generate-sw.js (End to End)`, function()
'globStrict',
'ignoreUrlParametersMatching',
'importScripts',
'importWorkboxFromCDN',
'importWorkboxFrom',
'manifestTransforms',
'maximumFileSizeToCacheInBytes',
'modifyUrlPrefix',
Expand Down Expand Up @@ -132,11 +132,11 @@ describe(`[workbox-build] entry-points/generate-sw.js (End to End)`, function()
}});
});

it(`should use defaults and make local copies of the Workbox libraries when importWorkboxFromCDN is false`, async function() {
it(`should use defaults and make local copies of the Workbox libraries when importWorkboxFrom is 'local'`, async function() {
const swDest = path.join(tempy.directory(), 'sw.js');
const options = Object.assign({}, BASE_OPTIONS, {
swDest,
importWorkboxFromCDN: false,
importWorkboxFrom: 'local',
});

const {count, size} = await generateSW(options);
Expand Down Expand Up @@ -241,7 +241,7 @@ describe(`[workbox-build] entry-points/generate-sw.js (End to End)`, function()
const options = Object.assign({}, BASE_OPTIONS, {
globDirectory,
swDest,
importWorkboxFromCDN: false,
importWorkboxFrom: 'local',
});

const {count, size} = await generateSW(options);
Expand Down
2 changes: 1 addition & 1 deletion test/workbox-build/node/entry-points/get-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe(`[workbox-build] entry-points/get-manifest.js (End to End)`, function()
'directoryIndex',
'ignoreUrlParametersMatching',
'importScripts',
'importWorkboxFromCDN',
'importWorkboxFrom',
'injectionPointRegexp',
'navigateFallback',
'navigateFallbackWhitelist',
Expand Down
2 changes: 1 addition & 1 deletion test/workbox-build/node/entry-points/inject-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe(`[workbox-build] entry-points/inject-manifest.js (End to End)`, functio
'directoryIndex',
'ignoreUrlParametersMatching',
'importScripts',
'importWorkboxFromCDN',
'importWorkboxFrom',
'navigateFallback',
'navigateFallbackWhitelist',
'runtimeCaching',
Expand Down

0 comments on commit 7103d7b

Please sign in to comment.