@vizejs/nuxt 0.160.0 → 0.162.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 +80 -20
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import path from "node:path";
|
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
//#region src/components.ts
|
|
9
9
|
const COMPONENT_CALL_RE = /_?resolveComponent\s*\(\s*["'`]([^"'`]+)["'`]\s*(?:,\s*[^)]+)?\)/g;
|
|
10
|
+
const COMPONENTS_IMPORT_RE = /import\s+(?!type\b)\{([^}]*)\}\s+from\s+(["'])#components\2\s*;?/g;
|
|
10
11
|
const COMPONENT_EXT_RE = /\.(?:[cm]?js|ts|vue)$/;
|
|
11
12
|
const DTS_COMPONENT_RE = /^export const (\w+): (?:LazyComponent<)?typeof import\((["'])(.+?)\2\)(?:\.([A-Za-z_$][\w$]*)|\[['"]([A-Za-z_$][\w$]*)['"]\])>?/;
|
|
12
13
|
const DTS_EXT_RE = /\.d\.ts$/;
|
|
@@ -23,6 +24,7 @@ const RUNTIME_COMPONENT_DIRS = [
|
|
|
23
24
|
"dist/runtime/components/nuxt4",
|
|
24
25
|
"runtime/components"
|
|
25
26
|
];
|
|
27
|
+
const IMPORT_SPECIFIER_RE = /^(type\s+)?([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/;
|
|
26
28
|
function toKebabCase(name) {
|
|
27
29
|
return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/_/g, "-").toLowerCase();
|
|
28
30
|
}
|
|
@@ -59,6 +61,21 @@ function detectComponentMode(filePath) {
|
|
|
59
61
|
function normalizeComponentMode(mode) {
|
|
60
62
|
return mode === "client" || mode === "server" ? mode : void 0;
|
|
61
63
|
}
|
|
64
|
+
function parseComponentImportSpecifier(raw) {
|
|
65
|
+
const trimmed = raw.trim();
|
|
66
|
+
if (!trimmed) return null;
|
|
67
|
+
const match = trimmed.match(IMPORT_SPECIFIER_RE);
|
|
68
|
+
if (!match) return null;
|
|
69
|
+
const [, typeKeyword, importedName, localName] = match;
|
|
70
|
+
return {
|
|
71
|
+
importedName,
|
|
72
|
+
localName: localName || importedName,
|
|
73
|
+
typeOnly: Boolean(typeKeyword)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function splitComponentImportSpecifiers(specifiers) {
|
|
77
|
+
return specifiers.split(",").map((specifier) => specifier.trim()).filter(Boolean);
|
|
78
|
+
}
|
|
62
79
|
function createComponentImport(filePath, exportName, lazy, mode) {
|
|
63
80
|
const componentImport = {
|
|
64
81
|
exportName,
|
|
@@ -69,6 +86,42 @@ function createComponentImport(filePath, exportName, lazy, mode) {
|
|
|
69
86
|
if (resolvedMode) componentImport.mode = resolvedMode;
|
|
70
87
|
return componentImport;
|
|
71
88
|
}
|
|
89
|
+
function addResolvedComponentBinding(componentImports, resolved, variableName, rawVariableName) {
|
|
90
|
+
let needsCreateClientOnly = false;
|
|
91
|
+
let needsDefineAsyncComponent = false;
|
|
92
|
+
if (resolved.lazy) {
|
|
93
|
+
needsDefineAsyncComponent = true;
|
|
94
|
+
const exportAccessor = resolved.exportName === "default" ? "module.default" : `module[${JSON.stringify(resolved.exportName)}]`;
|
|
95
|
+
if (resolved.mode === "client") {
|
|
96
|
+
needsCreateClientOnly = true;
|
|
97
|
+
componentImports.push(`const ${variableName} = __nuxt_define_async_component(() => import(${JSON.stringify(resolved.filePath)}).then((module) => __nuxt_create_client_only(${exportAccessor})));`);
|
|
98
|
+
} else componentImports.push(`const ${variableName} = __nuxt_define_async_component(() => import(${JSON.stringify(resolved.filePath)}).then((module) => ${exportAccessor}));`);
|
|
99
|
+
return {
|
|
100
|
+
needsCreateClientOnly,
|
|
101
|
+
needsDefineAsyncComponent
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (resolved.exportName === "default") {
|
|
105
|
+
if (resolved.mode === "client") {
|
|
106
|
+
needsCreateClientOnly = true;
|
|
107
|
+
componentImports.push(`import ${rawVariableName} from ${JSON.stringify(resolved.filePath)};`);
|
|
108
|
+
componentImports.push(`const ${variableName} = __nuxt_create_client_only(${rawVariableName});`);
|
|
109
|
+
} else componentImports.push(`import ${variableName} from ${JSON.stringify(resolved.filePath)};`);
|
|
110
|
+
return {
|
|
111
|
+
needsCreateClientOnly,
|
|
112
|
+
needsDefineAsyncComponent
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
if (resolved.mode === "client") {
|
|
116
|
+
needsCreateClientOnly = true;
|
|
117
|
+
componentImports.push(`import { ${resolved.exportName} as ${rawVariableName} } from ${JSON.stringify(resolved.filePath)};`);
|
|
118
|
+
componentImports.push(`const ${variableName} = __nuxt_create_client_only(${rawVariableName});`);
|
|
119
|
+
} else componentImports.push(`import { ${resolved.exportName} as ${variableName} } from ${JSON.stringify(resolved.filePath)};`);
|
|
120
|
+
return {
|
|
121
|
+
needsCreateClientOnly,
|
|
122
|
+
needsDefineAsyncComponent
|
|
123
|
+
};
|
|
124
|
+
}
|
|
72
125
|
function getNuxtComponentDtsFiles(rootDir, buildDir) {
|
|
73
126
|
const candidates = [
|
|
74
127
|
path.join(buildDir, "components.d.ts"),
|
|
@@ -178,9 +231,32 @@ function injectNuxtComponentImports(code, resolveComponentImport) {
|
|
|
178
231
|
const componentImports = [];
|
|
179
232
|
const importedComponents = /* @__PURE__ */ new Map();
|
|
180
233
|
let counter = 0;
|
|
234
|
+
let importCounter = 0;
|
|
181
235
|
let needsDefineAsyncComponent = false;
|
|
182
236
|
let needsCreateClientOnly = false;
|
|
183
|
-
const nextCode = code.replace(
|
|
237
|
+
const nextCode = code.replace(COMPONENTS_IMPORT_RE, (match, specifiers) => {
|
|
238
|
+
const unresolvedSpecifiers = [];
|
|
239
|
+
let changed = false;
|
|
240
|
+
for (const rawSpecifier of splitComponentImportSpecifiers(specifiers)) {
|
|
241
|
+
const specifier = parseComponentImportSpecifier(rawSpecifier);
|
|
242
|
+
if (!specifier || specifier.typeOnly) {
|
|
243
|
+
unresolvedSpecifiers.push(rawSpecifier);
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
const resolved = resolveComponentImport(specifier.importedName);
|
|
247
|
+
if (!resolved) {
|
|
248
|
+
unresolvedSpecifiers.push(rawSpecifier);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
changed = true;
|
|
252
|
+
const result = addResolvedComponentBinding(componentImports, resolved, specifier.localName, `__nuxt_import_component_${importCounter++}_raw`);
|
|
253
|
+
needsCreateClientOnly ||= result.needsCreateClientOnly;
|
|
254
|
+
needsDefineAsyncComponent ||= result.needsDefineAsyncComponent;
|
|
255
|
+
}
|
|
256
|
+
if (!changed) return match;
|
|
257
|
+
if (unresolvedSpecifiers.length === 0) return "";
|
|
258
|
+
return `import { ${unresolvedSpecifiers.join(", ")} } from "#components";`;
|
|
259
|
+
}).replace(COMPONENT_CALL_RE, (match, name) => {
|
|
184
260
|
const resolved = resolveComponentImport(name);
|
|
185
261
|
if (!resolved) return match;
|
|
186
262
|
const importKey = `${resolved.exportName}\u0000${resolved.filePath}\u0000${resolved.lazy ? "lazy" : "eager"}\u0000${resolved.mode ?? "default"}`;
|
|
@@ -188,25 +264,9 @@ function injectNuxtComponentImports(code, resolveComponentImport) {
|
|
|
188
264
|
if (!variableName) {
|
|
189
265
|
variableName = `__nuxt_component_${counter++}`;
|
|
190
266
|
importedComponents.set(importKey, variableName);
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (resolved.mode === "client") {
|
|
195
|
-
needsCreateClientOnly = true;
|
|
196
|
-
componentImports.push(`const ${variableName} = __nuxt_define_async_component(() => import(${JSON.stringify(resolved.filePath)}).then((module) => __nuxt_create_client_only(${exportAccessor})));`);
|
|
197
|
-
} else componentImports.push(`const ${variableName} = __nuxt_define_async_component(() => import(${JSON.stringify(resolved.filePath)}).then((module) => ${exportAccessor}));`);
|
|
198
|
-
} else if (resolved.exportName === "default") if (resolved.mode === "client") {
|
|
199
|
-
needsCreateClientOnly = true;
|
|
200
|
-
const rawVariableName = `${variableName}_raw`;
|
|
201
|
-
componentImports.push(`import ${rawVariableName} from ${JSON.stringify(resolved.filePath)};`);
|
|
202
|
-
componentImports.push(`const ${variableName} = __nuxt_create_client_only(${rawVariableName});`);
|
|
203
|
-
} else componentImports.push(`import ${variableName} from ${JSON.stringify(resolved.filePath)};`);
|
|
204
|
-
else if (resolved.mode === "client") {
|
|
205
|
-
needsCreateClientOnly = true;
|
|
206
|
-
const rawVariableName = `${variableName}_raw`;
|
|
207
|
-
componentImports.push(`import { ${resolved.exportName} as ${rawVariableName} } from ${JSON.stringify(resolved.filePath)};`);
|
|
208
|
-
componentImports.push(`const ${variableName} = __nuxt_create_client_only(${rawVariableName});`);
|
|
209
|
-
} else componentImports.push(`import { ${resolved.exportName} as ${variableName} } from ${JSON.stringify(resolved.filePath)};`);
|
|
267
|
+
const result = addResolvedComponentBinding(componentImports, resolved, variableName, `${variableName}_raw`);
|
|
268
|
+
needsCreateClientOnly ||= result.needsCreateClientOnly;
|
|
269
|
+
needsDefineAsyncComponent ||= result.needsDefineAsyncComponent;
|
|
210
270
|
}
|
|
211
271
|
return variableName;
|
|
212
272
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.162.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.
|
|
45
|
-
"@vizejs/vite-plugin": "0.
|
|
46
|
-
"@vizejs/vite-plugin-musea": "0.
|
|
47
|
-
"vize": "0.
|
|
44
|
+
"@vizejs/musea-nuxt": "0.162.0",
|
|
45
|
+
"@vizejs/vite-plugin": "0.162.0",
|
|
46
|
+
"@vizejs/vite-plugin-musea": "0.162.0",
|
|
47
|
+
"vize": "0.162.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"typescript": "6.0.3",
|