@intlify/unplugin-vue-i18n 11.2.3 → 11.2.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 CHANGED
@@ -177,11 +177,11 @@ function getDescriptor(filename, code, options) {
177
177
  }
178
178
 
179
179
  const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
180
- const VIRTUAL_PREFIX = "\0";
180
+ const VIRTUAL_PREFIX = "virtual:";
181
181
  const RE_RESOURCE_FORMAT = /\.(json5?|ya?ml|[c|m]?[j|t]s)$/;
182
182
  const RE_SFC_I18N_CUSTOM_BLOCK = /\?vue&type=i18n/;
183
183
  const RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK = /blockType=i18n/;
184
- const VITE_VIRTUAL_PREFIX = "\0intlify-i18n-";
184
+ const VITE_VIRTUAL_PREFIX = "virtual:intlify-i18n-";
185
185
  const debug$3 = createDebug__default(resolveNamespace("resource"));
186
186
  function resourcePlugin({
187
187
  onlyLocales,
@@ -242,11 +242,12 @@ function resourcePlugin({
242
242
  const realPathToVirtualId = /* @__PURE__ */ new Map();
243
243
  let virtualCounter = 0;
244
244
  function intlifyVirtualize(realPath) {
245
- let virtualId = realPathToVirtualId.get(realPath);
245
+ const normalized = pathe.normalize(realPath);
246
+ let virtualId = realPathToVirtualId.get(normalized);
246
247
  if (!virtualId) {
247
248
  virtualId = `${VITE_VIRTUAL_PREFIX}${virtualCounter++}`;
248
- virtualIdToRealPath.set(virtualId, realPath);
249
- realPathToVirtualId.set(realPath, virtualId);
249
+ virtualIdToRealPath.set(virtualId, normalized);
250
+ realPathToVirtualId.set(normalized, virtualId);
250
251
  }
251
252
  return virtualId;
252
253
  }
@@ -379,7 +380,16 @@ function resourcePlugin({
379
380
  }
380
381
  if (meta.framework === "vite" && !hasViteJsonPlugin) {
381
382
  if (id.includes("?vue&type=i18n") && /[?&]lang\.(?:json|json5)(?:$|&)/.test(id)) {
382
- return intlifyVirtualize(id);
383
+ const { filename, query } = parseVueRequest(id);
384
+ let virtualKey = id;
385
+ if (query.src && importer) {
386
+ const importerPath = (isIntlifyVirtualId(importer) ? virtualIdToRealPath.get(importer) : importer).split("?")[0];
387
+ if (importerPath.endsWith(".vue")) {
388
+ const resolvedSidecar = pathe.resolve(pathe.dirname(importerPath), filename);
389
+ virtualKey = id.replace(filename, resolvedSidecar);
390
+ }
391
+ }
392
+ return intlifyVirtualize(virtualKey);
383
393
  }
384
394
  const idPath = id.split("?")[0];
385
395
  if (!RE_RESOURCE_FORMAT.test(idPath)) return;
@@ -424,15 +434,21 @@ function resourcePlugin({
424
434
  const realId = virtualIdToRealPath.get(id);
425
435
  if (realId.includes("?vue&type=i18n")) {
426
436
  const { filename, query } = parseVueRequest(realId);
427
- this.addWatchFile(filename);
428
- const sfcSource = await node_fs.promises.readFile(filename, "utf-8");
429
- const { descriptor } = getSfcParser()(sfcSource, {
430
- sourceMap,
431
- filename
432
- });
433
- const block = descriptor.customBlocks[query.index];
434
- if (!block) return;
435
- let source = block.src ? await node_fs.promises.readFile(block.src, "utf-8") : block.content;
437
+ let source;
438
+ if (query.src) {
439
+ this.addWatchFile(filename);
440
+ source = await node_fs.promises.readFile(filename, "utf-8");
441
+ } else {
442
+ this.addWatchFile(filename);
443
+ const sfcSource = await node_fs.promises.readFile(filename, "utf-8");
444
+ const { descriptor } = getSfcParser()(sfcSource, {
445
+ sourceMap,
446
+ filename
447
+ });
448
+ const block = descriptor.customBlocks[query.index];
449
+ if (!block) return;
450
+ source = block.content;
451
+ }
436
452
  if (typeof transformI18nBlock === "function") {
437
453
  const modifiedSource = transformI18nBlock(source);
438
454
  if (modifiedSource && typeof modifiedSource === "string") {
@@ -715,7 +731,7 @@ async function getCode(source, filename, sourceMap, query, parser, framework = "
715
731
  });
716
732
  const block = result.descriptor.customBlocks[index];
717
733
  if (block) {
718
- const code = block.src ? await getRaw(block.src) : block.content;
734
+ const code = block.src ? await getRaw(resolveBlockSrc(block.src, filename)) : block.content;
719
735
  debug$3(`getCode (webpack) ${index} from SFC`, code);
720
736
  return code;
721
737
  } else {
@@ -789,6 +805,12 @@ function getOptions(filename, isProduction, query, sourceMap, {
789
805
  });
790
806
  }
791
807
  }
808
+ function resolveBlockSrc(src, sfcFilename) {
809
+ if (src.startsWith(".") || !src.startsWith("/") && !/^[a-z]:[/\\]/i.test(src)) {
810
+ return pathe.resolve(pathe.dirname(sfcFilename), src);
811
+ }
812
+ return src;
813
+ }
792
814
  function getVirtualId(id, framework = "vite") {
793
815
  return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
794
816
  }
package/lib/index.mjs CHANGED
@@ -165,11 +165,11 @@ function getDescriptor(filename, code, options) {
165
165
  }
166
166
 
167
167
  const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
168
- const VIRTUAL_PREFIX = "\0";
168
+ const VIRTUAL_PREFIX = "virtual:";
169
169
  const RE_RESOURCE_FORMAT = /\.(json5?|ya?ml|[c|m]?[j|t]s)$/;
170
170
  const RE_SFC_I18N_CUSTOM_BLOCK = /\?vue&type=i18n/;
171
171
  const RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK = /blockType=i18n/;
172
- const VITE_VIRTUAL_PREFIX = "\0intlify-i18n-";
172
+ const VITE_VIRTUAL_PREFIX = "virtual:intlify-i18n-";
173
173
  const debug$3 = createDebug(resolveNamespace("resource"));
174
174
  function resourcePlugin({
175
175
  onlyLocales,
@@ -230,11 +230,12 @@ function resourcePlugin({
230
230
  const realPathToVirtualId = /* @__PURE__ */ new Map();
231
231
  let virtualCounter = 0;
232
232
  function intlifyVirtualize(realPath) {
233
- let virtualId = realPathToVirtualId.get(realPath);
233
+ const normalized = normalize(realPath);
234
+ let virtualId = realPathToVirtualId.get(normalized);
234
235
  if (!virtualId) {
235
236
  virtualId = `${VITE_VIRTUAL_PREFIX}${virtualCounter++}`;
236
- virtualIdToRealPath.set(virtualId, realPath);
237
- realPathToVirtualId.set(realPath, virtualId);
237
+ virtualIdToRealPath.set(virtualId, normalized);
238
+ realPathToVirtualId.set(normalized, virtualId);
238
239
  }
239
240
  return virtualId;
240
241
  }
@@ -367,7 +368,16 @@ function resourcePlugin({
367
368
  }
368
369
  if (meta.framework === "vite" && !hasViteJsonPlugin) {
369
370
  if (id.includes("?vue&type=i18n") && /[?&]lang\.(?:json|json5)(?:$|&)/.test(id)) {
370
- return intlifyVirtualize(id);
371
+ const { filename, query } = parseVueRequest(id);
372
+ let virtualKey = id;
373
+ if (query.src && importer) {
374
+ const importerPath = (isIntlifyVirtualId(importer) ? virtualIdToRealPath.get(importer) : importer).split("?")[0];
375
+ if (importerPath.endsWith(".vue")) {
376
+ const resolvedSidecar = resolve(dirname(importerPath), filename);
377
+ virtualKey = id.replace(filename, resolvedSidecar);
378
+ }
379
+ }
380
+ return intlifyVirtualize(virtualKey);
371
381
  }
372
382
  const idPath = id.split("?")[0];
373
383
  if (!RE_RESOURCE_FORMAT.test(idPath)) return;
@@ -412,15 +422,21 @@ function resourcePlugin({
412
422
  const realId = virtualIdToRealPath.get(id);
413
423
  if (realId.includes("?vue&type=i18n")) {
414
424
  const { filename, query } = parseVueRequest(realId);
415
- this.addWatchFile(filename);
416
- const sfcSource = await promises.readFile(filename, "utf-8");
417
- const { descriptor } = getSfcParser()(sfcSource, {
418
- sourceMap,
419
- filename
420
- });
421
- const block = descriptor.customBlocks[query.index];
422
- if (!block) return;
423
- let source = block.src ? await promises.readFile(block.src, "utf-8") : block.content;
425
+ let source;
426
+ if (query.src) {
427
+ this.addWatchFile(filename);
428
+ source = await promises.readFile(filename, "utf-8");
429
+ } else {
430
+ this.addWatchFile(filename);
431
+ const sfcSource = await promises.readFile(filename, "utf-8");
432
+ const { descriptor } = getSfcParser()(sfcSource, {
433
+ sourceMap,
434
+ filename
435
+ });
436
+ const block = descriptor.customBlocks[query.index];
437
+ if (!block) return;
438
+ source = block.content;
439
+ }
424
440
  if (typeof transformI18nBlock === "function") {
425
441
  const modifiedSource = transformI18nBlock(source);
426
442
  if (modifiedSource && typeof modifiedSource === "string") {
@@ -703,7 +719,7 @@ async function getCode(source, filename, sourceMap, query, parser, framework = "
703
719
  });
704
720
  const block = result.descriptor.customBlocks[index];
705
721
  if (block) {
706
- const code = block.src ? await getRaw(block.src) : block.content;
722
+ const code = block.src ? await getRaw(resolveBlockSrc(block.src, filename)) : block.content;
707
723
  debug$3(`getCode (webpack) ${index} from SFC`, code);
708
724
  return code;
709
725
  } else {
@@ -777,6 +793,12 @@ function getOptions(filename, isProduction, query, sourceMap, {
777
793
  });
778
794
  }
779
795
  }
796
+ function resolveBlockSrc(src, sfcFilename) {
797
+ if (src.startsWith(".") || !src.startsWith("/") && !/^[a-z]:[/\\]/i.test(src)) {
798
+ return resolve(dirname(sfcFilename), src);
799
+ }
800
+ return src;
801
+ }
780
802
  function getVirtualId(id, framework = "vite") {
781
803
  return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
782
804
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
- "version": "11.2.3",
3
+ "version": "11.2.4",
4
4
  "description": "unplugin for Vue I18n",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
@@ -39,7 +39,7 @@
39
39
  "picocolors": "^1.0.0",
40
40
  "unplugin": "^2.3.4",
41
41
  "vue": "~3.5.34",
42
- "@intlify/bundle-utils": "11.2.3"
42
+ "@intlify/bundle-utils": "11.2.4"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@intlify/core-base": "next",