@formatjs/cli 6.12.1 → 6.12.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/bin/formatjs +38 -12
- package/package.json +2 -2
package/bin/formatjs
CHANGED
|
@@ -229318,7 +229318,18 @@ function evaluateStringConcat(ts2, node) {
|
|
|
229318
229318
|
}
|
|
229319
229319
|
return ["", false];
|
|
229320
229320
|
}
|
|
229321
|
-
function extractMessageDescriptor(ts2, node, { overrideIdFn, extractSourceLocation, preserveWhitespace, flatten: flatten2 }, sf) {
|
|
229321
|
+
function extractMessageDescriptor(ts2, node, { overrideIdFn, extractSourceLocation, preserveWhitespace, flatten: flatten2, throws = true, onMsgError }, sf) {
|
|
229322
|
+
let extractionError = null;
|
|
229323
|
+
function handleError(errorMsg) {
|
|
229324
|
+
const error2 = new Error(errorMsg);
|
|
229325
|
+
if (throws) {
|
|
229326
|
+
throw error2;
|
|
229327
|
+
}
|
|
229328
|
+
extractionError = error2;
|
|
229329
|
+
if (onMsgError) {
|
|
229330
|
+
onMsgError(sf.fileName, error2);
|
|
229331
|
+
}
|
|
229332
|
+
}
|
|
229322
229333
|
let properties = void 0;
|
|
229323
229334
|
if (ts2.isObjectLiteralExpression(node)) {
|
|
229324
229335
|
properties = node.properties;
|
|
@@ -229364,7 +229375,8 @@ function extractMessageDescriptor(ts2, node, { overrideIdFn, extractSourceLocati
|
|
|
229364
229375
|
}
|
|
229365
229376
|
const { template } = initializer;
|
|
229366
229377
|
if (!ts2.isNoSubstitutionTemplateLiteral(template)) {
|
|
229367
|
-
|
|
229378
|
+
handleError("[FormatJS] Tagged template expression must be no substitution");
|
|
229379
|
+
return;
|
|
229368
229380
|
}
|
|
229369
229381
|
switch (name.text) {
|
|
229370
229382
|
case "id":
|
|
@@ -229412,7 +229424,8 @@ function extractMessageDescriptor(ts2, node, { overrideIdFn, extractSourceLocati
|
|
|
229412
229424
|
}
|
|
229413
229425
|
const { expression: { template } } = initializer;
|
|
229414
229426
|
if (!ts2.isNoSubstitutionTemplateLiteral(template)) {
|
|
229415
|
-
|
|
229427
|
+
handleError("[FormatJS] Tagged template expression must be no substitution");
|
|
229428
|
+
return;
|
|
229416
229429
|
}
|
|
229417
229430
|
switch (name.text) {
|
|
229418
229431
|
case "id":
|
|
@@ -229441,10 +229454,12 @@ function extractMessageDescriptor(ts2, node, { overrideIdFn, extractSourceLocati
|
|
|
229441
229454
|
break;
|
|
229442
229455
|
}
|
|
229443
229456
|
} else if (MESSAGE_DESC_KEYS.includes(name.text) && name.text !== "description") {
|
|
229444
|
-
|
|
229457
|
+
handleError(`[FormatJS] \`${name.text}\` must be a string literal or statically evaluable expression to be extracted.`);
|
|
229458
|
+
return;
|
|
229445
229459
|
}
|
|
229446
229460
|
} else if (MESSAGE_DESC_KEYS.includes(name.text) && name.text !== "description") {
|
|
229447
|
-
|
|
229461
|
+
handleError(`[FormatJS] \`${name.text}\` must be a string literal to be extracted.`);
|
|
229462
|
+
return;
|
|
229448
229463
|
}
|
|
229449
229464
|
} else if (ts2.isBinaryExpression(initializer)) {
|
|
229450
229465
|
const [result, isStatic] = evaluateStringConcat(ts2, initializer);
|
|
@@ -229461,15 +229476,20 @@ function extractMessageDescriptor(ts2, node, { overrideIdFn, extractSourceLocati
|
|
|
229461
229476
|
break;
|
|
229462
229477
|
}
|
|
229463
229478
|
} else if (MESSAGE_DESC_KEYS.includes(name.text) && name.text !== "description") {
|
|
229464
|
-
|
|
229479
|
+
handleError(`[FormatJS] \`${name.text}\` must be a string literal or statically evaluable expression to be extracted.`);
|
|
229480
|
+
return;
|
|
229465
229481
|
}
|
|
229466
229482
|
} else if (ts2.isObjectLiteralExpression(initializer) && name.text === "description") {
|
|
229467
229483
|
msg.description = objectLiteralExpressionToObj(ts2, initializer);
|
|
229468
229484
|
} else if (MESSAGE_DESC_KEYS.includes(name.text) && name.text !== "description") {
|
|
229469
|
-
|
|
229485
|
+
handleError(`[FormatJS] \`${name.text}\` must be a string literal to be extracted.`);
|
|
229486
|
+
return;
|
|
229470
229487
|
}
|
|
229471
229488
|
}
|
|
229472
229489
|
});
|
|
229490
|
+
if (extractionError) {
|
|
229491
|
+
return;
|
|
229492
|
+
}
|
|
229473
229493
|
if (!msg.defaultMessage && !msg.id) {
|
|
229474
229494
|
return;
|
|
229475
229495
|
}
|
|
@@ -230442,6 +230462,12 @@ async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
|
|
|
230442
230462
|
}
|
|
230443
230463
|
async function extract(files, extractOpts) {
|
|
230444
230464
|
const { throws, readFromStdin, ...opts } = extractOpts;
|
|
230465
|
+
const shouldThrow = throws === true;
|
|
230466
|
+
const optsWithThrows = {
|
|
230467
|
+
...opts,
|
|
230468
|
+
throws: shouldThrow,
|
|
230469
|
+
onMsgError: !shouldThrow ? (_, e) => warn(e.message) : void 0
|
|
230470
|
+
};
|
|
230445
230471
|
let rawResults = [];
|
|
230446
230472
|
try {
|
|
230447
230473
|
if (readFromStdin) {
|
|
@@ -230450,14 +230476,14 @@ async function extract(files, extractOpts) {
|
|
|
230450
230476
|
warn("Reading source file from TTY.");
|
|
230451
230477
|
}
|
|
230452
230478
|
const stdinSource = await getStdinAsString();
|
|
230453
|
-
rawResults = [await processFile(stdinSource, "dummy",
|
|
230479
|
+
rawResults = [await processFile(stdinSource, "dummy", optsWithThrows)];
|
|
230454
230480
|
} else {
|
|
230455
|
-
if (
|
|
230481
|
+
if (!shouldThrow) {
|
|
230456
230482
|
const settledResults = await Promise.allSettled(
|
|
230457
230483
|
files.map(async (fn) => {
|
|
230458
230484
|
debug("Extracting file:", fn);
|
|
230459
230485
|
const source = await (0, import_promises.readFile)(fn, "utf8");
|
|
230460
|
-
return processFile(source, fn,
|
|
230486
|
+
return processFile(source, fn, optsWithThrows);
|
|
230461
230487
|
})
|
|
230462
230488
|
);
|
|
230463
230489
|
rawResults = settledResults.map((result) => {
|
|
@@ -230473,13 +230499,13 @@ async function extract(files, extractOpts) {
|
|
|
230473
230499
|
files.map(async (fn) => {
|
|
230474
230500
|
debug("Extracting file:", fn);
|
|
230475
230501
|
const source = await (0, import_promises.readFile)(fn, "utf8");
|
|
230476
|
-
return processFile(source, fn,
|
|
230502
|
+
return processFile(source, fn, optsWithThrows);
|
|
230477
230503
|
})
|
|
230478
230504
|
);
|
|
230479
230505
|
}
|
|
230480
230506
|
}
|
|
230481
230507
|
} catch (e) {
|
|
230482
|
-
if (
|
|
230508
|
+
if (shouldThrow) {
|
|
230483
230509
|
throw e;
|
|
230484
230510
|
} else {
|
|
230485
230511
|
warn(String(e));
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formatjs/cli",
|
|
3
3
|
"description": "A CLI for formatjs.",
|
|
4
|
-
"version": "6.12.
|
|
4
|
+
"version": "6.12.2",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Linjie Ding <linjie@airtable.com>",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">= 16"
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
|
-
"@formatjs/cli-lib": "8.2.
|
|
11
|
+
"@formatjs/cli-lib": "8.2.3"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"@glimmer/syntax": "^0.84.3 || ^0.95.0",
|