New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

offline-plugin-patched

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

offline-plugin-patched - npm Package Compare versions

Comparing version 4.8.3 to 4.9.1-fetchfix

lib/default-options.js

26

lib/app-cache.js

@@ -11,2 +11,4 @@ 'use strict';

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }

@@ -24,2 +26,6 @@

var _deepExtend2 = require('deep-extend');
var _deepExtend3 = _interopRequireDefault(_deepExtend2);
var AppCache = (function () {

@@ -105,5 +111,19 @@ function AppCache(options) {

if (this.FALLBACK) {
FALLBACK = 'FALLBACK:\n' + Object.keys(this.FALLBACK).map(function (path) {
return path + ' ' + _this.FALLBACK[path];
if (plugin.appShell) {
var scope = undefined;
if (plugin.relativePaths) {
scope = '';
} else {
scope = plugin.publicPath;
}
FALLBACK = (0, _deepExtend3['default'])(_defineProperty({}, this.pathRewrite(scope), plugin.appShell), this.FALLBACK || {});
} else if (this.FALLBACK) {
FALLBACK = this.FALLBACK;
}
if (FALLBACK) {
FALLBACK = 'FALLBACK:\n' + Object.keys(FALLBACK).map(function (path) {
return path + ' ' + FALLBACK[path];
}).join('\n');

@@ -110,0 +130,0 @@ }

119

lib/index.js

@@ -21,2 +21,8 @@ 'use strict';

var _defaultOptions = require('./default-options');
var _defaultOptions2 = _interopRequireDefault(_defaultOptions);
var _miscUtils = require('./misc/utils');
var _path2 = require('path');

@@ -38,4 +44,2 @@

var _miscUtils = require('./misc/utils');
var _loaderUtils = require('loader-utils');

@@ -57,64 +61,3 @@

var updateStrategies = ['all', 'hash', 'changed'];
var defaultOptions = {
caches: 'all',
publicPath: void 0,
updateStrategy: 'changed',
responseStrategy: 'cache-first',
externals: [],
excludes: ['**/.*', '**/*.map'],
// Hack to have intermediate value, e.g. default one, true and false
relativePaths: ':relativePaths:',
version: null,
autoUpdate: false,
rewrites: function rewrites(asset) {
return asset.replace(/^([\s\S]*?)index.htm(l?)$/, function (match, dir) {
if ((0, _miscUtils.isAbsoluteURL)(match)) {
return match;
}
return dir || './';
});
},
cacheMaps: null,
ServiceWorker: {
output: 'sw.js',
entry: _path3['default'].join(__dirname, '../tpls/empty-entry.js'),
scope: null,
events: false,
prefetchRequest: {
credentials: 'omit',
headers: void 0,
mode: 'cors',
cache: void 0
},
minify: null,
navigateFallbackForRedirects: true
},
AppCache: {
NETWORK: '*',
FALLBACK: null,
directory: 'appcache/',
caches: ['main'],
events: false,
disableInstall: false,
includeCrossOrigin: false
},
// Needed for testing
__tests: {
swMetadataOnly: false,
ignoreRuntime: false,
noVersionDump: false
},
// Not yet used
alwaysRevalidate: void 0,
preferOnline: void 0,
ignoreSearch: ['**']
};
var OfflinePlugin = (function () {

@@ -126,3 +69,3 @@ function OfflinePlugin(options) {

this.options = (0, _deepExtend2['default'])({}, defaultOptions, options);
this.options = (0, _deepExtend2['default'])({}, _defaultOptions2['default'], options);
this.hash = null;

@@ -177,3 +120,3 @@ this.assets = null;

var rewrites = this.options.rewrites || defaultOptions.rewrites;
var rewrites = this.options.rewrites || _defaultOptions2['default'].rewrites;

@@ -202,4 +145,18 @@ if (typeof rewrites === 'function') {

this.cacheMaps = this.stringifyCacheMaps(this.options.cacheMaps);
if (this.options.appShell && typeof this.options.appShell === 'string') {
this.appShell = this.options.appShell;
}
var cacheMaps = this.options.cacheMaps;
if (this.appShell) {
// Make appShell the latest in the chain so it could be overridden
cacheMaps = (cacheMaps || []).concat({
match: new Function('return new URL(' + JSON.stringify(this.appShell) + ', location);'),
requestTypes: ['navigate']
});
}
this.cacheMaps = this.stringifyCacheMaps(cacheMaps);
this.REST_KEY = ':rest:';

@@ -247,3 +204,3 @@ this.EXTERNALS_KEY = ':externals:';

if (this.relativePaths === defaultOptions.relativePaths) {
if (this.relativePaths === _defaultOptions2['default'].relativePaths) {
this.relativePaths = !this.publicPath;

@@ -298,4 +255,11 @@ }

var runtimeTemplatePath = _path3['default'].resolve(__dirname, '../tpls/runtime-template.js');
var hasRuntime = true;
if (compilation.fileDependencies.indexOf(runtimeTemplatePath) === -1 && !_this2.__tests.ignoreRuntime) {
if (compilation.fileDependencies.indexOf) {
hasRuntime = compilation.fileDependencies.indexOf(runtimeTemplatePath) !== -1;
} else if (compilation.fileDependencies.has) {
hasRuntime = compilation.fileDependencies.has(runtimeTemplatePath);
}
if (!hasRuntime && !_this2.__tests.ignoreRuntime) {
compilation.errors.push(new Error('OfflinePlugin: Plugin\'s runtime wasn\'t added to one of your bundle entries. See this https://goo.gl/YwewYp for details.'));

@@ -338,6 +302,6 @@ callback();

var caches = this.options.caches || defaultOptions.caches;
var caches = this.options.caches || _defaultOptions2['default'].caches;
if (this.options.safeToUseOptionalCaches !== true && (caches.additional && caches.additional.length || caches.optional && caches.optional.length)) {
compilation.warnings.push(new Error('OfflinePlugin: Cache sections `additional` and `optional` could be used ' + 'only when each asset passed to it has unique name (e.g. hash or version in it) and ' + 'is permanently available for given URL. If you think that it\' your case, ' + 'set `safeToUseOptionalCaches` option to `true`, to remove this warning.'));
compilation.warnings.push(new Error('OfflinePlugin: Cache sections `additional` and `optional` could be used ' + 'only when each asset passed to it has unique name (e.g. hash or version in it) and ' + 'is permanently available for given URL. If you think that it\'s your case, ' + 'set `safeToUseOptionalCaches` option to `true`, to remove this warning.'));
}

@@ -444,3 +408,3 @@

compilation.warnings.push(new Error('OfflinePlugin: Cache asset [' + cacheKey + '] is not found in the output assets,' + 'if the asset is not processed by webpack, move it to the |externals| option to remove this warning.'));
compilation.warnings.push(new Error('OfflinePlugin: Cache asset [' + cacheKey + '] is not found in the output assets, ' + 'if the asset is not processed by webpack, move it to the |externals| option to remove this warning.'));
} else {

@@ -613,5 +577,6 @@ assets.splice(index, 1);

var to = undefined;
var match = undefined;
if (typeof map.to === 'function') {
to = map.to + '';
to = (0, _miscUtils.functionToString)(map.to);
} else {

@@ -621,4 +586,10 @@ to = map.to ? JSON.stringify(map.to) : null;

if (typeof map.match === 'function') {
match = (0, _miscUtils.functionToString)(map.match);
} else {
match = map.match + '';
}
return {
match: map.match + '',
match: match,
to: to,

@@ -773,3 +744,3 @@ requestTypes: map.requestTypes || null

OfflinePlugin.defaultOptions = defaultOptions;
OfflinePlugin.defaultOptions = _defaultOptions2['default'];
module.exports = exports['default'];

@@ -52,4 +52,6 @@ 'use strict';

var helpersCode = [', {', 'loaders: ' + loadersCode + ',', 'cacheMaps: ' + cacheMapsCode + ',', '}'];
var navigationPreloadCode = params.navigationPreload;
var helpersCode = [', {', 'loaders: ' + loadersCode + ',', 'cacheMaps: ' + cacheMapsCode + ',', 'navigationPreload: ' + navigationPreloadCode + ',', '}'];
Promise.all([].concat(_toConsumableArray(modules.map(function (mod) {

@@ -56,0 +58,0 @@ return readFile(path.join(__dirname, mod));

@@ -10,4 +10,8 @@ 'use strict';

var cacheMaps = helpers.cacheMaps;
// navigationPreload: true, { map: (URL) => URL, test: (URL) => boolean }
var navigationPreload = helpers.navigationPreload;
// (update)strategy: changed, all
var strategy = params.strategy;
// responseStrategy: cache-first, network-first
var responseStrategy = params.responseStrategy;

@@ -21,7 +25,2 @@

// Not used yet
// const alwaysRevalidate = params.alwaysRevalidate;
// const ignoreSearch = params.ignoreSearch;
// const preferOnline = params.preferOnline;
var CACHE_PREFIX = params.name;

@@ -31,2 +30,3 @@ var CACHE_TAG = params.version;

var PRELOAD_CACHE_NAME = CACHE_PREFIX + '$preload';
var STORED_DATA_KEY = '__offline_webpack__data';

@@ -37,4 +37,7 @@

var allAssets = [].concat(assets.main, assets.additional, assets.optional);
// Deprecated {
var navigateFallbackURL = params.navigateFallbackURL;
var navigateFallbackForRedirects = params.navigateFallbackForRedirects;
// }

@@ -70,2 +73,6 @@ self.addEventListener('install', function (event) {

if (navigationPreload && self.registration.navigationPreload) {
activation = Promise.all([activation, self.registration.navigationPreload.enable()]);
}
event.waitUntil(activation);

@@ -272,8 +279,30 @@ });

// If isn't a cached asset and is a navigation request,
// fallback to navigateFallbackURL if available
// perform network request and fallback to navigateFallbackURL if available.
//
// Requesting with fetchWithPreload().
// Preload is used only if navigationPreload is enabled and
// navigationPreload mapping is not used.
if (navigateFallbackURL && isNavigateRequest(event.request)) {
event.respondWith(handleNavigateFallback(fetch(event.request)));
event.respondWith(handleNavigateFallback(fetchWithPreload(event)));
return;
}
if (navigationPreload === true) {
event.respondWith(fetchWithPreload(event));
return;
}
// Something else, positive, but not `true`
if (navigationPreload) {
var preloadedResponse = retrivePreloadedResponse(event);
if (preloadedResponse) {
event.respondWith(preloadedResponse);
return;
}
}
// Logic exists here if no cache match, or no preload
return;
}

@@ -287,8 +316,8 @@

// Logic exists here if no cache match
return;
}
// Logic of caching / fetching is here
// * urlString -- url to match from the CACHE_NAME
// * event.request -- original Request to perform fetch() if necessary
// Cache handling/storing/fetching starts here
var resource = undefined;

@@ -299,3 +328,3 @@

}
// 'cache-first'
// 'cache-first' otherwise
// (responseStrategy has been validated before)

@@ -326,2 +355,4 @@ else {

function cacheFirstResponse(event, urlString, cacheUrl) {
handleNavigationPreload(event);
return cachesMatch(cacheUrl, CACHE_NAME).then(function (response) {

@@ -371,3 +402,3 @@ if (response) {

function networkFirstResponse(event, urlString, cacheUrl) {
return fetch(event.request).then(function (response) {
return fetchWithPreload(event).then(function (response) {
if (response.ok) {

@@ -395,2 +426,112 @@ if (DEBUG) {

function handleNavigationPreload(event) {
if (navigationPreload && typeof navigationPreload.map === 'function' &&
// Use request.mode === 'navigate' instead of isNavigateRequest
// because everything what supports navigationPreload supports
// 'navigate' request.mode
event.preloadResponse && event.request.mode === 'navigate') {
var mapped = navigationPreload.map(new URL(event.request.url), event.request);
if (mapped) {
storePreloadedResponse(mapped, event);
}
}
}
// Temporary in-memory store for faster access
var navigationPreloadStore = new Map();
function storePreloadedResponse(_url, event) {
var url = new URL(_url, location);
var preloadResponsePromise = event.preloadResponse;
navigationPreloadStore.set(preloadResponsePromise, {
url: url,
response: preloadResponsePromise
});
var isSamePreload = function isSamePreload() {
return navigationPreloadStore.has(preloadResponsePromise);
};
var storing = preloadResponsePromise.then(function (res) {
// Return if preload isn't enabled or hasn't happened
if (!res) return;
// If navigationPreloadStore already consumed
// or navigationPreloadStore already contains another preload,
// then do not store anything and return
if (!isSamePreload()) {
return;
}
var clone = res.clone();
// Storing the preload response for later consume (hasn't yet been consumed)
return caches.open(PRELOAD_CACHE_NAME).then(function (cache) {
if (!isSamePreload()) return;
return cache.put(url, clone).then(function () {
if (!isSamePreload()) {
return caches.open(PRELOAD_CACHE_NAME).then(function (cache) {
return cache['delete'](url);
});
}
});
});
});
event.waitUntil(storing);
}
function retriveInMemoryPreloadedResponse(url) {
if (!navigationPreloadStore) {
return;
}
var foundResponse = undefined;
var foundKey = undefined;
navigationPreloadStore.forEach(function (store, key) {
if (store.url.href === url.href) {
foundResponse = store.response;
foundKey = key;
}
});
if (foundResponse) {
navigationPreloadStore['delete'](foundKey);
return foundResponse;
}
}
function retrivePreloadedResponse(event) {
var url = new URL(event.request.url);
if (self.registration.navigationPreload && navigationPreload && navigationPreload.test && navigationPreload.test(url, event.request)) {} else {
return;
}
var fromMemory = retriveInMemoryPreloadedResponse(url);
var request = event.request;
if (fromMemory) {
event.waitUntil(caches.open(PRELOAD_CACHE_NAME).then(function (cache) {
return cache['delete'](request);
}));
return fromMemory;
}
return cachesMatch(request, PRELOAD_CACHE_NAME).then(function (response) {
if (response) {
event.waitUntil(caches.open(PRELOAD_CACHE_NAME).then(function (cache) {
return cache['delete'](request);
}));
}
return response || fetch(event.request);
});
}
function handleNavigateFallback(fetching) {

@@ -467,3 +608,7 @@ return fetching['catch'](function () {}).then(function (response) {

var extracted = [];
var addAll = [];
return Promise.all(requests.map(function (request) {
if (bustValue) {

@@ -473,18 +618,15 @@ request = applyCacheBust(request, bustValue);

return fetch(request, requestInit).then(fixRedirectedResponse);
})).then(function (responses) {
if (responses.some(function (response) {
return !response.ok;
})) {
return Promise.reject(new Error('Wrong response status'));
}
return fetch(request, requestInit).then(fixRedirectedResponse).then(function (response) {
var extracted = [];
var addAll = responses.map(function (response, i) {
if (!response.ok) {
return Promise.reject(new Error('Wrong response status'));
}
if (allowLoaders) {
extracted.push(extractAssetsWithLoaders(requests[i], response));
extracted.push(extractAssetsWithLoaders(request, response));
}
return cache.put(requests[i], response);
addAll.push(cache.put(request, response));
});
})).then(function () {

@@ -538,3 +680,3 @@ if (extracted.length) {

if (request.mode === 'navigate') {
if (isNavigateRequest(request)) {
requestType = 'navigate';

@@ -568,2 +710,12 @@ } else if (url.origin === location.origin) {

}
function fetchWithPreload(event) {
if (!event.preloadResponse || navigationPreload !== true) {
return fetch(event.request);
}
return event.preloadResponse.then(function (response) {
return response || fetch(event.request);
});
}
}

@@ -575,3 +727,3 @@

}).then(function (response) {
if (isNotRedirectedResponse()) {
if (isNotRedirectedResponse(response)) {
return response;

@@ -598,29 +750,2 @@ }

function getClientsURLs() {
if (!self.clients) {
return Promise.resolve([]);
}
return self.clients.matchAll({
includeUncontrolled: true
}).then(function (clients) {
if (!clients.length) return [];
var result = [];
clients.forEach(function (client) {
var url = new URL(client.url);
url.search = '';
url.hash = '';
var urlString = url.toString();
if (!result.length || result.indexOf(urlString) === -1) {
result.push(urlString);
}
});
return result;
});
}
function isNavigateRequest(request) {

@@ -627,0 +752,0 @@ return request.mode === 'navigate' || request.headers.get('Upgrade-Insecure-Requests') || (request.headers.get('Accept') || '').indexOf('text/html') !== -1;

@@ -10,2 +10,4 @@ 'use strict';

exports.isAbsoluteURL = isAbsoluteURL;
exports.functionToString = functionToString;
exports.arrowFnToNormalFn = arrowFnToNormalFn;

@@ -79,2 +81,35 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

function functionToString(fn) {
if (typeof fn !== 'function') {
return '(void 0)';
}
var string = fn + '';
return arrowFnToNormalFn(string);
}
// Migrate to separate npm-package with full tests
function arrowFnToNormalFn(string) {
var match = string.match(/^([\s\S]+?)=\>(\s*{)?([\s\S]*?)(}\s*)?$/);
if (!match) {
return string;
}
var args = match[1];
var body = match[3];
var needsReturn = !(match[2] && match[4]);
args = args.replace(/^(\s*\(\s*)([\s\S]*?)(\s*\)\s*)$/, '$2');
if (needsReturn) {
body = 'return ' + body;
}
return 'function(' + args + ') {' + body + '}';
}
exports.isAbsolutePath = isAbsolutePath;

@@ -54,2 +54,3 @@ 'use strict';

this.prefetchRequest = this.validatePrefetch(options.prefetchRequest);
this.navigationPreload = options.navigationPreload;

@@ -81,3 +82,4 @@ var cacheNameQualifier = '';

loaders: Object.keys(plugin.loaders),
cacheMaps: plugin.cacheMaps
cacheMaps: plugin.cacheMaps,
navigationPreload: this.stringifyNavigationPreload(this.navigationPreload, plugin)
});

@@ -260,2 +262,23 @@

}
}, {
key: 'stringifyNavigationPreload',
value: function stringifyNavigationPreload(navigationPreload, plugin) {
var result = undefined;
if (typeof navigationPreload === 'object') {
result = navigationPreload = '{\n map: ' + (0, _miscUtils.functionToString)(navigationPreload.map) + ',\n test: ' + (0, _miscUtils.functionToString)(navigationPreload.test) + '\n }';
} else {
if (typeof navigationPreload !== 'boolean') {
if (plugin.responseStrategy === 'network-first') {
navigationPreload = true;
} else {
navigationPreload = false;
}
}
result = JSON.stringify(navigationPreload);
}
return result;
}
}]);

@@ -262,0 +285,0 @@

{
"name": "offline-plugin-patched",
"version": "4.8.3",
"version": "4.9.1-fetchfix",
"description": "offline-plugin for webpack, patched for AppCache fixes",

@@ -13,3 +13,7 @@ "main": "lib/index.js",

"scripts": {
"test": "node tests/legacy/run && eslint -c configs/eslint.tests.json 'tests/**/**.js'",
"test": "node tests/legacy/run && eslint -c configs/eslint.tests.json 'tests/legacy/**.js'",
"test:browser": "node tests/run-browser-tests.js",
"test:ci_fixtures": "npm run test",
"test:ci_browser": "npm install puppeteer@^0.12.0 && npm run test:browser",
"test:ci_all": "npm run test:ci_fixtures && npm run test:ci_browser",
"build": "./node_modules/.bin/babel src/ -d lib/",

@@ -24,5 +28,6 @@ "watch": "npm run build -- --watch",

"release:latest:major": "npm version major && npm run tag && npm run publish:latest",
"release:next:patch": "npm version patch && npm run tag && npm run publish:next",
"release:next:minor": "npm version minor && npm run tag && npm run publish:next",
"release:next:major": "npm version major && npm run tag && npm run publish:next"
"release:next:patch": "npm --no-git-tag-version version prepatch && npm run publish:next",
"release:next:minor": "npm --no-git-tag-version version preminor && npm run publish:next",
"release:next:major": "npm --no-git-tag-version version premajor && npm run publish:next",
"release:next:update": "npm --no-git-tag-version version prerelease && npm run publish:next"
},

@@ -36,3 +41,3 @@ "collective": {

"type": "git",
"url": "https://github.com/jampy81/offline-plugin.git"
"url": "https://github.com/NekR/offline-plugin.git"
},

@@ -42,2 +47,3 @@ "author": "Arthur Stolyar <nekr.fabula@gmail.com>",

"dependencies": {
"babel": "^5.8.38",
"deep-extend": "^0.4.0",

@@ -72,2 +78,3 @@ "ejs": "^2.3.4",

"cli-highlight": "^1.1.4",
"copy-webpack-plugin": "^4.2.0",
"del": "^2.2.2",

@@ -77,2 +84,5 @@ "diff": "^3.0.1",

"eslint": "^3.14.1",
"express": "^4.16.2",
"glob": "^7.1.2",
"mocha": "^4.0.1",
"on-build-webpack": "^0.1.0",

@@ -79,0 +89,0 @@ "webpack": "1.14.0"

@@ -1,2 +0,2 @@

<div align="center">
<div align="center">
<a href="https://offline-plugin.now.sh/"><img src="https://rawgit.com/NekR/offline-plugin/master/logo/logo.svg" width="120" alt="offline-plugin logo"></a>

@@ -10,3 +10,2 @@

<a href="https://www.npmjs.com/package/offline-plugin"><img src="https://img.shields.io/npm/dm/offline-plugin.svg?maxAge=3600" alt="npm"></a>
<a href="https://gitter.im/NekR/offline-plugin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/NekR/offline-plugin.svg" alt="Join the chat at https://gitter.im/NekR/offline-plugin"></a>
</div>

@@ -18,3 +17,3 @@ <br>

<div align="center">
<strong>Demo:<br><a href="https://offline-plugin.now.sh/"> Progressive Web App built with <code>offline-plugin</code></a></strong><br>
<strong>Demo:<br><a href="https://offline-plugin.now.sh/"> Progressive Web App built with <code>offline-plugin</code></a></strong><br>
<div>(<a href="https://github.com/NekR/offline-plugin-pwa"><i>source code</i></a>)</div>

@@ -141,2 +140,3 @@ </div>

* [Online Board](https://onlineboard.sonnywebdesign.com/) ([source](https://github.com/andreasonny83/online-board))
* [CodePan](https://codepan.net) ([source](https://github.com/egoist/codepan))

@@ -188,3 +188,3 @@

See [CONTRIBUTING](CONTIBUTING.md)
See [CONTRIBUTING](CONTRIBUTING.md)

@@ -191,0 +191,0 @@ ## License

@@ -147,2 +147,3 @@ var appCacheIframe;

var match = (e.data + '').match(/__offline-plugin_AppCacheEvent:(\w+)/);
if (!match) return;
var event = match[1];

@@ -149,0 +150,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc