WIP - add extractor, generate snippet_data

This commit is contained in:
Stefan Fejes
2019-08-20 15:52:05 +02:00
parent 88084d3d30
commit cc8f1d8a7a
37396 changed files with 4588842 additions and 133 deletions

3
node_modules/workbox-build/build/_types.js generated vendored Normal file
View File

@ -0,0 +1,3 @@
'use strict';
require('./_version.mjs');

6
node_modules/workbox-build/build/cdn-details.json generated vendored Normal file
View File

@ -0,0 +1,6 @@
{
"origin": "https://storage.googleapis.com",
"bucketName": "workbox-cdn",
"releasesDir": "releases",
"latestVersion": "3.6.3"
}

View File

@ -0,0 +1,89 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
/**
* This method generates a service worker based on the configuration options
* provided.
*
* @param {Object} config Please refer to the
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#generateswstring_mode).
* @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`.
*
* @memberof module:workbox-build
*/
var generateSWString = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) {
var options, _ref2, manifestEntries, warnings, swString;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
options = validate(config, generateSWStringSchema);
_context.next = 3;
return getFileManifestEntries(options);
case 3:
_ref2 = _context.sent;
manifestEntries = _ref2.manifestEntries;
warnings = _ref2.warnings;
_context.next = 8;
return populateSWTemplate((0, _assign2.default)({
manifestEntries
}, options));
case 8:
swString = _context.sent;
return _context.abrupt('return', { swString, warnings });
case 10:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function generateSWString(_x) {
return _ref.apply(this, arguments);
};
}();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var generateSWStringSchema = require('./options/generate-sw-string-schema');
var getFileManifestEntries = require('../lib/get-file-manifest-entries');
var populateSWTemplate = require('../lib/populate-sw-template');
var validate = require('./options/validate');
module.exports = generateSWString;

View File

@ -0,0 +1,142 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
/**
* This method creates a list of URLs to precache, referred to as a "precache
* manifest", based on the options you provide.
*
* It also takes in additional options that configures the service worker's
* behavior, like any `runtimeCaching` rules it should use.
*
* Based on the precache manifest and the additional configuration, it writes
* a ready-to-use service worker file to disk at `swDest`.
*
* @param {Object} config Please refer to the
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_generatesw_config).
* @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`.
*
* @memberof module:workbox-build
*/
var generateSW = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) {
var options, destDirectory, cdnUrl, workboxDirectoryName, workboxSWPkg, workboxSWFilename, _ref2, count, size, manifestEntries, warnings;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
options = validate(config, generateSWSchema);
destDirectory = path.dirname(options.swDest);
// Do nothing if importWorkboxFrom is set to 'disabled'. Otherwise, check:
if (!(options.importWorkboxFrom === 'cdn')) {
_context.next = 7;
break;
}
cdnUrl = cdnUtils.getModuleUrl('workbox-sw');
options.workboxSWImport = cdnUrl;
_context.next = 16;
break;
case 7:
if (!(options.importWorkboxFrom === 'local')) {
_context.next = 16;
break;
}
_context.next = 10;
return copyWorkboxLibraries(destDirectory);
case 10:
workboxDirectoryName = _context.sent;
// The Workbox library files should not be precached, since they're cached
// automatically by virtue of being used with importScripts().
options.globIgnores = [`**/${workboxDirectoryName}/*.js*`].concat(options.globIgnores || []);
workboxSWPkg = require(`workbox-sw/package.json`);
workboxSWFilename = path.basename(workboxSWPkg.main);
options.workboxSWImport = `${workboxDirectoryName}/${workboxSWFilename}`;
options.modulePathPrefix = workboxDirectoryName;
case 16:
_context.next = 18;
return getFileManifestEntries(options);
case 18:
_ref2 = _context.sent;
count = _ref2.count;
size = _ref2.size;
manifestEntries = _ref2.manifestEntries;
warnings = _ref2.warnings;
_context.next = 25;
return writeServiceWorkerUsingDefaultTemplate((0, _assign2.default)({
manifestEntries
}, options));
case 25:
return _context.abrupt('return', { count, size, warnings });
case 26:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function generateSW(_x) {
return _ref.apply(this, arguments);
};
}();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var path = require('path');
var cdnUtils = require('../lib/cdn-utils');
var copyWorkboxLibraries = require('../lib/copy-workbox-libraries');
var generateSWSchema = require('./options/generate-sw-schema');
var getFileManifestEntries = require('../lib/get-file-manifest-entries');
var validate = require('./options/validate');
var writeServiceWorkerUsingDefaultTemplate = require('../lib/write-sw-using-default-template');
module.exports = generateSW;

View File

@ -0,0 +1,83 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
/**
* This method returns a list of URLs to precache, referred to as a "precache
* manifest", along with details about the number of entries and their size,
* based on the options you provide.
*
* @param {Object} config Please refer to the
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#getmanifest_mode).
* @return {Promise<{manifestEntries: Array<ManifestEntry>,
* 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`.
*
* @memberof module:workbox-build
*/
var getManifest = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) {
var options, _ref2, manifestEntries, count, size, warnings;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
options = validate(config, getManifestSchema);
_context.next = 3;
return getFileManifestEntries(options);
case 3:
_ref2 = _context.sent;
manifestEntries = _ref2.manifestEntries;
count = _ref2.count;
size = _ref2.size;
warnings = _ref2.warnings;
return _context.abrupt('return', { manifestEntries, count, size, warnings });
case 9:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function getManifest(_x) {
return _ref.apply(this, arguments);
};
}();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var getFileManifestEntries = require('../lib/get-file-manifest-entries');
var getManifestSchema = require('./options/get-manifest-schema');
var validate = require('./options/validate');
module.exports = getManifest;

View File

