@lingui/cli 5.1.2 → 5.3.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 (35) hide show
  1. package/dist/api/catalog/extractFromFiles.d.ts +1 -3
  2. package/dist/api/catalog/extractFromFiles.js +2 -3
  3. package/dist/api/catalog/getCatalogDependentFiles.js +18 -9
  4. package/dist/api/catalog/getCatalogs.js +3 -4
  5. package/dist/api/catalog/getFallbackListForLocale.js +1 -2
  6. package/dist/api/catalog/getTranslationsForCatalog.js +6 -8
  7. package/dist/api/catalog/mergeCatalog.js +28 -39
  8. package/dist/api/catalog.d.ts +12 -14
  9. package/dist/api/catalog.js +29 -41
  10. package/dist/api/compile.d.ts +18 -1
  11. package/dist/api/compile.js +33 -14
  12. package/dist/api/extractors/babel.js +6 -6
  13. package/dist/api/extractors/index.js +2 -2
  14. package/dist/api/formats/index.js +2 -2
  15. package/dist/api/help.js +4 -3
  16. package/dist/api/index.d.ts +1 -0
  17. package/dist/api/index.js +4 -1
  18. package/dist/api/messages.d.ts +4 -0
  19. package/dist/api/messages.js +32 -0
  20. package/dist/api/pseudoLocalize.js +4 -4
  21. package/dist/api/stats.js +3 -3
  22. package/dist/api/utils.js +11 -11
  23. package/dist/extract-experimental/bundleSource.js +1 -2
  24. package/dist/extract-experimental/getEntryPoints.js +1 -2
  25. package/dist/extract-experimental/getExperimentalCatalogs.js +1 -2
  26. package/dist/extract-experimental/resolveCatalogPath.js +2 -3
  27. package/dist/extract-experimental/resolveTemplatePath.js +1 -2
  28. package/dist/extract-experimental/writeCatalogs.js +3 -4
  29. package/dist/lingui-compile.d.ts +1 -0
  30. package/dist/lingui-compile.js +37 -32
  31. package/dist/lingui-extract-experimental.js +1 -1
  32. package/dist/lingui-extract-template.js +1 -1
  33. package/dist/lingui-extract.js +4 -4
  34. package/dist/services/translationIO.js +2 -2
  35. package/package.json +9 -10
@@ -1,5 +1,3 @@
1
1
  import type { LinguiConfigNormalized } from "@lingui/conf";
2
2
  import { ExtractedCatalogType } from "../types";
