DEV: Cachebust workbox assets (#23383)

The changes in e1d27400f5 slightly changed the sourcemap paths of our workbox assets. The sourcemaps now have the extension `.prod.map` instead of `prod.js.map`. However, since the version number of workbox didn't change, the directory digest remained the same, and so cached versions of the JS were pointing to the now-nonexistant map files.

This commit introduces a cachebusting constant which we can bump for these kinds of changes in future.
This commit is contained in:
David Taylor 2023-09-04 16:04:39 +01:00 committed by GitHub
parent aaf47c02bc
commit f645706e6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -2,6 +2,10 @@ const crypto = require("crypto");
const mergeTrees = require("broccoli-merge-trees");
const funnel = require("broccoli-funnel");
// Bump to cache-bust if there are any changes to the workbox compilation logic
// which are not caused by a simple workbox version bump
const COMPILER_VERSION = 2;
module.exports = function generateWorkboxTree() {
const workboxDeps = [
"workbox-sw",
@ -25,7 +29,7 @@ module.exports = function generateWorkboxTree() {
// Sprockets' default behaviour for these files is disabled via freedom_patches/sprockets.rb.
const versionHash = crypto
.createHash("md5")
.update(versions.join("|"))
.update(`${versions.join("|")}|${COMPILER_VERSION}`)
.digest("hex");
return funnel(mergeTrees(nodes), {