@intlify/unplugin-vue-i18n 12.0.0-alpha.3 → 12.0.0-alpha.4
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 +32 -109
- package/lib/index.mjs +32 -109
- package/package.json +4 -4
package/lib/index.cjs
CHANGED
|
@@ -140,7 +140,7 @@ function getVueCompiler(vuePlugin) {
|
|
|
140
140
|
|
|
141
141
|
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
142
142
|
const VIRTUAL_PREFIX = "\0";
|
|
143
|
-
const supportedFileExtensionsRE = /\.(json5?|ya?ml|[c|m]?[j|t]s)$/;
|
|
143
|
+
const supportedFileExtensionsRE = /\.(?:json5?|ya?ml|[c|m]?[j|t]s)$/;
|
|
144
144
|
const RE_SFC_I18N_CUSTOM_BLOCK = /\?vue&type=i18n/;
|
|
145
145
|
const RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK = /blockType=i18n/;
|
|
146
146
|
const debug$1 = createDebug__default(resolveNamespace("resource"));
|
|
@@ -148,7 +148,7 @@ function resourcePlugin(opts, meta) {
|
|
|
148
148
|
const importedResources = /* @__PURE__ */ new Set();
|
|
149
149
|
function resolveIncludeExclude() {
|
|
150
150
|
const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
|
|
151
|
-
return opts.include ? [[...opts.include, customBlockInclude], opts.exclude] : [[
|
|
151
|
+
return opts.include ? [[...opts.include, customBlockInclude], opts.exclude] : [[customBlockInclude], void 0];
|
|
152
152
|
}
|
|
153
153
|
function resolveIncludeExcludeForLegacy() {
|
|
154
154
|
const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
|
|
@@ -171,22 +171,6 @@ function resourcePlugin(opts, meta) {
|
|
|
171
171
|
}
|
|
172
172
|
return (val) => _filter(val) || importedResources.has(val);
|
|
173
173
|
}
|
|
174
|
-
const VITE_VIRTUAL_PREFIX = "\0intlify-i18n-";
|
|
175
|
-
const virtualIdToRealPath = /* @__PURE__ */ new Map();
|
|
176
|
-
const realPathToVirtualId = /* @__PURE__ */ new Map();
|
|
177
|
-
let virtualCounter = 0;
|
|
178
|
-
function intlifyVirtualize(realPath) {
|
|
179
|
-
let virtualId = realPathToVirtualId.get(realPath);
|
|
180
|
-
if (!virtualId) {
|
|
181
|
-
virtualId = `${VITE_VIRTUAL_PREFIX}${virtualCounter++}`;
|
|
182
|
-
virtualIdToRealPath.set(virtualId, realPath);
|
|
183
|
-
realPathToVirtualId.set(realPath, virtualId);
|
|
184
|
-
}
|
|
185
|
-
return virtualId;
|
|
186
|
-
}
|
|
187
|
-
function isIntlifyVirtualId(id) {
|
|
188
|
-
return virtualIdToRealPath.has(id);
|
|
189
|
-
}
|
|
190
174
|
debug$1(`vue-i18n alias name: ${opts.module}`);
|
|
191
175
|
const ctx = {
|
|
192
176
|
prod: false,
|
|
@@ -206,7 +190,7 @@ function resourcePlugin(opts, meta) {
|
|
|
206
190
|
}
|
|
207
191
|
function result(code) {
|
|
208
192
|
if (meta.framework === "vite") {
|
|
209
|
-
return { code, map: { mappings: "" } };
|
|
193
|
+
return { code, map: { mappings: "" }, moduleType: "js" };
|
|
210
194
|
}
|
|
211
195
|
return { code };
|
|
212
196
|
}
|
|
@@ -315,101 +299,24 @@ function resourcePlugin(opts, meta) {
|
|
|
315
299
|
if (id === INTLIFY_BUNDLE_IMPORT_ID) {
|
|
316
300
|
return asVirtualId(id, meta.framework);
|
|
317
301
|
}
|
|
318
|
-
if (meta.framework === "vite" && !hasViteJsonPlugin) {
|
|
319
|
-
if (id.includes("?vue&type=i18n") && /[?&]lang\.(?:json|json5)(?:$|&)/.test(id)) {
|
|
320
|
-
return intlifyVirtualize(id);
|
|
321
|
-
}
|
|
322
|
-
const idPath = id.split("?")[0];
|
|
323
|
-
if (!supportedFileExtensionsRE.test(idPath)) return;
|
|
324
|
-
let resolvedPath;
|
|
325
|
-
if (idPath.startsWith(".")) {
|
|
326
|
-
const realImporter = importer && isIntlifyVirtualId(importer) ? virtualIdToRealPath.get(importer) : importer;
|
|
327
|
-
if (!realImporter) return;
|
|
328
|
-
resolvedPath = node_path.resolve(node_path.dirname(realImporter), idPath);
|
|
329
|
-
} else if (idPath.startsWith("/") || /^[a-z]:[/\\]/i.test(idPath)) {
|
|
330
|
-
resolvedPath = idPath;
|
|
331
|
-
} else {
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
const filter = await getFilter();
|
|
335
|
-
if (!filter(resolvedPath)) return;
|
|
336
|
-
return intlifyVirtualize(resolvedPath);
|
|
337
|
-
}
|
|
338
302
|
},
|
|
339
303
|
loadInclude(id) {
|
|
340
|
-
|
|
341
|
-
return isIntlifyVirtualId(id);
|
|
304
|
+
return INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework);
|
|
342
305
|
},
|
|
343
306
|
async load(id) {
|
|
344
307
|
debug$1("load", id);
|
|
345
|
-
if (INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework)
|
|
308
|
+
if (INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework)) {
|
|
309
|
+
if (resourcePaths.size === 0) {
|
|
310
|
+
warn(
|
|
311
|
+
`\`${INTLIFY_BUNDLE_IMPORT_ID}\` is imported, but no locale resources match \`include\``
|
|
312
|
+
);
|
|
313
|
+
}
|
|
346
314
|
const code = generateBundleResources(resourcePaths);
|
|
347
315
|
for (const p of resourcePaths) {
|
|
348
316
|
this.addWatchFile(p);
|
|
349
317
|
}
|
|
350
318
|
return result(code);
|
|
351
319
|
}
|
|
352
|
-
if (isIntlifyVirtualId(id)) {
|
|
353
|
-
const realId = virtualIdToRealPath.get(id);
|
|
354
|
-
if (realId.includes("?vue&type=i18n")) {
|
|
355
|
-
const { filename, query } = parseVueRequest(realId);
|
|
356
|
-
this.addWatchFile(filename);
|
|
357
|
-
const sfcSource = readFile(filename);
|
|
358
|
-
const { descriptor } = getSfcParser()(sfcSource, {
|
|
359
|
-
sourceMap: ctx.sourceMap,
|
|
360
|
-
filename
|
|
361
|
-
});
|
|
362
|
-
const block = descriptor.customBlocks[query.index];
|
|
363
|
-
if (!block) return;
|
|
364
|
-
let source = block.src ? readFile(block.src) : block.content;
|
|
365
|
-
if (typeof opts.transformI18nBlock === "function") {
|
|
366
|
-
const modifiedSource = opts.transformI18nBlock(source);
|
|
367
|
-
if (modifiedSource && typeof modifiedSource === "string") {
|
|
368
|
-
source = modifiedSource;
|
|
369
|
-
} else {
|
|
370
|
-
warn("transformI18nBlock should return a string");
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
const langInfo2 = query.lang || opts.defaultSFCLang;
|
|
374
|
-
const generate2 = getGenerator(langInfo2, bundleUtils.generateYAML);
|
|
375
|
-
const parseOptions2 = getOptions(filename, ctx, query, {
|
|
376
|
-
...opts,
|
|
377
|
-
allowDynamic: false,
|
|
378
|
-
transformI18nBlock: void 0
|
|
379
|
-
});
|
|
380
|
-
const { code: generatedCode } = generate2(source, parseOptions2);
|
|
381
|
-
return result(generatedCode);
|
|
382
|
-
}
|
|
383
|
-
const realPath = realId;
|
|
384
|
-
this.addWatchFile(realPath);
|
|
385
|
-
const code = readFile(realPath);
|
|
386
|
-
const imports = mlly.findStaticImports(code);
|
|
387
|
-
for (const p of imports) {
|
|
388
|
-
const res = node_path.resolve(node_path.dirname(realPath), p.specifier);
|
|
389
|
-
importedResources.add(res);
|
|
390
|
-
}
|
|
391
|
-
const langInfo = node_path.parse(realPath).ext;
|
|
392
|
-
const generate = getGenerator(langInfo);
|
|
393
|
-
const parseOptions = getOptions(realPath, ctx, {}, {
|
|
394
|
-
...opts,
|
|
395
|
-
transformI18nBlock: void 0
|
|
396
|
-
});
|
|
397
|
-
try {
|
|
398
|
-
const { code: generatedCode } = generate(code, parseOptions);
|
|
399
|
-
return result(generatedCode);
|
|
400
|
-
} catch (err) {
|
|
401
|
-
if (err instanceof bundleUtils.DynamicResourceError) {
|
|
402
|
-
error(
|
|
403
|
-
`Unable to precompile or optimize \`${realPath}\` - excluding from virtual bundle \`${INTLIFY_BUNDLE_IMPORT_ID}\`.
|
|
404
|
-
`,
|
|
405
|
-
err
|
|
406
|
-
);
|
|
407
|
-
return `export default {}`;
|
|
408
|
-
} else {
|
|
409
|
-
throw err;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
320
|
},
|
|
414
321
|
transformInclude(id) {
|
|
415
322
|
debug$1("transformInclude", id);
|
|
@@ -432,7 +339,6 @@ function resourcePlugin(opts, meta) {
|
|
|
432
339
|
return supportedFileExtensionsRE.test(filename) && filterWithImported(filename) && isResourcePath;
|
|
433
340
|
},
|
|
434
341
|
async transform(code, id) {
|
|
435
|
-
if (isIntlifyVirtualId(id)) return;
|
|
436
342
|
const { filename, query } = parseVueRequest(id);
|
|
437
343
|
debug$1("transform", id, JSON.stringify(query), filename);
|
|
438
344
|
let langInfo = opts.defaultSFCLang;
|
|
@@ -493,7 +399,7 @@ function resourcePlugin(opts, meta) {
|
|
|
493
399
|
}
|
|
494
400
|
}
|
|
495
401
|
const generate = getGenerator(langInfo, bundleUtils.generateYAML);
|
|
496
|
-
const { code: generatedCode, map } = generate(source, parseOptions);
|
|
402
|
+
const { code: generatedCode, map } = /\.?[cm]?[jt]s$/.test(langInfo) ? generateJsTsBlock(generate, source, parseOptions) : generate(source, parseOptions);
|
|
497
403
|
debug$1("generated code", generatedCode);
|
|
498
404
|
debug$1("sourcemap", map, ctx.sourceMap);
|
|
499
405
|
if (code !== generatedCode) {
|
|
@@ -507,17 +413,28 @@ function getGenerator(ext, fallback = bundleUtils.generateJSON) {
|
|
|
507
413
|
if (/\.?json5?$/.test(ext)) {
|
|
508
414
|
return bundleUtils.generateJSON;
|
|
509
415
|
}
|
|
510
|
-
if (
|
|
416
|
+
if (/\.?ya?ml$/.test(ext)) {
|
|
511
417
|
return bundleUtils.generateYAML;
|
|
512
418
|
}
|
|
513
|
-
if (
|
|
419
|
+
if (/\.?[cm]?js$/.test(ext)) {
|
|
514
420
|
return bundleUtils.generateJavaScript;
|
|
515
421
|
}
|
|
516
|
-
if (
|
|
422
|
+
if (/\.?[cm]?ts$/.test(ext)) {
|
|
517
423
|
return bundleUtils.generateTypescript;
|
|
518
424
|
}
|
|
519
425
|
return fallback;
|
|
520
426
|
}
|
|
427
|
+
function generateJsTsBlock(generate, source, options) {
|
|
428
|
+
try {
|
|
429
|
+
return generate(source, options);
|
|
430
|
+
} catch (error2) {
|
|
431
|
+
try {
|
|
432
|
+
return generate(`export default ${source.replace(/^[\s;]+/, "")}`, options);
|
|
433
|
+
} catch (wrappedError) {
|
|
434
|
+
throw /^\s*export\s+default\b/m.test(source) ? error2 : wrappedError;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
521
438
|
async function loadWebpack() {
|
|
522
439
|
const mod = await import('webpack');
|
|
523
440
|
return mod.default || mod;
|
|
@@ -580,7 +497,7 @@ function getCode(source, filename, sourceMap, query, parser, meta) {
|
|
|
580
497
|
const result = parser(readFile(filename), { sourceMap, filename });
|
|
581
498
|
const block = result.descriptor.customBlocks[query.index];
|
|
582
499
|
if (block) {
|
|
583
|
-
const code = block.src ? readFile(block.src) : block.content;
|
|
500
|
+
const code = block.src ? readFile(resolveBlockSrc(block.src, filename)) : block.content;
|
|
584
501
|
debug$1(`getCode (${meta.framework}) ${query.index} from SFC`, code);
|
|
585
502
|
return code;
|
|
586
503
|
}
|
|
@@ -628,6 +545,12 @@ function getOptions(filename, ctx, query, opts) {
|
|
|
628
545
|
isGlobal: false
|
|
629
546
|
});
|
|
630
547
|
}
|
|
548
|
+
function resolveBlockSrc(src, sfcFilename) {
|
|
549
|
+
if (src.startsWith(".") || !src.startsWith("/") && !/^[a-z]:[/\\]/i.test(src)) {
|
|
550
|
+
return node_path.resolve(node_path.dirname(sfcFilename), src);
|
|
551
|
+
}
|
|
552
|
+
return src;
|
|
553
|
+
}
|
|
631
554
|
function getVirtualId(id, framework = "vite") {
|
|
632
555
|
return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
|
|
633
556
|
}
|
package/lib/index.mjs
CHANGED
|
@@ -129,7 +129,7 @@ function getVueCompiler(vuePlugin) {
|
|
|
129
129
|
|
|
130
130
|
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
131
131
|
const VIRTUAL_PREFIX = "\0";
|
|
132
|
-
const supportedFileExtensionsRE = /\.(json5?|ya?ml|[c|m]?[j|t]s)$/;
|
|
132
|
+
const supportedFileExtensionsRE = /\.(?:json5?|ya?ml|[c|m]?[j|t]s)$/;
|
|
133
133
|
const RE_SFC_I18N_CUSTOM_BLOCK = /\?vue&type=i18n/;
|
|
134
134
|
const RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK = /blockType=i18n/;
|
|
135
135
|
const debug$1 = createDebug(resolveNamespace("resource"));
|
|
@@ -137,7 +137,7 @@ function resourcePlugin(opts, meta) {
|
|
|
137
137
|
const importedResources = /* @__PURE__ */ new Set();
|
|
138
138
|
function resolveIncludeExclude() {
|
|
139
139
|
const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
|
|
140
|
-
return opts.include ? [[...opts.include, customBlockInclude], opts.exclude] : [[
|
|
140
|
+
return opts.include ? [[...opts.include, customBlockInclude], opts.exclude] : [[customBlockInclude], void 0];
|
|
141
141
|
}
|
|
142
142
|
function resolveIncludeExcludeForLegacy() {
|
|
143
143
|
const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
|
|
@@ -160,22 +160,6 @@ function resourcePlugin(opts, meta) {
|
|
|
160
160
|
}
|
|
161
161
|
return (val) => _filter(val) || importedResources.has(val);
|
|
162
162
|
}
|
|
163
|
-
const VITE_VIRTUAL_PREFIX = "\0intlify-i18n-";
|
|
164
|
-
const virtualIdToRealPath = /* @__PURE__ */ new Map();
|
|
165
|
-
const realPathToVirtualId = /* @__PURE__ */ new Map();
|
|
166
|
-
let virtualCounter = 0;
|
|
167
|
-
function intlifyVirtualize(realPath) {
|
|
168
|
-
let virtualId = realPathToVirtualId.get(realPath);
|
|
169
|
-
if (!virtualId) {
|
|
170
|
-
virtualId = `${VITE_VIRTUAL_PREFIX}${virtualCounter++}`;
|
|
171
|
-
virtualIdToRealPath.set(virtualId, realPath);
|
|
172
|
-
realPathToVirtualId.set(realPath, virtualId);
|
|
173
|
-
}
|
|
174
|
-
return virtualId;
|
|
175
|
-
}
|
|
176
|
-
function isIntlifyVirtualId(id) {
|
|
177
|
-
return virtualIdToRealPath.has(id);
|
|
178
|
-
}
|
|
179
163
|
debug$1(`vue-i18n alias name: ${opts.module}`);
|
|
180
164
|
const ctx = {
|
|
181
165
|
prod: false,
|
|
@@ -195,7 +179,7 @@ function resourcePlugin(opts, meta) {
|
|
|
195
179
|
}
|
|
196
180
|
function result(code) {
|
|
197
181
|
if (meta.framework === "vite") {
|
|
198
|
-
return { code, map: { mappings: "" } };
|
|
182
|
+
return { code, map: { mappings: "" }, moduleType: "js" };
|
|
199
183
|
}
|
|
200
184
|
return { code };
|
|
201
185
|
}
|
|
@@ -304,101 +288,24 @@ function resourcePlugin(opts, meta) {
|
|
|
304
288
|
if (id === INTLIFY_BUNDLE_IMPORT_ID) {
|
|
305
289
|
return asVirtualId(id, meta.framework);
|
|
306
290
|
}
|
|
307
|
-
if (meta.framework === "vite" && !hasViteJsonPlugin) {
|
|
308
|
-
if (id.includes("?vue&type=i18n") && /[?&]lang\.(?:json|json5)(?:$|&)/.test(id)) {
|
|
309
|
-
return intlifyVirtualize(id);
|
|
310
|
-
}
|
|
311
|
-
const idPath = id.split("?")[0];
|
|
312
|
-
if (!supportedFileExtensionsRE.test(idPath)) return;
|
|
313
|
-
let resolvedPath;
|
|
314
|
-
if (idPath.startsWith(".")) {
|
|
315
|
-
const realImporter = importer && isIntlifyVirtualId(importer) ? virtualIdToRealPath.get(importer) : importer;
|
|
316
|
-
if (!realImporter) return;
|
|
317
|
-
resolvedPath = resolve(dirname(realImporter), idPath);
|
|
318
|
-
} else if (idPath.startsWith("/") || /^[a-z]:[/\\]/i.test(idPath)) {
|
|
319
|
-
resolvedPath = idPath;
|
|
320
|
-
} else {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
const filter = await getFilter();
|
|
324
|
-
if (!filter(resolvedPath)) return;
|
|
325
|
-
return intlifyVirtualize(resolvedPath);
|
|
326
|
-
}
|
|
327
291
|
},
|
|
328
292
|
loadInclude(id) {
|
|
329
|
-
|
|
330
|
-
return isIntlifyVirtualId(id);
|
|
293
|
+
return INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework);
|
|
331
294
|
},
|
|
332
295
|
async load(id) {
|
|
333
296
|
debug$1("load", id);
|
|
334
|
-
if (INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework)
|
|
297
|
+
if (INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework)) {
|
|
298
|
+
if (resourcePaths.size === 0) {
|
|
299
|
+
warn(
|
|
300
|
+
`\`${INTLIFY_BUNDLE_IMPORT_ID}\` is imported, but no locale resources match \`include\``
|
|
301
|
+
);
|
|
302
|
+
}
|
|
335
303
|
const code = generateBundleResources(resourcePaths);
|
|
336
304
|
for (const p of resourcePaths) {
|
|
337
305
|
this.addWatchFile(p);
|
|
338
306
|
}
|
|
339
307
|
return result(code);
|
|
340
308
|
}
|
|
341
|
-
if (isIntlifyVirtualId(id)) {
|
|
342
|
-
const realId = virtualIdToRealPath.get(id);
|
|
343
|
-
if (realId.includes("?vue&type=i18n")) {
|
|
344
|
-
const { filename, query } = parseVueRequest(realId);
|
|
345
|
-
this.addWatchFile(filename);
|
|
346
|
-
const sfcSource = readFile(filename);
|
|
347
|
-
const { descriptor } = getSfcParser()(sfcSource, {
|
|
348
|
-
sourceMap: ctx.sourceMap,
|
|
349
|
-
filename
|
|
350
|
-
});
|
|
351
|
-
const block = descriptor.customBlocks[query.index];
|
|
352
|
-
if (!block) return;
|
|
353
|
-
let source = block.src ? readFile(block.src) : block.content;
|
|
354
|
-
if (typeof opts.transformI18nBlock === "function") {
|
|
355
|
-
const modifiedSource = opts.transformI18nBlock(source);
|
|
356
|
-
if (modifiedSource && typeof modifiedSource === "string") {
|
|
357
|
-
source = modifiedSource;
|
|
358
|
-
} else {
|
|
359
|
-
warn("transformI18nBlock should return a string");
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
const langInfo2 = query.lang || opts.defaultSFCLang;
|
|
363
|
-
const generate2 = getGenerator(langInfo2, generateYAML);
|
|
364
|
-
const parseOptions2 = getOptions(filename, ctx, query, {
|
|
365
|
-
...opts,
|
|
366
|
-
allowDynamic: false,
|
|
367
|
-
transformI18nBlock: void 0
|
|
368
|
-
});
|
|
369
|
-
const { code: generatedCode } = generate2(source, parseOptions2);
|
|
370
|
-
return result(generatedCode);
|
|
371
|
-
}
|
|
372
|
-
const realPath = realId;
|
|
373
|
-
this.addWatchFile(realPath);
|
|
374
|
-
const code = readFile(realPath);
|
|
375
|
-
const imports = findStaticImports(code);
|
|
376
|
-
for (const p of imports) {
|
|
377
|
-
const res = resolve(dirname(realPath), p.specifier);
|
|
378
|
-
importedResources.add(res);
|
|
379
|
-
}
|
|
380
|
-
const langInfo = parse(realPath).ext;
|
|
381
|
-
const generate = getGenerator(langInfo);
|
|
382
|
-
const parseOptions = getOptions(realPath, ctx, {}, {
|
|
383
|
-
...opts,
|
|
384
|
-
transformI18nBlock: void 0
|
|
385
|
-
});
|
|
386
|
-
try {
|
|
387
|
-
const { code: generatedCode } = generate(code, parseOptions);
|
|
388
|
-
return result(generatedCode);
|
|
389
|
-
} catch (err) {
|
|
390
|
-
if (err instanceof DynamicResourceError) {
|
|
391
|
-
error(
|
|
392
|
-
`Unable to precompile or optimize \`${realPath}\` - excluding from virtual bundle \`${INTLIFY_BUNDLE_IMPORT_ID}\`.
|
|
393
|
-
`,
|
|
394
|
-
err
|
|
395
|
-
);
|
|
396
|
-
return `export default {}`;
|
|
397
|
-
} else {
|
|
398
|
-
throw err;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
309
|
},
|
|
403
310
|
transformInclude(id) {
|
|
404
311
|
debug$1("transformInclude", id);
|
|
@@ -421,7 +328,6 @@ function resourcePlugin(opts, meta) {
|
|
|
421
328
|
return supportedFileExtensionsRE.test(filename) && filterWithImported(filename) && isResourcePath;
|
|
422
329
|
},
|
|
423
330
|
async transform(code, id) {
|
|
424
|
-
if (isIntlifyVirtualId(id)) return;
|
|
425
331
|
const { filename, query } = parseVueRequest(id);
|
|
426
332
|
debug$1("transform", id, JSON.stringify(query), filename);
|
|
427
333
|
let langInfo = opts.defaultSFCLang;
|
|
@@ -482,7 +388,7 @@ function resourcePlugin(opts, meta) {
|
|
|
482
388
|
}
|
|
483
389
|
}
|
|
484
390
|
const generate = getGenerator(langInfo, generateYAML);
|
|
485
|
-
const { code: generatedCode, map } = generate(source, parseOptions);
|
|
391
|
+
const { code: generatedCode, map } = /\.?[cm]?[jt]s$/.test(langInfo) ? generateJsTsBlock(generate, source, parseOptions) : generate(source, parseOptions);
|
|
486
392
|
debug$1("generated code", generatedCode);
|
|
487
393
|
debug$1("sourcemap", map, ctx.sourceMap);
|
|
488
394
|
if (code !== generatedCode) {
|
|
@@ -496,17 +402,28 @@ function getGenerator(ext, fallback = generateJSON) {
|
|
|
496
402
|
if (/\.?json5?$/.test(ext)) {
|
|
497
403
|
return generateJSON;
|
|
498
404
|
}
|
|
499
|
-
if (
|
|
405
|
+
if (/\.?ya?ml$/.test(ext)) {
|
|
500
406
|
return generateYAML;
|
|
501
407
|
}
|
|
502
|
-
if (
|
|
408
|
+
if (/\.?[cm]?js$/.test(ext)) {
|
|
503
409
|
return generateJavaScript;
|
|
504
410
|
}
|
|
505
|
-
if (
|
|
411
|
+
if (/\.?[cm]?ts$/.test(ext)) {
|
|
506
412
|
return generateTypescript;
|
|
507
413
|
}
|
|
508
414
|
return fallback;
|
|
509
415
|
}
|
|
416
|
+
function generateJsTsBlock(generate, source, options) {
|
|
417
|
+
try {
|
|
418
|
+
return generate(source, options);
|
|
419
|
+
} catch (error2) {
|
|
420
|
+
try {
|
|
421
|
+
return generate(`export default ${source.replace(/^[\s;]+/, "")}`, options);
|
|
422
|
+
} catch (wrappedError) {
|
|
423
|
+
throw /^\s*export\s+default\b/m.test(source) ? error2 : wrappedError;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
510
427
|
async function loadWebpack() {
|
|
511
428
|
const mod = await import('webpack');
|
|
512
429
|
return mod.default || mod;
|
|
@@ -569,7 +486,7 @@ function getCode(source, filename, sourceMap, query, parser, meta) {
|
|
|
569
486
|
const result = parser(readFile(filename), { sourceMap, filename });
|
|
570
487
|
const block = result.descriptor.customBlocks[query.index];
|
|
571
488
|
if (block) {
|
|
572
|
-
const code = block.src ? readFile(block.src) : block.content;
|
|
489
|
+
const code = block.src ? readFile(resolveBlockSrc(block.src, filename)) : block.content;
|
|
573
490
|
debug$1(`getCode (${meta.framework}) ${query.index} from SFC`, code);
|
|
574
491
|
return code;
|
|
575
492
|
}
|
|
@@ -617,6 +534,12 @@ function getOptions(filename, ctx, query, opts) {
|
|
|
617
534
|
isGlobal: false
|
|
618
535
|
});
|
|
619
536
|
}
|
|
537
|
+
function resolveBlockSrc(src, sfcFilename) {
|
|
538
|
+
if (src.startsWith(".") || !src.startsWith("/") && !/^[a-z]:[/\\]/i.test(src)) {
|
|
539
|
+
return resolve(dirname(sfcFilename), src);
|
|
540
|
+
}
|
|
541
|
+
return src;
|
|
542
|
+
}
|
|
620
543
|
function getVirtualId(id, framework = "vite") {
|
|
621
544
|
return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
|
|
622
545
|
}
|
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.4",
|
|
5
5
|
"description": "unplugin for Vue I18n",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "kazuya kawaguchi",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"picocolors": "^1.0.0",
|
|
39
39
|
"tinyglobby": "^0.2.15",
|
|
40
40
|
"unplugin": "^2.2.0",
|
|
41
|
-
"vue": "~3.
|
|
42
|
-
"@intlify/bundle-utils": "12.0.0-alpha.
|
|
41
|
+
"vue": "~3.6.0-rc.12",
|
|
42
|
+
"@intlify/bundle-utils": "12.0.0-alpha.4"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@intlify/core-base": "next",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@vitejs/plugin-vue": "^6.0.6",
|
|
52
52
|
"jsdom": "^29.0.0",
|
|
53
53
|
"memory-fs": "^0.5.0",
|
|
54
|
-
"rollup-vite": "npm:vite@6.4.
|
|
54
|
+
"rollup-vite": "npm:vite@6.4.4",
|
|
55
55
|
"ts-loader": "~9.5.7",
|
|
56
56
|
"unbuild": "^3.6.1",
|
|
57
57
|
"vite": "^8.0.0",
|