3
- export declare function extractFromFiles(paths: string[], config: LinguiConfigNormalized): Promise<ExtractedCatalogType<{
4
- [x: string]: unknown;
5
- }>>;
3
+ export declare function extractFromFiles(paths: string[], config: LinguiConfigNormalized): Promise<ExtractedCatalogType>;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.extractFromFiles = void 0;
6
+ exports.extractFromFiles = extractFromFiles;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const extractors_1 = __importDefault(require("../extractors"));
@@ -23,7 +23,7 @@ function mergePlaceholders(prev, next) {
23
23
  async function extractFromFiles(paths, config) {
24
24
  const messages = {};
25
25
  let catalogSuccess = true;
26
- for (let filename of paths) {
26
+ for (const filename of paths) {
27
27
  const fileSuccess = await (0, extractors_1.default)(filename, (next) => {
28
28
  var _a;
29
29
  if (!messages[next.id]) {
@@ -58,4 +58,3 @@ async function extractFromFiles(paths, config) {
58
58
  return undefined;
59
59
  return messages;
60
60
  }
61
- exports.extractFromFiles = extractFromFiles;
@@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.getCatalogDependentFiles = void 0;
39
+ exports.getCatalogDependentFiles = getCatalogDependentFiles;
30
40
  const getFallbackListForLocale_1 = require("./getFallbackListForLocale");
31
41
  const promises_1 = __importDefault(require("node:fs/promises"));
32
42
  const node_path_1 = __importDefault(require("node:path"));
@@ -52,4 +62,3 @@ async function getCatalogDependentFiles(catalog, locale) {
52
62
  }
53
63
  return out;
54
64
  }
55
- exports.getCatalogDependentFiles = getCatalogDependentFiles;
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getCatalogForFile = exports.getCatalogForMerge = exports.getCatalogs = void 0;
6
+ exports.getCatalogs = getCatalogs;
7
+ exports.getCatalogForMerge = getCatalogForMerge;
8
+ exports.getCatalogForFile = getCatalogForFile;
7
9
  const glob_1 = require("glob");
8
10
  const path_1 = __importDefault(require("path"));
9
11
  const catalog_1 = require("../catalog");
@@ -65,7 +67,6 @@ async function getCatalogs(config) {
65
67
  }
66
68
  return catalogs;
67
69
  }
68
- exports.getCatalogs = getCatalogs;
69
70
  /**
70
71
  * Ensure that value is always array. If not, turn it into an array of one element.
71
72
  */
@@ -88,7 +89,6 @@ async function getCatalogForMerge(config) {
88
89
  format,
89
90
  }, config);
90
91
  }
91
- exports.getCatalogForMerge = getCatalogForMerge;
92
92
  function getCatalogForFile(file, catalogs) {
93
93
  for (const catalog of catalogs) {
94
94
  const catalogFile = `${catalog.path}${catalog.format.getCatalogExtension()}`;
@@ -104,7 +104,6 @@ function getCatalogForFile(file, catalogs) {
104
104
  }
105
105
  return null;
106
106
  }
107
- exports.getCatalogForFile = getCatalogForFile;
108
107
  /**
109
108
  * Validate that `catalogPath` doesn't end with trailing slash
110
109
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFallbackListForLocale = void 0;
3
+ exports.getFallbackListForLocale = getFallbackListForLocale;
4
4
  function getFallbackListForLocale(fallbackLocales, locale) {
5
5
  const fL = [];
6
6
  if (fallbackLocales === null || fallbackLocales === void 0 ? void 0 : fallbackLocales[locale]) {
@@ -12,4 +12,3 @@ function getFallbackListForLocale(fallbackLocales, locale) {
12
12
  }
13
13
  return fL;
14
14
  }
15
- exports.getFallbackListForLocale = getFallbackListForLocale;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTranslationsForCatalog = void 0;
3
+ exports.getTranslationsForCatalog = getTranslationsForCatalog;
4
4
  const getFallbackListForLocale_1 = require("./getFallbackListForLocale");
5
5
  async function getTranslationsForCatalog(catalog, locale, options) {
6
6
  const [catalogs, template] = await Promise.all([
@@ -14,7 +14,6 @@ async function getTranslationsForCatalog(catalog, locale, options) {
14
14
  return acc;
15
15
  }, {});
16
16
  }
17
- exports.getTranslationsForCatalog = getTranslationsForCatalog;
18
17
  function sourceLocaleFallback(catalog, key) {
19
18
  if (!(catalog === null || catalog === void 0 ? void 0 : catalog[key])) {
20
19
  return null;
@@ -44,7 +43,7 @@ function getTranslation(catalogs, msg, locale, key, options) {
44
43
  // -> template message
45
44
  // ** last resort **
46
45
  // -> id
47
- let translation =
46
+ const translation =
48
47
  // Get translation in target locale
49
48
  getTranslation(locale) ||
50
49
  // We search in fallbackLocales as dependent of each locale
@@ -53,11 +52,10 @@ function getTranslation(catalogs, msg, locale, key, options) {
53
52
  sourceLocale === locale &&
54
53
  sourceLocaleFallback(catalogs[sourceLocale], key));
55
54
  if (!translation) {
56
- onMissing &&
57
- onMissing({
58
- id: key,
59
- source: msg.message || sourceLocaleFallback(catalogs[sourceLocale], key),
60
- });
55
+ onMissing === null || onMissing === void 0 ? void 0 : onMissing({
56
+ id: key,
57
+ source: msg.message || sourceLocaleFallback(catalogs[sourceLocale], key),
58
+ });
61
59
  }
62
60
  return (translation ||
63
61
  (sourceLocale && sourceLocaleFallback(catalogs[sourceLocale], key)) ||
@@ -1,55 +1,44 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
24
12
  };
25
13
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.mergeCatalog = void 0;
27
- const R = __importStar(require("ramda"));
14
+ exports.mergeCatalog = mergeCatalog;
28
15
  function mergeCatalog(prevCatalog, nextCatalog, forSourceLocale, options) {
29
16
  const nextKeys = Object.keys(nextCatalog);
30
- const prevKeys = R.keys(prevCatalog).map(String);
31
- const newKeys = R.difference(nextKeys, prevKeys);
32
- const mergeKeys = R.intersection(nextKeys, prevKeys);
33
- const obsoleteKeys = R.difference(prevKeys, nextKeys);
17
+ const prevKeys = Object.keys(prevCatalog || {});
18
+ const newKeys = nextKeys.filter((key) => !prevKeys.includes(key));
19
+ const mergeKeys = nextKeys.filter((key) => prevKeys.includes(key));
20
+ const obsoleteKeys = prevKeys.filter((key) => !nextKeys.includes(key));
34
21
  // Initialize new catalog with new keys
35
- const newMessages = R.mapObjIndexed((message, key) => (Object.assign({ translation: forSourceLocale ? message.message || key : "" }, message)), R.pick(newKeys, nextCatalog));
22
+ const newMessages = Object.fromEntries(newKeys.map((key) => [
23
+ key,
24
+ Object.assign({ translation: forSourceLocale ? nextCatalog[key].message || key : "" }, nextCatalog[key]),
25
+ ]));
36
26
  // Merge translations from previous catalog
37
- const mergedMessages = mergeKeys.map((key) => {
27
+ const mergedMessages = Object.fromEntries(mergeKeys.map((key) => {
38
28
  const updateFromDefaults = forSourceLocale &&
39
29
  (prevCatalog[key].translation === prevCatalog[key].message ||
40
30
  options.overwrite);
41
31
  const translation = updateFromDefaults
42
32
  ? nextCatalog[key].message || key
43
33
  : prevCatalog[key].translation;
44
- return {
45
- [key]: Object.assign({ translation }, R.omit(["obsolete, translation"], nextCatalog[key])),
46
- };
47
- });
34
+ const _a = nextCatalog[key], { obsolete } = _a, rest = __rest(_a, ["obsolete"]);
35
+ return [key, Object.assign(Object.assign({}, rest), { translation })];
36
+ }));
48
37
  // Mark all remaining translations as obsolete
49
38
  // Only if *options.files* is not provided
50
- const obsoleteMessages = obsoleteKeys.map((key) => ({
51
- [key]: Object.assign(Object.assign({}, prevCatalog[key]), (!options.files && { obsolete: true })),
52
- }));
53
- return R.mergeAll([newMessages, ...mergedMessages, ...obsoleteMessages]);
39
+ const obsoleteMessages = Object.fromEntries(obsoleteKeys.map((key) => [
40
+ key,
41
+ Object.assign(Object.assign({}, prevCatalog[key]), (options.files ? {} : { obsolete: true })),
42
+ ]));
43
+ return Object.assign(Object.assign(Object.assign({}, newMessages), mergedMessages), obsoleteMessages);
54
44
  }
55
- exports.mergeCatalog = mergeCatalog;
@@ -1,11 +1,10 @@
1
- import * as R from "ramda";
2
1
  import { LinguiConfigNormalized, OrderBy } from "@lingui/conf";
3
2
  import { FormatterWrapper } from "./formats";
4
3
  import { CliExtractOptions } from "../lingui-extract";
5
4
  import { CliExtractTemplateOptions } from "../lingui-extract-template";
6
5
  import { CompiledCatalogNamespace } from "./compile";
7
- import { GetTranslationsOptions } from "./catalog/getTranslationsForCatalog";
8
- import { AllCatalogsType, CatalogType, ExtractedCatalogType, ExtractedMessageType } from "./types";
6
+ import { GetTranslationsOptions, TranslationMissingEvent } from "./catalog/getTranslationsForCatalog";
7
+ import { AllCatalogsType, CatalogType, ExtractedCatalogType } from "./types";
9
8
  export type MakeOptions = CliExtractOptions & {
10
9
  orderBy?: OrderBy;
11
10
  };
@@ -42,11 +41,14 @@ export declare class Catalog {
42
41
  collect(options?: {
43
42
  files?: string[];
44
43
  }): Promise<ExtractedCatalogType | undefined>;
45
- merge(prevCatalogs: AllCatalogsType, nextCatalog: ExtractedCatalogType, options: MergeOptions): Record<string, CatalogType<{
46
- [x: string]: unknown;
47
- }>>;
48
- getTranslations(locale: string, options: GetTranslationsOptions): Promise<{
49
- [id: string]: string;
44
+ merge(prevCatalogs: AllCatalogsType, nextCatalog: ExtractedCatalogType, options: MergeOptions): {
45
+ [k: string]: CatalogType;
46
+ };
47
+ getTranslations(locale: string, options: Omit<GetTranslationsOptions, "onMissing">): Promise<{
48
+ missing: TranslationMissingEvent[];
49
+ messages: {
50
+ [id: string]: string;
51
+ };
50
52
  }>;
51
53
  write(locale: string, messages: CatalogType): Promise<[created: boolean, filename: string]>;
52
54
  writeTemplate(messages: CatalogType): Promise<void>;
@@ -58,10 +60,6 @@ export declare class Catalog {
58
60
  get localeDir(): string;
59
61
  get locales(): string[];
60
62
  }
61
- export declare const cleanObsolete: <K extends ExtractedMessageType<{
62
- [x: string]: unknown;
63
- }>[] | R.Dictionary<ExtractedMessageType<{
64
- [x: string]: unknown;
65
- }>>>(source: K) => K extends (infer U)[] ? U[] : K extends R.Dictionary<infer U_1> ? R.Dictionary<U_1> : never;
66
- export declare function order<T extends ExtractedCatalogType>(by: OrderBy): (catalog: T) => T;
63
+ export declare function cleanObsolete<T extends ExtractedCatalogType>(messages: T): T;
64
+ export declare function order<T extends ExtractedCatalogType>(by: OrderBy, catalog: T): T;
67
65
  export declare function orderByMessage<T extends ExtractedCatalogType>(messages: T): T;
@@ -1,35 +1,14 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.orderByMessage = exports.order = exports.cleanObsolete = exports.Catalog = void 0;
6
+ exports.Catalog = void 0;
7
+ exports.cleanObsolete = cleanObsolete;
8
+ exports.order = order;
9
+ exports.orderByMessage = orderByMessage;
30
10
  const fs_1 = __importDefault(require("fs"));
31
11
  const path_1 = __importDefault(require("path"));
32
- const R = __importStar(require("ramda"));
33
12
  const glob_1 = require("glob");
34
13
  const normalize_path_1 = __importDefault(require("normalize-path"));
35
14
  const getTranslationsForCatalog_1 = require("./catalog/getTranslationsForCatalog");
@@ -64,12 +43,13 @@ class Catalog {
64
43
  files: options.files,
65
44
  });
66
45
  // Map over all locales and post-process each catalog
67
- const cleanAndSort = R.map(R.pipe(
68
- // Clean obsolete messages
69
- (options.clean ? exports.cleanObsolete : R.identity),
70
- // Sort messages
71
- order(options.orderBy)));
72
- const sortedCatalogs = cleanAndSort(catalogs);
46
+ const sortedCatalogs = Object.fromEntries(Object.entries(catalogs).map(([locale, catalog]) => {
47
+ if (options.clean) {
48
+ catalog = cleanObsolete(catalog);
49
+ }
50
+ catalog = order(options.orderBy, catalog);
51
+ return [locale, catalog];
52
+ }));
73
53
  const locales = options.locale ? options.locale : this.locales;
74
54
  await Promise.all(locales.map((locale) => this.write(locale, sortedCatalogs[locale])));
75
55
  return sortedCatalogs;
@@ -78,7 +58,7 @@ class Catalog {
78
58
  const catalog = await this.collect({ files: options.files });
79
59
  if (!catalog)
80
60
  return false;
81
- const sorted = order(options.orderBy)(catalog);
61
+ const sorted = order(options.orderBy, catalog);
82
62
  await this.writeTemplate(sorted);
83
63
  return sorted;
84
64
  }
@@ -115,12 +95,20 @@ class Catalog {
115
95
  * - all other languages: translation is kept empty
116
96
  */
117
97
  merge(prevCatalogs, nextCatalog, options) {
118
- return R.mapObjIndexed((prevCatalog, locale) => {
119
- return (0, mergeCatalog_1.mergeCatalog)(prevCatalog, nextCatalog, this.config.sourceLocale === locale, options);
120
- }, prevCatalogs);
98
+ return Object.fromEntries(Object.entries(prevCatalogs).map(([locale, prevCatalog]) => [
99
+ locale,
100
+ (0, mergeCatalog_1.mergeCatalog)(prevCatalog, nextCatalog, this.config.sourceLocale === locale, options),
101
+ ]));
121
102
  }
122
103
  async getTranslations(locale, options) {
123
- return await (0, getTranslationsForCatalog_1.getTranslationsForCatalog)(this, locale, options);
104
+ const missing = [];
105
+ const messages = await (0, getTranslationsForCatalog_1.getTranslationsForCatalog)(this, locale, Object.assign(Object.assign({}, options), { onMissing: (event) => {
106
+ missing.push(event);
107
+ } }));
108
+ return {
109
+ missing,
110
+ messages,
111
+ };
124
112
  }
125
113
  async write(locale, messages) {
126
114
  const filename = this.getFilename(locale);
@@ -194,15 +182,16 @@ exports.Catalog = Catalog;
194
182
  function getTemplatePath(ext, path) {
195
183
  return path.replace(LOCALE_SUFFIX_RE, "messages" + ext);
196
184
  }
197
- exports.cleanObsolete = R.filter((message) => !message.obsolete);
198
- function order(by) {
185
+ function cleanObsolete(messages) {
186
+ return Object.fromEntries(Object.entries(messages).filter(([, message]) => !message.obsolete));
187
+ }
188
+ function order(by, catalog) {
199
189
  return {
200
190
  messageId: orderByMessageId,
201
191
  message: orderByMessage,
202
192
  origin: orderByOrigin,
203
- }[by];
193
+ }[by](catalog);
204
194
  }
205
- exports.order = order;
206
195
  /**
207
196
  * Object keys are in the same order as they were created
208
197
  * https://stackoverflow.com/a/31102605/1535540
@@ -263,4 +252,3 @@ function orderByMessage(messages) {
263
252
  return acc;
264
253
  }, {});
265
254
  }
266
- exports.orderByMessage = orderByMessage;
@@ -10,7 +10,24 @@ export type CreateCompileCatalogOptions = {
10
10
  pseudoLocale?: string;
11
11
  compilerBabelOptions?: GeneratorOptions;
12
12
  };
13
- export declare function createCompiledCatalog(locale: string, messages: CompiledCatalogType, options: CreateCompileCatalogOptions): string;
13
+ export type MessageCompilationError = {
14
+ /**
15
+ * ID of the message in the Catalog
16
+ */
17
+ id: string;
18
+ /**
19
+ * Message itself
20
+ */
21
+ source: string;
22
+ /**
23
+ * Error associated with this message
24
+ */
25
+ error: Error;
26
+ };
27
+ export declare function createCompiledCatalog(locale: string, messages: CompiledCatalogType, options: CreateCompileCatalogOptions): {
28
+ source: string;
29
+ errors: MessageCompilationError[];
30
+ };
14
31
  /**
15
32
  * Compile string message into AST tree. Message format is parsed/compiled into
16
33
  * JS arrays, which are handled in client.
@@ -15,18 +15,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
37
  };
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.compile = exports.createCompiledCatalog = void 0;
39
+ exports.createCompiledCatalog = createCompiledCatalog;
40
+ exports.compile = compile;
30
41
  const t = __importStar(require("@babel/types"));
31
42
  const generator_1 = __importDefault(require("@babel/generator"));
32
43
  const compileMessage_1 = require("@lingui/message-utils/compileMessage");
@@ -34,14 +45,24 @@ const pseudoLocalize_1 = __importDefault(require("./pseudoLocalize"));
34
45
  function createCompiledCatalog(locale, messages, options) {
35
46
  const { strict = false, namespace = "cjs", pseudoLocale, compilerBabelOptions = {}, } = options;
36
47
  const shouldPseudolocalize = locale === pseudoLocale;
48
+ const errors = [];
37
49
  const compiledMessages = Object.keys(messages).reduce((obj, key) => {
38
50
  // Don't use `key` as a fallback translation in strict mode.
39
51
  const translation = (messages[key] || (!strict ? key : ""));
40
- obj[key] = compile(translation, shouldPseudolocalize);
52
+ try {
53
+ obj[key] = compile(translation, shouldPseudolocalize);
54
+ }
55
+ catch (e) {
56
+ errors.push({
57
+ id: key,
58
+ source: translation,
59
+ error: e,
60
+ });
61
+ }
41
62
  return obj;
42
63
  }, {});
43
64
  if (namespace === "json") {
44
- return JSON.stringify({ messages: compiledMessages });
65
+ return { source: JSON.stringify({ messages: compiledMessages }), errors };
45
66
  }
46
67
  const ast = buildExportStatement(
47
68
  //build JSON.parse(<compiledMessages>) statement
@@ -49,9 +70,8 @@ function createCompiledCatalog(locale, messages, options) {
49
70
  const code = (0, generator_1.default)(ast, Object.assign({ minified: true, jsescOption: {
50
71
  minimal: true,
51
72
  } }, compilerBabelOptions)).code;
52
- return "/*eslint-disable*/" + code;
73
+ return { source: "/*eslint-disable*/" + code, errors };
53
74
  }
54
- exports.createCompiledCatalog = createCompiledCatalog;
55
75
  function buildExportStatement(expression, namespace) {
56
76
  if (namespace === "ts") {
57
77
  // import type { Messages } from "@lingui/core";
@@ -95,6 +115,5 @@ function buildExportStatement(expression, namespace) {
95
115
  * JS arrays, which are handled in client.
96
116
  */
97
117
  function compile(message, shouldPseudolocalize = false) {
98
- return (0, compileMessage_1.compileMessage)(message, (value) => shouldPseudolocalize ? (0, pseudoLocalize_1.default)(value) : value);
118
+ return (0, compileMessage_1.compileMessageOrThrow)(message, (value) => shouldPseudolocalize ? (0, pseudoLocalize_1.default)(value) : value);
99
119
  }
100
- exports.compile = compile;
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getBabelParserOptions = exports.extractFromFileWithBabel = exports.babelRe = void 0;
6
+ exports.babelRe = void 0;
7
+ exports.extractFromFileWithBabel = extractFromFileWithBabel;
8
+ exports.getBabelParserOptions = getBabelParserOptions;
7
9
  const core_1 = require("@babel/core");
8
10
  const babel_plugin_extract_messages_1 = __importDefault(require("@lingui/babel-plugin-extract-messages"));
9
11
  const babel_plugin_lingui_macro_1 = __importDefault(require("@lingui/babel-plugin-lingui-macro"));
@@ -12,7 +14,7 @@ exports.babelRe = new RegExp("\\.(" +
12
14
  .map((ext) => ext.slice(1))
13
15
  .join("|") +
14
16
  ")$", "i");
15
- const inlineSourceMapsRE = new RegExp(/\/[\/\*][#@]\s+sourceMappingURL=data:application\/json;(?:charset:utf-8;)?base64,/i);
17
+ const inlineSourceMapsRE = new RegExp(/\/[/*][#@]\s+sourceMappingURL=data:application\/json;(?:charset:utf-8;)?base64,/i);
16
18
  /**
17
19
  * Create a source mapper which could read original positions
18
20
  * from either inline sourcemaps or from external passed as `sourceMaps` argument.
@@ -112,12 +114,11 @@ async function extractFromFileWithBabel(filename, code, onMessageExtracted, ctx,
112
114
  });
113
115
  mapper.destroy();
114
116
  }
115
- exports.extractFromFileWithBabel = extractFromFileWithBabel;
116
117
  function getBabelParserOptions(filename, parserOptions) {
117
118
  // https://babeljs.io/docs/en/babel-parser#latest-ecmascript-features
118
119
  const parserPlugins = [
119
- "importAttributes",
120
- "explicitResourceManagement",
120
+ "importAttributes", // stage3
121
+ "explicitResourceManagement", // stage3,
121
122
  "decoratorAutoAccessors", // stage3,
122
123
  ];
123
124
  if ([/\.ts$/, /\.mts$/, /\.cts$/, /\.tsx$/].some((r) => filename.match(r))) {
@@ -140,7 +141,6 @@ function getBabelParserOptions(filename, parserOptions) {
140
141
  }
141
142
  return parserPlugins;
142
143
  }
143
- exports.getBabelParserOptions = getBabelParserOptions;
144
144
  const extractor = {
145
145
  match(filename) {
146
146
  return exports.babelRe.test(filename);
@@ -3,13 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = extract;
6
7
  const promises_1 = __importDefault(require("fs/promises"));
7
8
  const babel_1 = __importDefault(require("./babel"));
8
9
  const DEFAULT_EXTRACTORS = [babel_1.default];
9
10
  async function extract(filename, onMessageExtracted, linguiConfig, options) {
10
11
  var _a;
11
12
  const extractorsToExtract = (_a = options.extractors) !== null && _a !== void 0 ? _a : DEFAULT_EXTRACTORS;
12
- for (let ext of extractorsToExtract) {
13
+ for (const ext of extractorsToExtract) {
13
14
  if (!ext.match(filename))
14
15
  continue;
15
16
  try {
@@ -27,4 +28,3 @@ async function extract(filename, onMessageExtracted, linguiConfig, options) {
27
28
  }
28
29
  return true;
29
30
  }
30
- exports.default = extract;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFormat = exports.FormatterWrapper = void 0;
3
+ exports.FormatterWrapper = void 0;
4
+ exports.getFormat = getFormat;
4
5
  const formatterWrapper_1 = require("./formatterWrapper");
5
6
  Object.defineProperty(exports, "FormatterWrapper", { enumerable: true, get: function () { return formatterWrapper_1.FormatterWrapper; } });
6
7
  const utils_1 = require("../utils");
@@ -44,4 +45,3 @@ async function getFormat(_format, options, sourceLocale) {
44
45
  }
45
46
  return new formatterWrapper_1.FormatterWrapper((await format())(options), sourceLocale);
46
47
  }
47
- exports.getFormat = getFormat;
package/dist/api/help.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.helpRun = void 0;
3
+ exports.helpRun = helpRun;
4
4
  /**
5
5
  * Detect where is the command lingui extract or lingui compile
6
6
  * and how is being run (npm, yarn, pnpm) and construct help
@@ -29,7 +29,9 @@ function helpRun(command) {
29
29
  try {
30
30
  findRootPkgJson = require((0, path_1.resolve)((0, path_1.join)(process.cwd(), "package.json")));
31
31
  }
32
- catch (error) { }
32
+ catch (error) {
33
+ // noting
34
+ }
33
35
  if (findRootPkgJson === null || findRootPkgJson === void 0 ? void 0 : findRootPkgJson.scripts) {
34
36
  const res = Object.entries(findRootPkgJson.scripts).find(([_, value]) => value.includes(`lingui ${command}`));
35
37
  if (res) {
@@ -39,7 +41,6 @@ function helpRun(command) {
39
41
  const runCommand = runCommandFrom(process.env.npm_config_user_agent);
40
42
  return `${runCommand} ${command}`;
41
43
  }
42
- exports.helpRun = helpRun;
43
44
  function runCommandFrom(userAgent) {
44
45
  const defaultRunCommand = "npm run";
45
46
  if (!userAgent) {
@@ -3,4 +3,5 @@ export { getCatalogForFile, getCatalogs } from "./catalog/getCatalogs";
3
3
  export { createCompiledCatalog } from "./compile";
4
4
  export { default as extractor, extractFromFileWithBabel, } from "./extractors/babel";
5
5
  export { getCatalogDependentFiles } from "./catalog/getCatalogDependentFiles";
6
+ export { createMissingErrorMessage, createCompilationErrorMessage, } from "./messages";
6
7
  export * from "./types";
package/dist/api/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.getCatalogDependentFiles = exports.extractFromFileWithBabel = exports.extractor = exports.createCompiledCatalog = exports.getCatalogs = exports.getCatalogForFile = exports.getFormat = void 0;
20
+ exports.createCompilationErrorMessage = exports.createMissingErrorMessage = exports.getCatalogDependentFiles = exports.extractFromFileWithBabel = exports.extractor = exports.createCompiledCatalog = exports.getCatalogs = exports.getCatalogForFile = exports.getFormat = void 0;
21
21
  var formats_1 = require("./formats");
22
22
  Object.defineProperty(exports, "getFormat", { enumerable: true, get: function () { return formats_1.getFormat; } });
23
23
  var getCatalogs_1 = require("./catalog/getCatalogs");
@@ -30,4 +30,7 @@ Object.defineProperty(exports, "extractor", { enumerable: true, get: function ()
30
30
  Object.defineProperty(exports, "extractFromFileWithBabel", { enumerable: true, get: function () { return babel_1.extractFromFileWithBabel; } });
31
31
  var getCatalogDependentFiles_1 = require("./catalog/getCatalogDependentFiles");
32
32
  Object.defineProperty(exports, "getCatalogDependentFiles", { enumerable: true, get: function () { return getCatalogDependentFiles_1.getCatalogDependentFiles; } });
33
+ var messages_1 = require("./messages");
34
+ Object.defineProperty(exports, "createMissingErrorMessage", { enumerable: true, get: function () { return messages_1.createMissingErrorMessage; } });
35
+ Object.defineProperty(exports, "createCompilationErrorMessage", { enumerable: true, get: function () { return messages_1.createCompilationErrorMessage; } });
33
36
  __exportStar(require("./types"), exports);
@@ -0,0 +1,4 @@
1
+ import { TranslationMissingEvent } from "./catalog/getTranslationsForCatalog";
2
+ import { MessageCompilationError } from "./compile";
3
+ export declare function createMissingErrorMessage(locale: string, missingMessages: TranslationMissingEvent[], configurationMsg: string): string;
4
+ export declare function createCompilationErrorMessage(locale: string, errors: MessageCompilationError[]): string;
@@ -0,0 +1,32 @@
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.createMissingErrorMessage = createMissingErrorMessage;
7
+ exports.createCompilationErrorMessage = createCompilationErrorMessage;
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ function createMissingErrorMessage(locale, missingMessages, configurationMsg) {
10
+ let message = `Failed to compile catalog for locale ${chalk_1.default.bold(locale)}!
11
+
12
+ Missing ${missingMessages.length} translation(s):
13
+ \n`;
14
+ missingMessages.forEach((missing) => {
15
+ const source = missing.source || missing.source === missing.id
16
+ ? `: ${missing.source}`
17
+ : "";
18
+ message += `${missing.id}${source}\n`;
19
+ });
20
+ return message;
21
+ }
22
+ function createCompilationErrorMessage(locale, errors) {
23
+ let message = `Failed to compile catalog for locale ${chalk_1.default.bold(locale)}!
24
+
25
+ Compilation error for ${errors.length} translation(s):
26
+ \n`;
27
+ errors.forEach((error) => {
28
+ const source = error.source || error.source === error.id ? `: ${error.source}` : "";
29
+ message += `${error.id}${source}\nReason: ${error.error.message}\n\n`;
30
+ });
31
+ return message;
32
+ }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const ramda_1 = __importDefault(require("ramda"));
6
+ exports.default = default_1;
7
7
  const pseudolocale_1 = __importDefault(require("pseudolocale"));
8
8
  const delimiter = "%&&&%";
9
9
  /**
@@ -40,12 +40,13 @@ function addDelimitersVariables(message) {
40
40
  return `${delimiter}${matchedString}${delimiter}`;
41
41
  });
42
42
  }
43
- const addDelimiters = ramda_1.default.compose(addDelimitersVariables, addDelimitersMacro, addDelimitersHTMLTags);
44
43
  function removeDelimiters(message) {
45
44
  return message.replace(new RegExp(delimiter, "g"), "");
46
45
  }
47
46
  function default_1(message) {
48
- message = addDelimiters(message);
47
+ message = addDelimitersHTMLTags(message);
48
+ message = addDelimitersMacro(message);
49
+ message = addDelimitersVariables(message);
49
50
  message = (0, pseudolocale_1.default)(message, {
50
51
  delimiter,
51
52
  prepend: "",
@@ -53,4 +54,3 @@ function default_1(message) {
53
54
  });
54
55
  return removeDelimiters(message);
55
56
  }
56
- exports.default = default_1;
package/dist/api/stats.js CHANGED
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.printStats = exports.getStats = void 0;
6
+ exports.getStats = getStats;
7
+ exports.printStats = printStats;
8
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
9
  // @ts-ignore
8
10
  const cli_table_1 = __importDefault(require("cli-table"));
9
11
  const chalk_1 = __importDefault(require("chalk"));
@@ -13,7 +15,6 @@ function getStats(catalog) {
13
15
  Object.keys(catalog).filter((key) => !catalog[key].translation).length,
14
16
  ];
15
17
  }
16
- exports.getStats = getStats;
17
18
  function printStats(config, catalogs) {
18
19
  const table = new cli_table_1.default({
19
20
  head: ["Language", "Total count", "Missing"],
@@ -40,4 +41,3 @@ function printStats(config, catalogs) {
40
41
  });
41
42
  return table;
42
43
  }
43
- exports.printStats = printStats;
package/dist/api/utils.js CHANGED
@@ -3,7 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.makePathRegexSafe = exports.normalizeRelativePath = exports.makeInstall = exports.hasYarn = exports.writeFileIfChanged = exports.writeFile = exports.isDirectory = exports.readFile = exports.replacePlaceholders = exports.prettyOrigin = exports.PATHSEP = void 0;
6
+ exports.PATHSEP = void 0;
7
+ exports.prettyOrigin = prettyOrigin;
8
+ exports.replacePlaceholders = replacePlaceholders;
9
+ exports.readFile = readFile;
10
+ exports.isDirectory = isDirectory;
11
+ exports.writeFile = writeFile;
12
+ exports.writeFileIfChanged = writeFileIfChanged;
13
+ exports.hasYarn = hasYarn;
14
+ exports.makeInstall = makeInstall;
15
+ exports.normalizeRelativePath = normalizeRelativePath;
16
+ exports.makePathRegexSafe = makePathRegexSafe;
7
17
  const fs_1 = __importDefault(require("fs"));
8
18
  const path_1 = __importDefault(require("path"));
9
19
  const normalize_path_1 = __importDefault(require("normalize-path"));
@@ -16,14 +26,12 @@ function prettyOrigin(origins) {
16
26
  return "";
17
27
  }
18
28
  }
19
- exports.prettyOrigin = prettyOrigin;
20
29
  function replacePlaceholders(input, values) {
21
30
  return input.replace(/\{([^}]+)}/g, (m, placeholder) => {
22
31
  var _a;
23
32
  return (_a = values[placeholder]) !== null && _a !== void 0 ? _a : m;
24
33
  });
25
34
  }
26
- exports.replacePlaceholders = replacePlaceholders;
27
35
  async function readFile(fileName) {
28
36
  try {
29
37
  return (await fs_1.default.promises.readFile(fileName, "utf-8")).toString();
@@ -34,7 +42,6 @@ async function readFile(fileName) {
34
42
  }
35
43
  }
36
44
  }
37
- exports.readFile = readFile;
38
45
  async function mkdirp(dir) {
39
46
  try {
40
47
  await fs_1.default.promises.mkdir(dir, {
@@ -57,12 +64,10 @@ function isDirectory(filePath) {
57
64
  }
58
65
  }
59
66
  }
60
- exports.isDirectory = isDirectory;
61
67
  async function writeFile(fileName, content) {
62
68
  await mkdirp(path_1.default.dirname(fileName));
63
69
  await fs_1.default.promises.writeFile(fileName, content, "utf-8");
64
70
  }
65
- exports.writeFile = writeFile;
66
71
  async function writeFileIfChanged(filename, newContent) {
67
72
  const raw = await readFile(filename);
68
73
  if (raw) {
@@ -74,18 +79,15 @@ async function writeFileIfChanged(filename, newContent) {
74
79
  await writeFile(filename, newContent);
75
80
  }
76
81
  }
77
- exports.writeFileIfChanged = writeFileIfChanged;
78
82
  function hasYarn() {
79
83
  return fs_1.default.existsSync(path_1.default.resolve("yarn.lock"));
80
84
  }
81
- exports.hasYarn = hasYarn;
82
85
  function makeInstall(packageName, dev = false) {
83
86
  const withYarn = hasYarn();
84
87
  return withYarn
85
88
  ? `yarn add ${dev ? "--dev " : ""}${packageName}`
86
89
  : `npm install ${dev ? "--save-dev" : "--save"} ${packageName}`;
87
90
  }
88
- exports.makeInstall = makeInstall;
89
91
  /**
90
92
  * Remove ./ at the beginning: ./relative => relative
91
93
  * relative => relative
@@ -102,11 +104,9 @@ function normalizeRelativePath(sourcePath) {
102
104
  return ((0, normalize_path_1.default)(path_1.default.relative(process.cwd(), sourcePath), false) +
103
105
  (isDir ? "/" : ""));
104
106
  }
105
- exports.normalizeRelativePath = normalizeRelativePath;
106
107
  /**
107
108
  * Escape special regex characters used in file-based routing systems
108
109
  */
109
110
  function makePathRegexSafe(path) {
110
111
  return path.replace(/[(){}[\]^$+]/g, "\\$&");
111
112
  }
112
- exports.makePathRegexSafe = makePathRegexSafe;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bundleSource = void 0;
3
+ exports.bundleSource = bundleSource;
4
4
  const linguiEsbuildPlugin_1 = require("./linguiEsbuildPlugin");
5
5
  function createExtRegExp(extensions) {
6
6
  return new RegExp("\\.(?:" + extensions.join("|") + ")(?:\\?.*)?$");
@@ -59,4 +59,3 @@ async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
59
59
  ? config.resolveEsbuildOptions(esbuildOptions)
60
60
  : esbuildOptions);
61
61
  }
62
- exports.bundleSource = bundleSource;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEntryPoints = void 0;
3
+ exports.getEntryPoints = getEntryPoints;
4
4
  const glob_1 = require("glob");
5
5
  function getEntryPoints(entries) {
6
6
  return (0, glob_1.globSync)(entries, { mark: true });
7
7
  }
8
- exports.getEntryPoints = getEntryPoints;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExperimentalCatalogs = void 0;
3
+ exports.getExperimentalCatalogs = getExperimentalCatalogs;
4
4
  const getEntryPoints_1 = require("./getEntryPoints");
5
5
  const resolveCatalogPath_1 = require("./resolveCatalogPath");
6
6
  const catalog_1 = require("../api/catalog");
@@ -23,4 +23,3 @@ async function getExperimentalCatalogs(linguiConfig) {
23
23
  }, linguiConfig);
24
24
  });
25
25
  }
26
- exports.getExperimentalCatalogs = getExperimentalCatalogs;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getEntryName = exports.resolveCatalogPath = void 0;
6
+ exports.resolveCatalogPath = resolveCatalogPath;
7
+ exports.getEntryName = getEntryName;
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const utils_1 = require("../api/utils");
9
10
  function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension) {
@@ -15,9 +16,7 @@ function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension)
15
16
  locale,
16
17
  }) + extension);
17
18
  }
