diff --git a/packages/gatsby-plugin-offline/src/gatsby-browser.js b/packages/gatsby-plugin-offline/src/gatsby-browser.js index 8285b08d6bcb2..a74e3aaf3ba94 100644 --- a/packages/gatsby-plugin-offline/src/gatsby-browser.js +++ b/packages/gatsby-plugin-offline/src/gatsby-browser.js @@ -107,3 +107,14 @@ exports.onRouteUpdate = ({ location, getResourceURLsForPathname }) => { exports.onPostPrefetchPathname = ({ pathname, getResourceURLsForPathname }) => { setPathResources(pathname, getResourceURLsForPathname) } + +export const onServiceWorkerUpdateReady = () => { + const answer = window.confirm( + `This application has been updated. ` + + `Reload to display the latest version?` + ) + + if (answer === true) { + window.location.reload() + } +} diff --git a/packages/gatsby-plugin-offline/src/gatsby-node.js b/packages/gatsby-plugin-offline/src/gatsby-node.js index a392d03412f0d..4c959e6c47743 100644 --- a/packages/gatsby-plugin-offline/src/gatsby-node.js +++ b/packages/gatsby-plugin-offline/src/gatsby-node.js @@ -1,13 +1,11 @@ -// use `let` to workaround https://github.com/jhnns/rewire/issues/144 -/* eslint-disable prefer-const */ -let fs = require(`fs`) -let workboxBuild = require(`workbox-build`) +const fs = require(`fs`) +const workboxBuild = require(`workbox-build`) const path = require(`path`) const { slash } = require(`gatsby-core-utils`) const glob = require(`glob`) const _ = require(`lodash`) -let getResourcesFromHTML = require(`./get-resources-from-html`) +const getResourcesFromHTML = require(`./get-resources-from-html`) exports.onPreBootstrap = ({ cache }) => { const appShellSourcePath = path.join(__dirname, `app-shell.js`) @@ -220,49 +218,3 @@ exports.onPostBuild = ( ) }) } - -const MATCH_ALL_KEYS = /^/ -exports.pluginOptionsSchema = function ({ Joi }) { - // These are the options of the v3: https://www.gatsbyjs.com/plugins/gatsby-plugin-offline/#available-options - return Joi.object({ - precachePages: Joi.array() - .items(Joi.string()) - .description( - `An array of pages whose resources should be precached by the service worker, using an array of globs` - ), - appendScript: Joi.string().description( - `A file (path) to be appended at the end of the generated service worker` - ), - debug: Joi.boolean().description( - `Specifies whether Workbox should show debugging output in the browser console at runtime. When undefined, defaults to showing debug messages on localhost only` - ), - workboxConfig: Joi.object({ - importWorkboxFrom: Joi.string(), - globDirectory: Joi.string(), - globPatterns: Joi.array().items(Joi.string()), - modifyURLPrefix: Joi.object().pattern(MATCH_ALL_KEYS, Joi.string()), - cacheId: Joi.string(), - dontCacheBustURLsMatching: Joi.object().instance(RegExp), - maximumFileSizeToCacheInBytes: Joi.number(), - runtimeCaching: Joi.array().items( - Joi.object({ - urlPattern: Joi.object().instance(RegExp), - handler: Joi.string().valid( - `StaleWhileRevalidate`, - `CacheFirst`, - `NetworkFirst`, - `NetworkOnly`, - `CacheOnly` - ), - options: Joi.object({ - networkTimeoutSeconds: Joi.number(), - }), - }) - ), - skipWaiting: Joi.boolean(), - clientsClaim: Joi.boolean(), - }) - .description(`Overrides workbox configuration. Helpful documentation: https://www.gatsbyjs.com/plugins/gatsby-plugin-offline/#overriding-workbox-configuration - `), - }) -}