@ -0,0 +1,155 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
/**
* This method creates a list of URLs to precache, referred to as a "precache
* manifest", based on the options you provide.
*
* The manifest is injected into the `swSrc` file, and the regular expression
* `injectionPointRegexp` determines where in the file the manifest should go.
*
* The final service worker file, with the manifest injected, is written to
* disk at `swDest`.
*
* @param {Object} config Please refer to the
* [configuration guide](https://developers.google.com/web/tools/workbox/modules/workbox-build#full_injectmanifest_config).
* @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`.
*
* @memberof module:workbox-build
*/
var injectManifest = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(config) {
var options, globalRegexp, _ref2, count, size, manifestEntries, warnings, swFileContents, injectionResults, entriesString;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
options = validate(config, injectManifestSchema);
if (!(path.normalize(config.swSrc) === path.normalize(config.swDest))) {
_context.next = 3;
break;
}
throw new Error(errors['same-src-and-dest']);
case 3:
globalRegexp = new RegExp(options.injectionPointRegexp, 'g');
_context.next = 6;
return getFileManifestEntries(options);
case 6:
_ref2 = _context.sent;
count = _ref2.count;
size = _ref2.size;
manifestEntries = _ref2.manifestEntries;
warnings = _ref2.warnings;
swFileContents = void 0;
_context.prev = 12;
_context.next = 15;
return fse.readFile(config.swSrc, 'utf8');
case 15:
swFileContents = _context.sent;
_context.next = 21;
break;
case 18:
_context.prev = 18;
_context.t0 = _context['catch'](12);
throw new Error(`${errors['invalid-sw-src']} ${_context.t0.message}`);
case 21:
injectionResults = swFileContents.match(globalRegexp);
assert(injectionResults, errors['injection-point-not-found'] + (
// Customize the error message when this happens:
// - If the default RegExp is used, then include the expected string that
// matches as a hint to the developer.
// - If a custom RegExp is used, then just include the raw RegExp.
options.injectionPointRegexp === defaults.injectionPointRegexp ? 'workbox.precaching.precacheAndRoute([])' : options.injectionPointRegexp));
assert(injectionResults.length === 1, errors['multiple-injection-points'] + ` ${options.injectionPointRegexp}`);
entriesString = (0, _stringify2.default)(manifestEntries, null, 2);
swFileContents = swFileContents.replace(globalRegexp, `$1${entriesString}$2`);
_context.prev = 26;
_context.next = 29;
return fse.mkdirp(path.dirname(options.swDest));
case 29:
_context.next = 34;
break;
case 31:
_context.prev = 31;
_context.t1 = _context['catch'](26);
throw new Error(errors['unable-to-make-injection-directory'] + ` '${_context.t1.message}'`);
case 34:
_context.next = 36;
return fse.writeFile(config.swDest, swFileContents);
case 36:
return _context.abrupt('return', { count, size, warnings });
case 37:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[12, 18], [26, 31]]);
}));
return function injectManifest(_x) {
return _ref.apply(this, arguments);
};
}();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var assert = require('assert');
var fse = require('fs-extra');
var path = require('path');
var defaults = require('./options/defaults');
var errors = require('../lib/errors');
var getFileManifestEntries = require('../lib/get-file-manifest-entries');
var injectManifestSchema = require('./options/inject-manifest-schema');
var validate = require('./options/validate');
module.exports = injectManifest;

View File

@ -0,0 +1,37 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var joi = require('joi');
var defaults = require('./defaults');
var regExpObject = require('./reg-exp-object');
// Define some common constrains used by all methods.
module.exports = joi.object().keys({
dontCacheBustUrlsMatching: regExpObject,
globFollow: joi.boolean().default(defaults.globFollow),
globIgnores: joi.array().items(joi.string()).default(defaults.globIgnores),
globPatterns: joi.array().items(joi.string()).default(defaults.globPatterns),
globStrict: joi.boolean().default(defaults.globStrict),
manifestTransforms: joi.array().items(joi.func().arity(1)),
maximumFileSizeToCacheInBytes: joi.number().min(1).default(defaults.maximumFileSizeToCacheInBytes),
modifyUrlPrefix: joi.object(),
// templatedUrls is an object where any property name is valid, and the values
// can be either a string or an array of strings.
templatedUrls: joi.object().pattern(/./, [joi.string(), joi.array().items(joi.string())])
});

View File

@ -0,0 +1,65 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var joi = require('joi');
var baseSchema = require('./base-schema');
var defaults = require('./defaults');
var regExpObject = require('./reg-exp-object');
// Add some constraints that apply to both generateSW and generateSWString.
module.exports = baseSchema.keys({
cacheId: joi.string(),
clientsClaim: joi.boolean().default(defaults.clientsClaim),
directoryIndex: joi.string(),
ignoreUrlParametersMatching: joi.array().items(regExpObject),
navigateFallback: joi.string().default(defaults.navigateFallback),
navigateFallbackBlacklist: joi.array().items(regExpObject),
navigateFallbackWhitelist: joi.array().items(regExpObject),
offlineGoogleAnalytics: joi.alternatives().try(joi.boolean(), joi.object()).default(defaults.offlineGoogleAnalytics),
runtimeCaching: joi.array().items(joi.object().keys({
method: joi.string().valid('DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT'),
urlPattern: [regExpObject, joi.string()],
handler: [joi.func(), joi.string().valid('cacheFirst', 'cacheOnly', 'networkFirst', 'networkOnly', 'staleWhileRevalidate')],
options: joi.object().keys({
backgroundSync: joi.object().keys({
name: joi.string().required(),
options: joi.object()
}),
broadcastUpdate: joi.object().keys({
channelName: joi.string().required(),
options: joi.object()
}),
cacheableResponse: joi.object().keys({
statuses: joi.array().items(joi.number().min(0).max(599)),
headers: joi.object()
}).or('statuses', 'headers'),
cacheName: joi.string(),
expiration: joi.object().keys({
maxEntries: joi.number().min(1),
maxAgeSeconds: joi.number().min(1),
purgeOnQuotaError: joi.boolean().default(defaults.purgeOnQuotaError)
}).or('maxEntries', 'maxAgeSeconds'),
networkTimeoutSeconds: joi.number().min(1),
plugins: joi.array().items(joi.object()),
fetchOptions: joi.object(),
matchOptions: joi.object()
}).with('expiration', 'cacheName')
}).requiredKeys('urlPattern', 'handler')),
skipWaiting: joi.boolean().default(defaults.skipWaiting)
});

View File

@ -0,0 +1,32 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
module.exports = {
clientsClaim: false,
globFollow: true,
globIgnores: ['**/node_modules/**/*'],
globPatterns: ['**/*.{js,css,html}'],
globStrict: true,
importWorkboxFrom: 'cdn',
injectionPointRegexp: /(\.precacheAndRoute\()\s*\[\s*\]\s*(\)|,)/,
maximumFileSizeToCacheInBytes: 2 * 1024 * 1024,
navigateFallback: undefined,
offlineGoogleAnalytics: false,
purgeOnQuotaError: false,
skipWaiting: false
};

View File

@ -0,0 +1,30 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var joi = require('joi');
var commonGenerateSchema = require('./common-generate-schema');
var defaults = require('./defaults');
// Define some additional constraints.
module.exports = commonGenerateSchema.keys({
globDirectory: joi.string().required(),
importScripts: joi.array().items(joi.string()),
importWorkboxFrom: joi.string().default(defaults.importWorkboxFrom).valid('cdn', 'local', 'disabled'),
swDest: joi.string().required()
});

View File

@ -0,0 +1,29 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var joi = require('joi');
var commonGenerateSchema = require('./common-generate-schema');
// Define some additional constraints.
module.exports = commonGenerateSchema.keys({
globDirectory: joi.string(),
importScripts: joi.array().items(joi.string()).required(),
modulePathPrefix: joi.string(),
workboxSWImport: joi.string()
});

View File

@ -0,0 +1,26 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var joi = require('joi');
var baseSchema = require('./base-schema');
// Define some additional constraints.
module.exports = baseSchema.keys({
globDirectory: joi.string()
});

View File

@ -0,0 +1,30 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var joi = require('joi');
var baseSchema = require('./base-schema');
var defaults = require('./defaults');
var regExpObject = require('./reg-exp-object');
module.exports = baseSchema.keys({
globDirectory: joi.string().required(),
injectionPointRegexp: regExpObject.default(defaults.injectionPointRegexp),
swSrc: joi.string().required(),
swDest: joi.string().required()
});

View File

@ -0,0 +1,23 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var joi = require('joi');
module.exports = joi.object().type(RegExp).error(function () {
return 'the value must be a RegExp';
});

View File

@ -0,0 +1,35 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
module.exports = function (options, schema) {
var _schema$validate = schema.validate(options, {
language: {
object: {
allowUnknown: 'is not a supported parameter.'
}
}
}),
value = _schema$validate.value,
error = _schema$validate.error;
if (error) {
throw error;
}
return value;
};

94
node_modules/workbox-build/build/index.js generated vendored Normal file
View File

@ -0,0 +1,94 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var copyWorkboxLibraries = require('./lib/copy-workbox-libraries');
var generateSW = require('./entry-points/generate-sw');
var generateSWString = require('./entry-points/generate-sw-string');
var getManifest = require('./entry-points/get-manifest');
var injectManifest = require('./entry-points/inject-manifest');
var _require = require('./lib/cdn-utils'),
getModuleUrl = _require.getModuleUrl;
/**
* This Node module can be used to generate a list of assets that should be
* precached in a service worker, generating a hash that can be used to
* intelligently update a cache when the service worker is updated.
*
* This module will use glob patterns to find assets in a given directory
* and use the resulting URL and revision data for one of the follow uses:
*
* 1. Generate a complete service worker with precaching and some basic
* configurable options, writing the resulting service worker file to disk. See
* [generateSW()]{@link module:workbox-build.generateSW}.
* 1. Generate a complete service worker with precaching and some basic
* configurable options, without writing the results to disk. See
* [generateSWString()]{@link module:workbox-build.generateSWString}.
* 1. Inject a manifest into an existing service worker. This allows you
* to control your own service worker while still taking advantage of
* [workboxSW.precache()]{@link module:workbox-sw.WorkboxSW#precache} logic.
* See [injectManifest()]{@link module:workbox-build.injectManifest}.
* 1. Just generate a manifest, not a full service worker file.
* This is useful if you want to make use of the manifest from your own existing
* service worker file and are okay with including the manifest yourself.
* See [getManifest()]{@link module:workbox-build.getManifest}.
*
* @property {Array<RegExp>} [ignoreUrlParametersMatching=[/^utm_/]] Any
* search parameter names that match against one of the regex's in this array
* will be removed before looking for a precache match.
*
* This is useful if your users might request URLs that contain, for example,
* URL parameters used to track the source of the traffic. Those URL parameters
* would normally cause the cache lookup to fail, since the URL strings used
* as cache keys would not be expected to include them.
*
* You can use `[/./]` to ignore all URL parameters.
*
* Note: This option is only valid when used with
* {@link module:workbox-build#generateSW|generateSW()}. When using
* {@link module:workbox-build.injectManifest|injectManifest()}, you can
* explicitly pass the desired value in to the
* {@link module:workbox-sw.WorkboxSW|WorkboxSW() constructor} in your `swSrc`
* file.
*
* E.g. `[/homescreen/]`
*
* @property {Boolean} [handleFetch=true] Whether or not `workbox-sw` should
* create a `fetch` event handler that responds to network requests. This is
* useful during development if you don't want the service worker serving stale
* content.
*
* Note: This option is only valid when used with
* {@link module:workbox-build#generateSW|generateSW()}. When using
* {@link module:workbox-build.injectManifest|injectManifest()}, you can
* explicitly pass the desired value in to the
* {@link module:workbox-sw.WorkboxSW|WorkboxSW() constructor} in your `swSrc`
* file.
*
* @module workbox-build
*/
module.exports = {
copyWorkboxLibraries,
generateSW,
generateSWString,
getManifest,
getModuleUrl,
injectManifest
};

50
node_modules/workbox-build/build/lib/cdn-utils.js generated vendored Normal file
View File

@ -0,0 +1,50 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var assert = require('assert');
var cdn = require('../cdn-details.json');
var errors = require('./errors');
var getCDNOrigin = function getCDNOrigin() {
return `${cdn.origin}/${cdn.bucketName}/${cdn.releasesDir}`;
};
var getVersionedCDNUrl = function getVersionedCDNUrl() {
return `${getCDNOrigin()}/${cdn.latestVersion}`;
};
var getModuleUrl = function getModuleUrl(moduleName, buildType) {
assert(moduleName, errors['no-module-name']);
if (buildType) {
var pkgJson = require(`${moduleName}/package.json`);
if (buildType === 'dev' && pkgJson.workbox.prodOnly) {
// This is not due to a public-facing exception, so just throw an Error(),
// without creating an entry in errors.js.
throw Error(`The 'dev' build of ${moduleName} is not available.`);
}
return `${getVersionedCDNUrl()}/${moduleName}.${buildType.slice(0, 4)}.js`;
}
return `${getVersionedCDNUrl()}/${moduleName}.js`;
};
module.exports = {
getCDNOrigin,
getModuleUrl
};

View File

