@formatjs/cli-lib 8.2.1 → 8.2.3

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 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.1",
4
+ "version": "8.2.3",
5
5
  "license": "MIT",
6
6
  "author": "Linjie Ding <linjie@airtable.com>",
7
7
  "type": "module",
@@ -20,9 +20,9 @@
20
20
  "loud-rejection": "^2",
21
21
  "tslib": "^2.8.1",
22
22
  "typescript": "^5.6.0",
23
- "@formatjs/icu-messageformat-parser": "3.5.0",
24
- "@formatjs/icu-skeleton-parser": "2.1.0",
25
- "@formatjs/ts-transformer": "4.3.1"
23
+ "@formatjs/ts-transformer": "4.3.3",
24
+ "@formatjs/icu-messageformat-parser": "3.5.1",
25
+ "@formatjs/icu-skeleton-parser": "2.1.1"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "@glimmer/syntax": "^0.84.3 || ^0.95.0",
package/src/cli.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { program } from "commander";
2
- import { sync as globSync } from "fast-glob";
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";
package/src/extract.js CHANGED
@@ -91,6 +91,14 @@ async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
91
91
  */
92
92
  export async function extract(files, extractOpts) {
93
93
  const { throws, readFromStdin, ...opts } = extractOpts;
94
+ // When throws is not explicitly true, we want to collect partial results
95
+ const shouldThrow = throws === true;
96
+ // Pass throws option to transformer for per-message error handling
97
+ const optsWithThrows = {
98
+ ...opts,
99
+ throws: shouldThrow,
100
+ onMsgError: !shouldThrow ? (_, e) => warn(e.message) : undefined
101
+ };
94
102
  let rawResults = [];
95
103
  try {
96
104
  if (readFromStdin) {
@@ -100,16 +108,33 @@ export async function extract(files, extractOpts) {
100
108
  warn("Reading source file from TTY.");
101
109
  }
102
110
  const stdinSource = await getStdinAsString();
103
- rawResults = [await processFile(stdinSource, "dummy", opts)];
111
+ rawResults = [await processFile(stdinSource, "dummy", optsWithThrows)];
104
112
  } else {
105
- rawResults = await Promise.all(files.map(async (fn) => {
106
- debug("Extracting file:", fn);
107
- const source = await readFile(fn, "utf8");
108
- return processFile(source, fn, opts);
109
- }));
113
+ // Use Promise.allSettled when throws is not explicitly true to collect partial results
114
+ if (!shouldThrow) {
115
+ const settledResults = await Promise.allSettled(files.map(async (fn) => {
116
+ debug("Extracting file:", fn);
117
+ const source = await readFile(fn, "utf8");
118
+ return processFile(source, fn, optsWithThrows);
119
+ }));
120
+ rawResults = settledResults.map((result) => {
121
+ if (result.status === "fulfilled") {
122
+ return result.value;
123
+ } else {
124
+ warn(String(result.reason));
125
+ return undefined;
126
+ }
127
+ });
128
+ } else {
129
+ rawResults = await Promise.all(files.map(async (fn) => {
130
+ debug("Extracting file:", fn);
131
+ const source = await readFile(fn, "utf8");
132
+ return processFile(source, fn, optsWithThrows);
133
+ }));
134
+ }
110
135
  }
111
136
  } catch (e) {
112
- if (throws) {
137
+ if (shouldThrow) {
113
138
  throw e;
114
139
  } else {
115
140
  warn(String(e));