mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-17 06:16:33 +00:00
Link old service worker to new name (#21581)
This commit is contained in:
parent
62d8434596
commit
dfbf4abd5d
@ -29,7 +29,7 @@ const compressDistZopfli = (rootDir, modernDir) =>
|
|||||||
[
|
[
|
||||||
`${rootDir}/**/${filesGlob}`,
|
`${rootDir}/**/${filesGlob}`,
|
||||||
`!${modernDir}/**/${filesGlob}`,
|
`!${modernDir}/**/${filesGlob}`,
|
||||||
`!${rootDir}/sw-modern.js`,
|
`!${rootDir}/{sw-modern,service_worker}.js`,
|
||||||
`${rootDir}/{authorize,onboarding}.html`,
|
`${rootDir}/{authorize,onboarding}.html`,
|
||||||
],
|
],
|
||||||
{ base: rootDir }
|
{ base: rootDir }
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import { deleteAsync } from "del";
|
import { deleteAsync } from "del";
|
||||||
import gulp from "gulp";
|
import gulp from "gulp";
|
||||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
import { mkdir, readFile, symlink, writeFile } from "node:fs/promises";
|
||||||
import { join, relative } from "node:path";
|
import { basename, join, relative } from "node:path";
|
||||||
import { injectManifest } from "workbox-build";
|
import { injectManifest } from "workbox-build";
|
||||||
import paths from "../paths.cjs";
|
import paths from "../paths.cjs";
|
||||||
|
|
||||||
@ -41,10 +41,11 @@ gulp.task("gen-service-worker-app-prod", () =>
|
|||||||
await readFile(join(outPath, "manifest.json"), "utf-8")
|
await readFile(join(outPath, "manifest.json"), "utf-8")
|
||||||
);
|
);
|
||||||
const swSrc = join(paths.app_output_root, manifest["service-worker.js"]);
|
const swSrc = join(paths.app_output_root, manifest["service-worker.js"]);
|
||||||
|
const swDest = join(paths.app_output_root, `sw-${build}.js`);
|
||||||
const buildDir = relative(paths.app_output_root, outPath);
|
const buildDir = relative(paths.app_output_root, outPath);
|
||||||
const { warnings } = await injectManifest({
|
const { warnings } = await injectManifest({
|
||||||
swSrc,
|
swSrc,
|
||||||
swDest: join(paths.app_output_root, `sw-${build}.js`),
|
swDest,
|
||||||
injectionPoint: "__WB_MANIFEST__",
|
injectionPoint: "__WB_MANIFEST__",
|
||||||
// Files that mach this pattern will be considered unique and skip revision check
|
// Files that mach this pattern will be considered unique and skip revision check
|
||||||
// ignore JS files + translation files
|
// ignore JS files + translation files
|
||||||
@ -76,6 +77,11 @@ gulp.task("gen-service-worker-app-prod", () =>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
await deleteAsync(`${swSrc}?(.map)`);
|
await deleteAsync(`${swSrc}?(.map)`);
|
||||||
|
// Needed to install new SW from a cached HTML
|
||||||
|
if (build === "modern") {
|
||||||
|
const swOld = join(paths.app_output_root, "service_worker.js");
|
||||||
|
await symlink(basename(swDest), swOld);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -23,13 +23,6 @@ export const registerServiceWorker = async (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reg?.active?.scriptURL.includes("service_worker.js")) {
|
|
||||||
// We are running an old version of the service worker. Force reload.
|
|
||||||
await reg.unregister();
|
|
||||||
// @ts-ignore Firefox supports force reload
|
|
||||||
location.reload(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
reg.addEventListener("updatefound", () => {
|
reg.addEventListener("updatefound", () => {
|
||||||
const installingWorker = reg.installing;
|
const installingWorker = reg.installing;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user