From 1263be617ffe70d8c56dfb04fc75791e148cbbd4 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 31 Mar 2020 14:23:24 -0700 Subject: [PATCH] Include workbox version in library path to ensure cache busting --- .gitignore | 2 +- Gruntfile.js | 11 +++++++++-- pwa.php | 3 ++- ...lass-wp-service-worker-configuration-component.php | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 30dbefd35..852b43693 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ /phpcs.xml /.phpcs.xml *.zip -/wp-includes/js/workbox/ +/wp-includes/js/workbox* diff --git a/Gruntfile.js b/Gruntfile.js index b4e6b82be..dc510d019 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -32,7 +32,7 @@ module.exports = function (grunt) { }, install_workbox: { command: - "if [ -e wp-includes/js/workbox* ]; then rm -r wp-includes/js/workbox*; fi; npx workbox copyLibraries wp-includes/js/ && mv wp-includes/js/workbox-v* wp-includes/js/workbox", + "if [ -e wp-includes/js/workbox* ]; then rm -r wp-includes/js/workbox*; fi; npx workbox copyLibraries wp-includes/js/", }, create_build_zip: { command: @@ -97,7 +97,7 @@ module.exports = function (grunt) { file ); }); - paths.push("wp-includes/js/workbox/*"); + paths.push("wp-includes/js/workbox*/**"); grunt.task.run("clean"); grunt.task.run("readme"); @@ -124,6 +124,13 @@ module.exports = function (grunt) { "$1" + version ); } + + const workboxVersion = grunt.file.readJSON("package.json") + .devDependencies["workbox-cli"]; + content = content.replace( + /define\(.+?PWA_WORKBOX_VERSION.+/, + `define( 'PWA_WORKBOX_VERSION', '${workboxVersion}' );` + ); } return content; }, diff --git a/pwa.php b/pwa.php index b85deddd8..8874e9ea3 100644 --- a/pwa.php +++ b/pwa.php @@ -20,6 +20,7 @@ define( 'PWA_VERSION', '0.4.0' ); define( 'PWA_PLUGIN_FILE', __FILE__ ); define( 'PWA_PLUGIN_DIR', dirname( __FILE__ ) ); +define( 'PWA_WORKBOX_VERSION', json_decode( file_get_contents( PWA_PLUGIN_DIR . '/package.json' ), true )['devDependencies']['workbox-cli'] ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Replaced with version literal build. define( 'PWA_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); /** @@ -95,7 +96,7 @@ function _pwa_print_build_needed_notice() { get_current_scope(); - $workbox_dir = 'wp-includes/js/workbox/'; + $workbox_dir = sprintf( 'wp-includes/js/workbox-v%s/', PWA_WORKBOX_VERSION ); $script = ''; if ( SCRIPT_DEBUG ) {