@lingui/conf 5.9.3 → 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/index.cjs DELETED
@@ -1,447 +0,0 @@
1
- 'use strict';
2
-
3
- const pico = require('picocolors');
4
- const jestValidate = require('jest-validate');
5
- const path = require('path');
6
- const fs = require('fs');
7
- const cosmiconfig = require('cosmiconfig');
8
- const jiti = require('jiti');
9
-
10
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
11
-
12
- const pico__default = /*#__PURE__*/_interopDefaultCompat(pico);
13
- const path__default = /*#__PURE__*/_interopDefaultCompat(path);
14
- const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
15
-
16
- function replaceRootDir(config, rootDir) {
17
- if (!rootDir) {
18
- return config;
19
- }
20
- return function replaceDeep(value, rootDir2) {
21
- const replace = (s) => s.replace("<rootDir>", rootDir2);
22
- if (value == null) {
23
- return value;
24
- } else if (typeof value === "string") {
25
- return replace(value);
26
- } else if (Array.isArray(value)) {
27
- return value.map((item) => replaceDeep(item, rootDir2));
28
- } else if (typeof value === "object") {
29
- Object.keys(value).forEach((key) => {
30
- const newKey = replaceDeep(key, rootDir2);
31
- value[newKey] = replaceDeep(value[key], rootDir2);
32
- if (key !== newKey)
33
- delete value[key];
34
- });
35
- }
36
- return value;
37
- }(config, rootDir);
38
- }
39
-
40
- function setCldrParentLocales(config) {
41
- if (config.fallbackLocales === false) {
42
- return {
43
- ...config,
44
- fallbackLocales: {}
45
- };
46
- }
47
- if (!config.fallbackLocales?.default) {
48
- config.locales.forEach((locale) => {
49
- const fl = getCldrParentLocale(locale.toLowerCase());
50
- if (fl && !config.fallbackLocales[locale]) {
51
- config.fallbackLocales = {
52
- ...config.fallbackLocales,
53
- [locale]: fl
54
- };
55
- }
56
- });
57
- }
58
- return config;
59
- }
60
- function getCldrParentLocale(sourceLocale) {
61
- return {
62
- "en-ag": "en",
63
- "en-ai": "en",
64
- "en-au": "en",
65
- "en-bb": "en",
66
- "en-bm": "en",
67
- "en-bs": "en",
68
- "en-bw": "en",
69
- "en-bz": "en",
70
- "en-ca": "en",
71
- "en-cc": "en",
72
- "en-ck": "en",
73
- "en-cm": "en",
74
- "en-cx": "en",
75
- "en-cy": "en",
76
- "en-dg": "en",
77
- "en-dm": "en",
78
- "en-er": "en",
79
- "en-fj": "en",
80
- "en-fk": "en",
81
- "en-fm": "en",
82
- "en-gb": "en",
83
- "en-gd": "en",
84
- "en-gg": "en",
85
- "en-gh": "en",
86
- "en-gi": "en",
87
- "en-gm": "en",
88
- "en-gy": "en",
89
- "en-hk": "en",
90
- "en-ie": "en",
91
- "en-il": "en",
92
- "en-im": "en",
93
- "en-in": "en",
94
- "en-io": "en",
95
- "en-je": "en",
96
- "en-jm": "en",
97
- "en-ke": "en",
98
- "en-ki": "en",
99
- "en-kn": "en",
100
- "en-ky": "en",
101
- "en-lc": "en",
102
- "en-lr": "en",
103
- "en-ls": "en",
104
- "en-mg": "en",
105
- "en-mo": "en",
106
- "en-ms": "en",
107
- "en-mt": "en",
108
- "en-mu": "en",
109
- "en-mw": "en",
110
- "en-my": "en",
111
- "en-na": "en",
112
- "en-nf": "en",
113
- "en-ng": "en",
114
- "en-nr": "en",
115
- "en-nu": "en",
116
- "en-nz": "en",
117
- "en-pg": "en",
118
- "en-ph": "en",
119
- "en-pk": "en",
120
- "en-pn": "en",
121
- "en-pw": "en",
122
- "en-rw": "en",
123
- "en-sb": "en",
124
- "en-sc": "en",
125
- "en-sd": "en",
126
- "en-sg": "en",
127
- "en-sh": "en",
128
- "en-sl": "en",
129
- "en-ss": "en",
130
- "en-sx": "en",
131
- "en-sz": "en",
132
- "en-tc": "en",
133
- "en-tk": "en",
134
- "en-to": "en",
135
- "en-tt": "en",
136
- "en-tv": "en",
137
- "en-tz": "en",
138
- "en-ug": "en",
139
- "en-us": "en",
140
- "en-vc": "en",
141
- "en-vg": "en",
142
- "en-vu": "en",
143
- "en-ws": "en",
144
- "en-za": "en",
145
- "en-zm": "en",
146
- "en-zw": "en",
147
- "en-at": "en",
148
- "en-be": "en",
149
- "en-ch": "en",
150
- "en-de": "en",
151
- "en-dk": "en",
152
- "en-fi": "en",
153
- "en-nl": "en",
154
- "en-se": "en",
155
- "en-si": "en",
156
- "es-ar": "es",
157
- "es-bo": "es",
158
- "es-br": "es",
159
- "es-bz": "es",
160
- "es-cl": "es",
161
- "es-co": "es",
162
- "es-cr": "es",
163
- "es-cu": "es",
164
- "es-do": "es",
165
- "es-ec": "es",
166
- "es-es": "es",
167
- "es-gt": "es",
168
- "es-hn": "es",
169
- "es-mx": "es",
170
- "es-ni": "es",
171
- "es-pa": "es",
172
- "es-pe": "es",
173
- "es-pr": "es",
174
- "es-py": "es",
175
- "es-sv": "es",
176
- "es-us": "es",
177
- "es-uy": "es",
178
- "es-ve": "es",
179
- "pt-ao": "pt",
180
- "pt-ch": "pt",
181
- "pt-cv": "pt",
182
- "pt-fr": "pt",
183
- "pt-gq": "pt",
184
- "pt-gw": "pt",
185
- "pt-lu": "pt",
186
- "pt-mo": "pt",
187
- "pt-mz": "pt",
188
- "pt-pt": "pt",
189
- "pt-st": "pt",
190
- "pt-tl": "pt",
191
- "az-arab": "az",
192
- "az-cyrl": "az",
193
- "blt-latn": "blt",
194
- "bm-nkoo": "bm",
195
- "bs-cyrl": "bs",
196
- "byn-latn": "byn",
197
- "cu-glag": "cu",
198
- "dje-arab": "dje",
199
- "dyo-arab": "dyo",
200
- "en-dsrt": "en",
201
- "en-shaw": "en",
202
- "ff-adlm": "ff",
203
- "ff-arab": "ff",
204
- "ha-arab": "ha",
205
- "hi-latn": "hi",
206
- "iu-latn": "iu",
207
- "kk-arab": "kk",
208
- "ks-deva": "ks",
209
- "ku-arab": "ku",
210
- "ky-arab": "ky",
211
- "ky-latn": "ky",
212
- "ml-arab": "ml",
213
- "mn-mong": "mn",
214
- "mni-mtei": "mni",
215
- "ms-arab": "ms",
216
- "pa-arab": "pa",
217
- "sat-deva": "sat",
218
- "sd-deva": "sd",
219
- "sd-khoj": "sd",
220
- "sd-sind": "sd",
221
- "shi-latn": "shi",
222
- "so-arab": "so",
223
- "sr-latn": "sr",
224
- "sw-arab": "sw",
225
- "tg-arab": "tg",
226
- "ug-cyrl": "ug",
227
- "uz-arab": "uz",
228
- "uz-cyrl": "uz",
229
- "vai-latn": "vai",
230
- "wo-arab": "wo",
231
- "yo-arab": "yo",
232
- "yue-hans": "yue",
233
- "zh-hant": "zh",
234
- "zh-hant-hk": "zh",
235
- "zh-hant-mo": "zh-hant-hk"
236
- }[sourceLocale];
237
- }
238
-
239
- const pathJoinPosix = (...values) => path__default.join(...values).split(path__default.sep).join("/");
240
-
241
- const getSymbolSource = (defaults, config) => {
242
- const name = defaults[1];
243
- if (Array.isArray(config)) {
244
- if (name === "i18n") {
245
- return config;
246
- }
247
- return defaults;
248
- }
249
- const override = config[name];
250
- if (!override) {
251
- return defaults;
252
- }
253
- return [override[0], override[1] || name];
254
- };
255
- function normalizeRuntimeConfigModule(config) {
256
- return {
257
- ...config,
258
- runtimeConfigModule: {
259
- i18n: getSymbolSource(
260
- ["@lingui/core", "i18n"],
261
- config.runtimeConfigModule
262
- ),
263
- useLingui: getSymbolSource(
264
- ["@lingui/react", "useLingui"],
265
- config.runtimeConfigModule
266
- ),
267
- Trans: getSymbolSource(
268
- ["@lingui/react", "Trans"],
269
- config.runtimeConfigModule
270
- )
271
- }
272
- };
273
- }
274
-
275
- function makeConfig(userConfig, opts = {}) {
276
- let config = {
277
- ...defaultConfig,
278
- ...userConfig,
279
- macro: {
280
- ...defaultConfig.macro,
281
- ...userConfig.macro
282
- }
283
- };
284
- if (!opts.skipValidation) {
285
- jestValidate.validate(config, configValidation);
286
- validateLocales(config);
287
- }
288
- config = setCldrParentLocales(config);
289
- config = normalizeRuntimeConfigModule(config);
290
- const out = replaceRootDir(
291
- config,
292
- config.rootDir
293
- );
294
- return {
295
- ...out,
296
- resolvedConfigPath: opts.resolvedConfigPath
297
- };
298
- }
299
- const defaultConfig = {
300
- catalogs: [
301
- {
302
- path: pathJoinPosix("<rootDir>", "locale", "{locale}", "messages"),
303
- include: ["<rootDir>"],
304
- exclude: ["*/node_modules/*"]
305
- }
306
- ],
307
- catalogsMergePath: "",
308
- compileNamespace: "cjs",
309
- compilerBabelOptions: {
310
- minified: true,
311
- jsescOption: {
312
- minimal: true
313
- }
314
- },
315
- extractorParserOptions: {
316
- flow: false,
317
- tsExperimentalDecorators: false
318
- },
319
- fallbackLocales: {},
320
- format: "po",
321
- formatOptions: { origins: true, lineNumbers: true },
322
- locales: [],
323
- orderBy: "message",
324
- pseudoLocale: "",
325
- rootDir: ".",
326
- runtimeConfigModule: ["@lingui/core", "i18n"],
327
- macro: {
328
- corePackage: ["@lingui/macro", "@lingui/core/macro"],
329
- jsxPackage: ["@lingui/macro", "@lingui/react/macro"]
330
- },
331
- sourceLocale: "",
332
- service: { name: "", apiKey: "" }
333
- };
334
- const exampleConfig = {
335
- ...defaultConfig,
336
- format: jestValidate.multipleValidOptions({}, "po"),
337
- extractors: jestValidate.multipleValidOptions([], ["babel"], [Object]),
338
- runtimeConfigModule: jestValidate.multipleValidOptions(
339
- { i18n: ["@lingui/core", "i18n"], Trans: ["@lingui/react", "Trans"] },
340
- ["@lingui/core", "i18n"]
341
- ),
342
- fallbackLocales: jestValidate.multipleValidOptions(
343
- {},
344
- { "en-US": "en" },
345
- { "en-US": ["en"] },
346
- { default: "en" },
347
- false
348
- ),
349
- extractorParserOptions: {
350
- flow: false,
351
- tsExperimentalDecorators: false
352
- },
353
- experimental: {
354
- extractor: {
355
- entries: [],
356
- includeDeps: [],
357
- excludeDeps: [],
358
- excludeExtensions: [],
359
- output: "",
360
- resolveEsbuildOptions: Function
361
- }
362
- }
363
- };
364
- const configValidation = {
365
- exampleConfig,
366
- comment: "Documentation: https://lingui.dev/ref/conf"
367
- };
368
- function validateLocales(config) {
369
- if (!Array.isArray(config.locales) || !config.locales.length) {
370
- console.error("No locales defined!\n");
371
- console.error(
372
- `Add ${pico__default.yellow(
373
- "'locales'"
374
- )} to your configuration. See ${pico__default.underline(
375
- "https://lingui.dev/ref/conf#locales"
376
- )}`
377
- );
378
- }
379
- }
380
-
381
- function defineConfig(config) {
382
- return config;
383
- }
384
-
385
- function configExists(path2) {
386
- return !!path2 && fs__default.existsSync(path2);
387
- }
388
- function JitiLoader() {
389
- return (filepath) => {
390
- const jiti$1 = jiti.createJiti(__filename);
391
- const mod = jiti$1(filepath);
392
- return mod?.default ?? mod;
393
- };
394
- }
395
- const moduleName = "lingui";
396
- const configExplorer = cosmiconfig.cosmiconfigSync(moduleName, {
397
- searchPlaces: [
398
- `${moduleName}.config.js`,
399
- `${moduleName}.config.cjs`,
400
- `${moduleName}.config.ts`,
401
- `${moduleName}.config.mjs`,
402
- "package.json",
403
- `.${moduleName}rc`,
404
- `.${moduleName}rc.json`,
405
- `.${moduleName}rc.yaml`,
406
- `.${moduleName}rc.yml`,
407
- `.${moduleName}rc.ts`,
408
- `.${moduleName}rc.js`
409
- ],
410
- loaders: {
411
- ".js": JitiLoader(),
412
- ".ts": JitiLoader(),
413
- ".mjs": JitiLoader()
414
- }
415
- });
416
- function getConfig({
417
- cwd,
418
- configPath,
419
- skipValidation = false
420
- } = {}) {
421
- const defaultRootDir = cwd || process.cwd();
422
- configPath = configPath || process.env.LINGUI_CONFIG;
423
- const result = configExists(configPath) ? configExplorer.load(configPath) : configExplorer.search(defaultRootDir);
424
- if (!result) {
425
- console.error("Lingui was unable to find a config!\n");
426
- console.error(
427
- `Create ${pico__default.bold(
428
- "'lingui.config.js'"
429
- )} file with LinguiJS configuration in root of your project (next to package.json). See ${pico__default.underline(
430
- "https://lingui.dev/ref/conf"
431
- )}`
432
- );
433
- throw new Error("No Lingui config found");
434
- }
435
- const userConfig = result ? result.config : {};
436
- return makeConfig(
437
- {
438
- rootDir: result ? path__default.dirname(result.filepath) : defaultRootDir,
439
- ...userConfig
440
- },
441
- { skipValidation, resolvedConfigPath: result.filepath }
442
- );
443
- }
444
-
445
- exports.defineConfig = defineConfig;
446
- exports.getConfig = getConfig;
447
- exports.makeConfig = makeConfig;