18
- exports.resolveCatalogPath = resolveCatalogPath;
19
19
  function getEntryName(entryPath) {
20
20
  const parsedPath = path_1.default.parse(entryPath);
21
21
  return parsedPath.name.replace(parsedPath.ext, "");
22
22
  }
23
- exports.getEntryName = getEntryName;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveTemplatePath = void 0;
3
+ exports.resolveTemplatePath = resolveTemplatePath;
4
4
  const resolveCatalogPath_1 = require("./resolveCatalogPath");
5
5
  const constants_1 = require("./constants");
6
6
  function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
@@ -13,4 +13,3 @@ function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
13
13
  }
14
14
  return (0, resolveCatalogPath_1.resolveCatalogPath)(output, entryPoint, rootDir, templateName, catalogExtension);
15
15
  }
16
- exports.resolveTemplatePath = resolveTemplatePath;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.writeTemplate = exports.writeCatalogs = void 0;
6
+ exports.writeCatalogs = writeCatalogs;
7
+ exports.writeTemplate = writeTemplate;
7
8
  const resolveTemplatePath_1 = require("./resolveTemplatePath");
8
9
  const chalk_1 = __importDefault(require("chalk"));
9
10
  const resolveCatalogPath_1 = require("./resolveCatalogPath");
@@ -14,7 +15,7 @@ function cleanAndSort(catalog, clean, orderBy) {
14
15
  if (clean) {
15
16
  catalog = (0, catalog_1.cleanObsolete)(catalog);
16
17
  }
17
- return (0, catalog_1.order)(orderBy)(catalog);
18
+ return (0, catalog_1.order)(orderBy, catalog);
18
19
  }
