@formatjs/cli 6.16.3 → 6.16.5

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 CHANGED
@@ -5,8 +5,8 @@ const __filename = _furl(import.meta.url);
5
5
  const __dirname = _dname(__filename);
6
6
  import { createRequire } from "node:module";
7
7
  import * as path from "path";
8
- import { basename, join, resolve } from "path";
9
- import { readFileSync } from "fs";
8
+ import { basename, extname, join, resolve } from "path";
9
+ import { existsSync, readFileSync } from "fs";
10
10
  import { readFile } from "fs/promises";
11
11
  import { pathToFileURL } from "url";
12
12
  import { clearLine, cursorTo } from "readline";
@@ -6753,7 +6753,7 @@ var require_pattern = /* @__PURE__ */ __commonJSMin(((exports) => {
6753
6753
  }
6754
6754
  exports.hasGlobStar = hasGlobStar;
6755
6755
  function endsWithSlashGlobStar(pattern) {
6756
- return pattern.endsWith("/" + GLOBSTAR);
6756
+ return pattern.endsWith("/**");
6757
6757
  }
6758
6758
  exports.endsWithSlashGlobStar = endsWithSlashGlobStar;
6759
6759
  function isAffectDepthOfReadingPattern(pattern) {
@@ -12360,13 +12360,29 @@ function compileMessagesWithNative(messages, opts = {}) {
12360
12360
  skipErrors: opts.skipErrors
12361
12361
  });
12362
12362
  }
12363
+ function extractWithNative(inputFiles, opts = {}) {
12364
+ return loadNative().extract([...inputFiles], {
12365
+ additionalComponentNames: opts.additionalComponentNames,
12366
+ additionalFunctionNames: opts.additionalFunctionNames,
12367
+ extractSourceLocation: opts.extractSourceLocation,
12368
+ flatten: opts.flatten,
12369
+ followLinks: opts.followLinks,
12370
+ format: opts.format,
12371
+ idInterpolationPattern: opts.idInterpolationPattern,
12372
+ ignore: opts.ignore,
12373
+ inFile: opts.inFile,
12374
+ pragma: opts.pragma,
12375
+ preserveWhitespace: opts.preserveWhitespace,
12376
+ throws: opts.throws
12377
+ });
12378
+ }
12363
12379
  //#endregion
12364
12380
  //#region packages/cli-lib/compile.ts
12365
12381
  const dynamicImport = new Function("specifier", "return import(specifier)");
12366
12382
  const globSync$1 = import_out.sync;
12367
12383
  const stringify$2 = import_json_stable_stringify.default || import_json_stable_stringify;
12368
12384
  const CUSTOM_FORMATTER_FILE_DEPRECATION_WARNING = "Passing a custom formatter file to --format during compilation is deprecated and will be removed in a future release. Prefer a built-in formatter name or pre-process translation files before running formatjs compile.";
12369
- const BUILTIN_FORMATTERS = new Set([
12385
+ const BUILTIN_FORMATTERS$1 = new Set([
12370
12386
  "default",
12371
12387
  "simple",
12372
12388
  "transifex",
@@ -12384,7 +12400,7 @@ async function compile$6(inputFiles, opts = {}) {
12384
12400
  debug$1("Compiling files:", inputFiles);
12385
12401
  const { ast, format, pseudoLocale, skipErrors, ignoreTag, signal, followLinks } = opts;
12386
12402
  signal?.throwIfAborted();
12387
- if (format && !isBuiltinFormatter(format)) return compileWithCustomFormatter(inputFiles, opts);
12403
+ if (format && !isBuiltinFormatter$1(format)) return compileWithCustomFormatter(inputFiles, opts);
12388
12404
  return compileWithNative(inputFiles, {
12389
12405
  ast,
12390
12406
  format: typeof format === "string" ? format : void 0,
@@ -12394,8 +12410,8 @@ async function compile$6(inputFiles, opts = {}) {
12394
12410
  skipErrors
12395
12411
  });
12396
12412
  }
12397
- function isBuiltinFormatter(format) {
12398
- return typeof format === "string" && BUILTIN_FORMATTERS.has(format);
12413
+ function isBuiltinFormatter$1(format) {
12414
+ return typeof format === "string" && BUILTIN_FORMATTERS$1.has(format);
12399
12415
  }
12400
12416
  async function compileWithCustomFormatter(inputFiles, opts) {
12401
12417
  if (typeof opts.format === "string") await warn(CUSTOM_FORMATTER_FILE_DEPRECATION_WARNING);
@@ -14210,6 +14226,37 @@ function matchIdentifierAtIndex(s, index) {
14210
14226
  IDENTIFIER_PREFIX_RE.lastIndex = index;
14211
14227
  return IDENTIFIER_PREFIX_RE.exec(s)[1] ?? "";
14212
14228
  }
14229
+ function plainTopLevelEndPosition(message) {
14230
+ if (message.length === 0) return null;
14231
+ let line = 1;
14232
+ let column = 1;
14233
+ for (let offset = 0; offset < message.length;) {
14234
+ const code = message.charCodeAt(offset);
14235
+ switch (code) {
14236
+ case 35:
14237
+ case 39:
14238
+ case 60:
14239
+ case 123:
14240
+ case 125: return null;
14241
+ }
14242
+ if (code === 10) {
14243
+ line++;
14244
+ column = 1;
14245
+ offset++;
14246
+ } else {
14247
+ column++;
14248
+ if (code >= 55296 && code <= 56319 && offset + 1 < message.length) {
14249
+ const next = message.charCodeAt(offset + 1);
14250
+ offset += next >= 56320 && next <= 57343 ? 2 : 1;
14251
+ } else offset++;
14252
+ }
14253
+ }
14254
+ return {
14255
+ offset: message.length,
14256
+ line,
14257
+ column
14258
+ };
14259
+ }
14213
14260
  var Parser = class {
14214
14261
  constructor(message, options = {}) {
14215
14262
  this.message = message;
@@ -14225,6 +14272,24 @@ var Parser = class {
14225
14272
  }
14226
14273
  parse() {
14227
14274
  if (this.offset() !== 0) throw Error("parser can only be used once");
14275
+ if (this.message.length > 0) {
14276
+ const firstCode = this.message.charCodeAt(0);
14277
+ if (firstCode !== 35 && firstCode !== 39 && firstCode !== 60 && firstCode !== 123 && firstCode !== 125) {
14278
+ const plainEndPosition = plainTopLevelEndPosition(this.message);
14279
+ if (plainEndPosition) {
14280
+ const start = this.clonePosition();
14281
+ this.position = plainEndPosition;
14282
+ return {
14283
+ val: [{
14284
+ type: 0,
14285
+ value: this.message,
14286
+ location: createLocation(start, this.clonePosition())
14287
+ }],
14288
+ err: null
14289
+ };
14290
+ }
14291
+ }
14292
+ }
14228
14293
  return this.parseMessage(0, "", false);
14229
14294
  }
14230
14295
  parseMessage(nestingLevel, parentArgType, expectingCloseTag) {
@@ -70200,7 +70265,7 @@ ${lanes.join("\n")}
70200
70265
  type = getIntendedTypeFromJSDocTypeReference(node);
70201
70266
  if (!type) {
70202
70267
  symbol = resolveTypeReferenceName(node, meaning, true);
70203
- if (symbol === unknownSymbol) symbol = resolveTypeReferenceName(node, meaning | 111551);
70268
+ if (symbol === unknownSymbol) symbol = resolveTypeReferenceName(node, 900095);
70204
70269
  else resolveTypeReferenceName(node, meaning);
70205
70270
  type = getTypeReferenceType(node, symbol);
70206
70271
  }
@@ -144842,7 +144907,7 @@ ${newComment.split("\n").map((c) => ` * ${c}`).join("\n")}
144842
144907
  };
144843
144908
  }
144844
144909
  return {
144845
- newText: openComment + closeComment,
144910
+ newText: "/** */",
144846
144911
  caretOffset: 3
144847
144912
  };
144848
144913
  }
@@ -163420,6 +163485,22 @@ ${e.message || ""}`;
163420
163485
  //#endregion
163421
163486
  //#region packages/cli-lib/extract.ts
163422
163487
  const stringify = import_json_stable_stringify.default || import_json_stable_stringify;
163488
+ const BUILTIN_FORMATTERS = new Set([
163489
+ "default",
163490
+ "simple",
163491
+ "transifex",
163492
+ "smartling",
163493
+ "lokalise",
163494
+ "crowdin"
163495
+ ]);
163496
+ const NATIVE_SUPPORTED_EXTENSIONS = new Set([
163497
+ ".cjs",
163498
+ ".js",
163499
+ ".jsx",
163500
+ ".mjs",
163501
+ ".ts",
163502
+ ".tsx"
163503
+ ]);
163423
163504
  function calculateLineColFromOffset(text, start) {
163424
163505
  if (!start) return {
163425
163506
  line: 1,
@@ -163432,6 +163513,12 @@ function calculateLineColFromOffset(text, start) {
163432
163513
  col: lastLine.length
163433
163514
  };
163434
163515
  }
163516
+ function isBuiltinFormatter(format) {
163517
+ return !format || typeof format === "string" && BUILTIN_FORMATTERS.has(format);
163518
+ }
163519
+ function canExtractWithNative(files, opts, readFromStdin) {
163520
+ return !readFromStdin && typeof opts.idInterpolationPattern === "string" && !opts.ast && !opts.extractSourceLocation && !opts.onMetaExtracted && !opts.onMsgError && !opts.onMsgExtracted && !opts.overrideIdFn && !opts.pragma && !opts.removeDefaultMessage && isBuiltinFormatter(opts.format) && files.every((file) => existsSync(file) && NATIVE_SUPPORTED_EXTENSIONS.has(extname(file).toLowerCase()));
163521
+ }
163435
163522
  async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
163436
163523
  let messages = [];
163437
163524
  let meta;
@@ -163461,19 +163548,19 @@ async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
163461
163548
  const scriptParseFn = parseScript(opts, fn);
163462
163549
  if (fn.endsWith(".vue")) {
163463
163550
  debug$1("Processing %s using vue extractor", fn);
163464
- const { parseFile } = await import("./vue_extractor-BFqKdH3o.js");
163551
+ const { parseFile } = await import("./vue_extractor-CGXoDm-M.js");
163465
163552
  parseFile(source, fn, scriptParseFn);
163466
163553
  } else if (fn.endsWith(".svelte")) {
163467
163554
  debug$1("Processing %s using svelte extractor", fn);
163468
- const { parseFile } = await import("./svelte_extractor-CLhHGLMq.js");
163555
+ const { parseFile } = await import("./svelte_extractor-R4PlmulG.js");
163469
163556
  parseFile(source, fn, scriptParseFn);
163470
163557
  } else if (fn.endsWith(".hbs")) {
163471
163558
  debug$1("Processing %s using hbs extractor", fn);
163472
- const { parseFile } = await import("./hbs_extractor-BGwD6qGk.js");
163559
+ const { parseFile } = await import("./hbs_extractor-DC74dtk6.js");
163473
163560
  parseFile(source, fn, opts);
163474
163561
  } else if (fn.endsWith(".gts") || fn.endsWith(".gjs")) {
163475
163562
  debug$1("Processing %s as gts/gjs file", fn);
163476
- const { parseFile } = await import("./gts_extractor-vkhePCTf.js");
163563
+ const { parseFile } = await import("./gts_extractor-Dk_HfFGZ.js");
163477
163564
  parseFile(source, fn, opts);
163478
163565
  } else {
163479
163566
  debug$1("Processing %s using typescript extractor", fn);
@@ -163504,6 +163591,15 @@ async function extract(files, extractOpts) {
163504
163591
  throws: shouldThrow,
163505
163592
  onMsgError: !shouldThrow ? (_, e) => warn(e.message) : void 0
163506
163593
  };
163594
+ if (!signal?.aborted && canExtractWithNative(files, opts, readFromStdin)) return extractWithNative(files, {
163595
+ additionalComponentNames: ["$formatMessage", ...opts.additionalComponentNames || []],
163596
+ additionalFunctionNames: opts.additionalFunctionNames,
163597
+ flatten: opts.flatten,
163598
+ format: typeof opts.format === "string" ? opts.format : void 0,
163599
+ idInterpolationPattern: opts.idInterpolationPattern,
163600
+ preserveWhitespace: opts.preserveWhitespace,
163601
+ throws: shouldThrow
163602
+ });
163507
163603
  let rawResults = [];
163508
163604
  try {
163509
163605
  if (readFromStdin) {