@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,2 +1,3 @@
|
|
|
1
|
-
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
|
|
1
|
+
import { ExperimentalExtractorOptions, LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
+
import { Metafile } from "esbuild";
|
|
3
|
+
export declare function bundleSource(linguiConfig: LinguiConfigNormalized, extractorConfig: ExperimentalExtractorOptions, entryPoints: string[], outDir: string, rootDir: string): Promise<Metafile>;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.bundleSource = bundleSource;
|
|
4
|
-
const linguiEsbuildPlugin_1 = require("./linguiEsbuildPlugin");
|
|
5
|
-
const buildIncludeDepsFilter_1 = require("./buildIncludeDepsFilter");
|
|
1
|
+
import { pluginLinguiMacro } from "./linguiEsbuildPlugin.js";
|
|
2
|
+
import { buildIncludeDepsFilter } from "./buildIncludeDepsFilter.js";
|
|
6
3
|
function createExtRegExp(extensions) {
|
|
7
4
|
return new RegExp("\\.(?:" + extensions.join("|") + ")(?:\\?.*)?$");
|
|
8
5
|
}
|
|
9
|
-
async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
|
|
6
|
+
export async function bundleSource(linguiConfig, extractorConfig, entryPoints, outDir, rootDir) {
|
|
10
7
|
const esbuild = await import("esbuild");
|
|
11
|
-
const
|
|
12
|
-
const excludeExtensions = config.excludeExtensions || [
|
|
8
|
+
const excludeExtensions = extractorConfig.excludeExtensions || [
|
|
13
9
|
"ico",
|
|
14
10
|
"pot",
|
|
15
11
|
"xliff",
|
|
@@ -44,16 +40,16 @@ async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
|
|
|
44
40
|
sourcesContent: false,
|
|
45
41
|
metafile: true,
|
|
46
42
|
plugins: [
|
|
47
|
-
|
|
43
|
+
pluginLinguiMacro({ linguiConfig }),
|
|
48
44
|
{
|
|
49
45
|
name: "externalize-deps",
|
|
50
46
|
setup(build) {
|
|
51
|
-
const shouldInclude =
|
|
47
|
+
const shouldInclude = buildIncludeDepsFilter(extractorConfig.includeDeps || []);
|
|
52
48
|
// considers all import paths that "look like" package imports in the original source code to be package imports.
|
|
53
49
|
// Specifically import paths that don't start with a path segment of / or . or .. are considered to be package imports.
|
|
54
50
|
// The only two exceptions to this rule are subpath imports (which start with a # character) and deps specified in the `includeDeps`
|
|
55
51
|
build.onResolve({ filter: /^[^.#/].*/ }, async (args) => {
|
|
56
|
-
if (shouldInclude(args.path)) {
|
|
52
|
+
if (shouldInclude(args.path) || args.kind === "entry-point") {
|
|
57
53
|
return { external: false };
|
|
58
54
|
}
|
|
59
55
|
return {
|
|
@@ -72,7 +68,8 @@ async function bundleSource(linguiConfig, entryPoints, outDir, rootDir) {
|
|
|
72
68
|
},
|
|
73
69
|
],
|
|
74
70
|
};
|
|
75
|
-
|
|
76
|
-
?
|
|
71
|
+
const bundleResult = await esbuild.build(extractorConfig.resolveEsbuildOptions
|
|
72
|
+
? extractorConfig.resolveEsbuildOptions(esbuildOptions)
|
|
77
73
|
: esbuildOptions);
|
|
74
|
+
return bundleResult.metafile;
|
|
78
75
|
}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.DEFAULT_TEMPLATE_NAME = exports.ENTRY_NAME_PH = void 0;
|
|
4
|
-
exports.ENTRY_NAME_PH = "{entryName}";
|
|
5
|
-
exports.DEFAULT_TEMPLATE_NAME = "messages";
|
|
1
|
+
export const ENTRY_NAME_PH = "{entryName}";
|
|
2
|
+
export const DEFAULT_TEMPLATE_NAME = "messages";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { FormatterWrapper } from "../api/formats";
|
|
2
|
+
import { FormatterWrapper } from "../api/formats/index.js";
|
|
3
3
|
export declare function extractFromBundleAndWrite(params: {
|
|
4
4
|
entryPoint: string;
|
|
5
5
|
bundleFile: string;
|
|
@@ -11,9 +11,8 @@ export declare function extractFromBundleAndWrite(params: {
|
|
|
11
11
|
clean: boolean;
|
|
12
12
|
overwrite: boolean;
|
|
13
13
|
}): Promise<{
|
|
14
|
-
success:
|
|
15
|
-
stat?: undefined;
|
|
14
|
+
success: false;
|
|
16
15
|
} | {
|
|
17
|
-
success:
|
|
16
|
+
success: true;
|
|
18
17
|
stat: string;
|
|
19
18
|
}>;
|
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.extractFromBundleAndWrite = extractFromBundleAndWrite;
|
|
7
|
-
const extractFromFiles_1 = require("../api/catalog/extractFromFiles");
|
|
8
|
-
const writeCatalogs_1 = require("./writeCatalogs");
|
|
9
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
10
|
-
const babel_1 = require("../api/extractors/babel");
|
|
1
|
+
import { mergeExtractedMessage } from "../api/catalog/extractFromFiles.js";
|
|
2
|
+
import { writeCatalogs, writeTemplate } from "./writeCatalogs.js";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import { extractFromFileWithBabel, getBabelParserOptions, } from "../api/extractors/babel.js";
|
|
11
5
|
async function extractFromBundle(filename, linguiConfig) {
|
|
12
6
|
const messages = {};
|
|
13
7
|
let success;
|
|
14
8
|
try {
|
|
15
|
-
const file = await
|
|
9
|
+
const file = await fs.readFile(filename);
|
|
16
10
|
const parserOptions = linguiConfig.extractorParserOptions;
|
|
17
|
-
await
|
|
18
|
-
|
|
11
|
+
await extractFromFileWithBabel(filename, file.toString(), (msg) => {
|
|
12
|
+
mergeExtractedMessage(msg, messages, linguiConfig);
|
|
19
13
|
}, {
|
|
20
14
|
linguiConfig,
|
|
21
15
|
}, {
|
|
22
|
-
plugins:
|
|
16
|
+
plugins: getBabelParserOptions(filename, parserOptions),
|
|
23
17
|
}, true);
|
|
24
18
|
success = true;
|
|
25
19
|
}
|
|
@@ -30,7 +24,7 @@ async function extractFromBundle(filename, linguiConfig) {
|
|
|
30
24
|
}
|
|
31
25
|
return { success, messages };
|
|
32
26
|
}
|
|
33
|
-
async function extractFromBundleAndWrite(params) {
|
|
27
|
+
export async function extractFromBundleAndWrite(params) {
|
|
34
28
|
const { linguiConfig, entryPoint, format, outputPattern, locales, overwrite, clean, template, } = params;
|
|
35
29
|
const { messages, success } = await extractFromBundle(params.bundleFile, params.linguiConfig);
|
|
36
30
|
if (!success) {
|
|
@@ -38,7 +32,7 @@ async function extractFromBundleAndWrite(params) {
|
|
|
38
32
|
}
|
|
39
33
|
let stat;
|
|
40
34
|
if (template) {
|
|
41
|
-
stat = (await
|
|
35
|
+
stat = (await writeTemplate({
|
|
42
36
|
linguiConfig,
|
|
43
37
|
clean,
|
|
44
38
|
format,
|
|
@@ -48,7 +42,7 @@ async function extractFromBundleAndWrite(params) {
|
|
|
48
42
|
})).statMessage;
|
|
49
43
|
}
|
|
50
44
|
else {
|
|
51
|
-
stat = (await
|
|
45
|
+
stat = (await writeCatalogs({
|
|
52
46
|
locales,
|
|
53
47
|
linguiConfig,
|
|
54
48
|
clean,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
-
import { Catalog } from "../api/catalog";
|
|
3
|
-
|
|
1
|
+
import { ExperimentalExtractorOptions, LinguiConfigNormalized } from "@lingui/conf";
|
|
2
|
+
import { Catalog } from "../api/catalog.js";
|
|
3
|
+
import { FormatterWrapper } from "../api/formats/index.js";
|
|
4
|
+
export declare function getExperimentalCatalogs(linguiConfig: LinguiConfigNormalized, format: FormatterWrapper, extractorConfig: ExperimentalExtractorOptions): Promise<Catalog[]>;
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const formats_1 = require("../api/formats");
|
|
9
|
-
async function getExperimentalCatalogs(linguiConfig) {
|
|
10
|
-
const config = linguiConfig.experimental.extractor;
|
|
11
|
-
const entryPoints = (0, getEntryPoints_1.getEntryPoints)(config.entries);
|
|
12
|
-
const format = await (0, formats_1.getFormat)(linguiConfig.format, linguiConfig.formatOptions, linguiConfig.sourceLocale);
|
|
1
|
+
import { globSync } from "node:fs";
|
|
2
|
+
import { resolveCatalogPath } from "./resolveCatalogPath.js";
|
|
3
|
+
import { Catalog } from "../api/catalog.js";
|
|
4
|
+
import { resolveTemplatePath } from "./resolveTemplatePath.js";
|
|
5
|
+
export async function getExperimentalCatalogs(linguiConfig, format, extractorConfig) {
|
|
6
|
+
const config = extractorConfig;
|
|
7
|
+
const entryPoints = globSync(config.entries);
|
|
13
8
|
return entryPoints.map((entryPoint) => {
|
|
14
|
-
const catalogPath =
|
|
15
|
-
const templatePath =
|
|
16
|
-
return new
|
|
9
|
+
const catalogPath = resolveCatalogPath(config.output, entryPoint, linguiConfig.rootDir, undefined, "");
|
|
10
|
+
const templatePath = resolveTemplatePath(entryPoint, config.output, linguiConfig.rootDir, format.getTemplateExtension());
|
|
11
|
+
return new Catalog({
|
|
17
12
|
name: undefined,
|
|
18
13
|
path: catalogPath,
|
|
19
14
|
templatePath,
|
|
@@ -1,36 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const core_1 = require("@babel/core");
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const babel_1 = require("../api/extractors/babel");
|
|
11
|
-
const babel_plugin_lingui_macro_1 = __importDefault(require("@lingui/babel-plugin-lingui-macro"));
|
|
12
|
-
const pluginLinguiMacro = (options) => ({
|
|
1
|
+
import { transformAsync } from "@babel/core";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { babelRe, getBabelParserOptions } from "../api/extractors/babel.js";
|
|
5
|
+
import linguiMacroPlugin from "@lingui/babel-plugin-lingui-macro";
|
|
6
|
+
export const pluginLinguiMacro = (options) => ({
|
|
13
7
|
name: "linguiMacro",
|
|
14
8
|
setup(build) {
|
|
15
|
-
build.onLoad({ filter:
|
|
16
|
-
const filename =
|
|
17
|
-
const contents = await
|
|
9
|
+
build.onLoad({ filter: babelRe, namespace: "" }, async (args) => {
|
|
10
|
+
const filename = path.relative(process.cwd(), args.path);
|
|
11
|
+
const contents = await fs.promises.readFile(args.path, "utf8");
|
|
18
12
|
const hasMacroRe = /from ["']@lingui(\/.+)?\/macro["']/g;
|
|
19
13
|
if (!hasMacroRe.test(contents)) {
|
|
20
14
|
// let esbuild process file as usual
|
|
21
15
|
return undefined;
|
|
22
16
|
}
|
|
23
|
-
const result = await
|
|
17
|
+
const result = await transformAsync(contents, {
|
|
24
18
|
babelrc: false,
|
|
25
19
|
configFile: false,
|
|
26
20
|
filename: filename,
|
|
27
21
|
sourceMaps: "inline",
|
|
28
22
|
parserOpts: {
|
|
29
|
-
plugins:
|
|
23
|
+
plugins: getBabelParserOptions(filename, options.linguiConfig.extractorParserOptions),
|
|
30
24
|
},
|
|
31
25
|
plugins: [
|
|
32
26
|
[
|
|
33
|
-
|
|
27
|
+
linguiMacroPlugin,
|
|
34
28
|
{
|
|
35
29
|
extract: true,
|
|
36
30
|
linguiConfig: options.linguiConfig,
|
|
@@ -42,4 +36,3 @@ const pluginLinguiMacro = (options) => ({
|
|
|
42
36
|
});
|
|
43
37
|
},
|
|
44
38
|
});
|
|
45
|
-
exports.pluginLinguiMacro = pluginLinguiMacro;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function resolveCatalogPath(configOutput: string, entryPath: string, rootDir: string, locale: string, extension: string): string;
|
|
1
|
+
export declare function resolveCatalogPath(configOutput: string, entryPath: string, rootDir: string, locale: string | undefined, extension: string): string;
|
|
2
2
|
export declare function getEntryName(entryPath: string): string;
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveCatalogPath = resolveCatalogPath;
|
|
7
|
-
exports.getEntryName = getEntryName;
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const utils_1 = require("../api/utils");
|
|
10
|
-
function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension) {
|
|
1
|
+
import nodepath from "path";
|
|
2
|
+
import { replacePlaceholders } from "../api/utils.js";
|
|
3
|
+
export function resolveCatalogPath(configOutput, entryPath, rootDir, locale, extension) {
|
|
11
4
|
const entryName = getEntryName(entryPath);
|
|
12
|
-
const entryDir =
|
|
13
|
-
return
|
|
5
|
+
const entryDir = nodepath.relative(rootDir, nodepath.dirname(entryPath));
|
|
6
|
+
return nodepath.normalize(replacePlaceholders(configOutput, {
|
|
14
7
|
entryName,
|
|
15
8
|
entryDir,
|
|
16
9
|
locale,
|
|
17
10
|
}) + extension);
|
|
18
11
|
}
|
|
19
|
-
function getEntryName(entryPath) {
|
|
20
|
-
const parsedPath =
|
|
12
|
+
export function getEntryName(entryPath) {
|
|
13
|
+
const parsedPath = nodepath.parse(entryPath);
|
|
21
14
|
return parsedPath.name.replace(parsedPath.ext, "");
|
|
22
15
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const resolveCatalogPath_1 = require("./resolveCatalogPath");
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
|
|
1
|
+
import { resolveCatalogPath, getEntryName } from "./resolveCatalogPath.js";
|
|
2
|
+
import { DEFAULT_TEMPLATE_NAME, ENTRY_NAME_PH } from "./constants.js";
|
|
3
|
+
export function resolveTemplatePath(entryPoint, output, rootDir, catalogExtension) {
|
|
7
4
|
let templateName;
|
|
8
|
-
if (output.includes(
|
|
9
|
-
templateName =
|
|
5
|
+
if (output.includes(ENTRY_NAME_PH)) {
|
|
6
|
+
templateName = DEFAULT_TEMPLATE_NAME;
|
|
10
7
|
}
|
|
11
8
|
else {
|
|
12
|
-
templateName =
|
|
9
|
+
templateName = getEntryName(entryPoint);
|
|
13
10
|
}
|
|
14
|
-
return
|
|
11
|
+
return resolveCatalogPath(output, entryPoint, rootDir, templateName, catalogExtension);
|
|
15
12
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type ExtractWorkerFunction = typeof extractWorker;
|
|
2
2
|
declare const extractWorker: (linguiConfigPath: string, entryPoint: string, bundleFile: string, outputPattern: string, template: boolean, locales: string[], clean: boolean, overwrite: boolean) => Promise<{
|
|
3
|
-
success:
|
|
4
|
-
|
|
3
|
+
success: false;
|
|
4
|
+
} | {
|
|
5
|
+
success: true;
|
|
6
|
+
stat: string;
|
|
5
7
|
}>;
|
|
6
|
-
export {};
|
|
8
|
+
export { extractWorker };
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const conf_1 = require("@lingui/conf");
|
|
5
|
-
const extractFromBundleAndWrite_1 = require("../extractFromBundleAndWrite");
|
|
6
|
-
const formats_1 = require("../../api/formats");
|
|
1
|
+
import { getConfig } from "@lingui/conf";
|
|
2
|
+
import { extractFromBundleAndWrite } from "../extractFromBundleAndWrite.js";
|
|
3
|
+
import { getFormat } from "../../api/formats/index.js";
|
|
7
4
|
let linguiConfig;
|
|
8
5
|
let format;
|
|
9
6
|
const extractWorker = async (linguiConfigPath, entryPoint, bundleFile, outputPattern, template, locales, clean, overwrite) => {
|
|
10
7
|
if (!linguiConfig) {
|
|
11
8
|
// initialize config once per worker, speed up workers follow execution
|
|
12
|
-
linguiConfig =
|
|
9
|
+
linguiConfig = getConfig({
|
|
13
10
|
configPath: linguiConfigPath,
|
|
14
11
|
skipValidation: true,
|
|
15
12
|
});
|
|
16
13
|
}
|
|
17
14
|
if (!format) {
|
|
18
|
-
format = await
|
|
15
|
+
format = await getFormat(linguiConfig.format, linguiConfig.sourceLocale);
|
|
19
16
|
}
|
|
20
|
-
return await
|
|
17
|
+
return await extractFromBundleAndWrite({
|
|
21
18
|
entryPoint,
|
|
22
19
|
bundleFile,
|
|
23
20
|
outputPattern,
|
|
@@ -29,4 +26,4 @@ const extractWorker = async (linguiConfigPath, entryPoint, bundleFile, outputPat
|
|
|
29
26
|
template,
|
|
30
27
|
});
|
|
31
28
|
};
|
|
32
|
-
|
|
29
|
+
export { extractWorker };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ExtractedCatalogType } from "../api";
|
|
1
|
+
import { ExtractedCatalogType } from "../api/index.js";
|
|
2
2
|
import { LinguiConfigNormalized } from "@lingui/conf";
|
|
3
|
-
import { FormatterWrapper } from "../api/formats";
|
|
3
|
+
import { FormatterWrapper } from "../api/formats/index.js";
|
|
4
4
|
type ExtractTemplateParams = {
|
|
5
5
|
format: FormatterWrapper;
|
|
6
6
|
clean: boolean;
|
|
@@ -1,40 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.writeTemplate = writeTemplate;
|
|
8
|
-
const resolveTemplatePath_1 = require("./resolveTemplatePath");
|
|
9
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
10
|
-
const resolveCatalogPath_1 = require("./resolveCatalogPath");
|
|
11
|
-
const mergeCatalog_1 = require("../api/catalog/mergeCatalog");
|
|
12
|
-
const stats_1 = require("../api/stats");
|
|
13
|
-
const catalog_1 = require("../api/catalog");
|
|
1
|
+
import { resolveTemplatePath } from "./resolveTemplatePath.js";
|
|
2
|
+
import { styleText } from "node:util";
|
|
3
|
+
import { resolveCatalogPath } from "./resolveCatalogPath.js";
|
|
4
|
+
import { mergeCatalog } from "../api/catalog/mergeCatalog.js";
|
|
5
|
+
import { printStats } from "../api/stats.js";
|
|
6
|
+
import { cleanObsolete, order } from "../api/catalog.js";
|
|
14
7
|
function cleanAndSort(catalog, clean, orderBy) {
|
|
15
8
|
if (clean) {
|
|
16
|
-
catalog =
|
|
9
|
+
catalog = cleanObsolete(catalog);
|
|
17
10
|
}
|
|
18
|
-
return
|
|
11
|
+
return order(orderBy, catalog);
|
|
19
12
|
}
|
|
20
|
-
async function writeCatalogs(params) {
|
|
13
|
+
export async function writeCatalogs(params) {
|
|
21
14
|
const { entryPoint, outputPattern, linguiConfig, locales, overwrite, format, clean, messages, } = params;
|
|
22
15
|
const stat = {};
|
|
23
16
|
for (const locale of locales) {
|
|
24
|
-
const catalogOutput =
|
|
25
|
-
const catalog =
|
|
17
|
+
const catalogOutput = resolveCatalogPath(outputPattern, entryPoint, linguiConfig.rootDir, locale, format.getCatalogExtension());
|
|
18
|
+
const catalog = mergeCatalog(await format.read(catalogOutput, locale), messages, locale === linguiConfig.sourceLocale, { overwrite });
|
|
26
19
|
await format.write(catalogOutput, cleanAndSort(catalog, clean, linguiConfig.orderBy), locale);
|
|
27
20
|
stat[locale] = catalog;
|
|
28
21
|
}
|
|
29
22
|
return {
|
|
30
|
-
statMessage:
|
|
23
|
+
statMessage: printStats(linguiConfig, stat).toString(),
|
|
31
24
|
};
|
|
32
25
|
}
|
|
33
|
-
async function writeTemplate(params) {
|
|
26
|
+
export async function writeTemplate(params) {
|
|
34
27
|
const { entryPoint, outputPattern, linguiConfig, format, clean, messages } = params;
|
|
35
|
-
const catalogOutput =
|
|
28
|
+
const catalogOutput = resolveTemplatePath(entryPoint, outputPattern, linguiConfig.rootDir, format.getTemplateExtension());
|
|
36
29
|
await format.write(catalogOutput, cleanAndSort(messages, clean, linguiConfig.orderBy), undefined);
|
|
37
30
|
return {
|
|
38
|
-
statMessage: `${
|
|
31
|
+
statMessage: `${styleText("bold", String(Object.keys(messages).length))} message(s) extracted`,
|
|
39
32
|
};
|
|
40
33
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineConfig = void 0;
|
|
4
|
-
var conf_1 = require("@lingui/conf");
|
|
5
|
-
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return conf_1.defineConfig; } });
|
|
1
|
+
export { defineConfig } from "@lingui/conf";
|
package/dist/lingui-compile.d.ts
CHANGED
package/dist/lingui-compile.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const compileLocale_1 = require("./api/compile/compileLocale");
|
|
14
|
-
const threads_1 = require("threads");
|
|
15
|
-
const resolveWorkersOptions_1 = require("./api/resolveWorkersOptions");
|
|
16
|
-
const ms_1 = __importDefault(require("ms"));
|
|
17
|
-
async function command(config, options) {
|
|
1
|
+
import { styleText } from "node:util";
|
|
2
|
+
import chokidar from "chokidar";
|
|
3
|
+
import { program } from "commander";
|
|
4
|
+
import { getConfig } from "@lingui/conf";
|
|
5
|
+
import { helpRun } from "./api/help.js";
|
|
6
|
+
import { getCatalogs } from "./api/index.js";
|
|
7
|
+
import { compileLocale } from "./api/compile/compileLocale.js";
|
|
8
|
+
import { createCompileWorkerPool } from "./api/workerPools.js";
|
|
9
|
+
import { resolveWorkersOptions, } from "./api/resolveWorkersOptions.js";
|
|
10
|
+
import ms from "ms";
|
|
11
|
+
import { getPathsForCompileWatcher } from "./api/getPathsForCompileWatcher.js";
|
|
12
|
+
export async function command(config, options) {
|
|
18
13
|
const startTime = Date.now();
|
|
19
14
|
// Check config.compile.merge if catalogs for current locale are to be merged into a single compiled file
|
|
20
15
|
const doMerge = !!config.catalogsMergePath;
|
|
@@ -22,10 +17,10 @@ async function command(config, options) {
|
|
|
22
17
|
let errored = false;
|
|
23
18
|
if (!options.workersOptions.poolSize) {
|
|
24
19
|
// single threaded
|
|
25
|
-
const catalogs = await
|
|
20
|
+
const catalogs = await getCatalogs(config);
|
|
26
21
|
for (const locale of config.locales) {
|
|
27
22
|
try {
|
|
28
|
-
await
|
|
23
|
+
await compileLocale(catalogs, locale, options, config, doMerge, console);
|
|
29
24
|
}
|
|
30
25
|
catch (err) {
|
|
31
26
|
if (err.name === "ProgramExit") {
|
|
@@ -38,39 +33,39 @@ async function command(config, options) {
|
|
|
38
33
|
}
|
|
39
34
|
}
|
|
40
35
|
else {
|
|
41
|
-
|
|
36
|
+
const resolvedConfigPath = config.resolvedConfigPath;
|
|
37
|
+
if (!resolvedConfigPath) {
|
|
42
38
|
throw new Error("Multithreading is only supported when lingui config loaded from file system, not passed by API");
|
|
43
39
|
}
|
|
44
40
|
options.verbose &&
|
|
45
41
|
console.log(`Use worker pool of size ${options.workersOptions.poolSize}`);
|
|
46
|
-
const pool = (
|
|
42
|
+
const pool = createCompileWorkerPool({
|
|
43
|
+
poolSize: options.workersOptions.poolSize,
|
|
44
|
+
});
|
|
47
45
|
try {
|
|
48
|
-
|
|
49
|
-
pool.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
await pool.completed(true);
|
|
46
|
+
await Promise.all(config.locales.map(async (locale) => {
|
|
47
|
+
const { logs, error, exitProgram } = await pool.run(locale, options, doMerge, resolvedConfigPath);
|
|
48
|
+
if (logs.errors) {
|
|
49
|
+
console.error(logs.errors);
|
|
50
|
+
}
|
|
51
|
+
if (exitProgram) {
|
|
52
|
+
errored = true;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (error) {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
64
59
|
}
|
|
65
60
|
finally {
|
|
66
|
-
await pool.
|
|
61
|
+
await pool.destroy();
|
|
67
62
|
}
|
|
68
63
|
}
|
|
69
|
-
console.log(`Done in ${(
|
|
64
|
+
console.log(`Done in ${ms(Date.now() - startTime)}`);
|
|
70
65
|
return !errored;
|
|
71
66
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
67
|
+
if (import.meta.main) {
|
|
68
|
+
program
|
|
74
69
|
.description("Compile message catalogs to compiled bundle.")
|
|
75
70
|
.option("--config <path>", "Path to the config file")
|
|
76
71
|
.option("--strict", "Disable defaults for missing translations")
|
|
@@ -84,23 +79,23 @@ if (require.main === module) {
|
|
|
84
79
|
.on("--help", function () {
|
|
85
80
|
console.log("\n Examples:\n");
|
|
86
81
|
console.log(" # Compile translations and use defaults or message IDs for missing translations");
|
|
87
|
-
console.log(` $ ${
|
|
82
|
+
console.log(` $ ${helpRun("compile")}`);
|
|
88
83
|
console.log("");
|
|
89
84
|
console.log(" # Compile translations but fail when there are missing");
|
|
90
85
|
console.log(" # translations (don't replace missing translations with");
|
|
91
86
|
console.log(" # default messages or message IDs)");
|
|
92
|
-
console.log(` $ ${
|
|
87
|
+
console.log(` $ ${helpRun("compile --strict")}`);
|
|
93
88
|
})
|
|
94
89
|
.parse(process.argv);
|
|
95
|
-
const options =
|
|
96
|
-
const config =
|
|
90
|
+
const options = program.opts();
|
|
91
|
+
const config = getConfig({ configPath: options.config });
|
|
97
92
|
let previousRun = Promise.resolve(true);
|
|
98
93
|
const compile = () => {
|
|
99
94
|
previousRun = previousRun.then(() => command(config, {
|
|
100
95
|
verbose: options.watch || options.verbose || false,
|
|
101
96
|
allowEmpty: !options.strict,
|
|
102
97
|
failOnCompileError: !!options.strict,
|
|
103
|
-
workersOptions:
|
|
98
|
+
workersOptions: resolveWorkersOptions(options),
|
|
104
99
|
typescript: options.typescript || config.compileNamespace === "ts" || false,
|
|
105
100
|
namespace: options.namespace, // we want this to be undefined if user does not specify so default can be used
|
|
106
101
|
outputPrefix: options.outputPrefix,
|
|
@@ -118,23 +113,14 @@ if (require.main === module) {
|
|
|
118
113
|
};
|
|
119
114
|
// Check if Watch Mode is enabled
|
|
120
115
|
if (options.watch) {
|
|
121
|
-
console.info(
|
|
116
|
+
console.info(styleText("bold", "Initializing Watch Mode..."));
|
|
122
117
|
(async function initWatch() {
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const paths = [];
|
|
126
|
-
config.locales.forEach((locale) => {
|
|
127
|
-
catalogs.forEach((catalog) => {
|
|
128
|
-
paths.push(`${catalog.path
|
|
129
|
-
.replace(/{locale}/g, locale)
|
|
130
|
-
.replace(/{name}/g, "*")}${format.getCatalogExtension()}`);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
const watcher = chokidar_1.default.watch(paths, {
|
|
118
|
+
const { paths } = await getPathsForCompileWatcher(config);
|
|
119
|
+
const watcher = chokidar.watch(paths, {
|
|
134
120
|
persistent: true,
|
|
135
121
|
});
|
|
136
122
|
const onReady = () => {
|
|
137
|
-
console.info(
|
|
123
|
+
console.info(styleText(["green", "bold"], "Watcher is ready!"));
|
|
138
124
|
watcher
|
|
139
125
|
.on("add", () => dispatchCompile())
|
|
140
126
|
.on("change", () => dispatchCompile());
|