@formatjs/cli-lib 6.4.4 → 6.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/index.js +3 -5
- package/package.json +6 -5
- package/src/cli.js +2 -0
- package/src/compile.d.ts +7 -0
- package/src/compile.js +4 -5
- package/src/compile_folder.js +1 -1
- package/src/console_utils.d.ts +0 -2
- package/src/console_utils.js +6 -6
- package/src/extract.js +2 -3
- package/src/formatters/index.js +1 -2
- package/src/gts_extractor.js +1 -2
- package/src/hbs_extractor.js +1 -2
- package/src/parse_script.js +1 -2
- package/src/pseudo_locale.js +5 -6
- package/src/vue_extractor.js +1 -2
package/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.compile = exports.compileAndWrite = exports.extract = exports.extractAndWrite = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
7
5
|
var extract_1 = require("./src/extract");
|
|
8
|
-
Object.defineProperty(exports, "extractAndWrite", { enumerable: true, get: function () { return __importDefault(extract_1).default; } });
|
|
6
|
+
Object.defineProperty(exports, "extractAndWrite", { enumerable: true, get: function () { return tslib_1.__importDefault(extract_1).default; } });
|
|
9
7
|
Object.defineProperty(exports, "extract", { enumerable: true, get: function () { return extract_1.extract; } });
|
|
10
8
|
var compile_1 = require("./src/compile");
|
|
11
|
-
Object.defineProperty(exports, "compileAndWrite", { enumerable: true, get: function () { return __importDefault(compile_1).default; } });
|
|
9
|
+
Object.defineProperty(exports, "compileAndWrite", { enumerable: true, get: function () { return tslib_1.__importDefault(compile_1).default; } });
|
|
12
10
|
Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return compile_1.compile; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/cli-lib",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"description": "Lib for CLI for formatjs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intl",
|
|
@@ -34,17 +34,18 @@
|
|
|
34
34
|
"@types/estree": "^1.0.0",
|
|
35
35
|
"@types/fs-extra": "^9.0.1",
|
|
36
36
|
"@types/json-stable-stringify": "^1.0.32",
|
|
37
|
-
"@types/node": "14 || 16 || 17",
|
|
37
|
+
"@types/node": "14 || 16 || 17 || 18",
|
|
38
38
|
"chalk": "^4.0.0",
|
|
39
39
|
"commander": "8",
|
|
40
40
|
"fast-glob": "^3.2.7",
|
|
41
41
|
"fs-extra": "10",
|
|
42
42
|
"json-stable-stringify": "^1.0.1",
|
|
43
43
|
"loud-rejection": "^2.2.0",
|
|
44
|
-
"tslib": "^2.
|
|
44
|
+
"tslib": "^2.7.0",
|
|
45
45
|
"typescript": "5",
|
|
46
|
-
"@formatjs/icu-messageformat-parser": "2.7.
|
|
47
|
-
"@formatjs/ts-transformer": "3.13.
|
|
46
|
+
"@formatjs/icu-messageformat-parser": "2.7.10",
|
|
47
|
+
"@formatjs/ts-transformer": "3.13.16",
|
|
48
|
+
"@formatjs/icu-skeleton-parser": "1.8.4"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
51
|
"@glimmer/env": "^0.1.7",
|
package/src/cli.js
CHANGED
|
@@ -118,6 +118,8 @@ for more information`)
|
|
|
118
118
|
.option('--skip-errors', `Whether to continue compiling messages after encountering an error. Any keys with errors will not be included in the output file.`)
|
|
119
119
|
.option('--pseudo-locale <pseudoLocale>', `Whether to generate pseudo-locale files. See https://formatjs.io/docs/tooling/cli#--pseudo-locale-pseudolocale for possible values.
|
|
120
120
|
"--ast" is required for this to work.`)
|
|
121
|
+
.option('--ignore-tag', `Whether the parser to treat HTML/XML tags as string literal instead of parsing them as tag token. When this is false we only allow
|
|
122
|
+
simple tags without any attributes.`)
|
|
121
123
|
.action(async (filePatterns, opts) => {
|
|
122
124
|
(0, console_utils_1.debug)('File pattern:', filePatterns);
|
|
123
125
|
(0, console_utils_1.debug)('Options:', opts);
|
package/src/compile.d.ts
CHANGED
|
@@ -26,6 +26,13 @@ export interface Opts {
|
|
|
26
26
|
* Whether to compile to pseudo locale
|
|
27
27
|
*/
|
|
28
28
|
pseudoLocale?: PseudoLocale;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the parser to treat HTML/XML tags as string literal
|
|
31
|
+
* instead of parsing them as tag token.
|
|
32
|
+
* When this is false we only allow simple tags without
|
|
33
|
+
* any attributes
|
|
34
|
+
*/
|
|
35
|
+
ignoreTag?: boolean;
|
|
29
36
|
}
|
|
30
37
|
/**
|
|
31
38
|
* Aggregate `inputFiles` into a single JSON blob and compile.
|
package/src/compile.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compile =
|
|
3
|
+
exports.compile = compile;
|
|
4
|
+
exports.default = compileAndWrite;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
|
|
6
7
|
const fs_extra_1 = require("fs-extra");
|
|
@@ -19,7 +20,7 @@ const pseudo_locale_1 = require("./pseudo_locale");
|
|
|
19
20
|
*/
|
|
20
21
|
async function compile(inputFiles, opts = {}) {
|
|
21
22
|
(0, console_utils_1.debug)('Compiling files:', inputFiles);
|
|
22
|
-
const { ast, format, pseudoLocale, skipErrors } = opts;
|
|
23
|
+
const { ast, format, pseudoLocale, skipErrors, ignoreTag } = opts;
|
|
23
24
|
const formatter = await (0, formatters_1.resolveBuiltinFormatter)(format);
|
|
24
25
|
const messages = {};
|
|
25
26
|
const messageAsts = {};
|
|
@@ -39,7 +40,7 @@ Message from ${inputFile}: ${compiled[id]}
|
|
|
39
40
|
`);
|
|
40
41
|
}
|
|
41
42
|
try {
|
|
42
|
-
const msgAst = (0, icu_messageformat_parser_1.parse)(compiled[id]);
|
|
43
|
+
const msgAst = (0, icu_messageformat_parser_1.parse)(compiled[id], { ignoreTag });
|
|
43
44
|
messages[id] = compiled[id];
|
|
44
45
|
switch (pseudoLocale) {
|
|
45
46
|
case 'xx-LS':
|
|
@@ -76,7 +77,6 @@ Message from ${inputFile}: ${compiled[id]}
|
|
|
76
77
|
cmp: formatter.compareMessages || undefined,
|
|
77
78
|
});
|
|
78
79
|
}
|
|
79
|
-
exports.compile = compile;
|
|
80
80
|
/**
|
|
81
81
|
* Aggregate `inputFiles` into a single JSON blob and compile.
|
|
82
82
|
* Also checks for conflicting IDs and write output to `outFile`.
|
|
@@ -93,4 +93,3 @@ async function compileAndWrite(inputFiles, compileOpts = {}) {
|
|
|
93
93
|
}
|
|
94
94
|
await (0, console_utils_1.writeStdout)(serializedResult);
|
|
95
95
|
}
|
|
96
|
-
exports.default = compileAndWrite;
|
package/src/compile_folder.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = compileFolder;
|
|
3
4
|
const compile_1 = require("./compile");
|
|
4
5
|
const path_1 = require("path");
|
|
5
6
|
const fs_extra_1 = require("fs-extra");
|
|
@@ -8,4 +9,3 @@ async function compileFolder(files, outFolder, opts = {}) {
|
|
|
8
9
|
const outFiles = files.map(f => (0, path_1.join)(outFolder, (0, path_1.basename)(f)));
|
|
9
10
|
return Promise.all(outFiles.map((outFile, i) => (0, fs_extra_1.outputFile)(outFile, results[i])));
|
|
10
11
|
}
|
|
11
|
-
exports.default = compileFolder;
|
package/src/console_utils.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
export declare const writeStderr: (arg1: string | Uint8Array) => Promise<void>;
|
|
4
2
|
export declare const writeStdout: (arg1: string | Uint8Array) => Promise<void>;
|
|
5
3
|
export declare function clearLine(terminal: (typeof process)['stderr']): Promise<void>;
|
package/src/console_utils.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.writeStdout = exports.writeStderr = void 0;
|
|
4
|
+
exports.clearLine = clearLine;
|
|
5
|
+
exports.debug = debug;
|
|
6
|
+
exports.warn = warn;
|
|
7
|
+
exports.error = error;
|
|
8
|
+
exports.getStdinAsString = getStdinAsString;
|
|
4
9
|
const tslib_1 = require("tslib");
|
|
5
10
|
const chalk_1 = require("chalk");
|
|
6
11
|
const readline_1 = tslib_1.__importDefault(require("readline"));
|
|
@@ -28,7 +33,6 @@ async function clearLine(terminal) {
|
|
|
28
33
|
await nativeCursorTo(terminal, 0, undefined);
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
|
-
exports.clearLine = clearLine;
|
|
32
36
|
const LEVEL_COLORS = {
|
|
33
37
|
debug: chalk_1.green,
|
|
34
38
|
warn: chalk_1.yellow,
|
|
@@ -45,19 +49,16 @@ async function debug(message, ...args) {
|
|
|
45
49
|
await (0, exports.writeStderr)((0, util_1.format)(label('debug', message), ...args));
|
|
46
50
|
await (0, exports.writeStderr)('\n');
|
|
47
51
|
}
|
|
48
|
-
exports.debug = debug;
|
|
49
52
|
async function warn(message, ...args) {
|
|
50
53
|
await clearLine(process.stderr);
|
|
51
54
|
await (0, exports.writeStderr)((0, util_1.format)(label('warn', message), ...args));
|
|
52
55
|
await (0, exports.writeStderr)('\n');
|
|
53
56
|
}
|
|
54
|
-
exports.warn = warn;
|
|
55
57
|
async function error(message, ...args) {
|
|
56
58
|
await clearLine(process.stderr);
|
|
57
59
|
await (0, exports.writeStderr)((0, util_1.format)(label('error', message), ...args));
|
|
58
60
|
await (0, exports.writeStderr)('\n');
|
|
59
61
|
}
|
|
60
|
-
exports.error = error;
|
|
61
62
|
function getStdinAsString() {
|
|
62
63
|
let result = '';
|
|
63
64
|
return new Promise(resolve => {
|
|
@@ -73,4 +74,3 @@ function getStdinAsString() {
|
|
|
73
74
|
});
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
|
-
exports.getStdinAsString = getStdinAsString;
|
package/src/extract.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extract =
|
|
3
|
+
exports.extract = extract;
|
|
4
|
+
exports.default = extractAndWrite;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const ts_transformer_1 = require("@formatjs/ts-transformer");
|
|
6
7
|
const fs_extra_1 = require("fs-extra");
|
|
@@ -179,7 +180,6 @@ ${JSON.stringify(message, undefined, 2)}`);
|
|
|
179
180
|
cmp: formatter.compareMessages || undefined,
|
|
180
181
|
});
|
|
181
182
|
}
|
|
182
|
-
exports.extract = extract;
|
|
183
183
|
/**
|
|
184
184
|
* Extract strings from source files, also writes to a file.
|
|
185
185
|
* @param files list of files
|
|
@@ -195,4 +195,3 @@ async function extractAndWrite(files, extractOpts) {
|
|
|
195
195
|
}
|
|
196
196
|
await (0, console_utils_1.writeStdout)(serializedResult);
|
|
197
197
|
}
|
|
198
|
-
exports.default = extractAndWrite;
|
package/src/formatters/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveBuiltinFormatter =
|
|
3
|
+
exports.resolveBuiltinFormatter = resolveBuiltinFormatter;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const url_1 = require("url");
|
|
@@ -38,4 +38,3 @@ async function resolveBuiltinFormatter(format) {
|
|
|
38
38
|
throw e;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
exports.resolveBuiltinFormatter = resolveBuiltinFormatter;
|
package/src/gts_extractor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFile =
|
|
3
|
+
exports.parseFile = parseFile;
|
|
4
4
|
const content_tag_1 = require("content-tag");
|
|
5
5
|
const hbs_extractor_1 = require("./hbs_extractor");
|
|
6
6
|
const parse_script_1 = require("./parse_script");
|
|
@@ -15,4 +15,3 @@ function parseFile(source, fileName, options) {
|
|
|
15
15
|
(0, hbs_extractor_1.parseFile)(parsed.contents, fileName, options);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
exports.parseFile = parseFile;
|
package/src/hbs_extractor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFile =
|
|
3
|
+
exports.parseFile = parseFile;
|
|
4
4
|
const ember_template_recast_1 = require("ember-template-recast");
|
|
5
5
|
function extractText(node, fileName, options) {
|
|
6
6
|
if (!options.onMsgExtracted)
|
|
@@ -46,4 +46,3 @@ function parseFile(source, fileName, options) {
|
|
|
46
46
|
// but it does not affect runtime
|
|
47
47
|
(0, ember_template_recast_1.transform)(source, visitor);
|
|
48
48
|
}
|
|
49
|
-
exports.parseFile = parseFile;
|
package/src/parse_script.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseScript =
|
|
3
|
+
exports.parseScript = parseScript;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const ts_transformer_1 = require("@formatjs/ts-transformer");
|
|
6
6
|
const typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
@@ -48,4 +48,3 @@ ${e.message || ''}`;
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
exports.parseScript = parseScript;
|
package/src/pseudo_locale.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.generateXXLS = generateXXLS;
|
|
4
|
+
exports.generateXXAC = generateXXAC;
|
|
5
|
+
exports.generateXXHA = generateXXHA;
|
|
6
|
+
exports.generateENXA = generateENXA;
|
|
7
|
+
exports.generateENXB = generateENXB;
|
|
4
8
|
const icu_messageformat_parser_1 = require("@formatjs/icu-messageformat-parser");
|
|
5
9
|
function forEachLiteralElement(ast, fn) {
|
|
6
10
|
ast.forEach(el => {
|
|
@@ -26,7 +30,6 @@ function generateXXLS(msg) {
|
|
|
26
30
|
}
|
|
27
31
|
return [...ast, { type: icu_messageformat_parser_1.TYPE.literal, value: 'SSSSSSSSSSSSSSSSSSSSSSSSS' }];
|
|
28
32
|
}
|
|
29
|
-
exports.generateXXLS = generateXXLS;
|
|
30
33
|
function generateXXAC(msg) {
|
|
31
34
|
const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
|
|
32
35
|
forEachLiteralElement(ast, el => {
|
|
@@ -34,7 +37,6 @@ function generateXXAC(msg) {
|
|
|
34
37
|
});
|
|
35
38
|
return ast;
|
|
36
39
|
}
|
|
37
|
-
exports.generateXXAC = generateXXAC;
|
|
38
40
|
function generateXXHA(msg) {
|
|
39
41
|
const ast = typeof msg === 'string' ? (0, icu_messageformat_parser_1.parse)(msg) : msg;
|
|
40
42
|
const [firstChunk, ...rest] = ast;
|
|
@@ -44,7 +46,6 @@ function generateXXHA(msg) {
|
|
|
44
46
|
}
|
|
45
47
|
return [{ type: icu_messageformat_parser_1.TYPE.literal, value: '[javascript]' }, ...ast];
|
|
46
48
|
}
|
|
47
|
-
exports.generateXXHA = generateXXHA;
|
|
48
49
|
const ACCENTED_MAP = {
|
|
49
50
|
// ȦƁƇḒḖƑƓĦĪĴĶĿḾȠǾƤɊŘŞŦŬṼẆẊẎẐ
|
|
50
51
|
// prettier-ignore
|
|
@@ -100,7 +101,6 @@ function generateENXA(msg) {
|
|
|
100
101
|
{ type: icu_messageformat_parser_1.TYPE.literal, value: ']' },
|
|
101
102
|
];
|
|
102
103
|
}
|
|
103
|
-
exports.generateENXA = generateENXA;
|
|
104
104
|
/**
|
|
105
105
|
* bidi - ɥsıʅƃuƎ ıpıԐ
|
|
106
106
|
* -------------------
|
|
@@ -120,4 +120,3 @@ function generateENXB(msg) {
|
|
|
120
120
|
{ type: icu_messageformat_parser_1.TYPE.literal, value: '\u202c' },
|
|
121
121
|
];
|
|
122
122
|
}
|
|
123
|
-
exports.generateENXB = generateENXB;
|
package/src/vue_extractor.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseFile =
|
|
3
|
+
exports.parseFile = parseFile;
|
|
4
4
|
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
5
|
const compiler_sfc_1 = require("vue/compiler-sfc");
|
|
6
6
|
function walk(node, visitor) {
|
|
@@ -69,4 +69,3 @@ function parseFile(source, filename, parseScriptFn) {
|
|
|
69
69
|
parseScriptFn(scriptSetup.content);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
exports.parseFile = parseFile;
|