@lingui/cli 5.3.3 → 5.4.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.
@@ -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 (const filename of paths) {
26
+ await Promise.all(paths.map(async (filename) => {
27
27
  const fileSuccess = await (0, extractors_1.default)(filename, (next) => {
28
28
  var _a;
29
29
  if (!messages[next.id]) {
@@ -47,13 +47,13 @@ async function extractFromFiles(paths, config) {
47
47
  `\n${picocolors_1.default.yellow((0, utils_1.prettyOrigin)([origin]))} ${next.message}`);
48
48
  }
49
49
  messages[next.id] = Object.assign(Object.assign({}, prev), { message: (_a = prev.message) !== null && _a !== void 0 ? _a : next.message, comments: next.comment
50
- ? [...prev.comments, next.comment]
51
- : prev.comments, origin: [...prev.origin, [filename, next.origin[1]]], placeholders: mergePlaceholders(prev.placeholders, next.placeholders) });
50
+ ? [...prev.comments, next.comment].sort()
51
+ : prev.comments, origin: [...prev.origin, [filename, next.origin[1]]].sort((a, b) => a[0].localeCompare(b[0])), placeholders: mergePlaceholders(prev.placeholders, next.placeholders) });
52
52
  }, config, {
53
53
  extractors: config.extractors,
54
54
  });
55
55
  catalogSuccess && (catalogSuccess = fileSuccess);
56
- }
56
+ }));
57
57
  if (!catalogSuccess)
58
58
  return undefined;
59
59
  return messages;
@@ -34,10 +34,12 @@ class Catalog {
34
34
  this.format.getCatalogExtension());
35
35
  }
