@formatjs/cli-lib 8.7.1 → 8.7.4

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,5 +1,5 @@
1
- import { t as parseScript } from "./parse_script-EspfGgzZ.js";
2
- import { parseFile as parseFile$1 } from "./hbs_extractor-Eiqkz4d7.js";
1
+ import { t as parseScript } from "./parse_script-B0J5TKud.js";
2
+ import { parseFile as parseFile$1 } from "./hbs_extractor-DdiPqGGL.js";
3
3
  import { Preprocessor } from "content-tag";
4
4
  //#region packages/cli-lib/gts_extractor.ts
5
5
  let p = new Preprocessor();
@@ -11,4 +11,4 @@ function parseFile(source, fileName, options) {
11
11
  //#endregion
12
12
  export { parseFile };
13
13
 
14
- //# sourceMappingURL=gts_extractor-Dc-C_f4R.js.map
14
+ //# sourceMappingURL=gts_extractor-DoWZ6UQJ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gts_extractor-Dc-C_f4R.js","names":[],"sources":["../gts_extractor.ts"],"sourcesContent":["import {Preprocessor} from 'content-tag'\nimport {parseFile as parseHbsFile} from '#packages/cli-lib/hbs_extractor.js'\nimport {parseScript} from '#packages/cli-lib/parse_script.js'\nlet p = new Preprocessor()\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const scriptParseFn = parseScript(options, fileName)\n const transformedSource = p.process(source, {filename: fileName})\n\n scriptParseFn(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,cAAc;AAE1B,SAAgB,UACd,QACA,UACA,SACM;CAIN,YAHkC,SAAS,SAG9B,CAFa,EAAE,QAAQ,QAAQ,EAAC,UAAU,UAAS,CAEjC,CAAC,KAAK;CAGrC,MAAM,cAAc,EAAE,MAAM,QAAQ,EAAC,UAAU,UAAS,CAAC;CAEzD,KAAK,IAAI,UAAU,aACjB,YAAa,OAAO,UAAU,UAAU,QAAQ"}
1
+ {"version":3,"file":"gts_extractor-DoWZ6UQJ.js","names":[],"sources":["../gts_extractor.ts"],"sourcesContent":["import {Preprocessor} from 'content-tag'\nimport {parseFile as parseHbsFile} from '#packages/cli-lib/hbs_extractor.js'\nimport {parseScript} from '#packages/cli-lib/parse_script.js'\nlet p = new Preprocessor()\n\nexport function parseFile(\n source: string,\n fileName: string,\n options: any\n): void {\n const scriptParseFn = parseScript(options, fileName)\n const transformedSource = p.process(source, {filename: fileName})\n\n scriptParseFn(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,SACM;CAIN,YAHkC,SAAS,QAG/B,EAFc,EAAE,QAAQ,QAAQ,EAAC,UAAU,SAAQ,CAEjC,EAAE,IAAI;CAGpC,MAAM,cAAc,EAAE,MAAM,QAAQ,EAAC,UAAU,SAAQ,CAAC;CAExD,KAAK,IAAI,UAAU,aACjB,YAAa,OAAO,UAAU,UAAU,OAAO;AAEnD"}
@@ -32,4 +32,4 @@ function parseFile(source, fileName, options) {
32
32
  //#endregion
33
33
  export { parseFile };
34
34
 
35
- //# sourceMappingURL=hbs_extractor-Eiqkz4d7.js.map
35
+ //# sourceMappingURL=hbs_extractor-DdiPqGGL.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hbs_extractor-Eiqkz4d7.js","names":[],"sources":["../hbs_extractor.ts"],"sourcesContent":["import {type Opts} from '@formatjs/ts-transformer'\nimport {preprocess, traverse, type AST, type ASTv1} from '@glimmer/syntax'\n\nfunction extractText(\n node: AST.MustacheStatement | AST.SubExpression,\n fileName: string,\n options: Opts\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,gBAAgB,CAAC,SAAS,KAAK,KAAK,SAAS,EAAE;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,MAAM,CAAC,QAAQ,SAAS,IAAI;EAGnD,IAAI,iBAAiB,SAAS,MAAM,CAAC,QAAQ,SAAS,IAAI;EAE1D,IAAI,KACF,OAAO,QAAQ,iBAAiB,WAC5B,QAAQ,eACR,QAAQ,aAAa,KAAA,GAAW,gBAAgB,MAAM,SAAS;EAErE,QAAQ,eAAe,UAAU,CAC/B;GACM;GACY;GAChB,aAAa;GACd,CACF,CAAC;;;AAIN,SAAgB,UACd,QACA,UACA,SACM;CAEN,SADY,WAAW,OACX,EAAE;EACZ,kBAAkB,MAA+B;GAC/C,YAAY,MAAM,UAAU,QAAQ;;EAEtC,cAAc,MAA2B;GACvC,YAAY,MAAM,UAAU,QAAQ;;EAEvC,CAAC"}
1
+ {"version":3,"file":"hbs_extractor-DdiPqGGL.js","names":[],"sources":["../hbs_extractor.ts"],"sourcesContent":["import {type Opts} from '@formatjs/ts-transformer'\nimport {preprocess, traverse, type AST, type ASTv1} from '@glimmer/syntax'\n\nfunction extractText(\n node: AST.MustacheStatement | AST.SubExpression,\n fileName: string,\n options: Opts\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,EAAE,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,EAAE,QAAQ,SAAS,GAAG;EAGlD,IAAI,iBAAiB,SAAS,KAAK,EAAE,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;CAEN,SADY,WAAW,MACZ,GAAG;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.js CHANGED
@@ -1,12 +1,13 @@
1
- import { a as writeStdout, i as warn, n as debug, r as getStdinAsString, t as parseScript } from "./parse_script-EspfGgzZ.js";
1
+ import { a as writeStdout, i as warn, n as debug, r as getStdinAsString, t as parseScript } from "./parse_script-B0J5TKud.js";
2
2
  import { interpolateName } from "@formatjs/ts-transformer";
3
+ import { existsSync } from "fs";
3
4
  import { outputFile } from "fs-extra/esm";
4
5
  import * as stringifyNs from "json-stable-stringify";
5
- import { resolve } from "path";
6
+ import { extname, resolve } from "path";
6
7
  import { pathToFileURL } from "url";
8
+ import { createRequire } from "module";
7
9
  import { readFile } from "fs/promises";
8
10
  import * as glob from "fast-glob";
9
- import { createRequire } from "module";
10
11
  //#region \0rolldown/runtime.js
11
12
  var __defProp = Object.defineProperty;
12
13
  var __exportAll = (all, no_symbols) => {
@@ -159,8 +160,84 @@ async function resolveBuiltinFormatter(format) {
159
160
  }
160
161
  }
161
162
  //#endregion
163
+ //#region packages/cli-lib/native.ts
164
+ const require$1 = createRequire(import.meta.url);
165
+ const NATIVE_PACKAGES = {
166
+ "darwin-arm64": "@formatjs/cli-native-darwin-arm64",
167
+ "linux-arm64": "@formatjs/cli-native-linux-arm64",
168
+ "linux-x64": "@formatjs/cli-native-linux-x64",
169
+ "win32-x64": "@formatjs/cli-native-win32-x64"
170
+ };
171
+ let nativeBinding;
172
+ function loadNative() {
173
+ if (nativeBinding !== void 0) {
174
+ if (nativeBinding) return nativeBinding;
175
+ throw new Error("Native @formatjs/cli-lib binding is unavailable");
176
+ }
177
+ const candidates = [process.env.FORMATJS_CLI_LIB_NATIVE_PATH, NATIVE_PACKAGES[`${process.platform}-${process.arch}`]].filter(Boolean);
178
+ const loadErrors = [];
179
+ for (const candidate of candidates) try {
180
+ nativeBinding = require$1(candidate);
181
+ return nativeBinding;
182
+ } catch (e) {
183
+ loadErrors.push(`${candidate}: ${e.message}`);
184
+ }
185
+ nativeBinding = null;
186
+ throw new Error(`Native @formatjs/cli-lib binding is unavailable.\n${loadErrors.join("\n")}`);
187
+ }
188
+ function compileWithNative(inputFiles, opts = {}) {
189
+ return loadNative().compile(inputFiles, {
190
+ ast: opts.ast,
191
+ format: opts.format,
192
+ followLinks: opts.followLinks,
193
+ ignoreTag: opts.ignoreTag,
194
+ pseudoLocale: opts.pseudoLocale,
195
+ skipErrors: opts.skipErrors
196
+ });
197
+ }
198
+ function compileMessagesWithNative(messages, opts = {}) {
199
+ return loadNative().compileMessages(messages, {
200
+ ast: opts.ast,
201
+ ignoreTag: opts.ignoreTag,
202
+ pseudoLocale: opts.pseudoLocale,
203
+ skipErrors: opts.skipErrors
204
+ });
205
+ }
206
+ function extractWithNative(inputFiles, opts = {}) {
207
+ return loadNative().extract([...inputFiles], {
208
+ additionalComponentNames: opts.additionalComponentNames,
209
+ additionalFunctionNames: opts.additionalFunctionNames,
210
+ extractSourceLocation: opts.extractSourceLocation,
211
+ flatten: opts.flatten,
212
+ followLinks: opts.followLinks,
213
+ format: opts.format,
214
+ idInterpolationPattern: opts.idInterpolationPattern,
215
+ ignore: opts.ignore,
216
+ inFile: opts.inFile,
217
+ pragma: opts.pragma,
218
+ preserveWhitespace: opts.preserveWhitespace,
219
+ throws: opts.throws
220
+ });
221
+ }
222
+ //#endregion
162
223
  //#region packages/cli-lib/extract.ts
163
224
  const stringify$1 = stringifyNs.default || stringifyNs;
225
+ const BUILTIN_FORMATTERS$1 = new Set([
226
+ "default",
227
+ "simple",
228
+ "transifex",
229
+ "smartling",
230
+ "lokalise",
231
+ "crowdin"
232
+ ]);
233
+ const NATIVE_SUPPORTED_EXTENSIONS = new Set([
234
+ ".cjs",
235
+ ".js",
236
+ ".jsx",
237
+ ".mjs",
238
+ ".ts",
239
+ ".tsx"
240
+ ]);
164
241
  function calculateLineColFromOffset(text, start) {
165
242
  if (!start) return {
166
243
  line: 1,
@@ -173,6 +250,12 @@ function calculateLineColFromOffset(text, start) {
173
250
  col: lastLine.length
174
251
  };
175
252
  }
253
+ function isBuiltinFormatter$1(format) {
254
+ return !format || typeof format === "string" && BUILTIN_FORMATTERS$1.has(format);
255
+ }
256
+ function canExtractWithNative(files, opts, readFromStdin) {
257
+ return !readFromStdin && typeof opts.idInterpolationPattern === "string" && !opts.ast && !opts.extractSourceLocation && !opts.onMetaExtracted && !opts.onMsgError && !opts.onMsgExtracted && !opts.overrideIdFn && !opts.pragma && !opts.removeDefaultMessage && isBuiltinFormatter$1(opts.format) && files.every((file) => existsSync(file) && NATIVE_SUPPORTED_EXTENSIONS.has(extname(file).toLowerCase()));
258
+ }
176
259
  async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
177
260
  let messages = [];
178
261
  let meta;
@@ -202,19 +285,19 @@ async function processFile(source, fn, { idInterpolationPattern, ...opts }) {
202
285
  const scriptParseFn = parseScript(opts, fn);
203
286
  if (fn.endsWith(".vue")) {
204
287
  debug("Processing %s using vue extractor", fn);
205
- const { parseFile } = await import("./vue_extractor-Btw05cfG.js");
288
+ const { parseFile } = await import("./vue_extractor-DFGbWp6f.js");
206
289
  parseFile(source, fn, scriptParseFn);
207
290
  } else if (fn.endsWith(".svelte")) {
208
291
  debug("Processing %s using svelte extractor", fn);
209
- const { parseFile } = await import("./svelte_extractor-Fr1Z3JHX.js");
292
+ const { parseFile } = await import("./svelte_extractor-CDRPXblP.js");
210
293
  parseFile(source, fn, scriptParseFn);
211
294
  } else if (fn.endsWith(".hbs")) {
212
295
  debug("Processing %s using hbs extractor", fn);
213
- const { parseFile } = await import("./hbs_extractor-Eiqkz4d7.js");
296
+ const { parseFile } = await import("./hbs_extractor-DdiPqGGL.js");
214
297
  parseFile(source, fn, opts);
215
298
  } else if (fn.endsWith(".gts") || fn.endsWith(".gjs")) {
216
299
  debug("Processing %s as gts/gjs file", fn);
217
- const { parseFile } = await import("./gts_extractor-Dc-C_f4R.js");
300
+ const { parseFile } = await import("./gts_extractor-DoWZ6UQJ.js");
218
301
  parseFile(source, fn, opts);
219
302
  } else {
220
303
  debug("Processing %s using typescript extractor", fn);
@@ -245,6 +328,15 @@ async function extract(files, extractOpts) {
245
328
  throws: shouldThrow,
246
329
  onMsgError: !shouldThrow ? (_, e) => warn(e.message) : void 0
247
330
  };
331
+ if (!signal?.aborted && canExtractWithNative(files, opts, readFromStdin)) return extractWithNative(files, {
332
+ additionalComponentNames: ["$formatMessage", ...opts.additionalComponentNames || []],
333
+ additionalFunctionNames: opts.additionalFunctionNames,
334
+ flatten: opts.flatten,
335
+ format: typeof opts.format === "string" ? opts.format : void 0,
336
+ idInterpolationPattern: opts.idInterpolationPattern,
337
+ preserveWhitespace: opts.preserveWhitespace,
338
+ throws: shouldThrow
339
+ });
248
340
  let rawResults = [];
249
341
  try {
250
342
  if (readFromStdin) {
@@ -322,50 +414,6 @@ async function extractAndWrite(files, extractOpts) {
322
414
  await writeStdout(serializedResult);
323
415
  }
324
416
  //#endregion
325
- //#region packages/cli-lib/native.ts
326
- const require$1 = createRequire(import.meta.url);
327
- const NATIVE_PACKAGES = {
328
- "darwin-arm64": "@formatjs/cli-native-darwin-arm64",
329
- "linux-arm64": "@formatjs/cli-native-linux-arm64",
330
- "linux-x64": "@formatjs/cli-native-linux-x64",
331
- "win32-x64": "@formatjs/cli-native-win32-x64"
332
- };
333
- let nativeBinding;
334
- function loadNative() {
335
- if (nativeBinding !== void 0) {
336
- if (nativeBinding) return nativeBinding;
337
- throw new Error("Native @formatjs/cli-lib binding is unavailable");
338
- }
339
- const candidates = [process.env.FORMATJS_CLI_LIB_NATIVE_PATH, NATIVE_PACKAGES[`${process.platform}-${process.arch}`]].filter(Boolean);
340
- const loadErrors = [];
341
- for (const candidate of candidates) try {
342
- nativeBinding = require$1(candidate);
343
- return nativeBinding;
344
- } catch (e) {
345
- loadErrors.push(`${candidate}: ${e.message}`);
346
- }
347
- nativeBinding = null;
348
- throw new Error(`Native @formatjs/cli-lib binding is unavailable.\n${loadErrors.join("\n")}`);
349
- }
350
- function compileWithNative(inputFiles, opts = {}) {
351
- return loadNative().compile(inputFiles, {
352
- ast: opts.ast,
353
- format: opts.format,
354
- followLinks: opts.followLinks,
355
- ignoreTag: opts.ignoreTag,
356
- pseudoLocale: opts.pseudoLocale,
357
- skipErrors: opts.skipErrors
358
- });
359
- }
360
- function compileMessagesWithNative(messages, opts = {}) {
361
- return loadNative().compileMessages(messages, {
362
- ast: opts.ast,
363
- ignoreTag: opts.ignoreTag,
364
- pseudoLocale: opts.pseudoLocale,
365
- skipErrors: opts.skipErrors
366
- });
367
- }
368
- //#endregion
369
417
  //#region packages/cli-lib/compile.ts
370
418
  const dynamicImport = new Function("specifier", "return import(specifier)");
371
419
  const globSync = glob.sync;
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["format","compile","format","compile","format","compile","format","compile","format","compile","compile","defaultFormatter","transifex","smartling","simple","lokalise","crowdin","stringify","require"],"sources":["../formatters/crowdin.ts","../formatters/default.ts","../formatters/lokalise.ts","../formatters/simple.ts","../formatters/smartling.ts","../formatters/transifex.ts","../formatters/index.ts","../extract.ts","../native.ts","../compile.ts"],"sourcesContent":["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 '@formatjs/ts-transformer'\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 {\n type MessageDescriptor,\n type Opts,\n interpolateName,\n} from '@formatjs/ts-transformer'\nimport {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'\n\nimport {\n type Formatter,\n resolveBuiltinFormatter,\n} from '#packages/cli-lib/formatters/index.js'\nimport {parseScript} from '#packages/cli-lib/parse_script.js'\nimport {readFile} from 'fs/promises'\n\nconst stringify = (stringifyNs as any).default || stringifyNs\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 = Opts & {\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} & Pick<Opts, 'onMsgExtracted' | 'onMetaExtracted'>\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\nasync function processFile(\n source: string,\n fn: string,\n {idInterpolationPattern, ...opts}: Opts & {idInterpolationPattern?: string}\n) {\n let messages: ExtractedMessageDescriptor[] = []\n let meta: Record<string, string> | undefined\n\n const onMsgExtracted = opts.onMsgExtracted\n const onMetaExtracted = opts.onMetaExtracted\n\n opts = {\n ...opts,\n additionalComponentNames: [\n '$formatMessage',\n ...(opts.additionalComponentNames || []),\n ],\n onMsgExtracted(filePath, msgs) {\n if (opts.extractSourceLocation) {\n msgs = msgs.map(msg => ({\n ...msg,\n ...calculateLineColFromOffset(source, msg.start),\n }))\n }\n messages = messages.concat(msgs)\n\n if (onMsgExtracted) {\n onMsgExtracted(filePath, msgs)\n }\n },\n onMetaExtracted(filePath, m) {\n meta = m\n\n if (onMetaExtracted) {\n onMetaExtracted(filePath, m)\n }\n },\n }\n\n if (!opts.overrideIdFn && idInterpolationPattern) {\n opts = {\n ...opts,\n overrideIdFn: (id, defaultMessage, description, fileName) =>\n id ||\n interpolateName(\n {\n resourcePath: fileName,\n } as any,\n idInterpolationPattern,\n {\n content: description\n ? `${defaultMessage}#${\n typeof description === 'string'\n ? description\n : stringify(description)\n }`\n : defaultMessage,\n }\n ),\n }\n }\n\n debug('Processing opts for %s: %s', fn, opts)\n\n const scriptParseFn = parseScript(opts, fn)\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, opts)\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, opts)\n } else {\n debug('Processing %s using typescript 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 }\n return {messages, meta}\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 // When throws is not explicitly true, we want to collect partial results\n const shouldThrow = throws === true\n // Pass throws option to transformer for per-message error handling\n const optsWithThrows = {\n ...opts,\n throws: shouldThrow,\n onMsgError: !shouldThrow\n ? (_: string, e: Error) => warn(e.message)\n : undefined,\n }\n let rawResults: Array<ExtractionResult | undefined> = []\n try {\n if (readFromStdin) {\n debug(`Reading input from stdin`)\n // Read from stdin\n if (process.stdin.isTTY) {\n warn('Reading source file from TTY.')\n }\n const stdinSource = await getStdinAsString()\n rawResults = [await processFile(stdinSource, 'dummy', optsWithThrows)]\n } else {\n // Use Promise.allSettled when throws is not explicitly true to collect partial results\n if (!shouldThrow) {\n const settledResults = await Promise.allSettled(\n files.map(async fn => {\n debug('Extracting file:', fn)\n const source = await readFile(fn, {encoding: 'utf8', signal})\n return processFile(source, fn, optsWithThrows)\n })\n )\n rawResults = settledResults.map(result => {\n if (result.status === 'fulfilled') {\n return result.value\n } else {\n warn(String(result.reason))\n return undefined\n }\n })\n } else {\n rawResults = await Promise.all(\n files.map(async fn => {\n debug('Extracting file:', fn)\n const source = await readFile(fn, {encoding: 'utf8', signal})\n return processFile(source, fn, optsWithThrows)\n })\n )\n }\n }\n } catch (e) {\n if (shouldThrow) {\n throw e\n } else {\n warn(String(e))\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 {createRequire} from 'module'\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': '@formatjs/cli-native-linux-arm64',\n 'linux-x64': '@formatjs/cli-native-linux-x64',\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 NativeBinding {\n compile(inputFiles: string[], opts?: NativeCompileOptions): string\n compileMessages(\n messages: NativeCompileMessage[],\n opts?: NativeCompileOptions\n ): string\n supportedBuiltinFormatters(): string[]\n}\n\nlet nativeBinding: NativeBinding | null | undefined\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 const overridePath = process.env.FORMATJS_CLI_LIB_NATIVE_PATH\n const platformPackage = NATIVE_PACKAGES[`${process.platform}-${process.arch}`]\n const candidates = [overridePath, platformPackage].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","import {outputFile} from 'fs-extra/esm'\nimport {readFile} from 'fs/promises'\nimport * as 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 CompileFn = (msgs: any) => Record<string, string>\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":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAaA,YAAgC,SAAQ;CACnD,MAAM,UAAuB,EAAE;CAC/B,KAAK,MAAM,CAAC,IAAI,QAAQ,OAAO,QAAQ,KAAK,EAC1C,QAAQ,MAAM;EACZ,SAAS,IAAI;EACb,aACE,OAAO,IAAI,gBAAgB,WACvB,IAAI,cACJ,KAAK,UAAU,IAAI,YAAY;EACtC;CAEH,OAAO;;AAGT,MAAaC,aAAkC,SAAQ;CACrD,MAAM,UAAkC,EAAE;CAC1C,KAAK,MAAM,CAAC,IAAI,QAAQ,OAAO,QAAQ,KAAK,EAAE;EAC5C,IAAI,OAAO,aACT;EAEF,QAAQ,MAAM,IAAI;;CAEpB,OAAO;;;;;;;;ACtBT,MAAaC,YAAmB,SAAQ;AAExC,MAAaC,aAAqB,SAAQ;CACxC,MAAM,UAAkC,EAAE;CAC1C,KAAK,MAAM,KAAK,MACd,QAAQ,KAAK,KAAK,GAAG;CAEvB,OAAO;;;;;;;;ACLT,MAAaC,YAAmC,SAAQ;CACtD,MAAM,UAA0B,EAAE;CAClC,KAAK,MAAM,CAAC,IAAI,QAAQ,OAAO,QAAQ,KAAK,EAC1C,QAAQ,MAAM;EACZ,aAAa,IAAI;EACjB,OACE,OAAO,IAAI,gBAAgB,WACvB,IAAI,cACJ,KAAK,UAAU,IAAI,YAAY;EAC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5B,YACA,cAA8B,EAAE,EACjB;CACf,MAAM,EAAC,SAAS,GAAG,SAAQ;CAC3B,MAAM,mBAAoB,MAAM,QAAQ,YAAY,KAAK,GAAI;CAC7D,IAAI,SAAS;EACX,MAAM,wBAAwB,QAAQ;EACtC,OAAO,WAAW,SAAS,iBAAiB;;CAE9C,MAAM,YAAY,iBAAiB"}
1
+ {"version":3,"file":"index.js","names":["format","compile","format","compile","format","compile","format","compile","format","compile","compile","defaultFormatter","transifex","smartling","simple","lokalise","crowdin","require","stringify","BUILTIN_FORMATTERS","isBuiltinFormatter"],"sources":["../formatters/crowdin.ts","../formatters/default.ts","../formatters/lokalise.ts","../formatters/simple.ts","../formatters/smartling.ts","../formatters/transifex.ts","../formatters/index.ts","../native.ts","../extract.ts","../compile.ts"],"sourcesContent":["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 '@formatjs/ts-transformer'\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'\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': '@formatjs/cli-native-linux-arm64',\n 'linux-x64': '@formatjs/cli-native-linux-x64',\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 NativeBinding {\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 supportedBuiltinFormatters(): string[]\n}\n\nlet nativeBinding: NativeBinding | null | undefined\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 const overridePath = process.env.FORMATJS_CLI_LIB_NATIVE_PATH\n const platformPackage = NATIVE_PACKAGES[`${process.platform}-${process.arch}`]\n const candidates = [overridePath, platformPackage].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 extractWithNative(\n inputFiles: readonly string[],\n opts: NativeExtractOptions = {}\n): string {\n const native = loadNative()\n return native.extract([...inputFiles], {\n additionalComponentNames: opts.additionalComponentNames,\n additionalFunctionNames: opts.additionalFunctionNames,\n extractSourceLocation: opts.extractSourceLocation,\n flatten: opts.flatten,\n followLinks: opts.followLinks,\n format: opts.format,\n idInterpolationPattern: opts.idInterpolationPattern,\n ignore: opts.ignore,\n inFile: opts.inFile,\n pragma: opts.pragma,\n preserveWhitespace: opts.preserveWhitespace,\n throws: opts.throws,\n })\n}\n","import {\n type MessageDescriptor,\n type Opts,\n interpolateName,\n} from '@formatjs/ts-transformer'\nimport {existsSync} from 'fs'\nimport {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'\n\nimport {\n type Formatter,\n resolveBuiltinFormatter,\n} from '#packages/cli-lib/formatters/index.js'\nimport {extractWithNative} from '#packages/cli-lib/native.js'\nimport {parseScript} from '#packages/cli-lib/parse_script.js'\nimport {readFile} from 'fs/promises'\n\nconst stringify = (stringifyNs as any).default || stringifyNs\nconst BUILTIN_FORMATTERS = new Set([\n 'default',\n 'simple',\n 'transifex',\n 'smartling',\n 'lokalise',\n 'crowdin',\n])\nconst NATIVE_SUPPORTED_EXTENSIONS = new Set([\n '.cjs',\n '.js',\n '.jsx',\n '.mjs',\n '.ts',\n '.tsx',\n])\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 = Opts & {\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} & Pick<Opts, 'onMsgExtracted' | 'onMetaExtracted'>\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 isBuiltinFormatter(\n format: ExtractOpts['format']\n): format is string | undefined {\n return (\n !format || (typeof format === 'string' && BUILTIN_FORMATTERS.has(format))\n )\n}\n\nfunction canExtractWithNative(\n files: readonly string[],\n opts: Omit<ExtractOpts, 'readFromStdin' | 'signal' | 'throws'>,\n readFromStdin: boolean | undefined\n): boolean {\n return (\n !readFromStdin &&\n typeof opts.idInterpolationPattern === 'string' &&\n !opts.ast &&\n !opts.extractSourceLocation &&\n !opts.onMetaExtracted &&\n !opts.onMsgError &&\n !opts.onMsgExtracted &&\n !opts.overrideIdFn &&\n !opts.pragma &&\n !opts.removeDefaultMessage &&\n isBuiltinFormatter(opts.format) &&\n files.every(\n file =>\n existsSync(file) &&\n NATIVE_SUPPORTED_EXTENSIONS.has(extname(file).toLowerCase())\n )\n )\n}\n\nasync function processFile(\n source: string,\n fn: string,\n {idInterpolationPattern, ...opts}: Opts & {idInterpolationPattern?: string}\n) {\n let messages: ExtractedMessageDescriptor[] = []\n let meta: Record<string, string> | undefined\n\n const onMsgExtracted = opts.onMsgExtracted\n const onMetaExtracted = opts.onMetaExtracted\n\n opts = {\n ...opts,\n additionalComponentNames: [\n '$formatMessage',\n ...(opts.additionalComponentNames || []),\n ],\n onMsgExtracted(filePath, msgs) {\n if (opts.extractSourceLocation) {\n msgs = msgs.map(msg => ({\n ...msg,\n ...calculateLineColFromOffset(source, msg.start),\n }))\n }\n messages = messages.concat(msgs)\n\n if (onMsgExtracted) {\n onMsgExtracted(filePath, msgs)\n }\n },\n onMetaExtracted(filePath, m) {\n meta = m\n\n if (onMetaExtracted) {\n onMetaExtracted(filePath, m)\n }\n },\n }\n\n if (!opts.overrideIdFn && idInterpolationPattern) {\n opts = {\n ...opts,\n overrideIdFn: (id, defaultMessage, description, fileName) =>\n id ||\n interpolateName(\n {\n resourcePath: fileName,\n } as any,\n idInterpolationPattern,\n {\n content: description\n ? `${defaultMessage}#${\n typeof description === 'string'\n ? description\n : stringify(description)\n }`\n : defaultMessage,\n }\n ),\n }\n }\n\n debug('Processing opts for %s: %s', fn, opts)\n\n const scriptParseFn = parseScript(opts, fn)\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, opts)\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, opts)\n } else {\n debug('Processing %s using typescript 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 }\n return {messages, meta}\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 // When throws is not explicitly true, we want to collect partial results\n const shouldThrow = throws === true\n // Pass throws option to transformer for per-message error handling\n const optsWithThrows = {\n ...opts,\n throws: shouldThrow,\n onMsgError: !shouldThrow\n ? (_: string, e: Error) => warn(e.message)\n : undefined,\n }\n\n if (!signal?.aborted && canExtractWithNative(files, opts, readFromStdin)) {\n return extractWithNative(files, {\n additionalComponentNames: [\n '$formatMessage',\n ...(opts.additionalComponentNames || []),\n ],\n additionalFunctionNames: opts.additionalFunctionNames,\n flatten: opts.flatten,\n format: typeof opts.format === 'string' ? opts.format : undefined,\n idInterpolationPattern: opts.idInterpolationPattern,\n preserveWhitespace: opts.preserveWhitespace,\n throws: shouldThrow,\n })\n }\n\n let rawResults: Array<ExtractionResult | undefined> = []\n try {\n if (readFromStdin) {\n debug(`Reading input from stdin`)\n // Read from stdin\n if (process.stdin.isTTY) {\n warn('Reading source file from TTY.')\n }\n const stdinSource = await getStdinAsString()\n rawResults = [await processFile(stdinSource, 'dummy', optsWithThrows)]\n } else {\n // Use Promise.allSettled when throws is not explicitly true to collect partial results\n if (!shouldThrow) {\n const settledResults = await Promise.allSettled(\n files.map(async fn => {\n debug('Extracting file:', fn)\n const source = await readFile(fn, {encoding: 'utf8', signal})\n return processFile(source, fn, optsWithThrows)\n })\n )\n rawResults = settledResults.map(result => {\n if (result.status === 'fulfilled') {\n return result.value\n } else {\n warn(String(result.reason))\n return undefined\n }\n })\n } else {\n rawResults = await Promise.all(\n files.map(async fn => {\n debug('Extracting file:', fn)\n const source = await readFile(fn, {encoding: 'utf8', signal})\n return processFile(source, fn, optsWithThrows)\n })\n )\n }\n }\n } catch (e) {\n if (shouldThrow) {\n throw e\n } else {\n warn(String(e))\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 * as 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;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AAgB;AACpC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/cli-lib",
3
3
  "description": "Lib for CLI for formatjs.",
4
- "version": "8.7.1",
4
+ "version": "8.7.4",
5
5
  "license": "MIT",
6
6
  "author": "Linjie Ding <linjie@airtable.com>",
7
7
  "type": "module",
@@ -23,8 +23,8 @@
23
23
  "loud-rejection": "^2",
24
24
  "typescript": "^5.6 || 6",
25
25
  "@formatjs/icu-skeleton-parser": "2.1.9",
26
- "@formatjs/ts-transformer": "4.4.9",
27
- "@formatjs/icu-messageformat-parser": "3.5.9"
26
+ "@formatjs/ts-transformer": "4.4.11",
27
+ "@formatjs/icu-messageformat-parser": "3.5.10"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@glimmer/syntax": "^0.84.3 || ^0.95.0",
@@ -56,8 +56,8 @@
56
56
  "optionalDependencies": {
57
57
  "@formatjs/cli-native-darwin-arm64": "1.1.0",
58
58
  "@formatjs/cli-native-linux-arm64": "1.2.0",
59
- "@formatjs/cli-native-win32-x64": "1.1.1",
60
- "@formatjs/cli-native-linux-x64": "1.1.0"
59
+ "@formatjs/cli-native-linux-x64": "1.1.0",
60
+ "@formatjs/cli-native-win32-x64": "1.1.1"
61
61
  },
62
62
  "peerDependenciesMeta": {
63
63
  "vue": {
@@ -90,4 +90,4 @@ ${e.message || ""}`;
90
90
  //#endregion
91
91
  export { writeStdout as a, warn as i, debug as n, getStdinAsString as r, parseScript as t };
92
92
 
93
- //# sourceMappingURL=parse_script-EspfGgzZ.js.map
93
+ //# sourceMappingURL=parse_script-B0J5TKud.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse_script-B0J5TKud.js","names":["clearLine"],"sources":["../console_utils.ts","../parse_script.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 {type Opts, transformWithTs} from '@formatjs/ts-transformer'\nimport * as ts from 'typescript'\nimport {debug} from '#packages/cli-lib/console_utils.js'\n/**\n * Invoid TypeScript module transpilation with our TS transformer\n * @param opts Formatjs TS Transformer opt\n * @param fn filename\n */\nexport function parseScript(opts: Opts, fn?: string) {\n return (source: string): void => {\n let output\n try {\n debug('Using TS compiler to process file', fn)\n output = ts.transpileModule(source, {\n compilerOptions: {\n allowJs: true,\n target: ts.ScriptTarget.ESNext,\n noEmit: true,\n experimentalDecorators: true,\n },\n reportDiagnostics: true,\n fileName: fn,\n transformers: {\n before: [transformWithTs(ts, opts)],\n },\n })\n } catch (e) {\n if (e instanceof Error) {\n e.message = `Error processing file ${fn} \n${e.message || ''}`\n }\n throw e\n }\n if (output.diagnostics) {\n const errs = output.diagnostics.filter(\n d => d.category === ts.DiagnosticCategory.Error\n )\n if (errs.length) {\n throw new Error(\n ts.formatDiagnosticsWithColorAndContext(errs, {\n getCanonicalFileName: fileName => fileName,\n getCurrentDirectory: () => process.cwd(),\n getNewLine: () => ts.sys.newLine,\n })\n )\n }\n }\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,mBAAmB;AAEzB,MAAa,cACX,UAAU,QAAQ,OAAO,KAAK,EAAE,KAAK,QAAQ,MAAM;AACrD,MAAa,cACX,UAAU,QAAQ,OAAO,KAAK,EAAE,KAAK,QAAQ,MAAM;AAIrD,eAAsBA,YACpB,UACe;CACf,IAAI,CAAC,SAAS,YAAY;MACpB,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,UACzB,aAAa,QACb,MAAM,YAAY,CACpB,EAAE,IAAI;AACR;AAEA,eAAsB,MAAM,SAAiB,GAAG,MAA4B;CAC1E,IAAI,QAAQ,IAAI,cAAc,SAC5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ACvC,kBAAkB,GAAG,IAAI;GAC3B,CAAC,CACH;EAEJ;CACF;AACF"}
@@ -93,4 +93,4 @@ function parseFile(source, filename, parseScriptFn) {
93
93
  //#endregion
94
94
  export { parseFile };
95
95
 
96
- //# sourceMappingURL=svelte_extractor-Fr1Z3JHX.js.map
96
+ //# sourceMappingURL=svelte_extractor-CDRPXblP.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"svelte_extractor-Fr1Z3JHX.js","names":[],"sources":["../svelte_extractor.ts"],"sourcesContent":["import {parse} from 'svelte/compiler'\n\nexport type ScriptParseFn = (source: string) => void\n\ninterface SvelteNode {\n type: string\n start: number\n end: number\n [key: string]: any\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})`)\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 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)\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 // 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))\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))\n }\n}\n"],"mappings":";;AAWA,SAAS,aACP,UACA,QACA,eACM;CACN,IAAI,CAAC,YAAY,CAAC,SAAS,OACzB;CAEF,KAAK,MAAM,QAAQ,SAAS,OAC1B,SAAS,MAAM,QAAQ,cAAc;;AAIzC,SAAS,kBACP,YACA,QACA,eACM;CACN,IAAI,CAAC,cAAc,WAAW,SAAS,QAAQ,WAAW,OAAO,MAC/D;CAEF,MAAM,UAAU,OAAO,MAAM,WAAW,OAAO,WAAW,IAAI;CAC9D,IAAI;EACF,cAAc,IAAI,QAAQ,GAAG;UACtB,GAAG;EACV,QAAQ,KACN,oBAAoB,QAAQ,uDAC5B,EACD;;;AAIL,SAAS,SACP,MACA,QACA,eACM;CACN,QAAQ,KAAK,MAAb;EACE,KAAK;GACH,kBAAkB,KAAK,YAAY,QAAQ,cAAc;GACzD;EAEF,KAAK;GAEH,IAAI,KAAK,aAAa;IACpB,MAAM,UAAU,OAAO,MACrB,KAAK,YAAY,OACjB,KAAK,YAAY,IAClB;IACD,IAAI;KACF,cAAc,QAAQ;aACf,GAAG;KACV,QAAQ,KACN,wFACA,EACD;;;GAGL;EAEF,KAAK;GACH,kBAAkB,KAAK,MAAM,QAAQ,cAAc;GACnD,aAAa,KAAK,YAAY,QAAQ,cAAc;GACpD,aAAa,KAAK,WAAW,QAAQ,cAAc;GACnD;EAEF,KAAK;GACH,kBAAkB,KAAK,YAAY,QAAQ,cAAc;GACzD,IAAI,KAAK,KACP,kBAAkB,KAAK,KAAK,QAAQ,cAAc;GAEpD,aAAa,KAAK,MAAM,QAAQ,cAAc;GAC9C,aAAa,KAAK,UAAU,QAAQ,cAAc;GAClD;EAEF,KAAK;GACH,kBAAkB,KAAK,YAAY,QAAQ,cAAc;GACzD,aAAa,KAAK,SAAS,QAAQ,cAAc;GACjD,aAAa,KAAK,MAAM,QAAQ,cAAc;GAC9C,aAAa,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compiler'\n\nexport type ScriptParseFn = (source: string) => void\n\ninterface SvelteNode {\n type: string\n start: number\n end: number\n [key: string]: any\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})`)\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 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)\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 // 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))\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))\n }\n}\n"],"mappings":";;AAWA,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,M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,IAAI,KAAK;SACF,MAAM,QAAQ,KAAK,YACtB,IAAI,KAAK,SAAS;SACZ,MAAM,QAAQ,KAAK,KAAK;WACrB,MAAM,KAAK,KAAK,OACnB,IAAI,EAAE,SAAS,iBACb,kBAAkB,EAAE,YAAY,QAAQ,aAAa;KAAA,OAGpD,IACL,OAAO,KAAK,UAAU,YACtB,KAAK,UAAU,QACf,KAAK,MAAM,SAAS,iBAEpB,kBAAkB,KAAK,MAAM,YAAY,QAAQ,aAAa;IAAA,OAE3D,IAAI,KAAK,SAAS,mBACvB,kBAAkB,KAAK,YAAY,QAAQ,aAAa;SACnD,IAAI,KAAK,YAEd,kBAAkB,KAAK,YAAY,QAAQ,aAAa;GAAA;GAK9D,aAAa,KAAK,UAAU,QAAQ,aAAa;GACjD;CACJ;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,CAAC;CACxD;CAGA,IAAI,IAAI,QAAQ;EACd,MAAM,UAAU,IAAI,OAAO;EAC3B,cAAc,OAAO,MAAM,QAAQ,OAAO,QAAQ,GAAG,CAAC;CACxD;AACF"}
@@ -38,4 +38,4 @@ function parseFile(source, filename, parseScriptFn) {
38
38
  //#endregion
39
39
  export { parseFile };
40
40
 
41
- //# sourceMappingURL=vue_extractor-Btw05cfG.js.map
41
+ //# sourceMappingURL=vue_extractor-DFGbWp6f.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vue_extractor-Btw05cfG.js","names":[],"sources":["../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 = (source: string) => 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} = 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})`)\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)\n }\n\n if (scriptSetup) {\n parseScriptFn(scriptSetup.content)\n }\n}\n"],"mappings":";;;AAeA,SAAS,KACP,MAUA,SAOA;CACA,IAAI,OAAO,SAAS,YAAY,QAAQ,MACtC;CAEF,IAAI,KAAK,SAAS,UAAU,MAAM;EAChC,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,QAAQ,CAAC;EAC5C;;CAEF,IACE,KAAK,SAAS,UAAU,WACxB,KAAK,SAAS,UAAU,uBACxB,KAAK,SAAS,UAAU,eAExB;CAEF,QAAQ,KAAK;CACb,IAAI,KAAK,SAAS,UAAU,eAC1B,QAAQ,KAAK,QAAQ;MAChB,IAAI,KAAK,SAAS,UAAU,SAAS;EAC1C,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,QAAQ,CAAC;EAC5C,KAAK,MACF,QACE,SAAgC,KAAK,SAAS,UAAU,UAC1D,CACA,QAAO,SAAQ,CAAC,CAAC,KAAK,IAAI,CAC1B,SAAQ,SAAQ,QAAQ,KAAK,IAAK,CAAC;QAEtC,KAAK,SAAS,SAAQ,MAAK,KAAK,GAAG,QAAQ,CAAC;;AAIhD,SAAS,oCAAoC,eAA8B;CACzE,QACE,MAIG;EACH,IAAI,OAAO,MAAM,UACf;EAEF,IAAI,EAAE,SAAS,UAAU,mBACvB;EAGF,MAAM,EAAC,YAAW;EAIlB,IAAI;GACF,cAAc,IAAI,QAAQ,GAAG;WACtB,GAAG;GACV,QAAQ,KACN,oBAAoB,QAAQ,uDAC5B,EACD;;;;AAKP,SAAgB,UACd,QACA,UACA,eACM;CACN,MAAM,EAAC,YAAY,WAAU,MAAM,QAAQ,EACzC,UACD,CAAC;CACF,IAAI,OAAO,QACT,MAAM,OAAO;CAEf,MAAM,EAAC,QAAQ,aAAa,aAAY;CAExC,IAAI,UACF,KAAK,SAAS,KAAK,oCAAoC,cAAc,CAAC;CAGxE,IAAI,QACF,cAAc,OAAO,QAAQ;CAG/B,IAAI,aACF,cAAc,YAAY,QAAQ"}
1
+ {"version":3,"file":"vue_extractor-DFGbWp6f.js","names":[],"sources":["../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 = (source: string) => 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} = 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})`)\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)\n }\n\n if (scriptSetup) {\n parseScriptFn(scriptSetup.content)\n }\n}\n"],"mappings":";;;AAeA,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,EACC,QAAO,SAAQ,CAAC,CAAC,KAAK,GAAG,EACzB,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,YAAW;EAIlB,IAAI;GACF,cAAc,IAAI,QAAQ,EAAE;EAC9B,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,OAAO;CAG9B,IAAI,aACF,cAAc,YAAY,OAAO;AAErC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse_script-EspfGgzZ.js","names":["clearLine"],"sources":["../console_utils.ts","../parse_script.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 async function error(message: string, ...args: any[]): Promise<void> {\n await clearLine(process.stderr)\n await writeStderr(format(label('error', 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 {type Opts, transformWithTs} from '@formatjs/ts-transformer'\nimport * as ts from 'typescript'\nimport {debug} from '#packages/cli-lib/console_utils.js'\n/**\n * Invoid TypeScript module transpilation with our TS transformer\n * @param opts Formatjs TS Transformer opt\n * @param fn filename\n */\nexport function parseScript(opts: Opts, fn?: string) {\n return (source: string): void => {\n let output\n try {\n debug('Using TS compiler to process file', fn)\n output = ts.transpileModule(source, {\n compilerOptions: {\n allowJs: true,\n target: ts.ScriptTarget.ESNext,\n noEmit: true,\n experimentalDecorators: true,\n },\n reportDiagnostics: true,\n fileName: fn,\n transformers: {\n before: [transformWithTs(ts, opts)],\n },\n })\n } catch (e) {\n if (e instanceof Error) {\n e.message = `Error processing file ${fn} \n${e.message || ''}`\n }\n throw e\n }\n if (output.diagnostics) {\n const errs = output.diagnostics.filter(\n d => d.category === ts.DiagnosticCategory.Error\n )\n if (errs.length) {\n throw new Error(\n ts.formatDiagnosticsWithColorAndContext(errs, {\n getCanonicalFileName: fileName => fileName,\n getCurrentDirectory: () => process.cwd(),\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