From 13aaa16dd9711e517059286224dde9c11ebaa567 Mon Sep 17 00:00:00 2001 From: nibtime <52962482+nibtime@users.noreply.github.com> Date: Thu, 18 Jun 2020 11:29:57 +0200 Subject: [PATCH] fix(gatsby-plugin-offline): versioned import of idb-keyval (#24938) * fix(sw): versioned import of idb-keyval with the version included it is ok to cache it immutable alongside the other fingerprinted js files produced by Gatsby * style: fix linting errors * fix(sw): replace versioned import in sw-append.js --- packages/gatsby-plugin-offline/src/gatsby-node.js | 5 ++++- packages/gatsby-plugin-offline/src/sw-append.js | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-plugin-offline/src/gatsby-node.js b/packages/gatsby-plugin-offline/src/gatsby-node.js index 1f5aa3981d620..ed4ded9be8538 100644 --- a/packages/gatsby-plugin-offline/src/gatsby-node.js +++ b/packages/gatsby-plugin-offline/src/gatsby-node.js @@ -162,7 +162,9 @@ exports.onPostBuild = ( const idbKeyvalFile = `idb-keyval-iife.min.js` const idbKeyvalSource = require.resolve(`idb-keyval/dist/${idbKeyvalFile}`) - const idbKeyvalDest = `public/${idbKeyvalFile}` + const idbKeyvalPackageJson = require(`idb-keyval/package.json`) + const idbKeyValVersioned = `idb-keyval-${idbKeyvalPackageJson.version}-iife.min.js` + const idbKeyvalDest = `public/${idbKeyValVersioned}` fs.createReadStream(idbKeyvalSource).pipe(fs.createWriteStream(idbKeyvalDest)) const swDest = `public/sw.js` @@ -183,6 +185,7 @@ exports.onPostBuild = ( const swAppend = fs .readFileSync(`${__dirname}/sw-append.js`, `utf8`) + .replace(/%idbKeyValVersioned%/g, idbKeyValVersioned) .replace(/%pathPrefix%/g, pathPrefix) .replace(/%appFile%/g, appFile) diff --git a/packages/gatsby-plugin-offline/src/sw-append.js b/packages/gatsby-plugin-offline/src/sw-append.js index 683d24b1d64e2..df7a37c4ab01e 100644 --- a/packages/gatsby-plugin-offline/src/sw-append.js +++ b/packages/gatsby-plugin-offline/src/sw-append.js @@ -1,6 +1,5 @@ /* global importScripts, workbox, idbKeyval */ - -importScripts(`idb-keyval-iife.min.js`) +importScripts(`%idbKeyValVersioned%`) const { NavigationRoute } = workbox.routing