nuxt-skew-protection 0.7.1 → 0.7.3
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 +65 -3
- package/dist/runtime/app/plugins/check-updates-adapter.client.js +2 -0
- package/dist/runtime/app/plugins/check-updates-sse.client.js +2 -0
- package/dist/runtime/app/plugins/check-updates-websocket.client.js +2 -0
- package/dist/runtime/app/plugins/sw-track-user-modules.client.js +2 -0
- package/package.json +11 -11
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { join } from 'node:path';
|
|
|
10
10
|
import { tmpdir } from 'node:os';
|
|
11
11
|
import { x } from 'tinyexec';
|
|
12
12
|
import { defineDriver, createStorage } from 'unstorage';
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
13
14
|
import { join as join$1, dirname } from 'pathe';
|
|
14
15
|
|
|
15
16
|
const logger = useLogger("nuxt-skew-protection");
|
|
@@ -666,9 +667,10 @@ function createAssetManager(options) {
|
|
|
666
667
|
}
|
|
667
668
|
logger.debug(`restoreOldAssetsToPublic: total ${formatDuration(Date.now() - startTime)}`);
|
|
668
669
|
}
|
|
669
|
-
async function augmentBuildMetadata(buildId, publicDir) {
|
|
670
|
+
async function augmentBuildMetadata(buildId, publicDir, serverDir) {
|
|
670
671
|
const manifest = await getVersionManifest(storage);
|
|
671
672
|
const latestPath = join$1(publicDir, "_nuxt", "builds", "latest.json");
|
|
673
|
+
let newLatestContent;
|
|
672
674
|
try {
|
|
673
675
|
const latestData = await promises.readFile(latestPath, "utf-8");
|
|
674
676
|
const latestJson = JSON.parse(latestData);
|
|
@@ -682,7 +684,8 @@ function createAssetManager(options) {
|
|
|
682
684
|
latestJson.skewProtection = {
|
|
683
685
|
versions: clientVersions
|
|
684
686
|
};
|
|
685
|
-
|
|
687
|
+
newLatestContent = JSON.stringify(latestJson, null, 2);
|
|
688
|
+
await promises.writeFile(latestPath, newLatestContent, "utf-8");
|
|
686
689
|
} catch (error) {
|
|
687
690
|
if (options.debug) {
|
|
688
691
|
logger.warn("Failed to augment builds/latest.json:", error);
|
|
@@ -705,6 +708,64 @@ function createAssetManager(options) {
|
|
|
705
708
|
logger.warn(`Failed to augment builds/meta/${buildId}.json:`, error);
|
|
706
709
|
}
|
|
707
710
|
}
|
|
711
|
+
if (serverDir && newLatestContent) {
|
|
712
|
+
await patchNitroManifest(serverDir, "/_nuxt/builds/latest.json", newLatestContent);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
async function patchNitroManifest(serverDir, assetPath, newContent) {
|
|
716
|
+
const nitroPath = join$1(serverDir, "chunks", "nitro", "nitro.mjs");
|
|
717
|
+
let nitro = await promises.readFile(nitroPath, "utf-8").catch(() => null);
|
|
718
|
+
if (!nitro)
|
|
719
|
+
return;
|
|
720
|
+
const assetIdx = nitro.indexOf(`"${assetPath}":`);
|
|
721
|
+
if (assetIdx === -1)
|
|
722
|
+
return;
|
|
723
|
+
const size = Buffer.byteLength(newContent, "utf-8");
|
|
724
|
+
const hash = createHash("sha1").update(newContent).digest("base64").substring(0, 27);
|
|
725
|
+
const newEtag = `"${size.toString(16)}-${hash}"`;
|
|
726
|
+
const start = nitro.indexOf("{", assetIdx);
|
|
727
|
+
if (start === -1)
|
|
728
|
+
return;
|
|
729
|
+
let depth = 0;
|
|
730
|
+
let stringChar = null;
|
|
731
|
+
let end = -1;
|
|
732
|
+
for (let i = start; i < nitro.length; i++) {
|
|
733
|
+
const char = nitro[i];
|
|
734
|
+
if (stringChar) {
|
|
735
|
+
if (char === "\\")
|
|
736
|
+
i++;
|
|
737
|
+
else if (char === stringChar)
|
|
738
|
+
stringChar = null;
|
|
739
|
+
} else {
|
|
740
|
+
if (char === '"' || char === "'") {
|
|
741
|
+
stringChar = char;
|
|
742
|
+
} else if (char === "{") {
|
|
743
|
+
depth++;
|
|
744
|
+
} else if (char === "}") {
|
|
745
|
+
depth--;
|
|
746
|
+
if (depth === 0) {
|
|
747
|
+
end = i;
|
|
748
|
+
break;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (end === -1)
|
|
754
|
+
return;
|
|
755
|
+
let entryStr = nitro.substring(start, end + 1);
|
|
756
|
+
entryStr = entryStr.replace(/(['"]?)size\1\s*:\s*\d+/, (match) => {
|
|
757
|
+
const prefix = match.match(/^(['"]?)size\1\s*:\s*/)?.[0] || "size:";
|
|
758
|
+
return `${prefix}${size}`;
|
|
759
|
+
});
|
|
760
|
+
entryStr = entryStr.replace(/(['"]?)etag\1\s*:\s*(['"])(?:[^\\]|\\.)*?\2/, (match) => {
|
|
761
|
+
const keyMatch = match.match(/^(['"]?)etag\1\s*:\s*/);
|
|
762
|
+
const prefix = keyMatch?.[0] || "etag:";
|
|
763
|
+
const quoteChar = match.match(/:\s*(['"])/)?.[1] || '"';
|
|
764
|
+
const escapedEtag = quoteChar === "'" ? newEtag : newEtag.replace(/"/g, '\\"');
|
|
765
|
+
return `${prefix}${quoteChar}${escapedEtag}${quoteChar}`;
|
|
766
|
+
});
|
|
767
|
+
nitro = nitro.substring(0, start) + entryStr + nitro.substring(end + 1);
|
|
768
|
+
await promises.writeFile(nitroPath, nitro, "utf-8");
|
|
708
769
|
}
|
|
709
770
|
return {
|
|
710
771
|
getAssetsFromBuild,
|
|
@@ -1002,7 +1063,8 @@ export {}
|
|
|
1002
1063
|
logger.log(`Restoring build files from ${versionCount} release${versionCount > 1 ? "s" : ""} (${totalAssets} assets) [${versionSizes.join(", ")}]...`);
|
|
1003
1064
|
}
|
|
1004
1065
|
await assetManager.restoreOldAssetsToPublic(buildId, publicDir, assets, isExistingVersion);
|
|
1005
|
-
|
|
1066
|
+
const serverDir = nitro.options.output.serverDir;
|
|
1067
|
+
await assetManager.augmentBuildMetadata(buildId, publicDir, serverDir);
|
|
1006
1068
|
});
|
|
1007
1069
|
nitro.hooks.hook("close", async () => {
|
|
1008
1070
|
if (assetManager) {
|
|
@@ -5,6 +5,8 @@ import { createSkewConnection } from "../utils/create-skew-connection.js";
|
|
|
5
5
|
export default defineNuxtPlugin({
|
|
6
6
|
name: "skew-protection:adapter-updates",
|
|
7
7
|
async setup() {
|
|
8
|
+
if (import.meta.prerender)
|
|
9
|
+
return {};
|
|
8
10
|
const nuxtApp = useNuxtApp();
|
|
9
11
|
const adapterName = useRuntimeConfig().public.skewProtection.adapterName;
|
|
10
12
|
const config = {
|
|
@@ -5,6 +5,8 @@ import { createSkewConnection } from "../utils/create-skew-connection.js";
|
|
|
5
5
|
export default defineNuxtPlugin({
|
|
6
6
|
name: "skew-protection:sse-updates",
|
|
7
7
|
async setup() {
|
|
8
|
+
if (import.meta.prerender)
|
|
9
|
+
return {};
|
|
8
10
|
const nuxtApp = useNuxtApp();
|
|
9
11
|
const router = useRouter();
|
|
10
12
|
const runtimeConfig = useRuntimeConfig();
|
|
@@ -6,6 +6,8 @@ import { createSkewConnection } from "../utils/create-skew-connection.js";
|
|
|
6
6
|
export default defineNuxtPlugin({
|
|
7
7
|
name: "skew-protection:ws-updates",
|
|
8
8
|
async setup() {
|
|
9
|
+
if (import.meta.prerender)
|
|
10
|
+
return {};
|
|
9
11
|
const nuxtApp = useNuxtApp();
|
|
10
12
|
const router = useRouter();
|
|
11
13
|
const runtimeConfig = useRuntimeConfig();
|
|
@@ -12,6 +12,8 @@ function normalizePath(pathOrUrl) {
|
|
|
12
12
|
export default defineNuxtPlugin({
|
|
13
13
|
name: "skew-protection:service-worker",
|
|
14
14
|
setup(nuxtApp) {
|
|
15
|
+
if (import.meta.prerender)
|
|
16
|
+
return;
|
|
15
17
|
if (!("serviceWorker" in navigator)) {
|
|
16
18
|
logger.debug("[SW] Service Worker not supported in this browser");
|
|
17
19
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-skew-protection",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.3",
|
|
5
5
|
"description": "Solve Nuxt version skews with persistent assets and instant updates.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -55,13 +55,13 @@
|
|
|
55
55
|
"consola": "^3.4.2",
|
|
56
56
|
"cookie-es": "^2.0.0",
|
|
57
57
|
"defu": "^6.1.4",
|
|
58
|
-
"nuxt-site-config": "^3.2.
|
|
58
|
+
"nuxt-site-config": "^3.2.17",
|
|
59
59
|
"ofetch": "^1.5.1",
|
|
60
60
|
"pathe": "^2.0.3",
|
|
61
61
|
"pkg-types": "^2.3.0",
|
|
62
62
|
"std-env": "^3.10.0",
|
|
63
63
|
"tinyexec": "^1.0.2",
|
|
64
|
-
"ufo": "^1.6.
|
|
64
|
+
"ufo": "^1.6.2",
|
|
65
65
|
"unstorage": "^1.17.3",
|
|
66
66
|
"zod": "^4.3.5"
|
|
67
67
|
},
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@nuxt/content": "^3.10.0",
|
|
72
72
|
"@nuxt/devtools-ui-kit": "^3.1.1",
|
|
73
73
|
"@nuxt/module-builder": "^1.0.2",
|
|
74
|
-
"@nuxt/test-utils": "^3.
|
|
74
|
+
"@nuxt/test-utils": "^3.23.0",
|
|
75
75
|
"@nuxt/ui": "^4.3.0",
|
|
76
76
|
"@nuxtjs/color-mode": "^4.0.0",
|
|
77
77
|
"@nuxtjs/eslint-config-typescript": "^12.1.0",
|
|
@@ -84,15 +84,15 @@
|
|
|
84
84
|
"@unocss/preset-uno": "66.5.12",
|
|
85
85
|
"@unocss/runtime": "66.5.12",
|
|
86
86
|
"@vueuse/nuxt": "^14.1.0",
|
|
87
|
-
"ably": "^2.
|
|
88
|
-
"better-sqlite3": "^12.
|
|
87
|
+
"ably": "^2.17.0",
|
|
88
|
+
"better-sqlite3": "^12.6.0",
|
|
89
89
|
"bumpp": "^10.3.2",
|
|
90
90
|
"eslint": "^9.39.2",
|
|
91
91
|
"eventsource": "^4.1.0",
|
|
92
92
|
"execa": "^9.6.1",
|
|
93
|
-
"firebase-functions": "^7.0.
|
|
94
|
-
"happy-dom": "^20.0
|
|
95
|
-
"ioredis": "^5.9.
|
|
93
|
+
"firebase-functions": "^7.0.3",
|
|
94
|
+
"happy-dom": "^20.1.0",
|
|
95
|
+
"ioredis": "^5.9.1",
|
|
96
96
|
"nuxt": "^4.2.2",
|
|
97
97
|
"nuxt-auth-utils": "^0.5.26",
|
|
98
98
|
"playwright-core": "^1.57.0",
|
|
@@ -100,11 +100,11 @@
|
|
|
100
100
|
"tsx": "^4.21.0",
|
|
101
101
|
"typescript": "^5.9.3",
|
|
102
102
|
"unocss": "66.5.12",
|
|
103
|
-
"vitest": "^4.0.
|
|
103
|
+
"vitest": "^4.0.17",
|
|
104
104
|
"vue": "^3.5.26",
|
|
105
105
|
"vue-router": "^4.6.4",
|
|
106
106
|
"vue-tsc": "^3.2.2",
|
|
107
|
-
"wrangler": "^4.
|
|
107
|
+
"wrangler": "^4.58.0",
|
|
108
108
|
"ws": "^8.19.0"
|
|
109
109
|
},
|
|
110
110
|
"resolutions": {
|