@formatjs/cli-lib 10.0.12 → 10.2.0

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.
@@ -1,13 +1,12 @@
1
- import { parseFile as parseFile$1 } from "./hbs_extractor-OLNU6TfH.js";
1
+ import { parseFile as parseFile$1 } from "./hbs_extractor-BDPJhcOo.js";
2
2
  import { Preprocessor } from "content-tag";
3
- //#region packages/cli-lib/gts_extractor.ts
3
+ // packages/cli-lib/gts_extractor.ts
4
4
  let p = new Preprocessor();
5
5
  function parseFile(source, fileName, options, parseScriptFn) {
6
6
  parseScriptFn(p.process(source, { filename: fileName }).code);
7
7
  const parseResult = p.parse(source, { filename: fileName });
8
8
  for (let parsed of parseResult) parseFile$1(parsed.contents, fileName, options);
9
9
  }
10
- //#endregion
11
10
  export { parseFile };
12
11
 
13
- //# sourceMappingURL=gts_extractor-DBQky2Xr.js.map
12
+ //# sourceMappingURL=gts_extractor-BE9qz7gr.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gts_extractor-DBQky2Xr.js","names":[],"sources":["sources/packages/cli-lib/gts_extractor.ts"],"sourcesContent":["import {Preprocessor} from 'content-tag'\nimport {parseFile as parseHbsFile} from '#packages/cli-lib/hbs_extractor.js'\nimport {type ScriptParseFn} from '#packages/cli-lib/svelte_extractor.js'\nlet p = new Preprocessor()\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any,\n parseScriptFn: ScriptParseFn\n): void {\n const transformedSource = p.process(source, {filename: fileName})\n\n parseScriptFn(transformedSource.code)\n\n // extract template from transformed source to then run through hbs processor\n const parseResult = p.parse(source, {filename: fileName})\n\n for (let parsed of parseResult) {\n parseHbsFile(parsed.contents, fileName, options)\n }\n}\n"],"mappings":";;;AAGA,IAAI,IAAI,IAAI,aAAa;AAEzB,SAAgB,UACd,QACA,UACA,SACA,eACM;CAGN,cAF0B,EAAE,QAAQ,QAAQ,EAAC,UAAU,SAAQ,CAEjC,CAAC,CAAC,IAAI;CAGpC,MAAM,cAAc,EAAE,MAAM,QAAQ,EAAC,UAAU,SAAQ,CAAC;CAExD,KAAK,IAAI,UAAU,aACjB,YAAa,OAAO,UAAU,UAAU,OAAO;AAEnD"}
1
+ {"version":3,"file":"gts_extractor-BE9qz7gr.js","names":[],"sources":["sources/packages/cli-lib/gts_extractor.ts"],"sourcesContent":["import {Preprocessor} from 'content-tag'\nimport {parseFile as parseHbsFile} from '#packages/cli-lib/hbs_extractor.js'\nimport {type ScriptParseFn} from '#packages/cli-lib/svelte_extractor.js'\nlet p = new Preprocessor()\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any,\n parseScriptFn: ScriptParseFn\n): void {\n const transformedSource = p.process(source, {filename: fileName})\n\n parseScriptFn(transformedSource.code)\n\n // extract template from transformed source to then run through hbs processor\n const parseResult = p.parse(source, {filename: fileName})\n\n for (let parsed of parseResult) {\n parseHbsFile(parsed.contents, fileName, options)\n }\n}\n"],"mappings":";;;AAGA,IAAI,IAAI,IAAI,aAAa;AAEzB,SAAgB,UACd,QACA,UACA,SACA,eACM;CAGN,cAF0B,EAAE,QAAQ,QAAQ,EAAC,UAAU,SAAQ,CAEjC,CAAC,CAAC,IAAI;CAGpC,MAAM,cAAc,EAAE,MAAM,QAAQ,EAAC,UAAU,SAAQ,CAAC;CAExD,KAAK,IAAI,UAAU,aACjB,YAAa,OAAO,UAAU,UAAU,OAAO;AAEnD"}
@@ -1,5 +1,5 @@
1
1
  import { preprocess, traverse } from "@glimmer/syntax";
2
- //#region packages/cli-lib/hbs_extractor.ts
2
+ // packages/cli-lib/hbs_extractor.ts
3
3
  function extractText(node, fileName, options) {
4
4
  if (!options.onMsgExtracted) return;
5
5
  if (!options.overrideIdFn) return;
@@ -30,7 +30,6 @@ function parseFile(source, fileName, options) {
30
30
  }
31
31
  });
32
32
  }
33
- //#endregion
34
33
  export { parseFile };
35
34
 
36
- //# sourceMappingURL=hbs_extractor-OLNU6TfH.js.map
35
+ //# sourceMappingURL=hbs_extractor-BDPJhcOo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hbs_extractor-OLNU6TfH.js","names":[],"sources":["sources/packages/cli-lib/hbs_extractor.ts"],"sourcesContent":["import {type ExtractTransformOptions} from '#packages/cli-lib/types.js'\nimport {preprocess, traverse, type AST, type ASTv1} from '@glimmer/syntax'\n\nfunction extractText(\n node: AST.MustacheStatement | AST.SubExpression,\n fileName: string,\n options: ExtractTransformOptions\n) {\n if (!options.onMsgExtracted) return\n if (!options.overrideIdFn) return\n\n if (node.path.type !== 'PathExpression') return\n\n if (['format-message', 'formatMessage'].includes(node.path.original)) {\n let [first, second] = node.params\n\n if (first.type !== 'StringLiteral') return\n\n let message = first?.value\n\n let desc: string | undefined\n if (second?.type === 'StringLiteral') {\n desc = second.value?.trim().replace(/\\s+/gm, ' ')\n }\n\n let defaultMessage = message?.trim().replace(/\\s+/gm, ' ')\n\n let id =\n typeof options.overrideIdFn === 'string'\n ? options.overrideIdFn\n : options.overrideIdFn(undefined, defaultMessage, desc, fileName)\n\n options.onMsgExtracted(fileName, [\n {\n id: id,\n defaultMessage: defaultMessage,\n description: desc,\n },\n ])\n }\n}\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const ast = preprocess(source)\n traverse(ast, {\n MustacheStatement(node: ASTv1.MustacheStatement) {\n extractText(node, fileName, options)\n },\n SubExpression(node: ASTv1.SubExpression) {\n extractText(node, fileName, options)\n },\n })\n}\n"],"mappings":";;AAGA,SAAS,YACP,MACA,UACA,SACA;CACA,IAAI,CAAC,QAAQ,gBAAgB;CAC7B,IAAI,CAAC,QAAQ,cAAc;CAE3B,IAAI,KAAK,KAAK,SAAS,kBAAkB;CAEzC,IAAI,CAAC,kBAAkB,eAAe,CAAC,CAAC,SAAS,KAAK,KAAK,QAAQ,GAAG;EACpE,IAAI,CAAC,OAAO,UAAU,KAAK;EAE3B,IAAI,MAAM,SAAS,iBAAiB;EAEpC,IAAI,UAAU,OAAO;EAErB,IAAI;EACJ,IAAI,QAAQ,SAAS,iBACnB,OAAO,OAAO,OAAO,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG;EAGlD,IAAI,iBAAiB,SAAS,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG;EAEzD,IAAI,KACF,OAAO,QAAQ,iBAAiB,WAC5B,QAAQ,eACR,QAAQ,aAAa,KAAA,GAAW,gBAAgB,MAAM,QAAQ;EAEpE,QAAQ,eAAe,UAAU,CAC/B;GACM;GACY;GAChB,aAAa;EACf,CACF,CAAC;CACH;AACF;AAEA,SAAgB,UACd,QACA,UACA,SACM;CACN,MAAM,MAAM,WAAW,MAAM;CAC7B,SAAS,KAAK;EACZ,kBAAkB,MAA+B;GAC/C,YAAY,MAAM,UAAU,OAAO;EACrC;EACA,cAAc,MAA2B;GACvC,YAAY,MAAM,UAAU,OAAO;EACrC;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"hbs_extractor-BDPJhcOo.js","names":[],"sources":["sources/packages/cli-lib/hbs_extractor.ts"],"sourcesContent":["import {type ExtractTransformOptions} from '#packages/cli-lib/types.js'\nimport {preprocess, traverse, type AST, type ASTv1} from '@glimmer/syntax'\n\nfunction extractText(\n node: AST.MustacheStatement | AST.SubExpression,\n fileName: string,\n options: ExtractTransformOptions\n) {\n if (!options.onMsgExtracted) return\n if (!options.overrideIdFn) return\n\n if (node.path.type !== 'PathExpression') return\n\n if (['format-message', 'formatMessage'].includes(node.path.original)) {\n let [first, second] = node.params\n\n if (first.type !== 'StringLiteral') return\n\n let message = first?.value\n\n let desc: string | undefined\n if (second?.type === 'StringLiteral') {\n desc = second.value?.trim().replace(/\\s+/gm, ' ')\n }\n\n let defaultMessage = message?.trim().replace(/\\s+/gm, ' ')\n\n let id =\n typeof options.overrideIdFn === 'string'\n ? options.overrideIdFn\n : options.overrideIdFn(undefined, defaultMessage, desc, fileName)\n\n options.onMsgExtracted(fileName, [\n {\n id: id,\n defaultMessage: defaultMessage,\n description: desc,\n },\n ])\n }\n}\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const ast = preprocess(source)\n traverse(ast, {\n MustacheStatement(node: ASTv1.MustacheStatement) {\n extractText(node, fileName, options)\n },\n SubExpression(node: ASTv1.SubExpression) {\n extractText(node, fileName, options)\n },\n })\n}\n"],"mappings":";;AAGA,SAAS,YACP,MACA,UACA,SACA;CACA,IAAI,CAAC,QAAQ,gBAAgB;CAC7B,IAAI,CAAC,QAAQ,cAAc;CAE3B,IAAI,KAAK,KAAK,SAAS,kBAAkB;CAEzC,IAAI,CAAC,kBAAkB,eAAe,CAAC,CAAC,SAAS,KAAK,KAAK,QAAQ,GAAG;EACpE,IAAI,CAAC,OAAO,UAAU,KAAK;EAE3B,IAAI,MAAM,SAAS,iBAAiB;EAEpC,IAAI,UAAU,OAAO;EAErB,IAAI;EACJ,IAAI,QAAQ,SAAS,iBACnB,OAAO,OAAO,OAAO,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG;EAGlD,IAAI,iBAAiB,SAAS,KAAK,CAAC,CAAC,QAAQ,SAAS,GAAG;EAEzD,IAAI,KACF,OAAO,QAAQ,iBAAiB,WAC5B,QAAQ,eACR,QAAQ,aAAa,KAAA,GAAW,gBAAgB,MAAM,QAAQ;EAEpE,QAAQ,eAAe,UAAU,CAC/B;GACM;GACY;GAChB,aAAa;EACf,CACF,CAAC;CACH;AACF;AAEA,SAAgB,UACd,QACA,UACA,SACM;CACN,MAAM,MAAM,WAAW,MAAM;CAC7B,SAAS,KAAK;EACZ,kBAAkB,MAA+B;GAC/C,YAAY,MAAM,UAAU,OAAO;EACrC;EACA,cAAc,MAA2B;GACvC,YAAY,MAAM,UAAU,OAAO;EACrC;CACF,CAAC;AACH"}
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Comparator, Comparator as Comparator$1 } from "json-stable-stringify";
2
- //#region packages/cli-lib/types.d.ts
3
2
  interface MessageDescriptor {
4
3
  id: string;
5
4
  description?: string | object;
@@ -26,21 +25,15 @@ interface ExtractTransformOptions {
26
25
  throws?: boolean;
27
26
  onMsgError?: (filePath: string, error: Error) => void;
28
27
  }
29
- //#endregion
30
- //#region packages/cli-lib/formatters/default.d.ts
31
28
  type FormatFn<T = Record<string, MessageDescriptor>> = (msgs: Record<string, MessageDescriptor>) => T;
32
29
  type CompileFn<T = Record<string, MessageDescriptor>> = (msgs: T) => Record<string, string>;
33
30
  type SerializeFn<T = Record<string, MessageDescriptor>> = (msgs: T) => string;
34
- //#endregion
35
- //#region packages/cli-lib/formatters/index.d.ts
36
31
  interface Formatter<T> {
37
32
  serialize?: SerializeFn<T>;
38
33
  format: FormatFn<T>;
39
34
  compile: CompileFn<T>;
40
35
  compareMessages?: Comparator$1;
41
36
  }
42
- //#endregion
43
- //#region packages/cli-lib/extract.d.ts
44
37
  type ExtractCLIOptions = Omit<ExtractOpts, "overrideIdFn" | "onMsgExtracted" | "onMetaExtracted"> & {
45
38
  /**
46
39
  * Output File
@@ -102,8 +95,6 @@ export declare function extract(files: readonly string[], extractOpts: ExtractOp
102
95
  * @returns A Promise that resolves if output file was written successfully
103
96
  */
104
97
  declare function extractAndWrite(files: readonly string[], extractOpts: ExtractCLIOptions): Promise<void>;
105
- //#endregion
106
- //#region packages/cli-lib/compile.d.ts
107
98
  type PseudoLocale = "xx-LS" | "xx-AC" | "xx-HA" | "en-XA" | "en-XB";
108
99
  interface CompileCLIOpts extends Opts {
109
100
  /**
@@ -163,6 +154,5 @@ export declare function compile(inputFiles: string[], opts?: Opts): Promise<stri
163
154
  * @returns A `Promise` that resolves if file was written successfully
164
155
  */
165
156
  declare function compileAndWrite(inputFiles: string[], compileOpts?: CompileCLIOpts): Promise<void>;
166
- //#endregion
167
157
  export { type Comparator, type CompileCLIOpts, type CompileFn, type Opts as CompileOpts, type ExtractCLIOptions, type ExtractOpts, type FormatFn, type MessageDescriptor, compileAndWrite, extractAndWrite };
168
158
  //# sourceMappingURL=index.d.ts.map
package/index.js CHANGED
@@ -9,7 +9,7 @@ import { createRequire } from "module";
9
9
  import { Runfiles } from "@bazel/runfiles";
10
10
  import { readFile } from "fs/promises";
11
11
  import glob from "fast-glob";
12
- //#region \0rolldown/runtime.js
12
+ // \0rolldown/runtime.js
13
13
  var __defProp = Object.defineProperty;
14
14
  var __exportAll = (all, no_symbols) => {
15
15
  let target = {};
@@ -20,8 +20,7 @@ var __exportAll = (all, no_symbols) => {
20
20
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
21
21
  return target;
22
22
  };
23
- //#endregion
24
- //#region packages/cli-lib/console_utils.ts
23
+ // packages/cli-lib/console_utils.ts
25
24
  const CLEAR_WHOLE_LINE = 0;
26
25
  const writeStderr = promisify(process.stderr.write).bind(process.stderr);
27
26
  const writeStdout = promisify(process.stdout.write).bind(process.stdout);
@@ -68,8 +67,7 @@ function getStdinAsString() {
68
67
  });
69
68
  });
70
69
  }
