@vizejs/nuxt 0.166.0 → 0.168.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.
Files changed (2) hide show
  1. package/dist/index.mjs +80 -5
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -433,19 +433,94 @@ function isVizeGeneratedVueModuleId(id) {
433
433
  function normalizeVizeVirtualVueModuleId(id) {
434
434
  return (id.startsWith("\0vize-ssr:") ? id.slice(10) : id.slice(1)).replace(/\.ts(?=\?|$)/, "");
435
435
  }
436
+ function normalizeVizeGeneratedVueModuleId(id) {
437
+ if (isVizeVirtualVueModuleId(id)) return normalizeVizeVirtualVueModuleId(id);
438
+ return id.replace(/^\/@id\/__x00__/, "").replace(/^__x00__/, "").replace(/\.ts(?=\?|$)/, "");
439
+ }
436
440
  const NUXT_INJECTED_MARKER = "/* nuxt-injected */";
437
441
  const NUXT_INJECTED_KEY_RE = /'\$[^']+'\s+\/\* nuxt-injected \*\//g;
442
+ const NUXT_FETCH_COMPOSABLE_RE = /\b(?:useFetch|useLazyFetch)\s*\(/g;
438
443
  function buildStableNuxtKey(id, index) {
439
444
  return createHash("sha256").update(id).update(":").update(String(index)).digest("base64url").slice(0, 10);
440
445
  }
441
- function normalizeNuxtInjectedKeysForVizeVirtualModule(code, id) {
442
- const normalizedId = normalizeVizeVirtualVueModuleId(id);
446
+ function normalizeNuxtInjectedKeysForVizeVirtualModule$1(code, id) {
447
+ const normalizedId = normalizeVizeGeneratedVueModuleId(id).replace(/\?.*$/, "");
443
448
  let index = 0;
444
449
  return code.replace(NUXT_INJECTED_KEY_RE, () => {
445
450
  index += 1;
446
451
  return `'$${buildStableNuxtKey(normalizedId, index)}' ${NUXT_INJECTED_MARKER}`;
447
452
  });
448
453
  }
454
+ function stabilizeNuxtInjectedKeysForVizeVirtualModule(code, id) {
455
+ return normalizeNuxtInjectedKeysForVizeVirtualModule$1(injectMissingNuxtFetchKeys(code), id);
456
+ }
457
+ function injectMissingNuxtFetchKeys(code) {
458
+ let output = "";
459
+ let cursor = 0;
460
+ for (const match of code.matchAll(NUXT_FETCH_COMPOSABLE_RE)) {
461
+ const openParenIndex = (match.index ?? 0) + match[0].length - 1;
462
+ if (openParenIndex < cursor) continue;
463
+ const closeParenIndex = findMatchingParen(code, openParenIndex);
464
+ if (closeParenIndex === -1) continue;
465
+ const args = code.slice(openParenIndex + 1, closeParenIndex);
466
+ if (args.includes(NUXT_INJECTED_MARKER)) continue;
467
+ output += code.slice(cursor, closeParenIndex);
468
+ output += `${args.trim().length === 0 ? "" : ", "}'$__vize_nuxt_key__' ${NUXT_INJECTED_MARKER}`;
469
+ cursor = closeParenIndex;
470
+ }
471
+ return cursor === 0 ? code : output + code.slice(cursor);
472
+ }
473
+ function findMatchingParen(code, openParenIndex) {
474
+ let depth = 0;
475
+ let quote = null;
476
+ let escaped = false;
477
+ let lineComment = false;
478
+ let blockComment = false;
479
+ for (let index = openParenIndex; index < code.length; index += 1) {
480
+ const char = code[index];
481
+ const next = code[index + 1];
482
+ if (lineComment) {
483
+ if (char === "\n" || char === "\r") lineComment = false;
484
+ continue;
485
+ }
486
+ if (blockComment) {
487
+ if (char === "*" && next === "/") {
488
+ blockComment = false;
489
+ index += 1;
490
+ }
491
+ continue;
492
+ }
493
+ if (quote) {
494
+ if (escaped) escaped = false;
495
+ else if (char === "\\") escaped = true;
496
+ else if (char === quote) quote = null;
497
+ continue;
498
+ }
499
+ if (char === "/" && next === "/") {
500
+ lineComment = true;
501
+ index += 1;
502
+ continue;
503
+ }
504
+ if (char === "/" && next === "*") {
505
+ blockComment = true;
506
+ index += 1;
507
+ continue;
508
+ }
509
+ if (char === "'" || char === "\"" || char === "`") {
510
+ quote = char;
511
+ continue;
512
+ }
513
+ if (char === "(") {
514
+ depth += 1;
515
+ continue;
516
+ }
517
+ if (char === ")") {
518
+ depth -= 1;
519
+ if (depth === 0) return index;
520
+ }
521
+ }
522
+ return -1;
523
+ }
449
524
  const NAMED_IMPORT_RE = /^import\s*\{([\s\S]*?)\}\s*from\s*(['"])(vue|#imports|#entry)\2\s*;?/gm;
450
525
  function parseNamedImportSpecifiers(specifierSource) {
451
526
  return specifierSource.split(",").map((specifier) => specifier.trim()).filter(Boolean).flatMap((specifier) => {
@@ -516,7 +591,7 @@ function preserveExplicitVueImportsFromNuxtAutoImports(originalCode, injectedCod
516
591
  }
517
592
  function preserveExplicitVueImportsFromVizeModuleSource(id, code) {
518
593
  if (!isVizeVirtualVueModuleId(id) && !isVizeGeneratedVueModuleId(id)) return code;
519
- const sourcePath = (isVizeVirtualVueModuleId(id) ? normalizeVizeVirtualVueModuleId(id) : id.replace(/^\/@id\/__x00__/, "").replace(/^__x00__/, "").replace(/\.ts(?=\?|$)/, "")).replace(/\?.*$/, "");
594
+ const sourcePath = normalizeVizeGeneratedVueModuleId(id).replace(/\?.*$/, "");
520
595
  if (!sourcePath.endsWith(".vue") || !fs.existsSync(sourcePath)) return code;
521
596
  return preserveExplicitVueImportsFromNuxtAutoImports(fs.readFileSync(sourcePath, "utf-8"), code);
522
597
  }
@@ -795,7 +870,7 @@ var src_default = defineNuxtModule({
795
870
  name: "vizejs:nuxt-transform-bridge",
796
871
  enforce: "post",
797
872
  async transform(code, id, ...args) {
798
- if (!isVizeVirtualVueModuleId(id)) return;
873
+ if (!isVizeGeneratedVueModuleId(id)) return;
799
874
  let result = code;
800
875
  let changed = false;
801
876
  if (nuxtComponentResolver) {
@@ -830,7 +905,7 @@ var src_default = defineNuxtModule({
830
905
  }
831
906
  }
832
907
  if (bridgeOptions.stableInjectedKeys) {
833
- const stableKeyResult = normalizeNuxtInjectedKeysForVizeVirtualModule(result, id);
908
+ const stableKeyResult = stabilizeNuxtInjectedKeysForVizeVirtualModule(result, id);
834
909
  if (stableKeyResult !== result) {
835
910
  result = stableKeyResult;
836
911
  changed = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.166.0",
3
+ "version": "0.168.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -41,10 +41,10 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@nuxt/kit": "4.4.6",
44
- "@vizejs/musea-nuxt": "0.166.0",
45
- "@vizejs/vite-plugin": "0.166.0",
46
- "@vizejs/vite-plugin-musea": "0.166.0",
47
- "vize": "0.166.0"
44
+ "@vizejs/musea-nuxt": "0.168.0",
45
+ "@vizejs/vite-plugin": "0.168.0",
46
+ "@vizejs/vite-plugin-musea": "0.168.0",
47
+ "vize": "0.168.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "6.0.3",