@lingui/cli 4.0.0-next.1 → 4.0.0-next.3
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/build/api/catalog/getCatalogs.js +20 -11
- package/build/api/catalog/getTranslationsForCatalog.js +3 -3
- package/build/api/catalog.js +46 -44
- package/build/api/compile.js +5 -0
- package/build/api/extractors/babel.js +12 -6
- package/build/api/formats/formatterWrapper.js +45 -0
- package/build/api/formats/index.js +46 -20
- package/build/api/rethrownError.js +14 -0
- package/build/api/utils.js +16 -14
- package/build/extract-experimental/buildExternalizeFilter.js +39 -0
- package/build/extract-experimental/bundleSource.js +69 -0
- package/build/extract-experimental/constants.js +10 -0
- package/build/extract-experimental/getEntryPoints.js +14 -0
- package/build/extract-experimental/getExperimentalCatalogs.js +28 -0
- package/build/extract-experimental/resolveCatalogPath.js +23 -0
- package/build/extract-experimental/resolveTemplatePath.js +17 -0
- package/build/extract-experimental/writeCatalogs.js +59 -0
- package/build/lingui-compile.js +44 -33
- package/build/lingui-extract-experimental.js +103 -0
- package/build/lingui-extract-template.js +1 -1
- package/build/lingui-extract.js +20 -18
- package/build/lingui.js +1 -1
- package/build/services/translationIO.js +27 -30
- package/build/tests.js +29 -5
- package/package.json +14 -20
- package/build/api/formats/csv.js +0 -52
- package/build/api/formats/lingui.js +0 -52
- package/build/api/formats/minimal.js +0 -44
- package/build/api/formats/po-gettext.js +0 -225
- package/build/api/formats/po.js +0 -129
|
@@ -12,6 +12,7 @@ var _catalog = require("../catalog");
|
|
|
12
12
|
var _utils = require("../utils");
|
|
13
13
|
var _micromatch = _interopRequireDefault(require("micromatch"));
|
|
14
14
|
var _formats = require("../formats");
|
|
15
|
+
var _getExperimentalCatalogs = require("../../extract-experimental/getExperimentalCatalogs");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
const NAME_PH = "{name}";
|
|
17
18
|
const LOCALE_PH = "{locale}";
|
|
@@ -19,11 +20,13 @@ const LOCALE_PH = "{locale}";
|
|
|
19
20
|
/**
|
|
20
21
|
* Parse `config.catalogs` and return a list of configured Catalog instances.
|
|
21
22
|
*/
|
|
22
|
-
function getCatalogs(config) {
|
|
23
|
+
async function getCatalogs(config) {
|
|
24
|
+
var _config$experimental, _config$experimental$;
|
|
23
25
|
const catalogsConfig = config.catalogs;
|
|
24
26
|
const catalogs = [];
|
|
27
|
+
const format = await (0, _formats.getFormat)(config.format, config.formatOptions, config.sourceLocale);
|
|
25
28
|
catalogsConfig.forEach(catalog => {
|
|
26
|
-
validateCatalogPath(catalog.path,
|
|
29
|
+
validateCatalogPath(catalog.path, format.getCatalogExtension());
|
|
27
30
|
const include = ensureArray(catalog.include).map(_utils.normalizeRelativePath);
|
|
28
31
|
const exclude = ensureArray(catalog.exclude).map(_utils.normalizeRelativePath);
|
|
29
32
|
|
|
@@ -38,7 +41,8 @@ function getCatalogs(config) {
|
|
|
38
41
|
name: getCatalogName(catalog.path),
|
|
39
42
|
path: (0, _utils.normalizeRelativePath)(catalog.path),
|
|
40
43
|
include,
|
|
41
|
-
exclude
|
|
44
|
+
exclude,
|
|
45
|
+
format
|
|
42
46
|
}, config));
|
|
43
47
|
return;
|
|
44
48
|
}
|
|
@@ -61,10 +65,14 @@ function getCatalogs(config) {
|
|
|
61
65
|
})),
|
|
62
66
|
exclude: exclude.map(path => (0, _utils.replacePlaceholders)(path, {
|
|
63
67
|
name
|
|
64
|
-
}))
|
|
68
|
+
})),
|
|
69
|
+
format
|
|
65
70
|
}, config));
|
|
66
71
|
});
|
|
67
72
|
});
|
|
73
|
+
if ((_config$experimental = config.experimental) !== null && _config$experimental !== void 0 && (_config$experimental$ = _config$experimental.extractor) !== null && _config$experimental$ !== void 0 && _config$experimental$.entries.length) {
|
|
74
|
+
catalogs.push(...(await (0, _getExperimentalCatalogs.getExperimentalCatalogs)(config)));
|
|
75
|
+
}
|
|
68
76
|
return catalogs;
|
|
69
77
|
}
|
|
70
78
|
|
|
@@ -79,18 +87,20 @@ const ensureArray = value => {
|
|
|
79
87
|
/**
|
|
80
88
|
* Create catalog for merged messages.
|
|
81
89
|
*/
|
|
82
|
-
function getCatalogForMerge(config) {
|
|
83
|
-
|
|
90
|
+
async function getCatalogForMerge(config) {
|
|
91
|
+
const format = await (0, _formats.getFormat)(config.format, config.formatOptions, config.sourceLocale);
|
|
92
|
+
validateCatalogPath(config.catalogsMergePath, format.getCatalogExtension());
|
|
84
93
|
return new _catalog.Catalog({
|
|
85
94
|
name: getCatalogName(config.catalogsMergePath),
|
|
86
95
|
path: (0, _utils.normalizeRelativePath)(config.catalogsMergePath),
|
|
87
96
|
include: [],
|
|
88
|
-
exclude: []
|
|
97
|
+
exclude: [],
|
|
98
|
+
format
|
|
89
99
|
}, config);
|
|
90
100
|
}
|
|
91
101
|
function getCatalogForFile(file, catalogs) {
|
|
92
102
|
for (const catalog of catalogs) {
|
|
93
|
-
const catalogFile = `${catalog.path}${catalog.format.
|
|
103
|
+
const catalogFile = `${catalog.path}${catalog.format.getCatalogExtension()}`;
|
|
94
104
|
const catalogGlob = (0, _utils.replacePlaceholders)(catalogFile, {
|
|
95
105
|
locale: "*"
|
|
96
106
|
});
|
|
@@ -108,14 +118,13 @@ function getCatalogForFile(file, catalogs) {
|
|
|
108
118
|
/**
|
|
109
119
|
* Validate that `catalogPath` doesn't end with trailing slash
|
|
110
120
|
*/
|
|
111
|
-
function validateCatalogPath(path,
|
|
121
|
+
function validateCatalogPath(path, extension) {
|
|
112
122
|
if (!path.endsWith(_utils.PATHSEP)) {
|
|
113
123
|
return;
|
|
114
124
|
}
|
|
115
|
-
const extension = (0, _formats.getFormat)(config.format).catalogExtension;
|
|
116
125
|
const correctPath = path.slice(0, -1);
|
|
117
126
|
const examplePath = (0, _utils.replacePlaceholders)(correctPath, {
|
|
118
|
-
locale:
|
|
127
|
+
locale: "en"
|
|
119
128
|
}) + extension;
|
|
120
129
|
throw new Error(
|
|
121
130
|
// prettier-ignore
|
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getTranslationsForCatalog = getTranslationsForCatalog;
|
|
7
|
-
function getTranslationsForCatalog(catalog, locale, options) {
|
|
8
|
-
const catalogs = catalog.readAll();
|
|
9
|
-
const template = catalog.readTemplate() || {};
|
|
7
|
+
async function getTranslationsForCatalog(catalog, locale, options) {
|
|
8
|
+
const catalogs = await catalog.readAll();
|
|
9
|
+
const template = (await catalog.readTemplate()) || {};
|
|
10
10
|
const sourceLocaleCatalog = catalogs[options.sourceLocale] || {};
|
|
11
11
|
const input = {
|
|
12
12
|
...template,
|
package/build/api/catalog.js
CHANGED
|
@@ -5,14 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.cleanObsolete = exports.Catalog = void 0;
|
|
7
7
|
exports.order = order;
|
|
8
|
-
exports.
|
|
9
|
-
exports.orderByOrigin = orderByOrigin;
|
|
8
|
+
exports.orderByMessage = orderByMessage;
|
|
10
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
10
|
var _path = _interopRequireDefault(require("path"));
|
|
12
11
|
var R = _interopRequireWildcard(require("ramda"));
|
|
13
12
|
var _glob = _interopRequireDefault(require("glob"));
|
|
14
13
|
var _normalizePath = _interopRequireDefault(require("normalize-path"));
|
|
15
|
-
var _formats = require("./formats");
|
|
16
14
|
var _getTranslationsForCatalog = require("./catalog/getTranslationsForCatalog");
|
|
17
15
|
var _mergeCatalog = require("./catalog/mergeCatalog");
|
|
18
16
|
var _extractFromFiles = require("./catalog/extractFromFiles");
|
|
@@ -28,6 +26,7 @@ class Catalog {
|
|
|
28
26
|
path,
|
|
29
27
|
include,
|
|
30
28
|
templatePath,
|
|
29
|
+
format,
|
|
31
30
|
exclude = []
|
|
32
31
|
}, config) {
|
|
33
32
|
this.config = config;
|
|
@@ -35,15 +34,15 @@ class Catalog {
|
|
|
35
34
|
this.path = (0, _utils.normalizeRelativePath)(path);
|
|
36
35
|
this.include = include.map(_utils.normalizeRelativePath);
|
|
37
36
|
this.exclude = [this.localeDir, ...exclude.map(_utils.normalizeRelativePath)];
|
|
38
|
-
this.format =
|
|
39
|
-
this.templateFile = templatePath || getTemplatePath(this.format, this.path);
|
|
37
|
+
this.format = format;
|
|
38
|
+
this.templateFile = templatePath || getTemplatePath(this.format.getTemplateExtension(), this.path);
|
|
40
39
|
}
|
|
41
40
|
async make(options) {
|
|
42
41
|
const nextCatalog = await this.collect({
|
|
43
42
|
files: options.files
|
|
44
43
|
});
|
|
45
44
|
if (!nextCatalog) return false;
|
|
46
|
-
const prevCatalogs = this.readAll();
|
|
45
|
+
const prevCatalogs = await this.readAll();
|
|
47
46
|
const catalogs = this.merge(prevCatalogs, nextCatalog, {
|
|
48
47
|
overwrite: options.overwrite,
|
|
49
48
|
files: options.files
|
|
@@ -56,11 +55,8 @@ class Catalog {
|
|
|
56
55
|
// Sort messages
|
|
57
56
|
order(options.orderBy)));
|
|
58
57
|
const sortedCatalogs = cleanAndSort(catalogs);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
} else {
|
|
62
|
-
this.writeAll(sortedCatalogs);
|
|
63
|
-
}
|
|
58
|
+
const locales = options.locale ? [options.locale] : this.locales;
|
|
59
|
+
await Promise.all(locales.map(locale => this.write(locale, sortedCatalogs[locale])));
|
|
64
60
|
return sortedCatalogs;
|
|
65
61
|
}
|
|
66
62
|
async makeTemplate(options) {
|
|
@@ -69,7 +65,7 @@ class Catalog {
|
|
|
69
65
|
});
|
|
70
66
|
if (!catalog) return false;
|
|
71
67
|
const sorted = order(options.orderBy)(catalog);
|
|
72
|
-
this.writeTemplate(sorted);
|
|
68
|
+
await this.writeTemplate(sorted);
|
|
73
69
|
return sorted;
|
|
74
70
|
}
|
|
75
71
|
|
|
@@ -111,33 +107,22 @@ class Catalog {
|
|
|
111
107
|
return (0, _mergeCatalog.mergeCatalog)(prevCatalog, nextCatalog, this.config.sourceLocale === locale, options);
|
|
112
108
|
}, prevCatalogs);
|
|
113
109
|
}
|
|
114
|
-
getTranslations(locale, options) {
|
|
115
|
-
return (0, _getTranslationsForCatalog.getTranslationsForCatalog)(this, locale, options);
|
|
110
|
+
async getTranslations(locale, options) {
|
|
111
|
+
return await (0, _getTranslationsForCatalog.getTranslationsForCatalog)(this, locale, options);
|
|
116
112
|
}
|
|
117
|
-
write(locale, messages) {
|
|
113
|
+
async write(locale, messages) {
|
|
118
114
|
const filename = (0, _utils.replacePlaceholders)(this.path, {
|
|
119
115
|
locale
|
|
120
|
-
}) + this.format.
|
|
116
|
+
}) + this.format.getCatalogExtension();
|
|
121
117
|
const created = !_fs.default.existsSync(filename);
|
|
122
|
-
|
|
123
|
-
...this.config.formatOptions,
|
|
124
|
-
locale
|
|
125
|
-
};
|
|
126
|
-
this.format.write(filename, messages, options);
|
|
118
|
+
await this.format.write(filename, messages, locale);
|
|
127
119
|
return [created, filename];
|
|
128
120
|
}
|
|
129
|
-
|
|
130
|
-
this.locales.forEach(locale => this.write(locale, catalogs[locale]));
|
|
131
|
-
}
|
|
132
|
-
writeTemplate(messages) {
|
|
121
|
+
async writeTemplate(messages) {
|
|
133
122
|
const filename = this.templateFile;
|
|
134
|
-
|
|
135
|
-
...this.config.formatOptions,
|
|
136
|
-
locale: undefined
|
|
137
|
-
};
|
|
138
|
-
this.format.write(filename, messages, options);
|
|
123
|
+
await this.format.write(filename, messages, undefined);
|
|
139
124
|
}
|
|
140
|
-
writeCompiled(locale, compiledCatalog, namespace) {
|
|
125
|
+
async writeCompiled(locale, compiledCatalog, namespace) {
|
|
141
126
|
let ext;
|
|
142
127
|
if (namespace === "es") {
|
|
143
128
|
ext = "mjs";
|
|
@@ -149,23 +134,29 @@ class Catalog {
|
|
|
149
134
|
const filename = `${(0, _utils.replacePlaceholders)(this.path, {
|
|
150
135
|
locale
|
|
151
136
|
})}.${ext}`;
|
|
152
|
-
(0, _utils.writeFile)(filename, compiledCatalog);
|
|
137
|
+
await (0, _utils.writeFile)(filename, compiledCatalog);
|
|
153
138
|
return filename;
|
|
154
139
|
}
|
|
155
|
-
read(locale) {
|
|
140
|
+
async read(locale) {
|
|
156
141
|
const filename = (0, _utils.replacePlaceholders)(this.path, {
|
|
157
142
|
locale
|
|
158
|
-
}) + this.format.
|
|
159
|
-
return this.format.read(filename);
|
|
143
|
+
}) + this.format.getCatalogExtension();
|
|
144
|
+
return await this.format.read(filename, locale);
|
|
160
145
|
}
|
|
161
|
-
readAll() {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
146
|
+
async readAll() {
|
|
147
|
+
const res = {};
|
|
148
|
+
await Promise.all(this.locales.map(async locale => res[locale] = await this.read(locale)));
|
|
149
|
+
|
|
150
|
+
// statement above will save locales in object in undetermined order
|
|
151
|
+
// resort here to have keys order the same as in locales definition
|
|
152
|
+
return this.locales.reduce((acc, locale) => {
|
|
153
|
+
acc[locale] = res[locale];
|
|
154
|
+
return acc;
|
|
155
|
+
}, {});
|
|
156
|
+
}
|
|
157
|
+
async readTemplate() {
|
|
167
158
|
const filename = this.templateFile;
|
|
168
|
-
return this.format.read(filename);
|
|
159
|
+
return await this.format.read(filename, undefined);
|
|
169
160
|
}
|
|
170
161
|
get sourcePaths() {
|
|
171
162
|
const includeGlobs = this.include.map(includePath => {
|
|
@@ -194,8 +185,7 @@ class Catalog {
|
|
|
194
185
|
}
|
|
195
186
|
}
|
|
196
187
|
exports.Catalog = Catalog;
|
|
197
|
-
function getTemplatePath(
|
|
198
|
-
const ext = format.templateExtension || format.catalogExtension;
|
|
188
|
+
function getTemplatePath(ext, path) {
|
|
199
189
|
return path.replace(LOCALE_SUFFIX_RE, "messages" + ext);
|
|
200
190
|
}
|
|
201
191
|
const cleanObsolete = R.filter(message => !message.obsolete);
|
|
@@ -203,6 +193,7 @@ exports.cleanObsolete = cleanObsolete;
|
|
|
203
193
|
function order(by) {
|
|
204
194
|
return {
|
|
205
195
|
messageId: orderByMessageId,
|
|
196
|
+
message: orderByMessage,
|
|
206
197
|
origin: orderByOrigin
|
|
207
198
|
}[by];
|
|
208
199
|
}
|
|
@@ -240,4 +231,15 @@ function orderByOrigin(messages) {
|
|
|
240
231
|
acc[key] = messages[key];
|
|
241
232
|
return acc;
|
|
242
233
|
}, {});
|
|
234
|
+
}
|
|
235
|
+
function orderByMessage(messages) {
|
|
236
|
+
return Object.keys(messages).sort((a, b) => {
|
|
237
|
+
const aMsg = messages[a].message || "";
|
|
238
|
+
const bMsg = messages[b].message || "";
|
|
239
|
+
return aMsg.localeCompare(bMsg);
|
|
240
|
+
}).reduce((acc, key) => {
|
|
241
|
+
;
|
|
242
|
+
acc[key] = messages[key];
|
|
243
|
+
return acc;
|
|
244
|
+
}, {});
|
|
243
245
|
}
|
package/build/api/compile.js
CHANGED
|
@@ -26,6 +26,11 @@ function createCompiledCatalog(locale, messages, options) {
|
|
|
26
26
|
obj[key] = compile(translation, shouldPseudolocalize);
|
|
27
27
|
return obj;
|
|
28
28
|
}, {});
|
|
29
|
+
if (namespace === "json") {
|
|
30
|
+
return JSON.stringify({
|
|
31
|
+
messages: compiledMessages
|
|
32
|
+
});
|
|
33
|
+
}
|
|
29
34
|
const ast = buildExportStatement(
|
|
30
35
|
//build JSON.parse(<compiledMessages>) statement
|
|
31
36
|
t.callExpression(t.memberExpression(t.identifier("JSON"), t.identifier("parse")), [t.stringLiteral(JSON.stringify(compiledMessages))]), namespace);
|
|
@@ -18,15 +18,21 @@ const extractor = {
|
|
|
18
18
|
},
|
|
19
19
|
async extract(filename, code, onMessageExtracted, ctx) {
|
|
20
20
|
const parserOptions = ctx.linguiConfig.extractorParserOptions;
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
// https://babeljs.io/docs/en/babel-parser#latest-ecmascript-features
|
|
23
|
-
[
|
|
24
|
-
decoratorsBeforeExport: (parserOptions === null || parserOptions === void 0 ? void 0 : parserOptions.decoratorsBeforeExport) || true
|
|
25
|
-
}]];
|
|
23
|
+
const parserPlugins = [];
|
|
26
24
|
if ([/\.ts$/, /\.mts$/, /\.cts$/, /\.tsx$/].some(r => filename.match(r))) {
|
|
27
25
|
parserPlugins.push("typescript");
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
if (parserOptions.tsExperimentalDecorators) {
|
|
27
|
+
parserPlugins.push("decorators-legacy");
|
|
28
|
+
} else {
|
|
29
|
+
parserPlugins.push("decorators");
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
parserPlugins.push("decorators");
|
|
33
|
+
if (parserOptions !== null && parserOptions !== void 0 && parserOptions.flow) {
|
|
34
|
+
parserPlugins.push("flow");
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
37
|
if ([/\.jsx$/, /\.tsx$/].some(r => filename.match(r))) {
|
|
32
38
|
parserPlugins.push("jsx");
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FormatterWrapper = void 0;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
var _rethrownError = require("../rethrownError");
|
|
9
|
+
class FormatterWrapper {
|
|
10
|
+
constructor(f, sourceLocale) {
|
|
11
|
+
this.f = f;
|
|
12
|
+
this.sourceLocale = sourceLocale;
|
|
13
|
+
}
|
|
14
|
+
getCatalogExtension() {
|
|
15
|
+
return this.f.catalogExtension;
|
|
16
|
+
}
|
|
17
|
+
getTemplateExtension() {
|
|
18
|
+
return this.f.templateExtension || this.f.catalogExtension;
|
|
19
|
+
}
|
|
20
|
+
async write(filename, catalog, locale) {
|
|
21
|
+
const content = await this.f.serialize(catalog, {
|
|
22
|
+
locale,
|
|
23
|
+
sourceLocale: this.sourceLocale,
|
|
24
|
+
existing: await (0, _utils.readFile)(filename),
|
|
25
|
+
filename
|
|
26
|
+
});
|
|
27
|
+
await (0, _utils.writeFileIfChanged)(filename, content);
|
|
28
|
+
}
|
|
29
|
+
async read(filename, locale) {
|
|
30
|
+
const content = await (0, _utils.readFile)(filename);
|
|
31
|
+
if (!content) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return this.f.parse(content, {
|
|
36
|
+
locale,
|
|
37
|
+
sourceLocale: this.sourceLocale,
|
|
38
|
+
filename
|
|
39
|
+
});
|
|
40
|
+
} catch (e) {
|
|
41
|
+
throw new _rethrownError.RethrownError(`Cannot read ${filename}`, e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.FormatterWrapper = FormatterWrapper;
|
|
@@ -3,29 +3,55 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "FormatterWrapper", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _formatterWrapper.FormatterWrapper;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
exports.getFormat = getFormat;
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"po-gettext": _poGettext.default
|
|
19
|
-
};
|
|
13
|
+
var _formatterWrapper = require("./formatterWrapper");
|
|
14
|
+
var _utils = require("../utils");
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
+
function createDeprecationError(packageName, format, installCode) {
|
|
18
|
+
const installCmd = (0, _utils.makeInstall)(packageName);
|
|
19
|
+
return `
|
|
20
|
+
Format \`${format}\` is no longer included in \`@lingui/cli\` by default.
|
|
21
|
+
You need to install it using ${installCmd} command and add to your \`lingui.config.{js,ts}\`:
|
|
22
|
+
|
|
23
|
+
import { formatter } from "${packageName}"
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
export default {
|
|
26
|
+
[...]
|
|
27
|
+
format: ${installCode}
|
|
28
|
+
}
|
|
29
|
+
`.trim();
|
|
30
|
+
}
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
// Introduced in v4. Remove this deprecation in v5
|
|
33
|
+
const formats = {
|
|
34
|
+
lingui: async () => {
|
|
35
|
+
throw new Error(createDeprecationError("@lingui/format-json", "lingui", 'formatter({style: "lingui"})'));
|
|
36
|
+
},
|
|
37
|
+
minimal: async () => {
|
|
38
|
+
throw new Error(createDeprecationError("@lingui/format-json", "minimal", 'formatter({style: "minimal"})'));
|
|
39
|
+
},
|
|
40
|
+
po: async () => (await Promise.resolve().then(() => _interopRequireWildcard(require("@lingui/format-po")))).formatter,
|
|
41
|
+
csv: async () => {
|
|
42
|
+
throw new Error(createDeprecationError("@lingui/format-csv", "csv", "formatter()"));
|
|
43
|
+
},
|
|
44
|
+
"po-gettext": async () => {
|
|
45
|
+
throw new Error(createDeprecationError("@lingui/format-po-gettext", "po-gettext", "formatter()"));
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
async function getFormat(_format, options, sourceLocale) {
|
|
49
|
+
if (typeof _format !== "string") {
|
|
50
|
+
return new _formatterWrapper.FormatterWrapper(_format, sourceLocale);
|
|
51
|
+
}
|
|
52
|
+
const format = formats[_format];
|
|
27
53
|
if (!format) {
|
|
28
|
-
throw new Error(`Unknown format "${
|
|
54
|
+
throw new Error(`Unknown format "${_format}". Use one of following: ${Object.keys(formats).join(", ")}`);
|
|
29
55
|
}
|
|
30
|
-
return format;
|
|
56
|
+
return new _formatterWrapper.FormatterWrapper((await format())(options), sourceLocale);
|
|
31
57
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RethrownError = void 0;
|
|
7
|
+
class RethrownError extends Error {
|
|
8
|
+
constructor(message, originalError) {
|
|
9
|
+
super();
|
|
10
|
+
this.message = message + " " + originalError.message;
|
|
11
|
+
this.stack = `Error: ${message} \nOriginal: ` + originalError.stack;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.RethrownError = RethrownError;
|
package/build/api/utils.js
CHANGED
|
@@ -31,7 +31,7 @@ function prettyOrigin(origins) {
|
|
|
31
31
|
}
|
|
32
32
|
function replacePlaceholders(input, values) {
|
|
33
33
|
return input.replace(/\{([^}]+)}/g, (m, placeholder) => {
|
|
34
|
-
return values[placeholder]
|
|
34
|
+
return values[placeholder] ?? m;
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
const splitOrigin = origin => {
|
|
@@ -41,18 +41,18 @@ const splitOrigin = origin => {
|
|
|
41
41
|
exports.splitOrigin = splitOrigin;
|
|
42
42
|
const joinOrigin = origin => origin.join(":");
|
|
43
43
|
exports.joinOrigin = joinOrigin;
|
|
44
|
-
function readFile(fileName) {
|
|
44
|
+
async function readFile(fileName) {
|
|
45
45
|
try {
|
|
46
|
-
return _fs.default.
|
|
46
|
+
return (await _fs.default.promises.readFile(fileName)).toString();
|
|
47
47
|
} catch (err) {
|
|
48
48
|
if (err.code != "ENOENT") {
|
|
49
49
|
throw err;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
function mkdirp(dir) {
|
|
53
|
+
async function mkdirp(dir) {
|
|
54
54
|
try {
|
|
55
|
-
_fs.default.
|
|
55
|
+
await _fs.default.promises.mkdir(dir, {
|
|
56
56
|
recursive: true
|
|
57
57
|
});
|
|
58
58
|
} catch (err) {
|
|
@@ -70,26 +70,26 @@ function isDirectory(filePath) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
function writeFile(fileName, content) {
|
|
74
|
-
mkdirp(_path.default.dirname(fileName));
|
|
75
|
-
_fs.default.
|
|
73
|
+
async function writeFile(fileName, content) {
|
|
74
|
+
await mkdirp(_path.default.dirname(fileName));
|
|
75
|
+
await _fs.default.promises.writeFile(fileName, content);
|
|
76
76
|
}
|
|
77
|
-
function writeFileIfChanged(filename, newContent) {
|
|
78
|
-
const raw = readFile(filename);
|
|
77
|
+
async function writeFileIfChanged(filename, newContent) {
|
|
78
|
+
const raw = await readFile(filename);
|
|
79
79
|
if (raw) {
|
|
80
80
|
if (newContent !== raw) {
|
|
81
|
-
writeFile(filename, newContent);
|
|
81
|
+
await writeFile(filename, newContent);
|
|
82
82
|
}
|
|
83
83
|
} else {
|
|
84
|
-
writeFile(filename, newContent);
|
|
84
|
+
await writeFile(filename, newContent);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
function hasYarn() {
|
|
88
88
|
return _fs.default.existsSync(_path.default.resolve("yarn.lock"));
|
|
89
89
|
}
|
|
90
|
-
function makeInstall() {
|
|
90
|
+
function makeInstall(packageName, dev = false) {
|
|
91
91
|
const withYarn = hasYarn();
|
|
92
|
-
return
|
|
92
|
+
return withYarn ? `yarn add ${dev ? "--dev " : ""}${packageName}` : `npm install ${dev ? "--save-dev" : "--save"} ${packageName}`;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
/**
|
|
@@ -110,6 +110,8 @@ function normalizeRelativePath(sourcePath) {
|
|
|
110
110
|
// absolute path
|
|
111
111
|
return (0, _normalizePath.default)(sourcePath, false);
|
|
112
112
|
}
|
|
113
|
+
|
|
114
|
+
// https://github.com/lingui/js-lingui/issues/809
|
|
113
115
|
const isDir = isDirectory(sourcePath);
|
|
114
116
|
return (0, _normalizePath.default)(_path.default.relative(process.cwd(), sourcePath), false) + (isDir ? "/" : "");
|
|
115
117
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildExternalizeFilter = buildExternalizeFilter;
|
|
7
|
+
exports.getPackageJson = getPackageJson;
|
|
8
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
function createPackageRegExp(packageName) {
|
|
11
|
+
return new RegExp("^" + packageName + "(?:\\/.+)?");
|
|
12
|
+
}
|
|
13
|
+
function packages(packages, includeDeps) {
|
|
14
|
+
return Object.keys(packages || {}).filter(packageName => {
|
|
15
|
+
return !includeDeps.some(incl => packageName.startsWith(incl));
|
|
16
|
+
}).map(createPackageRegExp);
|
|
17
|
+
}
|
|
18
|
+
function buildExternalizeFilter({
|
|
19
|
+
includeDeps,
|
|
20
|
+
excludeDeps,
|
|
21
|
+
packageJson
|
|
22
|
+
}) {
|
|
23
|
+
const external = [...packages(packageJson.dependencies, includeDeps), ...packages(packageJson.devDependencies, includeDeps), ...packages(packageJson.peerDependencies, includeDeps), ...packages(packageJson.optionalDependencies, includeDeps), ...excludeDeps.map(createPackageRegExp)];
|
|
24
|
+
return id => external.some(regExp => {
|
|
25
|
+
return regExp.test(id);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async function getPackageJson(rootDir) {
|
|
29
|
+
const {
|
|
30
|
+
default: pkgUp
|
|
31
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("pkg-up")));
|
|
32
|
+
const packageJsonPath = await pkgUp({
|
|
33
|
+
cwd: rootDir
|
|
34
|
+
});
|
|
35
|
+
if (!packageJsonPath) {
|
|
36
|
+
throw new Error("We could not able to find your package.json file. " + "Check that `rootDir` is pointing to the folder with package.json");
|
|
37
|
+
}
|
|
38
|
+
return await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(packageJsonPath);
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.bundleSource = bundleSource;
|
|
7
|
+
var _buildExternalizeFilter = require("./buildExternalizeFilter");
|
|
8
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
+
function createExtRegExp(extensions) {
|
|
11
|
+
return new RegExp("\\.(?:" + extensions.join("|") + ")(?:\\?.*)?$");
|
|
12
|
+
}
|
|
13
|
+
async function bundleSource(config, entryPoints, outDir, rootDir) {
|
|
14
|
+
const esbuild = await Promise.resolve().then(() => _interopRequireWildcard(require("esbuild")));
|
|
15
|
+
const excludeExtensions = config.excludeExtensions || ["ico", "pot", "xliff", "woff2", "woff", "eot", "gif", "otf", "ttf", "mp4", "svg", "png", "css", "sass", "less", "jpg"];
|
|
16
|
+
const packageJson = await (0, _buildExternalizeFilter.getPackageJson)(rootDir);
|
|
17
|
+
const esbuildOptions = {
|
|
18
|
+
entryPoints: entryPoints,
|
|
19
|
+
outExtension: {
|
|
20
|
+
".js": ".jsx"
|
|
21
|
+
},
|
|
22
|
+
jsx: "preserve",
|
|
23
|
+
bundle: true,
|
|
24
|
+
platform: "node",
|
|
25
|
+
target: ["esnext"],
|
|
26
|
+
format: "esm",
|
|
27
|
+
splitting: false,
|
|
28
|
+
treeShaking: true,
|
|
29
|
+
outdir: outDir,
|
|
30
|
+
sourcemap: "inline",
|
|
31
|
+
sourceRoot: outDir,
|
|
32
|
+
sourcesContent: false,
|
|
33
|
+
outbase: rootDir,
|
|
34
|
+
metafile: true,
|
|
35
|
+
plugins: [{
|
|
36
|
+
name: "externalize-deps",
|
|
37
|
+
setup(build) {
|
|
38
|
+
const isExternal = (0, _buildExternalizeFilter.buildExternalizeFilter)({
|
|
39
|
+
includeDeps: config.includeDeps || [],
|
|
40
|
+
excludeDeps: config.excludeDeps || [],
|
|
41
|
+
packageJson
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// externalize bare imports
|
|
45
|
+
build.onResolve({
|
|
46
|
+
filter: /^[^.].*/
|
|
47
|
+
}, async ({
|
|
48
|
+
path: id
|
|
49
|
+
}) => {
|
|
50
|
+
if (isExternal(id)) {
|
|
51
|
+
return {
|
|
52
|
+
external: true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
name: "externalize-files",
|
|
59
|
+
setup(build) {
|
|
60
|
+
build.onResolve({
|
|
61
|
+
filter: createExtRegExp(excludeExtensions)
|
|
62
|
+
}, () => ({
|
|
63
|
+
external: true
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
}]
|
|
67
|
+
};
|
|
68
|
+
return await esbuild.build(config.resolveEsbuildOptions ? config.resolveEsbuildOptions(esbuildOptions) : esbuildOptions);
|
|
69
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ENTRY_NAME_PH = exports.DEFAULT_TEMPLATE_NAME = void 0;
|
|
7
|
+
const ENTRY_NAME_PH = "{entryName}";
|
|
8
|
+
exports.ENTRY_NAME_PH = ENTRY_NAME_PH;
|
|
9
|
+
const DEFAULT_TEMPLATE_NAME = "messages";
|
|
10
|
+
exports.DEFAULT_TEMPLATE_NAME = DEFAULT_TEMPLATE_NAME;
|