36
36
  async make(options) {
37
- const nextCatalog = await this.collect({ files: options.files });
37
+ const [nextCatalog, prevCatalogs] = await Promise.all([
38
+ this.collect({ files: options.files }),
39
+ this.readAll(),
40
+ ]);
38
41
  if (!nextCatalog)
39
42
  return false;
40
- const prevCatalogs = await this.readAll();
41
43
  const catalogs = this.merge(prevCatalogs, nextCatalog, {
42
44
  overwrite: options.overwrite,
43
45
  files: options.files,
@@ -46,7 +46,9 @@ function createCompiledCatalog(locale, messages, options) {
46
46
  const { strict = false, namespace = "cjs", pseudoLocale, compilerBabelOptions = {}, } = options;
47
47
  const shouldPseudolocalize = locale === pseudoLocale;
48
48
  const errors = [];
49
- const compiledMessages = Object.keys(messages).reduce((obj, key) => {
49
+ const compiledMessages = Object.keys(messages)
50
+ .sort()
51
+ .reduce((obj, key) => {
50
52
  // Don't use `key` as a fallback translation in strict mode.
51
53
  const translation = (messages[key] || (!strict ? key : ""));
52
54
  try {
@@ -14,54 +14,70 @@ const api_1 = require("./api");
14
14
  const getCatalogs_1 = require("./api/catalog/getCatalogs");
15
15
  const normalize_path_1 = __importDefault(require("normalize-path"));
16
16
  const path_1 = __importDefault(require("path"));
17
+ class ProgramExit extends Error {
18
+ }
17
19
  async function command(config, options) {
18
20
  const catalogs = await (0, api_1.getCatalogs)(config);
19
21
  // Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
20
22
  const doMerge = !!config.catalogsMergePath;
21
- let mergedCatalogs = {};
22
23
  console.log("Compiling message catalogs…");
23
- for (const locale of config.locales) {
24
- for (const catalog of catalogs) {
25
- const { messages, missing: missingMessages } = await catalog.getTranslations(locale, {
26
- fallbackLocales: config.fallbackLocales,
27
- sourceLocale: config.sourceLocale,
28
- });
29
- if (!options.allowEmpty &&
30
- locale !== config.pseudoLocale &&
31
- missingMessages.length > 0) {
32
- console.error(picocolors_1.default.red(`Error: Failed to compile catalog for locale ${picocolors_1.default.bold(locale)}!`));
33
- if (options.verbose) {
34
- console.error(picocolors_1.default.red("Missing translations:"));
35
- missingMessages.forEach((missing) => {
36
- const source = missing.source || missing.source === missing.id
37
- ? `: (${missing.source})`
38
- : "";
39
- console.error(`${missing.id}${source}`);
40
- });
41
- }
42
- else {
43
- console.error(picocolors_1.default.red(`Missing ${missingMessages.length} translation(s)`));
44
- }
45
- console.error();
46
- return false;
24
+ let errored = false;
25
+ await Promise.all(config.locales.map(async (locale) => {
26
+ try {
27
+ await compileLocale(locale, catalogs, options, config, doMerge);
28
+ }
29
+ catch (err) {
30
+ if (err instanceof ProgramExit) {
31
+ errored = true;
47
32
  }
48
- if (doMerge) {
49
- mergedCatalogs = Object.assign(Object.assign({}, mergedCatalogs), messages);
33
+ else {
34
+ throw err;
35
+ }
36
+ }
37
+ }));
38
+ return !errored;
39
+ }
40
+ async function compileLocale(locale, catalogs, options, config, doMerge) {
41
+ let mergedCatalogs = {};
42
+ await Promise.all(catalogs.map(async (catalog) => {
43
+ const { messages, missing: missingMessages } = await catalog.getTranslations(locale, {
44
+ fallbackLocales: config.fallbackLocales,
45
+ sourceLocale: config.sourceLocale,
46
+ });
47
+ if (!options.allowEmpty &&
48
+ locale !== config.pseudoLocale &&
49
+ missingMessages.length > 0) {
50
+ console.error(picocolors_1.default.red(`Error: Failed to compile catalog for locale ${picocolors_1.default.bold(locale)}!`));
51
+ if (options.verbose) {
52
+ console.error(picocolors_1.default.red("Missing translations:"));
53
+ missingMessages.forEach((missing) => {
54
+ const source = missing.source || missing.source === missing.id
55
+ ? `: (${missing.source})`
56
+ : "";
57
+ console.error(`${missing.id}${source}`);
58
+ });
50
59
  }
51
60
  else {
52
- if (!(await compileAndWrite(locale, config, options, catalog, messages))) {
53
- return false;
54
- }
61
+ console.error(picocolors_1.default.red(`Missing ${missingMessages.length} translation(s)`));
55
62
  }
63
+ console.error();
64
+ throw new ProgramExit();
56
65
  }
57
66
  if (doMerge) {
58
- const result = await compileAndWrite(locale, config, options, await (0, getCatalogs_1.getCatalogForMerge)(config), mergedCatalogs);
59
- if (!result) {
60
- return false;
67
+ mergedCatalogs = Object.assign(Object.assign({}, mergedCatalogs), messages);
68
+ }
69
+ else {
70
+ if (!(await compileAndWrite(locale, config, options, catalog, messages))) {
71
+ throw new ProgramExit();
61
72
  }
62
73
  }
74
+ }));
75
+ if (doMerge) {
76
+ const result = await compileAndWrite(locale, config, options, await (0, getCatalogs_1.getCatalogForMerge)(config), mergedCatalogs);
77
+ if (!result) {
78
+ throw new ProgramExit();
79
+ }
63
80
  }
64
- return true;
65
81
  }
66
82
  async function compileAndWrite(locale, config, options, catalogToWrite, messages) {
67
83
  const namespace = options.typescript
@@ -20,11 +20,11 @@ async function command(config, options) {
20
20
  const catalogStats = {};
21
21
  let commandSuccess = true;
22
22
  const spinner = (0, ora_1.default)().start();
23
- for (const catalog of catalogs) {
23
+ await Promise.all(catalogs.map(async (catalog) => {
24
24
  const result = await catalog.make(Object.assign(Object.assign({}, options), { orderBy: config.orderBy }));
25
25
  catalogStats[(0, normalize_path_1.default)(path_1.default.relative(config.rootDir, catalog.path))] = result || {};
26
26
  commandSuccess && (commandSuccess = Boolean(result));
27
- }
27
+ }));
28
28
  if (commandSuccess) {
29
29
  spinner.succeed();
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "5.3.3",
3
+ "version": "5.4.0",
4
4
  "description": "CLI for working wit message catalogs",
5
5
  "keywords": [
6
6
  "cli",
@@ -12,6 +12,7 @@
12
12
  "translation",
13
13
  "multilingual"
14
14
  ],
15
+ "homepage": "https://lingui.dev",
15
16
  "repository": {
16
17
  "type": "git",
17
18
  "url": "git+https://github.com/lingui/js-lingui.git",
@@ -61,12 +62,12 @@
61
62
  "@babel/parser": "^7.22.0",
62
63
  "@babel/runtime": "^7.21.0",
63
64
  "@babel/types": "^7.21.2",
64
- "@lingui/babel-plugin-extract-messages": "5.3.3",
65
- "@lingui/babel-plugin-lingui-macro": "5.3.3",
66
- "@lingui/conf": "5.3.3",
67
- "@lingui/core": "5.3.3",
68
- "@lingui/format-po": "5.3.3",
69
- "@lingui/message-utils": "5.3.3",
65
+ "@lingui/babel-plugin-extract-messages": "5.4.0",
66
+ "@lingui/babel-plugin-lingui-macro": "5.4.0",
67
+ "@lingui/conf": "5.4.0",
68
+ "@lingui/core": "5.4.0",
69
+ "@lingui/format-po": "5.4.0",
70
+ "@lingui/message-utils": "5.4.0",
70
71
  "chokidar": "3.5.1",
71
72
  "cli-table": "^0.3.11",
72
73
  "commander": "^10.0.0",
@@ -90,5 +91,5 @@
90
91
  "mock-fs": "^5.2.0",
91
92
  "mockdate": "^3.0.5"
92
93
  },
93
- "gitHead": "f8dc4af3d9110f53613bb1b2fb303d6751e7a7b1"
94
+ "gitHead": "ce0d17bd0874f5f4f01fd073749f29087835a315"
94
95
  }