-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Motivation for the change, related issues To implement [offline support](#1535) we need to flush the cache every time Playground is updated. This PR introduces a `cacheVersion` to the web service worker which will be used in #1535 for cache busting. In this PR it doesn't do anything, but I wanted to add it as a separate PR to keep #1535 reasonably large. ## Implementation details This PR moves various Vite extensions into a shared `vite-extensions` folder to avoid code duplication. It adds a `buildVersionPlugin` Vite extension to create build versions in different projects (website and remote). The new build version is created in the _Playground remote_ project and sent to _PHP-wasm Web service worker_ in `initializeServiceWorker` options. I had issues with implementing the build version directly in _PHP-wasm Web service worker_, so I ended up working around the issue to unblock offline support. I recommend we move forward with this approach and change it if needed later. A benefit of setting the cache version in Remote is that Playground can control when the cache is busted. ## Testing Instructions (or ideally a Blueprint) - Checkout this branch - add the bellow code [after this line](https://github.com/WordPress/wordpress-playground/blob/3023e5b67767c586a5d160f7ab95519c84f77992/packages/php-wasm/web-service-worker/src/initialize-service-worker.ts#L14) ``` console.log('Service worker initialized', config.cacheVersion); ``` - Delete the service worker in dev tools - Reload Playground - See the version number in the browser console
- Loading branch information
Showing
25 changed files
with
48 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Defined in vite.config.ts | ||
declare module 'virtual:remote-config' { | ||
export const buildVersion: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { execSync } from 'node:child_process'; | ||
import virtualModule from './vite-virtual-module'; | ||
|
||
export const buildVersionPlugin = (name: string) => { | ||
let buildVersion: string; | ||
try { | ||
buildVersion = execSync('git rev-parse HEAD').toString().trim(); | ||
} catch (e) { | ||
buildVersion = (new Date().getTime() / 1000).toFixed(0); | ||
} | ||
|
||
return virtualModule({ | ||
name, | ||
content: ` | ||
export const buildVersion = ${JSON.stringify(buildVersion)};`, | ||
}); | ||
}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.