@intlify/bundle-utils 7.3.0 → 7.5.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 +49 -10
- package/lib/index.d.cts +83 -0
- package/lib/index.d.mts +83 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.mjs +49 -11
- package/package.json +3 -3
package/lib/index.cjs
CHANGED
|
@@ -11,6 +11,7 @@ const escodegen = require('escodegen');
|
|
|
11
11
|
const estreeWalker = require('estree-walker');
|
|
12
12
|
const module$1 = require('node:module');
|
|
13
13
|
|
|
14
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
14
15
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
15
16
|
|
|
16
17
|
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
@@ -261,9 +262,24 @@ function generateResourceAst(msg, options = {}, path) {
|
|
|
261
262
|
const code = !occured ? `${shared.friendlyJSONstringify(ast)}` : `\`${_msg}\``;
|
|
262
263
|
return { code, ast, map, errors };
|
|
263
264
|
}
|
|
265
|
+
function excludeLocales({
|
|
266
|
+
messages,
|
|
267
|
+
onlyLocales
|
|
268
|
+
}) {
|
|
269
|
+
const _messages = { ...messages };
|
|
270
|
+
Object.keys(_messages).forEach((locale) => {
|
|
271
|
+
if (!onlyLocales.includes(locale)) {
|
|
272
|
+
delete _messages[locale];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
return _messages;
|
|
276
|
+
}
|
|
264
277
|
|
|
265
|
-
function generateLegacyCode({
|
|
266
|
-
|
|
278
|
+
function generateLegacyCode({
|
|
279
|
+
isGlobal = false,
|
|
280
|
+
vueVersion = "v2.6"
|
|
281
|
+
}, generator) {
|
|
282
|
+
const componentNamespace = `Component${vueVersion === "v2.6" ? ".options" : ""}`;
|
|
267
283
|
const variableName = !isGlobal ? "__i18n" : "__i18nGlobal";
|
|
268
284
|
const exportSyntax = "export default";
|
|
269
285
|
const code = `${exportSyntax} function (Component) {
|
|
@@ -279,7 +295,9 @@ function generateLegacyCode({ isGlobal }, generator) {
|
|
|
279
295
|
function generate$2(targetSource, {
|
|
280
296
|
type = "plain",
|
|
281
297
|
legacy = false,
|
|
298
|
+
vueVersion = "v2.6",
|
|
282
299
|
bridge = false,
|
|
300
|
+
onlyLocales = [],
|
|
283
301
|
exportESM = false,
|
|
284
302
|
filename = "vue-i18n-loader.json",
|
|
285
303
|
inSourceMap = void 0,
|
|
@@ -294,8 +312,7 @@ function generate$2(targetSource, {
|
|
|
294
312
|
useClassComponent = false,
|
|
295
313
|
jit = false
|
|
296
314
|
}, injector) {
|
|
297
|
-
|
|
298
|
-
const value = target;
|
|
315
|
+
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
299
316
|
const options = {
|
|
300
317
|
type,
|
|
301
318
|
bridge,
|
|
@@ -315,10 +332,20 @@ function generate$2(targetSource, {
|
|
|
315
332
|
jit
|
|
316
333
|
};
|
|
317
334
|
const generator = createCodeGenerator(options);
|
|
318
|
-
|
|
335
|
+
let ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
|
|
336
|
+
if (!locale && type === "sfc" && onlyLocales?.length) {
|
|
337
|
+
const messages = jsoncEslintParser.getStaticJSONValue(ast);
|
|
338
|
+
value = JSON.stringify(
|
|
339
|
+
excludeLocales({
|
|
340
|
+
messages,
|
|
341
|
+
onlyLocales
|
|
342
|
+
})
|
|
343
|
+
);
|
|
344
|
+
ast = jsoncEslintParser.parseJSON(value, { filePath: filename });
|
|
345
|
+
}
|
|
319
346
|
if (legacy && type === "sfc") {
|
|
320
347
|
const gen = () => shared.friendlyJSONstringify(jsoncEslintParser.getStaticJSONValue(ast));
|
|
321
|
-
const code2 = generateLegacyCode(
|
|
348
|
+
const code2 = generateLegacyCode({ isGlobal, vueVersion }, gen);
|
|
322
349
|
const s = new MagicString__default(code2);
|
|
323
350
|
return {
|
|
324
351
|
ast,
|
|
@@ -539,7 +566,9 @@ function _generate$2(generator, node, options = {}, injector) {
|
|
|
539
566
|
function generate$1(targetSource, {
|
|
540
567
|
type = "plain",
|
|
541
568
|
legacy = false,
|
|
569
|
+
vueVersion = "v2.6",
|
|
542
570
|
bridge = false,
|
|
571
|
+
onlyLocales = [],
|
|
543
572
|
exportESM = false,
|
|
544
573
|
useClassComponent = false,
|
|
545
574
|
filename = "vue-i18n-loader.yaml",
|
|
@@ -554,7 +583,7 @@ function generate$1(targetSource, {
|
|
|
554
583
|
escapeHtml = false,
|
|
555
584
|
jit = false
|
|
556
585
|
}, injector) {
|
|
557
|
-
|
|
586
|
+
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
558
587
|
const options = {
|
|
559
588
|
type,
|
|
560
589
|
bridge,
|
|
@@ -574,10 +603,20 @@ function generate$1(targetSource, {
|
|
|
574
603
|
jit
|
|
575
604
|
};
|
|
576
605
|
const generator = createCodeGenerator(options);
|
|
577
|
-
|
|
606
|
+
let ast = yamlEslintParser.parseYAML(value, { filePath: filename });
|
|
607
|
+
if (!locale && type === "sfc" && onlyLocales?.length) {
|
|
608
|
+
const messages = yamlEslintParser.getStaticYAMLValue(ast);
|
|
609
|
+
value = JSON.stringify(
|
|
610
|
+
excludeLocales({
|
|
611
|
+
messages,
|
|
612
|
+
onlyLocales
|
|
613
|
+
})
|
|
614
|
+
);
|
|
615
|
+
ast = yamlEslintParser.parseYAML(value, { filePath: filename });
|
|
616
|
+
}
|
|
578
617
|
if (legacy && type === "sfc") {
|
|
579
618
|
const gen = () => shared.friendlyJSONstringify(yamlEslintParser.getStaticYAMLValue(ast));
|
|
580
|
-
const code2 = generateLegacyCode(
|
|
619
|
+
const code2 = generateLegacyCode({ isGlobal, vueVersion }, gen);
|
|
581
620
|
const s = new MagicString__default(code2);
|
|
582
621
|
return {
|
|
583
622
|
ast,
|
|
@@ -1149,7 +1188,7 @@ function getValue(node) {
|
|
|
1149
1188
|
return node.type === "Literal" ? node.value : node.type === "TemplateLiteral" ? node.quasis.map((quasi) => quasi.value.cooked).join("") : void 0;
|
|
1150
1189
|
}
|
|
1151
1190
|
|
|
1152
|
-
const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (
|
|
1191
|
+
const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
1153
1192
|
function checkInstallPackage(pkg, debug) {
|
|
1154
1193
|
let installedVueI18n = false;
|
|
1155
1194
|
try {
|
package/lib/index.d.cts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { JSONProgram } from 'jsonc-eslint-parser/lib/parser/ast';
|
|
2
|
+
import { RawSourceMap } from 'source-map-js';
|
|
3
|
+
import { CompileError } from '@intlify/message-compiler';
|
|
4
|
+
import { YAMLProgram } from 'yaml-eslint-parser/lib/ast';
|
|
5
|
+
import { Node } from 'estree';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Compilation dev environments
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
type DevEnv = 'development' | 'production';
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
interface CodeGenOptions {
|
|
17
|
+
type?: 'plain' | 'sfc' | 'bare';
|
|
18
|
+
legacy?: boolean;
|
|
19
|
+
vueVersion?: 'v2.6' | 'v2.7';
|
|
20
|
+
bridge?: boolean;
|
|
21
|
+
exportESM?: boolean;
|
|
22
|
+
onlyLocales?: string[];
|
|
23
|
+
source?: string;
|
|
24
|
+
sourceMap?: boolean;
|
|
25
|
+
filename?: string;
|
|
26
|
+
inSourceMap?: RawSourceMap;
|
|
27
|
+
isGlobal?: boolean;
|
|
28
|
+
locale?: string;
|
|
29
|
+
env?: DevEnv;
|
|
30
|
+
forceStringify?: boolean;
|
|
31
|
+
useClassComponent?: boolean;
|
|
32
|
+
allowDynamic?: boolean;
|
|
33
|
+
strictMessage?: boolean;
|
|
34
|
+
escapeHtml?: boolean;
|
|
35
|
+
jit?: boolean;
|
|
36
|
+
minify?: boolean;
|
|
37
|
+
onWarn?: (msg: string) => void;
|
|
38
|
+
onError?: (msg: string, extra?: {
|
|
39
|
+
source: string;
|
|
40
|
+
path: string;
|
|
41
|
+
code?: CompileError['code'];
|
|
42
|
+
domain?: CompileError['domain'];
|
|
43
|
+
location?: CompileError['location'];
|
|
44
|
+
}) => void;
|
|
45
|
+
}
|
|
46
|
+
interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
|
|
47
|
+
code: string;
|
|
48
|
+
ast: ASTNode;
|
|
49
|
+
errors?: CodeGenError[];
|
|
50
|
+
map?: RawSourceMap;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Code / AST generator for i18n json/json5 resource
|
|
55
|
+
*/
|
|
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>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Code generator for i18n yaml resource
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @internal
|
|
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>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Code generator for i18n js resource
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
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>;
|
|
76
|
+
|
|
77
|
+
type InstalledPackage = 'vue-i18n' | 'petite-vue-i18n';
|
|
78
|
+
declare function checkInstallPackage(pkg: string, debug: Function): InstalledPackage;
|
|
79
|
+
declare function checkVueI18nBridgeInstallPackage(debug: Function): boolean;
|
|
80
|
+
type VueI18nVersion = '8' | '9' | 'unknown' | '';
|
|
81
|
+
declare function getVueI18nVersion(debug: Function): VueI18nVersion;
|
|
82
|
+
|
|
83
|
+
export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, checkVueI18nBridgeInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
|
package/lib/index.d.mts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { JSONProgram } from 'jsonc-eslint-parser/lib/parser/ast';
|
|
2
|
+
import { RawSourceMap } from 'source-map-js';
|
|
3
|
+
import { CompileError } from '@intlify/message-compiler';
|
|
4
|
+
import { YAMLProgram } from 'yaml-eslint-parser/lib/ast';
|
|
5
|
+
import { Node } from 'estree';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Compilation dev environments
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
type DevEnv = 'development' | 'production';
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
interface CodeGenOptions {
|
|
17
|
+
type?: 'plain' | 'sfc' | 'bare';
|
|
18
|
+
legacy?: boolean;
|
|
19
|
+
vueVersion?: 'v2.6' | 'v2.7';
|
|
20
|
+
bridge?: boolean;
|
|
21
|
+
exportESM?: boolean;
|
|
22
|
+
onlyLocales?: string[];
|
|
23
|
+
source?: string;
|
|
24
|
+
sourceMap?: boolean;
|
|
25
|
+
filename?: string;
|
|
26
|
+
inSourceMap?: RawSourceMap;
|
|
27
|
+
isGlobal?: boolean;
|
|
28
|
+
locale?: string;
|
|
29
|
+
env?: DevEnv;
|
|
30
|
+
forceStringify?: boolean;
|
|
31
|
+
useClassComponent?: boolean;
|
|
32
|
+
allowDynamic?: boolean;
|
|
33
|
+
strictMessage?: boolean;
|
|
34
|
+
escapeHtml?: boolean;
|
|
35
|
+
jit?: boolean;
|
|
36
|
+
minify?: boolean;
|
|
37
|
+
onWarn?: (msg: string) => void;
|
|
38
|
+
onError?: (msg: string, extra?: {
|
|
39
|
+
source: string;
|
|
40
|
+
path: string;
|
|
41
|
+
code?: CompileError['code'];
|
|
42
|
+
domain?: CompileError['domain'];
|
|
43
|
+
location?: CompileError['location'];
|
|
44
|
+
}) => void;
|
|
45
|
+
}
|
|
46
|
+
interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
|
|
47
|
+
code: string;
|
|
48
|
+
ast: ASTNode;
|
|
49
|
+
errors?: CodeGenError[];
|
|
50
|
+
map?: RawSourceMap;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Code / AST generator for i18n json/json5 resource
|
|
55
|
+
*/
|
|
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>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Code generator for i18n yaml resource
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @internal
|
|
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>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Code generator for i18n js resource
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
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>;
|
|
76
|
+
|
|
77
|
+
type InstalledPackage = 'vue-i18n' | 'petite-vue-i18n';
|
|
78
|
+
declare function checkInstallPackage(pkg: string, debug: Function): InstalledPackage;
|
|
79
|
+
declare function checkVueI18nBridgeInstallPackage(debug: Function): boolean;
|
|
80
|
+
type VueI18nVersion = '8' | '9' | 'unknown' | '';
|
|
81
|
+
declare function getVueI18nVersion(debug: Function): VueI18nVersion;
|
|
82
|
+
|
|
83
|
+
export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, checkVueI18nBridgeInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
|
package/lib/index.d.ts
CHANGED
|
@@ -16,8 +16,10 @@ type DevEnv = 'development' | 'production';
|
|
|
16
16
|
interface CodeGenOptions {
|
|
17
17
|
type?: 'plain' | 'sfc' | 'bare';
|
|
18
18
|
legacy?: boolean;
|
|
19
|
+
vueVersion?: 'v2.6' | 'v2.7';
|
|
19
20
|
bridge?: boolean;
|
|
20
21
|
exportESM?: boolean;
|
|
22
|
+
onlyLocales?: string[];
|
|
21
23
|
source?: string;
|
|
22
24
|
sourceMap?: boolean;
|
|
23
25
|
filename?: string;
|
|
@@ -52,7 +54,7 @@ interface CodeGenResult<ASTNode, CodeGenError extends Error = Error> {
|
|
|
52
54
|
* Code / AST generator for i18n json/json5 resource
|
|
53
55
|
*/
|
|
54
56
|
|
|
55
|
-
declare function generate$2(targetSource: string | Buffer, { type, legacy, bridge, 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, legacy, vueVersion, bridge, onlyLocales, exportESM, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, useClassComponent, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<JSONProgram>;
|
|
56
58
|
|
|
57
59
|
/**
|
|
58
60
|
* Code generator for i18n yaml resource
|
|
@@ -61,7 +63,7 @@ declare function generate$2(targetSource: string | Buffer, { type, legacy, bridg
|
|
|
61
63
|
/**
|
|
62
64
|
* @internal
|
|
63
65
|
*/
|
|
64
|
-
declare function generate$1(targetSource: string | Buffer, { type, legacy, bridge, 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, legacy, vueVersion, bridge, onlyLocales, exportESM, useClassComponent, filename, inSourceMap, locale, isGlobal, sourceMap, env, forceStringify, onError, strictMessage, escapeHtml, jit }: CodeGenOptions, injector?: () => string): CodeGenResult<YAMLProgram>;
|
|
65
67
|
|
|
66
68
|
/**
|
|
67
69
|
* Code generator for i18n js resource
|
|
@@ -78,4 +80,4 @@ declare function checkVueI18nBridgeInstallPackage(debug: Function): boolean;
|
|
|
78
80
|
type VueI18nVersion = '8' | '9' | 'unknown' | '';
|
|
79
81
|
declare function getVueI18nVersion(debug: Function): VueI18nVersion;
|
|
80
82
|
|
|
81
|
-
export { CodeGenOptions, CodeGenResult, DevEnv, InstalledPackage, checkInstallPackage, checkVueI18nBridgeInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
|
|
83
|
+
export { type CodeGenOptions, type CodeGenResult, type DevEnv, type InstalledPackage, checkInstallPackage, checkVueI18nBridgeInstallPackage, generate$2 as generateJSON, generate as generateJavaScript, generate$1 as generateYAML, getVueI18nVersion };
|
package/lib/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { parseJSON,
|
|
1
|
+
import { parseJSON, getStaticJSONValue, traverseNodes } from 'jsonc-eslint-parser';
|
|
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
5
|
import MagicString from 'magic-string';
|
|
6
|
-
import { parseYAML, traverseNodes as traverseNodes$1
|
|
6
|
+
import { parseYAML, getStaticYAMLValue, traverseNodes as traverseNodes$1 } from 'yaml-eslint-parser';
|
|
7
7
|
import { parse } from 'acorn';
|
|
8
8
|
import { generate as generate$3 } from 'escodegen';
|
|
9
9
|
import { walk } from 'estree-walker';
|
|
@@ -254,9 +254,24 @@ function generateResourceAst(msg, options = {}, path) {
|
|
|
254
254
|
const code = !occured ? `${friendlyJSONstringify(ast)}` : `\`${_msg}\``;
|
|
255
255
|
return { code, ast, map, errors };
|
|
256
256
|
}
|
|
257
|
+
function excludeLocales({
|
|
258
|
+
messages,
|
|
259
|
+
onlyLocales
|
|
260
|
+
}) {
|
|
261
|
+
const _messages = { ...messages };
|
|
262
|
+
Object.keys(_messages).forEach((locale) => {
|
|
263
|
+
if (!onlyLocales.includes(locale)) {
|
|
264
|
+
delete _messages[locale];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
return _messages;
|
|
268
|
+
}
|
|
257
269
|
|
|
258
|
-
function generateLegacyCode({
|
|
259
|
-
|
|
270
|
+
function generateLegacyCode({
|
|
271
|
+
isGlobal = false,
|
|
272
|
+
vueVersion = "v2.6"
|
|
273
|
+
}, generator) {
|
|
274
|
+
const componentNamespace = `Component${vueVersion === "v2.6" ? ".options" : ""}`;
|
|
260
275
|
const variableName = !isGlobal ? "__i18n" : "__i18nGlobal";
|
|
261
276
|
const exportSyntax = "export default";
|
|
262
277
|
const code = `${exportSyntax} function (Component) {
|
|
@@ -272,7 +287,9 @@ function generateLegacyCode({ isGlobal }, generator) {
|
|
|
272
287
|
function generate$2(targetSource, {
|
|
273
288
|
type = "plain",
|
|
274
289
|
legacy = false,
|
|
290
|
+
vueVersion = "v2.6",
|
|
275
291
|
bridge = false,
|
|
292
|
+
onlyLocales = [],
|
|
276
293
|
exportESM = false,
|
|
277
294
|
filename = "vue-i18n-loader.json",
|
|
278
295
|
inSourceMap = void 0,
|
|
@@ -287,8 +304,7 @@ function generate$2(targetSource, {
|
|
|
287
304
|
useClassComponent = false,
|
|
288
305
|
jit = false
|
|
289
306
|
}, injector) {
|
|
290
|
-
|
|
291
|
-
const value = target;
|
|
307
|
+
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
292
308
|
const options = {
|
|
293
309
|
type,
|
|
294
310
|
bridge,
|
|
@@ -308,10 +324,20 @@ function generate$2(targetSource, {
|
|
|
308
324
|
jit
|
|
309
325
|
};
|
|
310
326
|
const generator = createCodeGenerator(options);
|
|
311
|
-
|
|
327
|
+
let ast = parseJSON(value, { filePath: filename });
|
|
328
|
+
if (!locale && type === "sfc" && onlyLocales?.length) {
|
|
329
|
+
const messages = getStaticJSONValue(ast);
|
|
330
|
+
value = JSON.stringify(
|
|
331
|
+
excludeLocales({
|
|
332
|
+
messages,
|
|
333
|
+
onlyLocales
|
|
334
|
+
})
|
|
335
|
+
);
|
|
336
|
+
ast = parseJSON(value, { filePath: filename });
|
|
337
|
+
}
|
|
312
338
|
if (legacy && type === "sfc") {
|
|
313
339
|
const gen = () => friendlyJSONstringify(getStaticJSONValue(ast));
|
|
314
|
-
const code2 = generateLegacyCode(
|
|
340
|
+
const code2 = generateLegacyCode({ isGlobal, vueVersion }, gen);
|
|
315
341
|
const s = new MagicString(code2);
|
|
316
342
|
return {
|
|
317
343
|
ast,
|
|
@@ -532,7 +558,9 @@ function _generate$2(generator, node, options = {}, injector) {
|
|
|
532
558
|
function generate$1(targetSource, {
|
|
533
559
|
type = "plain",
|
|
534
560
|
legacy = false,
|
|
561
|
+
vueVersion = "v2.6",
|
|
535
562
|
bridge = false,
|
|
563
|
+
onlyLocales = [],
|
|
536
564
|
exportESM = false,
|
|
537
565
|
useClassComponent = false,
|
|
538
566
|
filename = "vue-i18n-loader.yaml",
|
|
@@ -547,7 +575,7 @@ function generate$1(targetSource, {
|
|
|
547
575
|
escapeHtml = false,
|
|
548
576
|
jit = false
|
|
549
577
|
}, injector) {
|
|
550
|
-
|
|
578
|
+
let value = Buffer.isBuffer(targetSource) ? targetSource.toString() : targetSource;
|
|
551
579
|
const options = {
|
|
552
580
|
type,
|
|
553
581
|
bridge,
|
|
@@ -567,10 +595,20 @@ function generate$1(targetSource, {
|
|
|
567
595
|
jit
|
|
568
596
|
};
|
|
569
597
|
const generator = createCodeGenerator(options);
|
|
570
|
-
|
|
598
|
+
let ast = parseYAML(value, { filePath: filename });
|
|
599
|
+
if (!locale && type === "sfc" && onlyLocales?.length) {
|
|
600
|
+
const messages = getStaticYAMLValue(ast);
|
|
601
|
+
value = JSON.stringify(
|
|
602
|
+
excludeLocales({
|
|
603
|
+
messages,
|
|
604
|
+
onlyLocales
|
|
605
|
+
})
|
|
606
|
+
);
|
|
607
|
+
ast = parseYAML(value, { filePath: filename });
|
|
608
|
+
}
|
|
571
609
|
if (legacy && type === "sfc") {
|
|
572
610
|
const gen = () => friendlyJSONstringify(getStaticYAMLValue(ast));
|
|
573
|
-
const code2 = generateLegacyCode(
|
|
611
|
+
const code2 = generateLegacyCode({ isGlobal, vueVersion }, gen);
|
|
574
612
|
const s = new MagicString(code2);
|
|
575
613
|
return {
|
|
576
614
|
ast,
|
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.
|
|
4
|
+
"version": "7.5.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
7
7
|
"email": "kawakazu80@gmail.com"
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"yaml-eslint-parser": "^1.2.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/escodegen": "^0.0.
|
|
33
|
+
"@types/escodegen": "^0.0.10",
|
|
34
34
|
"@types/estree": "^1.0.0",
|
|
35
|
-
"unbuild": "^
|
|
35
|
+
"unbuild": "^2.0.0"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">= 14.16"
|