@intlify/unplugin-vue-i18n 11.2.3 → 11.2.5

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
  }
@@ -321,16 +322,22 @@ function resourcePlugin({
321
322
  }
322
323
  }
323
324
  },
324
- async handleHotUpdate({ file, server }) {
325
- if (RE_RESOURCE_FORMAT.test(file)) {
326
- const module2 = server.moduleGraph.getModuleById(
327
- asVirtualId(INTLIFY_BUNDLE_IMPORT_ID, meta.framework)
328
- );
329
- if (module2) {
330
- server.moduleGraph.invalidateModule(module2);
331
- return [module2];
332
- }
325
+ handleHotUpdate({ file, modules, server }) {
326
+ const key = pathe.normalize(file);
327
+ const virtualId = realPathToVirtualId.get(key);
328
+ const inBundle = !!(include && pluginutils.createFilter(include, exclude)(key));
329
+ if (!virtualId && !inBundle) return;
330
+ const affected = new Set(modules);
331
+ const addById = (id) => {
332
+ const mod = id && server.moduleGraph.getModuleById(id);
333
+ if (mod) affected.add(mod);
334
+ };
335
+ addById(virtualId);
336
+ if (inBundle) {
337
+ addById(asVirtualId(INTLIFY_BUNDLE_IMPORT_ID, meta.framework));
333
338
  }
339
+ if (affected.size === modules.length) return;
340
+ return [...affected];
334
341
  }
335
342
  },
336
343
  webpack(compiler) {
@@ -379,7 +386,16 @@ function resourcePlugin({
379
386
  }
380
387
  if (meta.framework === "vite" && !hasViteJsonPlugin) {
381
388
  if (id.includes("?vue&type=i18n") && /[?&]lang\.(?:json|json5)(?:$|&)/.test(id)) {
382
- return intlifyVirtualize(id);
389
+ const { filename, query } = parseVueRequest(id);
390
+ let virtualKey = id;
391
+ if (query.src && importer) {
392
+ const importerPath = (isIntlifyVirtualId(importer) ? virtualIdToRealPath.get(importer) : importer).split("?")[0];
393
+ if (importerPath.endsWith(".vue")) {
394
+ const resolvedSidecar = pathe.resolve(pathe.dirname(importerPath), filename);
395
+ virtualKey = id.replace(filename, resolvedSidecar);
396
+ }
397
+ }
398
+ return intlifyVirtualize(virtualKey);
383
399
  }
384
400
  const idPath = id.split("?")[0];
385
401
  if (!RE_RESOURCE_FORMAT.test(idPath)) return;
@@ -424,15 +440,21 @@ function resourcePlugin({
424
440
  const realId = virtualIdToRealPath.get(id);
425
441
  if (realId.includes("?vue&type=i18n")) {
426
442
  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;
443
+ let source;
444
+ if (query.src) {
445
+ this.addWatchFile(filename);
446
+ source = await node_fs.promises.readFile(filename, "utf-8");
447
+ } else {
448
+ this.addWatchFile(filename);
449
+ const sfcSource = await node_fs.promises.readFile(filename, "utf-8");
450
+ const { descriptor } = getSfcParser()(sfcSource, {
451
+ sourceMap,
452
+ filename
453
+ });
454
+ const block = descriptor.customBlocks[query.index];
455
+ if (!block) return;
456
+ source = block.content;
457
+ }
436
458
  if (typeof transformI18nBlock === "function") {
437
459
  const modifiedSource = transformI18nBlock(source);
438
460
  if (modifiedSource && typeof modifiedSource === "string") {
@@ -715,7 +737,7 @@ async function getCode(source, filename, sourceMap, query, parser, framework = "
715
737
  });
716
738
  const block = result.descriptor.customBlocks[index];
717
739
  if (block) {
718
- const code = block.src ? await getRaw(block.src) : block.content;
740
+ const code = block.src ? await getRaw(resolveBlockSrc(block.src, filename)) : block.content;
719
741
  debug$3(`getCode (webpack) ${index} from SFC`, code);
720
742
  return code;
721
743
  } else {
@@ -789,6 +811,12 @@ function getOptions(filename, isProduction, query, sourceMap, {
789
811
  });
790
812
  }
791
813
  }
814
+ function resolveBlockSrc(src, sfcFilename) {
815
+ if (src.startsWith(".") || !src.startsWith("/") && !/^[a-z]:[/\\]/i.test(src)) {
816
+ return pathe.resolve(pathe.dirname(sfcFilename), src);
817
+ }
818
+ return src;
819
+ }
792
820
  function getVirtualId(id, framework = "vite") {
793
821
  return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
794
822
  }
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
  }
@@ -309,16 +310,22 @@ function resourcePlugin({
309
310
  }
310
311
  }
311
312
  },
312
- async handleHotUpdate({ file, server }) {
313
- if (RE_RESOURCE_FORMAT.test(file)) {
314
- const module2 = server.moduleGraph.getModuleById(
315
- asVirtualId(INTLIFY_BUNDLE_IMPORT_ID, meta.framework)
316
- );
317
- if (module2) {
318
- server.moduleGraph.invalidateModule(module2);
319
- return [module2];
320
- }
313
+ handleHotUpdate({ file, modules, server }) {
314
+ const key = normalize(file);
315
+ const virtualId = realPathToVirtualId.get(key);
316
+ const inBundle = !!(include && createFilter(include, exclude)(key));
317
+ if (!virtualId && !inBundle) return;
318
+ const affected = new Set(modules);
319
+ const addById = (id) => {
320
+ const mod = id && server.moduleGraph.getModuleById(id);
321
+ if (mod) affected.add(mod);
322
+ };
323
+ addById(virtualId);
324
+ if (inBundle) {
325
+ addById(asVirtualId(INTLIFY_BUNDLE_IMPORT_ID, meta.framework));
321
326
  }
327
+ if (affected.size === modules.length) return;
328
+ return [...affected];
322
329
  }
323
330
  },
324
331
  webpack(compiler) {
@@ -367,7 +374,16 @@ function resourcePlugin({
367
374
  }
368
375
  if (meta.framework === "vite" && !hasViteJsonPlugin) {
369
376
  if (id.includes("?vue&type=i18n") && /[?&]lang\.(?:json|json5)(?:$|&)/.test(id)) {
370
- return intlifyVirtualize(id);
377
+ const { filename, query } = parseVueRequest(id);
378
+ let virtualKey = id;
379
+ if (query.src && importer) {
380
+ const importerPath = (isIntlifyVirtualId(importer) ? virtualIdToRealPath.get(importer) : importer).split("?")[0];
381
+ if (importerPath.endsWith(".vue")) {
382
+ const resolvedSidecar = resolve(dirname(importerPath), filename);
383
+ virtualKey = id.replace(filename, resolvedSidecar);
384
+ }
385
+ }
386
+ return intlifyVirtualize(virtualKey);
371
387
  }
372
388
  const idPath = id.split("?")[0];
373
389
  if (!RE_RESOURCE_FORMAT.test(idPath)) return;
@@ -412,15 +428,21 @@ function resourcePlugin({
412
428
  const realId = virtualIdToRealPath.get(id);
413
429
  if (realId.includes("?vue&type=i18n")) {
414
430
  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;
431
+ let source;
432
+ if (query.src) {
433
+ this.addWatchFile(filename);
434
+ source = await promises.readFile(filename, "utf-8");
435
+ } else {
436
+ this.addWatchFile(filename);
437
+ const sfcSource = await promises.readFile(filename, "utf-8");
438
+ const { descriptor } = getSfcParser()(sfcSource, {
439
+ sourceMap,
440
+ filename
441
+ });
442
+ const block = descriptor.customBlocks[query.index];
443
+ if (!block) return;
444
+ source = block.content;
445
+ }
424
446
  if (typeof transformI18nBlock === "function") {
425
447
  const modifiedSource = transformI18nBlock(source);
426
448
  if (modifiedSource && typeof modifiedSource === "string") {
@@ -703,7 +725,7 @@ async function getCode(source, filename, sourceMap, query, parser, framework = "
703
725
  });
704
726
  const block = result.descriptor.customBlocks[index];
705
727
  if (block) {
706
- const code = block.src ? await getRaw(block.src) : block.content;
728
+ const code = block.src ? await getRaw(resolveBlockSrc(block.src, filename)) : block.content;
707
729
  debug$3(`getCode (webpack) ${index} from SFC`, code);
708
730
  return code;
709
731
  } else {
@@ -777,6 +799,12 @@ function getOptions(filename, isProduction, query, sourceMap, {
777
799
  });
778
800
  }
779
801
  }
802
+ function resolveBlockSrc(src, sfcFilename) {
803
+ if (src.startsWith(".") || !src.startsWith("/") && !/^[a-z]:[/\\]/i.test(src)) {
804
+ return resolve(dirname(sfcFilename), src);
805
+ }
806
+ return src;
807
+ }
780
808
  function getVirtualId(id, framework = "vite") {
781
809
  return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
782
810
  }
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.5",
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.5"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@intlify/core-base": "next",