@vizejs/nuxt 0.70.0 → 0.71.0
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/index.mjs +61 -6
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { addServerPlugin, addVitePlugin, createResolver, defineNuxtModule } from
|
|
|
4
4
|
import vize from "@vizejs/vite-plugin";
|
|
5
5
|
import { musea } from "@vizejs/vite-plugin-musea";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
7
8
|
//#region src/components.ts
|
|
8
9
|
const COMPONENT_CALL_RE = /_?resolveComponent\s*\(\s*["'`]([^"'`]+)["'`]\s*(?:,\s*[^)]+)?\)/g;
|
|
9
10
|
const COMPONENT_EXT_RE = /\.(?:[cm]?js|ts|vue)$/;
|
|
@@ -226,11 +227,18 @@ function getLocalAlias(specifier) {
|
|
|
226
227
|
}
|
|
227
228
|
function collectUsedI18nSpecifiers(code) {
|
|
228
229
|
const used = /* @__PURE__ */ new Set();
|
|
230
|
+
let firstUseIndex = Number.POSITIVE_INFINITY;
|
|
229
231
|
for (const match of code.matchAll(I18N_FN_RE)) {
|
|
230
232
|
const specifier = I18N_FN_MAP[`$${match[1]}`];
|
|
231
|
-
if (specifier)
|
|
233
|
+
if (specifier) {
|
|
234
|
+
used.add(specifier);
|
|
235
|
+
firstUseIndex = Math.min(firstUseIndex, match.index ?? firstUseIndex);
|
|
236
|
+
}
|
|
232
237
|
}
|
|
233
|
-
return
|
|
238
|
+
return {
|
|
239
|
+
firstUseIndex,
|
|
240
|
+
specifiers: Array.from(used)
|
|
241
|
+
};
|
|
234
242
|
}
|
|
235
243
|
function collectDestructuredLocalNames(destructure) {
|
|
236
244
|
const locals = /* @__PURE__ */ new Set();
|
|
@@ -245,18 +253,20 @@ function collectDestructuredLocalNames(destructure) {
|
|
|
245
253
|
return locals;
|
|
246
254
|
}
|
|
247
255
|
function injectNuxtI18nHelpers(code) {
|
|
248
|
-
const usedSpecifiers = collectUsedI18nSpecifiers(code);
|
|
249
|
-
if (usedSpecifiers.length === 0) return code;
|
|
250
256
|
const setupMatch = code.match(SETUP_FN_RE);
|
|
251
257
|
if (!setupMatch || setupMatch.index === void 0) return code;
|
|
252
258
|
const setupBodyStart = setupMatch.index + setupMatch[0].length;
|
|
253
|
-
const
|
|
259
|
+
const setupBody = code.slice(setupBodyStart);
|
|
260
|
+
const { firstUseIndex, specifiers: usedSpecifiers } = collectUsedI18nSpecifiers(setupBody);
|
|
261
|
+
if (usedSpecifiers.length === 0) return code;
|
|
262
|
+
const existingMatch = setupBody.match(USE_I18N_DESTRUCTURE_RE);
|
|
254
263
|
if (existingMatch && existingMatch.index !== void 0) {
|
|
255
264
|
const existingLocals = collectDestructuredLocalNames(existingMatch[1]);
|
|
256
265
|
const missingSpecifiers = usedSpecifiers.filter((specifier) => {
|
|
257
266
|
return !existingLocals.has(getLocalAlias(specifier));
|
|
258
267
|
});
|
|
259
268
|
if (missingSpecifiers.length === 0) return code;
|
|
269
|
+
if (existingMatch.index > firstUseIndex) return code.slice(0, setupBodyStart) + `\nconst { ${missingSpecifiers.join(", ")} } = useI18n();\n` + code.slice(setupBodyStart);
|
|
260
270
|
const merged = existingMatch[1].trim();
|
|
261
271
|
const nextDestructure = merged ? `${merged}, ${missingSpecifiers.join(", ")}` : missingSpecifiers.join(", ");
|
|
262
272
|
const matchStart = setupBodyStart + existingMatch.index;
|
|
@@ -288,6 +298,19 @@ function isVizeVirtualVueModuleId(id) {
|
|
|
288
298
|
function normalizeVizeVirtualVueModuleId(id) {
|
|
289
299
|
return (id.startsWith("\0vize-ssr:") ? id.slice(10) : id.slice(1)).replace(/\.ts(?=\?|$)/, "");
|
|
290
300
|
}
|
|
301
|
+
const NUXT_INJECTED_MARKER = "/* nuxt-injected */";
|
|
302
|
+
const NUXT_INJECTED_KEY_RE = /'\$[^']+'\s+\/\* nuxt-injected \*\//g;
|
|
303
|
+
function buildStableNuxtKey(id, index) {
|
|
304
|
+
return createHash("sha256").update(id).update(":").update(String(index)).digest("base64url").slice(0, 10);
|
|
305
|
+
}
|
|
306
|
+
function normalizeNuxtInjectedKeysForVizeVirtualModule(code, id) {
|
|
307
|
+
const normalizedId = normalizeVizeVirtualVueModuleId(id);
|
|
308
|
+
let index = 0;
|
|
309
|
+
return code.replace(NUXT_INJECTED_KEY_RE, () => {
|
|
310
|
+
index += 1;
|
|
311
|
+
return `'$${buildStableNuxtKey(normalizedId, index)}' ${NUXT_INJECTED_MARKER}`;
|
|
312
|
+
});
|
|
313
|
+
}
|
|
291
314
|
//#endregion
|
|
292
315
|
//#region src/index.ts
|
|
293
316
|
/**
|
|
@@ -299,6 +322,31 @@ function normalizeVizeVirtualVueModuleId(id) {
|
|
|
299
322
|
* - Linter: `vize lint` CLI command (via `vize` bin)
|
|
300
323
|
* - Type Checker: `vize check` CLI command (via `vize` bin)
|
|
301
324
|
*/
|
|
325
|
+
function normalizeNuxtKeyedTransformResult(id, result) {
|
|
326
|
+
if (!isVizeVirtualVueModuleId(id) || result == null) return result;
|
|
327
|
+
if (typeof result === "string") return normalizeNuxtInjectedKeysForVizeVirtualModule(result, id);
|
|
328
|
+
if (typeof result.code !== "string") return result;
|
|
329
|
+
const code = normalizeNuxtInjectedKeysForVizeVirtualModule(result.code, id);
|
|
330
|
+
return code === result.code ? result : {
|
|
331
|
+
...result,
|
|
332
|
+
code
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function patchNuxtKeyedFunctionsPlugin(plugin) {
|
|
336
|
+
if (typeof plugin.transform === "function") {
|
|
337
|
+
const original = plugin.transform;
|
|
338
|
+
plugin.transform = async function(code, id, ...args) {
|
|
339
|
+
return normalizeNuxtKeyedTransformResult(id, await original.call(this, code, id, ...args));
|
|
340
|
+
};
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const transform = plugin.transform;
|
|
344
|
+
if (!transform || typeof transform.handler !== "function") return;
|
|
345
|
+
const original = transform.handler;
|
|
346
|
+
transform.handler = async function(code, id, ...args) {
|
|
347
|
+
return normalizeNuxtKeyedTransformResult(id, await original.call(this, code, id, ...args));
|
|
348
|
+
};
|
|
349
|
+
}
|
|
302
350
|
var src_default = defineNuxtModule({
|
|
303
351
|
meta: {
|
|
304
352
|
name: "@vizejs/nuxt",
|
|
@@ -325,7 +373,9 @@ var src_default = defineNuxtModule({
|
|
|
325
373
|
nuxt.hook("vite:configResolved", (config) => {
|
|
326
374
|
for (let i = config.plugins.length - 1; i >= 0; i--) {
|
|
327
375
|
const p = config.plugins[i];
|
|
328
|
-
|
|
376
|
+
const name = p && typeof p === "object" && "name" in p ? p.name : "";
|
|
377
|
+
if (name === "vite:vue") config.plugins.splice(i, 1);
|
|
378
|
+
else if (name === "nuxt:compiler:keyed-functions") patchNuxtKeyedFunctionsPlugin(p);
|
|
329
379
|
}
|
|
330
380
|
});
|
|
331
381
|
}
|
|
@@ -367,6 +417,11 @@ var src_default = defineNuxtModule({
|
|
|
367
417
|
changed = true;
|
|
368
418
|
}
|
|
369
419
|
} catch {}
|
|
420
|
+
const stableKeyResult = normalizeNuxtInjectedKeysForVizeVirtualModule(result, id);
|
|
421
|
+
if (stableKeyResult !== result) {
|
|
422
|
+
result = stableKeyResult;
|
|
423
|
+
changed = true;
|
|
424
|
+
}
|
|
370
425
|
if (changed) return {
|
|
371
426
|
code: result,
|
|
372
427
|
map: null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.0",
|
|
4
4
|
"description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -37,10 +37,10 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@nuxt/kit": "4.4.2",
|
|
40
|
-
"@vizejs/musea-nuxt": "0.
|
|
41
|
-
"@vizejs/vite-plugin": "0.
|
|
42
|
-
"@vizejs/vite-plugin-musea": "0.
|
|
43
|
-
"vize": "0.
|
|
40
|
+
"@vizejs/musea-nuxt": "0.71.0",
|
|
41
|
+
"@vizejs/vite-plugin": "0.71.0",
|
|
42
|
+
"@vizejs/vite-plugin-musea": "0.71.0",
|
|
43
|
+
"vize": "0.71.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"typescript": "6.0.3",
|