@vizejs/nuxt 0.165.0 → 0.167.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 +91 -6
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -393,6 +393,7 @@ function injectNuxtI18nHelpers(code) {
393
393
  }
394
394
  //#endregion
395
395
  //#region src/utils.ts
396
+ const NUXT_OG_IMAGE_RENDERER_SFC_EXCLUDE = /\.takumi\.vue(?:\?|$)/;
396
397
  function normalizeUrlPrefix(value) {
397
398
  const withLeadingSlash = value.startsWith("/") ? value : `/${value}`;
398
399
  return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
@@ -408,9 +409,18 @@ function buildNuxtCompilerOptions(rootDir, baseURL = "/", buildAssetsDir = "/_nu
408
409
  root: rootDir,
409
410
  scanPatterns: []
410
411
  };
411
- for (const [key, value] of Object.entries(overrides)) if (value !== void 0) defaults[key] = value;
412
+ if (overrides.customRenderer === true && overrides.exclude !== void 0) defaults.exclude = overrides.exclude;
413
+ else if (overrides.customRenderer !== true) defaults.exclude = mergeNuxtCompilerPatterns(NUXT_OG_IMAGE_RENDERER_SFC_EXCLUDE, overrides.exclude);
414
+ for (const [key, value] of Object.entries(overrides)) {
415
+ if (key === "exclude") continue;
416
+ if (value !== void 0) defaults[key] = value;
417
+ }
412
418
  return defaults;
413
419
  }
420
+ function mergeNuxtCompilerPatterns(defaultPattern, userPattern) {
421
+ if (userPattern == null) return defaultPattern;
422
+ return [defaultPattern, ...Array.isArray(userPattern) ? userPattern : [userPattern]];
423
+ }
414
424
  function isVizeVirtualVueModuleId(id) {
415
425
  return id.startsWith("\0") && /\.vue\.ts(?:\?|$)/.test(id);
416
426
  }
@@ -423,19 +433,94 @@ function isVizeGeneratedVueModuleId(id) {
423
433
  function normalizeVizeVirtualVueModuleId(id) {
424
434
  return (id.startsWith("\0vize-ssr:") ? id.slice(10) : id.slice(1)).replace(/\.ts(?=\?|$)/, "");
425
435
  }
436
+ function normalizeVizeGeneratedVueModuleId(id) {
437
+ if (isVizeVirtualVueModuleId(id)) return normalizeVizeVirtualVueModuleId(id);
438
+ return id.replace(/^\/@id\/__x00__/, "").replace(/^__x00__/, "").replace(/\.ts(?=\?|$)/, "");
439
+ }
426
440
  const NUXT_INJECTED_MARKER = "/* nuxt-injected */";
427
441
  const NUXT_INJECTED_KEY_RE = /'\$[^']+'\s+\/\* nuxt-injected \*\//g;
442
+ const NUXT_FETCH_COMPOSABLE_RE = /\b(?:useFetch|useLazyFetch)\s*\(/g;
428
443
  function buildStableNuxtKey(id, index) {
429
444
  return createHash("sha256").update(id).update(":").update(String(index)).digest("base64url").slice(0, 10);
430
445
  }
431
- function normalizeNuxtInjectedKeysForVizeVirtualModule(code, id) {
432
- const normalizedId = normalizeVizeVirtualVueModuleId(id);
446
+ function normalizeNuxtInjectedKeysForVizeVirtualModule$1(code, id) {
447
+ const normalizedId = normalizeVizeGeneratedVueModuleId(id).replace(/\?.*$/, "");
433
448
  let index = 0;
434
449
  return code.replace(NUXT_INJECTED_KEY_RE, () => {
435
450
  index += 1;
436
451
  return `'$${buildStableNuxtKey(normalizedId, index)}' ${NUXT_INJECTED_MARKER}`;
437
452
  });
438
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
+ }
439
524
  const NAMED_IMPORT_RE = /^import\s*\{([\s\S]*?)\}\s*from\s*(['"])(vue|#imports|#entry)\2\s*;?/gm;
440
525
  function parseNamedImportSpecifiers(specifierSource) {
441
526
  return specifierSource.split(",").map((specifier) => specifier.trim()).filter(Boolean).flatMap((specifier) => {
@@ -506,7 +591,7 @@ function preserveExplicitVueImportsFromNuxtAutoImports(originalCode, injectedCod
506
591
  }
507
592
  function preserveExplicitVueImportsFromVizeModuleSource(id, code) {
508
593
  if (!isVizeVirtualVueModuleId(id) && !isVizeGeneratedVueModuleId(id)) return code;
509
- const sourcePath = (isVizeVirtualVueModuleId(id) ? normalizeVizeVirtualVueModuleId(id) : id.replace(/^\/@id\/__x00__/, "").replace(/^__x00__/, "").replace(/\.ts(?=\?|$)/, "")).replace(/\?.*$/, "");
594
+ const sourcePath = normalizeVizeGeneratedVueModuleId(id).replace(/\?.*$/, "");
510
595
  if (!sourcePath.endsWith(".vue") || !fs.existsSync(sourcePath)) return code;
511
596
  return preserveExplicitVueImportsFromNuxtAutoImports(fs.readFileSync(sourcePath, "utf-8"), code);
512
597
  }
@@ -785,7 +870,7 @@ var src_default = defineNuxtModule({
785
870
  name: "vizejs:nuxt-transform-bridge",
786
871
  enforce: "post",
787
872
  async transform(code, id, ...args) {
788
- if (!isVizeVirtualVueModuleId(id)) return;
873
+ if (!isVizeGeneratedVueModuleId(id)) return;
789
874
  let result = code;
790
875
  let changed = false;
791
876
  if (nuxtComponentResolver) {
@@ -820,7 +905,7 @@ var src_default = defineNuxtModule({
820
905
  }
821
906
  }
822
907
  if (bridgeOptions.stableInjectedKeys) {
823
- const stableKeyResult = normalizeNuxtInjectedKeysForVizeVirtualModule(result, id);
908
+ const stableKeyResult = stabilizeNuxtInjectedKeysForVizeVirtualModule(result, id);
824
909
  if (stableKeyResult !== result) {
825
910
  result = stableKeyResult;
826
911
  changed = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.165.0",
3
+ "version": "0.167.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.165.0",
45
- "@vizejs/vite-plugin": "0.165.0",
46
- "@vizejs/vite-plugin-musea": "0.165.0",
47
- "vize": "0.165.0"
44
+ "@vizejs/musea-nuxt": "0.167.0",
45
+ "@vizejs/vite-plugin": "0.167.0",
46
+ "@vizejs/vite-plugin-musea": "0.167.0",
47
+ "vize": "0.167.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "6.0.3",