@lingui/cli 5.9.3 → 6.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/api/ProgramExit.js +1 -5
  2. package/dist/api/catalog/extractFromFiles.d.ts +4 -4
  3. package/dist/api/catalog/extractFromFiles.js +38 -32
  4. package/dist/api/catalog/getCatalogDependentFiles.d.ts +1 -1
  5. package/dist/api/catalog/getCatalogDependentFiles.js +8 -47
  6. package/dist/api/catalog/getCatalogs.d.ts +2 -2
  7. package/dist/api/catalog/getCatalogs.js +35 -44
  8. package/dist/api/catalog/getFallbackListForLocale.js +5 -8
  9. package/dist/api/catalog/getTranslationsForCatalog.d.ts +1 -1
  10. package/dist/api/catalog/getTranslationsForCatalog.js +9 -13
  11. package/dist/api/catalog/mergeCatalog.d.ts +3 -3
  12. package/dist/api/catalog/mergeCatalog.js +13 -21
  13. package/dist/api/catalog.d.ts +15 -15
  14. package/dist/api/catalog.js +48 -45
  15. package/dist/api/compile/compileLocale.d.ts +3 -3
  16. package/dist/api/compile/compileLocale.js +28 -33
  17. package/dist/api/compile.js +13 -49
  18. package/dist/api/extractors/babel.d.ts +20 -4
  19. package/dist/api/extractors/babel.js +66 -56
  20. package/dist/api/extractors/index.js +16 -13
  21. package/dist/api/formats/formatterWrapper.d.ts +2 -2
  22. package/dist/api/formats/formatterWrapper.js +10 -12
  23. package/dist/api/formats/index.d.ts +3 -4
  24. package/dist/api/formats/index.js +5 -44
  25. package/dist/api/getPathsForCompileWatcher.d.ts +7 -0
  26. package/dist/api/getPathsForCompileWatcher.js +15 -0
  27. package/dist/api/getPathsForExtractWatcher.d.ts +8 -0
  28. package/dist/api/getPathsForExtractWatcher.js +14 -0
  29. package/dist/api/help.js +5 -7
  30. package/dist/api/index.d.ts +7 -7
  31. package/dist/api/index.js +7 -36
  32. package/dist/api/logger.d.ts +1 -1
  33. package/dist/api/logger.js +1 -2
  34. package/dist/api/messages.d.ts +2 -2
  35. package/dist/api/messages.js +5 -12
  36. package/dist/api/pseudoLocalize.js +3 -9
  37. package/dist/api/resolveWorkersOptions.js +3 -9
  38. package/dist/api/rethrownError.js +2 -5
  39. package/dist/api/stats.d.ts +3 -2
  40. package/dist/api/stats.js +7 -16
  41. package/dist/api/typedPool.d.ts +6 -0
  42. package/dist/api/typedPool.js +16 -0
  43. package/dist/api/types.js +1 -2
  44. package/dist/api/utils.d.ts +2 -2
  45. package/dist/api/utils.js +24 -41
  46. package/dist/api/workerLogger.d.ts +2 -2
  47. package/dist/api/workerLogger.js +2 -8
  48. package/dist/api/workerPools.d.ts +3 -0
  49. package/dist/api/workerPools.js +7 -0
  50. package/dist/extract-experimental/buildIncludeDepsFilter.js +1 -4
  51. package/dist/extract-experimental/bundleSource.d.ts +3 -2
  52. package/dist/extract-experimental/bundleSource.js +10 -13
  53. package/dist/extract-experimental/constants.js +2 -5
  54. package/dist/extract-experimental/extractFromBundleAndWrite.d.ts +3 -4
  55. package/dist/extract-experimental/extractFromBundleAndWrite.js +9 -22
  56. package/dist/extract-experimental/getExperimentalCatalogs.d.ts +4 -3
  57. package/dist/extract-experimental/getExperimentalCatalogs.js +10 -15
  58. package/dist/extract-experimental/linguiEsbuildPlugin.js +12 -19
  59. package/dist/extract-experimental/resolveCatalogPath.d.ts +1 -1
  60. package/dist/extract-experimental/resolveCatalogPath.js +7 -14
  61. package/dist/extract-experimental/resolveTemplatePath.js +7 -10
  62. package/dist/extract-experimental/workers/extractWorker.d.ts +5 -3
  63. package/dist/extract-experimental/workers/extractWorker.js +7 -10
  64. package/dist/extract-experimental/workers/extractWorkerWrapper.prod.d.ts +8 -0
  65. package/dist/extract-experimental/workers/extractWorkerWrapper.prod.js +2 -0
  66. package/dist/extract-experimental/writeCatalogs.d.ts +2 -2
  67. package/dist/extract-experimental/writeCatalogs.js +15 -22
  68. package/dist/index.js +1 -5
  69. package/dist/lingui-compile.d.ts +1 -1
  70. package/dist/lingui-compile.js +45 -59
  71. package/dist/lingui-extract-experimental.d.ts +3 -2
  72. package/dist/lingui-extract-experimental.js +58 -62
  73. package/dist/lingui-extract-template.d.ts +5 -4
  74. package/dist/lingui-extract-template.js +25 -27
  75. package/dist/lingui-extract.d.ts +3 -4
  76. package/dist/lingui-extract.js +62 -69
  77. package/dist/lingui.js +5 -10
  78. package/dist/services/translationIO/segment-converters.d.ts +1 -1
  79. package/dist/services/translationIO/segment-converters.js +16 -20
  80. package/dist/services/translationIO/translationio-api.d.ts +11 -7
  81. package/dist/services/translationIO/translationio-api.js +2 -19
  82. package/dist/services/translationIO.d.ts +4 -4
  83. package/dist/services/translationIO.js +28 -35
  84. package/dist/workers/compileWorker.d.ts +8 -11
  85. package/dist/workers/compileWorker.js +30 -36
  86. package/dist/workers/compileWorkerWrapper.prod.d.ts +7 -0
  87. package/dist/workers/compileWorkerWrapper.prod.js +2 -0
  88. package/dist/workers/extractWorker.d.ts +2 -3
  89. package/dist/workers/extractWorker.js +5 -12
  90. package/dist/workers/extractWorkerWrapper.prod.d.ts +6 -0
  91. package/dist/workers/extractWorkerWrapper.prod.js +2 -0
  92. package/package.json +26 -43
  93. package/dist/api/extractWorkerPool.d.ts +0 -1
  94. package/dist/api/extractWorkerPool.js +0 -8
  95. package/dist/api/extractors/typescript.d.ts +0 -3
  96. package/dist/api/extractors/typescript.js +0 -11
  97. package/dist/extract-experimental/getEntryPoints.d.ts +0 -1
  98. package/dist/extract-experimental/getEntryPoints.js +0 -7
