@intlify/unplugin-vue-i18n 0.5.0 → 0.6.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/CHANGELOG.md +18 -0
- package/lib/index.cjs +119 -42
- package/lib/index.mjs +120 -43
- package/package.json +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
|
|
2
|
+
## @intlify/unplugin-vue-i18n@0.6.1 (2022-09-26)
|
|
3
|
+
|
|
4
|
+
#### :zap: Improvement Features
|
|
5
|
+
* [#184](https://github.com/intlify/bundle-tools/pull/184) fix(unplugin-vue-i18n): port vue-i18n-bridge module detecting from vite-plugin-vue-i18n ([@kazupon](https://github.com/kazupon))
|
|
6
|
+
|
|
7
|
+
#### Committers: 1
|
|
8
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## @intlify/unplugin-vue-i18n@0.6.0 (2022-09-19)
|
|
12
|
+
|
|
13
|
+
#### :bug: Bug Fixes
|
|
14
|
+
* [#180](https://github.com/intlify/bundle-tools/pull/180) fix(unplugin-vue-i18n): improve compilation error handling ([@kazupon](https://github.com/kazupon))
|
|
15
|
+
|
|
16
|
+
#### Committers: 1
|
|
17
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
18
|
+
|
|
19
|
+
|
|
2
20
|
## @intlify/unplugin-vue-i18n@0.5.0 (2022-07-26)
|
|
3
21
|
|
|
4
22
|
#### :star: Features
|
package/lib/index.cjs
CHANGED
|
@@ -27,7 +27,9 @@ function parseVueRequest(id) {
|
|
|
27
27
|
const [filename, rawQuery] = id.split(`?`, 2);
|
|
28
28
|
const params = new URLSearchParams(rawQuery);
|
|
29
29
|
const ret = {};
|
|
30
|
-
const langPart = Object.keys(Object.fromEntries(params)).find(
|
|
30
|
+
const langPart = Object.keys(Object.fromEntries(params)).find(
|
|
31
|
+
(key) => /lang\./i.test(key)
|
|
32
|
+
);
|
|
31
33
|
ret.vue = params.has("vue");
|
|
32
34
|
ret.global = params.has("global");
|
|
33
35
|
ret.src = params.has("src");
|
|
@@ -95,11 +97,23 @@ function raiseError(message) {
|
|
|
95
97
|
throw new Error(`[unplugin-vue-i18n] ${message}`);
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
function checkVueI18nBridgeInstallPackage(debug) {
|
|
101
|
+
let ret = false;
|
|
102
|
+
try {
|
|
103
|
+
debug(`vue-i18n-bridge load path: ${require.resolve("vue-i18n-bridge")}`);
|
|
104
|
+
ret = true;
|
|
105
|
+
} catch (e) {
|
|
106
|
+
debug(`cannot find 'vue-i18n-bridge'`, e);
|
|
107
|
+
}
|
|
108
|
+
return ret;
|
|
109
|
+
}
|
|
110
|
+
|
|
98
111
|
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
99
112
|
const INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID = "@intlify/vite-plugin-vue-i18n/messages";
|
|
100
113
|
const VIRTUAL_PREFIX = "\0";
|
|
101
114
|
const debug = createDebug__default("unplugin-vue-i18n");
|
|
102
115
|
const installedPkg = bundleUtils.checkInstallPackage("@intlify/unplugin-vue-i18n", debug);
|
|
116
|
+
const installedVueI18nBridge = checkVueI18nBridgeInstallPackage(debug);
|
|
103
117
|
const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
104
118
|
debug("plugin options:", options, meta.framework);
|
|
105
119
|
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
@@ -131,7 +145,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
131
145
|
warn(`'useVueI18nImportName' option is experimental`);
|
|
132
146
|
}
|
|
133
147
|
debug("useVueI18nImportName", useVueI18nImportName);
|
|
134
|
-
const getAliasName = () => installedPkg === "petite-vue-i18n" && shared.isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : `${installedPkg}`;
|
|
148
|
+
const getAliasName = () => installedVueI18nBridge && installedPkg === "vue-i18n" ? "vue-i18n-bridge" : installedPkg === "petite-vue-i18n" && shared.isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : `${installedPkg}`;
|
|
135
149
|
const esm = shared.isBoolean(options.esm) ? options.esm : true;
|
|
136
150
|
debug("esm", esm);
|
|
137
151
|
let isProduction = false;
|
|
@@ -152,7 +166,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
152
166
|
config.resolve.alias[getAliasName()] = `${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`;
|
|
153
167
|
}
|
|
154
168
|
debug(`alias name: ${getAliasName()}`);
|
|
155
|
-
debug(
|
|
169
|
+
debug(
|
|
170
|
+
`set ${installedPkg} runtime only: ${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`
|
|
171
|
+
);
|
|
156
172
|
} else if (command === "serve" && installedPkg === "petite-vue-i18n" && useVueI18nImportName) {
|
|
157
173
|
normalizeConfigResolveAlias(config.resolve, meta.framework);
|
|
158
174
|
if (shared.isArray(config.resolve.alias)) {
|
|
@@ -167,15 +183,21 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
167
183
|
}
|
|
168
184
|
config.define = config.define || {};
|
|
169
185
|
config.define["__VUE_I18N_LEGACY_API__"] = !compositionOnly;
|
|
170
|
-
debug(
|
|
186
|
+
debug(
|
|
187
|
+
`set __VUE_I18N_LEGACY_API__ is '${config.define["__VUE_I18N_LEGACY_API__"]}'`
|
|
188
|
+
);
|
|
171
189
|
config.define["__VUE_I18N_FULL_INSTALL__"] = fullInstall;
|
|
172
|
-
debug(
|
|
190
|
+
debug(
|
|
191
|
+
`set __VUE_I18N_FULL_INSTALL__ is '${config.define["__VUE_I18N_FULL_INSTALL__"]}'`
|
|
192
|
+
);
|
|
173
193
|
config.define["__VUE_I18N_PROD_DEVTOOLS__"] = false;
|
|
174
194
|
},
|
|
175
195
|
configResolved(config) {
|
|
176
196
|
isProduction = config.isProduction;
|
|
177
197
|
sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
|
|
178
|
-
debug(
|
|
198
|
+
debug(
|
|
199
|
+
`configResolved: isProduction = ${isProduction}, sourceMap = ${sourceMap}`
|
|
200
|
+
);
|
|
179
201
|
const jsonPlugin = config.plugins.find((p) => p.name === "vite:json");
|
|
180
202
|
if (jsonPlugin) {
|
|
181
203
|
const orgTransform = jsonPlugin.transform;
|
|
@@ -203,11 +225,13 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
203
225
|
}
|
|
204
226
|
loadWebpack().then((webpack) => {
|
|
205
227
|
if (webpack) {
|
|
206
|
-
compiler.options.plugins.push(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
228
|
+
compiler.options.plugins.push(
|
|
229
|
+
new webpack.DefinePlugin({
|
|
230
|
+
__VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
|
|
231
|
+
__VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
|
|
232
|
+
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
233
|
+
})
|
|
234
|
+
);
|
|
211
235
|
debug(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
|
|
212
236
|
debug(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
213
237
|
} else {
|
|
@@ -225,7 +249,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
225
249
|
resolveId(id, importer) {
|
|
226
250
|
debug("resolveId", id, importer);
|
|
227
251
|
if (id === INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) {
|
|
228
|
-
warn(
|
|
252
|
+
warn(
|
|
253
|
+
`deprected '${INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID}', you should switch to '${INTLIFY_BUNDLE_IMPORT_ID}'`
|
|
254
|
+
);
|
|
229
255
|
return asVirtualId(id, meta.framework);
|
|
230
256
|
}
|
|
231
257
|
if (id === INTLIFY_BUNDLE_IMPORT_ID) {
|
|
@@ -235,19 +261,28 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
235
261
|
async load(id) {
|
|
236
262
|
debug("load", id);
|
|
237
263
|
const { query } = parseVueRequest(id);
|
|
238
|
-
if ([INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(
|
|
264
|
+
if ([INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(
|
|
265
|
+
getVirtualId(id, meta.framework)
|
|
266
|
+
) && include) {
|
|
239
267
|
let resourcePaths = [];
|
|
240
268
|
const includePaths = shared.isArray(include) ? include : [include];
|
|
241
269
|
for (const inc of includePaths) {
|
|
242
270
|
resourcePaths = [...resourcePaths, ...await fg__default(inc)];
|
|
243
271
|
}
|
|
244
|
-
resourcePaths = resourcePaths.filter(
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
272
|
+
resourcePaths = resourcePaths.filter(
|
|
273
|
+
(el, pos) => resourcePaths.indexOf(el) === pos
|
|
274
|
+
);
|
|
275
|
+
const code = await generateBundleResources(
|
|
276
|
+
resourcePaths,
|
|
277
|
+
query,
|
|
278
|
+
isProduction,
|
|
279
|
+
{
|
|
280
|
+
forceStringify,
|
|
281
|
+
bridge,
|
|
282
|
+
exportESM: esm,
|
|
283
|
+
useClassComponent
|
|
284
|
+
}
|
|
285
|
+
);
|
|
251
286
|
return {
|
|
252
287
|
code,
|
|
253
288
|
map: { mappings: "" }
|
|
@@ -272,16 +307,26 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
272
307
|
if (/\.(json5?|ya?ml)$/.test(id) && filter(id)) {
|
|
273
308
|
langInfo = pathe.parse(filename).ext;
|
|
274
309
|
const generate = /\.?json5?/.test(langInfo) ? bundleUtils.generateJSON : bundleUtils.generateYAML;
|
|
275
|
-
const parseOptions = getOptions(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
310
|
+
const parseOptions = getOptions(
|
|
311
|
+
filename,
|
|
312
|
+
isProduction,
|
|
313
|
+
query,
|
|
314
|
+
sourceMap,
|
|
315
|
+
{
|
|
316
|
+
inSourceMap,
|
|
317
|
+
isGlobal: globalSFCScope,
|
|
318
|
+
useClassComponent,
|
|
319
|
+
bridge,
|
|
320
|
+
exportESM: esm,
|
|
321
|
+
forceStringify
|
|
322
|
+
}
|
|
323
|
+
);
|
|
283
324
|
debug("parseOptions", parseOptions);
|
|
284
|
-
const { code: generatedCode, map } = generate(
|
|
325
|
+
const { code: generatedCode, map } = generate(
|
|
326
|
+
code,
|
|
327
|
+
parseOptions,
|
|
328
|
+
bridge ? createBridgeCodeGenerator(code, query) : void 0
|
|
329
|
+
);
|
|
285
330
|
debug("generated code", generatedCode);
|
|
286
331
|
debug("sourcemap", map, sourceMap);
|
|
287
332
|
if (code === generatedCode)
|
|
@@ -305,17 +350,33 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
305
350
|
}
|
|
306
351
|
debug("langInfo", langInfo);
|
|
307
352
|
const generate = /\.?json5?/.test(langInfo) ? bundleUtils.generateJSON : bundleUtils.generateYAML;
|
|
308
|
-
const parseOptions = getOptions(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
353
|
+
const parseOptions = getOptions(
|
|
354
|
+
filename,
|
|
355
|
+
isProduction,
|
|
356
|
+
query,
|
|
357
|
+
sourceMap,
|
|
358
|
+
{
|
|
359
|
+
inSourceMap,
|
|
360
|
+
isGlobal: globalSFCScope,
|
|
361
|
+
useClassComponent,
|
|
362
|
+
bridge,
|
|
363
|
+
exportESM: esm,
|
|
364
|
+
forceStringify
|
|
365
|
+
}
|
|
366
|
+
);
|
|
316
367
|
debug("parseOptions", parseOptions);
|
|
317
|
-
const source = await getCode(
|
|
318
|
-
|
|
368
|
+
const source = await getCode(
|
|
369
|
+
code,
|
|
370
|
+
filename,
|
|
371
|
+
sourceMap,
|
|
372
|
+
query,
|
|
373
|
+
meta.framework
|
|
374
|
+
);
|
|
375
|
+
const { code: generatedCode, map } = generate(
|
|
376
|
+
source,
|
|
377
|
+
parseOptions,
|
|
378
|
+
bridge ? createBridgeCodeGenerator(source, query) : void 0
|
|
379
|
+
);
|
|
319
380
|
debug("generated code", generatedCode);
|
|
320
381
|
debug("sourcemap", map, sourceMap);
|
|
321
382
|
if (code === generatedCode)
|
|
@@ -378,7 +439,11 @@ async function generateBundleResources(resources, query, isProduction, {
|
|
|
378
439
|
forceStringify
|
|
379
440
|
});
|
|
380
441
|
parseOptions.type = "bare";
|
|
381
|
-
const { code } = generate(
|
|
442
|
+
const { code } = generate(
|
|
443
|
+
source,
|
|
444
|
+
parseOptions,
|
|
445
|
+
bridge ? createBridgeCodeGenerator(source, query) : void 0
|
|
446
|
+
);
|
|
382
447
|
debug("generated code", code);
|
|
383
448
|
codes.push(`${JSON.stringify(name)}: ${code}`);
|
|
384
449
|
}
|
|
@@ -439,8 +504,20 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
439
504
|
onWarn: (msg) => {
|
|
440
505
|
warn(`${filename} ${msg}`);
|
|
441
506
|
},
|
|
442
|
-
onError: (msg) => {
|
|
443
|
-
|
|
507
|
+
onError: (msg, extra) => {
|
|
508
|
+
const codeFrame = shared.generateCodeFrame(
|
|
509
|
+
extra?.source || extra?.location?.source || "",
|
|
510
|
+
extra?.location?.start.column,
|
|
511
|
+
extra?.location?.end.column
|
|
512
|
+
);
|
|
513
|
+
const errMssage = `${msg} (error code: ${extra?.code}) in ${filename}
|
|
514
|
+
target message: ${extra?.source}
|
|
515
|
+
target message path: ${extra?.path}
|
|
516
|
+
|
|
517
|
+
${codeFrame}
|
|
518
|
+
`;
|
|
519
|
+
error(errMssage);
|
|
520
|
+
throw new Error(errMssage);
|
|
444
521
|
}
|
|
445
522
|
};
|
|
446
523
|
if (isCustomBlock(query)) {
|
package/lib/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createUnplugin } from 'unplugin';
|
|
|
2
2
|
import { normalize, parse } from 'pathe';
|
|
3
3
|
import createDebug from 'debug';
|
|
4
4
|
import fg from 'fast-glob';
|
|
5
|
-
import { isString, isArray, isBoolean, isObject,
|
|
5
|
+
import { isString, isArray, isBoolean, isObject, isNumber, isEmptyObject, assign, generateCodeFrame } from '@intlify/shared';
|
|
6
6
|
import { createFilter } from '@rollup/pluginutils';
|
|
7
7
|
import { checkInstallPackage, generateJSON, generateYAML } from '@intlify/bundle-utils';
|
|
8
8
|
import { parse as parse$1 } from '@vue/compiler-sfc';
|
|
@@ -15,7 +15,9 @@ function parseVueRequest(id) {
|
|
|
15
15
|
const [filename, rawQuery] = id.split(`?`, 2);
|
|
16
16
|
const params = new URLSearchParams(rawQuery);
|
|
17
17
|
const ret = {};
|
|
18
|
-
const langPart = Object.keys(Object.fromEntries(params)).find(
|
|
18
|
+
const langPart = Object.keys(Object.fromEntries(params)).find(
|
|
19
|
+
(key) => /lang\./i.test(key)
|
|
20
|
+
);
|
|
19
21
|
ret.vue = params.has("vue");
|
|
20
22
|
ret.global = params.has("global");
|
|
21
23
|
ret.src = params.has("src");
|
|
@@ -83,11 +85,23 @@ function raiseError(message) {
|
|
|
83
85
|
throw new Error(`[unplugin-vue-i18n] ${message}`);
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
function checkVueI18nBridgeInstallPackage(debug) {
|
|
89
|
+
let ret = false;
|
|
90
|
+
try {
|
|
91
|
+
debug(`vue-i18n-bridge load path: ${require.resolve("vue-i18n-bridge")}`);
|
|
92
|
+
ret = true;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
debug(`cannot find 'vue-i18n-bridge'`, e);
|
|
95
|
+
}
|
|
96
|
+
return ret;
|
|
97
|
+
}
|
|
98
|
+
|
|
86
99
|
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
87
100
|
const INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID = "@intlify/vite-plugin-vue-i18n/messages";
|
|
88
101
|
const VIRTUAL_PREFIX = "\0";
|
|
89
102
|
const debug = createDebug("unplugin-vue-i18n");
|
|
90
103
|
const installedPkg = checkInstallPackage("@intlify/unplugin-vue-i18n", debug);
|
|
104
|
+
const installedVueI18nBridge = checkVueI18nBridgeInstallPackage(debug);
|
|
91
105
|
const unplugin = createUnplugin((options = {}, meta) => {
|
|
92
106
|
debug("plugin options:", options, meta.framework);
|
|
93
107
|
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
@@ -119,7 +133,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
119
133
|
warn(`'useVueI18nImportName' option is experimental`);
|
|
120
134
|
}
|
|
121
135
|
debug("useVueI18nImportName", useVueI18nImportName);
|
|
122
|
-
const getAliasName = () => installedPkg === "petite-vue-i18n" && isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : `${installedPkg}`;
|
|
136
|
+
const getAliasName = () => installedVueI18nBridge && installedPkg === "vue-i18n" ? "vue-i18n-bridge" : installedPkg === "petite-vue-i18n" && isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : `${installedPkg}`;
|
|
123
137
|
const esm = isBoolean(options.esm) ? options.esm : true;
|
|
124
138
|
debug("esm", esm);
|
|
125
139
|
let isProduction = false;
|
|
@@ -140,7 +154,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
140
154
|
config.resolve.alias[getAliasName()] = `${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`;
|
|
141
155
|
}
|
|
142
156
|
debug(`alias name: ${getAliasName()}`);
|
|
143
|
-
debug(
|
|
157
|
+
debug(
|
|
158
|
+
`set ${installedPkg} runtime only: ${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`
|
|
159
|
+
);
|
|
144
160
|
} else if (command === "serve" && installedPkg === "petite-vue-i18n" && useVueI18nImportName) {
|
|
145
161
|
normalizeConfigResolveAlias(config.resolve, meta.framework);
|
|
146
162
|
if (isArray(config.resolve.alias)) {
|
|
@@ -155,15 +171,21 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
155
171
|
}
|
|
156
172
|
config.define = config.define || {};
|
|
157
173
|
config.define["__VUE_I18N_LEGACY_API__"] = !compositionOnly;
|
|
158
|
-
debug(
|
|
174
|
+
debug(
|
|
175
|
+
`set __VUE_I18N_LEGACY_API__ is '${config.define["__VUE_I18N_LEGACY_API__"]}'`
|
|
176
|
+
);
|
|
159
177
|
config.define["__VUE_I18N_FULL_INSTALL__"] = fullInstall;
|
|
160
|
-
debug(
|
|
178
|
+
debug(
|
|
179
|
+
`set __VUE_I18N_FULL_INSTALL__ is '${config.define["__VUE_I18N_FULL_INSTALL__"]}'`
|
|
180
|
+
);
|
|
161
181
|
config.define["__VUE_I18N_PROD_DEVTOOLS__"] = false;
|
|
162
182
|
},
|
|
163
183
|
configResolved(config) {
|
|
164
184
|
isProduction = config.isProduction;
|
|
165
185
|
sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
|
|
166
|
-
debug(
|
|
186
|
+
debug(
|
|
187
|
+
`configResolved: isProduction = ${isProduction}, sourceMap = ${sourceMap}`
|
|
188
|
+
);
|
|
167
189
|
const jsonPlugin = config.plugins.find((p) => p.name === "vite:json");
|
|
168
190
|
if (jsonPlugin) {
|
|
169
191
|
const orgTransform = jsonPlugin.transform;
|
|
@@ -191,11 +213,13 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
191
213
|
}
|
|
192
214
|
loadWebpack().then((webpack) => {
|
|
193
215
|
if (webpack) {
|
|
194
|
-
compiler.options.plugins.push(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
216
|
+
compiler.options.plugins.push(
|
|
217
|
+
new webpack.DefinePlugin({
|
|
218
|
+
__VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
|
|
219
|
+
__VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
|
|
220
|
+
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
221
|
+
})
|
|
222
|
+
);
|
|
199
223
|
debug(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
|
|
200
224
|
debug(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
201
225
|
} else {
|
|
@@ -213,7 +237,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
213
237
|
resolveId(id, importer) {
|
|
214
238
|
debug("resolveId", id, importer);
|
|
215
239
|
if (id === INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) {
|
|
216
|
-
warn(
|
|
240
|
+
warn(
|
|
241
|
+
`deprected '${INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID}', you should switch to '${INTLIFY_BUNDLE_IMPORT_ID}'`
|
|
242
|
+
);
|
|
217
243
|
return asVirtualId(id, meta.framework);
|
|
218
244
|
}
|
|
219
245
|
if (id === INTLIFY_BUNDLE_IMPORT_ID) {
|
|
@@ -223,19 +249,28 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
223
249
|
async load(id) {
|
|
224
250
|
debug("load", id);
|
|
225
251
|
const { query } = parseVueRequest(id);
|
|
226
|
-
if ([INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(
|
|
252
|
+
if ([INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(
|
|
253
|
+
getVirtualId(id, meta.framework)
|
|
254
|
+
) && include) {
|
|
227
255
|
let resourcePaths = [];
|
|
228
256
|
const includePaths = isArray(include) ? include : [include];
|
|
229
257
|
for (const inc of includePaths) {
|
|
230
258
|
resourcePaths = [...resourcePaths, ...await fg(inc)];
|
|
231
259
|
}
|
|
232
|
-
resourcePaths = resourcePaths.filter(
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
260
|
+
resourcePaths = resourcePaths.filter(
|
|
261
|
+
(el, pos) => resourcePaths.indexOf(el) === pos
|
|
262
|
+
);
|
|
263
|
+
const code = await generateBundleResources(
|
|
264
|
+
resourcePaths,
|
|
265
|
+
query,
|
|
266
|
+
isProduction,
|
|
267
|
+
{
|
|
268
|
+
forceStringify,
|
|
269
|
+
bridge,
|
|
270
|
+
exportESM: esm,
|
|
271
|
+
useClassComponent
|
|
272
|
+
}
|
|
273
|
+
);
|
|
239
274
|
return {
|
|
240
275
|
code,
|
|
241
276
|
map: { mappings: "" }
|
|
@@ -260,16 +295,26 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
260
295
|
if (/\.(json5?|ya?ml)$/.test(id) && filter(id)) {
|
|
261
296
|
langInfo = parse(filename).ext;
|
|
262
297
|
const generate = /\.?json5?/.test(langInfo) ? generateJSON : generateYAML;
|
|
263
|
-
const parseOptions = getOptions(
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
298
|
+
const parseOptions = getOptions(
|
|
299
|
+
filename,
|
|
300
|
+
isProduction,
|
|
301
|
+
query,
|
|
302
|
+
sourceMap,
|
|
303
|
+
{
|
|
304
|
+
inSourceMap,
|
|
305
|
+
isGlobal: globalSFCScope,
|
|
306
|
+
useClassComponent,
|
|
307
|
+
bridge,
|
|
308
|
+
exportESM: esm,
|
|
309
|
+
forceStringify
|
|
310
|
+
}
|
|
311
|
+
);
|
|
271
312
|
debug("parseOptions", parseOptions);
|
|
272
|
-
const { code: generatedCode, map } = generate(
|
|
313
|
+
const { code: generatedCode, map } = generate(
|
|
314
|
+
code,
|
|
315
|
+
parseOptions,
|
|
316
|
+
bridge ? createBridgeCodeGenerator(code, query) : void 0
|
|
317
|
+
);
|
|
273
318
|
debug("generated code", generatedCode);
|
|
274
319
|
debug("sourcemap", map, sourceMap);
|
|
275
320
|
if (code === generatedCode)
|
|
@@ -293,17 +338,33 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
293
338
|
}
|
|
294
339
|
debug("langInfo", langInfo);
|
|
295
340
|
const generate = /\.?json5?/.test(langInfo) ? generateJSON : generateYAML;
|
|
296
|
-
const parseOptions = getOptions(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
341
|
+
const parseOptions = getOptions(
|
|
342
|
+
filename,
|
|
343
|
+
isProduction,
|
|
344
|
+
query,
|
|
345
|
+
sourceMap,
|
|
346
|
+
{
|
|
347
|
+
inSourceMap,
|
|
348
|
+
isGlobal: globalSFCScope,
|
|
349
|
+
useClassComponent,
|
|
350
|
+
bridge,
|
|
351
|
+
exportESM: esm,
|
|
352
|
+
forceStringify
|
|
353
|
+
}
|
|
354
|
+
);
|
|
304
355
|
debug("parseOptions", parseOptions);
|
|
305
|
-
const source = await getCode(
|
|
306
|
-
|
|
356
|
+
const source = await getCode(
|
|
357
|
+
code,
|
|
358
|
+
filename,
|
|
359
|
+
sourceMap,
|
|
360
|
+
query,
|
|
361
|
+
meta.framework
|
|
362
|
+
);
|
|
363
|
+
const { code: generatedCode, map } = generate(
|
|
364
|
+
source,
|
|
365
|
+
parseOptions,
|
|
366
|
+
bridge ? createBridgeCodeGenerator(source, query) : void 0
|
|
367
|
+
);
|
|
307
368
|
debug("generated code", generatedCode);
|
|
308
369
|
debug("sourcemap", map, sourceMap);
|
|
309
370
|
if (code === generatedCode)
|
|
@@ -366,7 +427,11 @@ async function generateBundleResources(resources, query, isProduction, {
|
|
|
366
427
|
forceStringify
|
|
367
428
|
});
|
|
368
429
|
parseOptions.type = "bare";
|
|
369
|
-
const { code } = generate(
|
|
430
|
+
const { code } = generate(
|
|
431
|
+
source,
|
|
432
|
+
parseOptions,
|
|
433
|
+
bridge ? createBridgeCodeGenerator(source, query) : void 0
|
|
434
|
+
);
|
|
370
435
|
debug("generated code", code);
|
|
371
436
|
codes.push(`${JSON.stringify(name)}: ${code}`);
|
|
372
437
|
}
|
|
@@ -427,8 +492,20 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
427
492
|
onWarn: (msg) => {
|
|
428
493
|
warn(`${filename} ${msg}`);
|
|
429
494
|
},
|
|
430
|
-
onError: (msg) => {
|
|
431
|
-
|
|
495
|
+
onError: (msg, extra) => {
|
|
496
|
+
const codeFrame = generateCodeFrame(
|
|
497
|
+
extra?.source || extra?.location?.source || "",
|
|
498
|
+
extra?.location?.start.column,
|
|
499
|
+
extra?.location?.end.column
|
|
500
|
+
);
|
|
501
|
+
const errMssage = `${msg} (error code: ${extra?.code}) in ${filename}
|
|
502
|
+
target message: ${extra?.source}
|
|
503
|
+
target message path: ${extra?.path}
|
|
504
|
+
|
|
505
|
+
${codeFrame}
|
|
506
|
+
`;
|
|
507
|
+
error(errMssage);
|
|
508
|
+
throw new Error(errMssage);
|
|
432
509
|
}
|
|
433
510
|
};
|
|
434
511
|
if (isCustomBlock(query)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "unplugin for Vue I18n",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"petite-vue-i18n": "*",
|
|
14
|
-
"vue-i18n": "*"
|
|
14
|
+
"vue-i18n": "*",
|
|
15
|
+
"vue-i18n-bridge": "*"
|
|
15
16
|
},
|
|
16
17
|
"peerDependenciesMeta": {
|
|
17
18
|
"petite-vue-i18n": {
|
|
@@ -19,10 +20,13 @@
|
|
|
19
20
|
},
|
|
20
21
|
"vue-i18n": {
|
|
21
22
|
"optional": true
|
|
23
|
+
},
|
|
24
|
+
"vue-i18n-bridge": {
|
|
25
|
+
"optional": true
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
"dependencies": {
|
|
25
|
-
"@intlify/bundle-utils": "
|
|
29
|
+
"@intlify/bundle-utils": "^3.1.2",
|
|
26
30
|
"@intlify/shared": "next",
|
|
27
31
|
"@rollup/pluginutils": "^4.2.0",
|
|
28
32
|
"@vue/compiler-sfc": "^3.2.23",
|
|
@@ -37,7 +41,7 @@
|
|
|
37
41
|
},
|
|
38
42
|
"devDependencies": {
|
|
39
43
|
"mlly": "^0.5.2",
|
|
40
|
-
"unbuild": "^0.
|
|
44
|
+
"unbuild": "^0.8.11"
|
|
41
45
|
},
|
|
42
46
|
"engines": {
|
|
43
47
|
"node": ">= 14.16"
|