@lingui/conf 5.9.1 → 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/index.d.mts CHANGED
@@ -1,18 +1,3 @@
1
- /**
2
- * @deprecated please pass formatter directly to `format`
3
- *
4
- * @example
5
- * ```js
6
- * // lingui.config.{js,ts}
7
- * import {formatter} from "@lingui/format-po"
8
- *
9
- * export default {
10
- * [...]
11
- * format: formatter({lineNumbers: false}),
12
- * }
13
- * ```
14
- */
15
- type CatalogFormat = "lingui" | "minimal" | "po" | "csv" | "po-gettext";
16
1
  type ExtractorCtx = {
17
2
  /**
18
3
  * Raw Sourcemaps object to mapping from.
@@ -23,7 +8,14 @@ type ExtractorCtx = {
23
8
  };
24
9
  type CatalogExtra = Record<string, unknown>;
25
10
  type MessageOrigin = [filename: string, line?: number];
26
- type ExtractedMessageType<Extra = CatalogExtra> = {
11
+ type ExtractedMessageType = {
12
+ message?: string;
13
+ origin: MessageOrigin[];
14
+ comments: string[];
15
+ context?: string;
16
+ placeholders: Record<string, string[]>;
17
+ };
18
+ type MessageType<Extra = CatalogExtra> = {
27
19
  message?: string;
28
20
  origin?: MessageOrigin[];
29
21
  comments?: string[];
@@ -35,19 +27,17 @@ type ExtractedMessageType<Extra = CatalogExtra> = {
35
27
  */
36
28
  extra?: Extra;
37
29
  placeholders?: Record<string, string[]>;
30
+ translation?: string;
38
31
  };
