nuxt-skew-protection 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/module.mjs +41 -21
- package/dist/runtime/app/components/SkewNotification.d.vue.ts +3 -2
- package/dist/runtime/app/components/SkewNotification.vue +16 -11
- package/dist/runtime/app/components/SkewNotification.vue.d.ts +3 -2
- package/dist/runtime/app/composables/useRuntimeConfigSkewProtection.js +4 -1
- package/dist/runtime/app/composables/useSkewProtection.d.ts +1 -1
- package/dist/runtime/app/composables/useSkewProtection.js +12 -5
- package/dist/runtime/app/plugins/check-updates-sse.client.js +3 -4
- package/dist/runtime/app/plugins/check-updates-websocket.client.js +4 -18
- package/dist/runtime/app/plugins/sw-track-user-modules.client.d.ts +1 -9
- package/dist/runtime/app/plugins/sw-track-user-modules.client.js +47 -24
- package/dist/runtime/server/routes/_skew/ws.js +3 -3
- package/dist/runtime/types.d.ts +1 -0
- package/dist/sw/_nuxt-skew-sw.js +1 -0
- package/package.json +2 -2
- package/dist/module.cjs +0 -737
- package/dist/module.d.cts +0 -64
- package/dist/module.d.ts +0 -64
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -204,7 +204,10 @@ async function resolveBuildTimeDriver(storage) {
|
|
|
204
204
|
if (!namespaceId) {
|
|
205
205
|
namespaceId = await detectCloudflareKVNamespace();
|
|
206
206
|
}
|
|
207
|
-
return cloudflareKVWranglerDriver(
|
|
207
|
+
return cloudflareKVWranglerDriver({
|
|
208
|
+
namespaceId,
|
|
209
|
+
...driverOptions
|
|
210
|
+
});
|
|
208
211
|
}
|
|
209
212
|
case "vercel-kv": {
|
|
210
213
|
return vercelKVCLIDriver(driverOptions);
|
|
@@ -548,7 +551,8 @@ function createAssetManager(options) {
|
|
|
548
551
|
storeAssetsInStorage,
|
|
549
552
|
listExistingVersions,
|
|
550
553
|
restoreOldAssetsToPublic,
|
|
551
|
-
augmentBuildMetadata
|
|
554
|
+
augmentBuildMetadata,
|
|
555
|
+
getManifest: () => getVersionManifest(storage)
|
|
552
556
|
};
|
|
553
557
|
}
|
|
554
558
|
|
|
@@ -589,7 +593,7 @@ const module = defineNuxtModule({
|
|
|
589
593
|
cookie: options.cookie,
|
|
590
594
|
debug: options.debug
|
|
591
595
|
};
|
|
592
|
-
const nitroPreset =
|
|
596
|
+
const nitroPreset = resolveNitroPreset(nuxt.options.nitro);
|
|
593
597
|
addTypeTemplate({
|
|
594
598
|
filename: "types/nuxt-skew-protection.d.ts",
|
|
595
599
|
getContents: () => {
|
|
@@ -670,29 +674,45 @@ export {}
|
|
|
670
674
|
nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || [];
|
|
671
675
|
nuxt.options.nitro.publicAssets.push({
|
|
672
676
|
dir: swPath,
|
|
673
|
-
maxAge: 0
|
|
677
|
+
maxAge: 0
|
|
674
678
|
// Service workers should not be cached
|
|
675
|
-
baseURL: "/_skew"
|
|
676
679
|
});
|
|
677
680
|
if (options.storage && options.bundlePreviousDeploymentChunks) {
|
|
678
|
-
nuxt.hook("nitro:
|
|
681
|
+
nuxt.hook("nitro:init", (nitro) => {
|
|
679
682
|
const buildId = nuxt.options.runtimeConfig.app.buildId ||= nuxt.options.buildId;
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
683
|
+
let assetManager;
|
|
684
|
+
nitro.hooks.hook("compiled", async () => {
|
|
685
|
+
const outputDir = nitro.options.output.dir;
|
|
686
|
+
assetManager = createAssetManager({
|
|
687
|
+
...options,
|
|
688
|
+
driver: await resolveBuildTimeDriver(options.storage)
|
|
689
|
+
});
|
|
690
|
+
const assets = await assetManager.getAssetsFromBuild(outputDir);
|
|
691
|
+
const { isExistingVersion } = await assetManager.updateVersionsManifest(buildId, assets);
|
|
692
|
+
logger.log(`Storing ${assets.length} assets in storage...`);
|
|
693
|
+
await assetManager.storeAssetsInStorage(buildId, outputDir, assets);
|
|
694
|
+
const existingVersions = await assetManager.listExistingVersions();
|
|
695
|
+
const versionCount = existingVersions.filter((v) => v.id !== buildId).length;
|
|
696
|
+
if (versionCount > 0) {
|
|
697
|
+
const manifest = await assetManager.getManifest();
|
|
698
|
+
let totalAssets = 0;
|
|
699
|
+
const versionSizes = [];
|
|
700
|
+
for (const [vId, vData] of Object.entries(manifest.versions)) {
|
|
701
|
+
if (vId !== buildId) {
|
|
702
|
+
totalAssets += vData.assets.length;
|
|
703
|
+
versionSizes.push(`${vId.slice(0, 8)}:${vData.assets.length}`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
logger.log(`Restoring build files from ${versionCount} release${versionCount > 1 ? "s" : ""} (${totalAssets} assets) [${versionSizes.join(", ")}]...`);
|
|
707
|
+
}
|
|
708
|
+
await assetManager.restoreOldAssetsToPublic(buildId, outputDir, assets, isExistingVersion);
|
|
709
|
+
await assetManager.augmentBuildMetadata(buildId, outputDir);
|
|
710
|
+
});
|
|
711
|
+
nitro.hooks.hook("close", async () => {
|
|
712
|
+
if (assetManager) {
|
|
713
|
+
await assetManager.cleanupExpiredVersions();
|
|
714
|
+
}
|
|
684
715
|
});
|
|
685
|
-
const assets = await assetManager.getAssetsFromBuild(outputDir);
|
|
686
|
-
const { isExistingVersion } = await assetManager.updateVersionsManifest(buildId, assets);
|
|
687
|
-
await assetManager.storeAssetsInStorage(buildId, outputDir, assets);
|
|
688
|
-
const existingVersions = await assetManager.listExistingVersions();
|
|
689
|
-
const versionCount = existingVersions.filter((v) => v.id !== buildId).length;
|
|
690
|
-
if (versionCount > 0) {
|
|
691
|
-
logger.log(`Restoring build files from the last ${versionCount} release${versionCount > 1 ? "s" : ""}...`);
|
|
692
|
-
}
|
|
693
|
-
await assetManager.restoreOldAssetsToPublic(buildId, outputDir, assets, isExistingVersion);
|
|
694
|
-
await assetManager.augmentBuildMetadata(buildId, outputDir);
|
|
695
|
-
await assetManager.cleanupExpiredVersions();
|
|
696
716
|
});
|
|
697
717
|
}
|
|
698
718
|
if (options.checkForUpdateStrategy === "ws") {
|
|
@@ -5,7 +5,8 @@ interface Props {
|
|
|
5
5
|
*/
|
|
6
6
|
forceOpen?: boolean;
|
|
7
7
|
}
|
|
8
|
-
declare var
|
|
8
|
+
declare var __VLS_7: {
|
|
9
|
+
version: any;
|
|
9
10
|
isCurrentChunksOutdated: any;
|
|
10
11
|
dismiss: any;
|
|
11
12
|
reload: any;
|
|
@@ -15,7 +16,7 @@ declare var __VLS_1: {
|
|
|
15
16
|
isAppOutdated: any;
|
|
16
17
|
};
|
|
17
18
|
type __VLS_Slots = {} & {
|
|
18
|
-
default?: (props: typeof
|
|
19
|
+
default?: (props: typeof __VLS_7) => any;
|
|
19
20
|
};
|
|
20
21
|
declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
21
22
|
dismiss: () => any;
|
|
@@ -3,11 +3,15 @@ import { useTimeAgo } from "@vueuse/core";
|
|
|
3
3
|
import { reloadNuxtApp } from "nuxt/app";
|
|
4
4
|
import { computed, ref } from "vue";
|
|
5
5
|
import { useSkewProtection } from "../composables/useSkewProtection";
|
|
6
|
+
defineOptions({
|
|
7
|
+
inheritAttrs: false
|
|
8
|
+
});
|
|
6
9
|
const props = defineProps({
|
|
7
10
|
forceOpen: { type: Boolean, required: false }
|
|
8
11
|
});
|
|
9
12
|
const emit = defineEmits(["dismiss", "reload", "update:open", "chunksOutdated"]);
|
|
10
13
|
const skewProtection = useSkewProtection();
|
|
14
|
+
const version = skewProtection.clientVersion;
|
|
11
15
|
const chunksOutdated = ref(false);
|
|
12
16
|
const appOutdated = ref(false);
|
|
13
17
|
const outdatedPayload = ref(null);
|
|
@@ -54,18 +58,19 @@ async function handleReload() {
|
|
|
54
58
|
persistState: true
|
|
55
59
|
});
|
|
56
60
|
}
|
|
57
|
-
const shouldRender = import.meta.client && !import.meta.prerender;
|
|
58
61
|
</script>
|
|
59
62
|
|
|
60
63
|
<template>
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
<ClientOnly>
|
|
65
|
+
<slot
|
|
66
|
+
:version="version"
|
|
67
|
+
:is-current-chunks-outdated="isCurrentChunksOutdated"
|
|
68
|
+
:dismiss="handleDismiss"
|
|
69
|
+
:reload="handleReload"
|
|
70
|
+
:time-ago="timeAgo"
|
|
71
|
+
:release-date="releaseDate"
|
|
72
|
+
:payload="outdatedPayload"
|
|
73
|
+
:is-app-outdated="isAppOutdated"
|
|
74
|
+
/>
|
|
75
|
+
</ClientOnly>
|
|
71
76
|
</template>
|
|
@@ -5,7 +5,8 @@ interface Props {
|
|
|
5
5
|
*/
|
|
6
6
|
forceOpen?: boolean;
|
|
7
7
|
}
|
|
8
|
-
declare var
|
|
8
|
+
declare var __VLS_7: {
|
|
9
|
+
version: any;
|
|
9
10
|
isCurrentChunksOutdated: any;
|
|
10
11
|
dismiss: any;
|
|
11
12
|
reload: any;
|
|
@@ -15,7 +16,7 @@ declare var __VLS_1: {
|
|
|
15
16
|
isAppOutdated: any;
|
|
16
17
|
};
|
|
17
18
|
type __VLS_Slots = {} & {
|
|
18
|
-
default?: (props: typeof
|
|
19
|
+
default?: (props: typeof __VLS_7) => any;
|
|
19
20
|
};
|
|
20
21
|
declare const __VLS_base: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
21
22
|
dismiss: () => any;
|
|
@@ -3,7 +3,7 @@ import type { ChunksOutdatedPayload } from '../../types.js';
|
|
|
3
3
|
export declare function checkForUpdates(): Promise<void>;
|
|
4
4
|
export declare function useSkewProtection(): {
|
|
5
5
|
manifest: import("vue").Ref<NuxtAppManifestMeta | undefined, NuxtAppManifestMeta | undefined>;
|
|
6
|
-
clientVersion:
|
|
6
|
+
clientVersion: string;
|
|
7
7
|
isOutdated: import("vue").ComputedRef<boolean | undefined>;
|
|
8
8
|
onCurrentChunksOutdated: (callback: (payload: ChunksOutdatedPayload) => void | Promise<void>) => () => void;
|
|
9
9
|
onAppOutdated: (callback: (manifest?: NuxtAppManifestMeta) => void | Promise<void>) => () => void;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { buildAssetsURL } from "#internal/nuxt/paths";
|
|
2
|
-
import {
|
|
2
|
+
import { useCookie, useNuxtApp } from "nuxt/app";
|
|
3
3
|
import { computed, onUnmounted, ref } from "vue";
|
|
4
|
+
import { useRuntimeConfigSkewProtection } from "./useRuntimeConfigSkewProtection.js";
|
|
4
5
|
export async function checkForUpdates() {
|
|
5
6
|
const nuxtApp = useNuxtApp();
|
|
6
|
-
const runtimeConfig =
|
|
7
|
-
const
|
|
7
|
+
const runtimeConfig = useRuntimeConfigSkewProtection();
|
|
8
|
+
const cookie = useCookie(runtimeConfig.cookie.name);
|
|
9
|
+
const clientVersion = import.meta.client ? cookie.value : runtimeConfig.buildId;
|
|
8
10
|
const meta = await $fetch(`${buildAssetsURL("builds/latest.json")}?${Date.now()}`).catch(() => {
|
|
9
11
|
return null;
|
|
10
12
|
});
|
|
@@ -14,8 +16,13 @@ export async function checkForUpdates() {
|
|
|
14
16
|
}
|
|
15
17
|
export function useSkewProtection() {
|
|
16
18
|
const nuxtApp = useNuxtApp();
|
|
17
|
-
const runtimeConfig =
|
|
18
|
-
const
|
|
19
|
+
const runtimeConfig = useRuntimeConfigSkewProtection();
|
|
20
|
+
const cookie = useCookie(runtimeConfig.cookie.name, {
|
|
21
|
+
default() {
|
|
22
|
+
return runtimeConfig.buildId;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const clientVersion = import.meta.client ? cookie.value : runtimeConfig.buildId;
|
|
19
26
|
const manifest = ref();
|
|
20
27
|
function onCurrentChunksOutdated(callback) {
|
|
21
28
|
const hook = nuxtApp.hooks.hook("skew-protection:chunks-outdated", callback);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
2
1
|
import { useEventSource } from "@vueuse/core";
|
|
2
|
+
import { defineNuxtPlugin } from "nuxt/app";
|
|
3
3
|
import { watch } from "vue";
|
|
4
4
|
import { logger } from "../../shared/logger.js";
|
|
5
|
-
import { checkForUpdates } from "../composables/useSkewProtection.js";
|
|
5
|
+
import { checkForUpdates, useSkewProtection } from "../composables/useSkewProtection.js";
|
|
6
6
|
export default defineNuxtPlugin({
|
|
7
7
|
name: "skew-protection:sse-updates",
|
|
8
8
|
setup(nuxtApp) {
|
|
9
|
-
const
|
|
10
|
-
const clientVersion = runtimeConfig.app.buildId;
|
|
9
|
+
const { clientVersion } = useSkewProtection();
|
|
11
10
|
const { data } = useEventSource(`/_skew/sse`, [], {
|
|
12
11
|
autoReconnect: {
|
|
13
12
|
retries: 10,
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
2
1
|
import { useWebSocket } from "@vueuse/core";
|
|
2
|
+
import { defineNuxtPlugin } from "nuxt/app";
|
|
3
3
|
import { watch } from "vue";
|
|
4
4
|
import { logger } from "../../shared/logger.js";
|
|
5
|
-
import {
|
|
6
|
-
import { checkForUpdates } from "../composables/useSkewProtection.js";
|
|
5
|
+
import { checkForUpdates, useSkewProtection } from "../composables/useSkewProtection.js";
|
|
7
6
|
export default defineNuxtPlugin({
|
|
8
7
|
name: "skew-protection:websocket-updates",
|
|
9
8
|
setup(nuxtApp) {
|
|
10
|
-
const
|
|
11
|
-
const runtimeConfig = useRuntimeConfig();
|
|
12
|
-
const clientVersion = runtimeConfig.app.buildId;
|
|
9
|
+
const { clientVersion } = useSkewProtection();
|
|
13
10
|
const protocol = typeof window !== "undefined" && window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
14
11
|
const url = typeof window !== "undefined" ? `${protocol}//${window.location.host}/_skew/ws` : "";
|
|
15
12
|
const {
|
|
@@ -41,21 +38,10 @@ export default defineNuxtPlugin({
|
|
|
41
38
|
return;
|
|
42
39
|
try {
|
|
43
40
|
const parsed = JSON.parse(message);
|
|
44
|
-
if (parsed.
|
|
41
|
+
if (parsed.version) {
|
|
45
42
|
const newVersion = parsed.version;
|
|
46
43
|
if (newVersion !== clientVersion) {
|
|
47
44
|
nuxtApp.runWithContext(checkForUpdates);
|
|
48
|
-
if (skewConfig.debug) {
|
|
49
|
-
logger.info(`Version update received via WebSocket: ${newVersion}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
} else if (parsed.type === "connected") {
|
|
53
|
-
if (skewConfig.debug) {
|
|
54
|
-
logger.info("WebSocket connection acknowledged");
|
|
55
|
-
}
|
|
56
|
-
} else if (parsed.type === "pong") {
|
|
57
|
-
if (skewConfig.debug) {
|
|
58
|
-
logger.debug("Received pong from WebSocket");
|
|
59
45
|
}
|
|
60
46
|
}
|
|
61
47
|
} catch (error) {
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
declare const _default: import("#app").Plugin<
|
|
2
|
-
skewServiceWorker: {
|
|
3
|
-
getLoadedModules: () => Promise<string[]>;
|
|
4
|
-
};
|
|
5
|
-
}> & import("#app").ObjectPlugin<{
|
|
6
|
-
skewServiceWorker: {
|
|
7
|
-
getLoadedModules: () => Promise<string[]>;
|
|
8
|
-
};
|
|
9
|
-
}>;
|
|
1
|
+
declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
|
|
10
2
|
export default _default;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { defineNuxtPlugin
|
|
1
|
+
import { defineNuxtPlugin } from "nuxt/app";
|
|
2
|
+
import { useSkewProtection } from "../composables/useSkewProtection.js";
|
|
2
3
|
function normalizePath(pathOrUrl) {
|
|
3
4
|
try {
|
|
4
5
|
const url = new URL(pathOrUrl);
|
|
@@ -13,10 +14,23 @@ export default defineNuxtPlugin({
|
|
|
13
14
|
if (!("serviceWorker" in navigator)) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const { clientVersion, onAppOutdated } = useSkewProtection();
|
|
18
|
+
const swRegistration = navigator.serviceWorker.register("/_nuxt-skew-sw.js");
|
|
19
|
+
swRegistration.then((registration) => {
|
|
20
|
+
const sw = registration.active || registration.installing || registration.waiting;
|
|
21
|
+
if (!sw)
|
|
22
|
+
return;
|
|
23
|
+
const alreadyLoadedModules = performance.getEntriesByType("resource").filter((r) => r.name.includes("/_nuxt/") && r.name.endsWith(".js")).map((r) => r.name);
|
|
24
|
+
alreadyLoadedModules.forEach((url) => {
|
|
25
|
+
sw.postMessage({ type: "ADD_MODULE", url });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
async function getLoadedModules() {
|
|
29
|
+
const registration = await swRegistration;
|
|
30
|
+
const sw = registration.active;
|
|
31
|
+
if (!sw) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
20
34
|
return new Promise((resolve) => {
|
|
21
35
|
let timeoutId;
|
|
22
36
|
const messageHandler = (event) => {
|
|
@@ -27,7 +41,7 @@ export default defineNuxtPlugin({
|
|
|
27
41
|
}
|
|
28
42
|
};
|
|
29
43
|
navigator.serviceWorker.addEventListener("message", messageHandler);
|
|
30
|
-
|
|
44
|
+
sw.postMessage({ type: "GET_MODULES" });
|
|
31
45
|
timeoutId = setTimeout(() => {
|
|
32
46
|
navigator.serviceWorker.removeEventListener("message", messageHandler);
|
|
33
47
|
resolve([]);
|
|
@@ -55,44 +69,53 @@ export default defineNuxtPlugin({
|
|
|
55
69
|
});
|
|
56
70
|
}
|
|
57
71
|
}
|
|
58
|
-
|
|
72
|
+
onAppOutdated(async (_manifest) => {
|
|
59
73
|
const versions = _manifest?.skewProtection?.versions;
|
|
60
74
|
if (!versions) {
|
|
61
75
|
return;
|
|
62
76
|
}
|
|
63
77
|
const newVersionId = _manifest.id;
|
|
64
|
-
if (!clientVersion || clientVersion === newVersionId) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
navigator.serviceWorker.controller?.postMessage({ type: "RESET_MODULES" });
|
|
68
78
|
const sortedVersions = Object.entries(versions).map(([id, data]) => ({ id, timestamp: new Date(data.timestamp).getTime() })).sort((a, b) => a.timestamp - b.timestamp);
|
|
69
79
|
const currentIdx = sortedVersions.findIndex((v) => v.id === clientVersion);
|
|
70
80
|
const newIdx = sortedVersions.findIndex((v) => v.id === newVersionId);
|
|
71
|
-
if (currentIdx === -1 || newIdx === -1) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
81
|
const allDeletedChunks = [];
|
|
75
82
|
const passedReleases = [];
|
|
76
|
-
|
|
77
|
-
const version
|
|
78
|
-
if (version) {
|
|
83
|
+
if (currentIdx === -1) {
|
|
84
|
+
for (const version of sortedVersions) {
|
|
79
85
|
passedReleases.push(version.id);
|
|
80
86
|
const versionData = versions[version.id];
|
|
81
87
|
if (versionData?.deletedChunks) {
|
|
82
88
|
allDeletedChunks.push(...versionData.deletedChunks);
|
|
83
89
|
}
|
|
84
90
|
}
|
|
91
|
+
} else if (newIdx === -1) {
|
|
92
|
+
for (let i = currentIdx + 1; i < sortedVersions.length; i++) {
|
|
93
|
+
const version = sortedVersions[i];
|
|
94
|
+
if (version) {
|
|
95
|
+
passedReleases.push(version.id);
|
|
96
|
+
const versionData = versions[version.id];
|
|
97
|
+
if (versionData?.deletedChunks) {
|
|
98
|
+
allDeletedChunks.push(...versionData.deletedChunks);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
for (let i = currentIdx + 1; i <= newIdx; i++) {
|
|
104
|
+
const version = sortedVersions[i];
|
|
105
|
+
if (version) {
|
|
106
|
+
passedReleases.push(version.id);
|
|
107
|
+
const versionData = versions[version.id];
|
|
108
|
+
if (versionData?.deletedChunks) {
|
|
109
|
+
allDeletedChunks.push(...versionData.deletedChunks);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
85
113
|
}
|
|
86
114
|
if (allDeletedChunks.length > 0) {
|
|
115
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
87
116
|
await checkDeletedChunks(allDeletedChunks, passedReleases);
|
|
88
117
|
}
|
|
118
|
+
swRegistration.then((reg) => reg.active?.postMessage({ type: "RESET_MODULES" }));
|
|
89
119
|
});
|
|
90
|
-
return {
|
|
91
|
-
provide: {
|
|
92
|
-
skewServiceWorker: {
|
|
93
|
-
getLoadedModules
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
120
|
}
|
|
98
121
|
});
|
|
@@ -3,15 +3,15 @@ import { useRuntimeConfig } from "nitropack/runtime";
|
|
|
3
3
|
export default defineWebSocketHandler({
|
|
4
4
|
open(peer) {
|
|
5
5
|
const runtimeConfig = useRuntimeConfig();
|
|
6
|
-
peer.send({
|
|
6
|
+
peer.send(JSON.stringify({
|
|
7
7
|
type: "connected",
|
|
8
8
|
version: runtimeConfig.app?.buildId,
|
|
9
9
|
timestamp: Date.now()
|
|
10
|
-
});
|
|
10
|
+
}));
|
|
11
11
|
},
|
|
12
12
|
message(peer, message) {
|
|
13
13
|
if (message.text().includes("ping")) {
|
|
14
|
-
peer.send("pong");
|
|
14
|
+
peer.send(JSON.stringify({ type: "pong" }));
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
});
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const loadedModules=new Set;self.addEventListener("activate",e=>{e.waitUntil(self.clients.claim())}),self.addEventListener("fetch",e=>{const t=e.request.url;(e.request.destination==="script"||t.endsWith(".js"))&&(loadedModules.add(t),e.waitUntil(self.clients.matchAll().then(a=>{a.forEach(s=>{s.postMessage({type:"MODULE_LOADED",url:t,modules:Array.from(loadedModules)})})})))}),self.addEventListener("message",e=>{if(e.data.type==="GET_MODULES"){const t=Array.from(loadedModules);e.source.postMessage({type:"MODULES_LIST",modules:t})}if(e.data.type==="CHECK_MODULE"){const t=loadedModules.has(e.data.url);e.source.postMessage({type:"MODULE_STATUS",url:e.data.url,loaded:t})}e.data.type==="RESET_MODULES"&&(loadedModules.clear(),e.source.postMessage({type:"MODULES_RESET",success:!0})),e.data.type==="ADD_MODULE"&&loadedModules.add(e.data.url)});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-skew-protection",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
5
5
|
"description": "Instantly adopted Nuxt releases with long-lived build assets.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"lint": "eslint . --fix",
|
|
89
|
-
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build",
|
|
89
|
+
"build": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && unbuild --config sw.build.config.ts",
|
|
90
90
|
"dev": "nuxi dev playground",
|
|
91
91
|
"dev:build": "nuxi build playground",
|
|
92
92
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && nuxi prepare playground",
|