@vizejs/nuxt 0.571.0 → 0.573.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.
|
@@ -39,6 +39,13 @@ function getNuxtBuilderKind(builder) {
|
|
|
39
39
|
if (isWebpackNuxtBuilder(builder)) return "webpack";
|
|
40
40
|
return "unsupported";
|
|
41
41
|
}
|
|
42
|
+
/** Nuxt 2's default webpack builder has no Nuxt 3-style builder name. */
|
|
43
|
+
function getDetectedNuxtBuilderKind(nuxt) {
|
|
44
|
+
const builder = nuxt.options.builder;
|
|
45
|
+
if (builder !== void 0) return getNuxtBuilderKind(builder);
|
|
46
|
+
if (getDetectedNuxtMajor(nuxt) !== 2) return "unsupported";
|
|
47
|
+
return nuxt.options.bridge && nuxt.options.bridge.vite === true ? "vite" : "webpack";
|
|
48
|
+
}
|
|
42
49
|
//#endregion
|
|
43
50
|
//#region src/lint/checker/options.ts
|
|
44
51
|
/**
|
|
@@ -538,6 +545,17 @@ function createNuxtLintCheckerWebpackPlugin(config, dependencies = {}) {
|
|
|
538
545
|
}
|
|
539
546
|
//#endregion
|
|
540
547
|
//#region src/lint/checker/setup.ts
|
|
548
|
+
function registerNuxt2Checker(nuxt, builder, plugin) {
|
|
549
|
+
if (!nuxt.hook) throw new Error("Nuxt 2 checker registration requires the host hook API.");
|
|
550
|
+
if (builder === "webpack") nuxt.hook("webpack:config", (value) => {
|
|
551
|
+
for (const config of value) if (config.name === "client") (config.plugins ??= []).push(plugin);
|
|
552
|
+
});
|
|
553
|
+
else nuxt.hook("vite:extendConfig", (value, context) => {
|
|
554
|
+
if (context?.isServer) return;
|
|
555
|
+
const config = value;
|
|
556
|
+
(config.plugins ??= []).push(plugin);
|
|
557
|
+
});
|
|
558
|
+
}
|
|
541
559
|
async function addVitePlugin(plugin) {
|
|
542
560
|
(await import("@nuxt/kit")).addVitePlugin(plugin, { server: false });
|
|
543
561
|
}
|
|
@@ -560,10 +578,16 @@ async function setupNuxtLintChecker(checker, nuxt, generation, dependencies = {}
|
|
|
560
578
|
options,
|
|
561
579
|
rootDir
|
|
562
580
|
};
|
|
563
|
-
const builder =
|
|
564
|
-
if (builder === "vite")
|
|
565
|
-
|
|
566
|
-
|
|
581
|
+
const builder = getDetectedNuxtBuilderKind(nuxt);
|
|
582
|
+
if (builder === "vite") {
|
|
583
|
+
const plugin = createNuxtLintCheckerVitePlugin(config);
|
|
584
|
+
if (!dependencies.addVitePlugin && getDetectedNuxtMajor(nuxt) === 2) registerNuxt2Checker(nuxt, builder, plugin);
|
|
585
|
+
else await (dependencies.addVitePlugin ?? addVitePlugin)(plugin);
|
|
586
|
+
} else if (builder === "webpack") {
|
|
587
|
+
const plugin = createNuxtLintCheckerWebpackPlugin(config);
|
|
588
|
+
if (!dependencies.addWebpackPlugin && getDetectedNuxtMajor(nuxt) === 2) registerNuxt2Checker(nuxt, builder, plugin);
|
|
589
|
+
else await (dependencies.addWebpackPlugin ?? addWebpackPlugin)(plugin);
|
|
590
|
+
} else {
|
|
567
591
|
const label = typeof nuxt.options.builder === "string" ? nuxt.options.builder : "unknown";
|
|
568
592
|
(dependencies.warn ?? console.warn)(`Unsupported Nuxt builder ${label}; Vize lint checker is disabled.`);
|
|
569
593
|
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { parseSync } from "vite";
|
|
2
|
+
//#region src/i18n.ts
|
|
3
|
+
const I18N_FN_MAP = {
|
|
4
|
+
$t: "t: $t",
|
|
5
|
+
$rt: "rt: $rt",
|
|
6
|
+
$d: "d: $d",
|
|
7
|
+
$n: "n: $n",
|
|
8
|
+
$tm: "tm: $tm",
|
|
9
|
+
$te: "te: $te"
|
|
10
|
+
};
|
|
11
|
+
const I18N_HELPER_LOCALS = new Set(Object.keys(I18N_FN_MAP));
|
|
12
|
+
const DEFAULT_PARSE_ID = "vize-nuxt-i18n-bridge.tsx";
|
|
13
|
+
function getLocalAlias(specifier) {
|
|
14
|
+
const colon = specifier.indexOf(":");
|
|
15
|
+
return (colon === -1 ? specifier : specifier.slice(colon + 1)).trim();
|
|
16
|
+
}
|
|
17
|
+
function isNode(value) {
|
|
18
|
+
return value != null && typeof value === "object" && typeof value.type === "string";
|
|
19
|
+
}
|
|
20
|
+
function getNodeStart(node) {
|
|
21
|
+
return typeof node.start === "number" ? node.start : null;
|
|
22
|
+
}
|
|
23
|
+
function getNodeEnd(node) {
|
|
24
|
+
return typeof node.end === "number" ? node.end : null;
|
|
25
|
+
}
|
|
26
|
+
function getNodeName(node) {
|
|
27
|
+
return isNode(node) && typeof node.name === "string" ? node.name : null;
|
|
28
|
+
}
|
|
29
|
+
function getChildNodes(node) {
|
|
30
|
+
const children = [];
|
|
31
|
+
for (const [key, value] of Object.entries(node)) {
|
|
32
|
+
if (key === "parent") continue;
|
|
33
|
+
if (Array.isArray(value)) {
|
|
34
|
+
for (const item of value) if (isNode(item)) children.push(item);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (isNode(value)) children.push(value);
|
|
38
|
+
}
|
|
39
|
+
return children;
|
|
40
|
+
}
|
|
41
|
+
function walkNode(node, visit) {
|
|
42
|
+
visit(node);
|
|
43
|
+
for (const child of getChildNodes(node)) walkNode(child, visit);
|
|
44
|
+
}
|
|
45
|
+
function parseProgram(code, id) {
|
|
46
|
+
try {
|
|
47
|
+
const result = parseSync(normalizeParseId(id), code);
|
|
48
|
+
if (isNode(result)) return result;
|
|
49
|
+
if (result != null && typeof result === "object") {
|
|
50
|
+
const program = result.program;
|
|
51
|
+
if (isNode(program)) return program;
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
} catch {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function normalizeParseId(id) {
|
|
59
|
+
return (id.startsWith("\0") ? id.slice(1) : id).split(/[?#]/, 1)[0] || DEFAULT_PARSE_ID;
|
|
60
|
+
}
|
|
61
|
+
function isSetupFunction(node) {
|
|
62
|
+
if (node.type !== "Property") return false;
|
|
63
|
+
const key = isNode(node.key) ? node.key : null;
|
|
64
|
+
const value = isNode(node.value) ? node.value : null;
|
|
65
|
+
if (getNodeName(key) !== "setup" || !value) return false;
|
|
66
|
+
if (value.type !== "FunctionExpression" && value.type !== "ArrowFunctionExpression") return false;
|
|
67
|
+
return getNodeName((Array.isArray(value.params) ? value.params : [])[0]) === "__props";
|
|
68
|
+
}
|
|
69
|
+
function findSetupFunctionBody(program) {
|
|
70
|
+
let setupBody = null;
|
|
71
|
+
walkNode(program, (node) => {
|
|
72
|
+
if (setupBody || !isSetupFunction(node)) return;
|
|
73
|
+
const value = isNode(node.value) ? node.value : null;
|
|
74
|
+
const body = value && isNode(value.body) ? value.body : null;
|
|
75
|
+
if (body?.type === "BlockStatement") setupBody = body;
|
|
76
|
+
});
|
|
77
|
+
return setupBody;
|
|
78
|
+
}
|
|
79
|
+
function isUseI18nCall(node) {
|
|
80
|
+
if (!isNode(node) || node.type !== "CallExpression") return false;
|
|
81
|
+
return getNodeName(isNode(node.callee) ? node.callee : null) === "useI18n";
|
|
82
|
+
}
|
|
83
|
+
function collectPatternBindingNames(pattern, locals) {
|
|
84
|
+
if (pattern.type === "Identifier" && typeof pattern.name === "string") {
|
|
85
|
+
locals.add(pattern.name);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (pattern.type === "AssignmentPattern" && isNode(pattern.left)) {
|
|
89
|
+
collectPatternBindingNames(pattern.left, locals);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (pattern.type === "RestElement" && isNode(pattern.argument)) {
|
|
93
|
+
collectPatternBindingNames(pattern.argument, locals);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (pattern.type === "Property" && isNode(pattern.value)) {
|
|
97
|
+
collectPatternBindingNames(pattern.value, locals);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
for (const child of getChildNodes(pattern)) collectPatternBindingNames(child, locals);
|
|
101
|
+
}
|
|
102
|
+
function collectDirectBindingNames(scope, locals) {
|
|
103
|
+
const statements = Array.isArray(scope.body) ? scope.body : [];
|
|
104
|
+
for (const statement of statements) {
|
|
105
|
+
if (!isNode(statement)) continue;
|
|
106
|
+
if (statement.type === "VariableDeclaration") {
|
|
107
|
+
const declarations = Array.isArray(statement.declarations) ? statement.declarations : [];
|
|
108
|
+
for (const declaration of declarations) if (isNode(declaration) && isNode(declaration.id)) collectPatternBindingNames(declaration.id, locals);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (statement.type === "FunctionDeclaration" || statement.type === "ClassDeclaration") {
|
|
112
|
+
const name = getNodeName(isNode(statement.id) ? statement.id : null);
|
|
113
|
+
if (name) locals.add(name);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (statement.type === "ImportDeclaration") {
|
|
117
|
+
const specifiers = Array.isArray(statement.specifiers) ? statement.specifiers : [];
|
|
118
|
+
for (const specifier of specifiers) {
|
|
119
|
+
const name = isNode(specifier) ? getNodeName(isNode(specifier.local) ? specifier.local : null) : null;
|
|
120
|
+
if (name) locals.add(name);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function findExistingUseI18nDestructure(setupBody) {
|
|
126
|
+
const statements = Array.isArray(setupBody.body) ? setupBody.body : [];
|
|
127
|
+
for (const statement of statements) {
|
|
128
|
+
if (!isNode(statement) || statement.type !== "VariableDeclaration") continue;
|
|
129
|
+
const declarations = Array.isArray(statement.declarations) ? statement.declarations : [];
|
|
130
|
+
for (const declaration of declarations) {
|
|
131
|
+
if (!isNode(declaration) || !isNode(declaration.id) || declaration.id.type !== "ObjectPattern") continue;
|
|
132
|
+
if (!isUseI18nCall(isNode(declaration.init) ? declaration.init : null)) continue;
|
|
133
|
+
const locals = /* @__PURE__ */ new Set();
|
|
134
|
+
collectPatternBindingNames(declaration.id, locals);
|
|
135
|
+
return {
|
|
136
|
+
declaration: statement,
|
|
137
|
+
pattern: declaration.id,
|
|
138
|
+
locals
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
function collectUsedI18nSpecifiers(setupBody, authoredBindings) {
|
|
145
|
+
const used = /* @__PURE__ */ new Map();
|
|
146
|
+
walkNode(setupBody, (node) => {
|
|
147
|
+
if (node.type !== "CallExpression") return;
|
|
148
|
+
const fnName = getNodeName(isNode(node.callee) ? node.callee : null);
|
|
149
|
+
const callStart = getNodeStart(node);
|
|
150
|
+
if (!fnName || callStart == null || !I18N_HELPER_LOCALS.has(fnName) || authoredBindings.has(fnName)) return;
|
|
151
|
+
if (!used.has(fnName)) used.set(fnName, callStart);
|
|
152
|
+
});
|
|
153
|
+
const helpers = Array.from(used.entries()).sort((a, b) => a[1] - b[1]);
|
|
154
|
+
return {
|
|
155
|
+
firstUseIndex: helpers[0]?.[1] ?? Number.POSITIVE_INFINITY,
|
|
156
|
+
specifiers: helpers.map(([name]) => I18N_FN_MAP[name]).filter((value) => value != null)
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function injectNuxtI18nHelpers(code, id = DEFAULT_PARSE_ID) {
|
|
160
|
+
const program = parseProgram(code, id);
|
|
161
|
+
if (!program) return code;
|
|
162
|
+
const setupBody = findSetupFunctionBody(program);
|
|
163
|
+
const setupBodyStart = setupBody ? getNodeStart(setupBody) : null;
|
|
164
|
+
if (!setupBody || setupBodyStart == null) return code;
|
|
165
|
+
const insertAt = setupBodyStart + 1;
|
|
166
|
+
const authoredBindings = /* @__PURE__ */ new Set();
|
|
167
|
+
collectDirectBindingNames(program, authoredBindings);
|
|
168
|
+
collectDirectBindingNames(setupBody, authoredBindings);
|
|
169
|
+
const { firstUseIndex, specifiers: usedSpecifiers } = collectUsedI18nSpecifiers(setupBody, authoredBindings);
|
|
170
|
+
if (usedSpecifiers.length === 0) return code;
|
|
171
|
+
const existing = findExistingUseI18nDestructure(setupBody);
|
|
172
|
+
if (existing) {
|
|
173
|
+
const missingSpecifiers = usedSpecifiers.filter((specifier) => {
|
|
174
|
+
return !existing.locals.has(getLocalAlias(specifier));
|
|
175
|
+
});
|
|
176
|
+
if (missingSpecifiers.length === 0) return code;
|
|
177
|
+
const declarationStart = getNodeStart(existing.declaration);
|
|
178
|
+
const declarationEnd = getNodeEnd(existing.declaration);
|
|
179
|
+
const patternStart = getNodeStart(existing.pattern);
|
|
180
|
+
const patternEnd = getNodeEnd(existing.pattern);
|
|
181
|
+
if (declarationStart == null || declarationEnd == null || patternStart == null || patternEnd == null) return code;
|
|
182
|
+
if (declarationStart > firstUseIndex) return code.slice(0, insertAt) + `\nconst { ${missingSpecifiers.join(", ")} } = useI18n();\n` + code.slice(insertAt);
|
|
183
|
+
const merged = code.slice(patternStart + 1, patternEnd - 1).trim();
|
|
184
|
+
const nextDestructure = merged ? `${merged}, ${missingSpecifiers.join(", ")}` : missingSpecifiers.join(", ");
|
|
185
|
+
return code.slice(0, declarationStart) + `const { ${nextDestructure} } = useI18n();` + code.slice(declarationEnd);
|
|
186
|
+
}
|
|
187
|
+
return code.slice(0, insertAt) + `\nconst { ${usedSpecifiers.join(", ")} } = useI18n();\n` + code.slice(insertAt);
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
export { injectNuxtI18nHelpers };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { i as setupLintInspector, l as setupNuxtLintChecker, m as hasNuxtViteCompilerSupport, n as setupNuxtLintConfigGeneration, p as getDetectedNuxtMajor } from "./generation-
|
|
1
|
+
import { i as setupLintInspector, l as setupNuxtLintChecker, m as hasNuxtViteCompilerSupport, n as setupNuxtLintConfigGeneration, p as getDetectedNuxtMajor } from "./generation-D16tn9Im.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import fs, { readFileSync, realpathSync } from "node:fs";
|
|
4
4
|
import path, { dirname, join, resolve } from "node:path";
|
|
5
|
-
import { parseSync } from "vite";
|
|
6
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
7
6
|
import { createHash } from "node:crypto";
|
|
8
7
|
//#region src/component-imports.ts
|
|
@@ -339,194 +338,6 @@ function createNuxtComponentResolver(options) {
|
|
|
339
338
|
};
|
|
340
339
|
}
|
|
341
340
|
//#endregion
|
|
342
|
-
//#region src/i18n.ts
|
|
343
|
-
const I18N_FN_MAP = {
|
|
344
|
-
$t: "t: $t",
|
|
345
|
-
$rt: "rt: $rt",
|
|
346
|
-
$d: "d: $d",
|
|
347
|
-
$n: "n: $n",
|
|
348
|
-
$tm: "tm: $tm",
|
|
349
|
-
$te: "te: $te"
|
|
350
|
-
};
|
|
351
|
-
const I18N_HELPER_LOCALS = new Set(Object.keys(I18N_FN_MAP));
|
|
352
|
-
const DEFAULT_PARSE_ID = "vize-nuxt-i18n-bridge.tsx";
|
|
353
|
-
function getLocalAlias(specifier) {
|
|
354
|
-
const colon = specifier.indexOf(":");
|
|
355
|
-
return (colon === -1 ? specifier : specifier.slice(colon + 1)).trim();
|
|
356
|
-
}
|
|
357
|
-
function isNode(value) {
|
|
358
|
-
return value != null && typeof value === "object" && typeof value.type === "string";
|
|
359
|
-
}
|
|
360
|
-
function getNodeStart(node) {
|
|
361
|
-
return typeof node.start === "number" ? node.start : null;
|
|
362
|
-
}
|
|
363
|
-
function getNodeEnd(node) {
|
|
364
|
-
return typeof node.end === "number" ? node.end : null;
|
|
365
|
-
}
|
|
366
|
-
function getNodeName(node) {
|
|
367
|
-
return isNode(node) && typeof node.name === "string" ? node.name : null;
|
|
368
|
-
}
|
|
369
|
-
function getChildNodes(node) {
|
|
370
|
-
const children = [];
|
|
371
|
-
for (const [key, value] of Object.entries(node)) {
|
|
372
|
-
if (key === "parent") continue;
|
|
373
|
-
if (Array.isArray(value)) {
|
|
374
|
-
for (const item of value) if (isNode(item)) children.push(item);
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
if (isNode(value)) children.push(value);
|
|
378
|
-
}
|
|
379
|
-
return children;
|
|
380
|
-
}
|
|
381
|
-
function walkNode(node, visit) {
|
|
382
|
-
visit(node);
|
|
383
|
-
for (const child of getChildNodes(node)) walkNode(child, visit);
|
|
384
|
-
}
|
|
385
|
-
function parseProgram(code, id) {
|
|
386
|
-
try {
|
|
387
|
-
const result = parseSync(normalizeParseId(id), code);
|
|
388
|
-
if (isNode(result)) return result;
|
|
389
|
-
if (result != null && typeof result === "object") {
|
|
390
|
-
const program = result.program;
|
|
391
|
-
if (isNode(program)) return program;
|
|
392
|
-
}
|
|
393
|
-
return null;
|
|
394
|
-
} catch {
|
|
395
|
-
return null;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
function normalizeParseId(id) {
|
|
399
|
-
return (id.startsWith("\0") ? id.slice(1) : id).split(/[?#]/, 1)[0] || DEFAULT_PARSE_ID;
|
|
400
|
-
}
|
|
401
|
-
function isSetupFunction(node) {
|
|
402
|
-
if (node.type !== "Property") return false;
|
|
403
|
-
const key = isNode(node.key) ? node.key : null;
|
|
404
|
-
const value = isNode(node.value) ? node.value : null;
|
|
405
|
-
if (getNodeName(key) !== "setup" || !value) return false;
|
|
406
|
-
if (value.type !== "FunctionExpression" && value.type !== "ArrowFunctionExpression") return false;
|
|
407
|
-
return getNodeName((Array.isArray(value.params) ? value.params : [])[0]) === "__props";
|
|
408
|
-
}
|
|
409
|
-
function findSetupFunctionBody(program) {
|
|
410
|
-
let setupBody = null;
|
|
411
|
-
walkNode(program, (node) => {
|
|
412
|
-
if (setupBody || !isSetupFunction(node)) return;
|
|
413
|
-
const value = isNode(node.value) ? node.value : null;
|
|
414
|
-
const body = value && isNode(value.body) ? value.body : null;
|
|
415
|
-
if (body?.type === "BlockStatement") setupBody = body;
|
|
416
|
-
});
|
|
417
|
-
return setupBody;
|
|
418
|
-
}
|
|
419
|
-
function isUseI18nCall(node) {
|
|
420
|
-
if (!isNode(node) || node.type !== "CallExpression") return false;
|
|
421
|
-
return getNodeName(isNode(node.callee) ? node.callee : null) === "useI18n";
|
|
422
|
-
}
|
|
423
|
-
function collectPatternBindingNames(pattern, locals) {
|
|
424
|
-
if (pattern.type === "Identifier" && typeof pattern.name === "string") {
|
|
425
|
-
locals.add(pattern.name);
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
if (pattern.type === "AssignmentPattern" && isNode(pattern.left)) {
|
|
429
|
-
collectPatternBindingNames(pattern.left, locals);
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
if (pattern.type === "RestElement" && isNode(pattern.argument)) {
|
|
433
|
-
collectPatternBindingNames(pattern.argument, locals);
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
if (pattern.type === "Property" && isNode(pattern.value)) {
|
|
437
|
-
collectPatternBindingNames(pattern.value, locals);
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
for (const child of getChildNodes(pattern)) collectPatternBindingNames(child, locals);
|
|
441
|
-
}
|
|
442
|
-
function collectDirectBindingNames(scope, locals) {
|
|
443
|
-
const statements = Array.isArray(scope.body) ? scope.body : [];
|
|
444
|
-
for (const statement of statements) {
|
|
445
|
-
if (!isNode(statement)) continue;
|
|
446
|
-
if (statement.type === "VariableDeclaration") {
|
|
447
|
-
const declarations = Array.isArray(statement.declarations) ? statement.declarations : [];
|
|
448
|
-
for (const declaration of declarations) if (isNode(declaration) && isNode(declaration.id)) collectPatternBindingNames(declaration.id, locals);
|
|
449
|
-
continue;
|
|
450
|
-
}
|
|
451
|
-
if (statement.type === "FunctionDeclaration" || statement.type === "ClassDeclaration") {
|
|
452
|
-
const name = getNodeName(isNode(statement.id) ? statement.id : null);
|
|
453
|
-
if (name) locals.add(name);
|
|
454
|
-
continue;
|
|
455
|
-
}
|
|
456
|
-
if (statement.type === "ImportDeclaration") {
|
|
457
|
-
const specifiers = Array.isArray(statement.specifiers) ? statement.specifiers : [];
|
|
458
|
-
for (const specifier of specifiers) {
|
|
459
|
-
const name = isNode(specifier) ? getNodeName(isNode(specifier.local) ? specifier.local : null) : null;
|
|
460
|
-
if (name) locals.add(name);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
function findExistingUseI18nDestructure(setupBody) {
|
|
466
|
-
const statements = Array.isArray(setupBody.body) ? setupBody.body : [];
|
|
467
|
-
for (const statement of statements) {
|
|
468
|
-
if (!isNode(statement) || statement.type !== "VariableDeclaration") continue;
|
|
469
|
-
const declarations = Array.isArray(statement.declarations) ? statement.declarations : [];
|
|
470
|
-
for (const declaration of declarations) {
|
|
471
|
-
if (!isNode(declaration) || !isNode(declaration.id) || declaration.id.type !== "ObjectPattern") continue;
|
|
472
|
-
if (!isUseI18nCall(isNode(declaration.init) ? declaration.init : null)) continue;
|
|
473
|
-
const locals = /* @__PURE__ */ new Set();
|
|
474
|
-
collectPatternBindingNames(declaration.id, locals);
|
|
475
|
-
return {
|
|
476
|
-
declaration: statement,
|
|
477
|
-
pattern: declaration.id,
|
|
478
|
-
locals
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return null;
|
|
483
|
-
}
|
|
484
|
-
function collectUsedI18nSpecifiers(setupBody, authoredBindings) {
|
|
485
|
-
const used = /* @__PURE__ */ new Map();
|
|
486
|
-
walkNode(setupBody, (node) => {
|
|
487
|
-
if (node.type !== "CallExpression") return;
|
|
488
|
-
const fnName = getNodeName(isNode(node.callee) ? node.callee : null);
|
|
489
|
-
const callStart = getNodeStart(node);
|
|
490
|
-
if (!fnName || callStart == null || !I18N_HELPER_LOCALS.has(fnName) || authoredBindings.has(fnName)) return;
|
|
491
|
-
if (!used.has(fnName)) used.set(fnName, callStart);
|
|
492
|
-
});
|
|
493
|
-
const helpers = Array.from(used.entries()).sort((a, b) => a[1] - b[1]);
|
|
494
|
-
return {
|
|
495
|
-
firstUseIndex: helpers[0]?.[1] ?? Number.POSITIVE_INFINITY,
|
|
496
|
-
specifiers: helpers.map(([name]) => I18N_FN_MAP[name]).filter((value) => value != null)
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
function injectNuxtI18nHelpers(code, id = DEFAULT_PARSE_ID) {
|
|
500
|
-
const program = parseProgram(code, id);
|
|
501
|
-
if (!program) return code;
|
|
502
|
-
const setupBody = findSetupFunctionBody(program);
|
|
503
|
-
const setupBodyStart = setupBody ? getNodeStart(setupBody) : null;
|
|
504
|
-
if (!setupBody || setupBodyStart == null) return code;
|
|
505
|
-
const insertAt = setupBodyStart + 1;
|
|
506
|
-
const authoredBindings = /* @__PURE__ */ new Set();
|
|
507
|
-
collectDirectBindingNames(program, authoredBindings);
|
|
508
|
-
collectDirectBindingNames(setupBody, authoredBindings);
|
|
509
|
-
const { firstUseIndex, specifiers: usedSpecifiers } = collectUsedI18nSpecifiers(setupBody, authoredBindings);
|
|
510
|
-
if (usedSpecifiers.length === 0) return code;
|
|
511
|
-
const existing = findExistingUseI18nDestructure(setupBody);
|
|
512
|
-
if (existing) {
|
|
513
|
-
const missingSpecifiers = usedSpecifiers.filter((specifier) => {
|
|
514
|
-
return !existing.locals.has(getLocalAlias(specifier));
|
|
515
|
-
});
|
|
516
|
-
if (missingSpecifiers.length === 0) return code;
|
|
517
|
-
const declarationStart = getNodeStart(existing.declaration);
|
|
518
|
-
const declarationEnd = getNodeEnd(existing.declaration);
|
|
519
|
-
const patternStart = getNodeStart(existing.pattern);
|
|
520
|
-
const patternEnd = getNodeEnd(existing.pattern);
|
|
521
|
-
if (declarationStart == null || declarationEnd == null || patternStart == null || patternEnd == null) return code;
|
|
522
|
-
if (declarationStart > firstUseIndex) return code.slice(0, insertAt) + `\nconst { ${missingSpecifiers.join(", ")} } = useI18n();\n` + code.slice(insertAt);
|
|
523
|
-
const merged = code.slice(patternStart + 1, patternEnd - 1).trim();
|
|
524
|
-
const nextDestructure = merged ? `${merged}, ${missingSpecifiers.join(", ")}` : missingSpecifiers.join(", ");
|
|
525
|
-
return code.slice(0, declarationStart) + `const { ${nextDestructure} } = useI18n();` + code.slice(declarationEnd);
|
|
526
|
-
}
|
|
527
|
-
return code.slice(0, insertAt) + `\nconst { ${usedSpecifiers.join(", ")} } = useI18n();\n` + code.slice(insertAt);
|
|
528
|
-
}
|
|
529
|
-
//#endregion
|
|
530
341
|
//#region src/musea-components.ts
|
|
531
342
|
const MUSEA_ART_COMPONENT_IGNORE = "**/*.art.vue";
|
|
532
343
|
function appendMuseaArtComponentIgnore(dirs) {
|
|
@@ -1654,6 +1465,7 @@ async function setupVizeNuxtModule(options, nuxt) {
|
|
|
1654
1465
|
}
|
|
1655
1466
|
}
|
|
1656
1467
|
if (bridgeOptions.i18n && hasI18nBridgeInput(result)) {
|
|
1468
|
+
const { injectNuxtI18nHelpers } = await import("./i18n-CPEBELnL.mjs");
|
|
1657
1469
|
const nextResult = injectNuxtI18nHelpers(result, id);
|
|
1658
1470
|
if (nextResult !== result) {
|
|
1659
1471
|
result = nextResult;
|
package/dist/lint/index.d.mts
CHANGED
|
@@ -173,9 +173,13 @@ declare function createNuxtLintCheckerWebpackPlugin(config: NuxtLintCheckerWebpa
|
|
|
173
173
|
//#endregion
|
|
174
174
|
//#region src/lint/checker/setup.d.ts
|
|
175
175
|
interface NuxtLintCheckerNuxt {
|
|
176
|
+
hook?(name: string, callback: (...args: unknown[]) => unknown): void;
|
|
176
177
|
options: {
|
|
177
178
|
buildDir: string;
|
|
178
179
|
builder?: unknown;
|
|
180
|
+
bridge?: false | {
|
|
181
|
+
vite?: boolean;
|
|
182
|
+
};
|
|
179
183
|
dev?: boolean;
|
|
180
184
|
rootDir: string;
|
|
181
185
|
srcDir?: string;
|
package/dist/lint/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as toNuxtLintProjectState, c as setupNuxtLintConfigAddons, d as createNuxtLintCheckerVitePlugin, f as resolveNuxtLintCheckerOptions, l as setupNuxtLintChecker, n as setupNuxtLintConfigGeneration, o as renderNuxtOxlintConfig, r as writeFileIfChanged, s as VIZE_NUXT_LINT_CONFIG_ADDONS_HOOK, t as ROOT_OXLINT_CONFIG_NAMES, u as createNuxtLintCheckerWebpackPlugin } from "../generation-
|
|
1
|
+
import { a as toNuxtLintProjectState, c as setupNuxtLintConfigAddons, d as createNuxtLintCheckerVitePlugin, f as resolveNuxtLintCheckerOptions, l as setupNuxtLintChecker, n as setupNuxtLintConfigGeneration, o as renderNuxtOxlintConfig, r as writeFileIfChanged, s as VIZE_NUXT_LINT_CONFIG_ADDONS_HOOK, t as ROOT_OXLINT_CONFIG_NAMES, u as createNuxtLintCheckerWebpackPlugin } from "../generation-D16tn9Im.mjs";
|
|
2
2
|
export * from "@vizejs/nuxt-lint-config";
|
|
3
3
|
export { ROOT_OXLINT_CONFIG_NAMES, VIZE_NUXT_LINT_CONFIG_ADDONS_HOOK, createNuxtLintCheckerVitePlugin, createNuxtLintCheckerWebpackPlugin, renderNuxtOxlintConfig, resolveNuxtLintCheckerOptions, setupNuxtLintChecker, setupNuxtLintConfigAddons, setupNuxtLintConfigGeneration, toNuxtLintProjectState, writeFileIfChanged };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vizejs/nuxt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.573.0",
|
|
4
4
|
"description": "Nuxt module for Vize - compiler, musea gallery, linter, and type checker",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiler",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@nuxt/kit": "3.11.2",
|
|
52
|
-
"@vizejs/native": "0.
|
|
53
|
-
"@vizejs/nuxt-lint-config": "0.
|
|
54
|
-
"@vizejs/vite-plugin": "0.
|
|
55
|
-
"@vizejs/vite-plugin-musea": "0.
|
|
56
|
-
"oxlint-plugin-vize": "0.
|
|
57
|
-
"vize": "0.
|
|
52
|
+
"@vizejs/native": "0.573.0",
|
|
53
|
+
"@vizejs/nuxt-lint-config": "0.573.0",
|
|
54
|
+
"@vizejs/vite-plugin": "0.573.0",
|
|
55
|
+
"@vizejs/vite-plugin-musea": "0.573.0",
|
|
56
|
+
"oxlint-plugin-vize": "0.573.0",
|
|
57
|
+
"vize": "0.573.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"jiti-nuxt2": "npm:jiti@1.21.7",
|