@intlify/unplugin-vue-i18n 12.0.0-alpha.0 → 12.0.0-alpha.1
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/README.md +5 -0
- package/lib/index.cjs +52 -368
- package/lib/index.mjs +52 -366
- package/lib/rspack.cjs +3 -7
- package/lib/rspack.mjs +3 -7
- package/lib/types.d.cts +0 -1
- package/lib/types.d.mts +0 -1
- package/lib/types.d.ts +0 -1
- package/lib/vite.cjs +3 -7
- package/lib/vite.mjs +3 -7
- package/lib/webpack.cjs +3 -7
- package/lib/webpack.mjs +3 -7
- package/package.json +5 -9
package/README.md
CHANGED
|
@@ -661,6 +661,11 @@ If do you will use this option, you need to enable `jitCompilation` option.
|
|
|
661
661
|
|
|
662
662
|
If you want to put it manually, you can specify the signature of the translation function as a string or a string array.
|
|
663
663
|
|
|
664
|
+
> [!IMPORTANT]
|
|
665
|
+
>
|
|
666
|
+
> `optimizeTranslationDirective` option is deprecated in v12, because `v-t` custom directive will be dropped in vue-i18n v12
|
|
667
|
+
> This option will be supported with unplugin-vue-i18n v6.x (vue-i18n until v11)
|
|
668
|
+
|
|
664
669
|
> [!WARNING]
|
|
665
670
|
> About for manually signature, see the details [vue-i18n-extensions API docs](https://github.com/intlify/vue-i18n-extensions/blob/next/docs/%40intlify/vue-i18n-extensions-api.md#translationsignatures) and [usecase from vue-i18n-extensions PR](https://github.com/intlify/vue-i18n-extensions/pull/217/files#diff-3fb9543f91e011d4b0dc9beff44082fe1a99c9eab70c1afab23c3c34352b7c38R121-R200)
|
|
666
671
|
|
package/lib/index.cjs
CHANGED
|
@@ -4,15 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const createDebug = require('debug');
|
|
6
6
|
const unplugin$1 = require('unplugin');
|
|
7
|
-
const shared = require('@intlify/shared');
|
|
8
|
-
const vueI18nExtensions = require('@intlify/vue-i18n-extensions');
|
|
9
|
-
const scopeManager = require('@typescript-eslint/scope-manager');
|
|
10
|
-
const typescriptEstree = require('@typescript-eslint/typescript-estree');
|
|
11
|
-
const path = require('node:path');
|
|
12
|
-
const eslintUitls = require('@eslint-community/eslint-utils');
|
|
13
|
-
const pc = require('picocolors');
|
|
14
7
|
const defu = require('defu');
|
|
8
|
+
const node_path = require('node:path');
|
|
15
9
|
const bundleUtils = require('@intlify/bundle-utils');
|
|
10
|
+
const shared = require('@intlify/shared');
|
|
16
11
|
const pluginutils = require('@rollup/pluginutils');
|
|
17
12
|
const fg = require('fast-glob');
|
|
18
13
|
const knitwork = require('knitwork');
|
|
@@ -20,16 +15,60 @@ const mlly = require('mlly');
|
|
|
20
15
|
const node_crypto = require('node:crypto');
|
|
21
16
|
const fs = require('node:fs');
|
|
22
17
|
const compilerSfc = require('vue/compiler-sfc');
|
|
18
|
+
const pc = require('picocolors');
|
|
23
19
|
|
|
24
20
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
25
21
|
|
|
26
22
|
const createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
|
|
27
|
-
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
28
|
-
const eslintUitls__default = /*#__PURE__*/_interopDefaultCompat(eslintUitls);
|
|
29
|
-
const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
|
|
30
23
|
const defu__default = /*#__PURE__*/_interopDefaultCompat(defu);
|
|
31
24
|
const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
|
|
32
25
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
26
|
+
const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
|
|
27
|
+
|
|
28
|
+
function toArray(value) {
|
|
29
|
+
return Array.isArray(value) ? value : [value];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const getVueI18nAliasPath = (opts) => {
|
|
33
|
+
const filename = [
|
|
34
|
+
opts.module,
|
|
35
|
+
opts.runtimeOnly ? "runtime" : "",
|
|
36
|
+
!opts.ssr ? "esm-bundler" : "node",
|
|
37
|
+
"js"
|
|
38
|
+
].filter(Boolean).join(".");
|
|
39
|
+
return `${opts.module}/dist/${filename}`;
|
|
40
|
+
};
|
|
41
|
+
function resolveOptions(options) {
|
|
42
|
+
const res = defu__default(options, {
|
|
43
|
+
ssr: false,
|
|
44
|
+
module: "vue-i18n",
|
|
45
|
+
escapeHtml: false,
|
|
46
|
+
onlyLocales: [],
|
|
47
|
+
fullInstall: true,
|
|
48
|
+
runtimeOnly: true,
|
|
49
|
+
strictMessage: true,
|
|
50
|
+
allowDynamic: false,
|
|
51
|
+
globalSFCScope: false,
|
|
52
|
+
forceStringify: false,
|
|
53
|
+
defaultSFCLang: "json",
|
|
54
|
+
dropMessageCompiler: false,
|
|
55
|
+
transformI18nBlock: void 0
|
|
56
|
+
});
|
|
57
|
+
const include = res.include ? toArray(res.include).map((item) => node_path.normalize(item)) : void 0;
|
|
58
|
+
const _exclude = res.exclude ? toArray(res.exclude).map((item) => node_path.normalize(item)) : void 0;
|
|
59
|
+
const exclude = res.include ? _exclude : ["**/**"];
|
|
60
|
+
const onlyLocales = toArray(res.onlyLocales);
|
|
61
|
+
const fullInstall = res.module !== "vue-i18n" ? false : res.fullInstall;
|
|
62
|
+
const vueI18nAliasPath = getVueI18nAliasPath(res);
|
|
63
|
+
return {
|
|
64
|
+
...res,
|
|
65
|
+
include,
|
|
66
|
+
exclude,
|
|
67
|
+
fullInstall,
|
|
68
|
+
onlyLocales,
|
|
69
|
+
vueI18nAliasPath
|
|
70
|
+
};
|
|
71
|
+
}
|
|
33
72
|
|
|
34
73
|
const PKG_NAME = "unplugin-vue-i18n";
|
|
35
74
|
|
|
@@ -58,29 +97,6 @@ function checkVuePlugin(vuePlugin) {
|
|
|
58
97
|
}
|
|
59
98
|
return true;
|
|
60
99
|
}
|
|
61
|
-
const isWindows = typeof process !== "undefined" && process.platform === "win32";
|
|
62
|
-
const windowsSlashRE = /\\/g;
|
|
63
|
-
function slash(p) {
|
|
64
|
-
return p.replace(windowsSlashRE, "/");
|
|
65
|
-
}
|
|
66
|
-
function normalizePath(id) {
|
|
67
|
-
return path__default.posix.normalize(isWindows ? slash(id) : id);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function createDescriptor(filename, source, { template, compiler }) {
|
|
71
|
-
const { descriptor, errors } = compiler.parse(source, {
|
|
72
|
-
filename,
|
|
73
|
-
templateParseOptions: template?.compilerOptions
|
|
74
|
-
});
|
|
75
|
-
return { descriptor, errors };
|
|
76
|
-
}
|
|
77
|
-
function getDescriptor(filename, code, options) {
|
|
78
|
-
const { descriptor, errors } = createDescriptor(filename, code, options);
|
|
79
|
-
if (errors.length) {
|
|
80
|
-
throw errors[0];
|
|
81
|
-
}
|
|
82
|
-
return descriptor;
|
|
83
|
-
}
|
|
84
100
|
|
|
85
101
|
function parseVueRequest(id) {
|
|
86
102
|
const [filename, rawQuery] = id.split(`?`, 2);
|
|
@@ -121,329 +137,6 @@ function parseVueRequest(id) {
|
|
|
121
137
|
function getVueCompiler(vuePlugin) {
|
|
122
138
|
return vuePlugin?.api?.options.compiler;
|
|
123
139
|
}
|
|
124
|
-
function getVuePluginOptions(vuePlugin) {
|
|
125
|
-
return {
|
|
126
|
-
isProduction: vuePlugin?.api?.options.isProduction,
|
|
127
|
-
root: vuePlugin?.api?.options.root,
|
|
128
|
-
template: vuePlugin?.api?.options.template,
|
|
129
|
-
compiler: vuePlugin?.api?.options.compiler
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const debug$2 = createDebug__default(resolveNamespace("directive"));
|
|
134
|
-
function directivePlugin({
|
|
135
|
-
optimizeTranslationDirective,
|
|
136
|
-
translationIdentifiers
|
|
137
|
-
}) {
|
|
138
|
-
let vuePlugin = null;
|
|
139
|
-
let vuePluginOptions = null;
|
|
140
|
-
const excludeLangs = ["pug", "jsx", "tsx"];
|
|
141
|
-
return {
|
|
142
|
-
name: resolveNamespace("directive"),
|
|
143
|
-
enforce: "pre",
|
|
144
|
-
vite: {
|
|
145
|
-
config(config) {
|
|
146
|
-
vuePlugin = getVitePlugin(config, "vite:vue");
|
|
147
|
-
if (!checkVuePlugin(vuePlugin)) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
if (optimizeTranslationDirective) {
|
|
151
|
-
vuePlugin.api.options = resolveVueOptions(
|
|
152
|
-
vuePlugin,
|
|
153
|
-
optimizeTranslationDirective,
|
|
154
|
-
translationIdentifiers
|
|
155
|
-
);
|
|
156
|
-
debug$2(`vite:vue options['template']:`, vuePlugin.api.options);
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
configResolved(config) {
|
|
160
|
-
vuePlugin = getVitePlugin(config, "vite:vue");
|
|
161
|
-
if (!checkVuePlugin(vuePlugin)) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
async transform(code, id) {
|
|
167
|
-
if (id.endsWith(".vue")) {
|
|
168
|
-
const { filename, query } = parseVueRequest(id);
|
|
169
|
-
if (!excludeLangs.includes(query.lang ?? "")) {
|
|
170
|
-
if (vuePluginOptions == null) {
|
|
171
|
-
vuePluginOptions = getVuePluginOptions(vuePlugin);
|
|
172
|
-
}
|
|
173
|
-
if (vuePluginOptions?.compiler) {
|
|
174
|
-
analyzeIdentifiers(
|
|
175
|
-
getDescriptor(filename, code, vuePluginOptions),
|
|
176
|
-
vuePluginOptions,
|
|
177
|
-
translationIdentifiers
|
|
178
|
-
);
|
|
179
|
-
return {
|
|
180
|
-
code,
|
|
181
|
-
map: { version: 3, mappings: "", sources: [] }
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function resolveVueOptions(vuePlugin, optimizeTranslationDirective, translationIdentifiers) {
|
|
190
|
-
var _a, _b;
|
|
191
|
-
const vueOptions = vuePlugin.api.options;
|
|
192
|
-
vueOptions.template || (vueOptions.template = {});
|
|
193
|
-
(_a = vueOptions.template).compilerOptions || (_a.compilerOptions = {});
|
|
194
|
-
(_b = vueOptions.template.compilerOptions).directiveTransforms || (_b.directiveTransforms = {});
|
|
195
|
-
const translationSignatureResolver = (context, baseResolver) => {
|
|
196
|
-
const { filename } = context;
|
|
197
|
-
const vuePluginOptions = getVuePluginOptions(vuePlugin);
|
|
198
|
-
const normalizedFilename = normalizePath(path__default.relative(vuePluginOptions.root, filename));
|
|
199
|
-
const resolveIdentifier2 = translationIdentifiers.get(normalizedFilename);
|
|
200
|
-
debug$2("resolved vue-i18n Identifier", resolveIdentifier2);
|
|
201
|
-
if (resolveIdentifier2 == null) {
|
|
202
|
-
return void 0;
|
|
203
|
-
}
|
|
204
|
-
if (resolveIdentifier2.type === "identifier") {
|
|
205
|
-
return baseResolver(context, resolveIdentifier2.key);
|
|
206
|
-
} else {
|
|
207
|
-
const resolvedSignature = baseResolver(context, resolveIdentifier2.key);
|
|
208
|
-
return resolveIdentifier2?.style === "script-setup" ? `${resolvedSignature}.t` : resolvedSignature;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
vueOptions.template.compilerOptions.directiveTransforms.t = vueI18nExtensions.transformVTDirective({
|
|
212
|
-
translationSignatures: shared.isBoolean(optimizeTranslationDirective) ? translationSignatureResolver : optimizeTranslationDirective
|
|
213
|
-
});
|
|
214
|
-
return vueOptions;
|
|
215
|
-
}
|
|
216
|
-
function analyzeIdentifiers(descriptor, { root }, translationIdentifiers) {
|
|
217
|
-
const source = descriptor.scriptSetup?.content || descriptor.script?.content;
|
|
218
|
-
debug$2("getDescriptor content", source);
|
|
219
|
-
if (!source) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
const ast = typescriptEstree.parse(source, { range: true });
|
|
223
|
-
typescriptEstree.simpleTraverse(ast, {
|
|
224
|
-
enter(node, parent) {
|
|
225
|
-
if (parent) {
|
|
226
|
-
node.parent = parent;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
const scopeManager$1 = scopeManager.analyze(ast, { sourceType: "module" });
|
|
231
|
-
const scope = getScope(scopeManager$1, ast);
|
|
232
|
-
const importLocalName = getImportLocalName(scope, "vue-i18n", "useI18n");
|
|
233
|
-
if (importLocalName == null) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
debug$2("importLocalName", importLocalName);
|
|
237
|
-
const resolvedIdentifier = getVueI18nIdentifier(scope, importLocalName);
|
|
238
|
-
if (resolvedIdentifier) {
|
|
239
|
-
const normalizedFilename = normalizePath(path__default.relative(root, descriptor.filename));
|
|
240
|
-
debug$2("set vue-i18n resolved identifier: ", resolvedIdentifier);
|
|
241
|
-
translationIdentifiers.set(normalizedFilename, resolvedIdentifier);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
function getScope(manager, node) {
|
|
245
|
-
const scope = manager.acquire(node, true);
|
|
246
|
-
if (scope) {
|
|
247
|
-
if (scope.type === "function-expression-name") {
|
|
248
|
-
return scope.childScopes[0];
|
|
249
|
-
}
|
|
250
|
-
return scope;
|
|
251
|
-
}
|
|
252
|
-
return manager.scopes[0];
|
|
253
|
-
}
|
|
254
|
-
function getImportLocalName(scope, source, imported) {
|
|
255
|
-
const importDecl = getImportDeclaration(scope, source);
|
|
256
|
-
if (importDecl) {
|
|
257
|
-
const specifierNode = importDecl.specifiers.find(
|
|
258
|
-
(specifierNode2) => isImportedIdentifierInImportClause(specifierNode2) && specifierNode2.imported.name === imported
|
|
259
|
-
);
|
|
260
|
-
return specifierNode ? specifierNode.local.name : null;
|
|
261
|
-
}
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
function getImportDeclaration(scope, source) {
|
|
265
|
-
const tracker = new eslintUitls__default.ReferenceTracker(scope);
|
|
266
|
-
const traceMap = {
|
|
267
|
-
[source]: {
|
|
268
|
-
[eslintUitls__default.ReferenceTracker.ESM]: true,
|
|
269
|
-
[eslintUitls__default.ReferenceTracker.READ]: true
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
const refs = Array.from(tracker.iterateEsmReferences(traceMap));
|
|
273
|
-
return refs.length ? refs[0].node : null;
|
|
274
|
-
}
|
|
275
|
-
function isImportedIdentifierInImportClause(node) {
|
|
276
|
-
return "imported" in node;
|
|
277
|
-
}
|
|
278
|
-
function getVueI18nIdentifier(scope, local) {
|
|
279
|
-
const { callExpression, returnStatement } = getCallExpressionAndReturnStatement(scope, local);
|
|
280
|
-
if (callExpression == null) {
|
|
281
|
-
return null;
|
|
282
|
-
}
|
|
283
|
-
const id = getVariableDeclarationIdFrom(callExpression);
|
|
284
|
-
if (id == null) {
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
const variableIdPairs = parseVariableId(id);
|
|
288
|
-
debug$2("variableIdPairs:", variableIdPairs);
|
|
289
|
-
const returnVariableIdPairs = parseReturnStatement(returnStatement);
|
|
290
|
-
debug$2("returnVariableIdPairs:", returnVariableIdPairs);
|
|
291
|
-
return resolveIdentifier(variableIdPairs, returnVariableIdPairs);
|
|
292
|
-
}
|
|
293
|
-
const EMPTY_NODE_RETURN = {
|
|
294
|
-
callExpression: null,
|
|
295
|
-
returnStatement: null
|
|
296
|
-
};
|
|
297
|
-
function getCallExpressionAndReturnStatement(scope, local) {
|
|
298
|
-
const variable = eslintUitls__default.findVariable(scope, local);
|
|
299
|
-
if (variable == null) {
|
|
300
|
-
return EMPTY_NODE_RETURN;
|
|
301
|
-
}
|
|
302
|
-
const callExpressionRef = variable.references.find((ref) => {
|
|
303
|
-
return ref.identifier.parent?.type === typescriptEstree.AST_NODE_TYPES.CallExpression;
|
|
304
|
-
});
|
|
305
|
-
if (callExpressionRef == null) {
|
|
306
|
-
return EMPTY_NODE_RETURN;
|
|
307
|
-
}
|
|
308
|
-
let returnStatement = null;
|
|
309
|
-
if (callExpressionRef.from.type === "function" && callExpressionRef.from.block.type === typescriptEstree.AST_NODE_TYPES.FunctionExpression && callExpressionRef.from.block.parent.type === typescriptEstree.AST_NODE_TYPES.Property && callExpressionRef.from.block.parent.key.type === typescriptEstree.AST_NODE_TYPES.Identifier && callExpressionRef.from.block.parent.key.name === "setup") {
|
|
310
|
-
returnStatement = callExpressionRef.from.block.body.body.find((statement) => {
|
|
311
|
-
return statement.type === typescriptEstree.AST_NODE_TYPES.ReturnStatement;
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
callExpression: callExpressionRef.identifier.parent,
|
|
316
|
-
returnStatement
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function getVariableDeclarationIdFrom(node) {
|
|
320
|
-
if (node.parent?.type !== typescriptEstree.AST_NODE_TYPES.VariableDeclarator) {
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
return node.parent.id;
|
|
324
|
-
}
|
|
325
|
-
function parseVariableId(node) {
|
|
326
|
-
if (node.type === typescriptEstree.AST_NODE_TYPES.Identifier) {
|
|
327
|
-
return [{ key: node.name, value: null }];
|
|
328
|
-
} else {
|
|
329
|
-
const props = node.properties.filter(
|
|
330
|
-
// ignore RestElement
|
|
331
|
-
(prop) => prop.type === typescriptEstree.AST_NODE_TYPES.Property
|
|
332
|
-
);
|
|
333
|
-
const pairs = [];
|
|
334
|
-
for (const prop of props) {
|
|
335
|
-
if (prop?.key.type === typescriptEstree.AST_NODE_TYPES.Identifier && prop?.value.type === typescriptEstree.AST_NODE_TYPES.Identifier) {
|
|
336
|
-
pairs.push({ key: prop.key.name, value: prop.value.name });
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
return pairs;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
function parseReturnStatement(node) {
|
|
343
|
-
const pairs = [];
|
|
344
|
-
if (node == null || node.argument == null) {
|
|
345
|
-
return pairs;
|
|
346
|
-
}
|
|
347
|
-
if (node.argument.type === typescriptEstree.AST_NODE_TYPES.ObjectExpression) {
|
|
348
|
-
for (const prop of node.argument.properties) {
|
|
349
|
-
if (prop.type === typescriptEstree.AST_NODE_TYPES.Property) {
|
|
350
|
-
if (prop.key.type === typescriptEstree.AST_NODE_TYPES.Identifier && prop.value.type === typescriptEstree.AST_NODE_TYPES.Identifier) {
|
|
351
|
-
pairs.push({ key: prop.key.name, value: prop.value.name });
|
|
352
|
-
} else if (prop.key.type === typescriptEstree.AST_NODE_TYPES.Identifier && prop.value.type === typescriptEstree.AST_NODE_TYPES.MemberExpression && prop.value.object.type === typescriptEstree.AST_NODE_TYPES.Identifier && prop.value.property.type === typescriptEstree.AST_NODE_TYPES.Identifier) {
|
|
353
|
-
pairs.push({
|
|
354
|
-
key: prop.key.name,
|
|
355
|
-
value: `${prop.value.object.name}.${prop.value.property.name}`
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return pairs;
|
|
361
|
-
} else if (node.argument.type === typescriptEstree.AST_NODE_TYPES.Identifier) {
|
|
362
|
-
return pairs;
|
|
363
|
-
} else {
|
|
364
|
-
return pairs;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
function resolveIdentifier(localVariables, returnVariable) {
|
|
368
|
-
if (returnVariable.length === 0) {
|
|
369
|
-
const variable = localVariables.find((pair) => pair.key === "t");
|
|
370
|
-
if (variable && variable.value) {
|
|
371
|
-
return { type: "identifier", key: variable.value };
|
|
372
|
-
}
|
|
373
|
-
const identifierOnly = localVariables.find((pair) => pair.value === null);
|
|
374
|
-
if (identifierOnly && identifierOnly.key) {
|
|
375
|
-
return { type: "object", key: identifierOnly.key, style: "script-setup" };
|
|
376
|
-
}
|
|
377
|
-
return null;
|
|
378
|
-
} else {
|
|
379
|
-
const variable = localVariables.find((pair) => pair.key === "t");
|
|
380
|
-
if (variable && variable.value) {
|
|
381
|
-
const returnVar = returnVariable.find((pair) => pair.value === variable.value);
|
|
382
|
-
if (returnVar && returnVar.key) {
|
|
383
|
-
return { type: "identifier", key: returnVar.key };
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
const identifierOnly = localVariables.find((pair) => pair.value === null);
|
|
387
|
-
if (identifierOnly && identifierOnly.key) {
|
|
388
|
-
const targetKey = identifierOnly.key;
|
|
389
|
-
const returnVar = returnVariable.find((pair) => pair.value?.startsWith(targetKey));
|
|
390
|
-
if (returnVar && returnVar.key) {
|
|
391
|
-
return { type: "object", key: returnVar.key, style: "setup-hook" };
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
return null;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function toArray(value) {
|
|
399
|
-
return Array.isArray(value) ? value : [value];
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const getVueI18nAliasPath = (opts) => {
|
|
403
|
-
const filename = [
|
|
404
|
-
opts.module,
|
|
405
|
-
opts.runtimeOnly ? "runtime" : "",
|
|
406
|
-
!opts.ssr ? "esm-bundler" : "node",
|
|
407
|
-
"js"
|
|
408
|
-
].filter(Boolean).join(".");
|
|
409
|
-
return `${opts.module}/dist/${filename}`;
|
|
410
|
-
};
|
|
411
|
-
function resolveOptions(options) {
|
|
412
|
-
const res = defu__default(options, {
|
|
413
|
-
ssr: false,
|
|
414
|
-
module: "vue-i18n",
|
|
415
|
-
escapeHtml: false,
|
|
416
|
-
onlyLocales: [],
|
|
417
|
-
fullInstall: true,
|
|
418
|
-
runtimeOnly: true,
|
|
419
|
-
strictMessage: true,
|
|
420
|
-
allowDynamic: false,
|
|
421
|
-
globalSFCScope: false,
|
|
422
|
-
forceStringify: false,
|
|
423
|
-
defaultSFCLang: "json",
|
|
424
|
-
dropMessageCompiler: false,
|
|
425
|
-
transformI18nBlock: void 0,
|
|
426
|
-
optimizeTranslationDirective: false
|
|
427
|
-
});
|
|
428
|
-
const include = res.include ? toArray(res.include).map((item) => path.normalize(item)) : void 0;
|
|
429
|
-
const _exclude = res.exclude ? toArray(res.exclude).map((item) => path.normalize(item)) : void 0;
|
|
430
|
-
const exclude = res.include ? _exclude : ["**/**"];
|
|
431
|
-
const onlyLocales = toArray(res.onlyLocales);
|
|
432
|
-
const fullInstall = res.module !== "vue-i18n" ? false : res.fullInstall;
|
|
433
|
-
const optimizeTranslationDirective = typeof res.optimizeTranslationDirective === "boolean" ? res.optimizeTranslationDirective : toArray(res.optimizeTranslationDirective);
|
|
434
|
-
const translationIdentifiers = /* @__PURE__ */ new Map();
|
|
435
|
-
const vueI18nAliasPath = getVueI18nAliasPath(res);
|
|
436
|
-
return {
|
|
437
|
-
...res,
|
|
438
|
-
include,
|
|
439
|
-
exclude,
|
|
440
|
-
fullInstall,
|
|
441
|
-
onlyLocales,
|
|
442
|
-
vueI18nAliasPath,
|
|
443
|
-
translationIdentifiers,
|
|
444
|
-
optimizeTranslationDirective
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
140
|
|
|
448
141
|
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
449
142
|
const VIRTUAL_PREFIX = "\0";
|
|
@@ -602,12 +295,12 @@ function resourcePlugin(opts, meta) {
|
|
|
602
295
|
if (filter(id)) {
|
|
603
296
|
const imports = mlly.findStaticImports(code);
|
|
604
297
|
for (const p of imports) {
|
|
605
|
-
const res =
|
|
298
|
+
const res = node_path.resolve(node_path.dirname(id), p.specifier);
|
|
606
299
|
importedResources.add(res);
|
|
607
300
|
}
|
|
608
301
|
}
|
|
609
302
|
if (!query.vue && supportedFileExtensionsRE.test(id) && filter(id)) {
|
|
610
|
-
langInfo =
|
|
303
|
+
langInfo = node_path.parse(filename).ext;
|
|
611
304
|
const generate = getGenerator(langInfo);
|
|
612
305
|
const parseOptions = getOptions(filename, ctx, query, {
|
|
613
306
|
...opts,
|
|
@@ -691,7 +384,7 @@ function generateBundleResources(resources) {
|
|
|
691
384
|
const imports = [];
|
|
692
385
|
for (const filename of resources) {
|
|
693
386
|
debug$1(`${filename} bundle loading ...`);
|
|
694
|
-
const { name } =
|
|
387
|
+
const { name } = node_path.parse(filename);
|
|
695
388
|
const varName = knitwork.genSafeVariableName(
|
|
696
389
|
[name, node_crypto.createHash("sha256").update(filename).digest("hex").substring(0, 8)].join("_")
|
|
697
390
|
);
|
|
@@ -808,15 +501,6 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
808
501
|
const resolvedOptions = resolveOptions(options);
|
|
809
502
|
debug("plugin options (resolved):", resolvedOptions);
|
|
810
503
|
const plugins = [resourcePlugin(resolvedOptions, meta)];
|
|
811
|
-
if (resolvedOptions.optimizeTranslationDirective) {
|
|
812
|
-
if (meta.framework === "webpack" || meta.framework === "rspack") {
|
|
813
|
-
raiseError(
|
|
814
|
-
`The 'optimizeTranslationDirective' option still is not supported for ${meta.framework}.
|
|
815
|
-
We are waiting for your Pull Request \u{1F642}.`
|
|
816
|
-
);
|
|
817
|
-
}
|
|
818
|
-
plugins.push(directivePlugin(resolvedOptions));
|
|
819
|
-
}
|
|
820
504
|
return plugins;
|
|
821
505
|
};
|
|
822
506
|
const unplugin = /* @__PURE__ */ unplugin$1.createUnplugin(unpluginFactory);
|
package/lib/index.mjs
CHANGED
|
@@ -1,21 +1,62 @@
|
|
|
1
1
|
import createDebug from 'debug';
|
|
2
2
|
import { createUnplugin } from 'unplugin';
|
|
3
|
-
import { isBoolean, assign, isEmptyObject, generateCodeFrame } from '@intlify/shared';
|
|
4
|
-
import { transformVTDirective } from '@intlify/vue-i18n-extensions';
|
|
5
|
-
import { analyze } from '@typescript-eslint/scope-manager';
|
|
6
|
-
import { parse, simpleTraverse, AST_NODE_TYPES } from '@typescript-eslint/typescript-estree';
|
|
7
|
-
import path, { normalize, resolve, dirname, parse as parse$1 } from 'node:path';
|
|
8
|
-
import eslintUitls from '@eslint-community/eslint-utils';
|
|
9
|
-
import pc from 'picocolors';
|
|
10
3
|
import defu from 'defu';
|
|
4
|
+
import { normalize, resolve, dirname, parse } from 'node:path';
|
|
11
5
|
import { DynamicResourceError, generateJSON, generateYAML, generateJavaScript } from '@intlify/bundle-utils';
|
|
6
|
+
import { assign, isEmptyObject, generateCodeFrame } from '@intlify/shared';
|
|
12
7
|
import { createFilter } from '@rollup/pluginutils';
|
|
13
8
|
import fg from 'fast-glob';
|
|
14
9
|
import { genSafeVariableName, genImport } from 'knitwork';
|
|
15
10
|
import { findStaticImports } from 'mlly';
|
|
16
11
|
import { createHash } from 'node:crypto';
|
|
17
12
|
import fs from 'node:fs';
|
|
18
|
-
import { parse as parse$
|
|
13
|
+
import { parse as parse$1 } from 'vue/compiler-sfc';
|
|
14
|
+
import pc from 'picocolors';
|
|
15
|
+
|
|
16
|
+
function toArray(value) {
|
|
17
|
+
return Array.isArray(value) ? value : [value];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getVueI18nAliasPath = (opts) => {
|
|
21
|
+
const filename = [
|
|
22
|
+
opts.module,
|
|
23
|
+
opts.runtimeOnly ? "runtime" : "",
|
|
24
|
+
!opts.ssr ? "esm-bundler" : "node",
|
|
25
|
+
"js"
|
|
26
|
+
].filter(Boolean).join(".");
|
|
27
|
+
return `${opts.module}/dist/${filename}`;
|
|
28
|
+
};
|
|
29
|
+
function resolveOptions(options) {
|
|
30
|
+
const res = defu(options, {
|
|
31
|
+
ssr: false,
|
|
32
|
+
module: "vue-i18n",
|
|
33
|
+
escapeHtml: false,
|
|
34
|
+
onlyLocales: [],
|
|
35
|
+
fullInstall: true,
|
|
36
|
+
runtimeOnly: true,
|
|
37
|
+
strictMessage: true,
|
|
38
|
+
allowDynamic: false,
|
|
39
|
+
globalSFCScope: false,
|
|
40
|
+
forceStringify: false,
|
|
41
|
+
defaultSFCLang: "json",
|
|
42
|
+
dropMessageCompiler: false,
|
|
43
|
+
transformI18nBlock: void 0
|
|
44
|
+
});
|
|
45
|
+
const include = res.include ? toArray(res.include).map((item) => normalize(item)) : void 0;
|
|
46
|
+
const _exclude = res.exclude ? toArray(res.exclude).map((item) => normalize(item)) : void 0;
|
|
47
|
+
const exclude = res.include ? _exclude : ["**/**"];
|
|
48
|
+
const onlyLocales = toArray(res.onlyLocales);
|
|
49
|
+
const fullInstall = res.module !== "vue-i18n" ? false : res.fullInstall;
|
|
50
|
+
const vueI18nAliasPath = getVueI18nAliasPath(res);
|
|
51
|
+
return {
|
|
52
|
+
...res,
|
|
53
|
+
include,
|
|
54
|
+
exclude,
|
|
55
|
+
fullInstall,
|
|
56
|
+
onlyLocales,
|
|
57
|
+
vueI18nAliasPath
|
|
58
|
+
};
|
|
59
|
+
}
|
|
19
60
|
|
|
20
61
|
const PKG_NAME = "unplugin-vue-i18n";
|
|
21
62
|
|
|
@@ -44,29 +85,6 @@ function checkVuePlugin(vuePlugin) {
|
|
|
44
85
|
}
|
|
45
86
|
return true;
|
|
46
87
|
}
|
|
47
|
-
const isWindows = typeof process !== "undefined" && process.platform === "win32";
|
|
48
|
-
const windowsSlashRE = /\\/g;
|
|
49
|
-
function slash(p) {
|
|
50
|
-
return p.replace(windowsSlashRE, "/");
|
|
51
|
-
}
|
|
52
|
-
function normalizePath(id) {
|
|
53
|
-
return path.posix.normalize(isWindows ? slash(id) : id);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function createDescriptor(filename, source, { template, compiler }) {
|
|
57
|
-
const { descriptor, errors } = compiler.parse(source, {
|
|
58
|
-
filename,
|
|
59
|
-
templateParseOptions: template?.compilerOptions
|
|
60
|
-
});
|
|
61
|
-
return { descriptor, errors };
|
|
62
|
-
}
|
|
63
|
-
function getDescriptor(filename, code, options) {
|
|
64
|
-
const { descriptor, errors } = createDescriptor(filename, code, options);
|
|
65
|
-
if (errors.length) {
|
|
66
|
-
throw errors[0];
|
|
67
|
-
}
|
|
68
|
-
return descriptor;
|
|
69
|
-
}
|
|
70
88
|
|
|
71
89
|
function parseVueRequest(id) {
|
|
72
90
|
const [filename, rawQuery] = id.split(`?`, 2);
|
|
@@ -107,329 +125,6 @@ function parseVueRequest(id) {
|
|
|
107
125
|
function getVueCompiler(vuePlugin) {
|
|
108
126
|
return vuePlugin?.api?.options.compiler;
|
|
109
127
|
}
|
|
110
|
-
function getVuePluginOptions(vuePlugin) {
|
|
111
|
-
return {
|
|
112
|
-
isProduction: vuePlugin?.api?.options.isProduction,
|
|
113
|
-
root: vuePlugin?.api?.options.root,
|
|
114
|
-
template: vuePlugin?.api?.options.template,
|
|
115
|
-
compiler: vuePlugin?.api?.options.compiler
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const debug$2 = createDebug(resolveNamespace("directive"));
|
|
120
|
-
function directivePlugin({
|
|
121
|
-
optimizeTranslationDirective,
|
|
122
|
-
translationIdentifiers
|
|
123
|
-
}) {
|
|
124
|
-
let vuePlugin = null;
|
|
125
|
-
let vuePluginOptions = null;
|
|
126
|
-
const excludeLangs = ["pug", "jsx", "tsx"];
|
|
127
|
-
return {
|
|
128
|
-
name: resolveNamespace("directive"),
|
|
129
|
-
enforce: "pre",
|
|
130
|
-
vite: {
|
|
131
|
-
config(config) {
|
|
132
|
-
vuePlugin = getVitePlugin(config, "vite:vue");
|
|
133
|
-
if (!checkVuePlugin(vuePlugin)) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (optimizeTranslationDirective) {
|
|
137
|
-
vuePlugin.api.options = resolveVueOptions(
|
|
138
|
-
vuePlugin,
|
|
139
|
-
optimizeTranslationDirective,
|
|
140
|
-
translationIdentifiers
|
|
141
|
-
);
|
|
142
|
-
debug$2(`vite:vue options['template']:`, vuePlugin.api.options);
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
configResolved(config) {
|
|
146
|
-
vuePlugin = getVitePlugin(config, "vite:vue");
|
|
147
|
-
if (!checkVuePlugin(vuePlugin)) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
},
|
|
152
|
-
async transform(code, id) {
|
|
153
|
-
if (id.endsWith(".vue")) {
|
|
154
|
-
const { filename, query } = parseVueRequest(id);
|
|
155
|
-
if (!excludeLangs.includes(query.lang ?? "")) {
|
|
156
|
-
if (vuePluginOptions == null) {
|
|
157
|
-
vuePluginOptions = getVuePluginOptions(vuePlugin);
|
|
158
|
-
}
|
|
159
|
-
if (vuePluginOptions?.compiler) {
|
|
160
|
-
analyzeIdentifiers(
|
|
161
|
-
getDescriptor(filename, code, vuePluginOptions),
|
|
162
|
-
vuePluginOptions,
|
|
163
|
-
translationIdentifiers
|
|
164
|
-
);
|
|
165
|
-
return {
|
|
166
|
-
code,
|
|
167
|
-
map: { version: 3, mappings: "", sources: [] }
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function resolveVueOptions(vuePlugin, optimizeTranslationDirective, translationIdentifiers) {
|
|
176
|
-
var _a, _b;
|
|
177
|
-
const vueOptions = vuePlugin.api.options;
|
|
178
|
-
vueOptions.template || (vueOptions.template = {});
|
|
179
|
-
(_a = vueOptions.template).compilerOptions || (_a.compilerOptions = {});
|
|
180
|
-
(_b = vueOptions.template.compilerOptions).directiveTransforms || (_b.directiveTransforms = {});
|
|
181
|
-
const translationSignatureResolver = (context, baseResolver) => {
|
|
182
|
-
const { filename } = context;
|
|
183
|
-
const vuePluginOptions = getVuePluginOptions(vuePlugin);
|
|
184
|
-
const normalizedFilename = normalizePath(path.relative(vuePluginOptions.root, filename));
|
|
185
|
-
const resolveIdentifier2 = translationIdentifiers.get(normalizedFilename);
|
|
186
|
-
debug$2("resolved vue-i18n Identifier", resolveIdentifier2);
|
|
187
|
-
if (resolveIdentifier2 == null) {
|
|
188
|
-
return void 0;
|
|
189
|
-
}
|
|
190
|
-
if (resolveIdentifier2.type === "identifier") {
|
|
191
|
-
return baseResolver(context, resolveIdentifier2.key);
|
|
192
|
-
} else {
|
|
193
|
-
const resolvedSignature = baseResolver(context, resolveIdentifier2.key);
|
|
194
|
-
return resolveIdentifier2?.style === "script-setup" ? `${resolvedSignature}.t` : resolvedSignature;
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
vueOptions.template.compilerOptions.directiveTransforms.t = transformVTDirective({
|
|
198
|
-
translationSignatures: isBoolean(optimizeTranslationDirective) ? translationSignatureResolver : optimizeTranslationDirective
|
|
199
|
-
});
|
|
200
|
-
return vueOptions;
|
|
201
|
-
}
|
|
202
|
-
function analyzeIdentifiers(descriptor, { root }, translationIdentifiers) {
|
|
203
|
-
const source = descriptor.scriptSetup?.content || descriptor.script?.content;
|
|
204
|
-
debug$2("getDescriptor content", source);
|
|
205
|
-
if (!source) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const ast = parse(source, { range: true });
|
|
209
|
-
simpleTraverse(ast, {
|
|
210
|
-
enter(node, parent) {
|
|
211
|
-
if (parent) {
|
|
212
|
-
node.parent = parent;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
const scopeManager = analyze(ast, { sourceType: "module" });
|
|
217
|
-
const scope = getScope(scopeManager, ast);
|
|
218
|
-
const importLocalName = getImportLocalName(scope, "vue-i18n", "useI18n");
|
|
219
|
-
if (importLocalName == null) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
debug$2("importLocalName", importLocalName);
|
|
223
|
-
const resolvedIdentifier = getVueI18nIdentifier(scope, importLocalName);
|
|
224
|
-
if (resolvedIdentifier) {
|
|
225
|
-
const normalizedFilename = normalizePath(path.relative(root, descriptor.filename));
|
|
226
|
-
debug$2("set vue-i18n resolved identifier: ", resolvedIdentifier);
|
|
227
|
-
translationIdentifiers.set(normalizedFilename, resolvedIdentifier);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function getScope(manager, node) {
|
|
231
|
-
const scope = manager.acquire(node, true);
|
|
232
|
-
if (scope) {
|
|
233
|
-
if (scope.type === "function-expression-name") {
|
|
234
|
-
return scope.childScopes[0];
|
|
235
|
-
}
|
|
236
|
-
return scope;
|
|
237
|
-
}
|
|
238
|
-
return manager.scopes[0];
|
|
239
|
-
}
|
|
240
|
-
function getImportLocalName(scope, source, imported) {
|
|
241
|
-
const importDecl = getImportDeclaration(scope, source);
|
|
242
|
-
if (importDecl) {
|
|
243
|
-
const specifierNode = importDecl.specifiers.find(
|
|
244
|
-
(specifierNode2) => isImportedIdentifierInImportClause(specifierNode2) && specifierNode2.imported.name === imported
|
|
245
|
-
);
|
|
246
|
-
return specifierNode ? specifierNode.local.name : null;
|
|
247
|
-
}
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
function getImportDeclaration(scope, source) {
|
|
251
|
-
const tracker = new eslintUitls.ReferenceTracker(scope);
|
|
252
|
-
const traceMap = {
|
|
253
|
-
[source]: {
|
|
254
|
-
[eslintUitls.ReferenceTracker.ESM]: true,
|
|
255
|
-
[eslintUitls.ReferenceTracker.READ]: true
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
const refs = Array.from(tracker.iterateEsmReferences(traceMap));
|
|
259
|
-
return refs.length ? refs[0].node : null;
|
|
260
|
-
}
|
|
261
|
-
function isImportedIdentifierInImportClause(node) {
|
|
262
|
-
return "imported" in node;
|
|
263
|
-
}
|
|
264
|
-
function getVueI18nIdentifier(scope, local) {
|
|
265
|
-
const { callExpression, returnStatement } = getCallExpressionAndReturnStatement(scope, local);
|
|
266
|
-
if (callExpression == null) {
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
const id = getVariableDeclarationIdFrom(callExpression);
|
|
270
|
-
if (id == null) {
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
const variableIdPairs = parseVariableId(id);
|
|
274
|
-
debug$2("variableIdPairs:", variableIdPairs);
|
|
275
|
-
const returnVariableIdPairs = parseReturnStatement(returnStatement);
|
|
276
|
-
debug$2("returnVariableIdPairs:", returnVariableIdPairs);
|
|
277
|
-
return resolveIdentifier(variableIdPairs, returnVariableIdPairs);
|
|
278
|
-
}
|
|
279
|
-
const EMPTY_NODE_RETURN = {
|
|
280
|
-
callExpression: null,
|
|
281
|
-
returnStatement: null
|
|
282
|
-
};
|
|
283
|
-
function getCallExpressionAndReturnStatement(scope, local) {
|
|
284
|
-
const variable = eslintUitls.findVariable(scope, local);
|
|
285
|
-
if (variable == null) {
|
|
286
|
-
return EMPTY_NODE_RETURN;
|
|
287
|
-
}
|
|
288
|
-
const callExpressionRef = variable.references.find((ref) => {
|
|
289
|
-
return ref.identifier.parent?.type === AST_NODE_TYPES.CallExpression;
|
|
290
|
-
});
|
|
291
|
-
if (callExpressionRef == null) {
|
|
292
|
-
return EMPTY_NODE_RETURN;
|
|
293
|
-
}
|
|
294
|
-
let returnStatement = null;
|
|
295
|
-
if (callExpressionRef.from.type === "function" && callExpressionRef.from.block.type === AST_NODE_TYPES.FunctionExpression && callExpressionRef.from.block.parent.type === AST_NODE_TYPES.Property && callExpressionRef.from.block.parent.key.type === AST_NODE_TYPES.Identifier && callExpressionRef.from.block.parent.key.name === "setup") {
|
|
296
|
-
returnStatement = callExpressionRef.from.block.body.body.find((statement) => {
|
|
297
|
-
return statement.type === AST_NODE_TYPES.ReturnStatement;
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
return {
|
|
301
|
-
callExpression: callExpressionRef.identifier.parent,
|
|
302
|
-
returnStatement
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
function getVariableDeclarationIdFrom(node) {
|
|
306
|
-
if (node.parent?.type !== AST_NODE_TYPES.VariableDeclarator) {
|
|
307
|
-
return null;
|
|
308
|
-
}
|
|
309
|
-
return node.parent.id;
|
|
310
|
-
}
|
|
311
|
-
function parseVariableId(node) {
|
|
312
|
-
if (node.type === AST_NODE_TYPES.Identifier) {
|
|
313
|
-
return [{ key: node.name, value: null }];
|
|
314
|
-
} else {
|
|
315
|
-
const props = node.properties.filter(
|
|
316
|
-
// ignore RestElement
|
|
317
|
-
(prop) => prop.type === AST_NODE_TYPES.Property
|
|
318
|
-
);
|
|
319
|
-
const pairs = [];
|
|
320
|
-
for (const prop of props) {
|
|
321
|
-
if (prop?.key.type === AST_NODE_TYPES.Identifier && prop?.value.type === AST_NODE_TYPES.Identifier) {
|
|
322
|
-
pairs.push({ key: prop.key.name, value: prop.value.name });
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
return pairs;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
function parseReturnStatement(node) {
|
|
329
|
-
const pairs = [];
|
|
330
|
-
if (node == null || node.argument == null) {
|
|
331
|
-
return pairs;
|
|
332
|
-
}
|
|
333
|
-
if (node.argument.type === AST_NODE_TYPES.ObjectExpression) {
|
|
334
|
-
for (const prop of node.argument.properties) {
|
|
335
|
-
if (prop.type === AST_NODE_TYPES.Property) {
|
|
336
|
-
if (prop.key.type === AST_NODE_TYPES.Identifier && prop.value.type === AST_NODE_TYPES.Identifier) {
|
|
337
|
-
pairs.push({ key: prop.key.name, value: prop.value.name });
|
|
338
|
-
} else if (prop.key.type === AST_NODE_TYPES.Identifier && prop.value.type === AST_NODE_TYPES.MemberExpression && prop.value.object.type === AST_NODE_TYPES.Identifier && prop.value.property.type === AST_NODE_TYPES.Identifier) {
|
|
339
|
-
pairs.push({
|
|
340
|
-
key: prop.key.name,
|
|
341
|
-
value: `${prop.value.object.name}.${prop.value.property.name}`
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return pairs;
|
|
347
|
-
} else if (node.argument.type === AST_NODE_TYPES.Identifier) {
|
|
348
|
-
return pairs;
|
|
349
|
-
} else {
|
|
350
|
-
return pairs;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
function resolveIdentifier(localVariables, returnVariable) {
|
|
354
|
-
if (returnVariable.length === 0) {
|
|
355
|
-
const variable = localVariables.find((pair) => pair.key === "t");
|
|
356
|
-
if (variable && variable.value) {
|
|
357
|
-
return { type: "identifier", key: variable.value };
|
|
358
|
-
}
|
|
359
|
-
const identifierOnly = localVariables.find((pair) => pair.value === null);
|
|
360
|
-
if (identifierOnly && identifierOnly.key) {
|
|
361
|
-
return { type: "object", key: identifierOnly.key, style: "script-setup" };
|
|
362
|
-
}
|
|
363
|
-
return null;
|
|
364
|
-
} else {
|
|
365
|
-
const variable = localVariables.find((pair) => pair.key === "t");
|
|
366
|
-
if (variable && variable.value) {
|
|
367
|
-
const returnVar = returnVariable.find((pair) => pair.value === variable.value);
|
|
368
|
-
if (returnVar && returnVar.key) {
|
|
369
|
-
return { type: "identifier", key: returnVar.key };
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
const identifierOnly = localVariables.find((pair) => pair.value === null);
|
|
373
|
-
if (identifierOnly && identifierOnly.key) {
|
|
374
|
-
const targetKey = identifierOnly.key;
|
|
375
|
-
const returnVar = returnVariable.find((pair) => pair.value?.startsWith(targetKey));
|
|
376
|
-
if (returnVar && returnVar.key) {
|
|
377
|
-
return { type: "object", key: returnVar.key, style: "setup-hook" };
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
return null;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function toArray(value) {
|
|
385
|
-
return Array.isArray(value) ? value : [value];
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
const getVueI18nAliasPath = (opts) => {
|
|
389
|
-
const filename = [
|
|
390
|
-
opts.module,
|
|
391
|
-
opts.runtimeOnly ? "runtime" : "",
|
|
392
|
-
!opts.ssr ? "esm-bundler" : "node",
|
|
393
|
-
"js"
|
|
394
|
-
].filter(Boolean).join(".");
|
|
395
|
-
return `${opts.module}/dist/${filename}`;
|
|
396
|
-
};
|
|
397
|
-
function resolveOptions(options) {
|
|
398
|
-
const res = defu(options, {
|
|
399
|
-
ssr: false,
|
|
400
|
-
module: "vue-i18n",
|
|
401
|
-
escapeHtml: false,
|
|
402
|
-
onlyLocales: [],
|
|
403
|
-
fullInstall: true,
|
|
404
|
-
runtimeOnly: true,
|
|
405
|
-
strictMessage: true,
|
|
406
|
-
allowDynamic: false,
|
|
407
|
-
globalSFCScope: false,
|
|
408
|
-
forceStringify: false,
|
|
409
|
-
defaultSFCLang: "json",
|
|
410
|
-
dropMessageCompiler: false,
|
|
411
|
-
transformI18nBlock: void 0,
|
|
412
|
-
optimizeTranslationDirective: false
|
|
413
|
-
});
|
|
414
|
-
const include = res.include ? toArray(res.include).map((item) => normalize(item)) : void 0;
|
|
415
|
-
const _exclude = res.exclude ? toArray(res.exclude).map((item) => normalize(item)) : void 0;
|
|
416
|
-
const exclude = res.include ? _exclude : ["**/**"];
|
|
417
|
-
const onlyLocales = toArray(res.onlyLocales);
|
|
418
|
-
const fullInstall = res.module !== "vue-i18n" ? false : res.fullInstall;
|
|
419
|
-
const optimizeTranslationDirective = typeof res.optimizeTranslationDirective === "boolean" ? res.optimizeTranslationDirective : toArray(res.optimizeTranslationDirective);
|
|
420
|
-
const translationIdentifiers = /* @__PURE__ */ new Map();
|
|
421
|
-
const vueI18nAliasPath = getVueI18nAliasPath(res);
|
|
422
|
-
return {
|
|
423
|
-
...res,
|
|
424
|
-
include,
|
|
425
|
-
exclude,
|
|
426
|
-
fullInstall,
|
|
427
|
-
onlyLocales,
|
|
428
|
-
vueI18nAliasPath,
|
|
429
|
-
translationIdentifiers,
|
|
430
|
-
optimizeTranslationDirective
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
128
|
|
|
434
129
|
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
435
130
|
const VIRTUAL_PREFIX = "\0";
|
|
@@ -444,7 +139,7 @@ function resourcePlugin(opts, meta) {
|
|
|
444
139
|
sourceMap: false
|
|
445
140
|
};
|
|
446
141
|
let vuePlugin = null;
|
|
447
|
-
const getSfcParser = () => vuePlugin ? getVueCompiler(vuePlugin).parse : parse$
|
|
142
|
+
const getSfcParser = () => vuePlugin ? getVueCompiler(vuePlugin).parse : parse$1;
|
|
448
143
|
const resourcePaths = /* @__PURE__ */ new Set();
|
|
449
144
|
for (const inc of opts.include || []) {
|
|
450
145
|
for (const resourcePath of fg.sync(inc, { ignore: opts.exclude })) {
|
|
@@ -593,7 +288,7 @@ function resourcePlugin(opts, meta) {
|
|
|
593
288
|
}
|
|
594
289
|
}
|
|
595
290
|
if (!query.vue && supportedFileExtensionsRE.test(id) && filter(id)) {
|
|
596
|
-
langInfo = parse
|
|
291
|
+
langInfo = parse(filename).ext;
|
|
597
292
|
const generate = getGenerator(langInfo);
|
|
598
293
|
const parseOptions = getOptions(filename, ctx, query, {
|
|
599
294
|
...opts,
|
|
@@ -677,7 +372,7 @@ function generateBundleResources(resources) {
|
|
|
677
372
|
const imports = [];
|
|
678
373
|
for (const filename of resources) {
|
|
679
374
|
debug$1(`${filename} bundle loading ...`);
|
|
680
|
-
const { name } = parse
|
|
375
|
+
const { name } = parse(filename);
|
|
681
376
|
const varName = genSafeVariableName(
|
|
682
377
|
[name, createHash("sha256").update(filename).digest("hex").substring(0, 8)].join("_")
|
|
683
378
|
);
|
|
@@ -794,15 +489,6 @@ const unpluginFactory = (options = {}, meta) => {
|
|
|
794
489
|
const resolvedOptions = resolveOptions(options);
|
|
795
490
|
debug("plugin options (resolved):", resolvedOptions);
|
|
796
491
|
const plugins = [resourcePlugin(resolvedOptions, meta)];
|
|
797
|
-
if (resolvedOptions.optimizeTranslationDirective) {
|
|
798
|
-
if (meta.framework === "webpack" || meta.framework === "rspack") {
|
|
799
|
-
raiseError(
|
|
800
|
-
`The 'optimizeTranslationDirective' option still is not supported for ${meta.framework}.
|
|
801
|
-
We are waiting for your Pull Request \u{1F642}.`
|
|
802
|
-
);
|
|
803
|
-
}
|
|
804
|
-
plugins.push(directivePlugin(resolvedOptions));
|
|
805
|
-
}
|
|
806
492
|
return plugins;
|
|
807
493
|
};
|
|
808
494
|
const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
package/lib/rspack.cjs
CHANGED
|
@@ -3,15 +3,10 @@
|
|
|
3
3
|
const unplugin = require('unplugin');
|
|
4
4
|
const index = require('./index.cjs');
|
|
5
5
|
require('debug');
|
|
6
|
-
require('@intlify/shared');
|
|
7
|
-
require('@intlify/vue-i18n-extensions');
|
|
8
|
-
require('@typescript-eslint/scope-manager');
|
|
9
|
-
require('@typescript-eslint/typescript-estree');
|
|
10
|
-
require('node:path');
|
|
11
|
-
require('@eslint-community/eslint-utils');
|
|
12
|
-
require('picocolors');
|
|
13
6
|
require('defu');
|
|
7
|
+
require('node:path');
|
|
14
8
|
require('@intlify/bundle-utils');
|
|
9
|
+
require('@intlify/shared');
|
|
15
10
|
require('@rollup/pluginutils');
|
|
16
11
|
require('fast-glob');
|
|
17
12
|
require('knitwork');
|
|
@@ -19,6 +14,7 @@ require('mlly');
|
|
|
19
14
|
require('node:crypto');
|
|
20
15
|
require('node:fs');
|
|
21
16
|
require('vue/compiler-sfc');
|
|
17
|
+
require('picocolors');
|
|
22
18
|
|
|
23
19
|
const rspack = unplugin.createRspackPlugin(index.unpluginFactory);
|
|
24
20
|
|
package/lib/rspack.mjs
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { createRspackPlugin } from 'unplugin';
|
|
2
2
|
import { unpluginFactory } from './index.mjs';
|
|
3
3
|
import 'debug';
|
|
4
|
-
import '@intlify/shared';
|
|
5
|
-
import '@intlify/vue-i18n-extensions';
|
|
6
|
-
import '@typescript-eslint/scope-manager';
|
|
7
|
-
import '@typescript-eslint/typescript-estree';
|
|
8
|
-
import 'node:path';
|
|
9
|
-
import '@eslint-community/eslint-utils';
|
|
10
|
-
import 'picocolors';
|
|
11
4
|
import 'defu';
|
|
5
|
+
import 'node:path';
|
|
12
6
|
import '@intlify/bundle-utils';
|
|
7
|
+
import '@intlify/shared';
|
|
13
8
|
import '@rollup/pluginutils';
|
|
14
9
|
import 'fast-glob';
|
|
15
10
|
import 'knitwork';
|
|
@@ -17,6 +12,7 @@ import 'mlly';
|
|
|
17
12
|
import 'node:crypto';
|
|
18
13
|
import 'node:fs';
|
|
19
14
|
import 'vue/compiler-sfc';
|
|
15
|
+
import 'picocolors';
|
|
20
16
|
|
|
21
17
|
const rspack = createRspackPlugin(unpluginFactory);
|
|
22
18
|
|
package/lib/types.d.cts
CHANGED
package/lib/types.d.mts
CHANGED
package/lib/types.d.ts
CHANGED
package/lib/vite.cjs
CHANGED
|
@@ -3,15 +3,10 @@
|
|
|
3
3
|
const unplugin = require('unplugin');
|
|
4
4
|
const index = require('./index.cjs');
|
|
5
5
|
require('debug');
|
|
6
|
-
require('@intlify/shared');
|
|
7
|
-
require('@intlify/vue-i18n-extensions');
|
|
8
|
-
require('@typescript-eslint/scope-manager');
|
|
9
|
-
require('@typescript-eslint/typescript-estree');
|
|
10
|
-
require('node:path');
|
|
11
|
-
require('@eslint-community/eslint-utils');
|
|
12
|
-
require('picocolors');
|
|
13
6
|
require('defu');
|
|
7
|
+
require('node:path');
|
|
14
8
|
require('@intlify/bundle-utils');
|
|
9
|
+
require('@intlify/shared');
|
|
15
10
|
require('@rollup/pluginutils');
|
|
16
11
|
require('fast-glob');
|
|
17
12
|
require('knitwork');
|
|
@@ -19,6 +14,7 @@ require('mlly');
|
|
|
19
14
|
require('node:crypto');
|
|
20
15
|
require('node:fs');
|
|
21
16
|
require('vue/compiler-sfc');
|
|
17
|
+
require('picocolors');
|
|
22
18
|
|
|
23
19
|
const vite = unplugin.createVitePlugin(index.unpluginFactory);
|
|
24
20
|
|
package/lib/vite.mjs
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { createVitePlugin } from 'unplugin';
|
|
2
2
|
import { unpluginFactory } from './index.mjs';
|
|
3
3
|
import 'debug';
|
|
4
|
-
import '@intlify/shared';
|
|
5
|
-
import '@intlify/vue-i18n-extensions';
|
|
6
|
-
import '@typescript-eslint/scope-manager';
|
|
7
|
-
import '@typescript-eslint/typescript-estree';
|
|
8
|
-
import 'node:path';
|
|
9
|
-
import '@eslint-community/eslint-utils';
|
|
10
|
-
import 'picocolors';
|
|
11
4
|
import 'defu';
|
|
5
|
+
import 'node:path';
|
|
12
6
|
import '@intlify/bundle-utils';
|
|
7
|
+
import '@intlify/shared';
|
|
13
8
|
import '@rollup/pluginutils';
|
|
14
9
|
import 'fast-glob';
|
|
15
10
|
import 'knitwork';
|
|
@@ -17,6 +12,7 @@ import 'mlly';
|
|
|
17
12
|
import 'node:crypto';
|
|
18
13
|
import 'node:fs';
|
|
19
14
|
import 'vue/compiler-sfc';
|
|
15
|
+
import 'picocolors';
|
|
20
16
|
|
|
21
17
|
const vite = createVitePlugin(unpluginFactory);
|
|
22
18
|
|
package/lib/webpack.cjs
CHANGED
|
@@ -3,15 +3,10 @@
|
|
|
3
3
|
const unplugin = require('unplugin');
|
|
4
4
|
const index = require('./index.cjs');
|
|
5
5
|
require('debug');
|
|
6
|
-
require('@intlify/shared');
|
|
7
|
-
require('@intlify/vue-i18n-extensions');
|
|
8
|
-
require('@typescript-eslint/scope-manager');
|
|
9
|
-
require('@typescript-eslint/typescript-estree');
|
|
10
|
-
require('node:path');
|
|
11
|
-
require('@eslint-community/eslint-utils');
|
|
12
|
-
require('picocolors');
|
|
13
6
|
require('defu');
|
|
7
|
+
require('node:path');
|
|
14
8
|
require('@intlify/bundle-utils');
|
|
9
|
+
require('@intlify/shared');
|
|
15
10
|
require('@rollup/pluginutils');
|
|
16
11
|
require('fast-glob');
|
|
17
12
|
require('knitwork');
|
|
@@ -19,6 +14,7 @@ require('mlly');
|
|
|
19
14
|
require('node:crypto');
|
|
20
15
|
require('node:fs');
|
|
21
16
|
require('vue/compiler-sfc');
|
|
17
|
+
require('picocolors');
|
|
22
18
|
|
|
23
19
|
const webpack = unplugin.createWebpackPlugin(index.unpluginFactory);
|
|
24
20
|
|
package/lib/webpack.mjs
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { createWebpackPlugin } from 'unplugin';
|
|
2
2
|
import { unpluginFactory } from './index.mjs';
|
|
3
3
|
import 'debug';
|
|
4
|
-
import '@intlify/shared';
|
|
5
|
-
import '@intlify/vue-i18n-extensions';
|
|
6
|
-
import '@typescript-eslint/scope-manager';
|
|
7
|
-
import '@typescript-eslint/typescript-estree';
|
|
8
|
-
import 'node:path';
|
|
9
|
-
import '@eslint-community/eslint-utils';
|
|
10
|
-
import 'picocolors';
|
|
11
4
|
import 'defu';
|
|
5
|
+
import 'node:path';
|
|
12
6
|
import '@intlify/bundle-utils';
|
|
7
|
+
import '@intlify/shared';
|
|
13
8
|
import '@rollup/pluginutils';
|
|
14
9
|
import 'fast-glob';
|
|
15
10
|
import 'knitwork';
|
|
@@ -17,6 +12,7 @@ import 'mlly';
|
|
|
17
12
|
import 'node:crypto';
|
|
18
13
|
import 'node:fs';
|
|
19
14
|
import 'vue/compiler-sfc';
|
|
15
|
+
import 'picocolors';
|
|
20
16
|
|
|
21
17
|
const webpack = createWebpackPlugin(unpluginFactory);
|
|
22
18
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "12.0.0-alpha.
|
|
4
|
+
"version": "12.0.0-alpha.1",
|
|
5
5
|
"description": "unplugin for Vue I18n",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "kazuya kawaguchi",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"url": "https://github.com/intlify/bundle-tools/issues"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"petite-vue-i18n": "
|
|
14
|
+
"petite-vue-i18n": "^12.0.0-alpha.2",
|
|
15
15
|
"vue": "^3.2.25",
|
|
16
|
-
"vue-i18n": "
|
|
16
|
+
"vue-i18n": "^12.0.0-alpha.2"
|
|
17
17
|
},
|
|
18
18
|
"peerDependenciesMeta": {
|
|
19
19
|
"petite-vue-i18n": {
|
|
@@ -24,12 +24,8 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@eslint-community/eslint-utils": "^4.4.0",
|
|
28
27
|
"@intlify/shared": "next",
|
|
29
|
-
"@intlify/vue-i18n-extensions": "^8.0.0",
|
|
30
28
|
"@rollup/pluginutils": "^5.1.0",
|
|
31
|
-
"@typescript-eslint/scope-manager": "^8.13.0",
|
|
32
|
-
"@typescript-eslint/typescript-estree": "^8.13.0",
|
|
33
29
|
"debug": "^4.3.3",
|
|
34
30
|
"defu": "^6.1.4",
|
|
35
31
|
"fast-glob": "^3.2.12",
|
|
@@ -38,7 +34,7 @@
|
|
|
38
34
|
"picocolors": "^1.0.0",
|
|
39
35
|
"unplugin": "^2.2.0",
|
|
40
36
|
"vue": "^3.4",
|
|
41
|
-
"@intlify/bundle-utils": "12.0.0-alpha.
|
|
37
|
+
"@intlify/bundle-utils": "12.0.0-alpha.1"
|
|
42
38
|
},
|
|
43
39
|
"devDependencies": {
|
|
44
40
|
"@types/node": "^20.14.8",
|
|
@@ -58,7 +54,7 @@
|
|
|
58
54
|
"webpack-merge": "^5.9.0"
|
|
59
55
|
},
|
|
60
56
|
"engines": {
|
|
61
|
-
"node": ">=
|
|
57
|
+
"node": ">= 20"
|
|
62
58
|
},
|
|
63
59
|
"files": [
|
|
64
60
|
"lib",
|