@lingui/cli 4.2.1 → 4.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.
|
@@ -1,4 +1,27 @@
|
|
|
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
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
@@ -6,6 +29,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
29
|
exports.getCatalogDependentFiles = void 0;
|
|
7
30
|
const getFallbackListForLocale_1 = require("./getFallbackListForLocale");
|
|
8
31
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
32
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
33
|
+
const process = __importStar(require("process"));
|
|
9
34
|
const fileExists = async (path) => !!(await promises_1.default.stat(path).catch(() => false));
|
|
10
35
|
/**
|
|
11
36
|
* Return all files catalog implicitly depends on.
|
|
@@ -19,7 +44,8 @@ async function getCatalogDependentFiles(catalog, locale) {
|
|
|
19
44
|
files.add(catalog.getFilename(catalog.config.sourceLocale));
|
|
20
45
|
}
|
|
21
46
|
const out = [];
|
|
22
|
-
for (
|
|
47
|
+
for (let file of files) {
|
|
48
|
+
file = node_path_1.default.isAbsolute(file) ? file : node_path_1.default.join(process.cwd(), file);
|
|
23
49
|
if (await fileExists(file)) {
|
|
24
50
|
out.push(file);
|
|
25
51
|
}
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
import { ParserOptions } from "@babel/core";
|
|
1
2
|
import type { ExtractorType } from "@lingui/conf";
|
|
3
|
+
import { ExtractedMessage, ExtractorCtx } from "@lingui/conf";
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*
|
|
7
|
+
* Low level function used in default Lingui extractor.
|
|
8
|
+
* This function setup source maps and lingui plugins needed for
|
|
9
|
+
* extraction process but leaving `parserOptions` up to userland implementation.
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const extractor: ExtractorType = {
|
|
15
|
+
* ...
|
|
16
|
+
* async extract(filename, code, onMessageExtracted, ctx) {
|
|
17
|
+
* return extractFromFileWithBabel(filename, code, onMessageExtracted, ctx, {
|
|
18
|
+
* // https://babeljs.io/docs/babel-parser#plugins
|
|
19
|
+
* plugins: [
|
|
20
|
+
* "decorators-legacy",
|
|
21
|
+
* "typescript",
|
|
22
|
+
* "jsx",
|
|
23
|
+
* ],
|
|
24
|
+
* })
|
|
25
|
+
* },
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractFromFileWithBabel(filename: string, code: string, onMessageExtracted: (msg: ExtractedMessage) => void, ctx: ExtractorCtx, parserOpts: ParserOptions): Promise<void>;
|
|
2
30
|
declare const extractor: ExtractorType;
|
|
3
31
|
export default extractor;
|
|
@@ -3,15 +3,117 @@ 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.extractFromFileWithBabel = void 0;
|
|
6
7
|
const core_1 = require("@babel/core");
|
|
7
8
|
const babel_plugin_extract_messages_1 = __importDefault(require("@lingui/babel-plugin-extract-messages"));
|
|
8
|
-
const source_map_1 = require("source-map");
|
|
9
9
|
const babelRe = new RegExp("\\.(" +
|
|
10
10
|
[...core_1.DEFAULT_EXTENSIONS, ".ts", ".mts", ".cts", ".tsx"]
|
|
11
11
|
.map((ext) => ext.slice(1))
|
|
12
12
|
.join("|") +
|
|
13
13
|
")$", "i");
|
|
14
14
|
const inlineSourceMapsRE = new RegExp(/\/[\/\*][#@]\s+sourceMappingURL=data:application\/json;(?:charset:utf-8;)?base64,/i);
|
|
15
|
+
/**
|
|
16
|
+
* Create a source mapper which could read original positions
|
|
17
|
+
* from either inline sourcemaps or from external passed as `sourceMaps` argument.
|
|
18
|
+
*
|
|
19
|
+
* Warning! You have to call destroy method after you finish working with a mapper.
|
|
20
|
+
*
|
|
21
|
+
* @param code source code
|
|
22
|
+
* @param sourceMaps Raw Sourcemaps object to mapping from. Check the https://github.com/mozilla/source-map#new-sourcemapconsumerrawsourcemap
|
|
23
|
+
*/
|
|
24
|
+
async function createSourceMapper(code, sourceMaps) {
|
|
25
|
+
let sourceMapsConsumer;
|
|
26
|
+
if (sourceMaps) {
|
|
27
|
+
const { SourceMapConsumer } = await import("source-map");
|
|
28
|
+
sourceMapsConsumer = await new SourceMapConsumer(sourceMaps);
|
|
29
|
+
}
|
|
30
|
+
else if (code.search(inlineSourceMapsRE) != -1) {
|
|
31
|
+
const { SourceMapConsumer } = await import("source-map");
|
|
32
|
+
const { fromSource } = await import("convert-source-map");
|
|
33
|
+
sourceMapsConsumer = await new SourceMapConsumer(fromSource(code).toObject());
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
destroy: () => {
|
|
37
|
+
if (sourceMapsConsumer) {
|
|
38
|
+
sourceMapsConsumer.destroy();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
originalPositionFor: (origin) => {
|
|
42
|
+
if (!sourceMapsConsumer) {
|
|
43
|
+
return origin;
|
|
44
|
+
}
|
|
45
|
+
const [_, line, column] = origin;
|
|
46
|
+
const mappedPosition = sourceMapsConsumer.originalPositionFor({
|
|
47
|
+
line,
|
|
48
|
+
column,
|
|
49
|
+
});
|
|
50
|
+
return [mappedPosition.source, mappedPosition.line, mappedPosition.column];
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @public
|
|
56
|
+
*
|
|
57
|
+
* Low level function used in default Lingui extractor.
|
|
58
|
+
* This function setup source maps and lingui plugins needed for
|
|
59
|
+
* extraction process but leaving `parserOptions` up to userland implementation.
|
|
60
|
+
*
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const extractor: ExtractorType = {
|
|
65
|
+
* ...
|
|
66
|
+
* async extract(filename, code, onMessageExtracted, ctx) {
|
|
67
|
+
* return extractFromFileWithBabel(filename, code, onMessageExtracted, ctx, {
|
|
68
|
+
* // https://babeljs.io/docs/babel-parser#plugins
|
|
69
|
+
* plugins: [
|
|
70
|
+
* "decorators-legacy",
|
|
71
|
+
* "typescript",
|
|
72
|
+
* "jsx",
|
|
73
|
+
* ],
|
|
74
|
+
* })
|
|
75
|
+
* },
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
async function extractFromFileWithBabel(filename, code, onMessageExtracted, ctx, parserOpts) {
|
|
80
|
+
const mapper = await createSourceMapper(code, ctx === null || ctx === void 0 ? void 0 : ctx.sourceMaps);
|
|
81
|
+
await (0, core_1.transformAsync)(code, {
|
|
82
|
+
// don't generate code
|
|
83
|
+
code: false,
|
|
84
|
+
babelrc: false,
|
|
85
|
+
configFile: false,
|
|
86
|
+
filename: filename,
|
|
87
|
+
inputSourceMap: ctx === null || ctx === void 0 ? void 0 : ctx.sourceMaps,
|
|
88
|
+
parserOpts,
|
|
89
|
+
plugins: [
|
|
90
|
+
[
|
|
91
|
+
"macros",
|
|
92
|
+
{
|
|
93
|
+
// macro plugin uses package `resolve` to find a path of macro file
|
|
94
|
+
// this will not follow jest pathMapping and will resolve path from ./build
|
|
95
|
+
// instead of ./src which makes testing & developing hard.
|
|
96
|
+
// here we override resolve and provide correct path for testing
|
|
97
|
+
resolvePath: (source) => require.resolve(source),
|
|
98
|
+
lingui: {
|
|
99
|
+
extract: true,
|
|
100
|
+
linguiConfig: ctx.linguiConfig,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
babel_plugin_extract_messages_1.default,
|
|
106
|
+
{
|
|
107
|
+
onMessageExtracted: (msg) => {
|
|
108
|
+
return onMessageExtracted(Object.assign(Object.assign({}, msg), { origin: mapper.originalPositionFor(msg.origin) }));
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
mapper.destroy();
|
|
115
|
+
}
|
|
116
|
+
exports.extractFromFileWithBabel = extractFromFileWithBabel;
|
|
15
117
|
const extractor = {
|
|
16
118
|
match(filename) {
|
|
17
119
|
return babelRe.test(filename);
|
|
@@ -38,64 +140,9 @@ const extractor = {
|
|
|
38
140
|
if ([/\.js$/, /\.jsx$/, /\.tsx$/].some((r) => filename.match(r))) {
|
|
39
141
|
parserPlugins.push("jsx");
|
|
40
142
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
sourceMapsConsumer = await new source_map_1.SourceMapConsumer(ctx === null || ctx === void 0 ? void 0 : ctx.sourceMaps);
|
|
44
|
-
}
|
|
45
|
-
else if (code.search(inlineSourceMapsRE) != -1) {
|
|
46
|
-
const { fromSource } = await import("convert-source-map");
|
|
47
|
-
sourceMapsConsumer = await new source_map_1.SourceMapConsumer(fromSource(code).toObject());
|
|
48
|
-
}
|
|
49
|
-
await (0, core_1.transformAsync)(code, {
|
|
50
|
-
// don't generate code
|
|
51
|
-
code: false,
|
|
52
|
-
babelrc: false,
|
|
53
|
-
configFile: false,
|
|
54
|
-
filename: filename,
|
|
55
|
-
inputSourceMap: ctx === null || ctx === void 0 ? void 0 : ctx.sourceMaps,
|
|
56
|
-
parserOpts: {
|
|
57
|
-
plugins: parserPlugins,
|
|
58
|
-
},
|
|
59
|
-
plugins: [
|
|
60
|
-
[
|
|
61
|
-
"macros",
|
|
62
|
-
{
|
|
63
|
-
// macro plugin uses package `resolve` to find a path of macro file
|
|
64
|
-
// this will not follow jest pathMapping and will resolve path from ./build
|
|
65
|
-
// instead of ./src which makes testing & developing hard.
|
|
66
|
-
// here we override resolve and provide correct path for testing
|
|
67
|
-
resolvePath: (source) => require.resolve(source),
|
|
68
|
-
lingui: {
|
|
69
|
-
extract: true,
|
|
70
|
-
linguiConfig: ctx.linguiConfig,
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
[
|
|
75
|
-
babel_plugin_extract_messages_1.default,
|
|
76
|
-
{
|
|
77
|
-
onMessageExtracted: (msg) => {
|
|
78
|
-
if (!sourceMapsConsumer) {
|
|
79
|
-
return onMessageExtracted(msg);
|
|
80
|
-
}
|
|
81
|
-
const [_, line, column] = msg.origin;
|
|
82
|
-
const mappedPosition = sourceMapsConsumer.originalPositionFor({
|
|
83
|
-
line,
|
|
84
|
-
column,
|
|
85
|
-
});
|
|
86
|
-
return onMessageExtracted(Object.assign(Object.assign({}, msg), { origin: [
|
|
87
|
-
mappedPosition.source,
|
|
88
|
-
mappedPosition.line,
|
|
89
|
-
mappedPosition.column,
|
|
90
|
-
] }));
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
],
|
|
143
|
+
return extractFromFileWithBabel(filename, code, onMessageExtracted, ctx, {
|
|
144
|
+
plugins: parserPlugins,
|
|
95
145
|
});
|
|
96
|
-
if (sourceMapsConsumer) {
|
|
97
|
-
sourceMapsConsumer.destroy();
|
|
98
|
-
}
|
|
99
146
|
},
|
|
100
147
|
};
|
|
101
148
|
exports.default = extractor;
|
package/dist/api/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getFormat } from "./formats";
|
|
2
2
|
export { getCatalogForFile, getCatalogs } from "./catalog/getCatalogs";
|
|
3
3
|
export { createCompiledCatalog } from "./compile";
|
|
4
|
-
export { default as extractor } from "./extractors/babel";
|
|
4
|
+
export { default as extractor, extractFromFileWithBabel, } from "./extractors/babel";
|
|
5
5
|
export { getCatalogDependentFiles } from "./catalog/getCatalogDependentFiles";
|
|
6
6
|
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.extractor = exports.createCompiledCatalog = exports.getCatalogs = exports.getCatalogForFile = exports.getFormat = void 0;
|
|
20
|
+
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");
|
|
@@ -27,6 +27,7 @@ var compile_1 = require("./compile");
|
|
|
27
27
|
Object.defineProperty(exports, "createCompiledCatalog", { enumerable: true, get: function () { return compile_1.createCompiledCatalog; } });
|
|
28
28
|
var babel_1 = require("./extractors/babel");
|
|
29
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; } });
|
|
30
31
|
var getCatalogDependentFiles_1 = require("./catalog/getCatalogDependentFiles");
|
|
31
32
|
Object.defineProperty(exports, "getCatalogDependentFiles", { enumerable: true, get: function () { return getCatalogDependentFiles_1.getCatalogDependentFiles; } });
|
|
32
33
|
__exportStar(require("./types"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "CLI for working wit message catalogs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"@babel/parser": "^7.21.2",
|
|
54
54
|
"@babel/runtime": "^7.21.0",
|
|
55
55
|
"@babel/types": "^7.21.2",
|
|
56
|
-
"@lingui/babel-plugin-extract-messages": "4.
|
|
57
|
-
"@lingui/conf": "4.
|
|
58
|
-
"@lingui/core": "4.
|
|
59
|
-
"@lingui/format-po": "4.
|
|
60
|
-
"@lingui/message-utils": "4.
|
|
56
|
+
"@lingui/babel-plugin-extract-messages": "4.4.0",
|
|
57
|
+
"@lingui/conf": "4.4.0",
|
|
58
|
+
"@lingui/core": "4.4.0",
|
|
59
|
+
"@lingui/format-po": "4.4.0",
|
|
60
|
+
"@lingui/message-utils": "4.4.0",
|
|
61
61
|
"babel-plugin-macros": "^3.0.1",
|
|
62
62
|
"chalk": "^4.1.0",
|
|
63
63
|
"chokidar": "3.5.1",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@lingui/jest-mocks": "*",
|
|
83
|
-
"@lingui/macro": "4.
|
|
83
|
+
"@lingui/macro": "4.4.0",
|
|
84
84
|
"@types/convert-source-map": "^2.0.0",
|
|
85
85
|
"@types/glob": "^8.1.0",
|
|
86
86
|
"@types/micromatch": "^4.0.1",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"mock-fs": "^5.2.0",
|
|
89
89
|
"mockdate": "^3.0.5"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "c36c0340ced1c4b76d5e1c340785932122449ac9"
|
|
92
92
|
}
|