19
20
  async function writeCatalogs(params) {
20
21
  const { entryPoint, outputPattern, linguiConfig, locales, overwrite, format, clean, messages, } = params;
@@ -29,7 +30,6 @@ async function writeCatalogs(params) {
29
30
  statMessage: (0, stats_1.printStats)(linguiConfig, stat).toString(),
30
31
  };
31
32
  }
32
- exports.writeCatalogs = writeCatalogs;
33
33
  async function writeTemplate(params) {
34
34
  const { entryPoint, outputPattern, linguiConfig, format, clean, messages } = params;
35
35
  const catalogOutput = (0, resolveTemplatePath_1.resolveTemplatePath)(entryPoint, outputPattern, linguiConfig.rootDir, format.getTemplateExtension());
@@ -38,4 +38,3 @@ async function writeTemplate(params) {
38
38
  statMessage: `${chalk_1.default.bold(Object.keys(messages).length)} message(s) extracted`,
39
39
  };
40
40
  }
41
- exports.writeTemplate = writeTemplate;
@@ -2,6 +2,7 @@ import { LinguiConfigNormalized } from "@lingui/conf";
2
2
  export type CliCompileOptions = {
3
3
  verbose?: boolean;
4
4
  allowEmpty?: boolean;
5
+ failOnCompileError?: boolean;
5
6
  typescript?: boolean;
6
7
  watch?: boolean;
7
8
  namespace?: string;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.command = void 0;
6
+ exports.command = command;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const chokidar_1 = __importDefault(require("chokidar"));
9
9
  const commander_1 = require("commander");
@@ -22,15 +22,13 @@ async function command(config, options) {
22
22
  console.log("Compiling message catalogs…");
23
23
  for (const locale of config.locales) {
24
24
  for (const catalog of catalogs) {
25
- const missingMessages = [];
26
- const messages = await catalog.getTranslations(locale, {
25
+ const { messages, missing: missingMessages } = await catalog.getTranslations(locale, {
27
26
  fallbackLocales: config.fallbackLocales,
28
27
  sourceLocale: config.sourceLocale,
29
- onMissing: (missing) => {
30
- missingMessages.push(missing);
31
- },
32
28
  });
33
- if (!options.allowEmpty && missingMessages.length > 0) {
29
+ if (!options.allowEmpty &&
30
+ locale !== config.pseudoLocale &&
31
+ missingMessages.length > 0) {
34
32
  console.error(chalk_1.default.red(`Error: Failed to compile catalog for locale ${chalk_1.default.bold(locale)}!`));
35
33
  if (options.verbose) {
36
34
  console.error(chalk_1.default.red("Missing translations:"));
@@ -51,38 +49,44 @@ async function command(config, options) {
51
49
  mergedCatalogs = Object.assign(Object.assign({}, mergedCatalogs), messages);
52
50
  }
53
51
  else {
54
- const namespace = options.typescript
55
- ? "ts"
56
- : options.namespace || config.compileNamespace;
57
- const compiledCatalog = (0, compile_1.createCompiledCatalog)(locale, messages, {
58
- strict: false,
59
- namespace,
60
- pseudoLocale: config.pseudoLocale,
61
- compilerBabelOptions: config.compilerBabelOptions,
62
- });
63
- let compiledPath = await catalog.writeCompiled(locale, compiledCatalog, namespace);
64
- compiledPath = (0, normalize_path_1.default)(path_1.default.relative(config.rootDir, compiledPath));
65
- options.verbose &&
66
- console.error(chalk_1.default.green(`${locale} ⇒ ${compiledPath}`));
52
+ if (!(await compileAndWrite(locale, config, options, catalog, messages))) {
53
+ return false;
54
+ }
67
55
  }
68
56
  }
69
57
  if (doMerge) {
70
- const compileCatalog = await (0, getCatalogs_1.getCatalogForMerge)(config);
71
- const namespace = options.namespace || config.compileNamespace;
72
- const compiledCatalog = (0, compile_1.createCompiledCatalog)(locale, mergedCatalogs, {
73
- strict: false,
74
- namespace: namespace,
75
- pseudoLocale: config.pseudoLocale,
76
- compilerBabelOptions: config.compilerBabelOptions,
77
- });
78
- let compiledPath = await compileCatalog.writeCompiled(locale, compiledCatalog, namespace);
79
- compiledPath = (0, normalize_path_1.default)(path_1.default.relative(config.rootDir, compiledPath));
80
- options.verbose && console.log(chalk_1.default.green(`${locale} ⇒ ${compiledPath}`));
58
+ return await compileAndWrite(locale, config, options, await (0, getCatalogs_1.getCatalogForMerge)(config), mergedCatalogs);
81
59
  }
82
60
  }
83
61
  return true;
84
62
  }
85
- exports.command = command;
63
+ async function compileAndWrite(locale, config, options, catalogToWrite, messages) {
64
+ const namespace = options.typescript
65
+ ? "ts"
66
+ : options.namespace || config.compileNamespace;
67
+ const { source: compiledCatalog, errors } = (0, compile_1.createCompiledCatalog)(locale, messages, {
68
+ strict: false,
69
+ namespace,
70
+ pseudoLocale: config.pseudoLocale,
71
+ compilerBabelOptions: config.compilerBabelOptions,
72
+ });
73
+ if (errors.length) {
74
+ let message = (0, api_1.createCompilationErrorMessage)(locale, errors);
75
+ if (options.failOnCompileError) {
76
+ message += `These errors fail command execution because \`--strict\` option passed`;
77
+ console.error(chalk_1.default.red(message));
78
+ return false;
79
+ }
80
+ else {
81
+ message += `You can fail command execution on these errors by passing \`--strict\` option`;
82
+ console.error(chalk_1.default.red(message));
83
+ }
84
+ }
85
+ let compiledPath = await catalogToWrite.writeCompiled(locale, compiledCatalog, namespace);
86
+ compiledPath = (0, normalize_path_1.default)(path_1.default.relative(config.rootDir, compiledPath));
87
+ options.verbose && console.error(chalk_1.default.green(`${locale} ⇒ ${compiledPath}`));
88
+ return true;
89
+ }
86
90
  if (require.main === module) {
87
91
  commander_1.program
88
92
  .description("Add compile message catalogs and add language data (plurals) to compiled bundle.")
@@ -111,6 +115,7 @@ if (require.main === module) {
111
115
  previousRun = previousRun.then(() => command(config, {
112
116
  verbose: options.watch || options.verbose || false,
113
117
  allowEmpty: !options.strict,
118
+ failOnCompileError: !!options.strict,
114
119
  typescript: options.typescript || config.compileNamespace === "ts" || false,
115
120
  namespace: options.namespace, // we want this to be undefined if user does not specify so default can be used
116
121
  }));
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.default = command;
7
8
  const commander_1 = require("commander");
8
9
  const conf_1 = require("@lingui/conf");
9
10
  const path_1 = __importDefault(require("path"));
@@ -98,7 +99,6 @@ async function command(linguiConfig, options) {
98
99
  });
99
100
  return commandSuccess;
100
101
  }
101
- exports.default = command;
102
102
  if (require.main === module) {
103
103
  commander_1.program
104
104
  .option("--config <path>", "Path to the config file")
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = command;
6
7
  const chalk_1 = __importDefault(require("chalk"));
7
8
  const commander_1 = require("commander");
8
9
  const conf_1 = require("@lingui/conf");
@@ -27,7 +28,6 @@ async function command(config, options) {
27
28
  });
28
29
  return commandSuccess;
29
30
  }
30
- exports.default = command;
31
31
  if (require.main === module) {
32
32
  commander_1.program
33
33
  .option("--config <path>", "Path to the config file")
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = command;
6
7
  const chalk_1 = __importDefault(require("chalk"));
7
8
  const chokidar_1 = __importDefault(require("chokidar"));
8
9
  const commander_1 = require("commander");
@@ -19,7 +20,7 @@ async function command(config, options) {
19
20
  const catalogStats = {};
20
21
  let commandSuccess = true;
21
22
  const spinner = (0, ora_1.default)().start();
22
- for (let catalog of catalogs) {
23
+ for (const catalog of catalogs) {
23
24
  const result = await catalog.make(Object.assign(Object.assign({}, options), { orderBy: config.orderBy }));
24
25
  catalogStats[(0, normalize_path_1.default)(path_1.default.relative(config.rootDir, catalog.path))] = result || {};
25
26
  commandSuccess && (commandSuccess = Boolean(result));
@@ -57,7 +58,6 @@ async function command(config, options) {
57
58
  }
58
59
  return commandSuccess;
59
60
  }
60
- exports.default = command;
61
61
  if (require.main === module) {
62
62
  commander_1.program
63
63
  .option("--config <path>", "Path to the config file")
@@ -135,8 +135,8 @@ if (require.main === module) {
135
135
  console.info(chalk_1.default.bold("Initializing Watch Mode..."));
136
136
  (async function initWatch() {
137
137
  const catalogs = await (0, api_1.getCatalogs)(config);
138
- let paths = [];
139
- let ignored = [];
138
+ const paths = [];
139
+ const ignored = [];
140
140
  catalogs.forEach((catalog) => {
141
141
  paths.push(...catalog.include);
142
142
  ignored.push(...catalog.exclude);
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = syncProcess;
6
7
  const fs_1 = __importDefault(require("fs"));
7
8
  const path_1 = require("path");
8
9
  const pofile_1 = __importDefault(require("pofile"));
@@ -48,7 +49,6 @@ async function syncProcess(config, options) {
48
49
  });
49
50
  });
50
51
  }
51
- exports.default = syncProcess;
52
52
  // Initialize project with source and existing translations (only first time!)
53
53
  // Cf. https://translation.io/docs/create-library#initialization
54
54
  function init(config, options, successCallback, failCallback) {
@@ -146,7 +146,7 @@ function createSegmentFromPoItem(item) {
146
146
  const itemHasExplicitId = item.extractedComments.includes(EXPLICIT_ID_FLAG);
147
147
  const itemHasContext = item.msgctxt != null;
148
148
  const segment = {
149
- type: "source",
149
+ type: "source", // No way to edit text for source language (inside code), so not using "key" here
150
150
  source: "",
151
151
  context: "",
152
152
  references: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "5.1.2",
3
+ "version": "5.3.0",
4
4
  "description": "CLI for working wit message catalogs",
5
5
  "keywords": [
6
6
  "cli",
@@ -57,12 +57,12 @@
57
57
  "@babel/parser": "^7.22.0",
58
58
  "@babel/runtime": "^7.21.0",
59
59
  "@babel/types": "^7.21.2",
60
- "@lingui/babel-plugin-extract-messages": "^5.1.2",
61
- "@lingui/babel-plugin-lingui-macro": "^5.1.2",
62
- "@lingui/conf": "^5.1.2",
63
- "@lingui/core": "^5.1.2",
64
- "@lingui/format-po": "^5.1.2",
65
- "@lingui/message-utils": "^5.1.2",
60
+ "@lingui/babel-plugin-extract-messages": "5.3.0",
61
+ "@lingui/babel-plugin-lingui-macro": "5.3.0",
62
+ "@lingui/conf": "5.3.0",
63
+ "@lingui/core": "5.3.0",
64
+ "@lingui/format-po": "5.3.0",
65
+ "@lingui/message-utils": "5.3.0",
66
66
  "babel-plugin-macros": "^3.0.1",
67
67
  "chalk": "^4.1.0",
68
68
  "chokidar": "3.5.1",
@@ -80,16 +80,15 @@
80
80
  "pkg-up": "^3.1.0",
81
81
  "pofile": "^1.1.4",
82
82
  "pseudolocale": "^2.0.0",
83
- "ramda": "^0.27.1",
84
83
  "source-map": "^0.8.0-beta.0"
85
84
  },
86
85
  "devDependencies": {
87
- "@lingui/jest-mocks": "^3.0.3",
86
+ "@lingui/jest-mocks": "*",
88
87
  "@types/convert-source-map": "^2.0.0",
89
88
  "@types/micromatch": "^4.0.1",
90
89
  "@types/normalize-path": "^3.0.0",
91
90
  "mock-fs": "^5.2.0",
92
91
  "mockdate": "^3.0.5"
93
92
  },
94
- "gitHead": "e45a2af5dfc1c88131fa8196d596e0f0f25678ea"
93
+ "gitHead": "ed491cce7e5209378922327e0e7b802fb7b5873d"
95
94
  }