@ -0,0 +1,240 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var fse = require('fs-extra');
var path = require('path');
var errors = require('./errors');
var useBuildType = require('./use-build-type');
// Used to filter the libraries to copy based on our package.json dependencies.
var WORKBOX_PREFIX = 'workbox-';
var BUILD_TYPES = ['dev', 'prod'];
/**
* This copies over a set of runtime libraries used by Workbox into a
* local directory, which should be deployed alongside your service worker file.
*
* As an alternative to deploying these local copies, you could instead use
* Workbox from its official CDN URL.
*
* This method is exposed for the benefit of developers using
* [injectManifest()]{@link module:workbox-build.injectManifest} who would
* 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
* `importWorkboxFrom` is set to `local`.
*
* @param {string} destDirectory The path to the parent directory under which
* the new directory of libraries will be created.
* @return {Promise<string>} The name of the newly created directory.
*
* @alias module:workbox-build.copyWorkboxLibraries
*/
module.exports = function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(destDirectory) {
var thisPkg, workboxDirectoryName, workboxDirectoryPath, copyPromises, librariesToCopy, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, library, pkg, defaultPathToLibrary, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, buildType, srcPath, destPath;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
thisPkg = require('../../package.json');
// Use the version string from workbox-build in the name of the parent
// directory. This should be safe, because lerna will bump workbox-build's
// pkg.version whenever one of the dependent libraries gets bumped, and we
// care about versioning the dependent libraries.
workboxDirectoryName = `workbox-v${thisPkg.version}`;
workboxDirectoryPath = path.join(destDirectory, workboxDirectoryName);
_context.next = 5;
return fse.ensureDir(workboxDirectoryPath);
case 5:
copyPromises = [];
librariesToCopy = (0, _keys2.default)(thisPkg.dependencies).filter(function (dependency) {
return dependency.startsWith(WORKBOX_PREFIX);
});
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 10;
_iterator = (0, _getIterator3.default)(librariesToCopy);
case 12:
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) {
_context.next = 49;
break;
}
library = _step.value;
pkg = require(`${library}/package.json`);
defaultPathToLibrary = require.resolve(`${library}/${pkg.main}`);
_iteratorNormalCompletion2 = true;
_didIteratorError2 = false;
_iteratorError2 = undefined;
_context.prev = 19;
_iterator2 = (0, _getIterator3.default)(BUILD_TYPES);
case 21:
if (_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done) {
_context.next = 32;
break;
}
buildType = _step2.value;
if (!(library === 'workbox-sw' && buildType === BUILD_TYPES[0])) {
_context.next = 25;
break;
}
return _context.abrupt('continue', 29);
case 25:
srcPath = useBuildType(defaultPathToLibrary, buildType);
destPath = path.join(workboxDirectoryPath, path.basename(srcPath));
copyPromises.push(fse.copy(srcPath, destPath));
copyPromises.push(fse.copy(`${srcPath}.map`, `${destPath}.map`));
case 29:
_iteratorNormalCompletion2 = true;
_context.next = 21;
break;
case 32:
_context.next = 38;
break;
case 34:
_context.prev = 34;
_context.t0 = _context['catch'](19);
_didIteratorError2 = true;
_iteratorError2 = _context.t0;
case 38:
_context.prev = 38;
_context.prev = 39;
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
case 41:
_context.prev = 41;
if (!_didIteratorError2) {
_context.next = 44;
break;
}
throw _iteratorError2;
case 44:
return _context.finish(41);
case 45:
return _context.finish(38);
case 46:
_iteratorNormalCompletion = true;
_context.next = 12;
break;
case 49:
_context.next = 55;
break;
case 51:
_context.prev = 51;
_context.t1 = _context['catch'](10);
_didIteratorError = true;
_iteratorError = _context.t1;
case 55:
_context.prev = 55;
_context.prev = 56;
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 58:
_context.prev = 58;
if (!_didIteratorError) {
_context.next = 61;
break;
}
throw _iteratorError;
case 61:
return _context.finish(58);
case 62:
return _context.finish(55);
case 63:
_context.prev = 63;
_context.next = 66;
return _promise2.default.all(copyPromises);
case 66:
return _context.abrupt('return', workboxDirectoryName);
case 69:
_context.prev = 69;
_context.t2 = _context['catch'](63);
throw Error(`${errors['unable-to-copy-workbox-libraries']} ${_context.t2}`);
case 72:
case 'end':
return _context.stop();
}
}
}, _callee, undefined, [[10, 51, 55, 63], [19, 34, 38, 46], [39,, 41, 45], [56,, 58, 62], [63, 69]]);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();

113
node_modules/workbox-build/build/lib/errors.js generated vendored Normal file
View File

@ -0,0 +1,113 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var ol = require('common-tags').oneLine;
module.exports = {
'unable-to-get-rootdir': `Unable to get the root directory of your web app.`,
'no-extension': ol`Unable to detect a usable extension for a file in your web
app directory.`,
'invalid-file-manifest-name': ol`The File Manifest Name must have at least one
character.`,
'unable-to-get-file-manifest-name': 'Unable to get a file manifest name.',
'invalid-sw-dest': `The 'swDest' value must be a valid path.`,
'unable-to-get-sw-name': 'Unable to get a service worker file name.',
'unable-to-get-save-config': ol`An error occurred when asking to save details
in a config file.`,
'unable-to-get-file-hash': ol`An error occurred when attempting to create a
file hash.`,
'unable-to-get-file-size': ol`An error occurred when attempting to get a file
size.`,
'unable-to-glob-files': 'An error occurred when globbing for files.',
'unable-to-make-manifest-directory': ol`Unable to make output directory for
file manifest.`,
'read-manifest-template-failure': 'Unable to read template for file manifest',
'populating-manifest-tmpl-failed': ol`An error occurred when populating the
file manifest template.`,
'manifest-file-write-failure': 'Unable to write the file manifest.',
'unable-to-make-sw-directory': ol`Unable to make the directories to output
the service worker path.`,
'read-sw-template-failure': ol`Unable to read the service worker template
file.`,
'sw-write-failure': 'Unable to write the service worker file.',
'sw-write-failure-directory': ol`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-libraries': ol`One or more of the Workbox libraries
could not be copied over to the destination directory: `,
'invalid-generate-sw-input': ol`The input to generateSW() must be an object.`,
'invalid-glob-directory': ol`The supplied globDirectory must be a path as a
string.`,
'invalid-dont-cache-bust': ol`The supplied 'dontCacheBustUrlsMatching'
parameter must be a RegExp.`,
'invalid-exclude-files': 'The excluded files should be an array of strings.',
'invalid-get-manifest-entries-input': ol`The input to
'getFileManifestEntries()' must be an object.`,
'invalid-manifest-path': ol`The supplied manifest path is not a string with
at least one character.`,
'invalid-manifest-entries': ol`The manifest entries must be an array of
strings or JavaScript objects containing a url parameter.`,
'invalid-manifest-format': ol`The value of the 'format' option passed to
generateFileManifest() must be either 'iife' (the default) or 'es'.`,
'invalid-static-file-globs': ol`The 'globPatterns' value must be an array
of strings.`,
'invalid-templated-urls': ol`The 'templatedUrls' value should be an object
that maps URLs to either a string, or to an array of glob patterns.`,
'templated-url-matches-glob': ol`One of the 'templatedUrls' URLs is already
being tracked via 'globPatterns': `,
'invalid-glob-ignores': ol`The 'globIgnores' parameter must be an array of
glob pattern strings.`,
'manifest-entry-bad-url': ol`The generated manifest contains an entry without
a URL string. This is likely an error with workbox-build.`,
'modify-url-prefix-bad-prefixes': ol`The 'modifyUrlPrefix' parameter must be
an object with string key value pairs.`,
'invalid-inject-manifest-arg': ol`The input to 'injectManifest()' must be an
object.`,
'injection-point-not-found': ol`Unable to find a place to inject the manifest.
Please ensure that your service worker file contains the following: `,
'multiple-injection-points': ol`Please ensure that your 'swSrc' file contains
only one match for the RegExp:`,
'populating-sw-tmpl-failed': ol`Unable to generate service worker from
template.`,
'useless-glob-pattern': ol`One of the glob patterns doesn't match any files.
Please remove or fix the following: `,
'bad-template-urls-asset': ol`There was an issue using one of the provided
'templatedUrls'.`,
'invalid-runtime-caching': ol`The 'runtimeCaching' parameter must an an
array of objects with at least a 'urlPattern' and 'handler'.`,
'static-file-globs-deprecated': ol`'staticFileGlobs' is deprecated.
Please use 'globPatterns' instead.`,
'dynamic-url-deprecated': ol`'dynamicUrlToDependencies' is deprecated.
Please use 'templatedUrls' instead.`,
'urlPattern-is-required': ol`The 'urlPattern' option is required when using
'runtimeCaching'.`,
'handler-is-required': ol`The 'handler' option is required when using
runtimeCaching.`,
'invalid-generate-file-manifest-arg': ol`The input to generateFileManifest()
must be an Object.`,
'invalid-sw-src': `The 'swSrc' file can't be read.`,
'same-src-and-dest': ol`'swSrc' and 'swDest' should not be set to the same ` + `file. Please use a different file path for 'swDest'.`,
'only-regexp-routes-supported': ol`Please use a regular expression object as
the urlPattern parameter. (Express-style routes are not currently
supported.)`,
'bad-runtime-caching-config': ol`An unknown configuration option was used
with runtimeCaching:`,
'invalid-network-timeout-seconds': ol`When using networkTimeoutSeconds, you
must set the handler to 'networkFirst'.`,
'no-module-name': ol`You must provide a moduleName parameter when calling
getModuleUrl().`
};

