@formatjs/cli-lib 8.2.2 → 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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/extract.js +14 -6
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.2",
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/ts-transformer": "4.3.2",
24
- "@formatjs/icu-skeleton-parser": "2.1.1",
25
- "@formatjs/icu-messageformat-parser": "3.5.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/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,14 +108,14 @@ 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
- // Use Promise.allSettled when throws is false to collect partial results
106
- if (throws === false) {
113
+ // Use Promise.allSettled when throws is not explicitly true to collect partial results
114
+ if (!shouldThrow) {
107
115
  const settledResults = await Promise.allSettled(files.map(async (fn) => {
108
116
  debug("Extracting file:", fn);
109
117
  const source = await readFile(fn, "utf8");
110
- return processFile(source, fn, opts);
118
+ return processFile(source, fn, optsWithThrows);
111
119
  }));
112
120
  rawResults = settledResults.map((result) => {
113
121
  if (result.status === "fulfilled") {
@@ -121,12 +129,12 @@ export async function extract(files, extractOpts) {
121
129
  rawResults = await Promise.all(files.map(async (fn) => {
122
130
  debug("Extracting file:", fn);
123
131
  const source = await readFile(fn, "utf8");
124
- return processFile(source, fn, opts);
132
+ return processFile(source, fn, optsWithThrows);
125
133
  }));
126
134
  }
127
135
  }
128
136
  } catch (e) {
129
- if (throws) {
137
+ if (shouldThrow) {
130
138
  throw e;
131
139
  } else {
132
140
  warn(String(e));