@vizejs/nuxt 0.163.0 → 0.165.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 +60 -13
  2. package/package.json +7 -6
package/dist/index.mjs CHANGED
@@ -10,6 +10,7 @@ const COMPONENT_CALL_RE = /_?resolveComponent\s*\(\s*["'`]([^"'`]+)["'`]\s*(?:,\
10
10
  const COMPONENTS_IMPORT_RE = /import\s+(?!type\b)\{([^}]*)\}\s+from\s+(["'])#components\2\s*;?/g;
11
11
  const COMPONENT_EXT_RE = /\.(?:[cm]?js|ts|vue)$/;
12
12
  const DTS_COMPONENT_RE = /^export const (\w+): (?:LazyComponent<)?typeof import\((["'])(.+?)\2\)(?:\.([A-Za-z_$][\w$]*)|\[['"]([A-Za-z_$][\w$]*)['"]\])>?/;
13
+ const DTS_GLOBAL_COMPONENT_RE = /^(?:"([^"]+)"|'([^']+)'|([A-Za-z_$][\w$]*))\??:\s*(?:LazyComponent<)?typeof import\((["'])(.+?)\4\)(?:\.([A-Za-z_$][\w$]*)|\[['"]([A-Za-z_$][\w$]*)['"]\])>?;?$/;
13
14
  const DTS_EXT_RE = /\.d\.ts$/;
14
15
  const FILE_EXTS = [
15
16
  ".js",
@@ -19,6 +20,7 @@ const FILE_EXTS = [
19
20
  ];
20
21
  const CLIENT_COMPONENT_RE = /\.client\.(?:[cm]?js|ts|vue)$/;
21
22
  const SERVER_COMPONENT_RE = /\.server\.(?:[cm]?js|ts|vue)$/;
23
+ const NUXT_ROUTE_ANNOUNCER_RE = /(?:^|[/\\])nuxt-route-announcer\.(?:[cm]?js|ts|vue)$/;
22
24
  const RUNTIME_COMPONENT_DIRS = [
23
25
  "dist/runtime/components",
24
26
  "dist/runtime/components/nuxt4",
@@ -61,6 +63,10 @@ function detectComponentMode(filePath) {
61
63
  function normalizeComponentMode(mode) {
62
64
  return mode === "client" || mode === "server" ? mode : void 0;
63
65
  }
66
+ function needsClientOnlyWrapper(resolved) {
67
+ if (resolved.mode !== "client") return false;
68
+ return !NUXT_ROUTE_ANNOUNCER_RE.test(resolved.filePath);
69
+ }
64
70
  function parseComponentImportSpecifier(raw) {
65
71
  const trimmed = raw.trim();
66
72
  if (!trimmed) return null;
@@ -89,10 +95,11 @@ function createComponentImport(filePath, exportName, lazy, mode) {
89
95
  function addResolvedComponentBinding(componentImports, resolved, variableName, rawVariableName) {
90
96
  let needsCreateClientOnly = false;
91
97
  let needsDefineAsyncComponent = false;
98
+ const wrapClientOnly = needsClientOnlyWrapper(resolved);
92
99
  if (resolved.lazy) {
93
100
  needsDefineAsyncComponent = true;
94
101
  const exportAccessor = resolved.exportName === "default" ? "module.default" : `module[${JSON.stringify(resolved.exportName)}]`;
95
- if (resolved.mode === "client") {
102
+ if (wrapClientOnly) {
96
103
  needsCreateClientOnly = true;
97
104
  componentImports.push(`const ${variableName} = __nuxt_define_async_component(() => import(${JSON.stringify(resolved.filePath)}).then((module) => __nuxt_create_client_only(${exportAccessor})));`);
98
105
  } else componentImports.push(`const ${variableName} = __nuxt_define_async_component(() => import(${JSON.stringify(resolved.filePath)}).then((module) => ${exportAccessor}));`);
@@ -102,7 +109,7 @@ function addResolvedComponentBinding(componentImports, resolved, variableName, r
102
109
  };
103
110
  }
104
111
  if (resolved.exportName === "default") {
105
- if (resolved.mode === "client") {
112
+ if (wrapClientOnly) {
106
113
  needsCreateClientOnly = true;
107
114
  componentImports.push(`import ${rawVariableName} from ${JSON.stringify(resolved.filePath)};`);
108
115
  componentImports.push(`const ${variableName} = __nuxt_create_client_only(${rawVariableName});`);
@@ -112,7 +119,7 @@ function addResolvedComponentBinding(componentImports, resolved, variableName, r
112
119
  needsDefineAsyncComponent
113
120
  };
114
121
  }
115
- if (resolved.mode === "client") {
122
+ if (wrapClientOnly) {
116
123
  needsCreateClientOnly = true;
117
124
  componentImports.push(`import { ${resolved.exportName} as ${rawVariableName} } from ${JSON.stringify(resolved.filePath)};`);
118
125
  componentImports.push(`const ${variableName} = __nuxt_create_client_only(${rawVariableName});`);
@@ -144,18 +151,58 @@ function forEachLine(content, visit) {
144
151
  }
145
152
  function loadDtsComponents(rootDir, buildDir) {
146
153
  const resolved = /* @__PURE__ */ new Map();
147
- for (const filePath of getNuxtComponentDtsFiles(rootDir, buildDir)) forEachLine(fs.readFileSync(filePath, "utf-8"), (line) => {
148
- const match = line.match(DTS_COMPONENT_RE);
149
- if (!match) return;
150
- const [, name, , importPath, exportNameDot, exportNameBracket] = match;
151
- const exportName = exportNameDot || exportNameBracket;
152
- if (!exportName) return;
153
- const componentImport = createComponentImport(resolveImportPath(path.resolve(path.dirname(filePath), importPath)), exportName, name.startsWith("Lazy"));
154
- addComponentAlias(resolved, name, componentImport);
155
- addLazyComponentAlias(resolved, name, componentImport);
156
- });
154
+ for (const filePath of getNuxtComponentDtsFiles(rootDir, buildDir)) {
155
+ let inGlobalComponents = false;
156
+ let braceDepth = 0;
157
+ forEachLine(fs.readFileSync(filePath, "utf-8"), (line) => {
158
+ const trimmed = line.trim();
159
+ if (!inGlobalComponents && trimmed.includes("interface GlobalComponents")) {
160
+ inGlobalComponents = true;
161
+ braceDepth = countBraceDelta(trimmed);
162
+ return;
163
+ }
164
+ if (inGlobalComponents) {
165
+ braceDepth += countBraceDelta(trimmed);
166
+ if (braceDepth <= 0) {
167
+ inGlobalComponents = false;
168
+ return;
169
+ }
170
+ const globalMatch = trimmed.match(DTS_GLOBAL_COMPONENT_RE);
171
+ if (globalMatch) {
172
+ const doubleQuotedName = globalMatch[1];
173
+ const singleQuotedName = globalMatch[2];
174
+ const bareName = globalMatch[3];
175
+ const importPath = globalMatch[5];
176
+ const exportNameDot = globalMatch[6];
177
+ const exportNameBracket = globalMatch[7];
178
+ const name = doubleQuotedName || singleQuotedName || bareName;
179
+ const exportName = exportNameDot || exportNameBracket;
180
+ if (name && exportName) {
181
+ const componentImport = createComponentImport(resolveImportPath(path.resolve(path.dirname(filePath), importPath)), exportName, name.startsWith("Lazy"));
182
+ addComponentAlias(resolved, name, componentImport);
183
+ addLazyComponentAlias(resolved, name, componentImport);
184
+ }
185
+ }
186
+ return;
187
+ }
188
+ const match = trimmed.match(DTS_COMPONENT_RE);
189
+ if (!match) return;
190
+ const [, name, , importPath, exportNameDot, exportNameBracket] = match;
191
+ const exportName = exportNameDot || exportNameBracket;
192
+ if (!exportName) return;
193
+ const componentImport = createComponentImport(resolveImportPath(path.resolve(path.dirname(filePath), importPath)), exportName, name.startsWith("Lazy"));
194
+ addComponentAlias(resolved, name, componentImport);
195
+ addLazyComponentAlias(resolved, name, componentImport);
196
+ });
197
+ }
157
198
  return resolved;
158
199
  }
200
+ function countBraceDelta(line) {
201
+ let delta = 0;
202
+ for (const ch of line) if (ch === "{") delta++;
203
+ else if (ch === "}") delta--;
204
+ return delta;
205
+ }
159
206
  function getProjectPackageNames(moduleNames) {
160
207
  const packageNames = new Set(["nuxt"]);
161
208
  for (const name of moduleNames || []) packageNames.add(name);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizejs/nuxt",
3
- "version": "0.163.0",
3
+ "version": "0.165.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.163.0",
45
- "@vizejs/vite-plugin": "0.163.0",
46
- "@vizejs/vite-plugin-musea": "0.163.0",
47
- "vize": "0.163.0"
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"
48
48
  },
49
49
  "devDependencies": {
50
50
  "typescript": "6.0.3",
@@ -54,7 +54,8 @@
54
54
  "vue-router": "4.5.1"
55
55
  },
56
56
  "peerDependencies": {
57
- "nuxt": "^2.16.0 || ^3.0.0 || ^4.0.0"
57
+ "nuxt": "^2.16.0 || ^3.0.0 || ^4.0.0",
58
+ "vite": "^8.0.0"
58
59
  },
59
60
  "engines": {
60
61
  "node": ">=22"