@lingui/cli 5.9.2 → 6.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +51 -48
  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 +2 -2
  19. package/dist/api/extractors/babel.js +52 -45
  20. package/dist/api/extractors/index.js +6 -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 +11 -17
  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,2 +1,3 @@
1
- import { LinguiConfigNormalized } from "@lingui/conf";
2
- export declare function bundleSource(linguiConfig: LinguiConfigNormalized, entryPoints: string[], outDir: string, rootDir: string): Promise<import("esbuild").BuildResult<any>>;
1
+ import { ExperimentalExtractorOptions, LinguiConfigNormalized } from "@lingui/conf";
2
+ import { Metafile } from "esbuild";
3
+ export declare function bundleSource(linguiConfig: LinguiConfigNormalized, extractorConfig: ExperimentalExtractorOptions, entryPoints: string[], outDir: string, rootDir: string): Promise<Metafile>;
@@ -1,15 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bundleSource = bundleSource;
4
- const linguiEsbuildPlugin_1 = require("./linguiEsbuildPlugin");
5
- const buildIncludeDepsFilter_1 = require("./buildIncludeDepsFilter");
1
+ import { pluginLinguiMacro } from "./linguiEsbuildPlugin.js";
2
+ import { buildIncludeDepsFilter } from "./buildIncludeDepsFilter.js";
6
3
  function createExtRegExp(extensions) {
7
4
  return new RegExp("\\.(?:" + extensions.join("|") + ")(?:\\?.*)?$");
8
5
  }
