@lingui/cli 6.0.0-next.0 → 6.0.0-next.1
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/catalog.js +3 -3
- package/dist/api/extractors/babel.d.ts +20 -4
- package/dist/api/extractors/babel.js +16 -13
- package/dist/api/extractors/index.js +13 -3
- package/dist/extract-experimental/extractFromBundleAndWrite.js +3 -10
- package/dist/extract-experimental/linguiEsbuildPlugin.js +1 -1
- package/package.json +8 -8
package/dist/api/catalog.js
CHANGED
|
@@ -238,10 +238,10 @@ export async function writeCompiled(path, locale, compiledCatalog, namespace) {
|
|
|
238
238
|
await writeFile(filename, compiledCatalog);
|
|
239
239
|
return filename;
|
|
240
240
|
}
|
|
241
|
+
// hardcoded en-US locale to have consistent sorting
|
|
242
|
+
// @see https://github.com/lingui/js-lingui/pull/1808
|
|
243
|
+
const collator = new Intl.Collator("en-US");
|
|
241
244
|
export const orderByMessage = (a, b) => {
|
|
242
|
-
// hardcoded en-US locale to have consistent sorting
|
|
243
|
-
// @see https://github.com/lingui/js-lingui/pull/1808
|
|
244
|
-
const collator = new Intl.Collator("en-US");
|
|
245
245
|
const aMsg = a.entry.message || "";
|
|
246
246
|
const bMsg = b.entry.message || "";
|
|
247
247
|
const aCtxt = a.entry.context || "";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParserOptions } from "@babel/core";
|
|
2
|
-
import { ExtractorType,
|
|
2
|
+
import { ExtractorType, ExtractedMessage, ExtractorCtx } from "@lingui/conf";
|
|
3
3
|
export declare const babelRe: RegExp;
|
|
4
4
|
/**
|
|
5
5
|
* @public
|
|
@@ -27,6 +27,22 @@ export declare const babelRe: RegExp;
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
export declare function extractFromFileWithBabel(filename: string, code: string, onMessageExtracted: (msg: ExtractedMessage) => void, ctx: ExtractorCtx, parserOpts: ParserOptions, skipMacroPlugin?: boolean): Promise<void>;
|
|
30
|
-
export declare function getBabelParserOptions(filename: string, parserOptions:
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
export declare function getBabelParserOptions(filename: string, parserOptions: BabelExtractorOptions["parserOptions"]): (import("@babel/parser").ParserPluginWithOptions | ("decimal" | "asyncDoExpressions" | "asyncGenerators" | "bigInt" | "classPrivateMethods" | "classPrivateProperties" | "classProperties" | "classStaticBlock" | "decorators-legacy" | "deferredImportEvaluation" | "decoratorAutoAccessors" | "destructuringPrivate" | "doExpressions" | "dynamicImport" | "explicitResourceManagement" | "exportDefaultFrom" | "exportNamespaceFrom" | "flow" | "flowComments" | "functionBind" | "functionSent" | "importMeta" | "jsx" | "logicalAssignment" | "importAssertions" | "importReflection" | "moduleBlocks" | "moduleStringNames" | "nullishCoalescingOperator" | "numericSeparator" | "objectRestSpread" | "optionalCatchBinding" | "optionalChaining" | "partialApplication" | "placeholders" | "privateIn" | "regexpUnicodeSets" | "sourcePhaseImports" | "throwExpressions" | "topLevelAwait" | "v8intrinsic" | "decorators" | "estree" | "importAttributes" | "moduleAttributes" | "optionalChainingAssign" | "pipelineOperator" | "recordAndTuple" | "typescript"))[];
|
|
31
|
+
export type BabelExtractorOptions = {
|
|
32
|
+
parserOptions?: {
|
|
33
|
+
/**
|
|
34
|
+
* default false
|
|
35
|
+
*
|
|
36
|
+
* By default, standard decorators (Stage3) are applied for TS files
|
|
37
|
+
* Enable this if you want to use TypesScript's experimental decorators.
|
|
38
|
+
*/
|
|
39
|
+
tsExperimentalDecorators?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Enable if you use flow. This will apply Flow syntax to js files
|
|
42
|
+
*/
|
|
43
|
+
flow?: boolean;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export declare function createBabelExtractor(options?: BabelExtractorOptions): ExtractorType;
|
|
47
|
+
export declare const babelExtractor: ExtractorType;
|
|
48
|
+
export default babelExtractor;
|
|
@@ -131,7 +131,7 @@ export function getBabelParserOptions(filename, parserOptions) {
|
|
|
131
131
|
];
|
|
132
132
|
if ([/\.ts$/, /\.mts$/, /\.cts$/, /\.tsx$/].some((r) => filename.match(r))) {
|
|
133
133
|
parserPlugins.push("typescript");
|
|
134
|
-
if (parserOptions
|
|
134
|
+
if (parserOptions?.tsExperimentalDecorators) {
|
|
135
135
|
parserPlugins.push("decorators-legacy");
|
|
136
136
|
}
|
|
137
137
|
else {
|
|
@@ -149,15 +149,18 @@ export function getBabelParserOptions(filename, parserOptions) {
|
|
|
149
149
|
}
|
|
150
150
|
return parserPlugins;
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
152
|
+
export function createBabelExtractor(options) {
|
|
153
|
+
return {
|
|
154
|
+
match(filename) {
|
|
155
|
+
return babelRe.test(filename);
|
|
156
|
+
},
|
|
157
|
+
async extract(filename, code, onMessageExtracted, ctx) {
|
|
158
|
+
const parserOptions = options?.parserOptions ?? ctx.linguiConfig.extractorParserOptions;
|
|
159
|
+
return extractFromFileWithBabel(filename, code, onMessageExtracted, ctx, {
|
|
160
|
+
plugins: getBabelParserOptions(filename, parserOptions),
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
export const babelExtractor = createBabelExtractor();
|
|
166
|
+
export default babelExtractor;
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import fs from "fs/promises";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import { createBabelExtractor } from "./babel.js";
|
|
3
|
+
let defaultExtractor;
|
|
4
|
+
function createDefaultExtractor(linguiConfig) {
|
|
5
|
+
if (!defaultExtractor) {
|
|
6
|
+
defaultExtractor = createBabelExtractor({
|
|
7
|
+
parserOptions: linguiConfig.extractorParserOptions,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return defaultExtractor;
|
|
11
|
+
}
|
|
4
12
|
export default async function extract(filename, onMessageExtracted, linguiConfig) {
|
|
5
|
-
const extractorsToExtract = linguiConfig.extractors ??
|
|
13
|
+
const extractorsToExtract = linguiConfig.extractors ?? [
|
|
14
|
+
createDefaultExtractor(linguiConfig),
|
|
15
|
+
];
|
|
6
16
|
for (const ext of extractorsToExtract) {
|
|
7
17
|
if (!ext.match(filename))
|
|
8
18
|
continue;
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
import { mergeExtractedMessage } from "../api/catalog/extractFromFiles.js";
|
|
2
2
|
import { writeCatalogs, writeTemplate } from "./writeCatalogs.js";
|
|
3
|
-
import
|
|
4
|
-
import { extractFromFileWithBabel, getBabelParserOptions, } from "../api/extractors/babel.js";
|
|
3
|
+
import extract from "../api/extractors/index.js";
|
|
5
4
|
async function extractFromBundle(filename, linguiConfig) {
|
|
6
5
|
const messages = {};
|
|
7
6
|
let success;
|
|
8
7
|
try {
|
|
9
|
-
|
|
10
|
-
const parserOptions = linguiConfig.extractorParserOptions;
|
|
11
|
-
await extractFromFileWithBabel(filename, file.toString(), (msg) => {
|
|
8
|
+
await extract(filename, (msg) => {
|
|
12
9
|
mergeExtractedMessage(msg, messages, linguiConfig);
|
|
13
|
-
},
|
|
14
|
-
linguiConfig,
|
|
15
|
-
}, {
|
|
16
|
-
plugins: getBabelParserOptions(filename, parserOptions),
|
|
17
|
-
}, true);
|
|
10
|
+
}, linguiConfig);
|
|
18
11
|
success = true;
|
|
19
12
|
}
|
|
20
13
|
catch (e) {
|
|
@@ -20,7 +20,7 @@ export const pluginLinguiMacro = (options) => ({
|
|
|
20
20
|
filename: filename,
|
|
21
21
|
sourceMaps: "inline",
|
|
22
22
|
parserOpts: {
|
|
23
|
-
plugins: getBabelParserOptions(filename,
|
|
23
|
+
plugins: getBabelParserOptions(filename, {}),
|
|
24
24
|
},
|
|
25
25
|
plugins: [
|
|
26
26
|
[
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/cli",
|
|
3
|
-
"version": "6.0.0-next.
|
|
3
|
+
"version": "6.0.0-next.1",
|
|
4
4
|
"description": "CLI for working wit message catalogs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@babel/generator": "^7.28.5",
|
|
51
51
|
"@babel/parser": "^7.22.0",
|
|
52
52
|
"@babel/types": "^7.21.2",
|
|
53
|
-
"@lingui/babel-plugin-extract-messages": "6.0.0-next.
|
|
54
|
-
"@lingui/babel-plugin-lingui-macro": "6.0.0-next.
|
|
55
|
-
"@lingui/conf": "6.0.0-next.
|
|
56
|
-
"@lingui/core": "6.0.0-next.
|
|
57
|
-
"@lingui/format-po": "6.0.0-next.
|
|
58
|
-
"@lingui/message-utils": "6.0.0-next.
|
|
53
|
+
"@lingui/babel-plugin-extract-messages": "6.0.0-next.1",
|
|
54
|
+
"@lingui/babel-plugin-lingui-macro": "6.0.0-next.1",
|
|
55
|
+
"@lingui/conf": "6.0.0-next.1",
|
|
56
|
+
"@lingui/core": "6.0.0-next.1",
|
|
57
|
+
"@lingui/format-po": "6.0.0-next.1",
|
|
58
|
+
"@lingui/message-utils": "6.0.0-next.1",
|
|
59
59
|
"chokidar": "5.0.0",
|
|
60
60
|
"cli-table3": "^0.6.5",
|
|
61
61
|
"commander": "^14.0.2",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"msw": "^2.12.7",
|
|
80
80
|
"vitest": "4.0.18"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "783af0c0371c7795e1fc43316f49dd253e161221"
|
|
83
83
|
}
|