@intlify/unplugin-vue-i18n 12.0.0-alpha.1 → 12.0.0-alpha.2
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/lib/index.cjs +31 -8
- package/lib/index.d.cts +4 -2
- package/lib/index.d.mts +1 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.mjs +32 -9
- package/package.json +11 -11
package/lib/index.cjs
CHANGED
|
@@ -88,6 +88,23 @@ function resolveNamespace(name) {
|
|
|
88
88
|
function getVitePlugin(config, name) {
|
|
89
89
|
return config.plugins.find((p) => p.name === name);
|
|
90
90
|
}
|
|
91
|
+
function getVitePluginTransform(plugin) {
|
|
92
|
+
if (plugin.transform) {
|
|
93
|
+
return "handler" in plugin.transform ? [plugin.transform.handler, "handler"] : [plugin.transform, "transform"];
|
|
94
|
+
} else {
|
|
95
|
+
return [void 0, void 0];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function overrideVitePluginTransform(plugin, override, to) {
|
|
99
|
+
if (plugin.transform == void 0) {
|
|
100
|
+
throw new Error("plugin.transform is undefined");
|
|
101
|
+
}
|
|
102
|
+
if (to === "handler" && "handler" in plugin.transform) {
|
|
103
|
+
plugin.transform.handler = override;
|
|
104
|
+
} else {
|
|
105
|
+
plugin.transform = override;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
91
108
|
function checkVuePlugin(vuePlugin) {
|
|
92
109
|
if (vuePlugin == null || !vuePlugin.api) {
|
|
93
110
|
error(
|
|
@@ -239,8 +256,11 @@ function resourcePlugin(opts, meta) {
|
|
|
239
256
|
debug$1(`configResolved: isProduction = ${ctx.prod}, sourceMap = ${ctx.sourceMap}`);
|
|
240
257
|
const jsonPlugin = getVitePlugin(config, "vite:json");
|
|
241
258
|
if (jsonPlugin) {
|
|
242
|
-
const orgTransform = jsonPlugin
|
|
243
|
-
|
|
259
|
+
const [orgTransform, transformWay] = getVitePluginTransform(jsonPlugin);
|
|
260
|
+
if (!orgTransform) {
|
|
261
|
+
throw new Error("vite:json plugin not found!");
|
|
262
|
+
}
|
|
263
|
+
async function overrideViteJsonPlugin(code, id) {
|
|
244
264
|
if (!/\.json$/.test(id) || filter(id)) {
|
|
245
265
|
return;
|
|
246
266
|
}
|
|
@@ -250,7 +270,8 @@ function resourcePlugin(opts, meta) {
|
|
|
250
270
|
}
|
|
251
271
|
debug$1("org json plugin");
|
|
252
272
|
return orgTransform.apply(this, [code, id]);
|
|
253
|
-
}
|
|
273
|
+
}
|
|
274
|
+
overrideVitePluginTransform(jsonPlugin, overrideViteJsonPlugin, transformWay);
|
|
254
275
|
}
|
|
255
276
|
}
|
|
256
277
|
},
|
|
@@ -308,11 +329,10 @@ function resourcePlugin(opts, meta) {
|
|
|
308
329
|
});
|
|
309
330
|
debug$1("parseOptions", parseOptions);
|
|
310
331
|
try {
|
|
311
|
-
const { code: generatedCode, map } = generate(code, parseOptions);
|
|
332
|
+
const { code: generatedCode, map } = await generate(code, parseOptions);
|
|
312
333
|
debug$1("generated code", generatedCode);
|
|
313
334
|
debug$1("sourcemap", map, ctx.sourceMap);
|
|
314
|
-
if (code === generatedCode)
|
|
315
|
-
return;
|
|
335
|
+
if (code === generatedCode) return;
|
|
316
336
|
return result(generatedCode);
|
|
317
337
|
} catch (err) {
|
|
318
338
|
if (err instanceof bundleUtils.DynamicResourceError) {
|
|
@@ -349,7 +369,7 @@ function resourcePlugin(opts, meta) {
|
|
|
349
369
|
}
|
|
350
370
|
}
|
|
351
371
|
const generate = getGenerator(langInfo, bundleUtils.generateYAML);
|
|
352
|
-
const { code: generatedCode, map } = generate(source, parseOptions);
|
|
372
|
+
const { code: generatedCode, map } = await generate(source, parseOptions);
|
|
353
373
|
debug$1("generated code", generatedCode);
|
|
354
374
|
debug$1("sourcemap", map, ctx.sourceMap);
|
|
355
375
|
if (code !== generatedCode) {
|
|
@@ -366,9 +386,12 @@ function getGenerator(ext, fallback = bundleUtils.generateJSON) {
|
|
|
366
386
|
if (/\.ya?ml$/.test(ext)) {
|
|
367
387
|
return bundleUtils.generateYAML;
|
|
368
388
|
}
|
|
369
|
-
if (/\.[c|m]?
|
|
389
|
+
if (/\.[c|m]?js$/.test(ext)) {
|
|
370
390
|
return bundleUtils.generateJavaScript;
|
|
371
391
|
}
|
|
392
|
+
if (/\.[c|m]?ts$/.test(ext)) {
|
|
393
|
+
return bundleUtils.generateTypescript;
|
|
394
|
+
}
|
|
372
395
|
return fallback;
|
|
373
396
|
}
|
|
374
397
|
async function loadWebpack() {
|
package/lib/index.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnpluginInstance, UnpluginFactory } from 'unplugin';
|
|
2
2
|
import { PluginOptions } from './types.cjs';
|
|
3
3
|
export { SFCLangFormat, VueI18nModule } from './types.cjs';
|
|
4
4
|
|
|
5
5
|
declare const unpluginFactory: UnpluginFactory<PluginOptions | undefined>;
|
|
6
6
|
declare const unplugin: UnpluginInstance<PluginOptions | undefined, boolean>;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
export = unplugin;
|
|
10
|
+
export { PluginOptions, unplugin, unpluginFactory };
|
package/lib/index.d.mts
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnpluginInstance, UnpluginFactory } from 'unplugin';
|
|
2
2
|
import { PluginOptions } from './types.js';
|
|
3
3
|
export { SFCLangFormat, VueI18nModule } from './types.js';
|
|
4
4
|
|
|
5
5
|
declare const unpluginFactory: UnpluginFactory<PluginOptions | undefined>;
|
|
6
6
|
declare const unplugin: UnpluginInstance<PluginOptions | undefined, boolean>;
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
export = unplugin;
|
|
10
|
+
export { PluginOptions, unplugin, unpluginFactory };
|
package/lib/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import createDebug from 'debug';
|
|
|
2
2
|
import { createUnplugin } from 'unplugin';
|
|
3
3
|
import defu from 'defu';
|
|
4
4
|
import { normalize, resolve, dirname, parse } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import { generateJSON, DynamicResourceError, generateYAML, generateJavaScript, generateTypescript } from '@intlify/bundle-utils';
|
|
6
6
|
import { assign, isEmptyObject, generateCodeFrame } from '@intlify/shared';
|
|
7
7
|
import { createFilter } from '@rollup/pluginutils';
|
|
8
8
|
import fg from 'fast-glob';
|
|
@@ -76,6 +76,23 @@ function resolveNamespace(name) {
|
|
|
76
76
|
function getVitePlugin(config, name) {
|
|
77
77
|
return config.plugins.find((p) => p.name === name);
|
|
78
78
|
}
|
|
79
|
+
function getVitePluginTransform(plugin) {
|
|
80
|
+
if (plugin.transform) {
|
|
81
|
+
return "handler" in plugin.transform ? [plugin.transform.handler, "handler"] : [plugin.transform, "transform"];
|
|
82
|
+
} else {
|
|
83
|
+
return [void 0, void 0];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function overrideVitePluginTransform(plugin, override, to) {
|
|
87
|
+
if (plugin.transform == void 0) {
|
|
88
|
+
throw new Error("plugin.transform is undefined");
|
|
89
|
+
}
|
|
90
|
+
if (to === "handler" && "handler" in plugin.transform) {
|
|
91
|
+
plugin.transform.handler = override;
|
|
92
|
+
} else {
|
|
93
|
+
plugin.transform = override;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
79
96
|
function checkVuePlugin(vuePlugin) {
|
|
80
97
|
if (vuePlugin == null || !vuePlugin.api) {
|
|
81
98
|
error(
|
|
@@ -227,8 +244,11 @@ function resourcePlugin(opts, meta) {
|
|
|
227
244
|
debug$1(`configResolved: isProduction = ${ctx.prod}, sourceMap = ${ctx.sourceMap}`);
|
|
228
245
|
const jsonPlugin = getVitePlugin(config, "vite:json");
|
|
229
246
|
if (jsonPlugin) {
|
|
230
|
-
const orgTransform = jsonPlugin
|
|
231
|
-
|
|
247
|
+
const [orgTransform, transformWay] = getVitePluginTransform(jsonPlugin);
|
|
248
|
+
if (!orgTransform) {
|
|
249
|
+
throw new Error("vite:json plugin not found!");
|
|
250
|
+
}
|
|
251
|
+
async function overrideViteJsonPlugin(code, id) {
|
|
232
252
|
if (!/\.json$/.test(id) || filter(id)) {
|
|
233
253
|
return;
|
|
234
254
|
}
|
|
@@ -238,7 +258,8 @@ function resourcePlugin(opts, meta) {
|
|
|
238
258
|
}
|
|
239
259
|
debug$1("org json plugin");
|
|
240
260
|
return orgTransform.apply(this, [code, id]);
|
|
241
|
-
}
|
|
261
|
+
}
|
|
262
|
+
overrideVitePluginTransform(jsonPlugin, overrideViteJsonPlugin, transformWay);
|
|
242
263
|
}
|
|
243
264
|
}
|
|
244
265
|
},
|
|
@@ -296,11 +317,10 @@ function resourcePlugin(opts, meta) {
|
|
|
296
317
|
});
|
|
297
318
|
debug$1("parseOptions", parseOptions);
|
|
298
319
|
try {
|
|
299
|
-
const { code: generatedCode, map } = generate(code, parseOptions);
|
|
320
|
+
const { code: generatedCode, map } = await generate(code, parseOptions);
|
|
300
321
|
debug$1("generated code", generatedCode);
|
|
301
322
|
debug$1("sourcemap", map, ctx.sourceMap);
|
|
302
|
-
if (code === generatedCode)
|
|
303
|
-
return;
|
|
323
|
+
if (code === generatedCode) return;
|
|
304
324
|
return result(generatedCode);
|
|
305
325
|
} catch (err) {
|
|
306
326
|
if (err instanceof DynamicResourceError) {
|
|
@@ -337,7 +357,7 @@ function resourcePlugin(opts, meta) {
|
|
|
337
357
|
}
|
|
338
358
|
}
|
|
339
359
|
const generate = getGenerator(langInfo, generateYAML);
|
|
340
|
-
const { code: generatedCode, map } = generate(source, parseOptions);
|
|
360
|
+
const { code: generatedCode, map } = await generate(source, parseOptions);
|
|
341
361
|
debug$1("generated code", generatedCode);
|
|
342
362
|
debug$1("sourcemap", map, ctx.sourceMap);
|
|
343
363
|
if (code !== generatedCode) {
|
|
@@ -354,9 +374,12 @@ function getGenerator(ext, fallback = generateJSON) {
|
|
|
354
374
|
if (/\.ya?ml$/.test(ext)) {
|
|
355
375
|
return generateYAML;
|
|
356
376
|
}
|
|
357
|
-
if (/\.[c|m]?
|
|
377
|
+
if (/\.[c|m]?js$/.test(ext)) {
|
|
358
378
|
return generateJavaScript;
|
|
359
379
|
}
|
|
380
|
+
if (/\.[c|m]?ts$/.test(ext)) {
|
|
381
|
+
return generateTypescript;
|
|
382
|
+
}
|
|
360
383
|
return fallback;
|
|
361
384
|
}
|
|
362
385
|
async function loadWebpack() {
|
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.2",
|
|
5
5
|
"description": "unplugin for Vue I18n",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "kazuya kawaguchi",
|
|
@@ -33,24 +33,24 @@
|
|
|
33
33
|
"mlly": "^1.2.0",
|
|
34
34
|
"picocolors": "^1.0.0",
|
|
35
35
|
"unplugin": "^2.2.0",
|
|
36
|
-
"vue": "^3.
|
|
37
|
-
"@intlify/bundle-utils": "12.0.0-alpha.
|
|
36
|
+
"vue": "^3.5.13",
|
|
37
|
+
"@intlify/bundle-utils": "12.0.0-alpha.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@
|
|
40
|
+
"@intlify/core-base": "next",
|
|
41
|
+
"@rspack/core": "^1.2.7",
|
|
42
|
+
"@types/debug": "^4.1.5",
|
|
41
43
|
"@types/jsdom": "^16.2.5",
|
|
42
44
|
"@types/memory-fs": "^0.3.2",
|
|
43
|
-
"@types/
|
|
44
|
-
"@rspack/core": "^1.2.7",
|
|
45
|
-
"@intlify/core-base": "next",
|
|
46
|
-
"vite": "^6.2.2",
|
|
45
|
+
"@types/node": "^22.13.11",
|
|
47
46
|
"@vitejs/plugin-vue": "^5.2.3",
|
|
48
47
|
"jsdom": "^25.0.1",
|
|
49
48
|
"memory-fs": "^0.5.0",
|
|
50
|
-
"vue-loader": "^16.3.0",
|
|
51
49
|
"ts-loader": "^9.5.2",
|
|
52
|
-
"unbuild": "^
|
|
53
|
-
"
|
|
50
|
+
"unbuild": "^3.5.0",
|
|
51
|
+
"vite": "^6.2.2",
|
|
52
|
+
"vue-loader": "^16.8.3",
|
|
53
|
+
"webpack": "^5.92.0",
|
|
54
54
|
"webpack-merge": "^5.9.0"
|
|
55
55
|
},
|
|
56
56
|
"engines": {
|