@@ -1,20 +1,15 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.command = command;
7
- const picocolors_1 = __importDefault(require("picocolors"));
8
- const chokidar_1 = __importDefault(require("chokidar"));
9
- const commander_1 = require("commander");
10
- const conf_1 = require("@lingui/conf");
11
- const help_1 = require("./api/help");
12
- const api_1 = require("./api");
13
- const compileLocale_1 = require("./api/compile/compileLocale");
14
- const threads_1 = require("threads");
15
- const resolveWorkersOptions_1 = require("./api/resolveWorkersOptions");
16
- const ms_1 = __importDefault(require("ms"));
17
- async function command(config, options) {
1
+ import { styleText } from "node:util";
2
+ import chokidar from "chokidar";
3
+ import { program } from "commander";
4
+ import { getConfig } from "@lingui/conf";
5
+ import { helpRun } from "./api/help.js";
6
+ import { getCatalogs } from "./api/index.js";
7
+ import { compileLocale } from "./api/compile/compileLocale.js";
8
+ import { createCompileWorkerPool } from "./api/workerPools.js";
9
+ import { resolveWorkersOptions, } from "./api/resolveWorkersOptions.js";
10
+ import ms from "ms";
11
+ import { getPathsForCompileWatcher } from "./api/getPathsForCompileWatcher.js";
12
+ export async function command(config, options) {
18
13
  const startTime = Date.now();
19
14
  // Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
20
15
  const doMerge = !!config.catalogsMergePath;
@@ -22,10 +17,10 @@ async function command(config, options) {
22
17
  let errored = false;
23
18
  if (!options.workersOptions.poolSize) {
24
19
  // single threaded
25
- const catalogs = await (0, api_1.getCatalogs)(config);
20
+ const catalogs = await getCatalogs(config);
26
21
  for (const locale of config.locales) {
27
22
  try {
28
- await (0, compileLocale_1.compileLocale)(catalogs, locale, options, config, doMerge, console);
23
+ await compileLocale(catalogs, locale, options, config, doMerge, console);
29
24
  }
30
25
  catch (err) {
31
26
  if (err.name === "ProgramExit") {
@@ -38,39 +33,39 @@ async function command(config, options) {
38
33
  }
39
34
  }
40
35
  else {
41
- if (!config.resolvedConfigPath) {
36
+ const resolvedConfigPath = config.resolvedConfigPath;
37
+ if (!resolvedConfigPath) {
42
38
  throw new Error("Multithreading is only supported when lingui config loaded from file system, not passed by API");
43
39
  }
44
40
  options.verbose &&
45
41
  console.log(`Use worker pool of size ${options.workersOptions.poolSize}`);
46
- const pool = (0, threads_1.Pool)(() => (0, threads_1.spawn)(new threads_1.Worker("./workers/compileWorker")), { size: options.workersOptions.poolSize });
42
+ const pool = createCompileWorkerPool({
43
+ poolSize: options.workersOptions.poolSize,
44
+ });
47
45
  try {
48
- for (const locale of config.locales) {
49
- pool.queue(async (worker) => {
50
- const { logs, error, exitProgram } = await worker.compileLocale(locale, options, doMerge, config.resolvedConfigPath);
51
- if (logs.errors) {
52
- console.error(logs.errors);
53
- }
54
- if (exitProgram) {
55
- errored = true;
56
- return;
57
- }
58
- if (error) {
59
- throw error;
60
- }
61
- });
62
- }
63
- await pool.completed(true);
46
+ await Promise.all(config.locales.map(async (locale) => {
47
+ const { logs, error, exitProgram } = await pool.run(locale, options, doMerge, resolvedConfigPath);
48
+ if (logs.errors) {
49
+ console.error(logs.errors);
50
+ }
51
+ if (exitProgram) {
52
+ errored = true;
53
+ return;
54
+ }
55
+ if (error) {
56
+ throw error;
57
+ }
58
+ }));
64
59
  }
65
60
  finally {
66
- await pool.terminate(true);
61
+ await pool.destroy();
67
62
  }
68
63
  }
69
- console.log(`Done in ${(0, ms_1.default)(Date.now() - startTime)}`);
64
+ console.log(`Done in ${ms(Date.now() - startTime)}`);
70
65
  return !errored;
71
66
  }
72
- if (require.main === module) {
73
- commander_1.program
67
+ if (import.meta.main) {
68
+ program
74
69
  .description("Compile message catalogs to compiled bundle.")
75
70
  .option("--config <path>", "Path to the config file")
76
71
  .option("--strict", "Disable defaults for missing translations")
@@ -84,23 +79,23 @@ if (require.main === module) {
84
79
  .on("--help", function () {
85
80
  console.log("\n Examples:\n");
86
81
  console.log(" # Compile translations and use defaults or message IDs for missing translations");
87
- console.log(` $ ${(0, help_1.helpRun)("compile")}`);
82
+ console.log(` $ ${helpRun("compile")}`);
88
83
  console.log("");
89
84
  console.log(" # Compile translations but fail when there are missing");
90
85
  console.log(" # translations (don't replace missing translations with");
91
86
  console.log(" # default messages or message IDs)");
92
- console.log(` $ ${(0, help_1.helpRun)("compile --strict")}`);
87
+ console.log(` $ ${helpRun("compile --strict")}`);
93
88
  })
94
89
  .parse(process.argv);
95
- const options = commander_1.program.opts();
96
- const config = (0, conf_1.getConfig)({ configPath: options.config });
90
+ const options = program.opts();
91
+ const config = getConfig({ configPath: options.config });
97
92
  let previousRun = Promise.resolve(true);
98
93
  const compile = () => {
99
94
  previousRun = previousRun.then(() => command(config, {
100
95
  verbose: options.watch || options.verbose || false,
101
96
  allowEmpty: !options.strict,
102
97
  failOnCompileError: !!options.strict,
103
- workersOptions: (0, resolveWorkersOptions_1.resolveWorkersOptions)(options),
98
+ workersOptions: resolveWorkersOptions(options),
104
99
  typescript: options.typescript || config.compileNamespace === "ts" || false,
105
100
  namespace: options.namespace, // we want this to be undefined if user does not specify so default can be used
106
101
  outputPrefix: options.outputPrefix,
@@ -118,23 +113,14 @@ if (require.main === module) {
118
113
  };
119
114
  // Check if Watch Mode is enabled
120
115
  if (options.watch) {
121
- console.info(picocolors_1.default.bold("Initializing Watch Mode..."));
116
+ console.info(styleText("bold", "Initializing Watch Mode..."));
122
117
  (async function initWatch() {
123
- const format = await (0, api_1.getFormat)(config.format, config.formatOptions, config.sourceLocale);
124
- const catalogs = await (0, api_1.getCatalogs)(config);
125
- const paths = [];
126
- config.locales.forEach((locale) => {
127
- catalogs.forEach((catalog) => {
128
- paths.push(`${catalog.path
129
- .replace(/{locale}/g, locale)
130
- .replace(/{name}/g, "*")}${format.getCatalogExtension()}`);
131
- });
132
- });
133
- const watcher = chokidar_1.default.watch(paths, {
118
+ const { paths } = await getPathsForCompileWatcher(config);
119
+ const watcher = chokidar.watch(paths, {
134
120
  persistent: true,
135
121
  });
136
122
  const onReady = () => {
137
- console.info(picocolors_1.default.green(picocolors_1.default.bold("Watcher is ready!")));
123
+ console.info(styleText(["green", "bold"], "Watcher is ready!"));
138
124
  watcher
139
125
  .on("add", () => dispatchCompile())
140
126
  .on("change", () => dispatchCompile());
@@ -1,6 +1,6 @@
1
1
  import { LinguiConfigNormalized } from "@lingui/conf";
2
- import { WorkersOptions } from "./api/resolveWorkersOptions";
3
- export type CliExtractTemplateOptions = {
2
+ import { WorkersOptions } from "./api/resolveWorkersOptions.js";
3
+ type CliExtractTemplateOptions = {
4
4
  verbose?: boolean;
5
5
  files?: string[];
6
6
  template?: boolean;
@@ -10,3 +10,4 @@ export type CliExtractTemplateOptions = {
10
10
  workersOptions: WorkersOptions;
11
11
  };
12
12
  export default function command(linguiConfig: LinguiConfigNormalized, options: CliExtractTemplateOptions): Promise<boolean>;
13
+ export {};
@@ -1,30 +1,22 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- var _a;
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.default = command;
8
- const commander_1 = require("commander");
9
- const conf_1 = require("@lingui/conf");
10
- const path_1 = __importDefault(require("path"));
11
- const formats_1 = require("./api/formats");
12
- const promises_1 = __importDefault(require("fs/promises"));
13
- const normalize_path_1 = __importDefault(require("normalize-path"));
14
- const bundleSource_1 = require("./extract-experimental/bundleSource");
15
- const getEntryPoints_1 = require("./extract-experimental/getEntryPoints");
16
- const picocolors_1 = __importDefault(require("picocolors"));
17
- const threads_1 = require("threads");
18
- const resolveWorkersOptions_1 = require("./api/resolveWorkersOptions");
19
- const extractFromBundleAndWrite_1 = require("./extract-experimental/extractFromBundleAndWrite");
20
- async function command(linguiConfig, options) {
21
- var _a;
1
+ import { program } from "commander";
2
+ import { getConfig } from "@lingui/conf";
3
+ import nodepath from "path";
4
+ import { getFormat } from "./api/formats/index.js";
5
+ import fs from "fs/promises";
6
+ import normalizePath from "normalize-path";
7
+ import { bundleSource } from "./extract-experimental/bundleSource.js";
8
+ import { globSync } from "node:fs";
9
+ import { styleText } from "node:util";
10
+ import { resolveWorkersOptions, } from "./api/resolveWorkersOptions.js";
11
+ import { extractFromBundleAndWrite } from "./extract-experimental/extractFromBundleAndWrite.js";
12
+ import { createExtractExperimentalWorkerPool } from "./api/workerPools.js";
13
+ export default async function command(linguiConfig, options) {
22
14
  options.verbose && console.log("Extracting messages from source files…");
23
- const config = (_a = linguiConfig.experimental) === null || _a === void 0 ? void 0 : _a.extractor;
24
- if (!config) {
15
+ const extractorConfig = linguiConfig.experimental?.extractor;
16
+ if (!extractorConfig) {
25
17
  throw new Error("The configuration for experimental extractor is empty. Please read the docs.");
26
18
  }
27
- console.log(picocolors_1.default.yellow([
19
+ console.log(styleText("yellow", [
28
20
  "You have using an experimental feature",
29
21
  "Experimental features are not covered by semver, and may cause unexpected or broken application behavior." +
30
22
  " Use at your own risk.",
@@ -37,61 +29,65 @@ async function command(linguiConfig, options) {
37
29
  // sourcemaps itself doesn't allow to have absolute windows path, because they are not URL compatible.
38
30
  // that's why we store esbuild bundles in .lingui folder
39
31
  const tmpPrefix = ".lingui/";
40
- await promises_1.default.mkdir(tmpPrefix, { recursive: true });
41
- const tempDir = await promises_1.default.mkdtemp(tmpPrefix);
42
- await promises_1.default.rm(tempDir, { recursive: true, force: true });
43
- const bundleResult = await (0, bundleSource_1.bundleSource)(linguiConfig, (0, getEntryPoints_1.getEntryPoints)(config.entries), tempDir, linguiConfig.rootDir);
32
+ await fs.mkdir(tmpPrefix, { recursive: true });
33
+ const tempDir = await fs.mkdtemp(tmpPrefix);
34
+ await fs.rm(tempDir, { recursive: true, force: true });
35
+ const bundleResult = await bundleSource(linguiConfig, extractorConfig, globSync(extractorConfig.entries), tempDir, linguiConfig.rootDir);
44
36
  const stats = [];
45
37
  let commandSuccess = true;
46
38
  if (options.workersOptions.poolSize) {
47
- if (!linguiConfig.resolvedConfigPath) {
39
+ const resolvedConfigPath = linguiConfig.resolvedConfigPath;
40
+ if (!resolvedConfigPath) {
48
41
  throw new Error("Multithreading is only supported when lingui config loaded from file system, not passed by API");
49
42
  }
50
43
  options.verbose &&
51
44
  console.log(`Use worker pool of size ${options.workersOptions.poolSize}`);
52
- const pool = (0, threads_1.Pool)(() => (0, threads_1.spawn)(new threads_1.Worker("./extract-experimental/workers/extractWorker")), { size: options.workersOptions.poolSize });
45
+ const pool = createExtractExperimentalWorkerPool({
46
+ poolSize: options.workersOptions.poolSize,
47
+ });
53
48
  try {
54
- for (const outFile of Object.keys(bundleResult.metafile.outputs)) {
55
- const { entryPoint } = bundleResult.metafile.outputs[outFile];
56
- pool.queue(async (extractFromBundleAndWrite) => {
57
- const { success, stat } = await extractFromBundleAndWrite(linguiConfig.resolvedConfigPath, entryPoint, outFile, config.output, options.template, options.locales || linguiConfig.locales, options.clean, options.overwrite);
58
- commandSuccess && (commandSuccess = success);
49
+ await Promise.all(Object.keys(bundleResult.outputs).map(async (outFile) => {
50
+ const { entryPoint } = bundleResult.outputs[outFile];
51
+ const result = await pool.run(resolvedConfigPath, entryPoint, outFile, extractorConfig.output, options.template || false, options.locales || linguiConfig.locales, options.clean || false, options.overwrite || false);
52
+ commandSuccess &&= result.success;
53
+ if (result.success) {
59
54
  stats.push({
60
- entry: (0, normalize_path_1.default)(path_1.default.relative(linguiConfig.rootDir, entryPoint)),
61
- content: stat,
55
+ entry: normalizePath(nodepath.relative(linguiConfig.rootDir, entryPoint)),
56
+ content: result.stat,
62
57
  });
63
- });
64
- }
65
- await pool.completed();
58
+ }
59
+ }));
66
60
  }
67
61
  finally {
68
- await pool.terminate(true);
62
+ await pool.destroy();
69
63
  }
70
64
  }
71
65
  else {
72
- const format = await (0, formats_1.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
73
- for (const outFile of Object.keys(bundleResult.metafile.outputs)) {
74
- const { entryPoint } = bundleResult.metafile.outputs[outFile];
75
- const { success, stat } = await (0, extractFromBundleAndWrite_1.extractFromBundleAndWrite)({
76
- entryPoint,
66
+ const format = await getFormat(linguiConfig.format, linguiConfig.sourceLocale);
67
+ for (const outFile of Object.keys(bundleResult.outputs)) {
68
+ const { entryPoint } = bundleResult.outputs[outFile];
69
+ const result = await extractFromBundleAndWrite({
70
+ entryPoint: entryPoint,
77
71
  bundleFile: outFile,
78
- outputPattern: config.output,
72
+ outputPattern: extractorConfig.output,
79
73
  format,
80
74
  linguiConfig,
81
75
  locales: options.locales || linguiConfig.locales,
82
- overwrite: options.overwrite,
83
- clean: options.clean,
84
- template: options.template,
85
- });
86
- commandSuccess && (commandSuccess = success);
87
- stats.push({
88
- entry: (0, normalize_path_1.default)(path_1.default.relative(linguiConfig.rootDir, entryPoint)),
89
- content: stat,
76
+ overwrite: options.overwrite || false,
77
+ clean: options.clean || false,
78
+ template: options.template || false,
90
79
  });
80
+ commandSuccess &&= result.success;
81
+ if (result.success) {
82
+ stats.push({
83
+ entry: normalizePath(nodepath.relative(linguiConfig.rootDir, entryPoint)),
84
+ content: result.stat,
85
+ });
86
+ }
91
87
  }
92
88
  }
93
89
  // cleanup temp directory
94
- await promises_1.default.rm(tempDir, { recursive: true, force: true });
90
+ await fs.rm(tempDir, { recursive: true, force: true });
95
91
  stats
96
92
  .sort((a, b) => a.entry.localeCompare(b.entry))
97
93
  .forEach(({ entry, content }) => {
@@ -99,8 +95,8 @@ async function command(linguiConfig, options) {
99
95
  });
100
96
  return commandSuccess;
101
97
  }
102
- if (require.main === module) {
103
- commander_1.program
98
+ if (import.meta.main) {
99
+ program
104
100
  .option("--config <path>", "Path to the config file")
105
101
  .option("--template", "Extract to template")
106
102
  .option("--overwrite", "Overwrite translations for source locale")
@@ -109,17 +105,17 @@ if (require.main === module) {
109
105
  .option("--verbose", "Verbose output")
110
106
  .option("--workers <n>", "Number of worker threads to use (default: CPU count - 1, capped at 8). Pass `--workers 1` to disable worker threads and run everything in a single process")
111
107
  .parse(process.argv);
112
- const options = commander_1.program.opts();
113
- const config = (0, conf_1.getConfig)({
108
+ const options = program.opts();
109
+ const config = getConfig({
114
110
  configPath: options.config,
115
111
  });
116
112
  const result = command(config, {
117
113
  verbose: options.verbose || false,
118
114
  template: options.template,
119
- locales: (_a = options.locale) === null || _a === void 0 ? void 0 : _a.split(","),
115
+ locales: options.locale?.split(","),
120
116
  overwrite: options.overwrite,
121
117
  clean: options.clean,
122
- workersOptions: (0, resolveWorkersOptions_1.resolveWorkersOptions)(options),
118
+ workersOptions: resolveWorkersOptions(options),
123
119
  }).then(() => {
124
120
  if (!result)
125
121
  process.exit(1);
@@ -1,8 +1,9 @@
1
1
  import { LinguiConfigNormalized } from "@lingui/conf";
2
- import { WorkersOptions } from "./api/resolveWorkersOptions";
3
- export type CliExtractTemplateOptions = {
4
- verbose: boolean;
2
+ import { WorkersOptions } from "./api/resolveWorkersOptions.js";
3
+ type CliExtractTemplateOptions = {
4
+ verbose?: boolean;
5
5
  files?: string[];
6
6
  workersOptions: WorkersOptions;
7
7
  };
8
- export default function command(config: LinguiConfigNormalized, options: Partial<CliExtractTemplateOptions>): Promise<boolean>;
8
+ export default function command(config: LinguiConfigNormalized, options: CliExtractTemplateOptions): Promise<boolean>;
9
+ export {};
@@ -1,61 +1,59 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = command;
7
- const picocolors_1 = __importDefault(require("picocolors"));
8
- const commander_1 = require("commander");
9
- const conf_1 = require("@lingui/conf");
10
- const api_1 = require("./api");
11
- const path_1 = __importDefault(require("path"));
12
- const normalize_path_1 = __importDefault(require("normalize-path"));
13
- const extractWorkerPool_1 = require("./api/extractWorkerPool");
14
- const resolveWorkersOptions_1 = require("./api/resolveWorkersOptions");
15
- async function command(config, options) {
1
+ import { styleText } from "node:util";
2
+ import { program } from "commander";
3
+ import { getConfig } from "@lingui/conf";
4
+ import { getCatalogs } from "./api/index.js";
5
+ import nodepath from "path";
6
+ import normalizePath from "normalize-path";
7
+ import { createExtractWorkerPool, } from "./api/workerPools.js";
8
+ import { resolveWorkersOptions, } from "./api/resolveWorkersOptions.js";
9
+ export default async function command(config, options) {
16
10
  options.verbose && console.log("Extracting messages from source files…");
17
- const catalogs = await (0, api_1.getCatalogs)(config);
11
+ const catalogs = await getCatalogs(config);
18
12
  const catalogStats = {};
19
13
  let commandSuccess = true;
20
14
  let workerPool;
21
15
  if (options.workersOptions.poolSize) {
22
16
  options.verbose &&
23
17
  console.log(`Use worker pool of size ${options.workersOptions.poolSize}`);
24
- workerPool = (0, extractWorkerPool_1.createExtractWorkerPool)(options.workersOptions);
18
+ workerPool = createExtractWorkerPool(options.workersOptions);
25
19
  }
26
20
  try {
27
21
  await Promise.all(catalogs.map(async (catalog) => {
28
- const result = await catalog.makeTemplate(Object.assign(Object.assign({}, options), { orderBy: config.orderBy, workerPool }));
22
+ const result = await catalog.makeTemplate({
23
+ ...options,
24
+ orderBy: config.orderBy,
25
+ workerPool,
26
+ });
29
27
  if (result) {
30
- catalogStats[(0, normalize_path_1.default)(path_1.default.relative(config.rootDir, catalog.templateFile))] = Object.keys(result).length;
28
+ catalogStats[normalizePath(nodepath.relative(config.rootDir, catalog.templateFile))] = Object.keys(result).length;
31
29
  }
32
- commandSuccess && (commandSuccess = Boolean(result));
30
+ commandSuccess &&= Boolean(result);
33
31
  }));
34
32
  }
35
33
  finally {
36
34
  if (workerPool) {
37
- await workerPool.terminate(true);
35
+ await workerPool.destroy();
38
36
  }
39
37
  }
40
38
  Object.entries(catalogStats).forEach(([key, value]) => {
41
- console.log(`Catalog statistics for ${picocolors_1.default.bold(key)}: ${picocolors_1.default.green(value)} messages`);
39
+ console.log(`Catalog statistics for ${styleText("bold", key)}: ${styleText("green", String(value))} messages`);
42
40
  console.log();
43
41
  });
44
42
  return commandSuccess;
45
43
  }
46
- if (require.main === module) {
47
- commander_1.program
44
+ if (import.meta.main) {
45
+ program
48
46
  .option("--config <path>", "Path to the config file")
49
47
  .option("--verbose", "Verbose output")
50
48
  .option("--workers <n>", "Number of worker threads to use (default: CPU count - 1, capped at 8). Pass `--workers 1` to disable worker threads and run everything in a single process")
51
49
  .parse(process.argv);
52
- const options = commander_1.program.opts();
53
- const config = (0, conf_1.getConfig)({
50
+ const options = program.opts();
51
+ const config = getConfig({
54
52
  configPath: options.config,
55
53
  });
56
54
  const result = command(config, {
57
55
  verbose: options.verbose || false,
58
- workersOptions: (0, resolveWorkersOptions_1.resolveWorkersOptions)(options),
56
+ workersOptions: resolveWorkersOptions(options),
59
57
  }).then(() => {
60
58
  if (!result)
61
59
  process.exit(1);
@@ -1,13 +1,12 @@
1
1
  import { LinguiConfigNormalized } from "@lingui/conf";
2
- import { WorkersOptions } from "./api/resolveWorkersOptions";
2
+ import { WorkersOptions } from "./api/resolveWorkersOptions.js";
3
3
  export type CliExtractOptions = {
4
4
  verbose: boolean;
5
5
  files?: string[];
6
6
  clean: boolean;
7
7
  overwrite: boolean;
8
- locale: string[];
9
- prevFormat: string | null;
8
+ locale?: string[];
10
9
  watch?: boolean;
11
10
  workersOptions: WorkersOptions;
12
11
  };
13
- export default function command(config: LinguiConfigNormalized, options: Partial<CliExtractOptions>): Promise<boolean>;
12
+ export default function command(config: LinguiConfigNormalized, options: CliExtractOptions): Promise<boolean>;