@vizejs/nuxt 0.695.0 → 0.697.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 +55 -16
  2. package/package.json +7 -7
package/dist/index.mjs CHANGED
@@ -4,6 +4,15 @@ import fs, { readFileSync, realpathSync } from "node:fs";
4
4
  import path, { dirname, join, resolve } from "node:path";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import { createHash } from "node:crypto";
7
+ //#region src/component-registration.ts
8
+ function registeredComponentPath(component, components) {
9
+ const name = component.pascalName ?? component.name;
10
+ const hasClientVariant = components.some((candidate) => candidate.pascalName === component.pascalName && candidate.mode === "client");
11
+ if (component._raw || component.mode !== "server" || !name || hasClientVariant) return component.filePath;
12
+ const separator = component.filePath.includes("?") ? "&" : "?";
13
+ return `${component.filePath}${separator}nuxt_component=server&nuxt_component_name=${name}&nuxt_component_export=${component.export ?? "default"}`;
14
+ }
15
+ //#endregion
7
16
  //#region src/component-imports.ts
8
17
  const COMPONENT_CALL_RE = /_?resolveComponent\s*\(\s*["'`]([^"'`]+)["'`]\s*(?:,\s*[^)]+)?\)/g;
9
18
  const COMPONENTS_IMPORT_RE = /import\s+(?!type\b)\{([^}]*)\}\s+from\s+(["'])#components\2\s*;?/g;
@@ -88,7 +97,7 @@ function injectNuxtComponentImports(code, resolveComponentImport) {
88
97
  continue;
89
98
  }
90
99
  changed = true;
91
- const result = addResolvedComponentBinding(explicitComponentImports, resolved, specifier.localName, `__nuxt_import_component_${importCounter++}_raw`);
100
+ const result = addResolvedComponentBinding(explicitComponentImports, resolved, specifier.localName, `__vize_nuxt_import_component_${importCounter++}_raw`);
92
101
  needsCreateClientOnly ||= result.needsCreateClientOnly;
93
102
  needsDefineAsyncComponent ||= result.needsDefineAsyncComponent;
94
103
  }
@@ -102,7 +111,7 @@ function injectNuxtComponentImports(code, resolveComponentImport) {
102
111
  const importKey = `${resolved.exportName}\u0000${resolved.filePath}\u0000${resolved.lazy ? "lazy" : "eager"}\u0000${resolved.mode ?? "default"}`;
103
112
  let variableName = importedComponents.get(importKey);
104
113
  if (!variableName) {
105
- variableName = `__nuxt_component_${counter++}`;
114
+ variableName = `__vize_nuxt_component_${counter++}`;
106
115
  importedComponents.set(importKey, variableName);
107
116
  const result = addResolvedComponentBinding(componentImports, resolved, variableName, `${variableName}_raw`);
108
117
  needsCreateClientOnly ||= result.needsCreateClientOnly;
@@ -150,6 +159,27 @@ function addComponentAlias(map, name, resolved) {
150
159
  const pascalName = toPascalCase(name);
151
160
  if (!map.has(pascalName)) map.set(pascalName, resolved);
152
161
  }
162
+ function addRegisteredComponentAlias(map, name, resolved) {
163
+ if (!name) return;
164
+ for (const alias of new Set([
165
+ name,
166
+ toKebabCase(name),
167
+ toPascalCase(name)
168
+ ])) {
169
+ const candidates = map.get(alias) ?? [];
170
+ if (candidates.some((candidate) => candidate.mode === resolved.mode)) continue;
171
+ candidates.push(resolved);
172
+ map.set(alias, candidates);
173
+ }
174
+ }
175
+ function selectRegisteredComponent(candidates, mode) {
176
+ if (!candidates || candidates.length === 0) return null;
177
+ if (!mode) return candidates[0] ?? null;
178
+ return candidates.find((candidate) => candidate.mode === mode) ?? candidates.find((candidate) => candidate.mode === void 0) ?? null;
179
+ }
180
+ function matchesBuildMode(component, mode) {
181
+ return Boolean(component && (!mode || !component.mode || component.mode === mode));
182
+ }
153
183
  function addLazyComponentAlias(map, name, resolved) {
154
184
  if (!name || name.startsWith("Lazy")) return;
155
185
  addComponentAlias(map, `Lazy${toPascalCase(name)}`, {
@@ -319,21 +349,32 @@ function createNuxtComponentResolver(options) {
319
349
  return {
320
350
  register(components) {
321
351
  for (const component of components) {
322
- const resolved = createComponentImport(component.filePath, component.export || "default", false, component.mode);
323
- addComponentAlias(registered, component.pascalName, resolved);
324
- addComponentAlias(registered, component.kebabName, resolved);
325
- addComponentAlias(registered, component.name, resolved);
326
- addLazyComponentAlias(registered, component.pascalName, resolved);
327
- addLazyComponentAlias(registered, component.kebabName, resolved);
328
- addLazyComponentAlias(registered, component.name, resolved);
352
+ const resolved = createComponentImport(registeredComponentPath(component, components), component.export || "default", false, component.mode);
353
+ addRegisteredComponentAlias(registered, component.pascalName, resolved);
354
+ addRegisteredComponentAlias(registered, component.kebabName, resolved);
355
+ addRegisteredComponentAlias(registered, component.name, resolved);
356
+ for (const name of [
357
+ component.pascalName,
358
+ component.kebabName,
359
+ component.name
360
+ ]) {
361
+ if (!name || name.startsWith("Lazy")) continue;
362
+ addRegisteredComponentAlias(registered, `Lazy${toPascalCase(name)}`, {
363
+ ...resolved,
364
+ lazy: true
365
+ });
366
+ }
329
367
  }
330
368
  },
331
- resolve(name) {
369
+ resolve(name, mode) {
332
370
  const normalizedName = name.trim();
333
- const directResolved = registered.get(normalizedName) ?? getDtsResolved().get(normalizedName);
334
- if (directResolved) return directResolved;
371
+ const registeredResolved = selectRegisteredComponent(registered.get(normalizedName), mode);
372
+ if (registeredResolved) return registeredResolved;
373
+ const dtsResolved = getDtsResolved().get(normalizedName);
374
+ if (matchesBuildMode(dtsResolved, mode)) return dtsResolved;
335
375
  if (!/[A-Z]/.test(normalizedName)) return null;
336
- return getRuntimeResolved().get(normalizedName) ?? null;
376
+ const runtimeResolved = getRuntimeResolved().get(normalizedName);
377
+ return matchesBuildMode(runtimeResolved, mode) ? runtimeResolved : null;
337
378
  }
338
379
  };
339
380
  }
@@ -1635,9 +1676,7 @@ async function setupVizeNuxtModule(raw, nuxt) {
1635
1676
  let result = code;
1636
1677
  let changed = false;
1637
1678
  if (nuxtComponentResolver && hasComponentBridgeInput(result)) {
1638
- const nextComponentResult = injectNuxtComponentImports(result, (name) => {
1639
- return nuxtComponentResolver.resolve(name);
1640
- });
1679
+ const nextComponentResult = injectNuxtComponentImports(result, (name) => nuxtComponentResolver.resolve(name, isViteSsrTransform(args) ? "server" : "client"));
1641
1680
  if (nextComponentResult !== result) {
1642
1681
  result = nextComponentResult;
1643
1682
  changed = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.695.0",
3
+ "version": "0.697.0",
4
4
  "description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
5
5
  "keywords": [
6
6
  "compiler",
@@ -49,15 +49,15 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@nuxt/kit": "3.21.8",
52
- "@vizejs/native": "0.695.0",
53
- "@vizejs/nuxt-lint-config": "0.695.0",
54
- "@vizejs/vite-plugin": "0.695.0",
55
- "@vizejs/vite-plugin-musea": "0.695.0",
56
- "vize": "0.695.0"
52
+ "@vizejs/native": "0.697.0",
53
+ "@vizejs/nuxt-lint-config": "0.697.0",
54
+ "@vizejs/vite-plugin": "0.697.0",
55
+ "@vizejs/vite-plugin-musea": "0.697.0",
56
+ "vize": "0.697.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "jiti-nuxt2": "npm:jiti@1.21.7",
60
- "oxlint-plugin-vize": "0.695.0",
60
+ "oxlint-plugin-vize": "0.697.0",
61
61
  "typescript": "6.0.3",
62
62
  "vite": "npm:@voidzero-dev/vite-plus-core@1.3.0",
63
63
  "vite-plus": "1.3.0",