@formatjs/cli 6.12.0 → 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 +94 -49
- package/package.json +2 -2
package/bin/formatjs
CHANGED
|
@@ -5431,7 +5431,7 @@ var require_scan = __commonJS({
|
|
|
5431
5431
|
}
|
|
5432
5432
|
let base = str;
|
|
5433
5433
|
let prefix = "";
|
|
5434
|
-
let
|
|
5434
|
+
let glob2 = "";
|
|
5435
5435
|
if (start > 0) {
|
|
5436
5436
|
prefix = str.slice(0, start);
|
|
5437
5437
|
str = str.slice(start);
|
|
@@ -5439,10 +5439,10 @@ var require_scan = __commonJS({
|
|
|
5439
5439
|
}
|
|
5440
5440
|
if (base && isGlob === true && lastIndex > 0) {
|
|
5441
5441
|
base = str.slice(0, lastIndex);
|
|
5442
|
-
|
|
5442
|
+
glob2 = str.slice(lastIndex);
|
|
5443
5443
|
} else if (isGlob === true) {
|
|
5444
5444
|
base = "";
|
|
5445
|
-
|
|
5445
|
+
glob2 = str;
|
|
5446
5446
|
} else {
|
|
5447
5447
|
base = str;
|
|
5448
5448
|
}
|
|
@@ -5452,8 +5452,8 @@ var require_scan = __commonJS({
|
|
|
5452
5452
|
}
|
|
5453
5453
|
}
|
|
5454
5454
|
if (opts.unescape === true) {
|
|
5455
|
-
if (
|
|
5456
|
-
|
|
5455
|
+
if (glob2)
|
|
5456
|
+
glob2 = utils.removeBackslashes(glob2);
|
|
5457
5457
|
if (base && backslashes === true) {
|
|
5458
5458
|
base = utils.removeBackslashes(base);
|
|
5459
5459
|
}
|
|
@@ -5463,7 +5463,7 @@ var require_scan = __commonJS({
|
|
|
5463
5463
|
input,
|
|
5464
5464
|
start,
|
|
5465
5465
|
base,
|
|
5466
|
-
glob,
|
|
5466
|
+
glob: glob2,
|
|
5467
5467
|
isBrace,
|
|
5468
5468
|
isBracket,
|
|
5469
5469
|
isGlob,
|
|
@@ -6309,9 +6309,9 @@ var require_picomatch = __commonJS({
|
|
|
6309
6309
|
var utils = require_utils2();
|
|
6310
6310
|
var constants = require_constants2();
|
|
6311
6311
|
var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
6312
|
-
var picomatch = (
|
|
6313
|
-
if (Array.isArray(
|
|
6314
|
-
const fns =
|
|
6312
|
+
var picomatch = (glob2, options, returnState = false) => {
|
|
6313
|
+
if (Array.isArray(glob2)) {
|
|
6314
|
+
const fns = glob2.map((input) => picomatch(input, options, returnState));
|
|
6315
6315
|
const arrayMatcher = (str) => {
|
|
6316
6316
|
for (const isMatch of fns) {
|
|
6317
6317
|
const state2 = isMatch(str);
|
|
@@ -6322,13 +6322,13 @@ var require_picomatch = __commonJS({
|
|
|
6322
6322
|
};
|
|
6323
6323
|
return arrayMatcher;
|
|
6324
6324
|
}
|
|
6325
|
-
const isState = isObject(
|
|
6326
|
-
if (
|
|
6325
|
+
const isState = isObject(glob2) && glob2.tokens && glob2.input;
|
|
6326
|
+
if (glob2 === "" || typeof glob2 !== "string" && !isState) {
|
|
6327
6327
|
throw new TypeError("Expected pattern to be a non-empty string");
|
|
6328
6328
|
}
|
|
6329
6329
|
const opts = options || {};
|
|
6330
6330
|
const posix = utils.isWindows(options);
|
|
6331
|
-
const regex = isState ? picomatch.compileRe(
|
|
6331
|
+
const regex = isState ? picomatch.compileRe(glob2, options) : picomatch.makeRe(glob2, options, false, true);
|
|
6332
6332
|
const state = regex.state;
|
|
6333
6333
|
delete regex.state;
|
|
6334
6334
|
let isIgnored = () => false;
|
|
@@ -6337,8 +6337,8 @@ var require_picomatch = __commonJS({
|
|
|
6337
6337
|
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
|
6338
6338
|
}
|
|
6339
6339
|
const matcher = (input, returnObject = false) => {
|
|
6340
|
-
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
|
|
6341
|
-
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
|
6340
|
+
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob: glob2, posix });
|
|
6341
|
+
const result = { glob: glob2, state, regex, posix, input, output, match, isMatch };
|
|
6342
6342
|
if (typeof opts.onResult === "function") {
|
|
6343
6343
|
opts.onResult(result);
|
|
6344
6344
|
}
|
|
@@ -6363,7 +6363,7 @@ var require_picomatch = __commonJS({
|
|
|
6363
6363
|
}
|
|
6364
6364
|
return matcher;
|
|
6365
6365
|
};
|
|
6366
|
-
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
|
6366
|
+
picomatch.test = (input, regex, options, { glob: glob2, posix } = {}) => {
|
|
6367
6367
|
if (typeof input !== "string") {
|
|
6368
6368
|
throw new TypeError("Expected input to be a string");
|
|
6369
6369
|
}
|
|
@@ -6372,11 +6372,11 @@ var require_picomatch = __commonJS({
|
|
|
6372
6372
|
}
|
|
6373
6373
|
const opts = options || {};
|
|
6374
6374
|
const format9 = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
6375
|
-
let match = input ===
|
|
6375
|
+
let match = input === glob2;
|
|
6376
6376
|
let output = match && format9 ? format9(input) : input;
|
|
6377
6377
|
if (match === false) {
|
|
6378
6378
|
output = format9 ? format9(input) : input;
|
|
6379
|
-
match = output ===
|
|
6379
|
+
match = output === glob2;
|
|
6380
6380
|
}
|
|
6381
6381
|
if (match === false || opts.capture === true) {
|
|
6382
6382
|
if (opts.matchBase === true || opts.basename === true) {
|
|
@@ -6387,8 +6387,8 @@ var require_picomatch = __commonJS({
|
|
|
6387
6387
|
}
|
|
6388
6388
|
return { isMatch: Boolean(match), match, output };
|
|
6389
6389
|
};
|
|
6390
|
-
picomatch.matchBase = (input,
|
|
6391
|
-
const regex =
|
|
6390
|
+
picomatch.matchBase = (input, glob2, options, posix = utils.isWindows(options)) => {
|
|
6391
|
+
const regex = glob2 instanceof RegExp ? glob2 : picomatch.makeRe(glob2, options);
|
|
6392
6392
|
return regex.test(path2.basename(input));
|
|
6393
6393
|
};
|
|
6394
6394
|
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
|
@@ -6581,9 +6581,9 @@ var require_micromatch = __commonJS({
|
|
|
6581
6581
|
}
|
|
6582
6582
|
return [].concat(patterns).every((p2) => picomatch(p2, options)(str));
|
|
6583
6583
|
};
|
|
6584
|
-
micromatch.capture = (
|
|
6584
|
+
micromatch.capture = (glob2, input, options) => {
|
|
6585
6585
|
let posix = utils.isWindows(options);
|
|
6586
|
-
let regex = picomatch.makeRe(String(
|
|
6586
|
+
let regex = picomatch.makeRe(String(glob2), { ...options, capture: true });
|
|
6587
6587
|
let match = regex.exec(posix ? utils.toPosixSlashes(input) : input);
|
|
6588
6588
|
if (match) {
|
|
6589
6589
|
return match.slice(1).map((v) => v === void 0 ? "" : v);
|
|
@@ -7183,7 +7183,7 @@ var require_out = __commonJS({
|
|
|
7183
7183
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7184
7184
|
exports.statSync = exports.stat = exports.Settings = void 0;
|
|
7185
7185
|
var async = require_async();
|
|
7186
|
-
var
|
|
7186
|
+
var sync2 = require_sync();
|
|
7187
7187
|
var settings_1 = require_settings();
|
|
7188
7188
|
exports.Settings = settings_1.default;
|
|
7189
7189
|
function stat(path2, optionsOrSettingsOrCallback, callback) {
|
|
@@ -7196,7 +7196,7 @@ var require_out = __commonJS({
|
|
|
7196
7196
|
exports.stat = stat;
|
|
7197
7197
|
function statSync(path2, optionsOrSettings) {
|
|
7198
7198
|
const settings = getSettings(optionsOrSettings);
|
|
7199
|
-
return
|
|
7199
|
+
return sync2.read(path2, settings);
|
|
7200
7200
|
}
|
|
7201
7201
|
exports.statSync = statSync;
|
|
7202
7202
|
function getSettings(settingsOrOptions = {}) {
|
|
@@ -7574,7 +7574,7 @@ var require_out2 = __commonJS({
|
|
|
7574
7574
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7575
7575
|
exports.Settings = exports.scandirSync = exports.scandir = void 0;
|
|
7576
7576
|
var async = require_async2();
|
|
7577
|
-
var
|
|
7577
|
+
var sync2 = require_sync2();
|
|
7578
7578
|
var settings_1 = require_settings2();
|
|
7579
7579
|
exports.Settings = settings_1.default;
|
|
7580
7580
|
function scandir(path2, optionsOrSettingsOrCallback, callback) {
|
|
@@ -7587,7 +7587,7 @@ var require_out2 = __commonJS({
|
|
|
7587
7587
|
exports.scandir = scandir;
|
|
7588
7588
|
function scandirSync(path2, optionsOrSettings) {
|
|
7589
7589
|
const settings = getSettings(optionsOrSettings);
|
|
7590
|
-
return
|
|
7590
|
+
return sync2.read(path2, settings);
|
|
7591
7591
|
}
|
|
7592
7592
|
exports.scandirSync = scandirSync;
|
|
7593
7593
|
function getSettings(settingsOrOptions = {}) {
|
|
@@ -9005,15 +9005,15 @@ var require_out4 = __commonJS({
|
|
|
9005
9005
|
}
|
|
9006
9006
|
(function(FastGlob2) {
|
|
9007
9007
|
FastGlob2.glob = FastGlob2;
|
|
9008
|
-
FastGlob2.globSync =
|
|
9008
|
+
FastGlob2.globSync = sync2;
|
|
9009
9009
|
FastGlob2.globStream = stream;
|
|
9010
9010
|
FastGlob2.async = FastGlob2;
|
|
9011
|
-
function
|
|
9011
|
+
function sync2(source, options) {
|
|
9012
9012
|
assertPatternsInput(source);
|
|
9013
9013
|
const works = getWorks(source, sync_1.default, options);
|
|
9014
9014
|
return utils.array.flatten(works);
|
|
9015
9015
|
}
|
|
9016
|
-
FastGlob2.sync =
|
|
9016
|
+
FastGlob2.sync = sync2;
|
|
9017
9017
|
function stream(source, options) {
|
|
9018
9018
|
assertPatternsInput(source);
|
|
9019
9019
|
const works = getWorks(source, stream_1.default, options);
|
|
@@ -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
|
}
|
|
@@ -229909,7 +229929,7 @@ var {
|
|
|
229909
229929
|
} = import_index.default;
|
|
229910
229930
|
|
|
229911
229931
|
// packages/cli-lib/src/cli.ts
|
|
229912
|
-
var
|
|
229932
|
+
var glob = __toESM(require_out4());
|
|
229913
229933
|
var import_loud_rejection = __toESM(require_loud_rejection());
|
|
229914
229934
|
|
|
229915
229935
|
// packages/cli-lib/src/compile.ts
|
|
@@ -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,18 +230476,36 @@ 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
|
-
|
|
230456
|
-
|
|
230457
|
-
|
|
230458
|
-
|
|
230459
|
-
|
|
230460
|
-
|
|
230461
|
-
|
|
230481
|
+
if (!shouldThrow) {
|
|
230482
|
+
const settledResults = await Promise.allSettled(
|
|
230483
|
+
files.map(async (fn) => {
|
|
230484
|
+
debug("Extracting file:", fn);
|
|
230485
|
+
const source = await (0, import_promises.readFile)(fn, "utf8");
|
|
230486
|
+
return processFile(source, fn, optsWithThrows);
|
|
230487
|
+
})
|
|
230488
|
+
);
|
|
230489
|
+
rawResults = settledResults.map((result) => {
|
|
230490
|
+
if (result.status === "fulfilled") {
|
|
230491
|
+
return result.value;
|
|
230492
|
+
} else {
|
|
230493
|
+
warn(String(result.reason));
|
|
230494
|
+
return void 0;
|
|
230495
|
+
}
|
|
230496
|
+
});
|
|
230497
|
+
} else {
|
|
230498
|
+
rawResults = await Promise.all(
|
|
230499
|
+
files.map(async (fn) => {
|
|
230500
|
+
debug("Extracting file:", fn);
|
|
230501
|
+
const source = await (0, import_promises.readFile)(fn, "utf8");
|
|
230502
|
+
return processFile(source, fn, optsWithThrows);
|
|
230503
|
+
})
|
|
230504
|
+
);
|
|
230505
|
+
}
|
|
230462
230506
|
}
|
|
230463
230507
|
} catch (e) {
|
|
230464
|
-
if (
|
|
230508
|
+
if (shouldThrow) {
|
|
230465
230509
|
throw e;
|
|
230466
230510
|
} else {
|
|
230467
230511
|
warn(String(e));
|
|
@@ -230689,6 +230733,7 @@ async function verify(files, { sourceLocale, missingKeys, extraKeys, structuralE
|
|
|
230689
230733
|
// packages/cli-lib/src/cli.ts
|
|
230690
230734
|
var import_path4 = require("path");
|
|
230691
230735
|
var import_fs = require("fs");
|
|
230736
|
+
var globSync = glob.sync;
|
|
230692
230737
|
var KNOWN_COMMANDS = ["extract"];
|
|
230693
230738
|
async function main(argv) {
|
|
230694
230739
|
(0, import_loud_rejection.default)();
|
|
@@ -230778,7 +230823,7 @@ sentences are not translator-friendly.`
|
|
|
230778
230823
|
const files = [];
|
|
230779
230824
|
if (filePatterns.length) {
|
|
230780
230825
|
files.push(
|
|
230781
|
-
...(
|
|
230826
|
+
...globSync(filePatterns, {
|
|
230782
230827
|
ignore: cmdObj.ignore
|
|
230783
230828
|
})
|
|
230784
230829
|
);
|
|
@@ -230839,7 +230884,7 @@ This is especially useful to convert from a TMS-specific format back to react-in
|
|
|
230839
230884
|
).action(async (filePatterns, opts) => {
|
|
230840
230885
|
debug("File pattern:", filePatterns);
|
|
230841
230886
|
debug("Options:", opts);
|
|
230842
|
-
const files = (
|
|
230887
|
+
const files = globSync(filePatterns);
|
|
230843
230888
|
if (!files.length) {
|
|
230844
230889
|
throw new Error(`No input file found with pattern ${filePatterns}`);
|
|
230845
230890
|
}
|
|
@@ -230873,7 +230918,7 @@ This is especially useful to convert from a TMS-specific format back to react-in
|
|
|
230873
230918
|
).action(async (folder, outFolder, opts) => {
|
|
230874
230919
|
debug("Folder:", folder);
|
|
230875
230920
|
debug("Options:", opts);
|
|
230876
|
-
const files = (
|
|
230921
|
+
const files = globSync(`${folder}/*.json`);
|
|
230877
230922
|
if (!files.length) {
|
|
230878
230923
|
throw new Error(`No JSON file found in ${folder}`);
|
|
230879
230924
|
}
|
|
@@ -230901,7 +230946,7 @@ This is especially useful to convert from a TMS-specific format back to react-in
|
|
|
230901
230946
|
).action(async (filePatterns, opts) => {
|
|
230902
230947
|
debug("File pattern:", filePatterns);
|
|
230903
230948
|
debug("Options:", opts);
|
|
230904
|
-
const files = (
|
|
230949
|
+
const files = globSync(filePatterns, {
|
|
230905
230950
|
ignore: opts.ignore
|
|
230906
230951
|
});
|
|
230907
230952
|
if (!files.length) {
|
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",
|