@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.
- package/dist/api/ProgramExit.js +1 -5
- package/dist/api/catalog/extractFromFiles.d.ts +4 -4
- package/dist/api/catalog/extractFromFiles.js +38 -32
- package/dist/api/catalog/getCatalogDependentFiles.d.ts +1 -1
- package/dist/api/catalog/getCatalogDependentFiles.js +8 -47
- package/dist/api/catalog/getCatalogs.d.ts +2 -2
- package/dist/api/catalog/getCatalogs.js +35 -44
- package/dist/api/catalog/getFallbackListForLocale.js +5 -8
- package/dist/api/catalog/getTranslationsForCatalog.d.ts +1 -1
- package/dist/api/catalog/getTranslationsForCatalog.js +9 -13
- package/dist/api/catalog/mergeCatalog.d.ts +3 -3
- package/dist/api/catalog/mergeCatalog.js +13 -21
- package/dist/api/catalog.d.ts +15 -15
- package/dist/api/catalog.js +51 -48
- package/dist/api/compile/compileLocale.d.ts +3 -3
- package/dist/api/compile/compileLocale.js +28 -33
- package/dist/api/compile.js +13 -49
- package/dist/api/extractors/babel.d.ts +2 -2
- package/dist/api/extractors/babel.js +52 -45
- package/dist/api/extractors/index.js +6 -13
- package/dist/api/formats/formatterWrapper.d.ts +2 -2
- package/dist/api/formats/formatterWrapper.js +10 -12
- package/dist/api/formats/index.d.ts +3 -4
- package/dist/api/formats/index.js +5 -44
- package/dist/api/getPathsForCompileWatcher.d.ts +7 -0
- package/dist/api/getPathsForCompileWatcher.js +15 -0
- package/dist/api/getPathsForExtractWatcher.d.ts +8 -0
- package/dist/api/getPathsForExtractWatcher.js +14 -0
- package/dist/api/help.js +5 -7
- package/dist/api/index.d.ts +7 -7
- package/dist/api/index.js +7 -36
- package/dist/api/logger.d.ts +1 -1
- package/dist/api/logger.js +1 -2
- package/dist/api/messages.d.ts +2 -2
- package/dist/api/messages.js +5 -12
- package/dist/api/pseudoLocalize.js +3 -9
- package/dist/api/resolveWorkersOptions.js +3 -9
- package/dist/api/rethrownError.js +2 -5
- package/dist/api/stats.d.ts +3 -2
- package/dist/api/stats.js +7 -16
- package/dist/api/typedPool.d.ts +6 -0
- package/dist/api/typedPool.js +16 -0
- package/dist/api/types.js +1 -2
- package/dist/api/utils.d.ts +2 -2
- package/dist/api/utils.js +24 -41
- package/dist/api/workerLogger.d.ts +2 -2
- package/dist/api/workerLogger.js +2 -8
- package/dist/api/workerPools.d.ts +3 -0
- package/dist/api/workerPools.js +7 -0
- package/dist/extract-experimental/buildIncludeDepsFilter.js +1 -4
- package/dist/extract-experimental/bundleSource.d.ts +3 -2
- package/dist/extract-experimental/bundleSource.js +10 -13
- package/dist/extract-experimental/constants.js +2 -5
- package/dist/extract-experimental/extractFromBundleAndWrite.d.ts +3 -4
- package/dist/extract-experimental/extractFromBundleAndWrite.js +11 -17
- package/dist/extract-experimental/getExperimentalCatalogs.d.ts +4 -3
- package/dist/extract-experimental/getExperimentalCatalogs.js +10 -15
- package/dist/extract-experimental/linguiEsbuildPlugin.js +12 -19
- package/dist/extract-experimental/resolveCatalogPath.d.ts +1 -1
- package/dist/extract-experimental/resolveCatalogPath.js +7 -14
- package/dist/extract-experimental/resolveTemplatePath.js +7 -10
- package/dist/extract-experimental/workers/extractWorker.d.ts +5 -3
- package/dist/extract-experimental/workers/extractWorker.js +7 -10
- package/dist/extract-experimental/workers/extractWorkerWrapper.prod.d.ts +8 -0
- package/dist/extract-experimental/workers/extractWorkerWrapper.prod.js +2 -0
- package/dist/extract-experimental/writeCatalogs.d.ts +2 -2
- package/dist/extract-experimental/writeCatalogs.js +15 -22
- package/dist/index.js +1 -5
- package/dist/lingui-compile.d.ts +1 -1
- package/dist/lingui-compile.js +45 -59
- package/dist/lingui-extract-experimental.d.ts +3 -2
- package/dist/lingui-extract-experimental.js +58 -62
- package/dist/lingui-extract-template.d.ts +5 -4
- package/dist/lingui-extract-template.js +25 -27
- package/dist/lingui-extract.d.ts +3 -4
- package/dist/lingui-extract.js +62 -69
- package/dist/lingui.js +5 -10
- package/dist/services/translationIO/segment-converters.d.ts +1 -1
- package/dist/services/translationIO/segment-converters.js +16 -20
- package/dist/services/translationIO/translationio-api.d.ts +11 -7
- package/dist/services/translationIO/translationio-api.js +2 -19
- package/dist/services/translationIO.d.ts +4 -4
- package/dist/services/translationIO.js +28 -35
- package/dist/workers/compileWorker.d.ts +8 -11
- package/dist/workers/compileWorker.js +30 -36
- package/dist/workers/compileWorkerWrapper.prod.d.ts +7 -0
- package/dist/workers/compileWorkerWrapper.prod.js +2 -0
- package/dist/workers/extractWorker.d.ts +2 -3
- package/dist/workers/extractWorker.js +5 -12
- package/dist/workers/extractWorkerWrapper.prod.d.ts +6 -0
- package/dist/workers/extractWorkerWrapper.prod.js +2 -0
- package/package.json +26 -43
- package/dist/api/extractWorkerPool.d.ts +0 -1
- package/dist/api/extractWorkerPool.js +0 -8
- package/dist/api/extractors/typescript.d.ts +0 -3
- package/dist/api/extractors/typescript.js +0 -11
- package/dist/extract-experimental/getEntryPoints.d.ts +0 -1
- package/dist/extract-experimental/getEntryPoints.js +0 -7
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class FormatterWrapper {
|
|
1
|
+
import { readFile, writeFileIfChanged } from "../utils.js";
|
|
2
|
+
import { RethrownError } from "../rethrownError.js";
|
|
3
|
+
export class FormatterWrapper {
|
|
4
|
+
f;
|
|
5
|
+
sourceLocale;
|
|
7
6
|
constructor(f, sourceLocale) {
|
|
8
7
|
this.f = f;
|
|
9
8
|
this.sourceLocale = sourceLocale;
|
|
@@ -18,15 +17,15 @@ class FormatterWrapper {
|
|
|
18
17
|
const content = await this.f.serialize(catalog, {
|
|
19
18
|
locale,
|
|
20
19
|
sourceLocale: this.sourceLocale,
|
|
21
|
-
existing: await
|
|
20
|
+
existing: await readFile(filename),
|
|
22
21
|
filename,
|
|
23
22
|
});
|
|
24
|
-
await
|
|
23
|
+
await writeFileIfChanged(filename, content);
|
|
25
24
|
}
|
|
26
25
|
async read(filename, locale) {
|
|
27
|
-
const content = await
|
|
26
|
+
const content = await readFile(filename);
|
|
28
27
|
if (!content) {
|
|
29
|
-
return
|
|
28
|
+
return undefined;
|
|
30
29
|
}
|
|
31
30
|
try {
|
|
32
31
|
return this.f.parse(content, {
|
|
@@ -36,8 +35,7 @@ class FormatterWrapper {
|
|
|
36
35
|
});
|
|
37
36
|
}
|
|
38
37
|
catch (e) {
|
|
39
|
-
throw new
|
|
38
|
+
throw new RethrownError(`Cannot read ${filename}`, e);
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
|
-
exports.FormatterWrapper = FormatterWrapper;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import { FormatterWrapper } from "./formatterWrapper";
|
|
1
|
+
import type { CatalogFormatter } from "@lingui/conf";
|
|
2
|
+
import { FormatterWrapper } from "./formatterWrapper.js";
|
|
4
3
|
export { FormatterWrapper };
|
|
5
|
-
export declare function getFormat(
|
|
4
|
+
export declare function getFormat(format: CatalogFormatter | undefined, sourceLocale: string): Promise<FormatterWrapper>;
|
|
@@ -1,47 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.getFormat = getFormat;
|
|
5
|
-
const formatterWrapper_1 = require("./formatterWrapper");
|
|
6
|
-
Object.defineProperty(exports, "FormatterWrapper", { enumerable: true, get: function () { return formatterWrapper_1.FormatterWrapper; } });
|
|
7
|
-
const utils_1 = require("../utils");
|
|
8
|
-
function createDeprecationError(packageName, format, installCode) {
|
|
9
|
-
const installCmd = (0, utils_1.makeInstall)(packageName);
|
|
10
|
-
return `
|
|
11
|
-
Format \`${format}\` is no longer included in \`@lingui/cli\` by default.
|
|
12
|
-
You need to install it using ${installCmd} command and add to your \`lingui.config.{js,ts}\`:
|
|
13
|
-
|
|
14
|
-
import { formatter } from "${packageName}"
|
|
15
|
-
|
|
16
|
-
export default {
|
|
17
|
-
[...]
|
|
18
|
-
format: ${installCode}
|
|
19
|
-
}
|
|
20
|
-
`.trim();
|
|
21
|
-
}
|
|
22
|
-
// Introduced in v4. Remove this deprecation in v5
|
|
23
|
-
const formats = {
|
|
24
|
-
lingui: async () => {
|
|
25
|
-
throw new Error(createDeprecationError("@lingui/format-json", "lingui", 'formatter({style: "lingui"})'));
|
|
26
|
-
},
|
|
27
|
-
minimal: async () => {
|
|
28
|
-
throw new Error(createDeprecationError("@lingui/format-json", "minimal", 'formatter({style: "minimal"})'));
|
|
29
|
-
},
|
|
30
|
-
po: async () => (await import("@lingui/format-po")).formatter,
|
|
31
|
-
csv: async () => {
|
|
32
|
-
throw new Error(createDeprecationError("@lingui/format-csv", "csv", "formatter()"));
|
|
33
|
-
},
|
|
34
|
-
"po-gettext": async () => {
|
|
35
|
-
throw new Error(createDeprecationError("@lingui/format-po-gettext", "po-gettext", "formatter()"));
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
async function getFormat(_format, options, sourceLocale) {
|
|
39
|
-
if (typeof _format !== "string") {
|
|
40
|
-
return new formatterWrapper_1.FormatterWrapper(_format, sourceLocale);
|
|
41
|
-
}
|
|
42
|
-
const format = formats[_format];
|
|
1
|
+
import { FormatterWrapper } from "./formatterWrapper.js";
|
|
2
|
+
export { FormatterWrapper };
|
|
3
|
+
export async function getFormat(format, sourceLocale) {
|
|
43
4
|
if (!format) {
|
|
44
|
-
|
|
5
|
+
format = (await import("@lingui/format-po")).formatter();
|
|
45
6
|
}
|
|
46
|
-
return new
|
|
7
|
+
return new FormatterWrapper(format, sourceLocale);
|
|
47
8
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getCatalogs } from "./catalog/getCatalogs.js";
|
|
2
|
+
/**
|
|
3
|
+
* Return paths of catalogs to watch
|
|
4
|
+
*/
|
|
5
|
+
export async function getPathsForCompileWatcher(config) {
|
|
6
|
+
const catalogs = await getCatalogs(config);
|
|
7
|
+
const paths = new Set();
|
|
8
|
+
config.locales.forEach((locale) => {
|
|
9
|
+
catalogs.forEach((catalog) => {
|
|
10
|
+
const filename = catalog.getFilename(locale);
|
|
11
|
+
paths.add(filename);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
return { paths: [...paths] };
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getCatalogs } from "./catalog/getCatalogs.js";
|
|
2
|
+
/**
|
|
3
|
+
* returns glob patterns to match
|
|
4
|
+
*/
|
|
5
|
+
export async function getPathsForExtractWatcher(config) {
|
|
6
|
+
const catalogs = await getCatalogs(config);
|
|
7
|
+
const paths = [];
|
|
8
|
+
const ignored = [];
|
|
9
|
+
catalogs.forEach((catalog) => {
|
|
10
|
+
paths.push(...catalog.include);
|
|
11
|
+
ignored.push(...catalog.exclude);
|
|
12
|
+
});
|
|
13
|
+
return { paths, ignored };
|
|
14
|
+
}
|
package/dist/api/help.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.helpRun = helpRun;
|
|
4
1
|
/**
|
|
5
2
|
* Detect where is the command lingui extract or lingui compile
|
|
6
3
|
* and how is being run (npm, yarn, pnpm) and construct help
|
|
@@ -23,16 +20,17 @@ exports.helpRun = helpRun;
|
|
|
23
20
|
* ...
|
|
24
21
|
* (use "npm run compile" to compile catalogs for production)
|
|
25
22
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
import { resolve, join } from "path";
|
|
24
|
+
import { readFileSync } from "node:fs";
|
|
25
|
+
export function helpRun(command) {
|
|
28
26
|
let findRootPkgJson;
|
|
29
27
|
try {
|
|
30
|
-
findRootPkgJson =
|
|
28
|
+
findRootPkgJson = JSON.parse(readFileSync(resolve(join(process.cwd(), "package.json")), "utf8"));
|
|
31
29
|
}
|
|
32
30
|
catch (error) {
|
|
33
31
|
// noting
|
|
34
32
|
}
|
|
35
|
-
if (findRootPkgJson
|
|
33
|
+
if (findRootPkgJson?.scripts) {
|
|
36
34
|
const res = Object.entries(findRootPkgJson.scripts).find(([_, value]) => value.includes(`lingui ${command}`));
|
|
37
35
|
if (res) {
|
|
38
36
|
command = res[0];
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { getFormat } from "./formats";
|
|
2
|
-
export { getCatalogForFile, getCatalogs } from "./catalog/getCatalogs";
|
|
3
|
-
export { createCompiledCatalog } from "./compile";
|
|
4
|
-
export { default as extractor, extractFromFileWithBabel, } from "./extractors/babel";
|
|
5
|
-
export { getCatalogDependentFiles } from "./catalog/getCatalogDependentFiles";
|
|
6
|
-
export { createMissingErrorMessage, createCompilationErrorMessage, } from "./messages";
|
|
7
|
-
export * from "./types";
|
|
1
|
+
export { getFormat } from "./formats/index.js";
|
|
2
|
+
export { getCatalogForFile, getCatalogs } from "./catalog/getCatalogs.js";
|
|
3
|
+
export { createCompiledCatalog } from "./compile.js";
|
|
4
|
+
export { default as extractor, extractFromFileWithBabel, } from "./extractors/babel.js";
|
|
5
|
+
export { getCatalogDependentFiles } from "./catalog/getCatalogDependentFiles.js";
|
|
6
|
+
export { createMissingErrorMessage, createCompilationErrorMessage, } from "./messages.js";
|
|
7
|
+
export * from "./types.js";
|
package/dist/api/index.js
CHANGED
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.createCompilationErrorMessage = exports.createMissingErrorMessage = exports.getCatalogDependentFiles = exports.extractFromFileWithBabel = exports.extractor = exports.createCompiledCatalog = exports.getCatalogs = exports.getCatalogForFile = exports.getFormat = void 0;
|
|
21
|
-
var formats_1 = require("./formats");
|
|
22
|
-
Object.defineProperty(exports, "getFormat", { enumerable: true, get: function () { return formats_1.getFormat; } });
|
|
23
|
-
var getCatalogs_1 = require("./catalog/getCatalogs");
|
|
24
|
-
Object.defineProperty(exports, "getCatalogForFile", { enumerable: true, get: function () { return getCatalogs_1.getCatalogForFile; } });
|
|
25
|
-
Object.defineProperty(exports, "getCatalogs", { enumerable: true, get: function () { return getCatalogs_1.getCatalogs; } });
|
|
26
|
-
var compile_1 = require("./compile");
|
|
27
|
-
Object.defineProperty(exports, "createCompiledCatalog", { enumerable: true, get: function () { return compile_1.createCompiledCatalog; } });
|
|
28
|
-
var babel_1 = require("./extractors/babel");
|
|
29
|
-
Object.defineProperty(exports, "extractor", { enumerable: true, get: function () { return __importDefault(babel_1).default; } });
|
|
30
|
-
Object.defineProperty(exports, "extractFromFileWithBabel", { enumerable: true, get: function () { return babel_1.extractFromFileWithBabel; } });
|
|
31
|
-
var getCatalogDependentFiles_1 = require("./catalog/getCatalogDependentFiles");
|
|
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; } });
|
|
36
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export { getFormat } from "./formats/index.js";
|
|
2
|
+
export { getCatalogForFile, getCatalogs } from "./catalog/getCatalogs.js";
|
|
3
|
+
export { createCompiledCatalog } from "./compile.js";
|
|
4
|
+
export { default as extractor, extractFromFileWithBabel, } from "./extractors/babel.js";
|
|
5
|
+
export { getCatalogDependentFiles } from "./catalog/getCatalogDependentFiles.js";
|
|
6
|
+
export { createMissingErrorMessage, createCompilationErrorMessage, } from "./messages.js";
|
|
7
|
+
export * from "./types.js";
|
package/dist/api/logger.d.ts
CHANGED
package/dist/api/logger.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/api/messages.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TranslationMissingEvent } from "./catalog/getTranslationsForCatalog";
|
|
2
|
-
import { MessageCompilationError } from "./compile";
|
|
1
|
+
import { TranslationMissingEvent } from "./catalog/getTranslationsForCatalog.js";
|
|
2
|
+
import { MessageCompilationError } from "./compile.js";
|
|
3
3
|
export declare function createMissingErrorMessage(locale: string, missingMessages: TranslationMissingEvent[], configurationMsg: string): string;
|
|
4
4
|
export declare function createCompilationErrorMessage(locale: string, errors: MessageCompilationError[]): string;
|
package/dist/api/messages.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createMissingErrorMessage = createMissingErrorMessage;
|
|
7
|
-
exports.createCompilationErrorMessage = createCompilationErrorMessage;
|
|
8
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
9
|
-
function createMissingErrorMessage(locale, missingMessages, configurationMsg) {
|
|
10
|
-
let message = `Failed to compile catalog for locale ${picocolors_1.default.bold(locale)}!
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
export function createMissingErrorMessage(locale, missingMessages, configurationMsg) {
|
|
3
|
+
let message = `Failed to compile catalog for locale ${styleText("bold", locale)}!
|
|
11
4
|
|
|
12
5
|
Missing ${missingMessages.length} translation(s):
|
|
13
6
|
\n`;
|
|
@@ -19,8 +12,8 @@ Missing ${missingMessages.length} translation(s):
|
|
|
19
12
|
});
|
|
20
13
|
return message;
|
|
21
14
|
}
|
|
22
|
-
function createCompilationErrorMessage(locale, errors) {
|
|
23
|
-
let message = `Failed to compile catalog for locale ${
|
|
15
|
+
export function createCompilationErrorMessage(locale, errors) {
|
|
16
|
+
let message = `Failed to compile catalog for locale ${styleText("bold", locale)}!
|
|
24
17
|
|
|
25
18
|
Compilation error for ${errors.length} translation(s):
|
|
26
19
|
\n`;
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
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 = default_1;
|
|
7
|
-
const pseudolocale_1 = __importDefault(require("pseudolocale"));
|
|
1
|
+
import pseudolocale from "pseudolocale";
|
|
8
2
|
const delimiter = "%&&&%";
|
|
9
3
|
/**
|
|
10
4
|
* Regex should match HTML tags
|
|
@@ -43,11 +37,11 @@ function addDelimitersVariables(message) {
|
|
|
43
37
|
function removeDelimiters(message) {
|
|
44
38
|
return message.replace(new RegExp(delimiter, "g"), "");
|
|
45
39
|
}
|
|
46
|
-
function
|
|
40
|
+
export default function (message) {
|
|
47
41
|
message = addDelimitersHTMLTags(message);
|
|
48
42
|
message = addDelimitersMacro(message);
|
|
49
43
|
message = addDelimitersVariables(message);
|
|
50
|
-
message = (
|
|
44
|
+
message = pseudolocale(message, {
|
|
51
45
|
delimiter,
|
|
52
46
|
prepend: "",
|
|
53
47
|
append: "",
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveWorkersOptions = resolveWorkersOptions;
|
|
7
|
-
const node_os_1 = __importDefault(require("node:os"));
|
|
8
|
-
function resolveWorkersOptions(opts) {
|
|
9
|
-
const cores = node_os_1.default.availableParallelism();
|
|
1
|
+
import * as os from "node:os";
|
|
2
|
+
export function resolveWorkersOptions(opts) {
|
|
3
|
+
const cores = os.availableParallelism();
|
|
10
4
|
if (Number(opts.workers) <= 1 || cores === 1) {
|
|
11
5
|
return { poolSize: 0 };
|
|
12
6
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.RethrownError = void 0;
|
|
4
|
-
class RethrownError extends Error {
|
|
1
|
+
export class RethrownError extends Error {
|
|
2
|
+
message;
|
|
5
3
|
constructor(message, originalError) {
|
|
6
4
|
super();
|
|
7
5
|
this.message = message + " " + originalError.message;
|
|
8
6
|
this.stack = `Error: ${message} \nOriginal: ` + originalError.stack;
|
|
9
7
|
}
|
|
10
8
|
}
|
|
11
|
-
exports.RethrownError = RethrownError;
|
package/dist/api/stats.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import Table from "cli-table3";
|
|
1
2
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { AllCatalogsType, CatalogType } from "./types";
|
|
3
|
+
import { AllCatalogsType, CatalogType } from "./types.js";
|
|
3
4
|
type CatalogStats = [number, number];
|
|
4
5
|
export declare function getStats(catalog: CatalogType): CatalogStats;
|
|
5
|
-
export declare function printStats(config: LinguiConfigNormalized, catalogs: AllCatalogsType):
|
|
6
|
+
export declare function printStats(config: LinguiConfigNormalized, catalogs: AllCatalogsType): Table.Table;
|
|
6
7
|
export {};
|
package/dist/api/stats.js
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getStats = getStats;
|
|
7
|
-
exports.printStats = printStats;
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const cli_table_1 = __importDefault(require("cli-table"));
|
|
11
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
12
|
-
function getStats(catalog) {
|
|
1
|
+
import Table from "cli-table3";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
export function getStats(catalog) {
|
|
13
4
|
return [
|
|
14
5
|
Object.keys(catalog).length,
|
|
15
6
|
Object.keys(catalog).filter((key) => !catalog[key].translation).length,
|
|
16
7
|
];
|
|
17
8
|
}
|
|
18
|
-
function printStats(config, catalogs) {
|
|
19
|
-
const table = new
|
|
9
|
+
export function printStats(config, catalogs) {
|
|
10
|
+
const table = new Table({
|
|
20
11
|
head: ["Language", "Total count", "Missing"],
|
|
21
|
-
colAligns: ["left", "
|
|
12
|
+
colAligns: ["left", "center", "center"],
|
|
22
13
|
style: {
|
|
23
14
|
head: ["green"],
|
|
24
15
|
border: [],
|
|
@@ -41,7 +32,7 @@ function printStats(config, catalogs) {
|
|
|
41
32
|
// was not extracted due to a `--locale` filter
|
|
42
33
|
const [all, translated] = catalog ? getStats(catalog) : ["-", "-"];
|
|
43
34
|
if (config.sourceLocale === locale) {
|
|
44
|
-
table.push({ [`${
|
|
35
|
+
table.push({ [`${styleText("bold", locale)} (source)`]: [all, "-"] });
|
|
45
36
|
}
|
|
46
37
|
else {
|
|
47
38
|
table.push({ [locale]: [all, translated] });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type TypedPool<TArgs extends unknown[], TResult> = {
|
|
2
|
+
run(...args: TArgs): Promise<TResult>;
|
|
3
|
+
destroy(): Promise<void>;
|
|
4
|
+
};
|
|
5
|
+
export type WorkerPool<TFn extends (...args: never[]) => unknown> = TypedPool<Parameters<TFn>, Awaited<ReturnType<TFn>>>;
|
|
6
|
+
export declare const createWorkerPool: <TFn extends (...args: never[]) => unknown>(workerBasePath: string, baseUrl: string, poolSize: number) => WorkerPool<TFn>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Tinypool from "tinypool";
|
|
2
|
+
const createTypedPool = (options) => {
|
|
3
|
+
const pool = new Tinypool(options);
|
|
4
|
+
return {
|
|
5
|
+
run: (...args) => pool.run(args),
|
|
6
|
+
destroy: () => pool.destroy(),
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
const resolveWorkerFile = (basePath, baseUrl) => new URL(process.env.NODE_ENV === "test"
|
|
10
|
+
? `${basePath}.jiti.js`
|
|
11
|
+
: `${basePath}.prod.js`, baseUrl).href;
|
|
12
|
+
export const createWorkerPool = (workerBasePath, baseUrl, poolSize) => createTypedPool({
|
|
13
|
+
filename: resolveWorkerFile(workerBasePath, baseUrl),
|
|
14
|
+
minThreads: poolSize,
|
|
15
|
+
maxThreads: poolSize,
|
|
16
|
+
});
|
package/dist/api/types.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/api/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const PATHSEP = "/";
|
|
2
2
|
export declare function prettyOrigin(origins: [filename: string, line?: number][]): string;
|
|
3
|
-
export declare function replacePlaceholders(input: string, values: Record<string, string>): string;
|
|
3
|
+
export declare function replacePlaceholders(input: string, values: Record<string, string | undefined>): string;
|
|
4
4
|
export declare function readFile(fileName: string): Promise<string | undefined>;
|
|
5
|
-
export declare function isDirectory(filePath: string): boolean;
|
|
5
|
+
export declare function isDirectory(filePath: string): boolean | undefined;
|
|
6
6
|
export declare function writeFile(fileName: string, content: string): Promise<void>;
|
|
7
7
|
export declare function writeFileIfChanged(filename: string, newContent: string): Promise<void>;
|
|
8
8
|
export declare function hasYarn(): boolean;
|
package/dist/api/utils.js
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
17
|
-
const fs_1 = __importDefault(require("fs"));
|
|
18
|
-
const path_1 = __importDefault(require("path"));
|
|
19
|
-
const normalize_path_1 = __importDefault(require("normalize-path"));
|
|
20
|
-
exports.PATHSEP = "/"; // force posix everywhere
|
|
21
|
-
function prettyOrigin(origins) {
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import normalizePath from "normalize-path";
|
|
4
|
+
export const PATHSEP = "/"; // force posix everywhere
|
|
5
|
+
export function prettyOrigin(origins) {
|
|
22
6
|
try {
|
|
23
7
|
return origins.map((origin) => origin.join(":")).join(", ");
|
|
24
8
|
}
|
|
@@ -26,15 +10,14 @@ function prettyOrigin(origins) {
|
|
|
26
10
|
return "";
|
|
27
11
|
}
|
|
28
12
|
}
|
|
29
|
-
function replacePlaceholders(input, values) {
|
|
13
|
+
export function replacePlaceholders(input, values) {
|
|
30
14
|
return input.replace(/\{([^}]+)}/g, (m, placeholder) => {
|
|
31
|
-
|
|
32
|
-
return (_a = values[placeholder]) !== null && _a !== void 0 ? _a : m;
|
|
15
|
+
return values[placeholder] ?? m;
|
|
33
16
|
});
|
|
34
17
|
}
|
|
35
|
-
async function readFile(fileName) {
|
|
18
|
+
export async function readFile(fileName) {
|
|
36
19
|
try {
|
|
37
|
-
return (await
|
|
20
|
+
return (await fs.promises.readFile(fileName, "utf-8")).toString();
|
|
38
21
|
}
|
|
39
22
|
catch (err) {
|
|
40
23
|
if (err.code != "ENOENT") {
|
|
@@ -44,7 +27,7 @@ async function readFile(fileName) {
|
|
|
44
27
|
}
|
|
45
28
|
async function mkdirp(dir) {
|
|
46
29
|
try {
|
|
47
|
-
await
|
|
30
|
+
await fs.promises.mkdir(dir, {
|
|
48
31
|
recursive: true,
|
|
49
32
|
});
|
|
50
33
|
}
|
|
@@ -54,9 +37,9 @@ async function mkdirp(dir) {
|
|
|
54
37
|
}
|
|
55
38
|
}
|
|
56
39
|
}
|
|
57
|
-
function isDirectory(filePath) {
|
|
40
|
+
export function isDirectory(filePath) {
|
|
58
41
|
try {
|
|
59
|
-
return
|
|
42
|
+
return fs.lstatSync(filePath).isDirectory();
|
|
60
43
|
}
|
|
61
44
|
catch (err) {
|
|
62
45
|
if (err.code != "ENOENT") {
|
|
@@ -64,11 +47,11 @@ function isDirectory(filePath) {
|
|
|
64
47
|
}
|
|
65
48
|
}
|
|
66
49
|
}
|
|
67
|
-
async function writeFile(fileName, content) {
|
|
68
|
-
await mkdirp(
|
|
69
|
-
await
|
|
50
|
+
export async function writeFile(fileName, content) {
|
|
51
|
+
await mkdirp(path.dirname(fileName));
|
|
52
|
+
await fs.promises.writeFile(fileName, content, "utf-8");
|
|
70
53
|
}
|
|
71
|
-
async function writeFileIfChanged(filename, newContent) {
|
|
54
|
+
export async function writeFileIfChanged(filename, newContent) {
|
|
72
55
|
const raw = await readFile(filename);
|
|
73
56
|
if (raw) {
|
|
74
57
|
if (newContent !== raw) {
|
|
@@ -79,10 +62,10 @@ async function writeFileIfChanged(filename, newContent) {
|
|
|
79
62
|
await writeFile(filename, newContent);
|
|
80
63
|
}
|
|
81
64
|
}
|
|
82
|
-
function hasYarn() {
|
|
83
|
-
return
|
|
65
|
+
export function hasYarn() {
|
|
66
|
+
return fs.existsSync(path.resolve("yarn.lock"));
|
|
84
67
|
}
|
|
85
|
-
function makeInstall(packageName, dev = false) {
|
|
68
|
+
export function makeInstall(packageName, dev = false) {
|
|
86
69
|
const withYarn = hasYarn();
|
|
87
70
|
return withYarn
|
|
88
71
|
? `yarn add ${dev ? "--dev " : ""}${packageName}`
|
|
@@ -94,19 +77,19 @@ function makeInstall(packageName, dev = false) {
|
|
|
94
77
|
* Preserve directories: ./relative/ => relative/
|
|
95
78
|
* Preserve absolute paths: /absolute/path => /absolute/path
|
|
96
79
|
*/
|
|
97
|
-
function normalizeRelativePath(sourcePath) {
|
|
98
|
-
if (
|
|
80
|
+
export function normalizeRelativePath(sourcePath) {
|
|
81
|
+
if (path.isAbsolute(sourcePath)) {
|
|
99
82
|
// absolute path
|
|
100
|
-
return (
|
|
83
|
+
return normalizePath(sourcePath, false);
|
|
101
84
|
}
|
|
102
85
|
// https://github.com/lingui/js-lingui/issues/809
|
|
103
86
|
const isDir = isDirectory(sourcePath);
|
|
104
|
-
return ((
|
|
87
|
+
return (normalizePath(path.relative(process.cwd(), sourcePath), false) +
|
|
105
88
|
(isDir ? "/" : ""));
|
|
106
89
|
}
|
|
107
90
|
/**
|
|
108
91
|
* Escape special regex characters used in file-based routing systems
|
|
109
92
|
*/
|
|
110
|
-
function makePathRegexSafe(path) {
|
|
93
|
+
export function makePathRegexSafe(path) {
|
|
111
94
|
return path.replace(/[(){}[\]^$+]/g, "\\$&");
|
|
112
95
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Logger } from "./logger";
|
|
1
|
+
import { Logger } from "./logger.js";
|
|
2
2
|
export type SerializedLogs = {
|
|
3
3
|
errors: string;
|
|
4
4
|
};
|
|
5
5
|
export declare class WorkerLogger implements Logger {
|
|
6
6
|
private errors;
|
|
7
|
-
error(msg
|
|
7
|
+
error(msg: string): void;
|
|
8
8
|
flush(): SerializedLogs;
|
|
9
9
|
}
|
package/dist/api/workerLogger.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.WorkerLogger = void 0;
|
|
4
|
-
class WorkerLogger {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.errors = [];
|
|
7
|
-
}
|
|
1
|
+
export class WorkerLogger {
|
|
2
|
+
errors = [];
|
|
8
3
|
error(msg) {
|
|
9
4
|
this.errors.push(msg);
|
|
10
5
|
}
|
|
@@ -16,4 +11,3 @@ class WorkerLogger {
|
|
|
16
11
|
};
|
|
17
12
|
}
|
|
18
13
|
}
|
|
19
|
-
exports.WorkerLogger = WorkerLogger;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createWorkerPool } from "./typedPool.js";
|
|
2
|
+
/** @internal */
|
|
3
|
+
export const createExtractWorkerPool = (opts) => createWorkerPool("../workers/extractWorkerWrapper", import.meta.url, opts.poolSize);
|
|
4
|
+
/** @internal */
|
|
5
|
+
export const createExtractExperimentalWorkerPool = (opts) => createWorkerPool("../extract-experimental/workers/extractWorkerWrapper", import.meta.url, opts.poolSize);
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const createCompileWorkerPool = (opts) => createWorkerPool("../workers/compileWorkerWrapper", import.meta.url, opts.poolSize);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildIncludeDepsFilter = buildIncludeDepsFilter;
|
|
4
1
|
function createPackageRegExp(packageName) {
|
|
5
2
|
return new RegExp("^" + packageName + "(?:\\/.+)?");
|
|
6
3
|
}
|
|
7
|
-
function buildIncludeDepsFilter(includeDeps) {
|
|
4
|
+
export function buildIncludeDepsFilter(includeDeps) {
|
|
8
5
|
const include = includeDeps.map(createPackageRegExp);
|
|
9
6
|
return (id) => include.some((regExp) => regExp.test(id));
|
|
10
7
|
}
|