@formatjs/cli-lib 7.0.3 → 7.1.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.
Files changed (46) hide show
  1. package/lib_esnext/src/cli.js +21 -0
  2. package/lib_esnext/src/verify/checkMissingKeys.d.ts +1 -0
  3. package/lib_esnext/src/verify/checkMissingKeys.js +37 -0
  4. package/lib_esnext/src/verify/checkStructuralEquality.d.ts +1 -0
  5. package/lib_esnext/src/verify/checkStructuralEquality.js +56 -0
  6. package/lib_esnext/src/verify/index.d.ts +6 -0
  7. package/lib_esnext/src/verify/index.js +24 -0
  8. package/package.json +3 -3
  9. package/index.d.ts +0 -7
  10. package/index.js +0 -10
  11. package/main.d.ts +0 -2
  12. package/main.js +0 -4
  13. package/src/cli.d.ts +0 -2
  14. package/src/cli.js +0 -156
  15. package/src/compile.d.ts +0 -54
  16. package/src/compile.js +0 -95
  17. package/src/compile_folder.d.ts +0 -2
  18. package/src/compile_folder.js +0 -11
  19. package/src/console_utils.d.ts +0 -7
  20. package/src/console_utils.js +0 -76
  21. package/src/extract.d.ts +0 -74
  22. package/src/extract.js +0 -197
  23. package/src/formatters/crowdin.d.ts +0 -7
  24. package/src/formatters/crowdin.js +0 -27
  25. package/src/formatters/default.d.ts +0 -6
  26. package/src/formatters/default.js +0 -13
  27. package/src/formatters/index.d.ts +0 -9
  28. package/src/formatters/index.js +0 -40
  29. package/src/formatters/lokalise.d.ts +0 -9
  30. package/src/formatters/lokalise.js +0 -24
  31. package/src/formatters/simple.d.ts +0 -4
  32. package/src/formatters/simple.js +0 -12
  33. package/src/formatters/smartling.d.ts +0 -23
  34. package/src/formatters/smartling.js +0 -50
  35. package/src/formatters/transifex.d.ts +0 -9
  36. package/src/formatters/transifex.js +0 -24
  37. package/src/gts_extractor.d.ts +0 -1
  38. package/src/gts_extractor.js +0 -17
  39. package/src/hbs_extractor.d.ts +0 -1
  40. package/src/hbs_extractor.js +0 -48
  41. package/src/parse_script.d.ts +0 -7
  42. package/src/parse_script.js +0 -50
  43. package/src/pseudo_locale.d.ts +0 -22
  44. package/src/pseudo_locale.js +0 -122
  45. package/src/vue_extractor.d.ts +0 -2
  46. package/src/vue_extractor.js +0 -71
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseScript = parseScript;
4
- const tslib_1 = require("tslib");
5
- const ts_transformer_1 = require("@formatjs/ts-transformer");
6
- const typescript_1 = tslib_1.__importDefault(require("typescript"));
7
- const console_utils_1 = require("./console_utils");
8
- /**
9
- * Invoid TypeScript module transpilation with our TS transformer
10
- * @param opts Formatjs TS Transformer opt
11
- * @param fn filename
12
- */
13
- function parseScript(opts, fn) {
14
- return (source) => {
15
- let output;
16
- try {
17
- (0, console_utils_1.debug)('Using TS compiler to process file', fn);
18
- output = typescript_1.default.transpileModule(source, {
19
- compilerOptions: {
20
- allowJs: true,
21
- target: typescript_1.default.ScriptTarget.ESNext,
22
- noEmit: true,
23
- experimentalDecorators: true,
24
- },
25
- reportDiagnostics: true,
26
- fileName: fn,
27
- transformers: {
28
- before: [(0, ts_transformer_1.transformWithTs)(typescript_1.default, opts)],
29
- },
30
- });
31
- }
32
- catch (e) {
33
- if (e instanceof Error) {
34
- e.message = `Error processing file ${fn}
35
- ${e.message || ''}`;
36
- }
37
- throw e;
38
- }
39
- if (output.diagnostics) {
40
- const errs = output.diagnostics.filter(d => d.category === typescript_1.default.DiagnosticCategory.Error);
41
- if (errs.length) {
42
- throw new Error(typescript_1.default.formatDiagnosticsWithColorAndContext(errs, {
43
- getCanonicalFileName: fileName => fileName,
44
- getCurrentDirectory: () => process.cwd(),
45
- getNewLine: () => typescript_1.default.sys.newLine,
46
- }));
47
- }
48
- }
49
- };
50
- }
@@ -1,22 +0,0 @@
1
- import { MessageFormatElement } from '@formatjs/icu-messageformat-parser';
2
- export declare function generateXXLS(msg: string | MessageFormatElement[]): MessageFormatElement[];
3
- export declare function generateXXAC(msg: string | MessageFormatElement[]): MessageFormatElement[];
4
- export declare function generateXXHA(msg: string | MessageFormatElement[]): MessageFormatElement[];
5
- /**
6
- * accented - Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ
7
- * --------------------------------
8
- *
9
- * This locale replaces all Latin characters with their accented equivalents, and duplicates some
10
- * vowels to create roughly 30% longer strings. Strings are wrapped in markers (square brackets),
11
- * which help with detecting truncation.
12
- */
13
- export declare function generateENXA(msg: string | MessageFormatElement[]): MessageFormatElement[];
14
- /**
15
- * bidi - ɥsıʅƃuƎ ıpıԐ
16
- * -------------------
17
- *
18
- * This strategy replaces all Latin characters with their 180 degree rotated versions and enforces
19
- * right to left text flow using Unicode UAX#9 Explicit Directional Embeddings. In this mode, the UI
20
- * directionality will also be set to right-to-left.
21
- */
22
- export declare function generateENXB(msg: string | MessageFormatElement[]): MessageFormatElement[];
@@ -1,122 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateXXLS = generateXXLS;
4
- exports.generateXXAC = generateXXAC;
5
- exports.generateXXHA = generateXXHA;
6
- exports.generateENXA = generateENXA;
7
- exports.generateENXB = generateENXB;
8
- const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
9
- function forEachLiteralElement(ast, fn) {
10
- ast.forEach(el => {
11
- if ((0, icu_messageformat_parser_1.isLiteralElement)(el)) {
12
- fn(el);
13
- }
14
- else if ((0, icu_messageformat_parser_1.isPluralElement)(el) || (0, icu_messageformat_parser_1.isSelectElement)(el)) {
15
- for (const opt of Object.values(el.options)) {
16
- forEachLiteralElement(opt.value, fn);
17
- }
18
- }
19
- else if ((0, icu_messageformat_parser_1.isTagElement)(el)) {
20
- forEachLiteralElement(el.children, fn);
21
- }
22
- });
23
- }
24
- function generateXXLS(msg) {
25
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
26
- const lastChunk = ast[ast.length - 1];
27
- if (lastChunk && (0, icu_messageformat_parser_1.isLiteralElement)(lastChunk)) {
28
- lastChunk.value += 'SSSSSSSSSSSSSSSSSSSSSSSSS';
29
- return ast;
30
- }
31
- return [...ast, { type: icu_messageformat_parser_1.TYPE.literal, value: 'SSSSSSSSSSSSSSSSSSSSSSSSS' }];
32
- }
33
- function generateXXAC(msg) {
34
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
35
- forEachLiteralElement(ast, el => {
36
- el.value = el.value.toUpperCase();
37
- });
38
- return ast;
39
- }
40
- function generateXXHA(msg) {
41
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
42
- const [firstChunk, ...rest] = ast;
43
- if (firstChunk && (0, icu_messageformat_parser_1.isLiteralElement)(firstChunk)) {
44
- firstChunk.value = '[javascript]' + firstChunk.value;
45
- return [firstChunk, ...rest];
46
- }
47
- return [{ type: icu_messageformat_parser_1.TYPE.literal, value: '[javascript]' }, ...ast];
48
- }
49
- const ACCENTED_MAP = {
50
- // ȦƁƇḒḖƑƓĦĪĴĶĿḾȠǾƤɊŘŞŦŬṼẆẊẎẐ
51
- // prettier-ignore
52
- "caps": [550, 385, 391, 7698, 7702, 401, 403, 294, 298, 308, 310, 319, 7742, 544, 510, 420, 586, 344, 350, 358, 364, 7804, 7814, 7818, 7822, 7824],
53
- // ȧƀƈḓḗƒɠħīĵķŀḿƞǿƥɋřşŧŭṽẇẋẏẑ
54
- // prettier-ignore
55
- "small": [551, 384, 392, 7699, 7703, 402, 608, 295, 299, 309, 311, 320, 7743, 414, 511, 421, 587, 345, 351, 359, 365, 7805, 7815, 7819, 7823, 7825],
56
- };
57
- const FLIPPED_MAP = {
58
- // ∀ԐↃᗡƎℲ⅁HIſӼ⅂WNOԀÒᴚS⊥∩ɅMX⅄Z
59
- // prettier-ignore
60
- "caps": [8704, 1296, 8579, 5601, 398, 8498, 8513, 72, 73, 383, 1276, 8514, 87, 78, 79, 1280, 210, 7450, 83, 8869, 8745, 581, 77, 88, 8516, 90],
61
- // ɐqɔpǝɟƃɥıɾʞʅɯuodbɹsʇnʌʍxʎz
62
- // prettier-ignore
63
- "small": [592, 113, 596, 112, 477, 607, 387, 613, 305, 638, 670, 645, 623, 117, 111, 100, 98, 633, 115, 647, 110, 652, 653, 120, 654, 122],
64
- };
65
- /**
66
- * Based on: https://hg.mozilla.org/mozilla-central/file/a1f74e8c8fb72390d22054d6b00c28b1a32f6c43/intl/l10n/L10nRegistry.jsm#l425
67
- */
68
- function transformString(map, elongate = false, msg) {
69
- return msg.replace(/[a-z]/gi, ch => {
70
- const cc = ch.charCodeAt(0);
71
- if (cc >= 97 && cc <= 122) {
72
- const newChar = String.fromCodePoint(map.small[cc - 97]);
73
- // duplicate "a", "e", "o" and "u" to emulate ~30% longer text
74
- if (elongate && (cc === 97 || cc === 101 || cc === 111 || cc === 117)) {
75
- return newChar + newChar;
76
- }
77
- return newChar;
78
- }
79
- if (cc >= 65 && cc <= 90) {
80
- return String.fromCodePoint(map.caps[cc - 65]);
81
- }
82
- return ch;
83
- });
84
- }
85
- /**
86
- * accented - Ȧȧƈƈḗḗƞŧḗḗḓ Ḗḗƞɠŀīīşħ
87
- * --------------------------------
88
- *
89
- * This locale replaces all Latin characters with their accented equivalents, and duplicates some
90
- * vowels to create roughly 30% longer strings. Strings are wrapped in markers (square brackets),
91
- * which help with detecting truncation.
92
- */
93
- function generateENXA(msg) {
94
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
95
- forEachLiteralElement(ast, el => {
96
- el.value = transformString(ACCENTED_MAP, true, el.value);
97
- });
98
- return [
99
- { type: icu_messageformat_parser_1.TYPE.literal, value: '[' },
100
- ...ast,
101
- { type: icu_messageformat_parser_1.TYPE.literal, value: ']' },
102
- ];
103
- }
104
- /**
105
- * bidi - ɥsıʅƃuƎ ıpıԐ
106
- * -------------------
107
- *
108
- * This strategy replaces all Latin characters with their 180 degree rotated versions and enforces
109
- * right to left text flow using Unicode UAX#9 Explicit Directional Embeddings. In this mode, the UI
110
- * directionality will also be set to right-to-left.
111
- */
112
- function generateENXB(msg) {
113
- const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
114
- forEachLiteralElement(ast, el => {
115
- el.value = transformString(FLIPPED_MAP, false, el.value);
116
- });
117
- return [
118
- { type: icu_messageformat_parser_1.TYPE.literal, value: '\u202e' },
119
- ...ast,
120
- { type: icu_messageformat_parser_1.TYPE.literal, value: '\u202c' },
121
- ];
122
- }
@@ -1,2 +0,0 @@
1
- export type ScriptParseFn = (source: string) => void;
2
- export declare function parseFile(source: string, filename: string, parseScriptFn: ScriptParseFn): any;
@@ -1,71 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseFile = parseFile;
4
- const compiler_core_1 = require("@vue/compiler-core");
5
- const compiler_sfc_1 = require("vue/compiler-sfc");
6
- function walk(node, visitor) {
7
- if (typeof node !== 'object' || node == null) {
8
- return;
9
- }
10
- if (node.type === compiler_core_1.NodeTypes.ROOT) {
11
- node.children.forEach(n => walk(n, visitor));
12
- return;
13
- }
14
- if (node.type !== compiler_core_1.NodeTypes.ELEMENT &&
15
- node.type !== compiler_core_1.NodeTypes.COMPOUND_EXPRESSION &&
16
- node.type !== compiler_core_1.NodeTypes.INTERPOLATION) {
17
- return;
18
- }
19
- visitor(node);
20
- if (node.type === compiler_core_1.NodeTypes.INTERPOLATION) {
21
- visitor(node.content);
22
- }
23
- else if (node.type === compiler_core_1.NodeTypes.ELEMENT) {
24
- node.children.forEach(n => walk(n, visitor));
25
- node.props
26
- .filter((prop) => prop.type === compiler_core_1.NodeTypes.DIRECTIVE)
27
- .filter(prop => !!prop.exp)
28
- .forEach(prop => visitor(prop.exp));
29
- }
30
- else {
31
- node.children.forEach(n => walk(n, visitor));
32
- }
33
- }
34
- function templateSimpleExpressionNodeVisitor(parseScriptFn) {
35
- return (n) => {
36
- if (typeof n !== 'object') {
37
- return;
38
- }
39
- if (n.type !== compiler_core_1.NodeTypes.SIMPLE_EXPRESSION) {
40
- return;
41
- }
42
- const { content } = n;
43
- // Wrap this in () since a vue comp node attribute can just be
44
- // an object literal which, by itself is invalid TS
45
- // but with () it becomes an ExpressionStatement
46
- try {
47
- parseScriptFn(`(${content})`);
48
- }
49
- catch (e) {
50
- console.warn(`Failed to parse "${content}". Ignore this if content has no extractable message`, e);
51
- }
52
- };
53
- }
54
- function parseFile(source, filename, parseScriptFn) {
55
- const { descriptor, errors } = (0, compiler_sfc_1.parse)(source, {
56
- filename,
57
- });
58
- if (errors.length) {
59
- throw errors[0];
60
- }
61
- const { script, scriptSetup, template } = descriptor;
62
- if (template) {
63
- walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn));
64
- }
65
- if (script) {
66
- parseScriptFn(script.content);
67
- }
68
- if (scriptSetup) {
69
- parseScriptFn(scriptSetup.content);
70
- }
71
- }