183
node_modules/workbox-build/build/lib/filter-files.js generated vendored Normal file
View File

@ -0,0 +1,183 @@
'use strict';
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var maximumSizeTransform = require('./maximum-size-transform');
var modifyUrlPrefixTranform = require('./modify-url-prefix-transform');
var noRevisionForUrlsMatchingTransform = require('./no-revision-for-urls-matching-transform');
/**
* 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) => {
* 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: []};
* };
*
* @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) => {
* const manifest = manifestEntries.map(entry => {
* const hashRegExp = /\.\w{8}\./;
* if (entry.url.match(hashRegExp)) {
* delete entry.revision;
* }
* return entry;
* });
* return {manifest, warnings: []};
* };
*
* @callback ManifestTransform
* @param {Array<module:workbox-build.ManifestEntry>} manifestEntries The full
* array of entries, prior to the current transformation.
* @return {module:workbox-build.ManifestTransformResult}
* The array of entries with the transformation applied, and optionally, any
* warnings that should be reported back to the build tool.
*
* @memberof module:workbox-build
*/
module.exports = function (_ref) {
var dontCacheBustUrlsMatching = _ref.dontCacheBustUrlsMatching,
fileDetails = _ref.fileDetails,
manifestTransforms = _ref.manifestTransforms,
maximumFileSizeToCacheInBytes = _ref.maximumFileSizeToCacheInBytes,
modifyUrlPrefix = _ref.modifyUrlPrefix;
var allWarnings = [];
// Take the array of fileDetail objects and convert it into an array of
// {url, revision, size} objects, with \ replaced with /.
var normalizedManifest = fileDetails.map(function (fileDetails) {
return {
url: fileDetails.file.replace(/\\/g, '/'),
revision: fileDetails.hash,
size: fileDetails.size
};
});
var transformsToApply = [];
if (maximumFileSizeToCacheInBytes) {
transformsToApply.push(maximumSizeTransform(maximumFileSizeToCacheInBytes));
}
if (modifyUrlPrefix) {
transformsToApply.push(modifyUrlPrefixTranform(modifyUrlPrefix));
}
if (dontCacheBustUrlsMatching) {
transformsToApply.push(noRevisionForUrlsMatchingTransform(dontCacheBustUrlsMatching));
}
// Any additional manifestTransforms that were passed will be applied last.
transformsToApply = transformsToApply.concat(manifestTransforms || []);
var transformedManifest = normalizedManifest;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(transformsToApply), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var transform = _step.value;
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) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
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,
warnings: allWarnings
};
};

View File

@ -0,0 +1,66 @@
'use strict';
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var crypto = require('crypto');
module.exports = function (compositeUrl, dependencyDetails) {
var totalSize = 0;
var compositeHash = '';
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(dependencyDetails), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var fileDetails = _step.value;
totalSize += fileDetails.size;
compositeHash += fileDetails.hash;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var md5 = crypto.createHash('md5');
md5.update(compositeHash);
var hashOfHashes = md5.digest('hex');
return {
file: compositeUrl,
hash: hashOfHashes,
size: totalSize
};
};

View File

@ -0,0 +1,74 @@
'use strict';
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var glob = require('glob');
var path = require('path');
var errors = require('./errors');
var getFileSize = require('./get-file-size');
var getFileHash = require('./get-file-hash');
module.exports = function (globOptions) {
var globDirectory = globOptions.globDirectory,
globFollow = globOptions.globFollow,
globIgnores = globOptions.globIgnores,
globPattern = globOptions.globPattern,
globStrict = globOptions.globStrict;
var globbedFiles = void 0;
try {
globbedFiles = glob.sync(globPattern, {
cwd: globDirectory,
follow: globFollow,
ignore: globIgnores,
strict: globStrict
});
} catch (err) {
throw new Error(errors['unable-to-glob-files'] + ` '${err.message}'`);
}
if (globbedFiles.length === 0) {
throw new Error(errors['useless-glob-pattern'] + ' ' + (0, _stringify2.default)({ globDirectory, globPattern, globIgnores }, null, 2));
}
var fileDetails = globbedFiles.map(function (file) {
var fullPath = path.join(globDirectory, file);
var fileSize = getFileSize(fullPath);
if (fileSize === null) {
return null;
}
var fileHash = getFileHash(fullPath);
return {
file: `${path.relative(globDirectory, fullPath)}`,
hash: fileHash,
size: fileSize
};
});
// If !== null, means it's a valid file.
return fileDetails.filter(function (details) {
return details !== null;
});
};

31
node_modules/workbox-build/build/lib/get-file-hash.js generated vendored Normal file
View File

@ -0,0 +1,31 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var fs = require('fs');
var getStringHash = require('./get-string-hash');
var errors = require('./errors');
module.exports = function (file) {
try {
var buffer = fs.readFileSync(file);
return getStringHash(buffer);
} catch (err) {
throw new Error(errors['unable-to-get-file-hash'] + ` '${err.message}'`);
}
};

View File

