@intlify/bundle-utils 7.5.0 → 8.0.0

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
@@ -4,7 +4,6 @@ const jsoncEslintParser = require('jsonc-eslint-parser');
4
4
  const shared = require('@intlify/shared');
5
5
  const sourceMapJs = require('source-map-js');
6
6
  const messageCompiler = require('@intlify/message-compiler');
7
- const MagicString = require('magic-string');
8
7
  const yamlEslintParser = require('yaml-eslint-parser');
9
8
  const acorn = require('acorn');
10
9
  const escodegen = require('escodegen');
@@ -14,7 +13,6 @@ const module$1 = require('node:module');
14
13
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
15
14
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
16
15
 
17
- const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
18
16
  const module__default = /*#__PURE__*/_interopDefaultCompat(module$1);
19
17
 
20
18
  function createCodeGenerator(options = {
@@ -275,30 +273,9 @@ function excludeLocales({
275
273
  return _messages;
276
274
  }
277
275
 
278
- function generateLegacyCode({
279
- isGlobal = false,
280
- vueVersion = "v2.6"
281
- }, generator) {
282
- const componentNamespace = `Component${vueVersion === "v2.6" ? ".options" : ""}`;
283
- const variableName = !isGlobal ? "__i18n" : "__i18nGlobal";
284
- const exportSyntax = "export default";
285
- const code = `${exportSyntax} function (Component) {
286
- ${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []
287
- ${componentNamespace}.${variableName}.push(${shared.friendlyJSONstringify(
288
- generator()
289
- )})
290
- delete ${componentNamespace}._Ctor
291
- }`;
292
- return code;
293
- }
294
-
295
276
  function generate$2(targetSource, {
296
277
  type = "plain",
297
- legacy = false,
298
- vueVersion = "v2.6",
299
- bridge = false,
300
278
  onlyLocales = [],
301
- exportESM = false,
302
279
  filename = "vue-i18n-loader.json",
303
280
  inSourceMap = void 0,
304
281
  locale = "",
@@ -311,12 +288,10 @@ function generate$2(targetSource, {
311
288
  escapeHtml = false,
312
289
  useClassComponent = false,
313
290
  jit = false
314
- }, injector) {
291
+ }) {
315
292
  let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
316
293
  const options = {
317
294
  type,
318
- bridge,
319
- exportESM,
320
295
  source: value,
321
296
  sourceMap,
322
297
  locale,
@@ -343,21 +318,7 @@ function generate$2(targetSource, {
343
318
  );
344
319
  ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
345
320
  }
346
- if (legacy && type === "sfc") {
347
- const gen = () => shared.friendlyJSONstringify(jsoncEslintParser.getStaticJSONValue(ast));
348
- const code2 = generateLegacyCode({ isGlobal, vueVersion }, gen);
349
- const s = new MagicString__default(code2);
350
- return {
351
- ast,
352
- code: s.toString(),
353
- map: s.generateMap({
354
- file: filename,
355
- source: value,
356
- includeContent: true
357
- })
358
- };
359
- }
360
- const codeMaps = _generate$2(generator, ast, options, injector);
321
+ const codeMaps = _generate$2(generator, ast, options);
361
322
  const { code, map } = generator.context();
362
323
  const newMap = map && !jit ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
363
324
  return {
@@ -366,22 +327,13 @@ function generate$2(targetSource, {
366
327
  map: newMap != null ? newMap : void 0
367
328
  };
368
329
  }
369
- function _generate$2(generator, node, options = {}, injector) {
330
+ function _generate$2(generator, node, options = {}) {
370
331
  const propsCountStack = [];
371
332
  const pathStack = [];
372
333
  const itemsCountStack = [];
373
334
  const { forceStringify } = generator.context();
374
335
  const codeMaps = /* @__PURE__ */ new Map();
375
- const {
376
- type,
377
- bridge,
378
- exportESM,
379
- sourceMap,
380
- isGlobal,
381
- locale,
382
- useClassComponent,
383
- jit
384
- } = options;
336
+ const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options;
385
337
  const codegenFn = jit ? generateResourceAst : generateMessageFunction;
386
338
  const componentNamespace = "_Component";
387
339
  jsoncEslintParser.traverseNodes(node, {
@@ -393,10 +345,10 @@ function _generate$2(generator, node, options = {}, injector) {
393
345
  } else if (type === "sfc") {
394
346
  const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
395
347
  const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
396
- const exportSyntax = bridge ? exportESM ? `export default` : `module.exports =` : `export default`;
348
+ const exportSyntax = "export default";
397
349
  generator.push(`${exportSyntax} function (Component) {`);
398
350
  generator.indent();
399
- const componentVariable = bridge ? `Component.options || Component` : useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
351
+ const componentVariable = useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
400
352
  generator.pushline(`const ${componentNamespace} = ${componentVariable}`);
401
353
  generator.pushline(
402
354
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
@@ -495,16 +447,6 @@ function _generate$2(generator, node, options = {}, injector) {
495
447
  if (type === "sfc") {
496
448
  generator.deindent();
497
449
  generator.push(`})`);
498
- if (bridge && injector) {
499
- generator.newline();
500
- generator.pushline(
501
- `${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`
502
- );
503
- generator.pushline(
504
- `${componentNamespace}.__i18nBridge.push('${injector()}')`
505
- );
506
- generator.pushline(`delete ${componentNamespace}._Ctor`);
507
- }
508
450
  generator.deindent();
509
451
  generator.pushline(`}`);
510
452
  } else if (type === "plain") {
@@ -565,11 +507,7 @@ function _generate$2(generator, node, options = {}, injector) {
565
507
 
566
508
  function generate$1(targetSource, {
567
509
  type = "plain",
568
- legacy = false,
569
- vueVersion = "v2.6",
570
- bridge = false,
571
510
  onlyLocales = [],
572
- exportESM = false,
573
511
  useClassComponent = false,
574
512
  filename = "vue-i18n-loader.yaml",
575
513
  inSourceMap = void 0,
@@ -582,12 +520,10 @@ function generate$1(targetSource, {
582
520
  strictMessage = true,
583
521
  escapeHtml = false,
584
522
  jit = false
585
- }, injector) {
523
+ }) {
586
524
  let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
587
525
  const options = {
588
526
  type,
589
- bridge,
590
- exportESM,
591
527
  source: value,
592
528
  sourceMap,
593
529
  locale,
@@ -614,21 +550,7 @@ function generate$1(targetSource, {
614
550
  );
615
551
  ast = yamlEslintParser.parseYAML(value, { filePath: filename });
616
552
  }
617
- if (legacy && type === "sfc") {
618
- const gen = () => shared.friendlyJSONstringify(yamlEslintParser.getStaticYAMLValue(ast));
619
- const code2 = generateLegacyCode({ isGlobal, vueVersion }, gen);
620
- const s = new MagicString__default(code2);
621
- return {
622
- ast,
623
- code: s.toString(),
624
- map: s.generateMap({
625
- file: filename,
626
- source: value,
627
- includeContent: true
628
- })
629
- };
630
- }
631
- const codeMaps = _generate$1(generator, ast, options, injector);
553
+ const codeMaps = _generate$1(generator, ast, options);
632
554
  const { code, map } = generator.context();
633
555
  const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
634
556
  return {
@@ -637,22 +559,13 @@ function generate$1(targetSource, {
637
559
  map: newMap != null ? newMap : void 0
638
560
  };
639
561
  }
640
- function _generate$1(generator, node, options = {}, injector) {
562
+ function _generate$1(generator, node, options = {}) {
641
563
  const propsCountStack = [];
642
564
  const pathStack = [];
643
565
  const itemsCountStack = [];
644
566
  const { forceStringify } = generator.context();
645
567
  const codeMaps = /* @__PURE__ */ new Map();
646
- const {
647
- type,
648
- bridge,
649
- exportESM,
650
- sourceMap,
651
- isGlobal,
652
- locale,
653
- useClassComponent,
654
- jit
655
- } = options;
568
+ const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options;
656
569
  const codegenFn = jit ? generateResourceAst : generateMessageFunction;
657
570
  const componentNamespace = "_Component";
658
571
  yamlEslintParser.traverseNodes(node, {
@@ -664,10 +577,10 @@ function _generate$1(generator, node, options = {}, injector) {
664
577
  } else if (type === "sfc") {
665
578
  const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
666
579
  const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
667
- const exportSyntax = bridge ? exportESM ? `export default` : `module.exports =` : `export default`;
580
+ const exportSyntax = "export default";
668
581
  generator.push(`${exportSyntax} function (Component) {`);
669
582
  generator.indent();
670
- const componentVariable = bridge ? `Component.options || Component` : useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
583
+ const componentVariable = useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
671
584
  generator.pushline(`const ${componentNamespace} = ${componentVariable}`);
672
585
  generator.pushline(
673
586
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
@@ -766,16 +679,6 @@ function _generate$1(generator, node, options = {}, injector) {
766
679
  if (type === "sfc") {
767
680
  generator.deindent();
768
681
  generator.push(`})`);
769
- if (bridge && injector) {
770
- generator.newline();
771
- generator.pushline(
772
- `${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`
773
- );
774
- generator.pushline(
775
- `${componentNamespace}.__i18nBridge.push('${injector()}')`
776
- );
777
- generator.pushline(`delete ${componentNamespace}._Ctor`);
778
- }
779
682
  generator.deindent();
780
683
  generator.push(`}`);
781
684
  } else if (type === "plain") {
@@ -836,8 +739,6 @@ function _generate$1(generator, node, options = {}, injector) {
836
739
 
837
740
  function generate(targetSource, {
838
741
  type = "plain",
839
- bridge = false,
840
- exportESM = false,
841
742
  filename = "vue-i18n-loader.js",
842
743
  inSourceMap = void 0,
843
744
  locale = "",
@@ -851,13 +752,11 @@ function generate(targetSource, {
851
752
  useClassComponent = false,
852
753
  allowDynamic = false,
853
754
  jit = false
854
- }, injector) {
755
+ }) {
855
756
  const target = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
856
757
  const value = target;
857
758
  const options = {
858
759
  type,
859
- bridge,
860
- exportESM,
861
760
  source: value,
862
761
  sourceMap,
863
762
  locale,
@@ -900,7 +799,7 @@ function generate(targetSource, {
900
799
  };
901
800
  }
902
801
  }
903
- const codeMaps = _generate(generator, ast, options, injector);
802
+ const codeMaps = _generate(generator, ast, options);
904
803
  const { code, map } = generator.context();
905
804
  const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
906
805
  return {
@@ -930,23 +829,14 @@ function scanAst(ast) {
930
829
  }
931
830
  return ret;
932
831
  }
933
- function _generate(generator, node, options = {}, injector) {
832
+ function _generate(generator, node, options = {}) {
934
833
  const propsCountStack = [];
935
834
  const pathStack = [];
936
835
  const itemsCountStack = [];
937
836
  const skipStack = [];
938
837
  const { forceStringify } = generator.context();
939
838
  const codeMaps = /* @__PURE__ */ new Map();
940
- const {
941
- type,
942
- bridge,
943
- exportESM,
944
- sourceMap,
945
- isGlobal,
946
- locale,
947
- useClassComponent,
948
- jit
949
- } = options;
839
+ const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options;
950
840
  const codegenFn = jit ? generateResourceAst : generateMessageFunction;
951
841
  const componentNamespace = "_Component";
952
842
  estreeWalker.walk(node, {
@@ -965,10 +855,10 @@ function _generate(generator, node, options = {}, injector) {
965
855
  } else if (type === "sfc") {
966
856
  const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
967
857
  const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
968
- const exportSyntax = bridge ? exportESM ? `export default` : `module.exports =` : `export default`;
858
+ const exportSyntax = "export default";
969
859
  generator.push(`${exportSyntax} function (Component) {`);
970
860
  generator.indent();
971
- const componentVariable = bridge ? `Component.options || Component` : useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
861
+ const componentVariable = useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
972
862
  generator.pushline(`const ${componentNamespace} = ${componentVariable}`);
973
863
  generator.pushline(
974
864
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
@@ -1104,16 +994,6 @@ function _generate(generator, node, options = {}, injector) {
1104
994
  if (type === "sfc") {
1105
995
  generator.deindent();
1106
996
  generator.push(`})`);
1107
- if (bridge && injector) {
1108
- generator.newline();
1109
- generator.pushline(
1110
- `${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`
1111
- );
1112
- generator.pushline(
1113
- `${componentNamespace}.__i18nBridge.push('${injector()}')`
1114
- );
1115
- generator.pushline(`delete ${componentNamespace}._Ctor`);
1116
- }
1117
997
  generator.deindent();
1118
998
  generator.pushline(`}`);
1119
999
  } else if (type === "plain") {
@@ -1214,16 +1094,6 @@ function checkInstallPackage(pkg, debug) {
1214
1094
  `${pkg} requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
1215
1095
  );
1216
1096
  }
1217
- function checkVueI18nBridgeInstallPackage(debug) {
1218
- let ret = false;
1219
- try {
1220
- debug(`vue-i18n-bridge load path: ${_require.resolve("vue-i18n-bridge")}`);
1221
- ret = true;
1222
- } catch (e) {
1223
- debug(`cannot find 'vue-i18n-bridge'`, e);
1224
- }
1225
- return ret;
1226
- }
1227
1097
  function getVueI18nVersion(debug) {
1228
1098
  const VueI18n = loadModule("vue-i18n", debug);
1229
1099
  if (VueI18n == null) {
@@ -1247,7 +1117,6 @@ function loadModule(moduleName, debug) {
1247
1117
  }
1248
1118
 
1249
1119
  exports.checkInstallPackage = checkInstallPackage;
1250
- exports.checkVueI18nBridgeInstallPackage = checkVueI18nBridgeInstallPackage;
1251
1120
  exports.generateJSON = generate$2;
1252
1121
  exports.generateJavaScript = generate;
1253
1122
  exports.generateYAML = generate$1;
package/lib/index.d.cts CHANGED
@@ -54,7 +54,7 @@ interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
54
54
  * Code / AST generator for i18n json/json5 resource
55
55
  */
56
56
 
57
- declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVersion, bridge, onlyLocales, exportESM, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
57
+ declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
58
58
 
59
59
  /**
60
60
  * Code generator for i18n yaml resource
@@ -63,7 +63,7 @@ declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVe
63
63
  /**
64
64
  * @internal
65
65
  */
66
- declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVersion, bridge, onlyLocales, exportESM, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
66
+ declare function generate$1(targetSource: string | Buffer, { type, onlyLocales, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
67
67
 
68
68
  /**
69
69
  * Code generator for i18n js resource
@@ -72,12 +72,11 @@ declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVe
72
72
  /**
73
73
  * @internal
74
74
  */
75
- declare function generate(targetSource: string | Buffer, { type, bridge, exportESM, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, allowDynamic, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<Node>;
75
+ declare function generate(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
76
76
 
77
77
  type InstalledPackage = 'vue-i18n' | 'petite-vue-i18n';
78
78
  declare function checkInstallPackage(pkg: string, debug: Function): InstalledPackage;
79
- declare function checkVueI18nBridgeInstallPackage(debug: Function): boolean;
80
79
  type VueI18nVersion = '8' | '9' | 'unknown' | '';
81
80
  declare function getVueI18nVersion(debug: Function): VueI18nVersion;
82
81
 
83
- export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, checkVueI18nBridgeInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
82
+ export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
package/lib/index.d.mts CHANGED
@@ -54,7 +54,7 @@ interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
54
54
  * Code / AST generator for i18n json/json5 resource
55
55
  */
56
56
 
57
- declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVersion, bridge, onlyLocales, exportESM, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
57
+ declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
58
58
 
59
59
  /**
60
60
  * Code generator for i18n yaml resource
@@ -63,7 +63,7 @@ declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVe
63
63
  /**
64
64
  * @internal
65
65
  */
66
- declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVersion, bridge, onlyLocales, exportESM, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
66
+ declare function generate$1(targetSource: string | Buffer, { type, onlyLocales, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
67
67
 
68
68
  /**
69
69
  * Code generator for i18n js resource
@@ -72,12 +72,11 @@ declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVe
72
72
  /**
73
73
  * @internal
74
74
  */
75
- declare function generate(targetSource: string | Buffer, { type, bridge, exportESM, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, allowDynamic, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<Node>;
75
+ declare function generate(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
76
76
 
77
77
  type InstalledPackage = 'vue-i18n' | 'petite-vue-i18n';
78
78
  declare function checkInstallPackage(pkg: string, debug: Function): InstalledPackage;
79
- declare function checkVueI18nBridgeInstallPackage(debug: Function): boolean;
80
79
  type VueI18nVersion = '8' | '9' | 'unknown' | '';
81
80
  declare function getVueI18nVersion(debug: Function): VueI18nVersion;
82
81
 
83
- export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, checkVueI18nBridgeInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
82
+ export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
package/lib/index.d.ts CHANGED
@@ -54,7 +54,7 @@ interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
54
54
  * Code / AST generator for i18n json/json5 resource
55
55
  */
56
56
 
57
- declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVersion, bridge, onlyLocales, exportESM, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
57
+ declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
58
58
 
59
59
  /**
60
60
  * Code generator for i18n yaml resource
@@ -63,7 +63,7 @@ declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVe
63
63
  /**
64
64
  * @internal
65
65
  */
66
- declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVersion, bridge, onlyLocales, exportESM, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
66
+ declare function generate$1(targetSource: string | Buffer, { type, onlyLocales, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
67
67
 
68
68
  /**
69
69
  * Code generator for i18n js resource
@@ -72,12 +72,11 @@ declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVe
72
72
  /**
73
73
  * @internal
74
74
  */
75
- declare function generate(targetSource: string | Buffer, { type, bridge, exportESM, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, allowDynamic, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<Node>;
75
+ declare function generate(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
76
76
 
77
77
  type InstalledPackage = 'vue-i18n' | 'petite-vue-i18n';
78
78
  declare function checkInstallPackage(pkg: string, debug: Function): InstalledPackage;
79
- declare function checkVueI18nBridgeInstallPackage(debug: Function): boolean;
80
79
  type VueI18nVersion = '8' | '9' | 'unknown' | '';
81
80
  declare function getVueI18nVersion(debug: Function): VueI18nVersion;
82
81
 
83
- export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, checkVueI18nBridgeInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
82
+ export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
package/lib/index.mjs CHANGED
@@ -2,7 +2,6 @@ import { parseJSON, getStaticJSONValue, traverseNodes } from 'jsonc-eslint-parse
2
2
  import { isBoolean, format, escapeHtml, friendlyJSONstringify, isString, isNumber } from '@intlify/shared';
3
3
  import { SourceMapGenerator, SourceMapConsumer } from 'source-map-js';
4
4
  import { LOCATION_STUB, detectHtmlTag, baseCompile } from '@intlify/message-compiler';
5
- import MagicString from 'magic-string';
6
5
  import { parseYAML, getStaticYAMLValue, traverseNodes as traverseNodes$1 } from 'yaml-eslint-parser';
7
6
  import { parse } from 'acorn';
8
7
  import { generate as generate$3 } from 'escodegen';
@@ -267,30 +266,9 @@ function excludeLocales({
267
266
  return _messages;
268
267
  }
269
268
 
270
- function generateLegacyCode({
271
- isGlobal = false,
272
- vueVersion = "v2.6"
273
- }, generator) {
274
- const componentNamespace = `Component${vueVersion === "v2.6" ? ".options" : ""}`;
275
- const variableName = !isGlobal ? "__i18n" : "__i18nGlobal";
276
- const exportSyntax = "export default";
277
- const code = `${exportSyntax} function (Component) {
278
- ${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []
279
- ${componentNamespace}.${variableName}.push(${friendlyJSONstringify(
280
- generator()
281
- )})
282
- delete ${componentNamespace}._Ctor
283
- }`;
284
- return code;
285
- }
286
-
287
269
  function generate$2(targetSource, {
288
270
  type = "plain",
289
- legacy = false,
290
- vueVersion = "v2.6",
291
- bridge = false,
292
271
  onlyLocales = [],
293
- exportESM = false,
294
272
  filename = "vue-i18n-loader.json",
295
273
  inSourceMap = void 0,
296
274
  locale = "",
@@ -303,12 +281,10 @@ function generate$2(targetSource, {
303
281
  escapeHtml = false,
304
282
  useClassComponent = false,
305
283
  jit = false
306
- }, injector) {
284
+ }) {
307
285
  let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
308
286
  const options = {
309
287
  type,
310
- bridge,
311
- exportESM,
312
288
  source: value,
313
289
  sourceMap,
314
290
  locale,
@@ -335,21 +311,7 @@ function generate$2(targetSource, {
335
311
  );
336
312
  ast = parseJSON(value, { filePath: filename });
337
313
  }
338
- if (legacy && type === "sfc") {
339
- const gen = () => friendlyJSONstringify(getStaticJSONValue(ast));
340
- const code2 = generateLegacyCode({ isGlobal, vueVersion }, gen);
341
- const s = new MagicString(code2);
342
- return {
343
- ast,
344
- code: s.toString(),
345
- map: s.generateMap({
346
- file: filename,
347
- source: value,
348
- includeContent: true
349
- })
350
- };
351
- }
352
- const codeMaps = _generate$2(generator, ast, options, injector);
314
+ const codeMaps = _generate$2(generator, ast, options);
353
315
  const { code, map } = generator.context();
354
316
  const newMap = map && !jit ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
355
317
  return {
@@ -358,22 +320,13 @@ function generate$2(targetSource, {
358
320
  map: newMap != null ? newMap : void 0
359
321
  };
360
322
  }
361
- function _generate$2(generator, node, options = {}, injector) {
323
+ function _generate$2(generator, node, options = {}) {
362
324
  const propsCountStack = [];
363
325
  const pathStack = [];
364
326
  const itemsCountStack = [];
365
327
  const { forceStringify } = generator.context();
366
328
  const codeMaps = /* @__PURE__ */ new Map();
367
- const {
368
- type,
369
- bridge,
370
- exportESM,
371
- sourceMap,
372
- isGlobal,
373
- locale,
374
- useClassComponent,
375
- jit
376
- } = options;
329
+ const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options;
377
330
  const codegenFn = jit ? generateResourceAst : generateMessageFunction;
378
331
  const componentNamespace = "_Component";
379
332
  traverseNodes(node, {
@@ -385,10 +338,10 @@ function _generate$2(generator, node, options = {}, injector) {
385
338
  } else if (type === "sfc") {
386
339
  const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
387
340
  const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
388
- const exportSyntax = bridge ? exportESM ? `export default` : `module.exports =` : `export default`;
341
+ const exportSyntax = "export default";
389
342
  generator.push(`${exportSyntax} function (Component) {`);
390
343
  generator.indent();
391
- const componentVariable = bridge ? `Component.options || Component` : useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
344
+ const componentVariable = useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
392
345
  generator.pushline(`const ${componentNamespace} = ${componentVariable}`);
393
346
  generator.pushline(
394
347
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
@@ -487,16 +440,6 @@ function _generate$2(generator, node, options = {}, injector) {
487
440
  if (type === "sfc") {
488
441
  generator.deindent();
489
442
  generator.push(`})`);
490
- if (bridge && injector) {
491
- generator.newline();
492
- generator.pushline(
493
- `${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`
494
- );
495
- generator.pushline(
496
- `${componentNamespace}.__i18nBridge.push('${injector()}')`
497
- );
498
- generator.pushline(`delete ${componentNamespace}._Ctor`);
499
- }
500
443
  generator.deindent();
501
444
  generator.pushline(`}`);
502
445
  } else if (type === "plain") {
@@ -557,11 +500,7 @@ function _generate$2(generator, node, options = {}, injector) {
557
500
 
558
501
  function generate$1(targetSource, {
559
502
  type = "plain",
560
- legacy = false,
561
- vueVersion = "v2.6",
562
- bridge = false,
563
503
  onlyLocales = [],
564
- exportESM = false,
565
504
  useClassComponent = false,
566
505
  filename = "vue-i18n-loader.yaml",
567
506
  inSourceMap = void 0,
@@ -574,12 +513,10 @@ function generate$1(targetSource, {
574
513
  strictMessage = true,
575
514
  escapeHtml = false,
576
515
  jit = false
577
- }, injector) {
516
+ }) {
578
517
  let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
579
518
  const options = {
580
519
  type,
581
- bridge,
582
- exportESM,
583
520
  source: value,
584
521
  sourceMap,
585
522
  locale,
@@ -606,21 +543,7 @@ function generate$1(targetSource, {
606
543
  );
607
544
  ast = parseYAML(value, { filePath: filename });
608
545
  }
609
- if (legacy && type === "sfc") {
610
- const gen = () => friendlyJSONstringify(getStaticYAMLValue(ast));
611
- const code2 = generateLegacyCode({ isGlobal, vueVersion }, gen);
612
- const s = new MagicString(code2);
613
- return {
614
- ast,
615
- code: s.toString(),
616
- map: s.generateMap({
617
- file: filename,
618
- source: value,
619
- includeContent: true
620
- })
621
- };
622
- }
623
- const codeMaps = _generate$1(generator, ast, options, injector);
546
+ const codeMaps = _generate$1(generator, ast, options);
624
547
  const { code, map } = generator.context();
625
548
  const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
626
549
  return {
@@ -629,22 +552,13 @@ function generate$1(targetSource, {
629
552
  map: newMap != null ? newMap : void 0
630
553
  };
631
554
  }
632
- function _generate$1(generator, node, options = {}, injector) {
555
+ function _generate$1(generator, node, options = {}) {
633
556
  const propsCountStack = [];
634
557
  const pathStack = [];
635
558
  const itemsCountStack = [];
636
559
  const { forceStringify } = generator.context();
637
560
  const codeMaps = /* @__PURE__ */ new Map();
638
- const {
639
- type,
640
- bridge,
641
- exportESM,
642
- sourceMap,
643
- isGlobal,
644
- locale,
645
- useClassComponent,
646
- jit
647
- } = options;
561
+ const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options;
648
562
  const codegenFn = jit ? generateResourceAst : generateMessageFunction;
649
563
  const componentNamespace = "_Component";
650
564
  traverseNodes$1(node, {
@@ -656,10 +570,10 @@ function _generate$1(generator, node, options = {}, injector) {
656
570
  } else if (type === "sfc") {
657
571
  const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
658
572
  const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
659
- const exportSyntax = bridge ? exportESM ? `export default` : `module.exports =` : `export default`;
573
+ const exportSyntax = "export default";
660
574
  generator.push(`${exportSyntax} function (Component) {`);
661
575
  generator.indent();
662
- const componentVariable = bridge ? `Component.options || Component` : useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
576
+ const componentVariable = useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
663
577
  generator.pushline(`const ${componentNamespace} = ${componentVariable}`);
664
578
  generator.pushline(
665
579
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
@@ -758,16 +672,6 @@ function _generate$1(generator, node, options = {}, injector) {
758
672
  if (type === "sfc") {
759
673
  generator.deindent();
760
674
  generator.push(`})`);
761
- if (bridge && injector) {
762
- generator.newline();
763
- generator.pushline(
764
- `${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`
765
- );
766
- generator.pushline(
767
- `${componentNamespace}.__i18nBridge.push('${injector()}')`
768
- );
769
- generator.pushline(`delete ${componentNamespace}._Ctor`);
770
- }
771
675
  generator.deindent();
772
676
  generator.push(`}`);
773
677
  } else if (type === "plain") {
@@ -828,8 +732,6 @@ function _generate$1(generator, node, options = {}, injector) {
828
732
 
829
733
  function generate(targetSource, {
830
734
  type = "plain",
831
- bridge = false,
832
- exportESM = false,
833
735
  filename = "vue-i18n-loader.js",
834
736
  inSourceMap = void 0,
835
737
  locale = "",
@@ -843,13 +745,11 @@ function generate(targetSource, {
843
745
  useClassComponent = false,
844
746
  allowDynamic = false,
845
747
  jit = false
846
- }, injector) {
748
+ }) {
847
749
  const target = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
848
750
  const value = target;
849
751
  const options = {
850
752
  type,
851
- bridge,
852
- exportESM,
853
753
  source: value,
854
754
  sourceMap,
855
755
  locale,
@@ -892,7 +792,7 @@ function generate(targetSource, {
892
792
  };
893
793
  }
894
794
  }
895
- const codeMaps = _generate(generator, ast, options, injector);
795
+ const codeMaps = _generate(generator, ast, options);
896
796
  const { code, map } = generator.context();
897
797
  const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
898
798
  return {
@@ -922,23 +822,14 @@ function scanAst(ast) {
922
822
  }
923
823
  return ret;
924
824
  }
925
- function _generate(generator, node, options = {}, injector) {
825
+ function _generate(generator, node, options = {}) {
926
826
  const propsCountStack = [];
927
827
  const pathStack = [];
928
828
  const itemsCountStack = [];
929
829
  const skipStack = [];
930
830
  const { forceStringify } = generator.context();
931
831
  const codeMaps = /* @__PURE__ */ new Map();
932
- const {
933
- type,
934
- bridge,
935
- exportESM,
936
- sourceMap,
937
- isGlobal,
938
- locale,
939
- useClassComponent,
940
- jit
941
- } = options;
832
+ const { type, sourceMap, isGlobal, locale, useClassComponent, jit } = options;
942
833
  const codegenFn = jit ? generateResourceAst : generateMessageFunction;
943
834
  const componentNamespace = "_Component";
944
835
  walk(node, {
@@ -957,10 +848,10 @@ function _generate(generator, node, options = {}, injector) {
957
848
  } else if (type === "sfc") {
958
849
  const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
959
850
  const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
960
- const exportSyntax = bridge ? exportESM ? `export default` : `module.exports =` : `export default`;
851
+ const exportSyntax = "export default";
961
852
  generator.push(`${exportSyntax} function (Component) {`);
962
853
  generator.indent();
963
- const componentVariable = bridge ? `Component.options || Component` : useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
854
+ const componentVariable = useClassComponent ? `Component.__o || Component.__vccOpts || Component` : `Component`;
964
855
  generator.pushline(`const ${componentNamespace} = ${componentVariable}`);
965
856
  generator.pushline(
966
857
  `${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
@@ -1096,16 +987,6 @@ function _generate(generator, node, options = {}, injector) {
1096
987
  if (type === "sfc") {
1097
988
  generator.deindent();
1098
989
  generator.push(`})`);
1099
- if (bridge && injector) {
1100
- generator.newline();
1101
- generator.pushline(
1102
- `${componentNamespace}.__i18nBridge = ${componentNamespace}.__i18nBridge || []`
1103
- );
1104
- generator.pushline(
1105
- `${componentNamespace}.__i18nBridge.push('${injector()}')`
1106
- );
1107
- generator.pushline(`delete ${componentNamespace}._Ctor`);
1108
- }
1109
990
  generator.deindent();
1110
991
  generator.pushline(`}`);
1111
992
  } else if (type === "plain") {
@@ -1206,16 +1087,6 @@ function checkInstallPackage(pkg, debug) {
1206
1087
  `${pkg} requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
1207
1088
  );
1208
1089
  }
1209
- function checkVueI18nBridgeInstallPackage(debug) {
1210
- let ret = false;
1211
- try {
1212
- debug(`vue-i18n-bridge load path: ${_require.resolve("vue-i18n-bridge")}`);
1213
- ret = true;
1214
- } catch (e) {
1215
- debug(`cannot find 'vue-i18n-bridge'`, e);
1216
- }
1217
- return ret;
1218
- }
1219
1090
  function getVueI18nVersion(debug) {
1220
1091
  const VueI18n = loadModule("vue-i18n", debug);
1221
1092
  if (VueI18n == null) {
@@ -1238,4 +1109,4 @@ function loadModule(moduleName, debug) {
1238
1109
  }
1239
1110
  }
1240
1111
 
1241
- export { checkInstallPackage, checkVueI18nBridgeInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
1112
+ export { checkInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@intlify/bundle-utils",
3
3
  "description": "Bundle utilities for Intlify project",
4
- "version": "7.5.0",
4
+ "version": "8.0.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -21,10 +21,9 @@
21
21
  "@intlify/message-compiler": "^9.4.0",
22
22
  "@intlify/shared": "^9.4.0",
23
23
  "acorn": "^8.8.2",
24
- "escodegen": "^2.0.0",
24
+ "escodegen": "^2.1.0",
25
25
  "estree-walker": "^2.0.2",
26
26
  "jsonc-eslint-parser": "^2.3.0",
27
- "magic-string": "^0.30.0",
28
27
  "mlly": "^1.2.0",
29
28
  "source-map-js": "^1.0.1",
30
29
  "yaml-eslint-parser": "^1.2.2"