@intlify/bundle-utils 7.5.1 → 9.0.0-beta.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 +44 -163
- package/lib/index.d.cts +6 -9
- package/lib/index.d.mts +6 -9
- package/lib/index.d.ts +6 -9
- package/lib/index.mjs +45 -162
- package/package.json +4 -5
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 = "",
|
|
@@ -309,14 +286,11 @@ function generate$2(targetSource, {
|
|
|
309
286
|
onError = void 0,
|
|
310
287
|
strictMessage = true,
|
|
311
288
|
escapeHtml = false,
|
|
312
|
-
useClassComponent = false,
|
|
313
289
|
jit = false
|
|
314
|
-
}
|
|
290
|
+
}) {
|
|
315
291
|
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
316
292
|
const options = {
|
|
317
293
|
type,
|
|
318
|
-
bridge,
|
|
319
|
-
exportESM,
|
|
320
294
|
source: value,
|
|
321
295
|
sourceMap,
|
|
322
296
|
locale,
|
|
@@ -328,10 +302,8 @@ function generate$2(targetSource, {
|
|
|
328
302
|
onError,
|
|
329
303
|
strictMessage,
|
|
330
304
|
escapeHtml,
|
|
331
|
-
useClassComponent,
|
|
332
305
|
jit
|
|
333
306
|
};
|
|
334
|
-
const generator = createCodeGenerator(options);
|
|
335
307
|
let ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
|
|
336
308
|
if (!locale && type === "sfc" && onlyLocales?.length) {
|
|
337
309
|
const messages = jsoncEslintParser.getStaticJSONValue(ast);
|
|
@@ -343,21 +315,14 @@ function generate$2(targetSource, {
|
|
|
343
315
|
);
|
|
344
316
|
ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
|
|
345
317
|
}
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
ast,
|
|
352
|
-
code: s.toString(),
|
|
353
|
-
map: s.generateMap({
|
|
354
|
-
file: filename,
|
|
355
|
-
source: value,
|
|
356
|
-
includeContent: true
|
|
357
|
-
})
|
|
358
|
-
};
|
|
318
|
+
if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
|
|
319
|
+
value = JSON.stringify({});
|
|
320
|
+
ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
|
|
321
|
+
options.locale = "";
|
|
322
|
+
options.source = void 0;
|
|
359
323
|
}
|
|
360
|
-
const
|
|
324
|
+
const generator = createCodeGenerator(options);
|
|
325
|
+
const codeMaps = _generate$2(generator, ast, options);
|
|
361
326
|
const { code, map } = generator.context();
|
|
362
327
|
const newMap = map && !jit ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
|
|
363
328
|
return {
|
|
@@ -366,22 +331,13 @@ function generate$2(targetSource, {
|
|
|
366
331
|
map: newMap != null ? newMap : void 0
|
|
367
332
|
};
|
|
368
333
|
}
|
|
369
|
-
function _generate$2(generator, node, options = {}
|
|
334
|
+
function _generate$2(generator, node, options = {}) {
|
|
370
335
|
const propsCountStack = [];
|
|
371
336
|
const pathStack = [];
|
|
372
337
|
const itemsCountStack = [];
|
|
373
338
|
const { forceStringify } = generator.context();
|
|
374
339
|
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;
|
|
340
|
+
const { type, sourceMap, isGlobal, locale, jit } = options;
|
|
385
341
|
const codegenFn = jit ? generateResourceAst : generateMessageFunction;
|
|
386
342
|
const componentNamespace = "_Component";
|
|
387
343
|
jsoncEslintParser.traverseNodes(node, {
|
|
@@ -393,11 +349,13 @@ function _generate$2(generator, node, options = {}, injector) {
|
|
|
393
349
|
} else if (type === "sfc") {
|
|
394
350
|
const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
|
|
395
351
|
const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
|
|
396
|
-
const exportSyntax =
|
|
352
|
+
const exportSyntax = "export default";
|
|
397
353
|
generator.push(`${exportSyntax} function (Component) {`);
|
|
398
354
|
generator.indent();
|
|
399
|
-
const componentVariable =
|
|
400
|
-
generator.pushline(
|
|
355
|
+
const componentVariable = `Component`;
|
|
356
|
+
generator.pushline(
|
|
357
|
+
`const ${componentNamespace} = ${componentVariable}`
|
|
358
|
+
);
|
|
401
359
|
generator.pushline(
|
|
402
360
|
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
|
|
403
361
|
);
|
|
@@ -495,16 +453,6 @@ function _generate$2(generator, node, options = {}, injector) {
|
|
|
495
453
|
if (type === "sfc") {
|
|
496
454
|
generator.deindent();
|
|
497
455
|
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
456
|
generator.deindent();
|
|
509
457
|
generator.pushline(`}`);
|
|
510
458
|
} else if (type === "plain") {
|
|
@@ -565,12 +513,7 @@ function _generate$2(generator, node, options = {}, injector) {
|
|
|
565
513
|
|
|
566
514
|
function generate$1(targetSource, {
|
|
567
515
|
type = "plain",
|
|
568
|
-
legacy = false,
|
|
569
|
-
vueVersion = "v2.6",
|
|
570
|
-
bridge = false,
|
|
571
516
|
onlyLocales = [],
|
|
572
|
-
exportESM = false,
|
|
573
|
-
useClassComponent = false,
|
|
574
517
|
filename = "vue-i18n-loader.yaml",
|
|
575
518
|
inSourceMap = void 0,
|
|
576
519
|
locale = "",
|
|
@@ -582,12 +525,10 @@ function generate$1(targetSource, {
|
|
|
582
525
|
strictMessage = true,
|
|
583
526
|
escapeHtml = false,
|
|
584
527
|
jit = false
|
|
585
|
-
}
|
|
528
|
+
}) {
|
|
586
529
|
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
587
530
|
const options = {
|
|
588
531
|
type,
|
|
589
|
-
bridge,
|
|
590
|
-
exportESM,
|
|
591
532
|
source: value,
|
|
592
533
|
sourceMap,
|
|
593
534
|
locale,
|
|
@@ -599,10 +540,8 @@ function generate$1(targetSource, {
|
|
|
599
540
|
onError,
|
|
600
541
|
strictMessage,
|
|
601
542
|
escapeHtml,
|
|
602
|
-
useClassComponent,
|
|
603
543
|
jit
|
|
604
544
|
};
|
|
605
|
-
const generator = createCodeGenerator(options);
|
|
606
545
|
let ast = yamlEslintParser.parseYAML(value, { filePath: filename });
|
|
607
546
|
if (!locale && type === "sfc" && onlyLocales?.length) {
|
|
608
547
|
const messages = yamlEslintParser.getStaticYAMLValue(ast);
|
|
@@ -614,21 +553,14 @@ function generate$1(targetSource, {
|
|
|
614
553
|
);
|
|
615
554
|
ast = yamlEslintParser.parseYAML(value, { filePath: filename });
|
|
616
555
|
}
|
|
617
|
-
if (
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
ast,
|
|
623
|
-
code: s.toString(),
|
|
624
|
-
map: s.generateMap({
|
|
625
|
-
file: filename,
|
|
626
|
-
source: value,
|
|
627
|
-
includeContent: true
|
|
628
|
-
})
|
|
629
|
-
};
|
|
556
|
+
if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
|
|
557
|
+
value = JSON.stringify({});
|
|
558
|
+
ast = yamlEslintParser.parseYAML(value, { filePath: filename });
|
|
559
|
+
options.locale = "";
|
|
560
|
+
options.source = void 0;
|
|
630
561
|
}
|
|
631
|
-
const
|
|
562
|
+
const generator = createCodeGenerator(options);
|
|
563
|
+
const codeMaps = _generate$1(generator, ast, options);
|
|
632
564
|
const { code, map } = generator.context();
|
|
633
565
|
const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
|
|
634
566
|
return {
|
|
@@ -637,22 +569,13 @@ function generate$1(targetSource, {
|
|
|
637
569
|
map: newMap != null ? newMap : void 0
|
|
638
570
|
};
|
|
639
571
|
}
|
|
640
|
-
function _generate$1(generator, node, options = {}
|
|
572
|
+
function _generate$1(generator, node, options = {}) {
|
|
641
573
|
const propsCountStack = [];
|
|
642
574
|
const pathStack = [];
|
|
643
575
|
const itemsCountStack = [];
|
|
644
576
|
const { forceStringify } = generator.context();
|
|
645
577
|
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;
|
|
578
|
+
const { type, sourceMap, isGlobal, locale, jit } = options;
|
|
656
579
|
const codegenFn = jit ? generateResourceAst : generateMessageFunction;
|
|
657
580
|
const componentNamespace = "_Component";
|
|
658
581
|
yamlEslintParser.traverseNodes(node, {
|
|
@@ -664,11 +587,13 @@ function _generate$1(generator, node, options = {}, injector) {
|
|
|
664
587
|
} else if (type === "sfc") {
|
|
665
588
|
const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
|
|
666
589
|
const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
|
|
667
|
-
const exportSyntax =
|
|
590
|
+
const exportSyntax = "export default";
|
|
668
591
|
generator.push(`${exportSyntax} function (Component) {`);
|
|
669
592
|
generator.indent();
|
|
670
|
-
const componentVariable =
|
|
671
|
-
generator.pushline(
|
|
593
|
+
const componentVariable = `Component`;
|
|
594
|
+
generator.pushline(
|
|
595
|
+
`const ${componentNamespace} = ${componentVariable}`
|
|
596
|
+
);
|
|
672
597
|
generator.pushline(
|
|
673
598
|
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
|
|
674
599
|
);
|
|
@@ -766,16 +691,6 @@ function _generate$1(generator, node, options = {}, injector) {
|
|
|
766
691
|
if (type === "sfc") {
|
|
767
692
|
generator.deindent();
|
|
768
693
|
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
694
|
generator.deindent();
|
|
780
695
|
generator.push(`}`);
|
|
781
696
|
} else if (type === "plain") {
|
|
@@ -836,8 +751,6 @@ function _generate$1(generator, node, options = {}, injector) {
|
|
|
836
751
|
|
|
837
752
|
function generate(targetSource, {
|
|
838
753
|
type = "plain",
|
|
839
|
-
bridge = false,
|
|
840
|
-
exportESM = false,
|
|
841
754
|
filename = "vue-i18n-loader.js",
|
|
842
755
|
inSourceMap = void 0,
|
|
843
756
|
locale = "",
|
|
@@ -848,16 +761,13 @@ function generate(targetSource, {
|
|
|
848
761
|
onError = void 0,
|
|
849
762
|
strictMessage = true,
|
|
850
763
|
escapeHtml = false,
|
|
851
|
-
useClassComponent = false,
|
|
852
764
|
allowDynamic = false,
|
|
853
765
|
jit = false
|
|
854
|
-
}
|
|
766
|
+
}) {
|
|
855
767
|
const target = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
856
768
|
const value = target;
|
|
857
769
|
const options = {
|
|
858
770
|
type,
|
|
859
|
-
bridge,
|
|
860
|
-
exportESM,
|
|
861
771
|
source: value,
|
|
862
772
|
sourceMap,
|
|
863
773
|
locale,
|
|
@@ -869,7 +779,6 @@ function generate(targetSource, {
|
|
|
869
779
|
onError,
|
|
870
780
|
strictMessage,
|
|
871
781
|
escapeHtml,
|
|
872
|
-
useClassComponent,
|
|
873
782
|
jit
|
|
874
783
|
};
|
|
875
784
|
const generator = createCodeGenerator(options);
|
|
@@ -900,7 +809,7 @@ function generate(targetSource, {
|
|
|
900
809
|
};
|
|
901
810
|
}
|
|
902
811
|
}
|
|
903
|
-
const codeMaps = _generate(generator, ast, options
|
|
812
|
+
const codeMaps = _generate(generator, ast, options);
|
|
904
813
|
const { code, map } = generator.context();
|
|
905
814
|
const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
|
|
906
815
|
return {
|
|
@@ -930,23 +839,14 @@ function scanAst(ast) {
|
|
|
930
839
|
}
|
|
931
840
|
return ret;
|
|
932
841
|
}
|
|
933
|
-
function _generate(generator, node, options = {}
|
|
842
|
+
function _generate(generator, node, options = {}) {
|
|
934
843
|
const propsCountStack = [];
|
|
935
844
|
const pathStack = [];
|
|
936
845
|
const itemsCountStack = [];
|
|
937
846
|
const skipStack = [];
|
|
938
847
|
const { forceStringify } = generator.context();
|
|
939
848
|
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;
|
|
849
|
+
const { type, sourceMap, isGlobal, locale, jit } = options;
|
|
950
850
|
const codegenFn = jit ? generateResourceAst : generateMessageFunction;
|
|
951
851
|
const componentNamespace = "_Component";
|
|
952
852
|
estreeWalker.walk(node, {
|
|
@@ -965,11 +865,13 @@ function _generate(generator, node, options = {}, injector) {
|
|
|
965
865
|
} else if (type === "sfc") {
|
|
966
866
|
const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
|
|
967
867
|
const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
|
|
968
|
-
const exportSyntax =
|
|
868
|
+
const exportSyntax = "export default";
|
|
969
869
|
generator.push(`${exportSyntax} function (Component) {`);
|
|
970
870
|
generator.indent();
|
|
971
|
-
const componentVariable =
|
|
972
|
-
generator.pushline(
|
|
871
|
+
const componentVariable = `Component`;
|
|
872
|
+
generator.pushline(
|
|
873
|
+
`const ${componentNamespace} = ${componentVariable}`
|
|
874
|
+
);
|
|
973
875
|
generator.pushline(
|
|
974
876
|
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
|
|
975
877
|
);
|
|
@@ -1104,16 +1006,6 @@ function _generate(generator, node, options = {}, injector) {
|
|
|
1104
1006
|
if (type === "sfc") {
|
|
1105
1007
|
generator.deindent();
|
|
1106
1008
|
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
1009
|
generator.deindent();
|
|
1118
1010
|
generator.pushline(`}`);
|
|
1119
1011
|
} else if (type === "plain") {
|
|
@@ -1214,27 +1106,17 @@ function checkInstallPackage(pkg, debug) {
|
|
|
1214
1106
|
`${pkg} requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
|
|
1215
1107
|
);
|
|
1216
1108
|
}
|
|
1217
|
-
function
|
|
1218
|
-
|
|
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
|
-
function getVueI18nVersion(debug) {
|
|
1228
|
-
const VueI18n = loadModule("vue-i18n", debug);
|
|
1109
|
+
function getVueI18nVersion(debug, pkg = "vue-i18n") {
|
|
1110
|
+
const VueI18n = loadModule(pkg, debug);
|
|
1229
1111
|
if (VueI18n == null) {
|
|
1230
1112
|
return "";
|
|
1231
1113
|
}
|
|
1232
|
-
if (VueI18n.version && VueI18n.version.startsWith("8.")) {
|
|
1233
|
-
return "8";
|
|
1234
|
-
}
|
|
1235
1114
|
if (VueI18n.VERSION && VueI18n.VERSION.startsWith("9.")) {
|
|
1236
1115
|
return "9";
|
|
1237
1116
|
}
|
|
1117
|
+
if (VueI18n.VERSION && VueI18n.VERSION.startsWith("10.")) {
|
|
1118
|
+
return "10";
|
|
1119
|
+
}
|
|
1238
1120
|
return "unknown";
|
|
1239
1121
|
}
|
|
1240
1122
|
function loadModule(moduleName, debug) {
|
|
@@ -1247,7 +1129,6 @@ function loadModule(moduleName, debug) {
|
|
|
1247
1129
|
}
|
|
1248
1130
|
|
|
1249
1131
|
exports.checkInstallPackage = checkInstallPackage;
|
|
1250
|
-
exports.checkVueI18nBridgeInstallPackage = checkVueI18nBridgeInstallPackage;
|
|
1251
1132
|
exports.generateJSON = generate$2;
|
|
1252
1133
|
exports.generateJavaScript = generate;
|
|
1253
1134
|
exports.generateYAML = generate$1;
|
package/lib/index.d.cts
CHANGED
|
@@ -16,7 +16,6 @@ type DevEnv = 'development' | 'production';
|
|
|
16
16
|
interface CodeGenOptions {
|
|
17
17
|
type?: 'plain' | 'sfc' | 'bare';
|
|
18
18
|
legacy?: boolean;
|
|
19
|
-
vueVersion?: 'v2.6' | 'v2.7';
|
|
20
19
|
bridge?: boolean;
|
|
21
20
|
exportESM?: boolean;
|
|
22
21
|
onlyLocales?: string[];
|
|
@@ -28,7 +27,6 @@ interface CodeGenOptions {
|
|
|
28
27
|
locale?: string;
|
|
29
28
|
env?: DevEnv;
|
|
30
29
|
forceStringify?: boolean;
|
|
31
|
-
useClassComponent?: boolean;
|
|
32
30
|
allowDynamic?: boolean;
|
|
33
31
|
strictMessage?: boolean;
|
|
34
32
|
escapeHtml?: boolean;
|
|
@@ -54,7 +52,7 @@ interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
|
|
|
54
52
|
* Code / AST generator for i18n json/json5 resource
|
|
55
53
|
*/
|
|
56
54
|
|
|
57
|
-
declare function generate$2(targetSource: string | Buffer, { type,
|
|
55
|
+
declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
58
|
* Code generator for i18n yaml resource
|
|
@@ -63,7 +61,7 @@ declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVe
|
|
|
63
61
|
/**
|
|
64
62
|
* @internal
|
|
65
63
|
*/
|
|
66
|
-
declare function generate$1(targetSource: string | Buffer, { type,
|
|
64
|
+
declare function generate$1(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
|
|
67
65
|
|
|
68
66
|
/**
|
|
69
67
|
* Code generator for i18n js resource
|
|
@@ -72,12 +70,11 @@ declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVe
|
|
|
72
70
|
/**
|
|
73
71
|
* @internal
|
|
74
72
|
*/
|
|
75
|
-
declare function generate(targetSource: string | Buffer, { type,
|
|
73
|
+
declare function generate(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
|
|
76
74
|
|
|
77
75
|
type InstalledPackage = 'vue-i18n' | 'petite-vue-i18n';
|
|
78
76
|
declare function checkInstallPackage(pkg: string, debug: Function): InstalledPackage;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
declare function getVueI18nVersion(debug: Function): VueI18nVersion;
|
|
77
|
+
type VueI18nVersion = '9' | '10' | 'unknown' | '';
|
|
78
|
+
declare function getVueI18nVersion(debug: Function, pkg?: string): VueI18nVersion;
|
|
82
79
|
|
|
83
|
-
export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage,
|
|
80
|
+
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
|
@@ -16,7 +16,6 @@ type DevEnv = 'development' | 'production';
|
|
|
16
16
|
interface CodeGenOptions {
|
|
17
17
|
type?: 'plain' | 'sfc' | 'bare';
|
|
18
18
|
legacy?: boolean;
|
|
19
|
-
vueVersion?: 'v2.6' | 'v2.7';
|
|
20
19
|
bridge?: boolean;
|
|
21
20
|
exportESM?: boolean;
|
|
22
21
|
onlyLocales?: string[];
|
|
@@ -28,7 +27,6 @@ interface CodeGenOptions {
|
|
|
28
27
|
locale?: string;
|
|
29
28
|
env?: DevEnv;
|
|
30
29
|
forceStringify?: boolean;
|
|
31
|
-
useClassComponent?: boolean;
|
|
32
30
|
allowDynamic?: boolean;
|
|
33
31
|
strictMessage?: boolean;
|
|
34
32
|
escapeHtml?: boolean;
|
|
@@ -54,7 +52,7 @@ interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
|
|
|
54
52
|
* Code / AST generator for i18n json/json5 resource
|
|
55
53
|
*/
|
|
56
54
|
|
|
57
|
-
declare function generate$2(targetSource: string | Buffer, { type,
|
|
55
|
+
declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
58
|
* Code generator for i18n yaml resource
|
|
@@ -63,7 +61,7 @@ declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVe
|
|
|
63
61
|
/**
|
|
64
62
|
* @internal
|
|
65
63
|
*/
|
|
66
|
-
declare function generate$1(targetSource: string | Buffer, { type,
|
|
64
|
+
declare function generate$1(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
|
|
67
65
|
|
|
68
66
|
/**
|
|
69
67
|
* Code generator for i18n js resource
|
|
@@ -72,12 +70,11 @@ declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVe
|
|
|
72
70
|
/**
|
|
73
71
|
* @internal
|
|
74
72
|
*/
|
|
75
|
-
declare function generate(targetSource: string | Buffer, { type,
|
|
73
|
+
declare function generate(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
|
|
76
74
|
|
|
77
75
|
type InstalledPackage = 'vue-i18n' | 'petite-vue-i18n';
|
|
78
76
|
declare function checkInstallPackage(pkg: string, debug: Function): InstalledPackage;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
declare function getVueI18nVersion(debug: Function): VueI18nVersion;
|
|
77
|
+
type VueI18nVersion = '9' | '10' | 'unknown' | '';
|
|
78
|
+
declare function getVueI18nVersion(debug: Function, pkg?: string): VueI18nVersion;
|
|
82
79
|
|
|
83
|
-
export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage,
|
|
80
|
+
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
|
@@ -16,7 +16,6 @@ type DevEnv = 'development' | 'production';
|
|
|
16
16
|
interface CodeGenOptions {
|
|
17
17
|
type?: 'plain' | 'sfc' | 'bare';
|
|
18
18
|
legacy?: boolean;
|
|
19
|
-
vueVersion?: 'v2.6' | 'v2.7';
|
|
20
19
|
bridge?: boolean;
|
|
21
20
|
exportESM?: boolean;
|
|
22
21
|
onlyLocales?: string[];
|
|
@@ -28,7 +27,6 @@ interface CodeGenOptions {
|
|
|
28
27
|
locale?: string;
|
|
29
28
|
env?: DevEnv;
|
|
30
29
|
forceStringify?: boolean;
|
|
31
|
-
useClassComponent?: boolean;
|
|
32
30
|
allowDynamic?: boolean;
|
|
33
31
|
strictMessage?: boolean;
|
|
34
32
|
escapeHtml?: boolean;
|
|
@@ -54,7 +52,7 @@ interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
|
|
|
54
52
|
* Code / AST generator for i18n json/json5 resource
|
|
55
53
|
*/
|
|
56
54
|
|
|
57
|
-
declare function generate$2(targetSource: string | Buffer, { type,
|
|
55
|
+
declare function generate$2(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<JSONProgram>;
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
58
|
* Code generator for i18n yaml resource
|
|
@@ -63,7 +61,7 @@ declare function generate$2(targetSource: string | Buffer, { type, legacy, vueVe
|
|
|
63
61
|
/**
|
|
64
62
|
* @internal
|
|
65
63
|
*/
|
|
66
|
-
declare function generate$1(targetSource: string | Buffer, { type,
|
|
64
|
+
declare function generate$1(targetSource: string | Buffer, { type, onlyLocales, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions): CodeGenResult<YAMLProgram>;
|
|
67
65
|
|
|
68
66
|
/**
|
|
69
67
|
* Code generator for i18n js resource
|
|
@@ -72,12 +70,11 @@ declare function generate$1(targetSource: string | Buffer, { type, legacy, vueVe
|
|
|
72
70
|
/**
|
|
73
71
|
* @internal
|
|
74
72
|
*/
|
|
75
|
-
declare function generate(targetSource: string | Buffer, { type,
|
|
73
|
+
declare function generate(targetSource: string | Buffer, { type, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, allowDynamic, jit }: CodeGenOptions): CodeGenResult<Node>;
|
|
76
74
|
|
|
77
75
|
type InstalledPackage = 'vue-i18n' | 'petite-vue-i18n';
|
|
78
76
|
declare function checkInstallPackage(pkg: string, debug: Function): InstalledPackage;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
declare function getVueI18nVersion(debug: Function): VueI18nVersion;
|
|
77
|
+
type VueI18nVersion = '9' | '10' | 'unknown' | '';
|
|
78
|
+
declare function getVueI18nVersion(debug: Function, pkg?: string): VueI18nVersion;
|
|
82
79
|
|
|
83
|
-
export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage,
|
|
80
|
+
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 = "",
|
|
@@ -301,14 +279,11 @@ function generate$2(targetSource, {
|
|
|
301
279
|
onError = void 0,
|
|
302
280
|
strictMessage = true,
|
|
303
281
|
escapeHtml = false,
|
|
304
|
-
useClassComponent = false,
|
|
305
282
|
jit = false
|
|
306
|
-
}
|
|
283
|
+
}) {
|
|
307
284
|
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
308
285
|
const options = {
|
|
309
286
|
type,
|
|
310
|
-
bridge,
|
|
311
|
-
exportESM,
|
|
312
287
|
source: value,
|
|
313
288
|
sourceMap,
|
|
314
289
|
locale,
|
|
@@ -320,10 +295,8 @@ function generate$2(targetSource, {
|
|
|
320
295
|
onError,
|
|
321
296
|
strictMessage,
|
|
322
297
|
escapeHtml,
|
|
323
|
-
useClassComponent,
|
|
324
298
|
jit
|
|
325
299
|
};
|
|
326
|
-
const generator = createCodeGenerator(options);
|
|
327
300
|
let ast = parseJSON(value, { filePath: filename });
|
|
328
301
|
if (!locale && type === "sfc" && onlyLocales?.length) {
|
|
329
302
|
const messages = getStaticJSONValue(ast);
|
|
@@ -335,21 +308,14 @@ function generate$2(targetSource, {
|
|
|
335
308
|
);
|
|
336
309
|
ast = parseJSON(value, { filePath: filename });
|
|
337
310
|
}
|
|
338
|
-
if (
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
ast,
|
|
344
|
-
code: s.toString(),
|
|
345
|
-
map: s.generateMap({
|
|
346
|
-
file: filename,
|
|
347
|
-
source: value,
|
|
348
|
-
includeContent: true
|
|
349
|
-
})
|
|
350
|
-
};
|
|
311
|
+
if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
|
|
312
|
+
value = JSON.stringify({});
|
|
313
|
+
ast = parseJSON(value, { filePath: filename });
|
|
314
|
+
options.locale = "";
|
|
315
|
+
options.source = void 0;
|
|
351
316
|
}
|
|
352
|
-
const
|
|
317
|
+
const generator = createCodeGenerator(options);
|
|
318
|
+
const codeMaps = _generate$2(generator, ast, options);
|
|
353
319
|
const { code, map } = generator.context();
|
|
354
320
|
const newMap = map && !jit ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
|
|
355
321
|
return {
|
|
@@ -358,22 +324,13 @@ function generate$2(targetSource, {
|
|
|
358
324
|
map: newMap != null ? newMap : void 0
|
|
359
325
|
};
|
|
360
326
|
}
|
|
361
|
-
function _generate$2(generator, node, options = {}
|
|
327
|
+
function _generate$2(generator, node, options = {}) {
|
|
362
328
|
const propsCountStack = [];
|
|
363
329
|
const pathStack = [];
|
|
364
330
|
const itemsCountStack = [];
|
|
365
331
|
const { forceStringify } = generator.context();
|
|
366
332
|
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;
|
|
333
|
+
const { type, sourceMap, isGlobal, locale, jit } = options;
|
|
377
334
|
const codegenFn = jit ? generateResourceAst : generateMessageFunction;
|
|
378
335
|
const componentNamespace = "_Component";
|
|
379
336
|
traverseNodes(node, {
|
|
@@ -385,11 +342,13 @@ function _generate$2(generator, node, options = {}, injector) {
|
|
|
385
342
|
} else if (type === "sfc") {
|
|
386
343
|
const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
|
|
387
344
|
const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
|
|
388
|
-
const exportSyntax =
|
|
345
|
+
const exportSyntax = "export default";
|
|
389
346
|
generator.push(`${exportSyntax} function (Component) {`);
|
|
390
347
|
generator.indent();
|
|
391
|
-
const componentVariable =
|
|
392
|
-
generator.pushline(
|
|
348
|
+
const componentVariable = `Component`;
|
|
349
|
+
generator.pushline(
|
|
350
|
+
`const ${componentNamespace} = ${componentVariable}`
|
|
351
|
+
);
|
|
393
352
|
generator.pushline(
|
|
394
353
|
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
|
|
395
354
|
);
|
|
@@ -487,16 +446,6 @@ function _generate$2(generator, node, options = {}, injector) {
|
|
|
487
446
|
if (type === "sfc") {
|
|
488
447
|
generator.deindent();
|
|
489
448
|
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
449
|
generator.deindent();
|
|
501
450
|
generator.pushline(`}`);
|
|
502
451
|
} else if (type === "plain") {
|
|
@@ -557,12 +506,7 @@ function _generate$2(generator, node, options = {}, injector) {
|
|
|
557
506
|
|
|
558
507
|
function generate$1(targetSource, {
|
|
559
508
|
type = "plain",
|
|
560
|
-
legacy = false,
|
|
561
|
-
vueVersion = "v2.6",
|
|
562
|
-
bridge = false,
|
|
563
509
|
onlyLocales = [],
|
|
564
|
-
exportESM = false,
|
|
565
|
-
useClassComponent = false,
|
|
566
510
|
filename = "vue-i18n-loader.yaml",
|
|
567
511
|
inSourceMap = void 0,
|
|
568
512
|
locale = "",
|
|
@@ -574,12 +518,10 @@ function generate$1(targetSource, {
|
|
|
574
518
|
strictMessage = true,
|
|
575
519
|
escapeHtml = false,
|
|
576
520
|
jit = false
|
|
577
|
-
}
|
|
521
|
+
}) {
|
|
578
522
|
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
579
523
|
const options = {
|
|
580
524
|
type,
|
|
581
|
-
bridge,
|
|
582
|
-
exportESM,
|
|
583
525
|
source: value,
|
|
584
526
|
sourceMap,
|
|
585
527
|
locale,
|
|
@@ -591,10 +533,8 @@ function generate$1(targetSource, {
|
|
|
591
533
|
onError,
|
|
592
534
|
strictMessage,
|
|
593
535
|
escapeHtml,
|
|
594
|
-
useClassComponent,
|
|
595
536
|
jit
|
|
596
537
|
};
|
|
597
|
-
const generator = createCodeGenerator(options);
|
|
598
538
|
let ast = parseYAML(value, { filePath: filename });
|
|
599
539
|
if (!locale && type === "sfc" && onlyLocales?.length) {
|
|
600
540
|
const messages = getStaticYAMLValue(ast);
|
|
@@ -606,21 +546,14 @@ function generate$1(targetSource, {
|
|
|
606
546
|
);
|
|
607
547
|
ast = parseYAML(value, { filePath: filename });
|
|
608
548
|
}
|
|
609
|
-
if (
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
ast,
|
|
615
|
-
code: s.toString(),
|
|
616
|
-
map: s.generateMap({
|
|
617
|
-
file: filename,
|
|
618
|
-
source: value,
|
|
619
|
-
includeContent: true
|
|
620
|
-
})
|
|
621
|
-
};
|
|
549
|
+
if (locale && onlyLocales?.length && !onlyLocales.includes(locale)) {
|
|
550
|
+
value = JSON.stringify({});
|
|
551
|
+
ast = parseYAML(value, { filePath: filename });
|
|
552
|
+
options.locale = "";
|
|
553
|
+
options.source = void 0;
|
|
622
554
|
}
|
|
623
|
-
const
|
|
555
|
+
const generator = createCodeGenerator(options);
|
|
556
|
+
const codeMaps = _generate$1(generator, ast, options);
|
|
624
557
|
const { code, map } = generator.context();
|
|
625
558
|
const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
|
|
626
559
|
return {
|
|
@@ -629,22 +562,13 @@ function generate$1(targetSource, {
|
|
|
629
562
|
map: newMap != null ? newMap : void 0
|
|
630
563
|
};
|
|
631
564
|
}
|
|
632
|
-
function _generate$1(generator, node, options = {}
|
|
565
|
+
function _generate$1(generator, node, options = {}) {
|
|
633
566
|
const propsCountStack = [];
|
|
634
567
|
const pathStack = [];
|
|
635
568
|
const itemsCountStack = [];
|
|
636
569
|
const { forceStringify } = generator.context();
|
|
637
570
|
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;
|
|
571
|
+
const { type, sourceMap, isGlobal, locale, jit } = options;
|
|
648
572
|
const codegenFn = jit ? generateResourceAst : generateMessageFunction;
|
|
649
573
|
const componentNamespace = "_Component";
|
|
650
574
|
traverseNodes$1(node, {
|
|
@@ -656,11 +580,13 @@ function _generate$1(generator, node, options = {}, injector) {
|
|
|
656
580
|
} else if (type === "sfc") {
|
|
657
581
|
const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
|
|
658
582
|
const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
|
|
659
|
-
const exportSyntax =
|
|
583
|
+
const exportSyntax = "export default";
|
|
660
584
|
generator.push(`${exportSyntax} function (Component) {`);
|
|
661
585
|
generator.indent();
|
|
662
|
-
const componentVariable =
|
|
663
|
-
generator.pushline(
|
|
586
|
+
const componentVariable = `Component`;
|
|
587
|
+
generator.pushline(
|
|
588
|
+
`const ${componentNamespace} = ${componentVariable}`
|
|
589
|
+
);
|
|
664
590
|
generator.pushline(
|
|
665
591
|
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
|
|
666
592
|
);
|
|
@@ -758,16 +684,6 @@ function _generate$1(generator, node, options = {}, injector) {
|
|
|
758
684
|
if (type === "sfc") {
|
|
759
685
|
generator.deindent();
|
|
760
686
|
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
687
|
generator.deindent();
|
|
772
688
|
generator.push(`}`);
|
|
773
689
|
} else if (type === "plain") {
|
|
@@ -828,8 +744,6 @@ function _generate$1(generator, node, options = {}, injector) {
|
|
|
828
744
|
|
|
829
745
|
function generate(targetSource, {
|
|
830
746
|
type = "plain",
|
|
831
|
-
bridge = false,
|
|
832
|
-
exportESM = false,
|
|
833
747
|
filename = "vue-i18n-loader.js",
|
|
834
748
|
inSourceMap = void 0,
|
|
835
749
|
locale = "",
|
|
@@ -840,16 +754,13 @@ function generate(targetSource, {
|
|
|
840
754
|
onError = void 0,
|
|
841
755
|
strictMessage = true,
|
|
842
756
|
escapeHtml = false,
|
|
843
|
-
useClassComponent = false,
|
|
844
757
|
allowDynamic = false,
|
|
845
758
|
jit = false
|
|
846
|
-
}
|
|
759
|
+
}) {
|
|
847
760
|
const target = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
848
761
|
const value = target;
|
|
849
762
|
const options = {
|
|
850
763
|
type,
|
|
851
|
-
bridge,
|
|
852
|
-
exportESM,
|
|
853
764
|
source: value,
|
|
854
765
|
sourceMap,
|
|
855
766
|
locale,
|
|
@@ -861,7 +772,6 @@ function generate(targetSource, {
|
|
|
861
772
|
onError,
|
|
862
773
|
strictMessage,
|
|
863
774
|
escapeHtml,
|
|
864
|
-
useClassComponent,
|
|
865
775
|
jit
|
|
866
776
|
};
|
|
867
777
|
const generator = createCodeGenerator(options);
|
|
@@ -892,7 +802,7 @@ function generate(targetSource, {
|
|
|
892
802
|
};
|
|
893
803
|
}
|
|
894
804
|
}
|
|
895
|
-
const codeMaps = _generate(generator, ast, options
|
|
805
|
+
const codeMaps = _generate(generator, ast, options);
|
|
896
806
|
const { code, map } = generator.context();
|
|
897
807
|
const newMap = map ? mapLinesColumns(map.toJSON(), codeMaps, inSourceMap) || null : null;
|
|
898
808
|
return {
|
|
@@ -922,23 +832,14 @@ function scanAst(ast) {
|
|
|
922
832
|
}
|
|
923
833
|
return ret;
|
|
924
834
|
}
|
|
925
|
-
function _generate(generator, node, options = {}
|
|
835
|
+
function _generate(generator, node, options = {}) {
|
|
926
836
|
const propsCountStack = [];
|
|
927
837
|
const pathStack = [];
|
|
928
838
|
const itemsCountStack = [];
|
|
929
839
|
const skipStack = [];
|
|
930
840
|
const { forceStringify } = generator.context();
|
|
931
841
|
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;
|
|
842
|
+
const { type, sourceMap, isGlobal, locale, jit } = options;
|
|
942
843
|
const codegenFn = jit ? generateResourceAst : generateMessageFunction;
|
|
943
844
|
const componentNamespace = "_Component";
|
|
944
845
|
walk(node, {
|
|
@@ -957,11 +858,13 @@ function _generate(generator, node, options = {}, injector) {
|
|
|
957
858
|
} else if (type === "sfc") {
|
|
958
859
|
const variableName = type === "sfc" ? !isGlobal ? "__i18n" : "__i18nGlobal" : "";
|
|
959
860
|
const localeName = type === "sfc" ? locale != null ? locale : `""` : "";
|
|
960
|
-
const exportSyntax =
|
|
861
|
+
const exportSyntax = "export default";
|
|
961
862
|
generator.push(`${exportSyntax} function (Component) {`);
|
|
962
863
|
generator.indent();
|
|
963
|
-
const componentVariable =
|
|
964
|
-
generator.pushline(
|
|
864
|
+
const componentVariable = `Component`;
|
|
865
|
+
generator.pushline(
|
|
866
|
+
`const ${componentNamespace} = ${componentVariable}`
|
|
867
|
+
);
|
|
965
868
|
generator.pushline(
|
|
966
869
|
`${componentNamespace}.${variableName} = ${componentNamespace}.${variableName} || []`
|
|
967
870
|
);
|
|
@@ -1096,16 +999,6 @@ function _generate(generator, node, options = {}, injector) {
|
|
|
1096
999
|
if (type === "sfc") {
|
|
1097
1000
|
generator.deindent();
|
|
1098
1001
|
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
1002
|
generator.deindent();
|
|
1110
1003
|
generator.pushline(`}`);
|
|
1111
1004
|
} else if (type === "plain") {
|
|
@@ -1206,27 +1099,17 @@ function checkInstallPackage(pkg, debug) {
|
|
|
1206
1099
|
`${pkg} requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
|
|
1207
1100
|
);
|
|
1208
1101
|
}
|
|
1209
|
-
function
|
|
1210
|
-
|
|
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
|
-
function getVueI18nVersion(debug) {
|
|
1220
|
-
const VueI18n = loadModule("vue-i18n", debug);
|
|
1102
|
+
function getVueI18nVersion(debug, pkg = "vue-i18n") {
|
|
1103
|
+
const VueI18n = loadModule(pkg, debug);
|
|
1221
1104
|
if (VueI18n == null) {
|
|
1222
1105
|
return "";
|
|
1223
1106
|
}
|
|
1224
|
-
if (VueI18n.version && VueI18n.version.startsWith("8.")) {
|
|
1225
|
-
return "8";
|
|
1226
|
-
}
|
|
1227
1107
|
if (VueI18n.VERSION && VueI18n.VERSION.startsWith("9.")) {
|
|
1228
1108
|
return "9";
|
|
1229
1109
|
}
|
|
1110
|
+
if (VueI18n.VERSION && VueI18n.VERSION.startsWith("10.")) {
|
|
1111
|
+
return "10";
|
|
1112
|
+
}
|
|
1230
1113
|
return "unknown";
|
|
1231
1114
|
}
|
|
1232
1115
|
function loadModule(moduleName, debug) {
|
|
@@ -1238,4 +1121,4 @@ function loadModule(moduleName, debug) {
|
|
|
1238
1121
|
}
|
|
1239
1122
|
}
|
|
1240
1123
|
|
|
1241
|
-
export { checkInstallPackage,
|
|
1124
|
+
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": "
|
|
4
|
+
"version": "9.0.0-beta.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -18,13 +18,12 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@intlify/message-compiler": "
|
|
22
|
-
"@intlify/shared": "
|
|
21
|
+
"@intlify/message-compiler": "next",
|
|
22
|
+
"@intlify/shared": "next",
|
|
23
23
|
"acorn": "^8.8.2",
|
|
24
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"
|
|
@@ -35,7 +34,7 @@
|
|
|
35
34
|
"unbuild": "^2.0.0"
|
|
36
35
|
},
|
|
37
36
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
37
|
+
"node": ">= 18"
|
|
39
38
|
},
|
|
40
39
|
"files": [
|
|
41
40
|
"lib",
|