@ -0,0 +1,213 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _set = require('babel-runtime/core-js/set');
var _set2 = _interopRequireDefault(_set);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var assert = require('assert');
var path = require('path');
var errors = require('./errors');
var filterFiles = require('./filter-files');
var getCompositeDetails = require('./get-composite-details');
var getFileDetails = require('./get-file-details');
var getStringDetails = require('./get-string-details');
module.exports = function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(_ref) {
var dontCacheBustUrlsMatching = _ref.dontCacheBustUrlsMatching,
globDirectory = _ref.globDirectory,
globFollow = _ref.globFollow,
globIgnores = _ref.globIgnores,
globPatterns = _ref.globPatterns,
globStrict = _ref.globStrict,
manifestTransforms = _ref.manifestTransforms,
maximumFileSizeToCacheInBytes = _ref.maximumFileSizeToCacheInBytes,
modifyUrlPrefix = _ref.modifyUrlPrefix,
swDest = _ref.swDest,
templatedUrls = _ref.templatedUrls;
var warnings, fileDetails, fileSet, _loop, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, url, filteredFiles, _filteredFiles$warnin;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
warnings = [];
// Initialize to an empty array so that we can still pass something to
// filterFiles() and get a normalized output.
fileDetails = [];
fileSet = new _set2.default();
if (globDirectory) {
if (swDest) {
// Ensure that we ignore the SW file we're eventually writing to disk.
globIgnores.push(`**/${path.basename(swDest)}`);
}
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;
}
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 = 25;
break;
}
_loop = function _loop(url) {
assert(!fileSet.has(url), errors['templated-url-matches-glob']);
var dependencies = templatedUrls[url];
if (Array.isArray(dependencies)) {
var details = dependencies.reduce(function (previous, globPattern) {
try {
var globbedFileDetails = getFileDetails({
globDirectory,
globFollow,
globIgnores,
globPattern,
globStrict
});
return previous.concat(globbedFileDetails);
} catch (error) {
var debugObj = {};
debugObj[url] = dependencies;
throw new Error(`${errors['bad-template-urls-asset']} ` + `'${globPattern}' from '${(0, _stringify2.default)(debugObj)}':\n` + error);
}
}, []);
fileDetails.push(getCompositeDetails(url, details));
} else if (typeof dependencies === 'string') {
fileDetails.push(getStringDetails(url, dependencies));
}
};
_iteratorNormalCompletion = true;
_didIteratorError = false;
_iteratorError = undefined;
_context.prev = 9;
for (_iterator = (0, _getIterator3.default)((0, _keys2.default)(templatedUrls)); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
url = _step.value;
_loop(url);
}
_context.next = 17;
break;
case 13:
_context.prev = 13;
_context.t0 = _context['catch'](9);
_didIteratorError = true;
_iteratorError = _context.t0;
case 17:
_context.prev = 17;
_context.prev = 18;
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
case 20:
_context.prev = 20;
if (!_didIteratorError) {
_context.next = 23;
break;
}
throw _iteratorError;
case 23:
return _context.finish(20);
case 24:
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':
return _context.stop();
}
}
}, _callee, undefined, [[9, 13, 17, 25], [18,, 20, 24]]);
}));
return function (_x) {
return _ref2.apply(this, arguments);
};
}();

33
node_modules/workbox-build/build/lib/get-file-size.js generated vendored Normal file
View File

@ -0,0 +1,33 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var fs = require('fs');
var errors = require('./errors');
module.exports = function (file) {
try {
var stat = fs.statSync(file);
if (!stat.isFile()) {
return null;
}
return stat.size;
} catch (err) {
throw new Error(errors['unable-to-get-file-size'] + ` '${err.message}'`);
}
};

View File

@ -0,0 +1,27 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var getStringHash = require('./get-string-hash');
module.exports = function (url, string) {
return {
file: url,
hash: getStringHash(string),
size: string.length
};
};

View File

@ -0,0 +1,25 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var crypto = require('crypto');
module.exports = function (string) {
var md5 = crypto.createHash('md5');
md5.update(string);
return md5.digest('hex');
};

View File

@ -0,0 +1,35 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var prettyBytes = require('pretty-bytes');
module.exports = function (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 };
};
};

View File

@ -0,0 +1,87 @@
'use strict';
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var errors = require('./errors');
/**
* Escaping user input to be treated as a literal string within a regular
* expression can be accomplished by simple replacement.
*
* From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
*
* @private
* @param {string} string The string to be used as part of a regular
* expression
* @return {string} A string that is safe to use in a regular
* expression.
*
* @private
*/
var escapeRegExp = function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
};
module.exports = function (modifyUrlPrefix) {
if (!modifyUrlPrefix || typeof modifyUrlPrefix !== 'object' || Array.isArray(modifyUrlPrefix)) {
throw new Error(errors['modify-url-prefix-bad-prefixes']);
}
// If there are no entries in modifyUrlPrefix, just return an identity
// function as a shortcut.
if ((0, _keys2.default)(modifyUrlPrefix).length === 0) {
return function (entry) {
return entry;
};
}
(0, _keys2.default)(modifyUrlPrefix).forEach(function (key) {
if (typeof modifyUrlPrefix[key] !== 'string') {
throw new Error(errors['modify-url-prefix-bad-prefixes']);
}
});
// Escape the user input so it's safe to use in a regex.
var safeModifyUrlPrefixes = (0, _keys2.default)(modifyUrlPrefix).map(escapeRegExp);
// Join all the `modifyUrlPrefix` keys so a single regex can be used.
var prefixMatchesStrings = safeModifyUrlPrefixes.join('|');
// Add `^` to the front the prefix matches so it only matches the start of
// a string.
var modifyRegex = new RegExp(`^(${prefixMatchesStrings})`);
return function (originalManifest) {
var manifest = originalManifest.map(function (entry) {
if (typeof entry.url !== 'string') {
throw new Error(errors['manifest-entry-bad-url']);
}
entry.url = entry.url.replace(modifyRegex, function (match) {
return modifyUrlPrefix[match];
});
return entry;
});
return { manifest };
};
};

View File

@ -0,0 +1,41 @@
'use strict';
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var errors = require('./errors');
module.exports = function (regexp) {
if (!(regexp instanceof RegExp)) {
throw new Error(errors['invalid-dont-cache-bust']);
}
return function (originalManifest) {
var manifest = originalManifest.map(function (entry) {
if (typeof entry.url !== 'string') {
throw new Error(errors['manifest-entry-bad-url']);
}
if (entry.url.match(regexp)) {
delete entry.revision;
}
return entry;
});
return { manifest };
};
};

View File