9
- async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
6
+ export async function bundleSource(linguiConfig, extractorConfig, entryPoints, outDir, rootDir) {
10
7
  const esbuild = await import("esbuild");
11
- const config = linguiConfig.experimental.extractor;
12
- const excludeExtensions = config.excludeExtensions || [
8
+ const excludeExtensions = extractorConfig.excludeExtensions || [
13
9
  "ico",
14
10
  "pot",
15
11
  "xliff",
@@ -44,16 +40,16 @@ async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
44
40
  sourcesContent: false,
45
41
  metafile: true,
46
42
  plugins: [
47
- (0, linguiEsbuildPlugin_1.pluginLinguiMacro)({ linguiConfig }),
43
+ pluginLinguiMacro({ linguiConfig }),
48
44
  {
49
45
  name: "externalize-deps",
50
46
  setup(build) {
51
- const shouldInclude = (0, buildIncludeDepsFilter_1.buildIncludeDepsFilter)(config.includeDeps || []);
47
+ const shouldInclude = buildIncludeDepsFilter(extractorConfig.includeDeps || []);
52
48
  // considers all import paths that "look like" package imports in the original source code to be package imports.
53
49
  // Specifically import paths that don't start with a path segment of / or . or .. are considered to be package imports.
54
50
  // The only two exceptions to this rule are subpath imports (which start with a # character) and deps specified in the `includeDeps`
55
51
  build.onResolve({ filter: /^[^.#/].*/ }, async (args) => {
56
- if (shouldInclude(args.path)) {
52
+ if (shouldInclude(args.path) || args.kind === "entry-point") {
57
53
  return { external: false };
58
54
  }
59
55
  return {
@@ -72,7 +68,8 @@ async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
72
68
  },
73
69
  ],
74
70
  };
75
- return await esbuild.build(config.resolveEsbuildOptions
76
- ? config.resolveEsbuildOptions(esbuildOptions)
71
+ const bundleResult = await esbuild.build(extractorConfig.resolveEsbuildOptions
72
+ ? extractorConfig.resolveEsbuildOptions(esbuildOptions)
77
73
  : esbuildOptions);
74
+ return bundleResult.metafile;
78
75
  }
@@ -1,5 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_TEMPLATE_NAME = exports.ENTRY_NAME_PH = void 0;
4
- exports.ENTRY_NAME_PH = "{entryName}";
5
- exports.DEFAULT_TEMPLATE_NAME = "messages";
1
+ export const ENTRY_NAME_PH = "{entryName}";
2
+ export const DEFAULT_TEMPLATE_NAME = "messages";
@@ -1,5 +1,5 @@
1
1
  import { LinguiConfigNormalized } from "@lingui/conf";
2
- import { FormatterWrapper } from "../api/formats";
2
+ import { FormatterWrapper } from "../api/formats/index.js";
3
3
  export declare function extractFromBundleAndWrite(params: {
4
4
  entryPoint: string;
5
5
  bundleFile: string;
@@ -11,9 +11,8 @@ export declare function extractFromBundleAndWrite(params: {
11
11
  clean: boolean;
12
12
  overwrite: boolean;
13
13
  }): Promise<{
14
- success: boolean;
15
- stat?: undefined;
14
+ success: false;
16
15
  } | {
17
- success: boolean;
16
+ success: true;
18
17
  stat: string;
19
18
  }>;
@@ -1,25 +1,19 @@
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.extractFromBundleAndWrite = extractFromBundleAndWrite;
7
- const extractFromFiles_1 = require("../api/catalog/extractFromFiles");
8
- const writeCatalogs_1 = require("./writeCatalogs");
9
- const promises_1 = __importDefault(require("fs/promises"));
10
- const babel_1 = require("../api/extractors/babel");
1
+ import { mergeExtractedMessage } from "../api/catalog/extractFromFiles.js";
2
+ import { writeCatalogs, writeTemplate } from "./writeCatalogs.js";
3
+ import fs from "fs/promises";
4
+ import { extractFromFileWithBabel, getBabelParserOptions, } from "../api/extractors/babel.js";
11
5
  async function extractFromBundle(filename, linguiConfig) {
12
6
  const messages = {};
13
7
  let success;
14
8
  try {
15
- const file = await promises_1.default.readFile(filename);
9
+ const file = await fs.readFile(filename);
16
10
  const parserOptions = linguiConfig.extractorParserOptions;
17
- await (0, babel_1.extractFromFileWithBabel)(filename, file.toString(), (msg) => {
18
- (0, extractFromFiles_1.mergeExtractedMessage)(msg, messages, linguiConfig);
11
+ await extractFromFileWithBabel(filename, file.toString(), (msg) => {
12
+ mergeExtractedMessage(msg, messages, linguiConfig);
19
13
  }, {
20
14
  linguiConfig,
21
15
  }, {
22
- plugins: (0, babel_1.getBabelParserOptions)(filename, parserOptions),
16
+ plugins: getBabelParserOptions(filename, parserOptions),
23
17
  }, true);
24
18
  success = true;
25
19
  }
@@ -30,7 +24,7 @@ async function extractFromBundle(filename, linguiConfig) {
30
24
  }
31
25
  return { success, messages };
32
26
  }
33
- async function extractFromBundleAndWrite(params) {
27
+ export async function extractFromBundleAndWrite(params) {
34
28
  const { linguiConfig, entryPoint, format, outputPattern, locales, overwrite, clean, template, } = params;
35
29
  const { messages, success } = await extractFromBundle(params.bundleFile, params.linguiConfig);
36
30
  if (!success) {
@@ -38,7 +32,7 @@ async function extractFromBundleAndWrite(params) {
38
32
  }
39
33
  let stat;
40
34
  if (template) {
41
- stat = (await (0, writeCatalogs_1.writeTemplate)({
35
+ stat = (await writeTemplate({
42
36
  linguiConfig,
43
37
  clean,
44
38
  format,
@@ -48,7 +42,7 @@ async function extractFromBundleAndWrite(params) {
48
42
  })).statMessage;
49
43
  }
50
44
  else {
51
- stat = (await (0, writeCatalogs_1.writeCatalogs)({
45
+ stat = (await writeCatalogs({
52
46
  locales,
53
47
  linguiConfig,
54
48
  clean,
@@ -1,3 +1,4 @@
1
- import { LinguiConfigNormalized } from "@lingui/conf";
2
- import { Catalog } from "../api/catalog";
3
- export declare function getExperimentalCatalogs(linguiConfig: LinguiConfigNormalized): Promise<Catalog[]>;
1
+ import { ExperimentalExtractorOptions, LinguiConfigNormalized } from "@lingui/conf";
2
+ import { Catalog } from "../api/catalog.js";
3
+ import { FormatterWrapper } from "../api/formats/index.js";
4
+ export declare function getExperimentalCatalogs(linguiConfig: LinguiConfigNormalized, format: FormatterWrapper, extractorConfig: ExperimentalExtractorOptions): Promise<Catalog[]>;
@@ -1,19 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExperimentalCatalogs = getExperimentalCatalogs;
4
- const getEntryPoints_1 = require("./getEntryPoints");
5
- const resolveCatalogPath_1 = require("./resolveCatalogPath");
6
- const catalog_1 = require("../api/catalog");
7
- const resolveTemplatePath_1 = require("./resolveTemplatePath");
8
- const formats_1 = require("../api/formats");
9
- async function getExperimentalCatalogs(linguiConfig) {
10
- const config = linguiConfig.experimental.extractor;
11
- const entryPoints = (0, getEntryPoints_1.getEntryPoints)(config.entries);
12
- const format = await (0, formats_1.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
1
+ import { globSync } from "node:fs";
2
+ import { resolveCatalogPath } from "./resolveCatalogPath.js";
3
+ import { Catalog } from "../api/catalog.js";
4
+ import { resolveTemplatePath } from "./resolveTemplatePath.js";
5
+ export async function getExperimentalCatalogs(linguiConfig, format, extractorConfig) {
6
+ const config = extractorConfig;
7
+ const entryPoints = globSync(config.entries);
13
8
  return entryPoints.map((entryPoint) => {
14
- const catalogPath = (0, resolveCatalogPath_1.resolveCatalogPath)(config.output, entryPoint, linguiConfig.rootDir, undefined, "");
15
- const templatePath = (0, resolveTemplatePath_1.resolveTemplatePath)(entryPoint, config.output, linguiConfig.rootDir, format.getTemplateExtension());
16
- return new catalog_1.Catalog({
9
+ const catalogPath = resolveCatalogPath(config.output, entryPoint, linguiConfig.rootDir, undefined, "");
10
+ const templatePath = resolveTemplatePath(entryPoint, config.output, linguiConfig.rootDir, format.getTemplateExtension());
11
+ return new Catalog({
17
12
  name: undefined,
18
13
  path: catalogPath,
19
14
  templatePath,
@@ -1,36 +1,30 @@
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.pluginLinguiMacro = void 0;
7
- const core_1 = require("@babel/core");
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const babel_1 = require("../api/extractors/babel");
11
- const babel_plugin_lingui_macro_1 = __importDefault(require("@lingui/babel-plugin-lingui-macro"));
12
- const pluginLinguiMacro = (options) => ({
1
+ import { transformAsync } from "@babel/core";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import { babelRe, getBabelParserOptions } from "../api/extractors/babel.js";
5
+ import linguiMacroPlugin from "@lingui/babel-plugin-lingui-macro";
6
+ export const pluginLinguiMacro = (options) => ({
13
7
  name: "linguiMacro",
14
8
  setup(build) {
15
- build.onLoad({ filter: babel_1.babelRe, namespace: "" }, async (args) => {
16
- const filename = path_1.default.relative(process.cwd(), args.path);
17
- const contents = await fs_1.default.promises.readFile(args.path, "utf8");
9
+ build.onLoad({ filter: babelRe, namespace: "" }, async (args) => {
10
+ const filename = path.relative(process.cwd(), args.path);
11
+ const contents = await fs.promises.readFile(args.path, "utf8");
18
12
  const hasMacroRe = /from ["']@lingui(\/.+)?\/macro["']/g;
19
13
  if (!hasMacroRe.test(contents)) {
20
14
  // let esbuild process file as usual
21
15
  return undefined;
22
16
  }
23
- const result = await (0, core_1.transformAsync)(contents, {
17
+ const result = await transformAsync(contents, {
24
18
  babelrc: false,
25
19
  configFile: false,
26
20
  filename: filename,
27
21
  sourceMaps: "inline",
28
22
  parserOpts: {
29
- plugins: (0, babel_1.getBabelParserOptions)(filename, options.linguiConfig.extractorParserOptions),
23
+ plugins: getBabelParserOptions(filename, options.linguiConfig.extractorParserOptions),
30
24
  },
31
25
  plugins: [
32
26
  [
33
- babel_plugin_lingui_macro_1.default,
27
+ linguiMacroPlugin,
34
28
  {
35
29
  extract: true,
36
30
  linguiConfig: options.linguiConfig,
@@ -42,4 +36,3 @@ const pluginLinguiMacro = (options) => ({
42
36
  });
43
37
  },
44
38
  });
45
- exports.pluginLinguiMacro = pluginLinguiMacro;
@@ -1,2 +1,2 @@
1
- export declare function resolveCatalogPath(configOutput: string, entryPath: string, rootDir: string, locale: string, extension: string): string;
1
+ export declare function resolveCatalogPath(configOutput: string, entryPath: string, rootDir: string, locale: string | undefined, extension: string): string;
2
2
  export declare function getEntryName(entryPath: string): string;
@@ -1,22 +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.resolveCatalogPath = resolveCatalogPath;
7
- exports.getEntryName = getEntryName;
8
- const path_1 = __importDefault(require("path"));
9
- const utils_1 = require("../api/utils");
10
- function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension) {
1
+ import nodepath from "path";
2
+ import { replacePlaceholders } from "../api/utils.js";
3
+ export function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension) {
11
4
  const entryName = getEntryName(entryPath);
12
- const entryDir = path_1.default.relative(rootDir, path_1.default.dirname(entryPath));
13
- return path_1.default.normalize((0, utils_1.replacePlaceholders)(configOutput, {
5
+ const entryDir = nodepath.relative(rootDir, nodepath.dirname(entryPath));
6
+ return nodepath.normalize(replacePlaceholders(configOutput, {
14
7
  entryName,
15
8
  entryDir,
16
9
  locale,
17
10
  }) + extension);
18
11
  }
19
- function getEntryName(entryPath) {
20
- const parsedPath = path_1.default.parse(entryPath);
12
+ export function getEntryName(entryPath) {
13
+ const parsedPath = nodepath.parse(entryPath);
21
14
  return parsedPath.name.replace(parsedPath.ext, "");
22
15
  }
@@ -1,15 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveTemplatePath = resolveTemplatePath;
4
- const resolveCatalogPath_1 = require("./resolveCatalogPath");
5
- const constants_1 = require("./constants");
6
- function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
1
+ import { resolveCatalogPath, getEntryName } from "./resolveCatalogPath.js";
2
+ import { DEFAULT_TEMPLATE_NAME, ENTRY_NAME_PH } from "./constants.js";
3
+ export function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
7
4
  let templateName;
8
- if (output.includes(constants_1.ENTRY_NAME_PH)) {
9
- templateName = constants_1.DEFAULT_TEMPLATE_NAME;
5
+ if (output.includes(ENTRY_NAME_PH)) {
6
+ templateName = DEFAULT_TEMPLATE_NAME;
10
7
  }
11
8
  else {
12
- templateName = (0, resolveCatalogPath_1.getEntryName)(entryPoint);
9
+ templateName = getEntryName(entryPoint);
13
10
  }
14
- return (0, resolveCatalogPath_1.resolveCatalogPath)(output, entryPoint, rootDir, templateName, catalogExtension);
11
+ return resolveCatalogPath(output, entryPoint, rootDir, templateName, catalogExtension);
15
12
  }
@@ -1,6 +1,8 @@
1
1
  export type ExtractWorkerFunction = typeof extractWorker;
2
2
  declare const extractWorker: (linguiConfigPath: string, entryPoint: string, bundleFile: string, outputPattern: string, template: boolean, locales: string[], clean: boolean, overwrite: boolean) => Promise<{
3
- success: boolean;
4
- stat?: string;
3
+ success: false;
4
+ } | {
5
+ success: true;
6
+ stat: string;
5
7
  }>;
6
- export {};
8
+ export { extractWorker };
@@ -1,23 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const worker_1 = require("threads/worker");
4
- const conf_1 = require("@lingui/conf");
5
- const extractFromBundleAndWrite_1 = require("../extractFromBundleAndWrite");
6
- const formats_1 = require("../../api/formats");
1
+ import { getConfig } from "@lingui/conf";
2
+ import { extractFromBundleAndWrite } from "../extractFromBundleAndWrite.js";
3
+ import { getFormat } from "../../api/formats/index.js";
7
4
  let linguiConfig;
8
5
  let format;
9
6
  const extractWorker = async (linguiConfigPath, entryPoint, bundleFile, outputPattern, template, locales, clean, overwrite) => {
10
7
  if (!linguiConfig) {
11
8
  // initialize config once per worker, speed up workers follow execution
12
- linguiConfig = (0, conf_1.getConfig)({
9
+ linguiConfig = getConfig({
13
10
  configPath: linguiConfigPath,
14
11
  skipValidation: true,
15
12
  });
16
13
  }
17
14
  if (!format) {
18
- format = await (0, formats_1.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
15
+ format = await getFormat(linguiConfig.format, linguiConfig.sourceLocale);
19
16
  }
20
- return await (0, extractFromBundleAndWrite_1.extractFromBundleAndWrite)({
17
+ return await extractFromBundleAndWrite({
21
18
  entryPoint,
22
19
  bundleFile,
23
20
  outputPattern,
@@ -29,4 +26,4 @@ const extractWorker = async (linguiConfigPath, entryPoint, bundleFile, outputPat
29
26
  template,
30
27
  });
31
28
  };
32
- (0, worker_1.expose)(extractWorker);
29
+ export { extractWorker };
@@ -0,0 +1,8 @@
1
+ import { extractWorker } from "./extractWorker.js";
2
+ declare const _default: (args: Parameters<typeof extractWorker>) => Promise<{
3
+ success: false;
4
+ } | {
5
+ success: true;
6
+ stat: string;
7
+ }>;
8
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { extractWorker } from "./extractWorker.js";
2
+ export default (args) => extractWorker(...args);
@@ -1,6 +1,6 @@
1
- import { ExtractedCatalogType } from "../api";
1
+ import { ExtractedCatalogType } from "../api/index.js";
2
2
  import { LinguiConfigNormalized } from "@lingui/conf";
3
- import { FormatterWrapper } from "../api/formats";
3
+ import { FormatterWrapper } from "../api/formats/index.js";
4
4
  type ExtractTemplateParams = {
5
5
  format: FormatterWrapper;
6
6
  clean: boolean;
@@ -1,40 +1,33 @@
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.writeCatalogs = writeCatalogs;
7
- exports.writeTemplate = writeTemplate;
8
- const resolveTemplatePath_1 = require("./resolveTemplatePath");
9
- const picocolors_1 = __importDefault(require("picocolors"));
10
- const resolveCatalogPath_1 = require("./resolveCatalogPath");
11
- const mergeCatalog_1 = require("../api/catalog/mergeCatalog");
12
- const stats_1 = require("../api/stats");
13
- const catalog_1 = require("../api/catalog");
1
+ import { resolveTemplatePath } from "./resolveTemplatePath.js";
2
+ import { styleText } from "node:util";
3
+ import { resolveCatalogPath } from "./resolveCatalogPath.js";
4
+ import { mergeCatalog } from "../api/catalog/mergeCatalog.js";
5
+ import { printStats } from "../api/stats.js";
6
+ import { cleanObsolete, order } from "../api/catalog.js";
14
7
  function cleanAndSort(catalog, clean, orderBy) {
15
8
  if (clean) {
16
- catalog = (0, catalog_1.cleanObsolete)(catalog);
9
+ catalog = cleanObsolete(catalog);
17
10
  }
18
- return (0, catalog_1.order)(orderBy, catalog);
11
+ return order(orderBy, catalog);
19
12
  }
20
- async function writeCatalogs(params) {
13
+ export async function writeCatalogs(params) {
21
14
  const { entryPoint, outputPattern, linguiConfig, locales, overwrite, format, clean, messages, } = params;
22
15
  const stat = {};
23
16
  for (const locale of locales) {
24
- const catalogOutput = (0, resolveCatalogPath_1.resolveCatalogPath)(outputPattern, entryPoint, linguiConfig.rootDir, locale, format.getCatalogExtension());
25
- const catalog = (0, mergeCatalog_1.mergeCatalog)(await format.read(catalogOutput, locale), messages, locale === linguiConfig.sourceLocale, { overwrite });
17
+ const catalogOutput = resolveCatalogPath(outputPattern, entryPoint, linguiConfig.rootDir, locale, format.getCatalogExtension());
18
+ const catalog = mergeCatalog(await format.read(catalogOutput, locale), messages, locale === linguiConfig.sourceLocale, { overwrite });
26
19
  await format.write(catalogOutput, cleanAndSort(catalog, clean, linguiConfig.orderBy), locale);
27
20
  stat[locale] = catalog;
28
21
  }
29
22
  return {
30
- statMessage: (0, stats_1.printStats)(linguiConfig, stat).toString(),
23
+ statMessage: printStats(linguiConfig, stat).toString(),
31
24
  };
32
25
  }
33
- async function writeTemplate(params) {
26
+ export async function writeTemplate(params) {
34
27
  const { entryPoint, outputPattern, linguiConfig, format, clean, messages } = params;
35
- const catalogOutput = (0, resolveTemplatePath_1.resolveTemplatePath)(entryPoint, outputPattern, linguiConfig.rootDir, format.getTemplateExtension());
28
+ const catalogOutput = resolveTemplatePath(entryPoint, outputPattern, linguiConfig.rootDir, format.getTemplateExtension());
36
29
  await format.write(catalogOutput, cleanAndSort(messages, clean, linguiConfig.orderBy), undefined);
37
30
  return {
38
- statMessage: `${picocolors_1.default.bold(Object.keys(messages).length)} message(s) extracted`,
31
+ statMessage: `${styleText("bold", String(Object.keys(messages).length))} message(s) extracted`,
39
32
  };
40
33
  }
package/dist/index.js CHANGED
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.defineConfig = void 0;
4
- var conf_1 = require("@lingui/conf");
5
- Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return conf_1.defineConfig; } });
1
+ export { defineConfig } from "@lingui/conf";
@@ -1,5 +1,5 @@
1
1
  import { LinguiConfigNormalized } from "@lingui/conf";
2
- import { WorkersOptions } from "./api/resolveWorkersOptions";
2
+ import { WorkersOptions } from "./api/resolveWorkersOptions.js";
3
3
  export type CliCompileOptions = {
4
4
  verbose?: boolean;
5
5
  allowEmpty?: boolean;
@@ -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());