@formatjs/cli-lib 8.2.0 → 8.2.2
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/package.json +7 -11
- package/src/cli.js +3 -2
- package/src/extract.js +22 -5
- package/src/hbs_extractor.js +10 -14
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/cli-lib",
|
|
3
3
|
"description": "Lib for CLI for formatjs.",
|
|
4
|
-
"version": "8.2.
|
|
4
|
+
"version": "8.2.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Linjie Ding <linjie@airtable.com>",
|
|
7
7
|
"type": "module",
|
|
@@ -20,16 +20,15 @@
|
|
|
20
20
|
"loud-rejection": "^2",
|
|
21
21
|
"tslib": "^2.8.1",
|
|
22
22
|
"typescript": "^5.6.0",
|
|
23
|
-
"@formatjs/
|
|
24
|
-
"@formatjs/icu-skeleton-parser": "2.1.
|
|
25
|
-
"@formatjs/
|
|
23
|
+
"@formatjs/ts-transformer": "4.3.2",
|
|
24
|
+
"@formatjs/icu-skeleton-parser": "2.1.1",
|
|
25
|
+
"@formatjs/icu-messageformat-parser": "3.5.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@glimmer/syntax": "^0.95.0",
|
|
29
|
-
"@vue/compiler-core": "3.5.
|
|
28
|
+
"@glimmer/syntax": "^0.84.3 || ^0.95.0",
|
|
29
|
+
"@vue/compiler-core": "3.5.27",
|
|
30
30
|
"content-tag": "^4.1.0",
|
|
31
|
-
"
|
|
32
|
-
"vue": "3.5.26"
|
|
31
|
+
"vue": "3.5.27"
|
|
33
32
|
},
|
|
34
33
|
"bugs": "https://github.com/formatjs/formatjs/issues",
|
|
35
34
|
"homepage": "https://github.com/formatjs/formatjs",
|
|
@@ -70,9 +69,6 @@
|
|
|
70
69
|
"@glimmer/validator": {
|
|
71
70
|
"optional": true
|
|
72
71
|
},
|
|
73
|
-
"ember-template-recast": {
|
|
74
|
-
"optional": true
|
|
75
|
-
},
|
|
76
72
|
"content-tag": {
|
|
77
73
|
"optional": true
|
|
78
74
|
}
|
package/src/cli.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { program } from "commander";
|
|
2
|
-
import
|
|
2
|
+
import * as glob from "fast-glob";
|
|
3
|
+
const globSync = glob.sync;
|
|
3
4
|
import loudRejection from "loud-rejection";
|
|
4
5
|
import compile from "./compile.js";
|
|
5
6
|
import compileFolder from "./compile_folder.js";
|
|
@@ -104,7 +105,7 @@ type CompileFn = <T = Record<string, MessageDescriptor>>(
|
|
|
104
105
|
) => Record<string, string>;
|
|
105
106
|
\`\`\`
|
|
106
107
|
This is especially useful to convert from a TMS-specific format back to react-intl format
|
|
107
|
-
`).option("--ast", `Whether to compile to AST. See https://formatjs.github.io/docs/guides/advanced-usage#pre-parsing-messages for more information`).action(async (folder, outFolder, opts) => {
|
|
108
|
+
`).option("--ast", `Whether to compile to AST. See https://formatjs.github.io/docs/guides/advanced-usage#pre-parsing-messages for more information`).option("--skip-errors", `Whether to continue compiling messages after encountering an error. Any keys with errors will not be included in the output file.`).option("--pseudo-locale <pseudoLocale>", `Whether to generate pseudo-locale files. See https://formatjs.github.io/docs/tooling/cli#--pseudo-locale-pseudolocale for possible values. "--ast" is required for this to work.`).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 simple tags without any attributes.`).action(async (folder, outFolder, opts) => {
|
|
108
109
|
debug("Folder:", folder);
|
|
109
110
|
debug("Options:", opts);
|
|
110
111
|
// fast-glob expect `/` in Windows as well
|
package/src/extract.js
CHANGED
|
@@ -102,11 +102,28 @@ export async function extract(files, extractOpts) {
|
|
|
102
102
|
const stdinSource = await getStdinAsString();
|
|
103
103
|
rawResults = [await processFile(stdinSource, "dummy", opts)];
|
|
104
104
|
} else {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
// Use Promise.allSettled when throws is false to collect partial results
|
|
106
|
+
if (throws === false) {
|
|
107
|
+
const settledResults = await Promise.allSettled(files.map(async (fn) => {
|
|
108
|
+
debug("Extracting file:", fn);
|
|
109
|
+
const source = await readFile(fn, "utf8");
|
|
110
|
+
return processFile(source, fn, opts);
|
|
111
|
+
}));
|
|
112
|
+
rawResults = settledResults.map((result) => {
|
|
113
|
+
if (result.status === "fulfilled") {
|
|
114
|
+
return result.value;
|
|
115
|
+
} else {
|
|
116
|
+
warn(String(result.reason));
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
rawResults = await Promise.all(files.map(async (fn) => {
|
|
122
|
+
debug("Extracting file:", fn);
|
|
123
|
+
const source = await readFile(fn, "utf8");
|
|
124
|
+
return processFile(source, fn, opts);
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
110
127
|
}
|
|
111
128
|
} catch (e) {
|
|
112
129
|
if (throws) {
|
package/src/hbs_extractor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "@formatjs/ts-transformer";
|
|
2
|
-
import {
|
|
2
|
+
import { preprocess, traverse } from "@glimmer/syntax";
|
|
3
3
|
function extractText(node, fileName, options) {
|
|
4
4
|
if (!options.onMsgExtracted) return;
|
|
5
5
|
if (!options.overrideIdFn) return;
|
|
@@ -22,17 +22,13 @@ function extractText(node, fileName, options) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
export function parseFile(source, fileName, options) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
// SAFETY: ember-template-recast's types are out of date,
|
|
36
|
-
// but it does not affect runtime
|
|
37
|
-
transform(source, visitor);
|
|
25
|
+
const ast = preprocess(source);
|
|
26
|
+
traverse(ast, {
|
|
27
|
+
MustacheStatement(node) {
|
|
28
|
+
extractText(node, fileName, options);
|
|
29
|
+
},
|
|
30
|
+
SubExpression(node) {
|
|
31
|
+
extractText(node, fileName, options);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
38
34
|
}
|