@ -0,0 +1,95 @@
'use strict';
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var template = require('lodash.template');
var swTemplate = require('../templates/sw-template');
var errors = require('./errors');
var runtimeCachingConverter = require('./runtime-caching-converter');
var stringifyWithoutComments = require('./stringify-without-comments');
module.exports = function (_ref) {
var cacheId = _ref.cacheId,
clientsClaim = _ref.clientsClaim,
directoryIndex = _ref.directoryIndex,
ignoreUrlParametersMatching = _ref.ignoreUrlParametersMatching,
importScripts = _ref.importScripts,
manifestEntries = _ref.manifestEntries,
modulePathPrefix = _ref.modulePathPrefix,
navigateFallback = _ref.navigateFallback,
navigateFallbackBlacklist = _ref.navigateFallbackBlacklist,
navigateFallbackWhitelist = _ref.navigateFallbackWhitelist,
offlineGoogleAnalytics = _ref.offlineGoogleAnalytics,
runtimeCaching = _ref.runtimeCaching,
skipWaiting = _ref.skipWaiting,
workboxSWImport = _ref.workboxSWImport;
// These are all options that can be passed to the precacheAndRoute() method.
var precacheOptions = {
directoryIndex,
// An array of RegExp objects can't be serialized by JSON.stringify()'s
// default behavior, so if it's given, convert it manually.
ignoreUrlParametersMatching: ignoreUrlParametersMatching ? [] : undefined
};
var precacheOptionsString = (0, _stringify2.default)(precacheOptions, null, 2);
if (ignoreUrlParametersMatching) {
precacheOptionsString = precacheOptionsString.replace(`"ignoreUrlParametersMatching": []`, `"ignoreUrlParametersMatching": [` + `${ignoreUrlParametersMatching.join(', ')}]`);
}
var offlineAnalyticsConfigString = void 0;
if (offlineGoogleAnalytics) {
// If offlineGoogleAnalytics is a truthy value, we need to convert it to the
// format expected by the template.
offlineAnalyticsConfigString = offlineGoogleAnalytics === true ?
// If it's the literal value true, then use an empty config string.
'{}' :
// Otherwise, convert the config object into a more complex string, taking
// into account the fact that functions might need to be stringified.
stringifyWithoutComments(offlineGoogleAnalytics);
}
try {
var populatedTemplate = template(swTemplate)({
cacheId,
clientsClaim,
importScripts,
manifestEntries,
modulePathPrefix,
navigateFallback,
navigateFallbackBlacklist,
navigateFallbackWhitelist,
offlineAnalyticsConfigString,
precacheOptionsString,
skipWaiting,
runtimeCaching: runtimeCachingConverter(runtimeCaching),
workboxSWImport
});
// Clean up multiple blank lines.
return populatedTemplate.replace(/\n{3,}/g, '\n\n').trim() + '\n';
} catch (error) {
throw new Error(`${errors['populating-sw-tmpl-failed']} '${error.message}'`);
}
};

View File

@ -0,0 +1,230 @@
'use strict';
var _entries = require('babel-runtime/core-js/object/entries');
var _entries2 = _interopRequireDefault(_entries);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var ol = require('common-tags').oneLine;
var errors = require('./errors');
var stringifyWithoutComments = require('./stringify-without-comments');
/**
* Given a set of options that configures `sw-toolbox`'s behavior, convert it
* into a string that would configure equivalent `workbox-sw` behavior.
*
* @param {Object} options See
* https://googlechrome.github.io/sw-toolbox/api.html#options
* @return {string} A JSON string representing the equivalent options.
*
* @private
*/
function getOptionsString() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var plugins = [];
if (options.plugins) {
// Using libs because JSON.stringify won't handle functions.
plugins = options.plugins.map(stringifyWithoutComments);
delete options.plugins;
}
// Pull handler-specific config from the options object, since they are
// not directly used to construct a Plugin instance. If set, need to be
// passed as options to the handler constructor instead.
var handlerOptionKeys = ['cacheName', 'networkTimeoutSeconds', 'fetchOptions', 'matchOptions'];
var handlerOptions = {};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(handlerOptionKeys), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;
if (key in options) {
handlerOptions[key] = options[key];
delete options[key];
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var pluginsMapping = {
backgroundSync: 'workbox.backgroundSync.Plugin',
broadcastUpdate: 'workbox.broadcastUpdate.Plugin',
expiration: 'workbox.expiration.Plugin',
cacheableResponse: 'workbox.cacheableResponse.Plugin'
};
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = (0, _getIterator3.default)((0, _entries2.default)(options)), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _ref = _step2.value;
var _ref2 = (0, _slicedToArray3.default)(_ref, 2);
var pluginName = _ref2[0];
var pluginConfig = _ref2[1];
// Ensure that we have some valid configuration to pass to Plugin().
if ((0, _keys2.default)(pluginConfig).length === 0) {
continue;
}
var pluginString = pluginsMapping[pluginName];
if (!pluginString) {
throw new Error(`${errors['bad-runtime-caching-config']} ${pluginName}`);
}
var pluginCode = void 0;
switch (pluginName) {
// Special case logic for plugins that have a required parameter, and then
// an additional optional config parameter.
case 'backgroundSync':
{
var name = pluginConfig.name;
pluginCode = `new ${pluginString}(${(0, _stringify2.default)(name)}`;
if ('options' in pluginConfig) {
pluginCode += `, ${(0, _stringify2.default)(pluginConfig.options)}`;
}
pluginCode += `)`;
break;
}
case 'broadcastUpdate':
{
var channelName = pluginConfig.channelName;
pluginCode = `new ${pluginString}(${(0, _stringify2.default)(channelName)}`;
if ('options' in pluginConfig) {
pluginCode += `, ${(0, _stringify2.default)(pluginConfig.options)}`;
}
pluginCode += `)`;
break;
}
// For plugins that just pass in an Object to the constructor, like
// expiration and cacheableResponse
default:
{
pluginCode = `new ${pluginString}(${(0, _stringify2.default)(pluginConfig)})`;
}
}
plugins.push(pluginCode);
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
if ((0, _keys2.default)(handlerOptions).length > 0 || plugins.length > 0) {
var optionsString = (0, _stringify2.default)(handlerOptions).slice(1, -1);
return ol`{
${optionsString ? optionsString + ',' : ''}
plugins: [${plugins.join(', ')}]
}`;
} else {
return '';
}
}
module.exports = function () {
var runtimeCaching = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
return runtimeCaching.map(function (entry) {
var method = entry.method || 'GET';
if (!entry.urlPattern) {
throw new Error(errors['urlPattern-is-required']);
}
if (!entry.handler) {
throw new Error(errors['handler-is-required']);
}
// This validation logic is a bit too gnarly for joi, so it's manually
// implemented here.
if (entry.options && entry.options.networkTimeoutSeconds && entry.handler !== 'networkFirst') {
throw new Error(errors['invalid-network-timeout-seconds']);
}
// urlPattern might be either a string or a RegExp object.
// If it's a string, it needs to be quoted. If it's a RegExp, it should
// be used as-is.
var matcher = typeof entry.urlPattern === 'string' ? (0, _stringify2.default)(entry.urlPattern) : entry.urlPattern;
if (typeof entry.handler === 'string') {
var optionsString = getOptionsString(entry.options || {});
var strategyString = `workbox.strategies.${entry.handler}(${optionsString})`;
return `workbox.routing.registerRoute(` + `${matcher}, ${strategyString}, '${method}');\n`;
} else if (typeof entry.handler === 'function') {
return `workbox.routing.registerRoute(` + `${matcher}, ${entry.handler}, '${method}');\n`;
}
}).filter(function (entry) {
return Boolean(entry);
}); // Remove undefined map() return values.
};