39
- type MessageType<Extra = CatalogExtra> = ExtractedMessageType<Extra> & {
40
- translation: string;
41
- };
42
- type ExtractedCatalogType<Extra = CatalogExtra> = {
43
- [msgId: string]: ExtractedMessageType<Extra>;
32
+ type ExtractedCatalogType = {
33
+ [msgId: string]: ExtractedMessageType;
44
34
  };
45
35
  type CatalogType<Extra = CatalogExtra> = {
46
36
  [msgId: string]: MessageType<Extra>;
47
37
  };
48
38
  type ExtractorType = {
49
39
  match(filename: string): boolean;
50
- extract(filename: string, code: string, onMessageExtracted: (msg: ExtractedMessage) => void, ctx?: ExtractorCtx): Promise<void> | void;
40
+ extract(filename: string, code: string, onMessageExtracted: (msg: ExtractedMessage) => void, ctx: ExtractorCtx): Promise<void> | void;
51
41
  };
52
42
  type CatalogFormatter = {
53
43
  catalogExtension: string;
@@ -57,15 +47,15 @@ type CatalogFormatter = {
57
47
  */
58
48
  templateExtension?: string;
59
49
  parse(content: string, ctx: {
60
- locale: string | null;
50
+ locale: string | undefined;
61
51
  sourceLocale: string;
62
52
  filename: string;
63
53
  }): Promise<CatalogType> | CatalogType;
64
54
  serialize(catalog: CatalogType, ctx: {
65
- locale: string | null;
55
+ locale: string | undefined;
66
56
  sourceLocale: string;
67
57
  filename: string;
68
- existing: string | null;
58
+ existing: string | undefined;
69
59
  }): Promise<string> | string;
70
60
  };
71
61
  type ExtractedMessage = {
@@ -76,17 +66,12 @@ type ExtractedMessage = {
76
66
  comment?: string;
77
67
  placeholders?: Record<string, string>;
78
68
  };
79
- type CatalogFormatOptions = {
80
- origins?: boolean;
81
- lineNumbers?: boolean;
82
- disableSelectWarning?: boolean;
83
- };
84
69
  type OrderByFn = (a: {
85
70
  messageId: string;
86
- entry: ExtractedMessageType;
71
+ entry: MessageType;
87
72
  }, b: {
88
73
  messageId: string;
89
- entry: ExtractedMessageType;
74
+ entry: MessageType;
90
75
  }) => number;
91
76
  type OrderBy = "messageId" | "message" | "origin" | OrderByFn;
92
77
  type CatalogConfig = {
@@ -193,14 +178,26 @@ type LinguiConfig = {
193
178
  * https://lingui.dev/guides/custom-extractor
194
179
  */
195
180
  extractors?: ExtractorType[];
196
- prevFormat?: CatalogFormat;
197
181
  /**
198
- * Message catalog format. The po formatter is used by default. Other formatters are available as separate packages.
182
+ * Message catalog format. If not set, po formatter would be used.
183
+ *
184
+ * Other formatters are available as separate packages.
185
+ *
186
+ * If you want to set additional options for po formatter you need to
187
+ * install it as a separate package and provide in config:
188
+ *
189
+ * @example
190
+ * ```js
191
+ * import {formatter} from "@lingui/format-po"
192
+ *
193
+ * export default {
194
+ * [...]
195
+ * format: formatter({lineNumbers: false}),
196
+ * }
197
+ * ```
199
198
  *
200
- * @default "po"
201
199
  */
202
- format?: CatalogFormat | CatalogFormatter;
203
- formatOptions?: CatalogFormatOptions;
200
+ format?: CatalogFormatter;
204
201
  /**
205
202
  * The locale tags used in the project. The `extract` and `compile` commands write a catalog for each locale specified.
206
203
  *
@@ -297,7 +294,7 @@ type LinguiConfig = {
297
294
  * msg`Hello` // <-- would be correctly picked up by macro
298
295
  * ```
299
296
  *
300
- * @default ["@lingui/macro", "@lingui/core/macro"]
297
+ * @default [ "@lingui/core/macro"]
301
298
  */
302
299
  corePackage?: string[];
303
300
  /**
@@ -317,7 +314,7 @@ type LinguiConfig = {
317
314
  * <Trans>Hello</Trans> // <-- would be correctly picked up by macro
318
315
  * ```
319
316
  *
320
- * @default ["@lingui/macro", "@lingui/react/macro"]
317
+ * @default ["@lingui/react/macro"]
321
318
  */
322
319
  jsxPackage?: string[];
323
320
  };
@@ -326,9 +323,8 @@ type LinguiConfig = {
326
323
  };
327
324
  };
328
325
  type ModuleSourceNormalized = readonly [module: string, specifier: string];
329
- type LinguiConfigNormalized = Omit<LinguiConfig, "runtimeConfigModule"> & {
326
+ type LinguiConfigNormalized = Omit<LinguiConfig & typeof defaultConfig, "runtimeConfigModule"> & {
330
327
  resolvedConfigPath?: string;
331
- fallbackLocales?: FallbackLocales;
332
328
  runtimeConfigModule: {
333
329
  i18n: ModuleSourceNormalized;
334
330
  useLingui: ModuleSourceNormalized;
@@ -340,6 +336,36 @@ declare function makeConfig(userConfig: Partial<LinguiConfig>, opts?: {
340
336
  skipValidation?: boolean;
341
337
  resolvedConfigPath?: string;
342
338
  }): LinguiConfigNormalized;
339
+ declare const defaultConfig: {
340
+ catalogs: {
341
+ path: string;
342
+ include: string[];
343
+ exclude: string[];
344
+ }[];
345
+ catalogsMergePath: string;
346
+ compileNamespace: string;
347
+ compilerBabelOptions: {
348
+ minified: boolean;
349
+ jsescOption: {
350
+ minimal: boolean;
351
+ };
352
+ };
353
+ extractorParserOptions: {
354
+ flow: false;
355
+ tsExperimentalDecorators: false;
356
+ };
357
+ fallbackLocales: FallbackLocales;
358
+ locales: never[];
359
+ orderBy: "message";
360
+ pseudoLocale: string;
361
+ rootDir: string;
362
+ runtimeConfigModule: [string, string];
363
+ macro: {
364
+ corePackage: string[];
365
+ jsxPackage: string[];
366
+ };
367
+ sourceLocale: string;
368
+ };
343
369
 
344
370
  /**
345
371
  * Type helper for lingui.config.ts, returns {@link LinguiConfig} object
@@ -352,4 +378,5 @@ declare function getConfig({ cwd, configPath, skipValidation, }?: {
352
378
  skipValidation?: boolean;
353
379
  }): LinguiConfigNormalized;
354
380
 
355
- export { type CatalogConfig, type CatalogFormat, type CatalogFormatOptions, type CatalogFormatter, type CatalogType, type ExperimentalExtractorOptions, type ExtractedCatalogType, type ExtractedMessage, type ExtractedMessageType, type ExtractorCtx, type ExtractorType, type FallbackLocales, type LinguiConfig, type LinguiConfigNormalized, type MessageOrigin, type MessageType, type OrderBy, type OrderByFn, defineConfig, getConfig, makeConfig };
381
+ export { defineConfig, getConfig, makeConfig };
382
+ export type { CatalogConfig, CatalogFormatter, CatalogType, ExperimentalExtractorOptions, ExtractedCatalogType, ExtractedMessage, ExtractedMessageType, ExtractorCtx, ExtractorType, FallbackLocales, LinguiConfig, LinguiConfigNormalized, MessageOrigin, MessageType, OrderBy, OrderByFn };
package/dist/index.mjs CHANGED
@@ -1,15 +1,16 @@
1
- import pico from 'picocolors';
1
+ import { styleText } from 'node:util';
2
2
  import { validate, multipleValidOptions } from 'jest-validate';
3
3
  import path from 'path';
4
4
  import fs from 'fs';
5
- import { cosmiconfigSync } from 'cosmiconfig';
5
+ import { lilconfigSync } from 'lilconfig';
6
6
  import { createJiti } from 'jiti';
7
+ import normalizePath from 'normalize-path';
7
8
 
8
9
  function replaceRootDir(config, rootDir) {
9
10
  if (!rootDir) {
10
11
  return config;
11
12
  }
12
- return function replaceDeep(value, rootDir2) {
13
+ return (function replaceDeep(value, rootDir2) {
13
14
  const replace = (s) => s.replace("<rootDir>", rootDir2);
14
15
  if (value == null) {
15
16
  return value;
@@ -21,12 +22,11 @@ function replaceRootDir(config, rootDir) {
21
22
  Object.keys(value).forEach((key) => {
22
23
  const newKey = replaceDeep(key, rootDir2);
23
24
  value[newKey] = replaceDeep(value[key], rootDir2);
24
- if (key !== newKey)
25
- delete value[key];
25
+ if (key !== newKey) delete value[key];
26
26
  });
27
27
  }
28
28
  return value;
29
- }(config, rootDir);
29
+ })(config, rootDir);
30
30
  }
31
31
 
32
32
  function setCldrParentLocales(config) {
@@ -274,6 +274,7 @@ function makeConfig(userConfig, opts = {}) {
274
274
  }
275
275
  };
276
276
  if (!opts.skipValidation) {
277
+ validateFormat(config);
277
278
  validate(config, configValidation);
278
279
  validateLocales(config);
279
280
  }
@@ -309,23 +310,20 @@ const defaultConfig = {
309
310
  tsExperimentalDecorators: false
310
311
  },
311
312
  fallbackLocales: {},
312
- format: "po",
313
- formatOptions: { origins: true, lineNumbers: true },
314
313
  locales: [],
315
314
  orderBy: "message",
316
315
  pseudoLocale: "",
317
316
  rootDir: ".",
318
317
  runtimeConfigModule: ["@lingui/core", "i18n"],
319
318
  macro: {
320
- corePackage: ["@lingui/macro", "@lingui/core/macro"],
321
- jsxPackage: ["@lingui/macro", "@lingui/react/macro"]
319
+ corePackage: ["@lingui/core/macro"],
320
+ jsxPackage: ["@lingui/react/macro"]
322
321
  },
323
- sourceLocale: "",
324
- service: { name: "", apiKey: "" }
322
+ sourceLocale: ""
325
323
  };
326
324
  const exampleConfig = {
327
325
  ...defaultConfig,
328
- format: multipleValidOptions({}, "po"),
326
+ format: multipleValidOptions({}, {}),
329
327
  extractors: multipleValidOptions([], ["babel"], [Object]),
330
328
  runtimeConfigModule: multipleValidOptions(
331
329
  { i18n: ["@lingui/core", "i18n"], Trans: ["@lingui/react", "Trans"] },
@@ -342,6 +340,10 @@ const exampleConfig = {
342
340
  flow: false,
343
341
  tsExperimentalDecorators: false
344
342
  },
343
+ service: {
344
+ apiKey: "",
345
+ name: ""
346
+ },
345
347
  experimental: {
346
348
  extractor: {
347
349
  entries: [],
@@ -357,13 +359,32 @@ const configValidation = {
357
359
  exampleConfig,
358
360
  comment: "Documentation: https://lingui.dev/ref/conf"
359
361
  };
362
+ function validateFormat(config) {
363
+ if (typeof config.format === "string") {
364
+ throw new Error(
365
+ `String formats like \`{format: ${config.format}}\` are no longer supported.
366
+
367
+ Formatters must now be installed as separate packages and provided via format in lingui config:
368
+
369
+ import { formatter } from "@lingui/format-po"
370
+
371
+ export default {
372
+ [...]
373
+ format: formatter({lineNumbers: false}),
374
+ }
375
+ `.trim()
376
+ );
377
+ }
378
+ }
360
379
  function validateLocales(config) {
361
380
  if (!Array.isArray(config.locales) || !config.locales.length) {
362
381
  console.error("No locales defined!\n");
363
382
  console.error(
364
- `Add ${pico.yellow(
383
+ `Add ${styleText(
384
+ "yellow",
365
385
  "'locales'"
366
- )} to your configuration. See ${pico.underline(
386
+ )} to your configuration. See ${styleText(
387
+ "underline",
367
388
  "https://lingui.dev/ref/conf#locales"
368
389
  )}`
369
390
  );
@@ -379,13 +400,13 @@ function configExists(path2) {
379
400
  }
380
401
  function JitiLoader() {
381
402
  return (filepath) => {
382
- const jiti = createJiti(__filename);
403
+ const jiti = createJiti(import.meta.url);
383
404
  const mod = jiti(filepath);
384
405
  return mod?.default ?? mod;
385
406
  };
386
407
  }
387
408
  const moduleName = "lingui";
388
- const configExplorer = cosmiconfigSync(moduleName, {
409
+ const configExplorer = lilconfigSync(moduleName, {
389
410
  searchPlaces: [
390
411
  `${moduleName}.config.js`,
391
412
  `${moduleName}.config.cjs`,
@@ -394,8 +415,6 @@ const configExplorer = cosmiconfigSync(moduleName, {
394
415
  "package.json",
395
416
  `.${moduleName}rc`,
396
417
  `.${moduleName}rc.json`,
397
- `.${moduleName}rc.yaml`,
398
- `.${moduleName}rc.yml`,
399
418
  `.${moduleName}rc.ts`,
400
419
  `.${moduleName}rc.js`
401
420
  ],
@@ -412,23 +431,29 @@ function getConfig({
412
431
  } = {}) {
413
432
  const defaultRootDir = cwd || process.cwd();
414
433
  configPath = configPath || process.env.LINGUI_CONFIG;
415
- const result = configExists(configPath) ? configExplorer.load(configPath) : configExplorer.search(defaultRootDir);
434
+ let result;
435
+ try {
436
+ result = configExists(configPath) ? configExplorer.load(configPath) : configExplorer.search(defaultRootDir);
437
+ } catch (error) {
438
+ result = null;
439
+ }
416
440
  if (!result) {
417
441
  console.error("Lingui was unable to find a config!\n");
418
442
  console.error(
419
- `Create ${pico.bold(
443
+ `Create ${styleText(
444
+ "bold",
420
445
  "'lingui.config.js'"
421
- )} file with LinguiJS configuration in root of your project (next to package.json). See ${pico.underline(
446
+ )} file with LinguiJS configuration in root of your project (next to package.json). See ${styleText(
447
+ "underline",
422
448
  "https://lingui.dev/ref/conf"
423
449
  )}`
424
450
  );
425
451
  throw new Error("No Lingui config found");
426
452
  }
427
- const userConfig = result ? result.config : {};
428
453
  return makeConfig(
429
454
  {
430
- rootDir: result ? path.dirname(result.filepath) : defaultRootDir,
431
- ...userConfig
455
+ rootDir: result ? normalizePath(path.dirname(result.filepath)) : defaultRootDir,
456
+ ...result.config
432
457
  },
433
458
  { skipValidation, resolvedConfigPath: result.filepath }
434
459
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/conf",
3
- "version": "5.9.1",
3
+ "version": "6.0.0-next.0",
4
4
  "sideEffects": false,
5
5
  "description": "Get lingui configuration from package.json",
6
6
  "keywords": [
@@ -19,22 +19,22 @@
19
19
  "name": "Tomáš Ehrlich",
20
20
  "email": "tomas.ehrlich@gmail.com"
21
21
  },
22
- "main": "dist/index.cjs",
23
- "module": "dist/index.mjs",
24
- "types": "dist/index.d.ts",
22
+ "type": "module",
25
23
  "engines": {
26
- "node": ">=20.0.0"
24
+ "node": ">=22.19.0"
27
25
  },
28
26
  "scripts": {
29
- "build": "rimraf ./dist && unbuild",
30
- "stub": "unbuild --stub"
27
+ "build": "unbuild",
28
+ "check-types": "tsc --noEmit"
29
+ },
30
+ "exports": {
31
+ ".": "./dist/index.mjs"
31
32
  },
32
33
  "dependencies": {
33
- "@babel/runtime": "^7.20.13",
34
- "cosmiconfig": "^8.0.0",
35
34
  "jest-validate": "^29.4.3",
36
35
  "jiti": "^2.5.1",
37
- "picocolors": "^1.1.1"
36
+ "lilconfig": "^3.1.3",
37
+ "normalize-path": "^3.0.0"
38
38
  },
39
39
  "files": [
40
40
  "LICENSE",
@@ -42,8 +42,13 @@
42
42
  "/dist"
43
43
  ],
44
44
  "devDependencies": {
45
- "@lingui/jest-mocks": "*",
46
- "unbuild": "^2.0.0"
45
+ "@lingui/test-utils": "3.0.3",
46
+ "@types/normalize-path": "^3.0.0",
47
+ "unbuild": "3.6.1",
48
+ "vitest": "4.0.18"
49
+ },
50
+ "unbuild": {
51
+ "declaration": "node16"
47
52
  },
48
- "gitHead": "4abb5a8fff1e1936a83a7d1ae602092607c520a1"
53
+ "gitHead": "a9576050487a4f7dfbc88db20814d5a1bb861c8c"
49
54
  }