71
- //#endregion
72
- //#region packages/cli-lib/formatters/crowdin.ts
70
+ // packages/cli-lib/formatters/crowdin.ts
73
71
  var crowdin_exports = /* @__PURE__ */ __exportAll({
74
72
  compile: () => compile$6,
75
73
  format: () => format$6
@@ -90,8 +88,7 @@ const compile$6 = (msgs) => {
90
88
  }
91
89
  return results;
92
90
  };
93
- //#endregion
94
- //#region packages/cli-lib/formatters/default.ts
91
+ // packages/cli-lib/formatters/default.ts
95
92
  var default_exports = /* @__PURE__ */ __exportAll({
96
93
  compile: () => compile$5,
97
94
  format: () => format$5
@@ -102,8 +99,7 @@ const compile$5 = (msgs) => {
102
99
  for (const k in msgs) results[k] = msgs[k].defaultMessage;
103
100
  return results;
104
101
  };
105
- //#endregion
106
- //#region packages/cli-lib/formatters/lokalise.ts
102
+ // packages/cli-lib/formatters/lokalise.ts
107
103
  var lokalise_exports = /* @__PURE__ */ __exportAll({
108
104
  compile: () => compile$4,
109
105
  format: () => format$4
@@ -121,8 +117,7 @@ const compile$4 = (msgs) => {
121
117
  for (const [id, msg] of Object.entries(msgs)) results[id] = msg.translation;
122
118
  return results;
123
119
  };
124
- //#endregion
125
- //#region packages/cli-lib/formatters/simple.ts
120
+ // packages/cli-lib/formatters/simple.ts
126
121
  var simple_exports = /* @__PURE__ */ __exportAll({
127
122
  compile: () => compile$3,
128
123
  format: () => format$3
@@ -134,8 +129,7 @@ const format$3 = (msgs) => {
134
129
  }, {});
135
130
  };
136
131
  const compile$3 = (msgs) => msgs;
137
- //#endregion
138
- //#region packages/cli-lib/formatters/smartling.ts
132
+ // packages/cli-lib/formatters/smartling.ts
139
133
  var smartling_exports = /* @__PURE__ */ __exportAll({
140
134
  compareMessages: () => compareMessages,
141
135
  compile: () => compile$2,
@@ -170,8 +164,7 @@ const compile$2 = (msgs) => {
170
164
  }
171
165
  return results;
172
166
  };
173
- //#endregion
174
- //#region packages/cli-lib/formatters/transifex.ts
167
+ // packages/cli-lib/formatters/transifex.ts
175
168
  var transifex_exports = /* @__PURE__ */ __exportAll({
176
169
  compile: () => compile$1,
177
170
  format: () => format$1
@@ -189,8 +182,7 @@ const compile$1 = (msgs) => {
189
182
  for (const [id, msg] of Object.entries(msgs)) results[id] = msg.string;
190
183
  return results;
191
184
  };
192
- //#endregion
193
- //#region packages/cli-lib/formatters/index.ts
185
+ // packages/cli-lib/formatters/index.ts
194
186
  async function resolveBuiltinFormatter(format) {
195
187
  if (!format) return default_exports;
196
188
  if (typeof format !== "string") return format;
@@ -208,14 +200,15 @@ async function resolveBuiltinFormatter(format) {
208
200
  throw e;
209
201
  }
210
202
  }
211
- //#endregion
212
- //#region packages/cli-lib/native.ts
203
+ // packages/cli-lib/native.ts
213
204
  const require$1 = createRequire(import.meta.url);
214
205
  const NATIVE_PACKAGES = {
215
206
  "darwin-arm64": ["@formatjs/cli-native-darwin-arm64"],
207
+ "darwin-x64": ["@formatjs/cli-native-darwin-x64"],
216
208
  "linux-arm64": ["@formatjs/cli-native-linux-arm64", "@formatjs/cli-native-linux-arm64-musl"],
217
209
  "linux-x64": ["@formatjs/cli-native-linux-x64", "@formatjs/cli-native-linux-x64-musl"],
218
- "win32-x64": ["@formatjs/cli-native-win32-x64"]
210
+ "win32-x64": ["@formatjs/cli-native-win32-x64"],
211
+ "win32-arm64": ["@formatjs/cli-native-win32-arm64"]
219
212
  };
220
213
  let nativeBinding;
221
214
  function getInstalledNativePackageCandidates(candidates, canResolve = (candidate) => {
@@ -279,8 +272,7 @@ function extractSourcesWithNative(sources, opts = {}, generateIds = true) {
279
272
  function generateIdWithNative(pattern, defaultMessage, description, filename) {
280
273
  return loadNative().generateId(pattern, defaultMessage, description === void 0 ? void 0 : JSON.stringify(description), filename);
281
274
  }
282
- //#endregion
283
- //#region packages/cli-lib/extract.ts
275
+ // packages/cli-lib/extract.ts
284
276
  const stringify$1 = stringifyNs.default || stringifyNs;
285
277
  const DEFAULT_ID_INTERPOLATION_PATTERN = "[sha1:contenthash:base64:6]";
286
278
  function byteOffsetToStringOffset(text, offset) {
@@ -376,19 +368,19 @@ async function processFile(source, fn, opts) {
376
368
  };
377
369
  if (fn.endsWith(".vue")) {
378
370
  debug("Processing %s using vue extractor", fn);
379
- const { parseFile } = await import("./vue_extractor-C6UQIcDj.js");
371
+ const { parseFile } = await import("./vue_extractor-Dzn5fsfZ.js");
380
372
  parseFile(source, fn, scriptParseFn);
381
373
  } else if (fn.endsWith(".svelte")) {
382
374
  debug("Processing %s using svelte extractor", fn);
383
- const { parseFile } = await import("./svelte_extractor-Csb4fR2L.js");
375
+ const { parseFile } = await import("./svelte_extractor-CEd4aBBk.js");
384
376
  parseFile(source, fn, scriptParseFn);
385
377
  } else if (fn.endsWith(".hbs")) {
386
378
  debug("Processing %s using hbs extractor", fn);
387
- const { parseFile } = await import("./hbs_extractor-OLNU6TfH.js");
379
+ const { parseFile } = await import("./hbs_extractor-BDPJhcOo.js");
388
380
  parseFile(source, fn, hbsOptions);
389
381
  } else if (fn.endsWith(".gts") || fn.endsWith(".gjs")) {
390
382
  debug("Processing %s as gts/gjs file", fn);
391
- const { parseFile } = await import("./gts_extractor-DBQky2Xr.js");
383
+ const { parseFile } = await import("./gts_extractor-BE9qz7gr.js");
392
384
  parseFile(source, fn, hbsOptions, scriptParseFn);
393
385
  } else {
394
386
  debug("Processing %s using native extractor", fn);
@@ -511,8 +503,7 @@ async function extractAndWrite(files, extractOpts) {
511
503
  }
512
504
  await writeStdout(serializedResult);
513
505
  }
514
- //#endregion
515
- //#region packages/cli-lib/compile.ts
506
+ // packages/cli-lib/compile.ts
516
507
  const dynamicImport = new Function("specifier", "return import(specifier)");
517
508
  const globSync = glob.sync;
518
509
  const stringify = stringifyNs.default || stringifyNs;
@@ -605,7 +596,6 @@ async function compileAndWrite(inputFiles, compileOpts = {}) {
605
596
  }
606
597
  await writeStdout(serializedResult);
607
598
  }
608
- //#endregion
609
599
  export { compile, compileAndWrite, extract, extractAndWrite };
610
600
 
611
601
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["clearLine","format","compile","format","compile","format","compile","format","compile","format","compile","format","compile","defaultFormatter","transifex","smartling","simple","lokalise","crowdin","require","stringify"],"sources":["sources/packages/cli-lib/console_utils.ts","sources/packages/cli-lib/formatters/crowdin.ts","sources/packages/cli-lib/formatters/default.ts","sources/packages/cli-lib/formatters/lokalise.ts","sources/packages/cli-lib/formatters/simple.ts","sources/packages/cli-lib/formatters/smartling.ts","sources/packages/cli-lib/formatters/transifex.ts","sources/packages/cli-lib/formatters/index.ts","sources/packages/cli-lib/native.ts","sources/packages/cli-lib/extract.ts","sources/packages/cli-lib/compile.ts"],"sourcesContent":["import {\n clearLine as nativeClearLine,\n cursorTo as nativeCursorTo,\n} from 'readline'\nimport {format, promisify, styleText} from 'node:util'\n\nconst CLEAR_WHOLE_LINE = 0\n\nexport const writeStderr: (arg1: string | Uint8Array) => Promise<void> =\n promisify(process.stderr.write).bind(process.stderr)\nexport const writeStdout: (arg1: string | Uint8Array) => Promise<void> =\n promisify(process.stdout.write).bind(process.stdout)\n\n// From:\n// https://github.com/yarnpkg/yarn/blob/53d8004229f543f342833310d5af63a4b6e59c8a/src/reporters/console/util.js\nexport async function clearLine(\n terminal: (typeof process)['stderr']\n): Promise<void> {\n if (!terminal.hasColors?.()) {\n if (terminal.isTTY) {\n // terminal\n if (terminal.columns > 0) {\n await writeStderr(`\\r${' '.repeat(terminal.columns - 1)}`)\n }\n await writeStderr(`\\r`)\n }\n // ignore piping to file\n } else {\n nativeClearLine(terminal, CLEAR_WHOLE_LINE)\n nativeCursorTo(terminal, 0, undefined)\n }\n}\n\ntype LogLevel = 'debug' | 'warn' | 'error'\n\nconst LEVEL_COLORS: Record<LogLevel, 'green' | 'yellow' | 'red'> = {\n debug: 'green',\n warn: 'yellow',\n error: 'red',\n}\n\nfunction label(level: LogLevel, message: string) {\n return `[@formatjs/cli] [${styleText(\n LEVEL_COLORS[level],\n level.toUpperCase()\n )}] ${message}`\n}\n\nexport async function debug(message: string, ...args: any[]): Promise<void> {\n if (process.env.LOG_LEVEL !== 'debug') {\n return\n }\n await clearLine(process.stderr)\n await writeStderr(format(label('debug', message), ...args))\n await writeStderr('\\n')\n}\n\nexport async function warn(message: string, ...args: any[]): Promise<void> {\n await clearLine(process.stderr)\n await writeStderr(format(label('warn', message), ...args))\n await writeStderr('\\n')\n}\n\nexport function getStdinAsString(): Promise<string> {\n let result = ''\n return new Promise(resolve => {\n process.stdin.setEncoding('utf-8')\n process.stdin.on('readable', () => {\n let chunk\n while ((chunk = process.stdin.read())) {\n result += chunk\n }\n })\n process.stdin.on('end', () => {\n resolve(result)\n })\n })\n}\n","import {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport type CrowdinJson = Record<\n string,\n {\n message: string\n description?: string\n }\n>\n\nexport const format: FormatFn<CrowdinJson> = msgs => {\n const results: CrowdinJson = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = {\n message: msg.defaultMessage!,\n description:\n typeof msg.description === 'string'\n ? msg.description\n : JSON.stringify(msg.description),\n }\n }\n return results\n}\n\nexport const compile: CompileFn<CrowdinJson> = msgs => {\n const results: Record<string, string> = {}\n for (const [id, msg] of Object.entries(msgs)) {\n if (id === 'smartling') {\n continue\n }\n results[id] = msg.message\n }\n return results\n}\n","import {type MessageDescriptor} from '#packages/cli-lib/types.js'\nexport type FormatFn<T = Record<string, MessageDescriptor>> = (\n msgs: Record<string, MessageDescriptor>\n) => T\n\nexport type CompileFn<T = Record<string, MessageDescriptor>> = (\n msgs: T\n) => Record<string, string>\n\nexport type SerializeFn<T = Record<string, MessageDescriptor>> = (\n msgs: T\n) => string\n\nexport const format: FormatFn = msgs => msgs\n\nexport const compile: CompileFn = msgs => {\n const results: Record<string, string> = {}\n for (const k in msgs) {\n results[k] = msgs[k].defaultMessage!\n }\n return results\n}\n","import {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport type StructuredJson = Record<\n string,\n {\n translation: string\n notes?: string\n context?: string\n limit?: string\n }\n>\n\nexport const format: FormatFn<StructuredJson> = msgs => {\n const results: StructuredJson = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = {\n translation: msg.defaultMessage!,\n notes:\n typeof msg.description === 'string'\n ? msg.description\n : JSON.stringify(msg.description),\n }\n }\n return results\n}\n\nexport const compile: CompileFn<StructuredJson> = msgs => {\n const results: Record<string, string> = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = msg.translation\n }\n return results\n}\n","import {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport type PhraseJson = Record<string, string>\n\nexport const format: FormatFn<PhraseJson> = msgs => {\n return Object.keys(msgs).reduce((all: PhraseJson, k) => {\n all[k] = msgs[k].defaultMessage!\n return all\n }, {})\n}\n\nexport const compile: CompileFn<PhraseJson> = msgs => msgs\n","import type {Comparator} from 'json-stable-stringify'\nimport {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport interface SmartlingDirectives {\n translate_paths: [\n {\n path: string\n key: string\n instruction: string\n },\n ]\n variants_enabled: boolean\n string_format: string\n [k: string]: any\n}\n\nexport type SmartlingJson = {\n smartling: SmartlingDirectives\n} & Record<\n string,\n {\n message: string\n description?: string\n }\n>\n\nexport const format: FormatFn<SmartlingJson> = msgs => {\n const results: SmartlingJson = {\n smartling: {\n translate_paths: [\n {\n path: '*/message',\n key: '{*}/message',\n instruction: '*/description',\n },\n ],\n variants_enabled: true,\n string_format: 'icu',\n },\n } as any\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = {\n message: msg.defaultMessage!,\n description:\n typeof msg.description === 'string'\n ? msg.description\n : JSON.stringify(msg.description),\n }\n }\n return results\n}\n\nexport const compareMessages: Comparator = (el1, el2) => {\n // `smartling` has to be the 1st key\n if (el1.key === 'smartling') {\n return -1\n }\n if (el2.key === 'smartling') {\n return 1\n }\n return el1.key < el2.key ? -1 : el1.key === el2.key ? 0 : 1\n}\n\nexport const compile: CompileFn<SmartlingJson> = msgs => {\n const results: Record<string, string> = {}\n for (const [id, msg] of Object.entries(msgs)) {\n if (id === 'smartling') {\n continue\n }\n results[id] = msg.message\n }\n return results\n}\n","import {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport type StructuredJson = Record<\n string,\n {\n string: string\n developer_comment?: string\n context?: string\n character_limit?: string\n }\n>\n\nexport const format: FormatFn<StructuredJson> = msgs => {\n const results: StructuredJson = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = {\n string: msg.defaultMessage!,\n developer_comment:\n typeof msg.description === 'string'\n ? msg.description\n : JSON.stringify(msg.description),\n }\n }\n return results\n}\n\nexport const compile: CompileFn<StructuredJson> = msgs => {\n const results: Record<string, string> = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = msg.string\n }\n return results\n}\n","import type {Comparator} from 'json-stable-stringify'\nimport {resolve} from 'path'\nimport {pathToFileURL} from 'url'\nimport * as crowdin from '#packages/cli-lib/formatters/crowdin.js'\nimport * as defaultFormatter from '#packages/cli-lib/formatters/default.js'\nimport {\n type CompileFn,\n type FormatFn,\n type SerializeFn,\n} from '#packages/cli-lib/formatters/default.js'\nimport * as lokalise from '#packages/cli-lib/formatters/lokalise.js'\nimport * as simple from '#packages/cli-lib/formatters/simple.js'\nimport * as smartling from '#packages/cli-lib/formatters/smartling.js'\nimport * as transifex from '#packages/cli-lib/formatters/transifex.js'\n\nexport interface Formatter<T> {\n serialize?: SerializeFn<T>\n format: FormatFn<T>\n compile: CompileFn<T>\n compareMessages?: Comparator\n}\n\nexport async function resolveBuiltinFormatter(\n format?: string | Formatter<unknown>\n): Promise<any> {\n if (!format) {\n return defaultFormatter\n }\n if (typeof format !== 'string') {\n return format\n }\n switch (format) {\n case 'transifex':\n return transifex\n case 'smartling':\n return smartling\n case 'simple':\n return simple\n case 'lokalise':\n return lokalise\n case 'crowdin':\n return crowdin\n }\n try {\n // eslint-disable-next-line import/dynamic-import-chunkname\n return import(pathToFileURL(resolve(process.cwd(), format)).href)\n } catch (e) {\n console.error(`Cannot resolve formatter ${format}`)\n throw e\n }\n}\n","import {createRequire} from 'module'\nimport {Runfiles} from '@bazel/runfiles'\nimport type {\n EvaluationSpan,\n EvaluatedString,\n} from '#packages/cli-lib/static-evaluation.js'\n\nconst require = createRequire(import.meta.url)\n\nconst NATIVE_PACKAGES: Record<string, string[]> = {\n 'darwin-arm64': ['@formatjs/cli-native-darwin-arm64'],\n 'linux-arm64': [\n '@formatjs/cli-native-linux-arm64',\n '@formatjs/cli-native-linux-arm64-musl',\n ],\n 'linux-x64': [\n '@formatjs/cli-native-linux-x64',\n '@formatjs/cli-native-linux-x64-musl',\n ],\n 'win32-x64': ['@formatjs/cli-native-win32-x64'],\n}\n\nexport interface NativeCompileOptions {\n ast?: boolean\n format?: string\n ignoreTag?: boolean\n pseudoLocale?: string\n skipErrors?: boolean\n followLinks?: boolean\n}\n\nexport interface NativeCompileMessage {\n id: string\n message: string\n sourceFile: string\n}\n\nexport interface NativeExtractOptions {\n additionalComponentNames?: string[]\n additionalFunctionNames?: string[]\n extractSourceLocation?: boolean\n flatten?: boolean\n followLinks?: boolean\n format?: string\n idInterpolationPattern?: string\n ignore?: string[]\n inFile?: string\n pragma?: string\n preserveWhitespace?: boolean\n throws?: boolean\n}\n\nexport interface NativeExtractSourceInput {\n filename: string\n source: string\n}\n\nexport interface NativeMessageDescriptor {\n id?: string\n defaultMessage?: string\n description?: string | object\n file?: string\n start?: number\n end?: number\n}\n\nexport interface NativeExtractSourceResult {\n filename: string\n messages: NativeMessageDescriptor[]\n meta?: Record<string, string>\n errors?: string[]\n}\n\nexport interface NativeExtractSourcesResult {\n files: NativeExtractSourceResult[]\n warnings?: string[]\n}\n\nexport interface NativeBinding {\n evaluateStrings(\n source: string,\n filename: string,\n spans: EvaluationSpan[]\n ): EvaluatedString[]\n compile(inputFiles: string[], opts?: NativeCompileOptions): string\n compileMessages(\n messages: NativeCompileMessage[],\n opts?: NativeCompileOptions\n ): string\n extract(inputFiles: string[], opts?: NativeExtractOptions): string\n extractSources(\n sources: NativeExtractSourceInput[],\n opts?: NativeExtractOptions,\n generateIds?: boolean\n ): string\n generateId(\n pattern: string,\n defaultMessage?: string,\n descriptionJson?: string,\n filename?: string\n ): string\n supportedBuiltinFormatters(): string[]\n}\n\nlet nativeBinding: NativeBinding | null | undefined\n\nexport function getInstalledNativePackageCandidates(\n candidates: readonly string[],\n canResolve = (candidate: string): boolean => {\n try {\n require.resolve(candidate)\n return true\n } catch {\n return false\n }\n }\n): string[] {\n return candidates.filter(canResolve)\n}\n\nexport function getNativePackageCandidates(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch\n): string[] {\n const platformArch = `${platform}-${arch}`\n return NATIVE_PACKAGES[platformArch] || []\n}\n\nexport function loadNative(): NativeBinding {\n if (nativeBinding !== undefined) {\n if (nativeBinding) {\n return nativeBinding\n }\n throw new Error('Native @formatjs/cli-lib binding is unavailable')\n }\n\n let runfilesPath: string | undefined\n if (\n process.env.RUNFILES_DIR ||\n process.env.RUNFILES_MANIFEST_FILE ||\n process.env.RUNFILES\n ) {\n try {\n runfilesPath = new Runfiles().resolveWorkspaceRelative(\n 'packages/cli-lib/formatjs_cli_napi.node'\n )\n } catch {\n // Published packages use platform-specific npm packages.\n }\n }\n const packageCandidates = getNativePackageCandidates()\n const installedPackageCandidates =\n getInstalledNativePackageCandidates(packageCandidates)\n const candidates = [\n runfilesPath,\n ...(installedPackageCandidates.length\n ? installedPackageCandidates\n : packageCandidates),\n ].filter(Boolean) as string[]\n const loadErrors: string[] = []\n\n for (const candidate of candidates) {\n try {\n nativeBinding = require(candidate) as NativeBinding\n return nativeBinding\n } catch (e) {\n loadErrors.push(`${candidate}: ${(e as Error).message}`)\n }\n }\n\n nativeBinding = null\n throw new Error(\n `Native @formatjs/cli-lib binding is unavailable.\\n${loadErrors.join('\\n')}`\n )\n}\n\nexport function compileWithNative(\n inputFiles: string[],\n opts: NativeCompileOptions = {}\n): string {\n const native = loadNative()\n return native.compile(inputFiles, {\n ast: opts.ast,\n format: opts.format,\n followLinks: opts.followLinks,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n}\n\nexport function compileMessagesWithNative(\n messages: NativeCompileMessage[],\n opts: NativeCompileOptions = {}\n): string {\n const native = loadNative()\n return native.compileMessages(messages, {\n ast: opts.ast,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n}\n\nexport function extractSourcesWithNative(\n sources: NativeExtractSourceInput[],\n opts: NativeExtractOptions = {},\n generateIds = true\n): NativeExtractSourcesResult {\n const native = loadNative()\n return JSON.parse(native.extractSources(sources, opts, generateIds))\n}\n\nexport function generateIdWithNative(\n pattern: string,\n defaultMessage?: string,\n description?: string | object,\n filename?: string\n): string {\n return loadNative().generateId(\n pattern,\n defaultMessage,\n description === undefined ? undefined : JSON.stringify(description),\n filename\n )\n}\n","import {outputFile} from 'fs-extra/esm'\nimport {\n debug,\n getStdinAsString,\n warn,\n writeStdout,\n} from '#packages/cli-lib/console_utils.js'\nimport * as stringifyNs from 'json-stable-stringify'\nimport {extname} from 'path'\nimport {availableParallelism} from 'os'\n\nimport {\n type Formatter,\n resolveBuiltinFormatter,\n} from '#packages/cli-lib/formatters/index.js'\nimport {\n extractSourcesWithNative,\n generateIdWithNative,\n type NativeMessageDescriptor,\n} from '#packages/cli-lib/native.js'\nimport {\n type ExtractTransformOptions,\n type MessageDescriptor,\n} from '#packages/cli-lib/types.js'\nimport {readFile} from 'fs/promises'\n\nconst stringify = (stringifyNs as any).default || stringifyNs\nconst DEFAULT_ID_INTERPOLATION_PATTERN = '[sha1:contenthash:base64:6]'\nexport interface ExtractionResult<M = Record<string, string>> {\n /**\n * List of extracted messages\n */\n messages: MessageDescriptor[]\n /**\n * Metadata extracted w/ `pragma`\n */\n meta?: M\n}\n\nexport interface ExtractedMessageDescriptor extends MessageDescriptor {\n /**\n * Line number\n */\n line?: number\n /**\n * Column number\n */\n col?: number\n /**\n * Metadata extracted from pragma\n */\n meta?: Record<string, string>\n}\n\nexport type ExtractCLIOptions = Omit<\n ExtractOpts,\n 'overrideIdFn' | 'onMsgExtracted' | 'onMetaExtracted'\n> & {\n /**\n * Output File\n */\n outFile?: string\n /**\n * Input File\n */\n inFile?: string\n /**\n * Ignore file glob pattern\n */\n ignore?: string[]\n /**\n * Whether to follow symbolic links when traversing directories.\n * Defaults to true for compatibility with pnpm symlinked node_modules.\n */\n followLinks?: boolean\n}\n\nexport type ExtractOpts = ExtractTransformOptions & {\n /**\n * Whether to throw an error if we had any issues with\n * 1 of the source files\n */\n throws?: boolean\n /**\n * Message ID interpolation pattern\n */\n idInterpolationPattern?: string\n /**\n * Whether we read from stdin instead of a file\n */\n readFromStdin?: boolean\n /**\n * Either path to a formatter file that controls the shape of JSON file from `outFile` or {@link Formatter} object.\n */\n format?: string | Formatter<any>\n /**\n * Whether to hoist selectors & flatten sentences\n */\n flatten?: boolean\n /**\n * An AbortSignal to cancel the extraction\n */\n signal?: AbortSignal\n}\n\nfunction byteOffsetToStringOffset(text: string, offset: number): number {\n return Buffer.from(text).subarray(0, offset).toString().length\n}\n\nfunction calculateLineColFromOffset(\n text: string,\n start?: number\n): Pick<ExtractedMessageDescriptor, 'line' | 'col'> {\n if (!start) {\n return {line: 1, col: 1}\n }\n const chunk = text.slice(0, start)\n const lines = chunk.split('\\n')\n const lastLine = lines[lines.length - 1]\n return {line: lines.length, col: lastLine.length}\n}\n\nfunction nativeScriptFilename(filename: string): string {\n const extension = extname(filename).toLowerCase()\n if (\n [\n '.cjs',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.mts',\n '.rs',\n '.ts',\n '.tsx',\n ].includes(extension)\n ) {\n return filename\n }\n return `${filename}.tsx`\n}\n\nfunction applyOverrideId(\n message: NativeMessageDescriptor,\n filename: string,\n overrideIdFn: ExtractTransformOptions['overrideIdFn']\n): MessageDescriptor {\n const id =\n typeof overrideIdFn === 'function'\n ? overrideIdFn(\n message.id,\n message.defaultMessage,\n message.description,\n filename\n )\n : message.id\n return {...message, id: id || ''}\n}\n\nasync function processFile(source: string, fn: string, opts: ExtractOpts) {\n let messages: ExtractedMessageDescriptor[] = []\n let meta: Record<string, string> | undefined\n const idInterpolationPattern =\n typeof opts.overrideIdFn === 'string'\n ? opts.overrideIdFn\n : opts.idInterpolationPattern || DEFAULT_ID_INTERPOLATION_PATTERN\n\n debug('Processing opts for %s: %s', fn, opts)\n\n const collectMessages = (\n filePath: string,\n extracted: MessageDescriptor[]\n ) => {\n messages = messages.concat(extracted)\n opts.onMsgExtracted?.(filePath, extracted)\n }\n const scriptParseFn = (\n scriptSource: string,\n sourceOffset = 0,\n wrapperOffset = 0\n ): void => {\n const result = extractSourcesWithNative(\n [{filename: nativeScriptFilename(fn), source: scriptSource}],\n {\n additionalComponentNames: [\n '$formatMessage',\n ...(opts.additionalComponentNames || []),\n ],\n additionalFunctionNames: opts.additionalFunctionNames,\n extractSourceLocation: opts.extractSourceLocation,\n idInterpolationPattern,\n pragma: opts.pragma,\n preserveWhitespace: opts.preserveWhitespace,\n flatten: opts.flatten,\n throws: opts.throws,\n },\n typeof opts.overrideIdFn !== 'function'\n )\n const file = result.files[0]\n if (!file) return\n if (file.meta) {\n meta = {...meta, ...file.meta}\n }\n for (const error of file.errors || []) {\n opts.onMsgError?.(fn, new Error(error))\n }\n let extracted = file.messages.map(message =>\n applyOverrideId(message, fn, opts.overrideIdFn)\n )\n if (opts.extractSourceLocation) {\n extracted = extracted.map(message => {\n const start =\n message.start === undefined\n ? undefined\n : sourceOffset +\n Math.max(\n 0,\n byteOffsetToStringOffset(scriptSource, message.start) -\n wrapperOffset\n )\n const end =\n message.end === undefined\n ? undefined\n : sourceOffset +\n Math.max(\n 0,\n byteOffsetToStringOffset(scriptSource, message.end) -\n wrapperOffset\n )\n return {\n ...message,\n file: fn,\n start,\n end,\n ...calculateLineColFromOffset(source, start),\n }\n })\n }\n collectMessages(fn, extracted)\n }\n const hbsOptions: ExtractTransformOptions = {\n ...opts,\n overrideIdFn:\n typeof opts.overrideIdFn === 'function'\n ? opts.overrideIdFn\n : (id, defaultMessage, description, filename) =>\n id ||\n generateIdWithNative(\n idInterpolationPattern,\n defaultMessage,\n description,\n filename\n ),\n onMsgExtracted: collectMessages,\n onMetaExtracted(_filePath, extractedMeta) {\n meta = {...meta, ...extractedMeta}\n },\n }\n if (fn.endsWith('.vue')) {\n debug('Processing %s using vue extractor', fn)\n const {parseFile} = await import('./vue_extractor.js')\n parseFile(source, fn, scriptParseFn)\n } else if (fn.endsWith('.svelte')) {\n debug('Processing %s using svelte extractor', fn)\n const {parseFile} = await import('./svelte_extractor.js')\n parseFile(source, fn, scriptParseFn)\n } else if (fn.endsWith('.hbs')) {\n debug('Processing %s using hbs extractor', fn)\n const {parseFile} = await import('./hbs_extractor.js')\n parseFile(source, fn, hbsOptions)\n } else if (fn.endsWith('.gts') || fn.endsWith('.gjs')) {\n debug('Processing %s as gts/gjs file', fn)\n const {parseFile} = await import('./gts_extractor.js')\n parseFile(source, fn, hbsOptions, scriptParseFn)\n } else {\n debug('Processing %s using native extractor', fn)\n scriptParseFn(source)\n }\n debug('Done extracting %s messages: %s', fn, messages)\n if (meta) {\n debug('Extracted meta:', meta)\n messages.forEach(m => (m.meta = meta))\n opts.onMetaExtracted?.(fn, meta)\n }\n return {messages, meta}\n}\n\n// Match Rayon's default worker count and explicit thread override.\nfunction fileReadConcurrency(): number {\n const value = process.env.RAYON_NUM_THREADS || ''\n const threads = /^\\+?\\d+$/.test(value) ? Number(value) : 0\n return Number.isSafeInteger(threads) && threads > 0\n ? threads\n : availableParallelism()\n}\n\nasync function mapWithConcurrencyLimit<T, R>(\n items: readonly T[],\n limit: number,\n task: (item: T) => Promise<R>\n): Promise<R[]> {\n const results: R[] = []\n let nextIndex = 0\n let failed = false\n async function worker(): Promise<void> {\n while (!failed && nextIndex < items.length) {\n const index = nextIndex++\n try {\n results[index] = await task(items[index])\n } catch (error) {\n failed = true\n throw error\n }\n }\n }\n await Promise.all(\n Array.from({length: Math.min(limit, items.length)}, () => worker())\n )\n return results\n}\n\n/**\n * Extract strings from source files\n * @param files list of files\n * @param extractOpts extract options\n * @returns messages serialized as JSON string since key order\n * matters for some `format`\n */\nexport async function extract(\n files: readonly string[],\n extractOpts: ExtractOpts\n): Promise<string> {\n const {throws, readFromStdin, signal, ...opts} = extractOpts\n // Message errors may be skipped; input read failures are always fatal.\n const shouldThrow = throws === true\n // Pass throws option to transformer for per-message error handling\n const optsWithThrows = {\n ...opts,\n idInterpolationPattern:\n opts.idInterpolationPattern || DEFAULT_ID_INTERPOLATION_PATTERN,\n throws: shouldThrow,\n onMsgError: !shouldThrow\n ? opts.onMsgError || ((_: string, e: Error) => warn(e.message))\n : undefined,\n }\n\n async function processSource(source: string, filename: string) {\n try {\n return await processFile(source, filename, optsWithThrows)\n } catch (error) {\n if (shouldThrow) throw error\n warn(String(error))\n return undefined\n }\n }\n\n let rawResults: Array<ExtractionResult | undefined>\n if (readFromStdin) {\n debug('Reading input from stdin')\n if (process.stdin.isTTY) {\n warn('Reading source file from TTY.')\n }\n const source = await getStdinAsString()\n rawResults = [await processSource(source, 'dummy.ts')]\n } else {\n rawResults = await mapWithConcurrencyLimit(\n files,\n fileReadConcurrency(),\n async filename => {\n debug('Extracting file:', filename)\n const source = await readFile(filename, {encoding: 'utf8', signal})\n return processSource(source, filename)\n }\n )\n }\n\n const formatter: Formatter<unknown> = await resolveBuiltinFormatter(\n opts.format\n )\n const extractionResults = rawResults.filter((r): r is ExtractionResult => !!r)\n\n const extractedMessages = new Map<string, MessageDescriptor>()\n\n for (const {messages} of extractionResults) {\n for (const message of messages) {\n const {id, description, defaultMessage} = message\n if (!id) {\n const error = new Error(\n `[FormatJS CLI] Missing message id for message:\n${JSON.stringify(message, undefined, 2)}`\n )\n if (throws) {\n throw error\n } else {\n warn(error.message)\n }\n continue\n }\n\n if (extractedMessages.has(id)) {\n const existing = extractedMessages.get(id)!\n if (\n stringify(description) !== stringify(existing.description) ||\n defaultMessage !== existing.defaultMessage\n ) {\n const error = new Error(\n `[FormatJS CLI] Duplicate message id: \"${id}\", ` +\n 'but the `description` and/or `defaultMessage` are different.'\n )\n if (throws) {\n throw error\n } else {\n warn(error.message)\n }\n }\n }\n extractedMessages.set(id, message)\n }\n }\n const results: Record<string, Omit<MessageDescriptor, 'id'>> = {}\n const messages = Array.from(extractedMessages.values())\n for (const {id, ...msg} of messages) {\n // GH #3537: flatten is now applied during extraction in the babel plugin,\n // so we don't need to apply it again here. The messages are already flattened.\n results[id] = msg\n }\n if (typeof formatter.serialize === 'function') {\n return formatter.serialize(formatter.format(results as any))\n }\n return (\n stringify(formatter.format(results as any), {\n space: 2,\n cmp: formatter.compareMessages || undefined,\n }) ?? ''\n )\n}\n\n/**\n * Extract strings from source files, also writes to a file.\n * @param files list of files\n * @param extractOpts extract options\n * @returns A Promise that resolves if output file was written successfully\n */\nexport default async function extractAndWrite(\n files: readonly string[],\n extractOpts: ExtractCLIOptions\n): Promise<void> {\n const {outFile, ...opts} = extractOpts\n const serializedResult = (await extract(files, opts)) + '\\n'\n if (outFile) {\n debug('Writing output file:', outFile)\n return outputFile(outFile, serializedResult)\n }\n await writeStdout(serializedResult)\n}\n","import {outputFile} from 'fs-extra/esm'\nimport {readFile} from 'fs/promises'\nimport glob from 'fast-glob'\nimport * as stringifyNs from 'json-stable-stringify'\nimport {resolve} from 'path'\nimport {pathToFileURL} from 'url'\nimport {debug, warn, writeStdout} from '#packages/cli-lib/console_utils.js'\nimport {type Formatter} from '#packages/cli-lib/formatters/index.js'\nimport {\n type NativeCompileMessage,\n compileMessagesWithNative,\n compileWithNative,\n} from '#packages/cli-lib/native.js'\n\nconst dynamicImport = new Function('specifier', 'return import(specifier)') as (\n specifier: string\n) => Promise<Formatter<unknown>>\nconst globSync = glob.sync\nconst stringify = (stringifyNs as any).default || stringifyNs\nconst CUSTOM_FORMATTER_FILE_DEPRECATION_WARNING =\n '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.'\n\nconst BUILTIN_FORMATTERS = new Set([\n 'default',\n 'simple',\n 'transifex',\n 'smartling',\n 'lokalise',\n 'crowdin',\n])\n\nexport type PseudoLocale = 'xx-LS' | 'xx-AC' | 'xx-HA' | 'en-XA' | 'en-XB'\n\nexport interface CompileCLIOpts extends Opts {\n /**\n * The target file that contains compiled messages.\n */\n outFile?: string\n}\n\nexport interface Opts {\n /**\n * Whether to compile message into AST instead of just string\n */\n ast?: boolean\n /**\n * Whether to continue compiling messages after encountering an error.\n * Any keys with errors will not be included in the output file.\n */\n skipErrors?: boolean\n /**\n * Built-in formatter name or path to a formatter file that converts\n * <translation_files> to `Record<string, string>` so we can compile.\n * Formatter file paths are deprecated for compilation.\n */\n format?: string | Formatter<unknown>\n /**\n * Whether to compile to pseudo locale\n */\n pseudoLocale?: PseudoLocale\n /**\n * Whether the parser to treat HTML/XML tags as string literal\n * instead of parsing them as tag token.\n * When this is false we only allow simple tags without\n * any attributes\n */\n ignoreTag?: boolean\n /**\n * An AbortSignal to cancel the compilation before invoking native code.\n */\n signal?: AbortSignal\n /**\n * Whether to follow symbolic links when traversing directories.\n * Defaults to true for compatibility with pnpm symlinked node_modules.\n */\n followLinks?: boolean\n}\n\n/**\n * Compile extracted translation files with the native formatjs CLI binding.\n * @param inputFiles Input files or glob patterns\n * @param opts Options\n * @returns serialized result in string format\n */\nexport async function compile(\n inputFiles: string[],\n opts: Opts = {}\n): Promise<string> {\n debug('Compiling files:', inputFiles)\n const {\n ast,\n format,\n pseudoLocale,\n skipErrors,\n ignoreTag,\n signal,\n followLinks,\n } = opts\n signal?.throwIfAborted()\n\n if (format && !isBuiltinFormatter(format)) {\n return compileWithCustomFormatter(inputFiles, opts)\n }\n\n return compileWithNative(inputFiles, {\n ast,\n format: typeof format === 'string' ? format : undefined,\n followLinks,\n ignoreTag,\n pseudoLocale,\n skipErrors,\n })\n}\n\nfunction isBuiltinFormatter(\n format: string | Formatter<unknown>\n): format is string {\n return typeof format === 'string' && BUILTIN_FORMATTERS.has(format)\n}\n\nasync function compileWithCustomFormatter(\n inputFiles: string[],\n opts: Opts\n): Promise<string> {\n if (typeof opts.format === 'string') {\n await warn(CUSTOM_FORMATTER_FILE_DEPRECATION_WARNING)\n }\n\n const formatter = await resolveCustomFormatter(opts.format)\n const files = globSync(inputFiles, {\n followSymbolicLinks: opts.followLinks ?? true,\n })\n\n if (!files.length) {\n throw new Error('No translation files found matching the patterns')\n }\n\n const messages: NativeCompileMessage[] = []\n await Promise.all(\n files.map(async file => {\n opts.signal?.throwIfAborted()\n const content = await readFile(file, {\n encoding: 'utf8',\n signal: opts.signal,\n })\n const compiled = formatter.compile(JSON.parse(content))\n for (const id of Object.keys(compiled)) {\n messages.push({\n id,\n message: compiled[id],\n sourceFile: file,\n })\n }\n })\n )\n\n const serialized = compileMessagesWithNative(messages, {\n ast: opts.ast,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n\n if (formatter.compareMessages) {\n return (\n stringify(JSON.parse(serialized), {\n space: 2,\n cmp: formatter.compareMessages,\n }) ?? ''\n )\n }\n\n return serialized\n}\n\nasync function resolveCustomFormatter(\n format: string | Formatter<unknown> | undefined\n): Promise<Formatter<unknown>> {\n if (!format) {\n throw new Error('A custom formatter is required')\n }\n if (typeof format !== 'string') {\n return format\n }\n try {\n return dynamicImport(pathToFileURL(resolve(process.cwd(), format)).href)\n } catch (e) {\n console.error(`Cannot resolve formatter ${format}`)\n throw e\n }\n}\n\n/**\n * Compile extracted translation files with the native formatjs CLI binding and\n * write output to `outFile` when provided.\n * @param inputFiles Input files or glob patterns\n * @param compileOpts options\n * @returns A `Promise` that resolves if file was written successfully\n */\nexport default async function compileAndWrite(\n inputFiles: string[],\n compileOpts: CompileCLIOpts = {}\n): Promise<void> {\n const {outFile, ...opts} = compileOpts\n const serializedResult = (await compile(inputFiles, opts)) + '\\n'\n if (outFile) {\n debug('Writing output file:', outFile)\n return outputFile(outFile, serializedResult)\n }\n await writeStdout(serializedResult)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,mBAAmB;AAEzB,MAAa,cACX,UAAU,QAAQ,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ,MAAM;AACrD,MAAa,cACX,UAAU,QAAQ,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ,MAAM;AAIrD,eAAsBA,YACpB,UACe;CACf,IAAI,CAAC,SAAS,YAAY,GACpB;MAAA,SAAS,OAAO;GAElB,IAAI,SAAS,UAAU,GACrB,MAAM,YAAY,KAAK,IAAI,OAAO,SAAS,UAAU,CAAC,GAAG;GAE3D,MAAM,YAAY,IAAI;EACxB;QAEK;EACL,UAAgB,UAAU,gBAAgB;EAC1C,SAAe,UAAU,GAAG,KAAA,CAAS;CACvC;AACF;AAIA,MAAM,eAA6D;CACjE,OAAO;CACP,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AAM,OAAO,CAAC;EACtD,KAAK,MAAM,MAAM,OAAO,KAAK,QAAQ,GACnC,SAAS,KAAK;GACZ;GACA,SAAS,SAAS;GAClB,YAAY;EACd,CAAC;CAEL,CAAC,CACH;CAEA,MAAM,aAAa,0BAA0B,UAAU;EACrD,KAAK,KAAK;EACV,WAAW,KAAK;EAChB,cAAc,KAAK;EACnB,YAAY,KAAK;CACnB,CAAC;CAED,IAAI,UAAU,iBACZ,OACE,UAAU,KAAK,MAAM,UAAU,GAAG;EAChC,OAAO;EACP,KAAK,UAAU;CACjB,CAAC,KAAK;CAIV,OAAO;AACT;AAEA,eAAe,uBACb,QAC6B;CAC7B,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,gCAAgC;CAElD,IAAI,OAAO,WAAW,UACpB,OAAO;CAET,IAAI;EACF,OAAO,cAAc,cAAc,QAAQ,QAAQ,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI;CACzE,SAAS,GAAG;EACV,QAAQ,MAAM,4BAA4B,QAAQ;EAClD,MAAM;CACR;AACF;;;;;;;;AASA,eAA8B,gBAC5B,YACA,cAA8B,CAAC,GAChB;CACf,MAAM,EAAC,SAAS,GAAG,SAAQ;CAC3B,MAAM,mBAAoB,MAAM,QAAQ,YAAY,IAAI,IAAK;CAC7D,IAAI,SAAS;EACX,MAAM,wBAAwB,OAAO;EACrC,OAAO,WAAW,SAAS,gBAAgB;CAC7C;CACA,MAAM,YAAY,gBAAgB;AACpC"}
1
+ {"version":3,"file":"index.js","names":["clearLine","format","compile","format","compile","format","compile","format","compile","format","compile","format","compile","defaultFormatter","transifex","smartling","simple","lokalise","crowdin","require","stringify"],"sources":["sources/packages/cli-lib/console_utils.ts","sources/packages/cli-lib/formatters/crowdin.ts","sources/packages/cli-lib/formatters/default.ts","sources/packages/cli-lib/formatters/lokalise.ts","sources/packages/cli-lib/formatters/simple.ts","sources/packages/cli-lib/formatters/smartling.ts","sources/packages/cli-lib/formatters/transifex.ts","sources/packages/cli-lib/formatters/index.ts","sources/packages/cli-lib/native.ts","sources/packages/cli-lib/extract.ts","sources/packages/cli-lib/compile.ts"],"sourcesContent":["import {\n clearLine as nativeClearLine,\n cursorTo as nativeCursorTo,\n} from 'readline'\nimport {format, promisify, styleText} from 'node:util'\n\nconst CLEAR_WHOLE_LINE = 0\n\nexport const writeStderr: (arg1: string | Uint8Array) => Promise<void> =\n promisify(process.stderr.write).bind(process.stderr)\nexport const writeStdout: (arg1: string | Uint8Array) => Promise<void> =\n promisify(process.stdout.write).bind(process.stdout)\n\n// From:\n// https://github.com/yarnpkg/yarn/blob/53d8004229f543f342833310d5af63a4b6e59c8a/src/reporters/console/util.js\nexport async function clearLine(\n terminal: (typeof process)['stderr']\n): Promise<void> {\n if (!terminal.hasColors?.()) {\n if (terminal.isTTY) {\n // terminal\n if (terminal.columns > 0) {\n await writeStderr(`\\r${' '.repeat(terminal.columns - 1)}`)\n }\n await writeStderr(`\\r`)\n }\n // ignore piping to file\n } else {\n nativeClearLine(terminal, CLEAR_WHOLE_LINE)\n nativeCursorTo(terminal, 0, undefined)\n }\n}\n\ntype LogLevel = 'debug' | 'warn' | 'error'\n\nconst LEVEL_COLORS: Record<LogLevel, 'green' | 'yellow' | 'red'> = {\n debug: 'green',\n warn: 'yellow',\n error: 'red',\n}\n\nfunction label(level: LogLevel, message: string) {\n return `[@formatjs/cli] [${styleText(\n LEVEL_COLORS[level],\n level.toUpperCase()\n )}] ${message}`\n}\n\nexport async function debug(message: string, ...args: any[]): Promise<void> {\n if (process.env.LOG_LEVEL !== 'debug') {\n return\n }\n await clearLine(process.stderr)\n await writeStderr(format(label('debug', message), ...args))\n await writeStderr('\\n')\n}\n\nexport async function warn(message: string, ...args: any[]): Promise<void> {\n await clearLine(process.stderr)\n await writeStderr(format(label('warn', message), ...args))\n await writeStderr('\\n')\n}\n\nexport function getStdinAsString(): Promise<string> {\n let result = ''\n return new Promise(resolve => {\n process.stdin.setEncoding('utf-8')\n process.stdin.on('readable', () => {\n let chunk\n while ((chunk = process.stdin.read())) {\n result += chunk\n }\n })\n process.stdin.on('end', () => {\n resolve(result)\n })\n })\n}\n","import {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport type CrowdinJson = Record<\n string,\n {\n message: string\n description?: string\n }\n>\n\nexport const format: FormatFn<CrowdinJson> = msgs => {\n const results: CrowdinJson = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = {\n message: msg.defaultMessage!,\n description:\n typeof msg.description === 'string'\n ? msg.description\n : JSON.stringify(msg.description),\n }\n }\n return results\n}\n\nexport const compile: CompileFn<CrowdinJson> = msgs => {\n const results: Record<string, string> = {}\n for (const [id, msg] of Object.entries(msgs)) {\n if (id === 'smartling') {\n continue\n }\n results[id] = msg.message\n }\n return results\n}\n","import {type MessageDescriptor} from '#packages/cli-lib/types.js'\nexport type FormatFn<T = Record<string, MessageDescriptor>> = (\n msgs: Record<string, MessageDescriptor>\n) => T\n\nexport type CompileFn<T = Record<string, MessageDescriptor>> = (\n msgs: T\n) => Record<string, string>\n\nexport type SerializeFn<T = Record<string, MessageDescriptor>> = (\n msgs: T\n) => string\n\nexport const format: FormatFn = msgs => msgs\n\nexport const compile: CompileFn = msgs => {\n const results: Record<string, string> = {}\n for (const k in msgs) {\n results[k] = msgs[k].defaultMessage!\n }\n return results\n}\n","import {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport type StructuredJson = Record<\n string,\n {\n translation: string\n notes?: string\n context?: string\n limit?: string\n }\n>\n\nexport const format: FormatFn<StructuredJson> = msgs => {\n const results: StructuredJson = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = {\n translation: msg.defaultMessage!,\n notes:\n typeof msg.description === 'string'\n ? msg.description\n : JSON.stringify(msg.description),\n }\n }\n return results\n}\n\nexport const compile: CompileFn<StructuredJson> = msgs => {\n const results: Record<string, string> = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = msg.translation\n }\n return results\n}\n","import {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport type PhraseJson = Record<string, string>\n\nexport const format: FormatFn<PhraseJson> = msgs => {\n return Object.keys(msgs).reduce((all: PhraseJson, k) => {\n all[k] = msgs[k].defaultMessage!\n return all\n }, {})\n}\n\nexport const compile: CompileFn<PhraseJson> = msgs => msgs\n","import type {Comparator} from 'json-stable-stringify'\nimport {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport interface SmartlingDirectives {\n translate_paths: [\n {\n path: string\n key: string\n instruction: string\n },\n ]\n variants_enabled: boolean\n string_format: string\n [k: string]: any\n}\n\nexport type SmartlingJson = {\n smartling: SmartlingDirectives\n} & Record<\n string,\n {\n message: string\n description?: string\n }\n>\n\nexport const format: FormatFn<SmartlingJson> = msgs => {\n const results: SmartlingJson = {\n smartling: {\n translate_paths: [\n {\n path: '*/message',\n key: '{*}/message',\n instruction: '*/description',\n },\n ],\n variants_enabled: true,\n string_format: 'icu',\n },\n } as any\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = {\n message: msg.defaultMessage!,\n description:\n typeof msg.description === 'string'\n ? msg.description\n : JSON.stringify(msg.description),\n }\n }\n return results\n}\n\nexport const compareMessages: Comparator = (el1, el2) => {\n // `smartling` has to be the 1st key\n if (el1.key === 'smartling') {\n return -1\n }\n if (el2.key === 'smartling') {\n return 1\n }\n return el1.key < el2.key ? -1 : el1.key === el2.key ? 0 : 1\n}\n\nexport const compile: CompileFn<SmartlingJson> = msgs => {\n const results: Record<string, string> = {}\n for (const [id, msg] of Object.entries(msgs)) {\n if (id === 'smartling') {\n continue\n }\n results[id] = msg.message\n }\n return results\n}\n","import {\n type CompileFn,\n type FormatFn,\n} from '#packages/cli-lib/formatters/default.js'\n\nexport type StructuredJson = Record<\n string,\n {\n string: string\n developer_comment?: string\n context?: string\n character_limit?: string\n }\n>\n\nexport const format: FormatFn<StructuredJson> = msgs => {\n const results: StructuredJson = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = {\n string: msg.defaultMessage!,\n developer_comment:\n typeof msg.description === 'string'\n ? msg.description\n : JSON.stringify(msg.description),\n }\n }\n return results\n}\n\nexport const compile: CompileFn<StructuredJson> = msgs => {\n const results: Record<string, string> = {}\n for (const [id, msg] of Object.entries(msgs)) {\n results[id] = msg.string\n }\n return results\n}\n","import type {Comparator} from 'json-stable-stringify'\nimport {resolve} from 'path'\nimport {pathToFileURL} from 'url'\nimport * as crowdin from '#packages/cli-lib/formatters/crowdin.js'\nimport * as defaultFormatter from '#packages/cli-lib/formatters/default.js'\nimport {\n type CompileFn,\n type FormatFn,\n type SerializeFn,\n} from '#packages/cli-lib/formatters/default.js'\nimport * as lokalise from '#packages/cli-lib/formatters/lokalise.js'\nimport * as simple from '#packages/cli-lib/formatters/simple.js'\nimport * as smartling from '#packages/cli-lib/formatters/smartling.js'\nimport * as transifex from '#packages/cli-lib/formatters/transifex.js'\n\nexport interface Formatter<T> {\n serialize?: SerializeFn<T>\n format: FormatFn<T>\n compile: CompileFn<T>\n compareMessages?: Comparator\n}\n\nexport async function resolveBuiltinFormatter(\n format?: string | Formatter<unknown>\n): Promise<any> {\n if (!format) {\n return defaultFormatter\n }\n if (typeof format !== 'string') {\n return format\n }\n switch (format) {\n case 'transifex':\n return transifex\n case 'smartling':\n return smartling\n case 'simple':\n return simple\n case 'lokalise':\n return lokalise\n case 'crowdin':\n return crowdin\n }\n try {\n // eslint-disable-next-line import/dynamic-import-chunkname\n return import(pathToFileURL(resolve(process.cwd(), format)).href)\n } catch (e) {\n console.error(`Cannot resolve formatter ${format}`)\n throw e\n }\n}\n","import {createRequire} from 'module'\nimport {Runfiles} from '@bazel/runfiles'\nimport type {\n EvaluationSpan,\n EvaluatedString,\n} from '#packages/cli-lib/static-evaluation.js'\n\nconst require = createRequire(import.meta.url)\n\nconst NATIVE_PACKAGES: Record<string, string[]> = {\n 'darwin-arm64': ['@formatjs/cli-native-darwin-arm64'],\n 'darwin-x64': ['@formatjs/cli-native-darwin-x64'],\n 'linux-arm64': [\n '@formatjs/cli-native-linux-arm64',\n '@formatjs/cli-native-linux-arm64-musl',\n ],\n 'linux-x64': [\n '@formatjs/cli-native-linux-x64',\n '@formatjs/cli-native-linux-x64-musl',\n ],\n 'win32-x64': ['@formatjs/cli-native-win32-x64'],\n 'win32-arm64': ['@formatjs/cli-native-win32-arm64'],\n}\n\nexport interface NativeCompileOptions {\n ast?: boolean\n format?: string\n ignoreTag?: boolean\n pseudoLocale?: string\n skipErrors?: boolean\n followLinks?: boolean\n}\n\nexport interface NativeCompileMessage {\n id: string\n message: string\n sourceFile: string\n}\n\nexport interface NativeExtractOptions {\n additionalComponentNames?: string[]\n additionalFunctionNames?: string[]\n extractSourceLocation?: boolean\n flatten?: boolean\n followLinks?: boolean\n format?: string\n idInterpolationPattern?: string\n ignore?: string[]\n inFile?: string\n pragma?: string\n preserveWhitespace?: boolean\n throws?: boolean\n}\n\nexport interface NativeExtractSourceInput {\n filename: string\n source: string\n}\n\nexport interface NativeMessageDescriptor {\n id?: string\n defaultMessage?: string\n description?: string | object\n file?: string\n start?: number\n end?: number\n}\n\nexport interface NativeExtractSourceResult {\n filename: string\n messages: NativeMessageDescriptor[]\n meta?: Record<string, string>\n errors?: string[]\n}\n\nexport interface NativeExtractSourcesResult {\n files: NativeExtractSourceResult[]\n warnings?: string[]\n}\n\nexport interface NativeBinding {\n evaluateStrings(\n source: string,\n filename: string,\n spans: EvaluationSpan[]\n ): EvaluatedString[]\n compile(inputFiles: string[], opts?: NativeCompileOptions): string\n compileMessages(\n messages: NativeCompileMessage[],\n opts?: NativeCompileOptions\n ): string\n extract(inputFiles: string[], opts?: NativeExtractOptions): string\n extractSources(\n sources: NativeExtractSourceInput[],\n opts?: NativeExtractOptions,\n generateIds?: boolean\n ): string\n generateId(\n pattern: string,\n defaultMessage?: string,\n descriptionJson?: string,\n filename?: string\n ): string\n verifyJavaPrintf(catalogsJson: string, sourceLocale: string): string\n verifyXcstrings(\n catalogsJson: string,\n sourceLocale: string | undefined,\n missingKeys: boolean,\n structuralEquality: boolean\n ): string\n supportedBuiltinFormatters(): string[]\n}\n\nlet nativeBinding: NativeBinding | null | undefined\n\nexport function getInstalledNativePackageCandidates(\n candidates: readonly string[],\n canResolve = (candidate: string): boolean => {\n try {\n require.resolve(candidate)\n return true\n } catch {\n return false\n }\n }\n): string[] {\n return candidates.filter(canResolve)\n}\n\nexport function getNativePackageCandidates(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch\n): string[] {\n const platformArch = `${platform}-${arch}`\n return NATIVE_PACKAGES[platformArch] || []\n}\n\nexport function loadNative(): NativeBinding {\n if (nativeBinding !== undefined) {\n if (nativeBinding) {\n return nativeBinding\n }\n throw new Error('Native @formatjs/cli-lib binding is unavailable')\n }\n\n let runfilesPath: string | undefined\n if (\n process.env.RUNFILES_DIR ||\n process.env.RUNFILES_MANIFEST_FILE ||\n process.env.RUNFILES\n ) {\n try {\n runfilesPath = new Runfiles().resolveWorkspaceRelative(\n 'packages/cli-lib/formatjs_cli_napi.node'\n )\n } catch {\n // Published packages use platform-specific npm packages.\n }\n }\n const packageCandidates = getNativePackageCandidates()\n const installedPackageCandidates =\n getInstalledNativePackageCandidates(packageCandidates)\n const candidates = [\n runfilesPath,\n ...(installedPackageCandidates.length\n ? installedPackageCandidates\n : packageCandidates),\n ].filter(Boolean) as string[]\n const loadErrors: string[] = []\n\n for (const candidate of candidates) {\n try {\n nativeBinding = require(candidate) as NativeBinding\n return nativeBinding\n } catch (e) {\n loadErrors.push(`${candidate}: ${(e as Error).message}`)\n }\n }\n\n nativeBinding = null\n throw new Error(\n `Native @formatjs/cli-lib binding is unavailable.\\n${loadErrors.join('\\n')}`\n )\n}\n\nexport function compileWithNative(\n inputFiles: string[],\n opts: NativeCompileOptions = {}\n): string {\n const native = loadNative()\n return native.compile(inputFiles, {\n ast: opts.ast,\n format: opts.format,\n followLinks: opts.followLinks,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n}\n\nexport function compileMessagesWithNative(\n messages: NativeCompileMessage[],\n opts: NativeCompileOptions = {}\n): string {\n const native = loadNative()\n return native.compileMessages(messages, {\n ast: opts.ast,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n}\n\nexport function extractSourcesWithNative(\n sources: NativeExtractSourceInput[],\n opts: NativeExtractOptions = {},\n generateIds = true\n): NativeExtractSourcesResult {\n const native = loadNative()\n return JSON.parse(native.extractSources(sources, opts, generateIds))\n}\n\nexport function generateIdWithNative(\n pattern: string,\n defaultMessage?: string,\n description?: string | object,\n filename?: string\n): string {\n return loadNative().generateId(\n pattern,\n defaultMessage,\n description === undefined ? undefined : JSON.stringify(description),\n filename\n )\n}\n\nexport interface NativeVerificationIssue {\n locale: string\n messageId: string\n error: string\n}\n\nexport function verifyJavaPrintfWithNative(\n catalogs: Record<string, unknown>,\n sourceLocale: string\n): NativeVerificationIssue[] {\n const native = loadNative()\n if (typeof native.verifyJavaPrintf !== 'function') {\n throw new Error(\n 'Installed FormatJS native package does not support Java printf verification; update @formatjs/cli and its native package.'\n )\n }\n return JSON.parse(\n native.verifyJavaPrintf(JSON.stringify(catalogs), sourceLocale)\n )\n}\n\nexport function verifyXcstringsWithNative(\n catalogs: Record<string, unknown>,\n sourceLocale: string | undefined,\n missingKeys: boolean,\n structuralEquality: boolean\n): NativeVerificationIssue[] {\n const native = loadNative()\n if (typeof native.verifyXcstrings !== 'function') {\n throw new Error(\n 'Installed FormatJS native package does not support xcstrings verification; update @formatjs/cli and its native package.'\n )\n }\n return JSON.parse(\n native.verifyXcstrings(\n JSON.stringify(catalogs),\n sourceLocale,\n missingKeys,\n structuralEquality\n )\n )\n}\n","import {outputFile} from 'fs-extra/esm'\nimport {\n debug,\n getStdinAsString,\n warn,\n writeStdout,\n} from '#packages/cli-lib/console_utils.js'\nimport * as stringifyNs from 'json-stable-stringify'\nimport {extname} from 'path'\nimport {availableParallelism} from 'os'\n\nimport {\n type Formatter,\n resolveBuiltinFormatter,\n} from '#packages/cli-lib/formatters/index.js'\nimport {\n extractSourcesWithNative,\n generateIdWithNative,\n type NativeMessageDescriptor,\n} from '#packages/cli-lib/native.js'\nimport {\n type ExtractTransformOptions,\n type MessageDescriptor,\n} from '#packages/cli-lib/types.js'\nimport {readFile} from 'fs/promises'\n\nconst stringify = (stringifyNs as any).default || stringifyNs\nconst DEFAULT_ID_INTERPOLATION_PATTERN = '[sha1:contenthash:base64:6]'\nexport interface ExtractionResult<M = Record<string, string>> {\n /**\n * List of extracted messages\n */\n messages: MessageDescriptor[]\n /**\n * Metadata extracted w/ `pragma`\n */\n meta?: M\n}\n\nexport interface ExtractedMessageDescriptor extends MessageDescriptor {\n /**\n * Line number\n */\n line?: number\n /**\n * Column number\n */\n col?: number\n /**\n * Metadata extracted from pragma\n */\n meta?: Record<string, string>\n}\n\nexport type ExtractCLIOptions = Omit<\n ExtractOpts,\n 'overrideIdFn' | 'onMsgExtracted' | 'onMetaExtracted'\n> & {\n /**\n * Output File\n */\n outFile?: string\n /**\n * Input File\n */\n inFile?: string\n /**\n * Ignore file glob pattern\n */\n ignore?: string[]\n /**\n * Whether to follow symbolic links when traversing directories.\n * Defaults to true for compatibility with pnpm symlinked node_modules.\n */\n followLinks?: boolean\n}\n\nexport type ExtractOpts = ExtractTransformOptions & {\n /**\n * Whether to throw an error if we had any issues with\n * 1 of the source files\n */\n throws?: boolean\n /**\n * Message ID interpolation pattern\n */\n idInterpolationPattern?: string\n /**\n * Whether we read from stdin instead of a file\n */\n readFromStdin?: boolean\n /**\n * Either path to a formatter file that controls the shape of JSON file from `outFile` or {@link Formatter} object.\n */\n format?: string | Formatter<any>\n /**\n * Whether to hoist selectors & flatten sentences\n */\n flatten?: boolean\n /**\n * An AbortSignal to cancel the extraction\n */\n signal?: AbortSignal\n}\n\nfunction byteOffsetToStringOffset(text: string, offset: number): number {\n return Buffer.from(text).subarray(0, offset).toString().length\n}\n\nfunction calculateLineColFromOffset(\n text: string,\n start?: number\n): Pick<ExtractedMessageDescriptor, 'line' | 'col'> {\n if (!start) {\n return {line: 1, col: 1}\n }\n const chunk = text.slice(0, start)\n const lines = chunk.split('\\n')\n const lastLine = lines[lines.length - 1]\n return {line: lines.length, col: lastLine.length}\n}\n\nfunction nativeScriptFilename(filename: string): string {\n const extension = extname(filename).toLowerCase()\n if (\n [\n '.cjs',\n '.cts',\n '.js',\n '.jsx',\n '.mjs',\n '.mts',\n '.rs',\n '.ts',\n '.tsx',\n ].includes(extension)\n ) {\n return filename\n }\n return `${filename}.tsx`\n}\n\nfunction applyOverrideId(\n message: NativeMessageDescriptor,\n filename: string,\n overrideIdFn: ExtractTransformOptions['overrideIdFn']\n): MessageDescriptor {\n const id =\n typeof overrideIdFn === 'function'\n ? overrideIdFn(\n message.id,\n message.defaultMessage,\n message.description,\n filename\n )\n : message.id\n return {...message, id: id || ''}\n}\n\nasync function processFile(source: string, fn: string, opts: ExtractOpts) {\n let messages: ExtractedMessageDescriptor[] = []\n let meta: Record<string, string> | undefined\n const idInterpolationPattern =\n typeof opts.overrideIdFn === 'string'\n ? opts.overrideIdFn\n : opts.idInterpolationPattern || DEFAULT_ID_INTERPOLATION_PATTERN\n\n debug('Processing opts for %s: %s', fn, opts)\n\n const collectMessages = (\n filePath: string,\n extracted: MessageDescriptor[]\n ) => {\n messages = messages.concat(extracted)\n opts.onMsgExtracted?.(filePath, extracted)\n }\n const scriptParseFn = (\n scriptSource: string,\n sourceOffset = 0,\n wrapperOffset = 0\n ): void => {\n const result = extractSourcesWithNative(\n [{filename: nativeScriptFilename(fn), source: scriptSource}],\n {\n additionalComponentNames: [\n '$formatMessage',\n ...(opts.additionalComponentNames || []),\n ],\n additionalFunctionNames: opts.additionalFunctionNames,\n extractSourceLocation: opts.extractSourceLocation,\n idInterpolationPattern,\n pragma: opts.pragma,\n preserveWhitespace: opts.preserveWhitespace,\n flatten: opts.flatten,\n throws: opts.throws,\n },\n typeof opts.overrideIdFn !== 'function'\n )\n const file = result.files[0]\n if (!file) return\n if (file.meta) {\n meta = {...meta, ...file.meta}\n }\n for (const error of file.errors || []) {\n opts.onMsgError?.(fn, new Error(error))\n }\n let extracted = file.messages.map(message =>\n applyOverrideId(message, fn, opts.overrideIdFn)\n )\n if (opts.extractSourceLocation) {\n extracted = extracted.map(message => {\n const start =\n message.start === undefined\n ? undefined\n : sourceOffset +\n Math.max(\n 0,\n byteOffsetToStringOffset(scriptSource, message.start) -\n wrapperOffset\n )\n const end =\n message.end === undefined\n ? undefined\n : sourceOffset +\n Math.max(\n 0,\n byteOffsetToStringOffset(scriptSource, message.end) -\n wrapperOffset\n )\n return {\n ...message,\n file: fn,\n start,\n end,\n ...calculateLineColFromOffset(source, start),\n }\n })\n }\n collectMessages(fn, extracted)\n }\n const hbsOptions: ExtractTransformOptions = {\n ...opts,\n overrideIdFn:\n typeof opts.overrideIdFn === 'function'\n ? opts.overrideIdFn\n : (id, defaultMessage, description, filename) =>\n id ||\n generateIdWithNative(\n idInterpolationPattern,\n defaultMessage,\n description,\n filename\n ),\n onMsgExtracted: collectMessages,\n onMetaExtracted(_filePath, extractedMeta) {\n meta = {...meta, ...extractedMeta}\n },\n }\n if (fn.endsWith('.vue')) {\n debug('Processing %s using vue extractor', fn)\n const {parseFile} = await import('./vue_extractor.js')\n parseFile(source, fn, scriptParseFn)\n } else if (fn.endsWith('.svelte')) {\n debug('Processing %s using svelte extractor', fn)\n const {parseFile} = await import('./svelte_extractor.js')\n parseFile(source, fn, scriptParseFn)\n } else if (fn.endsWith('.hbs')) {\n debug('Processing %s using hbs extractor', fn)\n const {parseFile} = await import('./hbs_extractor.js')\n parseFile(source, fn, hbsOptions)\n } else if (fn.endsWith('.gts') || fn.endsWith('.gjs')) {\n debug('Processing %s as gts/gjs file', fn)\n const {parseFile} = await import('./gts_extractor.js')\n parseFile(source, fn, hbsOptions, scriptParseFn)\n } else {\n debug('Processing %s using native extractor', fn)\n scriptParseFn(source)\n }\n debug('Done extracting %s messages: %s', fn, messages)\n if (meta) {\n debug('Extracted meta:', meta)\n messages.forEach(m => (m.meta = meta))\n opts.onMetaExtracted?.(fn, meta)\n }\n return {messages, meta}\n}\n\n// Match Rayon's default worker count and explicit thread override.\nfunction fileReadConcurrency(): number {\n const value = process.env.RAYON_NUM_THREADS || ''\n const threads = /^\\+?\\d+$/.test(value) ? Number(value) : 0\n return Number.isSafeInteger(threads) && threads > 0\n ? threads\n : availableParallelism()\n}\n\nasync function mapWithConcurrencyLimit<T, R>(\n items: readonly T[],\n limit: number,\n task: (item: T) => Promise<R>\n): Promise<R[]> {\n const results: R[] = []\n let nextIndex = 0\n let failed = false\n async function worker(): Promise<void> {\n while (!failed && nextIndex < items.length) {\n const index = nextIndex++\n try {\n results[index] = await task(items[index])\n } catch (error) {\n failed = true\n throw error\n }\n }\n }\n await Promise.all(\n Array.from({length: Math.min(limit, items.length)}, () => worker())\n )\n return results\n}\n\n/**\n * Extract strings from source files\n * @param files list of files\n * @param extractOpts extract options\n * @returns messages serialized as JSON string since key order\n * matters for some `format`\n */\nexport async function extract(\n files: readonly string[],\n extractOpts: ExtractOpts\n): Promise<string> {\n const {throws, readFromStdin, signal, ...opts} = extractOpts\n // Message errors may be skipped; input read failures are always fatal.\n const shouldThrow = throws === true\n // Pass throws option to transformer for per-message error handling\n const optsWithThrows = {\n ...opts,\n idInterpolationPattern:\n opts.idInterpolationPattern || DEFAULT_ID_INTERPOLATION_PATTERN,\n throws: shouldThrow,\n onMsgError: !shouldThrow\n ? opts.onMsgError || ((_: string, e: Error) => warn(e.message))\n : undefined,\n }\n\n async function processSource(source: string, filename: string) {\n try {\n return await processFile(source, filename, optsWithThrows)\n } catch (error) {\n if (shouldThrow) throw error\n warn(String(error))\n return undefined\n }\n }\n\n let rawResults: Array<ExtractionResult | undefined>\n if (readFromStdin) {\n debug('Reading input from stdin')\n if (process.stdin.isTTY) {\n warn('Reading source file from TTY.')\n }\n const source = await getStdinAsString()\n rawResults = [await processSource(source, 'dummy.ts')]\n } else {\n rawResults = await mapWithConcurrencyLimit(\n files,\n fileReadConcurrency(),\n async filename => {\n debug('Extracting file:', filename)\n const source = await readFile(filename, {encoding: 'utf8', signal})\n return processSource(source, filename)\n }\n )\n }\n\n const formatter: Formatter<unknown> = await resolveBuiltinFormatter(\n opts.format\n )\n const extractionResults = rawResults.filter((r): r is ExtractionResult => !!r)\n\n const extractedMessages = new Map<string, MessageDescriptor>()\n\n for (const {messages} of extractionResults) {\n for (const message of messages) {\n const {id, description, defaultMessage} = message\n if (!id) {\n const error = new Error(\n `[FormatJS CLI] Missing message id for message:\n${JSON.stringify(message, undefined, 2)}`\n )\n if (throws) {\n throw error\n } else {\n warn(error.message)\n }\n continue\n }\n\n if (extractedMessages.has(id)) {\n const existing = extractedMessages.get(id)!\n if (\n stringify(description) !== stringify(existing.description) ||\n defaultMessage !== existing.defaultMessage\n ) {\n const error = new Error(\n `[FormatJS CLI] Duplicate message id: \"${id}\", ` +\n 'but the `description` and/or `defaultMessage` are different.'\n )\n if (throws) {\n throw error\n } else {\n warn(error.message)\n }\n }\n }\n extractedMessages.set(id, message)\n }\n }\n const results: Record<string, Omit<MessageDescriptor, 'id'>> = {}\n const messages = Array.from(extractedMessages.values())\n for (const {id, ...msg} of messages) {\n // GH #3537: flatten is now applied during extraction in the babel plugin,\n // so we don't need to apply it again here. The messages are already flattened.\n results[id] = msg\n }\n if (typeof formatter.serialize === 'function') {\n return formatter.serialize(formatter.format(results as any))\n }\n return (\n stringify(formatter.format(results as any), {\n space: 2,\n cmp: formatter.compareMessages || undefined,\n }) ?? ''\n )\n}\n\n/**\n * Extract strings from source files, also writes to a file.\n * @param files list of files\n * @param extractOpts extract options\n * @returns A Promise that resolves if output file was written successfully\n */\nexport default async function extractAndWrite(\n files: readonly string[],\n extractOpts: ExtractCLIOptions\n): Promise<void> {\n const {outFile, ...opts} = extractOpts\n const serializedResult = (await extract(files, opts)) + '\\n'\n if (outFile) {\n debug('Writing output file:', outFile)\n return outputFile(outFile, serializedResult)\n }\n await writeStdout(serializedResult)\n}\n","import {outputFile} from 'fs-extra/esm'\nimport {readFile} from 'fs/promises'\nimport glob from 'fast-glob'\nimport * as stringifyNs from 'json-stable-stringify'\nimport {resolve} from 'path'\nimport {pathToFileURL} from 'url'\nimport {debug, warn, writeStdout} from '#packages/cli-lib/console_utils.js'\nimport {type Formatter} from '#packages/cli-lib/formatters/index.js'\nimport {\n type NativeCompileMessage,\n compileMessagesWithNative,\n compileWithNative,\n} from '#packages/cli-lib/native.js'\n\nconst dynamicImport = new Function('specifier', 'return import(specifier)') as (\n specifier: string\n) => Promise<Formatter<unknown>>\nconst globSync = glob.sync\nconst stringify = (stringifyNs as any).default || stringifyNs\nconst CUSTOM_FORMATTER_FILE_DEPRECATION_WARNING =\n '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.'\n\nconst BUILTIN_FORMATTERS = new Set([\n 'default',\n 'simple',\n 'transifex',\n 'smartling',\n 'lokalise',\n 'crowdin',\n])\n\nexport type PseudoLocale = 'xx-LS' | 'xx-AC' | 'xx-HA' | 'en-XA' | 'en-XB'\n\nexport interface CompileCLIOpts extends Opts {\n /**\n * The target file that contains compiled messages.\n */\n outFile?: string\n}\n\nexport interface Opts {\n /**\n * Whether to compile message into AST instead of just string\n */\n ast?: boolean\n /**\n * Whether to continue compiling messages after encountering an error.\n * Any keys with errors will not be included in the output file.\n */\n skipErrors?: boolean\n /**\n * Built-in formatter name or path to a formatter file that converts\n * <translation_files> to `Record<string, string>` so we can compile.\n * Formatter file paths are deprecated for compilation.\n */\n format?: string | Formatter<unknown>\n /**\n * Whether to compile to pseudo locale\n */\n pseudoLocale?: PseudoLocale\n /**\n * Whether the parser to treat HTML/XML tags as string literal\n * instead of parsing them as tag token.\n * When this is false we only allow simple tags without\n * any attributes\n */\n ignoreTag?: boolean\n /**\n * An AbortSignal to cancel the compilation before invoking native code.\n */\n signal?: AbortSignal\n /**\n * Whether to follow symbolic links when traversing directories.\n * Defaults to true for compatibility with pnpm symlinked node_modules.\n */\n followLinks?: boolean\n}\n\n/**\n * Compile extracted translation files with the native formatjs CLI binding.\n * @param inputFiles Input files or glob patterns\n * @param opts Options\n * @returns serialized result in string format\n */\nexport async function compile(\n inputFiles: string[],\n opts: Opts = {}\n): Promise<string> {\n debug('Compiling files:', inputFiles)\n const {\n ast,\n format,\n pseudoLocale,\n skipErrors,\n ignoreTag,\n signal,\n followLinks,\n } = opts\n signal?.throwIfAborted()\n\n if (format && !isBuiltinFormatter(format)) {\n return compileWithCustomFormatter(inputFiles, opts)\n }\n\n return compileWithNative(inputFiles, {\n ast,\n format: typeof format === 'string' ? format : undefined,\n followLinks,\n ignoreTag,\n pseudoLocale,\n skipErrors,\n })\n}\n\nfunction isBuiltinFormatter(\n format: string | Formatter<unknown>\n): format is string {\n return typeof format === 'string' && BUILTIN_FORMATTERS.has(format)\n}\n\nasync function compileWithCustomFormatter(\n inputFiles: string[],\n opts: Opts\n): Promise<string> {\n if (typeof opts.format === 'string') {\n await warn(CUSTOM_FORMATTER_FILE_DEPRECATION_WARNING)\n }\n\n const formatter = await resolveCustomFormatter(opts.format)\n const files = globSync(inputFiles, {\n followSymbolicLinks: opts.followLinks ?? true,\n })\n\n if (!files.length) {\n throw new Error('No translation files found matching the patterns')\n }\n\n const messages: NativeCompileMessage[] = []\n await Promise.all(\n files.map(async file => {\n opts.signal?.throwIfAborted()\n const content = await readFile(file, {\n encoding: 'utf8',\n signal: opts.signal,\n })\n const compiled = formatter.compile(JSON.parse(content))\n for (const id of Object.keys(compiled)) {\n messages.push({\n id,\n message: compiled[id],\n sourceFile: file,\n })\n }\n })\n )\n\n const serialized = compileMessagesWithNative(messages, {\n ast: opts.ast,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n\n if (formatter.compareMessages) {\n return (\n stringify(JSON.parse(serialized), {\n space: 2,\n cmp: formatter.compareMessages,\n }) ?? ''\n )\n }\n\n return serialized\n}\n\nasync function resolveCustomFormatter(\n format: string | Formatter<unknown> | undefined\n): Promise<Formatter<unknown>> {\n if (!format) {\n throw new Error('A custom formatter is required')\n }\n if (typeof format !== 'string') {\n return format\n }\n try {\n return dynamicImport(pathToFileURL(resolve(process.cwd(), format)).href)\n } catch (e) {\n console.error(`Cannot resolve formatter ${format}`)\n throw e\n }\n}\n\n/**\n * Compile extracted translation files with the native formatjs CLI binding and\n * write output to `outFile` when provided.\n * @param inputFiles Input files or glob patterns\n * @param compileOpts options\n * @returns A `Promise` that resolves if file was written successfully\n */\nexport default async function compileAndWrite(\n inputFiles: string[],\n compileOpts: CompileCLIOpts = {}\n): Promise<void> {\n const {outFile, ...opts} = compileOpts\n const serializedResult = (await compile(inputFiles, opts)) + '\\n'\n if (outFile) {\n debug('Writing output file:', outFile)\n return outputFile(outFile, serializedResult)\n }\n await writeStdout(serializedResult)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAMA,MAAM,mBAAmB;AAEzB,MAAa,cACX,UAAU,QAAQ,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ,MAAM;AACrD,MAAa,cACX,UAAU,QAAQ,OAAO,KAAK,CAAC,CAAC,KAAK,QAAQ,MAAM;AAIrD,eAAsBA,YACpB,UACe;CACf,IAAI,CAAC,SAAS,YAAY,GACpB;MAAA,SAAS,OAAO;GAElB,IAAI,SAAS,UAAU,GACrB,MAAM,YAAY,KAAK,IAAI,OAAO,SAAS,UAAU,CAAC,GAAG;GAE3D,MAAM,YAAY,IAAI;EACxB;QAEK;EACL,UAAgB,UAAU,gBAAgB;EAC1C,SAAe,UAAU,GAAG,KAAA,CAAS;CACvC;AACF;AAIA,MAAM,eAA6D;CACjE,OAAO;CACP,MAAM;CACN,OAAO;AACT;AAEA,SAAS,MAAM,OAAiB,SAAiB;CAC/C,OAAO,oBAAoB,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MAAM,OAAO,KAAK,QAAQ,GACnC,SAAS,KAAK;GACZ;GACA,SAAS,SAAS;GAClB,YAAY;EACd,CAAC;CAEL,CAAC,CACH;CAEA,MAAM,aAAa,0BAA0B,UAAU;EACrD,KAAK,KAAK;EACV,WAAW,KAAK;EAChB,cAAc,KAAK;EACnB,YAAY,KAAK;CACnB,CAAC;CAED,IAAI,UAAU,iBACZ,OACE,UAAU,KAAK,MAAM,UAAU,GAAG;EAChC,OAAO;EACP,KAAK,UAAU;CACjB,CAAC,KAAK;CAIV,OAAO;AACT;AAEA,eAAe,uBACb,QAC6B;CAC7B,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,gCAAgC;CAElD,IAAI,OAAO,WAAW,UACpB,OAAO;CAET,IAAI;EACF,OAAO,cAAc,cAAc,QAAQ,QAAQ,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI;CACzE,SAAS,GAAG;EACV,QAAQ,MAAM,4BAA4B,QAAQ;EAClD,MAAM;CACR;AACF;;;;;;;;AASA,eAA8B,gBAC5B,YACA,cAA8B,CAAC,GAChB;CACf,MAAM,EAAC,SAAS,GAAG,SAAQ;CAC3B,MAAM,mBAAoB,MAAM,QAAQ,YAAY,IAAI,IAAK;CAC7D,IAAI,SAAS;EACX,MAAM,wBAAwB,OAAO;EACrC,OAAO,WAAW,SAAS,gBAAgB;CAC7C;CACA,MAAM,YAAY,gBAAgB;AACpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formatjs/cli-lib",
3
- "version": "10.0.12",
3
+ "version": "10.2.0",
4
4
  "description": "Lib for CLI for formatjs.",
5
5
  "keywords": [
6
6
  "cli",
@@ -39,7 +39,7 @@
39
39
  "@bazel/runfiles": "6",
40
40
  "@formatjs/icu-messageformat-parser": "3.5.22",
41
41
  "@types/fs-extra": "11",
42
- "@types/node": "22 || 24",
42
+ "@types/node": "22 || 24 || 26",
43
43
  "commander": "15",
44
44
  "fast-glob": "3",
45
45
  "fs-extra": "11",
@@ -47,7 +47,7 @@
47
47
  "loud-rejection": "2"
48
48
  },
49
49
  "peerDependencies": {
50
- "@glimmer/syntax": "^0.84.3 || ^0.95.0",
50
+ "@glimmer/syntax": "^0.84.3 || ^0.95.0 || ^0.97.0",
51
51
  "@vue/compiler-core": "3",
52
52
  "content-tag": "4",
53
53
  "svelte": "5",
@@ -80,12 +80,14 @@
80
80
  }
81
81
  },
82
82
  "optionalDependencies": {
83
- "@formatjs/cli-native-darwin-arm64": "1.1.30",
84
- "@formatjs/cli-native-linux-arm64": "1.2.30",
85
- "@formatjs/cli-native-linux-arm64-musl": "1.0.28",
86
- "@formatjs/cli-native-linux-x64": "1.1.30",
87
- "@formatjs/cli-native-linux-x64-musl": "1.0.28",
88
- "@formatjs/cli-native-win32-x64": "1.1.31"
83
+ "@formatjs/cli-native-darwin-arm64": "1.1.32",
84
+ "@formatjs/cli-native-darwin-x64": "1.1.0",
85
+ "@formatjs/cli-native-linux-arm64": "1.2.32",
86
+ "@formatjs/cli-native-linux-arm64-musl": "1.0.30",
87
+ "@formatjs/cli-native-linux-x64": "1.1.32",
88
+ "@formatjs/cli-native-linux-x64-musl": "1.0.30",
89
+ "@formatjs/cli-native-win32-arm64": "1.1.0",
90
+ "@formatjs/cli-native-win32-x64": "1.1.33"
89
91
  },
90
92
  "engines": {
91
93
  "node": ">= 22.12.0"
@@ -1,4 +1,3 @@
1
- //#region packages/cli-lib/static-evaluation.d.ts
2
1
  export interface EvaluationSpan {
3
2
  start: number;
4
3
  end: number;
@@ -8,5 +7,4 @@ export interface EvaluatedString extends EvaluationSpan {
8
7
  }
9
8
  /** Evaluate requested expressions using OXC's semantic analysis and constant evaluator. */
10
9
  export declare function evaluateStrings(source: string, filename: string, spans: EvaluationSpan[]): EvaluatedString[];
11
- //#endregion
12
10
  //# sourceMappingURL=static-evaluation.d.ts.map
@@ -1,12 +1,14 @@
1
1
  import { createRequire } from "module";
2
2
  import { Runfiles } from "@bazel/runfiles";
3
- //#region packages/cli-lib/native.ts
3
+ // packages/cli-lib/native.ts
4
4
  const require = createRequire(import.meta.url);
5
5
  const NATIVE_PACKAGES = {
6
6
  "darwin-arm64": ["@formatjs/cli-native-darwin-arm64"],
7
+ "darwin-x64": ["@formatjs/cli-native-darwin-x64"],
7
8
  "linux-arm64": ["@formatjs/cli-native-linux-arm64", "@formatjs/cli-native-linux-arm64-musl"],
8
9
  "linux-x64": ["@formatjs/cli-native-linux-x64", "@formatjs/cli-native-linux-x64-musl"],
9
- "win32-x64": ["@formatjs/cli-native-win32-x64"]
10
+ "win32-x64": ["@formatjs/cli-native-win32-x64"],
11
+ "win32-arm64": ["@formatjs/cli-native-win32-arm64"]
10
12
  };
11
13
  let nativeBinding;
12
14
  function getInstalledNativePackageCandidates(candidates, canResolve = (candidate) => {
@@ -45,13 +47,11 @@ function loadNative() {
45
47
  nativeBinding = null;
46
48
  throw new Error(`Native @formatjs/cli-lib binding is unavailable.\n${loadErrors.join("\n")}`);
47
49
  }
48
- //#endregion
49
- //#region packages/cli-lib/static-evaluation.ts
50
+ // packages/cli-lib/static-evaluation.ts
50
51
  /** Evaluate requested expressions using OXC's semantic analysis and constant evaluator. */
51
52
  function evaluateStrings(source, filename, spans) {
52
53
  return loadNative().evaluateStrings(source, filename, spans);
53
54
  }
54
- //#endregion
55
55
  export { evaluateStrings };
56
56
 
57
57
  //# sourceMappingURL=static-evaluation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"static-evaluation.js","names":[],"sources":["sources/packages/cli-lib/native.ts","sources/packages/cli-lib/static-evaluation.ts"],"sourcesContent":["import {createRequire} from 'module'\nimport {Runfiles} from '@bazel/runfiles'\nimport type {\n EvaluationSpan,\n EvaluatedString,\n} from '#packages/cli-lib/static-evaluation.js'\n\nconst require = createRequire(import.meta.url)\n\nconst NATIVE_PACKAGES: Record<string, string[]> = {\n 'darwin-arm64': ['@formatjs/cli-native-darwin-arm64'],\n 'linux-arm64': [\n '@formatjs/cli-native-linux-arm64',\n '@formatjs/cli-native-linux-arm64-musl',\n ],\n 'linux-x64': [\n '@formatjs/cli-native-linux-x64',\n '@formatjs/cli-native-linux-x64-musl',\n ],\n 'win32-x64': ['@formatjs/cli-native-win32-x64'],\n}\n\nexport interface NativeCompileOptions {\n ast?: boolean\n format?: string\n ignoreTag?: boolean\n pseudoLocale?: string\n skipErrors?: boolean\n followLinks?: boolean\n}\n\nexport interface NativeCompileMessage {\n id: string\n message: string\n sourceFile: string\n}\n\nexport interface NativeExtractOptions {\n additionalComponentNames?: string[]\n additionalFunctionNames?: string[]\n extractSourceLocation?: boolean\n flatten?: boolean\n followLinks?: boolean\n format?: string\n idInterpolationPattern?: string\n ignore?: string[]\n inFile?: string\n pragma?: string\n preserveWhitespace?: boolean\n throws?: boolean\n}\n\nexport interface NativeExtractSourceInput {\n filename: string\n source: string\n}\n\nexport interface NativeMessageDescriptor {\n id?: string\n defaultMessage?: string\n description?: string | object\n file?: string\n start?: number\n end?: number\n}\n\nexport interface NativeExtractSourceResult {\n filename: string\n messages: NativeMessageDescriptor[]\n meta?: Record<string, string>\n errors?: string[]\n}\n\nexport interface NativeExtractSourcesResult {\n files: NativeExtractSourceResult[]\n warnings?: string[]\n}\n\nexport interface NativeBinding {\n evaluateStrings(\n source: string,\n filename: string,\n spans: EvaluationSpan[]\n ): EvaluatedString[]\n compile(inputFiles: string[], opts?: NativeCompileOptions): string\n compileMessages(\n messages: NativeCompileMessage[],\n opts?: NativeCompileOptions\n ): string\n extract(inputFiles: string[], opts?: NativeExtractOptions): string\n extractSources(\n sources: NativeExtractSourceInput[],\n opts?: NativeExtractOptions,\n generateIds?: boolean\n ): string\n generateId(\n pattern: string,\n defaultMessage?: string,\n descriptionJson?: string,\n filename?: string\n ): string\n supportedBuiltinFormatters(): string[]\n}\n\nlet nativeBinding: NativeBinding | null | undefined\n\nexport function getInstalledNativePackageCandidates(\n candidates: readonly string[],\n canResolve = (candidate: string): boolean => {\n try {\n require.resolve(candidate)\n return true\n } catch {\n return false\n }\n }\n): string[] {\n return candidates.filter(canResolve)\n}\n\nexport function getNativePackageCandidates(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch\n): string[] {\n const platformArch = `${platform}-${arch}`\n return NATIVE_PACKAGES[platformArch] || []\n}\n\nexport function loadNative(): NativeBinding {\n if (nativeBinding !== undefined) {\n if (nativeBinding) {\n return nativeBinding\n }\n throw new Error('Native @formatjs/cli-lib binding is unavailable')\n }\n\n let runfilesPath: string | undefined\n if (\n process.env.RUNFILES_DIR ||\n process.env.RUNFILES_MANIFEST_FILE ||\n process.env.RUNFILES\n ) {\n try {\n runfilesPath = new Runfiles().resolveWorkspaceRelative(\n 'packages/cli-lib/formatjs_cli_napi.node'\n )\n } catch {\n // Published packages use platform-specific npm packages.\n }\n }\n const packageCandidates = getNativePackageCandidates()\n const installedPackageCandidates =\n getInstalledNativePackageCandidates(packageCandidates)\n const candidates = [\n runfilesPath,\n ...(installedPackageCandidates.length\n ? installedPackageCandidates\n : packageCandidates),\n ].filter(Boolean) as string[]\n const loadErrors: string[] = []\n\n for (const candidate of candidates) {\n try {\n nativeBinding = require(candidate) as NativeBinding\n return nativeBinding\n } catch (e) {\n loadErrors.push(`${candidate}: ${(e as Error).message}`)\n }\n }\n\n nativeBinding = null\n throw new Error(\n `Native @formatjs/cli-lib binding is unavailable.\\n${loadErrors.join('\\n')}`\n )\n}\n\nexport function compileWithNative(\n inputFiles: string[],\n opts: NativeCompileOptions = {}\n): string {\n const native = loadNative()\n return native.compile(inputFiles, {\n ast: opts.ast,\n format: opts.format,\n followLinks: opts.followLinks,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n}\n\nexport function compileMessagesWithNative(\n messages: NativeCompileMessage[],\n opts: NativeCompileOptions = {}\n): string {\n const native = loadNative()\n return native.compileMessages(messages, {\n ast: opts.ast,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n}\n\nexport function extractSourcesWithNative(\n sources: NativeExtractSourceInput[],\n opts: NativeExtractOptions = {},\n generateIds = true\n): NativeExtractSourcesResult {\n const native = loadNative()\n return JSON.parse(native.extractSources(sources, opts, generateIds))\n}\n\nexport function generateIdWithNative(\n pattern: string,\n defaultMessage?: string,\n description?: string | object,\n filename?: string\n): string {\n return loadNative().generateId(\n pattern,\n defaultMessage,\n description === undefined ? undefined : JSON.stringify(description),\n filename\n )\n}\n","import {loadNative} from '#packages/cli-lib/native.js'\n\nexport interface EvaluationSpan {\n start: number\n end: number\n}\n\nexport interface EvaluatedString extends EvaluationSpan {\n value: string\n}\n\n/** Evaluate requested expressions using OXC's semantic analysis and constant evaluator. */\nexport function evaluateStrings(\n source: string,\n filename: string,\n spans: EvaluationSpan[]\n): EvaluatedString[] {\n return loadNative().evaluateStrings(source, filename, spans)\n}\n"],"mappings":";;;AAOA,MAAM,UAAU,cAAc,YAAY,GAAG;AAE7C,MAAM,kBAA4C;CAChD,gBAAgB,CAAC,mCAAmC;CACpD,eAAe,CACb,oCACA,uCACF;CACA,aAAa,CACX,kCACA,qCACF;CACA,aAAa,CAAC,gCAAgC;AAChD;AAoFA,IAAI;AAEJ,SAAgB,oCACd,YACA,cAAc,cAA+B;CAC3C,IAAI;EACF,QAAQ,QAAQ,SAAS;EACzB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF,GACU;CACV,OAAO,WAAW,OAAO,UAAU;AACrC;AAEA,SAAgB,2BACd,WAA4B,QAAQ,UACpC,OAAe,QAAQ,MACb;CACV,MAAM,eAAe,GAAG,SAAS,GAAG;CACpC,OAAO,gBAAgB,iBAAiB,CAAC;AAC3C;AAEA,SAAgB,aAA4B;CAC1C,IAAI,kBAAkB,KAAA,GAAW;EAC/B,IAAI,eACF,OAAO;EAET,MAAM,IAAI,MAAM,iDAAiD;CACnE;CAEA,IAAI;CACJ,IACE,QAAQ,IAAI,gBACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,UAEZ,IAAI;EACF,eAAe,IAAI,SAAS,CAAC,CAAC,yBAC5B,yCACF;CACF,QAAQ,CAER;CAEF,MAAM,oBAAoB,2BAA2B;CACrD,MAAM,6BACJ,oCAAoC,iBAAiB;CACvD,MAAM,aAAa,CACjB,cACA,GAAI,2BAA2B,SAC3B,6BACA,iBACN,CAAC,CAAC,OAAO,OAAO;CAChB,MAAM,aAAuB,CAAC;CAE9B,KAAK,MAAM,aAAa,YACtB,IAAI;EACF,gBAAgB,QAAQ,SAAS;EACjC,OAAO;CACT,SAAS,GAAG;EACV,WAAW,KAAK,GAAG,UAAU,IAAK,EAAY,SAAS;CACzD;CAGF,gBAAgB;CAChB,MAAM,IAAI,MACR,qDAAqD,WAAW,KAAK,IAAI,GAC3E;AACF;;;;AClKA,SAAgB,gBACd,QACA,UACA,OACmB;CACnB,OAAO,WAAW,CAAC,CAAC,gBAAgB,QAAQ,UAAU,KAAK;AAC7D"}
1
+ {"version":3,"file":"static-evaluation.js","names":[],"sources":["sources/packages/cli-lib/native.ts","sources/packages/cli-lib/static-evaluation.ts"],"sourcesContent":["import {createRequire} from 'module'\nimport {Runfiles} from '@bazel/runfiles'\nimport type {\n EvaluationSpan,\n EvaluatedString,\n} from '#packages/cli-lib/static-evaluation.js'\n\nconst require = createRequire(import.meta.url)\n\nconst NATIVE_PACKAGES: Record<string, string[]> = {\n 'darwin-arm64': ['@formatjs/cli-native-darwin-arm64'],\n 'darwin-x64': ['@formatjs/cli-native-darwin-x64'],\n 'linux-arm64': [\n '@formatjs/cli-native-linux-arm64',\n '@formatjs/cli-native-linux-arm64-musl',\n ],\n 'linux-x64': [\n '@formatjs/cli-native-linux-x64',\n '@formatjs/cli-native-linux-x64-musl',\n ],\n 'win32-x64': ['@formatjs/cli-native-win32-x64'],\n 'win32-arm64': ['@formatjs/cli-native-win32-arm64'],\n}\n\nexport interface NativeCompileOptions {\n ast?: boolean\n format?: string\n ignoreTag?: boolean\n pseudoLocale?: string\n skipErrors?: boolean\n followLinks?: boolean\n}\n\nexport interface NativeCompileMessage {\n id: string\n message: string\n sourceFile: string\n}\n\nexport interface NativeExtractOptions {\n additionalComponentNames?: string[]\n additionalFunctionNames?: string[]\n extractSourceLocation?: boolean\n flatten?: boolean\n followLinks?: boolean\n format?: string\n idInterpolationPattern?: string\n ignore?: string[]\n inFile?: string\n pragma?: string\n preserveWhitespace?: boolean\n throws?: boolean\n}\n\nexport interface NativeExtractSourceInput {\n filename: string\n source: string\n}\n\nexport interface NativeMessageDescriptor {\n id?: string\n defaultMessage?: string\n description?: string | object\n file?: string\n start?: number\n end?: number\n}\n\nexport interface NativeExtractSourceResult {\n filename: string\n messages: NativeMessageDescriptor[]\n meta?: Record<string, string>\n errors?: string[]\n}\n\nexport interface NativeExtractSourcesResult {\n files: NativeExtractSourceResult[]\n warnings?: string[]\n}\n\nexport interface NativeBinding {\n evaluateStrings(\n source: string,\n filename: string,\n spans: EvaluationSpan[]\n ): EvaluatedString[]\n compile(inputFiles: string[], opts?: NativeCompileOptions): string\n compileMessages(\n messages: NativeCompileMessage[],\n opts?: NativeCompileOptions\n ): string\n extract(inputFiles: string[], opts?: NativeExtractOptions): string\n extractSources(\n sources: NativeExtractSourceInput[],\n opts?: NativeExtractOptions,\n generateIds?: boolean\n ): string\n generateId(\n pattern: string,\n defaultMessage?: string,\n descriptionJson?: string,\n filename?: string\n ): string\n verifyJavaPrintf(catalogsJson: string, sourceLocale: string): string\n verifyXcstrings(\n catalogsJson: string,\n sourceLocale: string | undefined,\n missingKeys: boolean,\n structuralEquality: boolean\n ): string\n supportedBuiltinFormatters(): string[]\n}\n\nlet nativeBinding: NativeBinding | null | undefined\n\nexport function getInstalledNativePackageCandidates(\n candidates: readonly string[],\n canResolve = (candidate: string): boolean => {\n try {\n require.resolve(candidate)\n return true\n } catch {\n return false\n }\n }\n): string[] {\n return candidates.filter(canResolve)\n}\n\nexport function getNativePackageCandidates(\n platform: NodeJS.Platform = process.platform,\n arch: string = process.arch\n): string[] {\n const platformArch = `${platform}-${arch}`\n return NATIVE_PACKAGES[platformArch] || []\n}\n\nexport function loadNative(): NativeBinding {\n if (nativeBinding !== undefined) {\n if (nativeBinding) {\n return nativeBinding\n }\n throw new Error('Native @formatjs/cli-lib binding is unavailable')\n }\n\n let runfilesPath: string | undefined\n if (\n process.env.RUNFILES_DIR ||\n process.env.RUNFILES_MANIFEST_FILE ||\n process.env.RUNFILES\n ) {\n try {\n runfilesPath = new Runfiles().resolveWorkspaceRelative(\n 'packages/cli-lib/formatjs_cli_napi.node'\n )\n } catch {\n // Published packages use platform-specific npm packages.\n }\n }\n const packageCandidates = getNativePackageCandidates()\n const installedPackageCandidates =\n getInstalledNativePackageCandidates(packageCandidates)\n const candidates = [\n runfilesPath,\n ...(installedPackageCandidates.length\n ? installedPackageCandidates\n : packageCandidates),\n ].filter(Boolean) as string[]\n const loadErrors: string[] = []\n\n for (const candidate of candidates) {\n try {\n nativeBinding = require(candidate) as NativeBinding\n return nativeBinding\n } catch (e) {\n loadErrors.push(`${candidate}: ${(e as Error).message}`)\n }\n }\n\n nativeBinding = null\n throw new Error(\n `Native @formatjs/cli-lib binding is unavailable.\\n${loadErrors.join('\\n')}`\n )\n}\n\nexport function compileWithNative(\n inputFiles: string[],\n opts: NativeCompileOptions = {}\n): string {\n const native = loadNative()\n return native.compile(inputFiles, {\n ast: opts.ast,\n format: opts.format,\n followLinks: opts.followLinks,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n}\n\nexport function compileMessagesWithNative(\n messages: NativeCompileMessage[],\n opts: NativeCompileOptions = {}\n): string {\n const native = loadNative()\n return native.compileMessages(messages, {\n ast: opts.ast,\n ignoreTag: opts.ignoreTag,\n pseudoLocale: opts.pseudoLocale,\n skipErrors: opts.skipErrors,\n })\n}\n\nexport function extractSourcesWithNative(\n sources: NativeExtractSourceInput[],\n opts: NativeExtractOptions = {},\n generateIds = true\n): NativeExtractSourcesResult {\n const native = loadNative()\n return JSON.parse(native.extractSources(sources, opts, generateIds))\n}\n\nexport function generateIdWithNative(\n pattern: string,\n defaultMessage?: string,\n description?: string | object,\n filename?: string\n): string {\n return loadNative().generateId(\n pattern,\n defaultMessage,\n description === undefined ? undefined : JSON.stringify(description),\n filename\n )\n}\n\nexport interface NativeVerificationIssue {\n locale: string\n messageId: string\n error: string\n}\n\nexport function verifyJavaPrintfWithNative(\n catalogs: Record<string, unknown>,\n sourceLocale: string\n): NativeVerificationIssue[] {\n const native = loadNative()\n if (typeof native.verifyJavaPrintf !== 'function') {\n throw new Error(\n 'Installed FormatJS native package does not support Java printf verification; update @formatjs/cli and its native package.'\n )\n }\n return JSON.parse(\n native.verifyJavaPrintf(JSON.stringify(catalogs), sourceLocale)\n )\n}\n\nexport function verifyXcstringsWithNative(\n catalogs: Record<string, unknown>,\n sourceLocale: string | undefined,\n missingKeys: boolean,\n structuralEquality: boolean\n): NativeVerificationIssue[] {\n const native = loadNative()\n if (typeof native.verifyXcstrings !== 'function') {\n throw new Error(\n 'Installed FormatJS native package does not support xcstrings verification; update @formatjs/cli and its native package.'\n )\n }\n return JSON.parse(\n native.verifyXcstrings(\n JSON.stringify(catalogs),\n sourceLocale,\n missingKeys,\n structuralEquality\n )\n )\n}\n","import {loadNative} from '#packages/cli-lib/native.js'\n\nexport interface EvaluationSpan {\n start: number\n end: number\n}\n\nexport interface EvaluatedString extends EvaluationSpan {\n value: string\n}\n\n/** Evaluate requested expressions using OXC's semantic analysis and constant evaluator. */\nexport function evaluateStrings(\n source: string,\n filename: string,\n spans: EvaluationSpan[]\n): EvaluatedString[] {\n return loadNative().evaluateStrings(source, filename, spans)\n}\n"],"mappings":";;;AAOA,MAAM,UAAU,cAAc,YAAY,GAAG;AAE7C,MAAM,kBAA4C;CAChD,gBAAgB,CAAC,mCAAmC;CACpD,cAAc,CAAC,iCAAiC;CAChD,eAAe,CACb,oCACA,uCACF;CACA,aAAa,CACX,kCACA,qCACF;CACA,aAAa,CAAC,gCAAgC;CAC9C,eAAe,CAAC,kCAAkC;AACpD;AA2FA,IAAI;AAEJ,SAAgB,oCACd,YACA,cAAc,cAA+B;CAC3C,IAAI;EACF,QAAQ,QAAQ,SAAS;EACzB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF,GACU;CACV,OAAO,WAAW,OAAO,UAAU;AACrC;AAEA,SAAgB,2BACd,WAA4B,QAAQ,UACpC,OAAe,QAAQ,MACb;CACV,MAAM,eAAe,GAAG,SAAS,GAAG;CACpC,OAAO,gBAAgB,iBAAiB,CAAC;AAC3C;AAEA,SAAgB,aAA4B;CAC1C,IAAI,kBAAkB,KAAA,GAAW;EAC/B,IAAI,eACF,OAAO;EAET,MAAM,IAAI,MAAM,iDAAiD;CACnE;CAEA,IAAI;CACJ,IACE,QAAQ,IAAI,gBACZ,QAAQ,IAAI,0BACZ,QAAQ,IAAI,UAEZ,IAAI;EACF,eAAe,IAAI,SAAS,CAAC,CAAC,yBAC5B,yCACF;CACF,QAAQ,CAER;CAEF,MAAM,oBAAoB,2BAA2B;CACrD,MAAM,6BACJ,oCAAoC,iBAAiB;CACvD,MAAM,aAAa,CACjB,cACA,GAAI,2BAA2B,SAC3B,6BACA,iBACN,CAAC,CAAC,OAAO,OAAO;CAChB,MAAM,aAAuB,CAAC;CAE9B,KAAK,MAAM,aAAa,YACtB,IAAI;EACF,gBAAgB,QAAQ,SAAS;EACjC,OAAO;CACT,SAAS,GAAG;EACV,WAAW,KAAK,GAAG,UAAU,IAAK,EAAY,SAAS;CACzD;CAGF,gBAAgB;CAChB,MAAM,IAAI,MACR,qDAAqD,WAAW,KAAK,IAAI,GAC3E;AACF;;;AC3KA,SAAgB,gBACd,QACA,UACA,OACmB;CACnB,OAAO,WAAW,CAAC,CAAC,gBAAgB,QAAQ,UAAU,KAAK;AAC7D"}
@@ -1,5 +1,5 @@
1
1
  import { parse } from "svelte/compiler";
2
- //#region packages/cli-lib/svelte_extractor.ts
2
+ // packages/cli-lib/svelte_extractor.ts
3
3
  const MESSAGE_DESCRIPTOR_PROPS = /* @__PURE__ */ new Set([
4
4
  "id",
5
5
  "defaultMessage",
@@ -135,7 +135,6 @@ function parseFile(source, filename, parseScriptFn) {
135
135
  parseScriptFn(source.slice(program.start, program.end), program.start);
136
136
  }
137
137
  }
138
- //#endregion
139
138
  export { parseFile };
140
139
 
141
- //# sourceMappingURL=svelte_extractor-Csb4fR2L.js.map
140
+ //# sourceMappingURL=svelte_extractor-CEd4aBBk.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"svelte_extractor-Csb4fR2L.js","names":[],"sources":["sources/packages/cli-lib/svelte_extractor.ts"],"sourcesContent":["import {parse} from 'svelte/compiler'\n\nexport type ScriptParseFn = (\n source: string,\n sourceOffset?: number,\n wrapperOffset?: number\n) => void\n\ninterface SvelteNode {\n type: string\n start: number\n end: number\n [key: string]: any\n}\n\nconst MESSAGE_DESCRIPTOR_PROPS = new Set([\n 'id',\n 'defaultMessage',\n 'description',\n])\n\nfunction isValidIdentifier(name: string): boolean {\n return /^[$A-Z_a-z][$\\w]*$/.test(name)\n}\n\nfunction walkFragment(\n fragment: SvelteNode | null | undefined,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (!fragment || !fragment.nodes) {\n return\n }\n for (const node of fragment.nodes) {\n walkNode(node, source, parseScriptFn)\n }\n}\n\nfunction extractExpression(\n expression: SvelteNode | null | undefined,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (!expression || expression.start == null || expression.end == null) {\n return\n }\n const content = source.slice(expression.start, expression.end)\n try {\n parseScriptFn(`(${content})`, expression.start, 1)\n } catch (e) {\n console.warn(\n `Failed to parse \"${content}\". Ignore this if content has no extractable message`,\n e\n )\n }\n}\n\nfunction getStringAttributeValue(value: SvelteNode): string {\n return value.data ?? value.raw ?? ''\n}\n\nfunction getAttributeExpression(\n attr: SvelteNode,\n source: string\n): string | undefined {\n if (attr.value === true || attr.value == null) {\n return undefined\n }\n\n if (!Array.isArray(attr.value)) {\n if (attr.value.type === 'ExpressionTag') {\n return source.slice(\n attr.value.expression.start,\n attr.value.expression.end\n )\n }\n return undefined\n }\n\n if (!attr.value.length) {\n return '\"\"'\n }\n\n if (attr.value.length === 1) {\n const [value] = attr.value\n if (value.type === 'ExpressionTag') {\n return source.slice(value.expression.start, value.expression.end)\n }\n return JSON.stringify(getStringAttributeValue(value))\n }\n\n let staticValue = ''\n for (const value of attr.value) {\n if (value.type === 'ExpressionTag') {\n return undefined\n }\n staticValue += getStringAttributeValue(value)\n }\n return JSON.stringify(staticValue)\n}\n\nfunction extractMessageComponent(\n node: SvelteNode,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (typeof node.name !== 'string' || !isValidIdentifier(node.name)) {\n return\n }\n\n const attributes: string[] = []\n for (const attr of node.attributes || []) {\n if (\n attr.type !== 'Attribute' ||\n typeof attr.name !== 'string' ||\n !MESSAGE_DESCRIPTOR_PROPS.has(attr.name)\n ) {\n continue\n }\n\n const expression = getAttributeExpression(attr, source)\n if (expression != null) {\n attributes.push(`${attr.name}={${expression}}`)\n }\n }\n\n if (!attributes.length) {\n return\n }\n\n try {\n parseScriptFn(`<${node.name} ${attributes.join(' ')} />`)\n } catch (e) {\n console.warn(\n `Failed to parse ${node.name} message component. Ignore this if component has no extractable message`,\n e\n )\n }\n}\n\nfunction walkNode(\n node: SvelteNode,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n switch (node.type) {\n case 'ExpressionTag':\n extractExpression(node.expression, source, parseScriptFn)\n break\n\n case 'ConstTag':\n // {@const x = expr} — the declaration contains the expression\n if (node.declaration) {\n const content = source.slice(\n node.declaration.start,\n node.declaration.end\n )\n try {\n parseScriptFn(content, node.declaration.start)\n } catch (e) {\n console.warn(\n `Failed to parse const declaration. Ignore this if content has no extractable message`,\n e\n )\n }\n }\n break\n\n case 'IfBlock':\n extractExpression(node.test, source, parseScriptFn)\n walkFragment(node.consequent, source, parseScriptFn)\n walkFragment(node.alternate, source, parseScriptFn)\n break\n\n case 'EachBlock':\n extractExpression(node.expression, source, parseScriptFn)\n if (node.key) {\n extractExpression(node.key, source, parseScriptFn)\n }\n walkFragment(node.body, source, parseScriptFn)\n walkFragment(node.fallback, source, parseScriptFn)\n break\n\n case 'AwaitBlock':\n extractExpression(node.expression, source, parseScriptFn)\n walkFragment(node.pending, source, parseScriptFn)\n walkFragment(node.then, source, parseScriptFn)\n walkFragment(node.catch, source, parseScriptFn)\n break\n\n case 'KeyBlock':\n extractExpression(node.expression, source, parseScriptFn)\n walkFragment(node.fragment, source, parseScriptFn)\n break\n\n case 'SnippetBlock':\n walkFragment(node.body, source, parseScriptFn)\n break\n\n case 'RegularElement':\n case 'Component':\n case 'SvelteComponent':\n case 'SvelteElement':\n case 'SvelteHead':\n case 'SvelteBody':\n case 'SvelteWindow':\n case 'SvelteDocument':\n case 'SlotElement':\n case 'SvelteSelf':\n case 'SvelteFragment':\n if (node.type === 'Component') {\n extractMessageComponent(node, source, parseScriptFn)\n }\n // Process attributes\n if (node.attributes) {\n for (const attr of node.attributes) {\n if (attr.type === 'Attribute') {\n if (Array.isArray(attr.value)) {\n for (const v of attr.value) {\n if (v.type === 'ExpressionTag') {\n extractExpression(v.expression, source, parseScriptFn)\n }\n }\n } else if (\n typeof attr.value === 'object' &&\n attr.value !== null &&\n attr.value.type === 'ExpressionTag'\n ) {\n extractExpression(attr.value.expression, source, parseScriptFn)\n }\n } else if (attr.type === 'SpreadAttribute') {\n extractExpression(attr.expression, source, parseScriptFn)\n } else if (attr.expression) {\n // Directive nodes (OnDirective, BindDirective, etc.)\n extractExpression(attr.expression, source, parseScriptFn)\n }\n }\n }\n // Process children\n walkFragment(node.fragment, source, parseScriptFn)\n break\n }\n}\n\nexport function parseFile(\n source: string,\n filename: string,\n parseScriptFn: ScriptParseFn\n): void {\n const ast = parse(source, {modern: true, filename})\n\n // Walk the template fragment\n walkFragment(ast.fragment as unknown as SvelteNode, source, parseScriptFn)\n\n // Process <script> block\n if (ast.instance) {\n const program = ast.instance.content as unknown as SvelteNode\n parseScriptFn(source.slice(program.start, program.end), program.start)\n }\n\n // Process <script context=\"module\"> / <script module> block\n if (ast.module) {\n const program = ast.module.content as unknown as SvelteNode\n parseScriptFn(source.slice(program.start, program.end), program.start)\n }\n}\n"],"mappings":";;AAeA,MAAM,2CAA2B,IAAI,IAAI;CACvC;CACA;CACA;AACF,CAAC;AAED,SAAS,kBAAkB,MAAuB;CAChD,OAAO,qBAAqB,KAAK,IAAI;AACvC;AAEA,SAAS,aACP,UACA,QACA,eACM;CACN,IAAI,CAAC,YAAY,CAAC,SAAS,OACzB;CAEF,KAAK,MAAM,QAAQ,SAAS,OAC1B,SAAS,MAAM,QAAQ,aAAa;AAExC;AAEA,SAAS,kBACP,YACA,QACA,eACM;CACN,IAAI,CAAC,cAAc,WAAW,SAAS,QAAQ,WAAW,OAAO,MAC/D;CAEF,MAAM,UAAU,OAAO,MAAM,WAAW,OAAO,WAAW,GAAG;CAC7D,IAAI;EACF,cAAc,IAAI,QAAQ,IAAI,WAAW,OAAO,CAAC;CACnD,SAAS,GAAG;EACV,QAAQ,KACN,oBAAoB,QAAQ,uDAC5B,CACF;CACF;AACF;AAEA,SAAS,wBAAwB,OAA2B;CAC1D,OAAO,MAAM,QAAQ,MAAM,OAAO;AACpC;AAEA,SAAS,uBACP,MACA,QACoB;CACpB,IAAI,KAAK,UAAU,QAAQ,KAAK,SAAS,MACvC;CAGF,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,GAAG;EAC9B,IAAI,KAAK,MAAM,SAAS,iBACtB,OAAO,OAAO,MACZ,KAAK,MAAM,WAAW,OACtB,KAAK,MAAM,WAAW,GACxB;EAEF;CACF;CAEA,IAAI,CAAC,KAAK,MAAM,QACd,OAAO;CAGT,IAAI,KAAK,MAAM,WAAW,GAAG;EAC3B,MAAM,CAAC,SAAS,KAAK;EACrB,IAAI,MAAM,SAAS,iBACjB,OAAO,OAAO,MAAM,MAAM,WAAW,OAAO,MAAM,WAAW,GAAG;EAElE,OAAO,KA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MAAM,MAAM,QAAQ;EAAC,QAAQ;EAAM;CAAQ,CAAC;CAGlD,aAAa,IAAI,UAAmC,QAAQ,aAAa;CAGzE,IAAI,IAAI,UAAU;EAChB,MAAM,UAAU,IAAI,SAAS;EAC7B,cAAc,OAAO,MAAM,QAAQ,OAAO,QAAQ,GAAG,GAAG,QAAQ,KAAK;CACvE;CAGA,IAAI,IAAI,QAAQ;EACd,MAAM,UAAU,IAAI,OAAO;EAC3B,cAAc,OAAO,MAAM,QAAQ,OAAO,QAAQ,GAAG,GAAG,QAAQ,KAAK;CACvE;AACF"}
1
+ {"version":3,"file":"svelte_extractor-CEd4aBBk.js","names":[],"sources":["sources/packages/cli-lib/svelte_extractor.ts"],"sourcesContent":["import {parse} from 'svelte/compiler'\n\nexport type ScriptParseFn = (\n source: string,\n sourceOffset?: number,\n wrapperOffset?: number\n) => void\n\ninterface SvelteNode {\n type: string\n start: number\n end: number\n [key: string]: any\n}\n\nconst MESSAGE_DESCRIPTOR_PROPS = new Set([\n 'id',\n 'defaultMessage',\n 'description',\n])\n\nfunction isValidIdentifier(name: string): boolean {\n return /^[$A-Z_a-z][$\\w]*$/.test(name)\n}\n\nfunction walkFragment(\n fragment: SvelteNode | null | undefined,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (!fragment || !fragment.nodes) {\n return\n }\n for (const node of fragment.nodes) {\n walkNode(node, source, parseScriptFn)\n }\n}\n\nfunction extractExpression(\n expression: SvelteNode | null | undefined,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (!expression || expression.start == null || expression.end == null) {\n return\n }\n const content = source.slice(expression.start, expression.end)\n try {\n parseScriptFn(`(${content})`, expression.start, 1)\n } catch (e) {\n console.warn(\n `Failed to parse \"${content}\". Ignore this if content has no extractable message`,\n e\n )\n }\n}\n\nfunction getStringAttributeValue(value: SvelteNode): string {\n return value.data ?? value.raw ?? ''\n}\n\nfunction getAttributeExpression(\n attr: SvelteNode,\n source: string\n): string | undefined {\n if (attr.value === true || attr.value == null) {\n return undefined\n }\n\n if (!Array.isArray(attr.value)) {\n if (attr.value.type === 'ExpressionTag') {\n return source.slice(\n attr.value.expression.start,\n attr.value.expression.end\n )\n }\n return undefined\n }\n\n if (!attr.value.length) {\n return '\"\"'\n }\n\n if (attr.value.length === 1) {\n const [value] = attr.value\n if (value.type === 'ExpressionTag') {\n return source.slice(value.expression.start, value.expression.end)\n }\n return JSON.stringify(getStringAttributeValue(value))\n }\n\n let staticValue = ''\n for (const value of attr.value) {\n if (value.type === 'ExpressionTag') {\n return undefined\n }\n staticValue += getStringAttributeValue(value)\n }\n return JSON.stringify(staticValue)\n}\n\nfunction extractMessageComponent(\n node: SvelteNode,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n if (typeof node.name !== 'string' || !isValidIdentifier(node.name)) {\n return\n }\n\n const attributes: string[] = []\n for (const attr of node.attributes || []) {\n if (\n attr.type !== 'Attribute' ||\n typeof attr.name !== 'string' ||\n !MESSAGE_DESCRIPTOR_PROPS.has(attr.name)\n ) {\n continue\n }\n\n const expression = getAttributeExpression(attr, source)\n if (expression != null) {\n attributes.push(`${attr.name}={${expression}}`)\n }\n }\n\n if (!attributes.length) {\n return\n }\n\n try {\n parseScriptFn(`<${node.name} ${attributes.join(' ')} />`)\n } catch (e) {\n console.warn(\n `Failed to parse ${node.name} message component. Ignore this if component has no extractable message`,\n e\n )\n }\n}\n\nfunction walkNode(\n node: SvelteNode,\n source: string,\n parseScriptFn: ScriptParseFn\n): void {\n switch (node.type) {\n case 'ExpressionTag':\n extractExpression(node.expression, source, parseScriptFn)\n break\n\n case 'ConstTag':\n // {@const x = expr} — the declaration contains the expression\n if (node.declaration) {\n const content = source.slice(\n node.declaration.start,\n node.declaration.end\n )\n try {\n parseScriptFn(content, node.declaration.start)\n } catch (e) {\n console.warn(\n `Failed to parse const declaration. Ignore this if content has no extractable message`,\n e\n )\n }\n }\n break\n\n case 'IfBlock':\n extractExpression(node.test, source, parseScriptFn)\n walkFragment(node.consequent, source, parseScriptFn)\n walkFragment(node.alternate, source, parseScriptFn)\n break\n\n case 'EachBlock':\n extractExpression(node.expression, source, parseScriptFn)\n if (node.key) {\n extractExpression(node.key, source, parseScriptFn)\n }\n walkFragment(node.body, source, parseScriptFn)\n walkFragment(node.fallback, source, parseScriptFn)\n break\n\n case 'AwaitBlock':\n extractExpression(node.expression, source, parseScriptFn)\n walkFragment(node.pending, source, parseScriptFn)\n walkFragment(node.then, source, parseScriptFn)\n walkFragment(node.catch, source, parseScriptFn)\n break\n\n case 'KeyBlock':\n extractExpression(node.expression, source, parseScriptFn)\n walkFragment(node.fragment, source, parseScriptFn)\n break\n\n case 'SnippetBlock':\n walkFragment(node.body, source, parseScriptFn)\n break\n\n case 'RegularElement':\n case 'Component':\n case 'SvelteComponent':\n case 'SvelteElement':\n case 'SvelteHead':\n case 'SvelteBody':\n case 'SvelteWindow':\n case 'SvelteDocument':\n case 'SlotElement':\n case 'SvelteSelf':\n case 'SvelteFragment':\n if (node.type === 'Component') {\n extractMessageComponent(node, source, parseScriptFn)\n }\n // Process attributes\n if (node.attributes) {\n for (const attr of node.attributes) {\n if (attr.type === 'Attribute') {\n if (Array.isArray(attr.value)) {\n for (const v of attr.value) {\n if (v.type === 'ExpressionTag') {\n extractExpression(v.expression, source, parseScriptFn)\n }\n }\n } else if (\n typeof attr.value === 'object' &&\n attr.value !== null &&\n attr.value.type === 'ExpressionTag'\n ) {\n extractExpression(attr.value.expression, source, parseScriptFn)\n }\n } else if (attr.type === 'SpreadAttribute') {\n extractExpression(attr.expression, source, parseScriptFn)\n } else if (attr.expression) {\n // Directive nodes (OnDirective, BindDirective, etc.)\n extractExpression(attr.expression, source, parseScriptFn)\n }\n }\n }\n // Process children\n walkFragment(node.fragment, source, parseScriptFn)\n break\n }\n}\n\nexport function parseFile(\n source: string,\n filename: string,\n parseScriptFn: ScriptParseFn\n): void {\n const ast = parse(source, {modern: true, filename})\n\n // Walk the template fragment\n walkFragment(ast.fragment as unknown as SvelteNode, source, parseScriptFn)\n\n // Process <script> block\n if (ast.instance) {\n const program = ast.instance.content as unknown as SvelteNode\n parseScriptFn(source.slice(program.start, program.end), program.start)\n }\n\n // Process <script context=\"module\"> / <script module> block\n if (ast.module) {\n const program = ast.module.content as unknown as SvelteNode\n parseScriptFn(source.slice(program.start, program.end), program.start)\n }\n}\n"],"mappings":";;AAeA,MAAM,2CAA2B,IAAI,IAAI;CACvC;CACA;CACA;AACF,CAAC;AAED,SAAS,kBAAkB,MAAuB;CAChD,OAAO,qBAAqB,KAAK,IAAI;AACvC;AAEA,SAAS,aACP,UACA,QACA,eACM;CACN,IAAI,CAAC,YAAY,CAAC,SAAS,OACzB;CAEF,KAAK,MAAM,QAAQ,SAAS,OAC1B,SAAS,MAAM,QAAQ,aAAa;AAExC;AAEA,SAAS,kBACP,YACA,QACA,eACM;CACN,IAAI,CAAC,cAAc,WAAW,SAAS,QAAQ,WAAW,OAAO,MAC/D;CAEF,MAAM,UAAU,OAAO,MAAM,WAAW,OAAO,WAAW,GAAG;CAC7D,IAAI;EACF,cAAc,IAAI,QAAQ,IAAI,WAAW,OAAO,CAAC;CACnD,SAAS,GAAG;EACV,QAAQ,KACN,oBAAoB,QAAQ,uDAC5B,CACF;CACF;AACF;AAEA,SAAS,wBAAwB,OAA2B;CAC1D,OAAO,MAAM,QAAQ,MAAM,OAAO;AACpC;AAEA,SAAS,uBACP,MACA,QACoB;CACpB,IAAI,KAAK,UAAU,QAAQ,KAAK,SAAS,MACvC;CAGF,IAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,GAAG;EAC9B,IAAI,KAAK,MAAM,SAAS,iBACtB,OAAO,OAAO,MACZ,KAAK,MAAM,WAAW,OACtB,KAAK,MAAM,WAAW,GACxB;EAEF;CACF;CAEA,IAAI,CAAC,KAAK,MAAM,QACd,OAAO;CAGT,IAAI,KAAK,MAAM,WAAW,GAAG;EAC3B,MAAM,CAAC,SAAS,KAAK;EACrB,IAAI,MAAM,SAAS,iBACjB,OAAO,O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,aAAa;CAErD;AACF;AAEA,SAAgB,UACd,QACA,UACA,eACM;CACN,MAAM,MAAM,MAAM,QAAQ;EAAC,QAAQ;EAAM;CAAQ,CAAC;CAGlD,aAAa,IAAI,UAAmC,QAAQ,aAAa;CAGzE,IAAI,IAAI,UAAU;EAChB,MAAM,UAAU,IAAI,SAAS;EAC7B,cAAc,OAAO,MAAM,QAAQ,OAAO,QAAQ,GAAG,GAAG,QAAQ,KAAK;CACvE;CAGA,IAAI,IAAI,QAAQ;EACd,MAAM,UAAU,IAAI,OAAO;EAC3B,cAAc,OAAO,MAAM,QAAQ,OAAO,QAAQ,GAAG,GAAG,QAAQ,KAAK;CACvE;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { NodeTypes } from "@vue/compiler-core";
2
2
  import { parse } from "vue/compiler-sfc";
3
- //#region packages/cli-lib/vue_extractor.ts
3
+ // packages/cli-lib/vue_extractor.ts
4
4
  function walk(node, visitor) {
5
5
  if (typeof node !== "object" || node == null) return;
6
6
  if (node.type === NodeTypes.ROOT) {
@@ -35,7 +35,6 @@ function parseFile(source, filename, parseScriptFn) {
35
35
  if (script) parseScriptFn(script.content, script.loc.start.offset);
36
36
  if (scriptSetup) parseScriptFn(scriptSetup.content, scriptSetup.loc.start.offset);
37
37
  }
38
- //#endregion
39
38
  export { parseFile };
40
39
 
41
- //# sourceMappingURL=vue_extractor-C6UQIcDj.js.map
40
+ //# sourceMappingURL=vue_extractor-Dzn5fsfZ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vue_extractor-C6UQIcDj.js","names":[],"sources":["sources/packages/cli-lib/vue_extractor.ts"],"sourcesContent":["import {\n NodeTypes,\n type TextNode,\n type CompoundExpressionNode,\n type DirectiveNode,\n type ElementNode,\n type InterpolationNode,\n type RootNode,\n type SimpleExpressionNode,\n type TemplateChildNode,\n} from '@vue/compiler-core'\nimport {parse} from 'vue/compiler-sfc'\n\nexport type ScriptParseFn = (\n source: string,\n sourceOffset?: number,\n wrapperOffset?: number\n) => void\n\nfunction walk(\n node:\n | RootNode\n | TemplateChildNode\n | SimpleExpressionNode\n | CompoundExpressionNode\n | InterpolationNode\n | TextNode\n | string\n | symbol\n | undefined,\n visitor: (\n node:\n | ElementNode\n | InterpolationNode\n | CompoundExpressionNode\n | SimpleExpressionNode\n ) => void\n) {\n if (typeof node !== 'object' || node == null) {\n return\n }\n if (node.type === NodeTypes.ROOT) {\n node.children.forEach(n => walk(n, visitor))\n return\n }\n if (\n node.type !== NodeTypes.ELEMENT &&\n node.type !== NodeTypes.COMPOUND_EXPRESSION &&\n node.type !== NodeTypes.INTERPOLATION\n ) {\n return\n }\n visitor(node)\n if (node.type === NodeTypes.INTERPOLATION) {\n visitor(node.content)\n } else if (node.type === NodeTypes.ELEMENT) {\n node.children.forEach(n => walk(n, visitor))\n node.props\n .filter(\n (prop): prop is DirectiveNode => prop.type === NodeTypes.DIRECTIVE\n )\n .filter(prop => !!prop.exp)\n .forEach(prop => visitor(prop.exp!))\n } else {\n node.children.forEach(n => walk(n, visitor))\n }\n}\n\nfunction templateSimpleExpressionNodeVisitor(parseScriptFn: ScriptParseFn) {\n return (\n n:\n | ElementNode\n | CompoundExpressionNode\n | CompoundExpressionNode['children'][0]\n ) => {\n if (typeof n !== 'object') {\n return\n }\n if (n.type !== NodeTypes.SIMPLE_EXPRESSION) {\n return\n }\n\n const {content, loc} = n as SimpleExpressionNode\n // Wrap this in () since a vue comp node attribute can just be\n // an object literal which, by itself is invalid TS\n // but with () it becomes an ExpressionStatement\n try {\n parseScriptFn(`(${content})`, loc.start.offset, 1)\n } catch (e) {\n console.warn(\n `Failed to parse \"${content}\". Ignore this if content has no extractable message`,\n e\n )\n }\n }\n}\n\nexport function parseFile(\n source: string,\n filename: string,\n parseScriptFn: ScriptParseFn\n): void {\n const {descriptor, errors} = parse(source, {\n filename,\n })\n if (errors.length) {\n throw errors[0]\n }\n const {script, scriptSetup, template} = descriptor\n\n if (template) {\n walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn))\n }\n\n if (script) {\n parseScriptFn(script.content, script.loc.start.offset)\n }\n\n if (scriptSetup) {\n parseScriptFn(scriptSetup.content, scriptSetup.loc.start.offset)\n }\n}\n"],"mappings":";;;AAmBA,SAAS,KACP,MAUA,SAOA;CACA,IAAI,OAAO,SAAS,YAAY,QAAQ,MACtC;CAEF,IAAI,KAAK,SAAS,UAAU,MAAM;EAChC,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;EAC3C;CACF;CACA,IACE,KAAK,SAAS,UAAU,WACxB,KAAK,SAAS,UAAU,uBACxB,KAAK,SAAS,UAAU,eAExB;CAEF,QAAQ,IAAI;CACZ,IAAI,KAAK,SAAS,UAAU,eAC1B,QAAQ,KAAK,OAAO;MACf,IAAI,KAAK,SAAS,UAAU,SAAS;EAC1C,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;EAC3C,KAAK,MACF,QACE,SAAgC,KAAK,SAAS,UAAU,SAC3D,CAAC,CACA,QAAO,SAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,CAC1B,SAAQ,SAAQ,QAAQ,KAAK,GAAI,CAAC;CACvC,OACE,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;AAE/C;AAEA,SAAS,oCAAoC,eAA8B;CACzE,QACE,MAIG;EACH,IAAI,OAAO,MAAM,UACf;EAEF,IAAI,EAAE,SAAS,UAAU,mBACvB;EAGF,MAAM,EAAC,SAAS,QAAO;EAIvB,IAAI;GACF,cAAc,IAAI,QAAQ,IAAI,IAAI,MAAM,QAAQ,CAAC;EACnD,SAAS,GAAG;GACV,QAAQ,KACN,oBAAoB,QAAQ,uDAC5B,CACF;EACF;CACF;AACF;AAEA,SAAgB,UACd,QACA,UACA,eACM;CACN,MAAM,EAAC,YAAY,WAAU,MAAM,QAAQ,EACzC,SACF,CAAC;CACD,IAAI,OAAO,QACT,MAAM,OAAO;CAEf,MAAM,EAAC,QAAQ,aAAa,aAAY;CAExC,IAAI,UACF,KAAK,SAAS,KAAK,oCAAoC,aAAa,CAAC;CAGvE,IAAI,QACF,cAAc,OAAO,SAAS,OAAO,IAAI,MAAM,MAAM;CAGvD,IAAI,aACF,cAAc,YAAY,SAAS,YAAY,IAAI,MAAM,MAAM;AAEnE"}
1
+ {"version":3,"file":"vue_extractor-Dzn5fsfZ.js","names":[],"sources":["sources/packages/cli-lib/vue_extractor.ts"],"sourcesContent":["import {\n NodeTypes,\n type TextNode,\n type CompoundExpressionNode,\n type DirectiveNode,\n type ElementNode,\n type InterpolationNode,\n type RootNode,\n type SimpleExpressionNode,\n type TemplateChildNode,\n} from '@vue/compiler-core'\nimport {parse} from 'vue/compiler-sfc'\n\nexport type ScriptParseFn = (\n source: string,\n sourceOffset?: number,\n wrapperOffset?: number\n) => void\n\nfunction walk(\n node:\n | RootNode\n | TemplateChildNode\n | SimpleExpressionNode\n | CompoundExpressionNode\n | InterpolationNode\n | TextNode\n | string\n | symbol\n | undefined,\n visitor: (\n node:\n | ElementNode\n | InterpolationNode\n | CompoundExpressionNode\n | SimpleExpressionNode\n ) => void\n) {\n if (typeof node !== 'object' || node == null) {\n return\n }\n if (node.type === NodeTypes.ROOT) {\n node.children.forEach(n => walk(n, visitor))\n return\n }\n if (\n node.type !== NodeTypes.ELEMENT &&\n node.type !== NodeTypes.COMPOUND_EXPRESSION &&\n node.type !== NodeTypes.INTERPOLATION\n ) {\n return\n }\n visitor(node)\n if (node.type === NodeTypes.INTERPOLATION) {\n visitor(node.content)\n } else if (node.type === NodeTypes.ELEMENT) {\n node.children.forEach(n => walk(n, visitor))\n node.props\n .filter(\n (prop): prop is DirectiveNode => prop.type === NodeTypes.DIRECTIVE\n )\n .filter(prop => !!prop.exp)\n .forEach(prop => visitor(prop.exp!))\n } else {\n node.children.forEach(n => walk(n, visitor))\n }\n}\n\nfunction templateSimpleExpressionNodeVisitor(parseScriptFn: ScriptParseFn) {\n return (\n n:\n | ElementNode\n | CompoundExpressionNode\n | CompoundExpressionNode['children'][0]\n ) => {\n if (typeof n !== 'object') {\n return\n }\n if (n.type !== NodeTypes.SIMPLE_EXPRESSION) {\n return\n }\n\n const {content, loc} = n as SimpleExpressionNode\n // Wrap this in () since a vue comp node attribute can just be\n // an object literal which, by itself is invalid TS\n // but with () it becomes an ExpressionStatement\n try {\n parseScriptFn(`(${content})`, loc.start.offset, 1)\n } catch (e) {\n console.warn(\n `Failed to parse \"${content}\". Ignore this if content has no extractable message`,\n e\n )\n }\n }\n}\n\nexport function parseFile(\n source: string,\n filename: string,\n parseScriptFn: ScriptParseFn\n): void {\n const {descriptor, errors} = parse(source, {\n filename,\n })\n if (errors.length) {\n throw errors[0]\n }\n const {script, scriptSetup, template} = descriptor\n\n if (template) {\n walk(template.ast, templateSimpleExpressionNodeVisitor(parseScriptFn))\n }\n\n if (script) {\n parseScriptFn(script.content, script.loc.start.offset)\n }\n\n if (scriptSetup) {\n parseScriptFn(scriptSetup.content, scriptSetup.loc.start.offset)\n }\n}\n"],"mappings":";;;AAmBA,SAAS,KACP,MAUA,SAOA;CACA,IAAI,OAAO,SAAS,YAAY,QAAQ,MACtC;CAEF,IAAI,KAAK,SAAS,UAAU,MAAM;EAChC,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;EAC3C;CACF;CACA,IACE,KAAK,SAAS,UAAU,WACxB,KAAK,SAAS,UAAU,uBACxB,KAAK,SAAS,UAAU,eAExB;CAEF,QAAQ,IAAI;CACZ,IAAI,KAAK,SAAS,UAAU,eAC1B,QAAQ,KAAK,OAAO;MACf,IAAI,KAAK,SAAS,UAAU,SAAS;EAC1C,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,OAAO,CAAC;EAC3C,KAAK,MACF,QACE,SAAgC,KAAK,SAAS,UAAU,SAC3D,CAAC,CACA,QAAO,SAAQ,CAAC,CAAC,KAAK,GAAG,CAAC,CAC1B,SAAQ,SAAQ,QAAQ,KAAK,GAAI,CAAC;CACvC,OACE,KAAK,SAAS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