View File

@ -0,0 +1,28 @@
'use strict';
/*
Copyright 2018 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var objectStringify = require('stringify-object');
var stripComments = require('strip-comments');
module.exports = function (obj) {
return objectStringify(obj, {
transform: function transform(_obj, _prop, str) {
return stripComments(str);
}
});
};

54
node_modules/workbox-build/build/lib/use-build-type.js generated vendored Normal file
View File

@ -0,0 +1,54 @@
'use strict';
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This is the build type that is expected to be present "by default".
var DEFAULT_BUILD_TYPE = 'prod';
/**
* Switches a string from using the "default" build type to an alternative
* build type. In practice, this is used to swap out "prod" for "dev" in the
* filename of a Workbox library.
*
* @param {string} source The path to a file, which will normally contain
* DEFAULT_BUILD_TYPE somewhere in it.
* @param {string} buildType The alternative build type value to swap in.
* @return {string} source, with the last occurrence of DEFAULT_BUILD_TYPE
* replaced with buildType.
* @private
*/
module.exports = function (source, buildType) {
// If we want the DEFAULT_BUILD_TYPE, then just return things as-is.
if (buildType === DEFAULT_BUILD_TYPE) {
return source;
}
// Otherwise, look for the last instance of DEFAULT_BUILD_TYPE, and replace it
// with the new buildType. This is easier via split/join than RegExp.
var parts = source.split(DEFAULT_BUILD_TYPE);
// Join the last two split parts with the new buildType. (If parts only has
// one item, this will be a no-op.)
var replaced = parts.slice(parts.length - 2).join(buildType);
// Take the remaining parts, if any exist, and join them with the replaced
// part using the DEFAULT_BUILD_TYPE, to restore any other matches as-is.
return [].concat((0, _toConsumableArray3.default)(parts.slice(0, parts.length - 2)), [replaced]).join(DEFAULT_BUILD_TYPE);
};

View File

@ -0,0 +1,122 @@
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var fse = require('fs-extra');
var path = require('path');
var errors = require('./errors');
var populateSWTemplate = require('./populate-sw-template');
module.exports = function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(_ref) {
var cacheId = _ref.cacheId,
clientsClaim = _ref.clientsClaim,
directoryIndex = _ref.directoryIndex,
handleFetch = _ref.handleFetch,
ignoreUrlParametersMatching = _ref.ignoreUrlParametersMatching,
importScripts = _ref.importScripts,
manifestEntries = _ref.manifestEntries,
modulePathPrefix = _ref.modulePathPrefix,
navigateFallback = _ref.navigateFallback,
navigateFallbackBlacklist = _ref.navigateFallbackBlacklist,
navigateFallbackWhitelist = _ref.navigateFallbackWhitelist,
offlineGoogleAnalytics = _ref.offlineGoogleAnalytics,
runtimeCaching = _ref.runtimeCaching,
skipWaiting = _ref.skipWaiting,
swDest = _ref.swDest,
workboxSWImport = _ref.workboxSWImport;
var populatedTemplate;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return fse.mkdirp(path.dirname(swDest));
case 3:
_context.next = 8;
break;
case 5:
_context.prev = 5;
_context.t0 = _context['catch'](0);
throw new Error(`${errors['unable-to-make-sw-directory']}. ` + `'${_context.t0.message}'`);
case 8:
populatedTemplate = populateSWTemplate({
cacheId,
clientsClaim,
directoryIndex,
handleFetch,
ignoreUrlParametersMatching,
importScripts,
manifestEntries,
modulePathPrefix,
navigateFallback,
navigateFallbackBlacklist,
navigateFallbackWhitelist,
offlineGoogleAnalytics,
runtimeCaching,
skipWaiting,
workboxSWImport
});
_context.prev = 9;
_context.next = 12;
return fse.writeFile(swDest, populatedTemplate);
case 12:
_context.next = 19;
break;
case 14:
_context.prev = 14;
_context.t1 = _context['catch'](9);
if (!(_context.t1.code === 'EISDIR')) {
_context.next = 18;
break;
}
throw new Error(errors['sw-write-failure-directory']);
case 18:
throw new Error(`${errors['sw-write-failure']}. '${_context.t1.message}'`);
case 19:
case 'end':
return _context.stop();
}
}
}, _callee, undefined, [[0, 5], [9, 14]]);
}));
return function (_x) {
return _ref2.apply(this, arguments);
};
}();

View File

@ -0,0 +1,69 @@
"use strict";
/*
Copyright 2017 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
module.exports = `/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
* See https://goo.gl/2aRDsh
*/
<% if (workboxSWImport) { %>
importScripts(<%= JSON.stringify(workboxSWImport) %>);
<% if (modulePathPrefix) { %>workbox.setConfig({modulePathPrefix: <%= JSON.stringify(modulePathPrefix) %>});<% } %>
<% } %>
<% if (importScripts) { %>
importScripts(
<%= importScripts.map(JSON.stringify).join(',\\n ') %>
);
<% } %>
<% if (cacheId) { %>workbox.core.setCacheNameDetails({prefix: <%= JSON.stringify(cacheId) %>});<% } %>
<% if (skipWaiting) { %>workbox.skipWaiting();<% } %>
<% if (clientsClaim) { %>workbox.clientsClaim();<% } %>
<% if (Array.isArray(manifestEntries)) {%>
/**
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
self.__precacheManifest = <%= JSON.stringify(manifestEntries, null, 2) %>.concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, <%= precacheOptionsString %>);
<% } else { %>
if (Array.isArray(self.__precacheManifest)) {
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, <%= precacheOptionsString %>);
}
<% } %>
<% if (navigateFallback) { %>workbox.routing.registerNavigationRoute(<%= JSON.stringify(navigateFallback) %><% if (navigateFallbackWhitelist || navigateFallbackBlacklist) { %>, {
<% if (navigateFallbackWhitelist) { %>whitelist: [<%= navigateFallbackWhitelist %>],<% } %>
<% if (navigateFallbackBlacklist) { %>blacklist: [<%= navigateFallbackBlacklist %>],<% } %>
}<% } %>);<% } %>
<% if (runtimeCaching) { runtimeCaching.forEach(runtimeCachingString => {%><%= runtimeCachingString %><% });} %>
<% if (offlineAnalyticsConfigString) { %>workbox.googleAnalytics.initialize(<%= offlineAnalyticsConfigString %>);<% } %>`;