@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,21 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSegmentFromLinguiItem = createSegmentFromLinguiItem;
4
- exports.createLinguiItemFromSegment = createLinguiItemFromSegment;
5
- const generateMessageId_1 = require("@lingui/message-utils/generateMessageId");
1
+ import { generateMessageId } from "@lingui/message-utils/generateMessageId";
6
2
  const EXPLICIT_ID_FLAG = "js-lingui-explicit-id";
7
3
  const EXPLICIT_ID_AND_CONTEXT_FLAG = "js-lingui-explicit-id-and-context";
8
4
  function isGeneratedId(id, message) {
9
- return id === (0, generateMessageId_1.generateMessageId)(message.message, message.context);
5
+ return id === generateMessageId(message.message, message.context);
10
6
  }
11
7
  const joinOrigin = (origin) => origin.join(":");
12
8
  const splitOrigin = (origin) => {
13
9
  const [file, line] = origin.split(":");
14
10
  return [file, line ? Number(line) : null];
15
11
  };
16
- function createSegmentFromLinguiItem(key, item) {
12
+ export function createSegmentFromLinguiItem(key, item) {
17
13
  const itemHasExplicitId = !isGeneratedId(key, item);
18
- const itemHasContext = !!item.context;
19
14
  const segment = {
20
15
  type: "source", // No way to edit text for source language (inside code), so not using "key" here
21
16
  source: "",
@@ -25,12 +20,12 @@ function createSegmentFromLinguiItem(key, item) {
25
20
  };
26
21
  // For segment.source & segment.context, we must remain compatible with projects created/synced before Lingui V4
27
22
  if (itemHasExplicitId) {
28
- segment.source = item.message || item.translation;
23
+ segment.source = item.message || item.translation || "";
29
24
  segment.context = key;
30
25
  }
31
26
  else {
32
- segment.source = item.message || item.translation;
33
- if (itemHasContext) {
27
+ segment.source = item.message || item.translation || "";
28
+ if (item.context) {
34
29
  segment.context = item.context;
35
30
  }
36
31
  }
@@ -40,7 +35,7 @@ function createSegmentFromLinguiItem(key, item) {
40
35
  // Since Lingui v4, when using explicit IDs, Lingui automatically adds 'js-lingui-explicit-id' to the extractedComments array
41
36
  const comments = [];
42
37
  if (itemHasExplicitId) {
43
- if (itemHasContext) {
38
+ if (item.context) {
44
39
  // segment.context is already used for the explicit ID, so we need to pass the context (for translators) in segment.comment
45
40
  comments.push(item.context, EXPLICIT_ID_AND_CONTEXT_FLAG);
46
41
  }
@@ -51,30 +46,31 @@ function createSegmentFromLinguiItem(key, item) {
51
46
  segment.comment = [...comments, ...(item.comments || [])].join(" | ");
52
47
  return segment;
53
48
  }
54
- function createLinguiItemFromSegment(segment) {
55
- var _a, _b, _c;
56
- const segmentHasExplicitId = (_a = segment.comment) === null || _a === void 0 ? void 0 : _a.includes(EXPLICIT_ID_FLAG);
57
- const segmentHasExplicitIdAndContext = (_b = segment.comment) === null || _b === void 0 ? void 0 : _b.includes(EXPLICIT_ID_AND_CONTEXT_FLAG);
49
+ export function createLinguiItemFromSegment(segment) {
50
+ const segmentHasExplicitId = segment.comment?.includes(EXPLICIT_ID_FLAG);
51
+ const segmentHasExplicitIdAndContext = segment.comment?.includes(EXPLICIT_ID_AND_CONTEXT_FLAG);
58
52
  const item = {
59
53
  translation: segment.target,
60
- origin: ((_c = segment.references) === null || _c === void 0 ? void 0 : _c.length)
54
+ origin: segment.references?.length
61
55
  ? segment.references.map(splitOrigin)
62
56
  : [],
63
57
  message: segment.source,
64
58
  comments: [],
59
+ placeholders: {},
65
60
  };
66
- let id = null;
61
+ let id;
67
62
  if (segmentHasExplicitId || segmentHasExplicitIdAndContext) {
68
63
  id = segment.context;
69
64
  }
70
65
  else {
71
- id = (0, generateMessageId_1.generateMessageId)(segment.source, segment.context);
66
+ id = generateMessageId(segment.source, segment.context);
72
67
  item.context = segment.context;
73
68
  }
74
69
  if (segment.comment) {
75
70
  item.comments = segment.comment.split(" | ").filter(
76
71
  // drop flags from comments
77
- (comment) => comment !== EXPLICIT_ID_AND_CONTEXT_FLAG && comment !== EXPLICIT_ID_FLAG);
72
+ (comment) => comment !== EXPLICIT_ID_AND_CONTEXT_FLAG &&
73
+ comment !== EXPLICIT_ID_FLAG);
78
74
  // We recompose a target PO Item that is consistent with the source PO Item
79
75
  if (segmentHasExplicitIdAndContext) {
80
76
  item.context = item.comments.shift();
@@ -27,13 +27,6 @@ export type TranslationIoProject = {
27
27
  name: string;
28
28
  url: string;
29
29
  };
30
- export type TranslationIoResponse = {
31
- errors?: string[];
32
- project?: TranslationIoProject;
33
- segments?: {
34
- [locale: string]: TranslationIoSegment[];
35
- };
36
- };
37
30
  export type FetchResult<T> = {
38
31
  data: T;
39
32
  error: undefined;
@@ -44,5 +37,16 @@ export type FetchResult<T> = {
44
37
  };
45
38
  data: undefined;
46
39
  };
40
+ export type TranslationIoResponse = TranslationIoErrorResponse | TranslationProjectResponse;
41
+ type TranslationIoErrorResponse = {
42
+ errors: string[];
43
+ };
44
+ type TranslationProjectResponse = {
45
+ project: TranslationIoProject;
46
+ segments: {
47
+ [locale: string]: TranslationIoSegment[];
48
+ };
49
+ };
47
50
  export declare function tioSync(request: TranslationIoSyncRequest, apiKey: string): Promise<FetchResult<TranslationIoResponse>>;
48
51
  export declare function tioInit(request: TranslationIoInitRequest, apiKey: string): Promise<FetchResult<TranslationIoResponse>>;
52
+ export {};
@@ -1,20 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tioSync = tioSync;
4
- exports.tioInit = tioInit;
5
- // todo: need to enable strictNullChecks to support this kind of type narrowing
6
- // export type TranslationIoResponse =
7
- // | TranslationIoErrorResponse
8
- // | TranslationProjectResponse
9
- //
10
- // type TranslationIoErrorResponse = {
11
- // errors: string[]
12
- // }
13
- // type TranslationProjectResponse = {
14
- // errors: null
15
- // project: TranslationIoProject
16
- // segments: { [locale: string]: TranslationIoSegment[] }
17
- // }
18
1
  async function post(url, request) {
19
2
  const response = await fetch(url, {
20
3
  method: "POST",
@@ -34,9 +17,9 @@ async function post(url, request) {
34
17
  }
35
18
  return { data: await response.json(), error: undefined };
36
19
  }
37
- async function tioSync(request, apiKey) {
20
+ export async function tioSync(request, apiKey) {
38
21
  return post(`https://translation.io/api/v1/segments/sync.json?api_key=${apiKey}`, request);
39
22
  }
40
- async function tioInit(request, apiKey) {
23
+ export async function tioInit(request, apiKey) {
41
24
  return post(`https://translation.io/api/v1/segments/init.json?api_key=${apiKey}`, request);
42
25
  }
@@ -1,8 +1,8 @@
1
1
  import { LinguiConfigNormalized } from "@lingui/conf";
2
- import { CliExtractOptions } from "../lingui-extract";
3
- import { TranslationIoProject, TranslationIoSegment } from "./translationIO/translationio-api";
4
- import { Catalog } from "../api/catalog";
5
- import { AllCatalogsType } from "../api/types";
2
+ import { CliExtractOptions } from "../lingui-extract.js";
3
+ import { TranslationIoProject, TranslationIoSegment } from "./translationIO/translationio-api.js";
4
+ import { Catalog } from "../api/catalog.js";
5
+ import { AllCatalogsType } from "../api/types.js";
6
6
  type ExtractionResult = {
7
7
  catalog: Catalog;
8
8
  messagesByLocale: AllCatalogsType;
@@ -1,24 +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.default = syncProcess;
7
- exports.init = init;
8
- exports.sync = sync;
9
- exports.writeSegmentsToCatalogs = writeSegmentsToCatalogs;
10
- const fs_1 = __importDefault(require("fs"));
11
- const path_1 = require("path");
12
- const translationio_api_1 = require("./translationIO/translationio-api");
13
- const catalog_1 = require("../api/catalog");
14
- const segment_converters_1 = require("./translationIO/segment-converters");
1
+ import fs from "fs";
2
+ import { dirname } from "path";
3
+ import { tioInit, tioSync, } from "./translationIO/translationio-api.js";
4
+ import { order } from "../api/catalog.js";
5
+ import { createLinguiItemFromSegment, createSegmentFromLinguiItem, } from "./translationIO/segment-converters.js";
15
6
  const getTargetLocales = (config) => {
16
7
  const sourceLocale = config.sourceLocale || "en";
17
8
  const pseudoLocale = config.pseudoLocale || "pseudo";
18
9
  return config.locales.filter((value) => value != sourceLocale && value != pseudoLocale);
19
10
  };
20
11
  // Main sync method, call "Init" or "Sync" depending on the project context
21
- async function syncProcess(config, options, extractionResult) {
12
+ export default async function syncProcess(config, options, extractionResult) {
22
13
  const reportSuccess = (project) => {
23
14
  return `\n----------\nProject successfully synchronized. Please use this URL to translate: ${project.url}\n----------`;
24
15
  };
@@ -40,7 +31,7 @@ async function syncProcess(config, options, extractionResult) {
40
31
  }
41
32
  // Initialize project with source and existing translations (only first time!)
42
33
  // Cf. https://translation.io/docs/create-library#initialization
43
- async function init(config, extractionResult) {
34
+ export async function init(config, extractionResult) {
44
35
  const sourceLocale = config.sourceLocale || "en";
45
36
  const targetLocales = getTargetLocales(config);
46
37
  const segments = {};
@@ -54,7 +45,7 @@ async function init(config, extractionResult) {
54
45
  if (entry.obsolete)
55
46
  return;
56
47
  targetLocales.forEach((targetLocale) => {
57
- segments[targetLocale].push((0, segment_converters_1.createSegmentFromLinguiItem)(key, entry));
48
+ segments[targetLocale].push(createSegmentFromLinguiItem(key, entry));
58
49
  });
59
50
  });
60
51
  }
@@ -69,7 +60,7 @@ async function init(config, extractionResult) {
69
60
  });
70
61
  }
71
62
  }
72
- const { data, error } = await (0, translationio_api_1.tioInit)({
63
+ const { data, error } = await tioInit({
73
64
  client: "lingui",
74
65
  version: require("@lingui/core/package.json").version,
75
66
  source_language: sourceLocale,
@@ -79,7 +70,7 @@ async function init(config, extractionResult) {
79
70
  if (error) {
80
71
  return { success: false, errors: [error.message] };
81
72
  }
82
- if (data.errors) {
73
+ if ("errors" in data) {
83
74
  return { success: false, errors: data.errors };
84
75
  }
85
76
  await writeSegmentsToCatalogs(config, sourceLocale, extractionResult, data.segments);
@@ -87,7 +78,7 @@ async function init(config, extractionResult) {
87
78
  }
88
79
  // Send all source text from PO to Translation.io and create new PO based on received translations
89
80
  // Cf. https://translation.io/docs/create-library#synchronization
90
- async function sync(config, options, extractionResult) {
81
+ export async function sync(config, options, extractionResult) {
91
82
  const sourceLocale = config.sourceLocale || "en";
92
83
  const targetLocales = getTargetLocales(config);
93
84
  const segments = [];
@@ -97,10 +88,10 @@ async function sync(config, options, extractionResult) {
97
88
  Object.entries(messages).forEach(([key, entry]) => {
98
89
  if (entry.obsolete)
99
90
  return;
100
- segments.push((0, segment_converters_1.createSegmentFromLinguiItem)(key, entry));
91
+ segments.push(createSegmentFromLinguiItem(key, entry));
101
92
  });
102
93
  }
103
- const { data, error } = await (0, translationio_api_1.tioSync)({
94
+ const { data, error } = await tioSync({
104
95
  client: "lingui",
105
96
  version: require("@lingui/core/package.json").version,
106
97
  source_language: sourceLocale,
@@ -112,13 +103,13 @@ async function sync(config, options, extractionResult) {
112
103
  if (error) {
113
104
  return { success: false, errors: [error.message] };
114
105
  }
115
- if (data.errors) {
106
+ if ("errors" in data) {
116
107
  return { success: false, errors: data.errors };
117
108
  }
118
109
  await writeSegmentsToCatalogs(config, sourceLocale, extractionResult, data.segments);
119
110
  return { success: true, project: data.project };
120
111
  }
121
- async function writeSegmentsToCatalogs(config, sourceLocale, extractionResult, segmentsPerLocale) {
112
+ export async function writeSegmentsToCatalogs(config, sourceLocale, extractionResult, segmentsPerLocale) {
122
113
  // Create segments from source locale PO items
123
114
  for (const { catalog, messagesByLocale } of extractionResult) {
124
115
  const sourceMessages = messagesByLocale[sourceLocale];
@@ -127,28 +118,30 @@ async function writeSegmentsToCatalogs(config, sourceLocale, extractionResult, s
127
118
  {
128
119
  const path = catalog.getFilename(targetLocale);
129
120
  const jsPath = path.replace(new RegExp(`${catalog.format.getCatalogExtension()}$`), "") + ".js";
130
- const dirPath = (0, path_1.dirname)(path);
121
+ const dirPath = dirname(path);
131
122
  // todo: check tests and all these logic, maybe it could be simplified to just drop the folder
132
123
  // Remove PO, JS and empty dir
133
- if (fs_1.default.existsSync(path)) {
134
- await fs_1.default.promises.unlink(path);
124
+ if (fs.existsSync(path)) {
125
+ await fs.promises.unlink(path);
135
126
  }
136
- if (fs_1.default.existsSync(jsPath)) {
137
- await fs_1.default.promises.unlink(jsPath);
127
+ if (fs.existsSync(jsPath)) {
128
+ await fs.promises.unlink(jsPath);
138
129
  }
139
- if (fs_1.default.existsSync(dirPath) && fs_1.default.readdirSync(dirPath).length === 0) {
140
- await fs_1.default.promises.rmdir(dirPath);
130
+ if (fs.existsSync(dirPath) && fs.readdirSync(dirPath).length === 0) {
131
+ await fs.promises.rmdir(dirPath);
141
132
  }
142
133
  }
143
- const translations = Object.fromEntries(segmentsPerLocale[targetLocale].map((segment) => (0, segment_converters_1.createLinguiItemFromSegment)(segment)));
134
+ const translations = Object.fromEntries(segmentsPerLocale[targetLocale].map((segment) => createLinguiItemFromSegment(segment)));
144
135
  const messages = Object.fromEntries(Object.entries(sourceMessages).map(([key, entry]) => {
145
- var _a;
146
136
  return [
147
137
  key,
148
- Object.assign(Object.assign({}, entry), { translation: (_a = translations[key]) === null || _a === void 0 ? void 0 : _a.translation }),
138
+ {
139
+ ...entry,
140
+ translation: translations[key]?.translation,
141
+ },
149
142
  ];
150
143
  }));
151
- await catalog.write(targetLocale, (0, catalog_1.order)(config.orderBy, messages));
144
+ await catalog.write(targetLocale, order(config.orderBy, messages));
152
145
  }
153
146
  }
154
147
  }
@@ -1,11 +1,8 @@
1
- import { CliCompileOptions } from "../lingui-compile";
2
- import { SerializedLogs } from "../api/workerLogger";
3
- declare const compileWorker: {
4
- compileLocale: (locale: string, options: CliCompileOptions, doMerge: boolean, linguiConfigPath: string) => Promise<{
5
- logs?: SerializedLogs;
6
- error?: unknown;
7
- exitProgram?: boolean;
8
- }>;
9
- };
10
- export type CompileWorker = typeof compileWorker;
11
- export {};
1
+ import { CliCompileOptions } from "../lingui-compile.js";
2
+ import { SerializedLogs } from "../api/workerLogger.js";
3
+ export type CompileWorkerFunction = typeof compileWorker;
4
+ export declare const compileWorker: (locale: string, options: CliCompileOptions, doMerge: boolean, linguiConfigPath: string) => Promise<{
5
+ logs: SerializedLogs;
6
+ error?: unknown;
7
+ exitProgram?: boolean;
8
+ }>;
@@ -1,39 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const worker_1 = require("threads/worker");
4
- const compileLocale_1 = require("../api/compile/compileLocale");
5
- const conf_1 = require("@lingui/conf");
6
- const workerLogger_1 = require("../api/workerLogger");
7
- const ProgramExit_1 = require("../api/ProgramExit");
8
- const getCatalogs_1 = require("../api/catalog/getCatalogs");
1
+ import { compileLocale } from "../api/compile/compileLocale.js";
2
+ import { getConfig } from "@lingui/conf";
3
+ import { WorkerLogger } from "../api/workerLogger.js";
4
+ import { ProgramExit } from "../api/ProgramExit.js";
5
+ import { getCatalogs } from "../api/catalog/getCatalogs.js";
9
6
  let linguiConfig;
10
7
  let catalogs;
11
- const compileWorker = {
12
- compileLocale: async (locale, options, doMerge, linguiConfigPath) => {
13
- if (!linguiConfig) {
14
- // initialize config once per worker, speed up workers follow execution
15
- linguiConfig = (0, conf_1.getConfig)({
16
- configPath: linguiConfigPath,
17
- skipValidation: true,
18
- });
19
- }
20
- if (!catalogs) {
21
- // catalogs holds path to the files and message catalogs, so it's kinda configuration object
22
- // it depends only on the config, so we can initialize it once per program execution
23
- catalogs = await (0, getCatalogs_1.getCatalogs)(linguiConfig);
24
- }
25
- const logger = new workerLogger_1.WorkerLogger();
26
- try {
27
- await (0, compileLocale_1.compileLocale)(catalogs, locale, options, linguiConfig, doMerge, logger);
28
- }
29
- catch (error) {
30
- return {
31
- logs: logger.flush(),
32
- error,
33
- exitProgram: error instanceof ProgramExit_1.ProgramExit,
34
- };
35
- }
36
- return { logs: logger.flush() };
37
- },
8
+ export const compileWorker = async (locale, options, doMerge, linguiConfigPath) => {
9
+ if (!linguiConfig) {
10
+ // initialize config once per worker, speed up workers follow execution
11
+ linguiConfig = getConfig({
12
+ configPath: linguiConfigPath,
13
+ skipValidation: true,
14
+ });
15
+ }
16
+ if (!catalogs) {
17
+ // catalogs holds path to the files and message catalogs, so it's kinda configuration object
18
+ // it depends only on the config, so we can initialize it once per program execution
19
+ catalogs = await getCatalogs(linguiConfig);
20
+ }
21
+ const logger = new WorkerLogger();
22
+ try {
23
+ await compileLocale(catalogs, locale, options, linguiConfig, doMerge, logger);
24
+ }
25
+ catch (error) {
26
+ return {
27
+ logs: logger.flush(),
28
+ error,
29
+ exitProgram: error instanceof ProgramExit,
30
+ };
31
+ }
32
+ return { logs: logger.flush() };
38
33
  };
39
- (0, worker_1.expose)(compileWorker);
@@ -0,0 +1,7 @@
1
+ import { compileWorker } from "./compileWorker.js";
2
+ declare const _default: (args: Parameters<typeof compileWorker>) => Promise<{
3
+ logs: import("../api/workerLogger.js").SerializedLogs;
4
+ error?: unknown;
5
+ exitProgram?: boolean;
6
+ }>;
7
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { compileWorker } from "./compileWorker.js";
2
+ export default (args) => compileWorker(...args);
@@ -1,7 +1,6 @@
1
1
  import { ExtractedMessage } from "@lingui/conf";
2
2
  export type ExtractWorkerFunction = typeof extractWorker;
3
- declare const extractWorker: (filename: string, linguiConfigPath: string) => Promise<{
4
- messages?: ExtractedMessage[];
3
+ export declare const extractWorker: (filename: string, linguiConfigPath: string) => Promise<{
4
+ messages: ExtractedMessage[];
5
5
  success: boolean;
6
6
  }>;
7
- export {};
@@ -1,24 +1,17 @@
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
- const worker_1 = require("threads/worker");
7
- const conf_1 = require("@lingui/conf");
8
- const extractors_1 = __importDefault(require("../api/extractors"));
1
+ import { getConfig, } from "@lingui/conf";
2
+ import extract from "../api/extractors/index.js";
9
3
  let linguiConfig;
10
- const extractWorker = async (filename, linguiConfigPath) => {
4
+ export const extractWorker = async (filename, linguiConfigPath) => {
11
5
  if (!linguiConfig) {
12
6
  // initialize config once per worker, speed up workers follow execution
13
- linguiConfig = (0, conf_1.getConfig)({
7
+ linguiConfig = getConfig({
14
8
  configPath: linguiConfigPath,
15
9
  skipValidation: true,
16
10
  });
17
11
  }
18
12
  const messages = [];
19
- const success = await (0, extractors_1.default)(filename, (msg) => {
13
+ const success = await extract(filename, (msg) => {
20
14
  messages.push(msg);
21
15
  }, linguiConfig);
22
16
  return { success, messages };
23
17
  };
24
- (0, worker_1.expose)(extractWorker);
@@ -0,0 +1,6 @@
1
+ import { extractWorker } from "./extractWorker.js";
2
+ declare const _default: (args: Parameters<typeof extractWorker>) => Promise<{
3
+ messages: import("packages/conf/dist/index.mjs").ExtractedMessage[];
4
+ success: boolean;
5
+ }>;
6
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { extractWorker } from "./extractWorker.js";
2
+ export default (args) => extractWorker(...args);
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "5.9.2",
3
+ "version": "6.0.0-next.0",
4
4
  "description": "CLI for working wit message catalogs",
5
+ "type": "module",
5
6
  "keywords": [
6
7
  "cli",
7
8
  "i18n",
@@ -28,28 +29,16 @@
28
29
  "lingui": "./dist/lingui.js"
29
30
  },
30
31
  "exports": {
31
- ".": {
32
- "types": "./dist/index.d.ts",
33
- "default": "./dist/index.js"
34
- },
35
- "./api": {
36
- "types": "./dist/api/index.d.ts",
37
- "default": "./dist/api/index.js"
38
- },
39
- "./api/extractors/babel": {
40
- "types": "./dist/api/extractors/babel.d.ts",
41
- "default": "./dist/api/extractors/babel.js"
42
- },
43
- "./api/extractors/typescript": {
44
- "types": "./dist/api/extractors/typescript.d.ts",
45
- "default": "./dist/api/extractors/typescript.js"
46
- }
32
+ ".": "./dist/index.js",
33
+ "./api": "./dist/api/index.js",
34
+ "./api/extractors/babel": "./dist/api/extractors/babel.js"
47
35
  },
48
36
  "scripts": {
49
- "build": "rimraf ./dist && tsc -p tsconfig.build.json"
37
+ "build": "tsc -p tsconfig.build.json",
38
+ "check-types": "tsc --noEmit"
50
39
  },
51
40
  "engines": {
52
- "node": ">=20.0.0"
41
+ "node": ">=22.19.0"
53
42
  },
54
43
  "files": [
55
44
  "LICENSE",
@@ -58,43 +47,37 @@
58
47
  ],
59
48
  "dependencies": {
60
49
  "@babel/core": "^7.21.0",
61
- "@babel/generator": "^7.21.1",
50
+ "@babel/generator": "^7.28.5",
62
51
  "@babel/parser": "^7.22.0",
63
- "@babel/runtime": "^7.21.0",
64
52
  "@babel/types": "^7.21.2",
65
- "@lingui/babel-plugin-extract-messages": "5.9.2",
66
- "@lingui/babel-plugin-lingui-macro": "5.9.2",
67
- "@lingui/conf": "5.9.2",
68
- "@lingui/core": "5.9.2",
69
- "@lingui/format-po": "5.9.2",
70
- "@lingui/message-utils": "5.9.2",
71
- "chokidar": "3.5.1",
72
- "cli-table": "^0.3.11",
73
- "commander": "^10.0.0",
74
- "convert-source-map": "^2.0.0",
75
- "date-fns": "^3.6.0",
53
+ "@lingui/babel-plugin-extract-messages": "6.0.0-next.0",
54
+ "@lingui/babel-plugin-lingui-macro": "6.0.0-next.0",
55
+ "@lingui/conf": "6.0.0-next.0",
56
+ "@lingui/core": "6.0.0-next.0",
57
+ "@lingui/format-po": "6.0.0-next.0",
58
+ "@lingui/message-utils": "6.0.0-next.0",
59
+ "chokidar": "5.0.0",
60
+ "cli-table3": "^0.6.5",
61
+ "commander": "^14.0.2",
76
62
  "esbuild": "^0.25.1",
77
- "glob": "^11.0.0",
63
+ "jiti": "^2.6.1",
78
64
  "micromatch": "^4.0.7",
79
65
  "ms": "^2.1.3",
80
66
  "normalize-path": "^3.0.0",
81
- "ora": "^5.1.0",
82
- "picocolors": "^1.1.1",
83
- "pofile": "^1.1.4",
84
- "pseudolocale": "^2.0.0",
67
+ "ora": "^9.1.0",
68
+ "pseudolocale": "^2.2.0",
85
69
  "source-map": "^0.7.6",
86
- "threads": "^1.7.0"
70
+ "tinypool": "^2.1.0"
87
71
  },
88
72
  "devDependencies": {
89
- "@lingui/jest-mocks": "*",
90
- "@types/convert-source-map": "^2.0.0",
73
+ "@lingui/test-utils": "3.0.3",
74
+ "@types/babel__generator": "^7.27.0",
91
75
  "@types/micromatch": "^4.0.1",
92
76
  "@types/ms": "^2.1.0",
93
77
  "@types/normalize-path": "^3.0.0",
94
78
  "mock-fs": "^5.2.0",
95
- "mockdate": "^3.0.5",
96
79
  "msw": "^2.12.7",
97
- "ts-node": "^10.9.2"
80
+ "vitest": "4.0.18"
98
81
  },
99
- "gitHead": "7b30f31b5510c98442eabbcef531a6b70e1c1381"
82
+ "gitHead": "a9576050487a4f7dfbc88db20814d5a1bb861c8c"
100
83
  }
@@ -1 +0,0 @@
1
- export type ExtractWorkerPool = ReturnType<typeof createExtractWorkerPool>;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createExtractWorkerPool = createExtractWorkerPool;
4
- const threads_1 = require("threads");
5
- /** @internal */
6
- function createExtractWorkerPool(opts) {
7
- return (0, threads_1.Pool)(() => (0, threads_1.spawn)(new threads_1.Worker("../workers/extractWorker")), { size: opts.poolSize });
8
- }
@@ -1,3 +0,0 @@
1
- import { ExtractorType } from "@lingui/conf";
2
- declare const extractor: ExtractorType;
3
- export default extractor;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const extractor = {
4
- match(filename) {
5
- throw new Error("Typescript extractor was removed. " +
6
- "Lingui CLI can parse typescript out of the box. " +
7
- "Please remove it from your lingui.config.js");
8
- },
9
- extract() { },
10
- };
11
- exports.default = extractor;
@@ -1 +0,0 @@
1
- export declare function getEntryPoints(entries: string[]): string[];
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEntryPoints = getEntryPoints;
4
- const glob_1 = require("glob");
5
- function getEntryPoints(entries) {
6
- return (0, glob_1.globSync)(entries, { mark: true });
7
- }