@lingui/cli 6.5.0 → 6.6.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.
@@ -43,13 +43,18 @@ export async function getCatalogs(config) {
43
43
  });
44
44
  candidates.forEach((catalogDir) => {
45
45
  const name = path.basename(catalogDir);
46
+ const globName = escapeCatalogNameForGlob(name);
46
47
  catalogs.push(new Catalog({
47
48
  name,
48
49
  path: normalizeRelativePath(replacePlaceholders(catalog.path, { name })),
49
50
  include: include.map((path) => replacePlaceholders(path, { name })),
50
51
  exclude: exclude.map((path) => replacePlaceholders(path, { name })),
51
52
  format,
52
- }, config));
53
+ }, config, {
54
+ path: replacePlaceholders(catalog.path, { name: globName }),
55
+ include: include.map((path) => replacePlaceholders(path, { name: globName })),
56
+ exclude: exclude.map((path) => replacePlaceholders(path, { name: globName })),
57
+ }));
53
58
  });
54
59
  });
55
60
  if (config.experimental?.extractor &&
@@ -58,6 +63,9 @@ export async function getCatalogs(config) {
58
63
  }
59
64
  return catalogs;
60
65
  }
66
+ function escapeCatalogNameForGlob(value) {
67
+ return value.replace(/[[\]()]/g, "[$&]");
68
+ }
61
69
  /**
62
70
  * Ensure that value is always array. If not, turn it into an array of one element.
63
71
  */
@@ -29,7 +29,13 @@ export type CatalogProps = {
29
29
  templatePath?: string;
30
30
  format: FormatterWrapper;
31
31
  };
32
+ type CatalogGlobPatterns = {
33
+ path: string;
34
+ include: Array<string>;
35
+ exclude: Array<string>;
36
+ };
32
37
  export declare class Catalog {
38
+ #private;
33
39
  config: LinguiConfigNormalized;
34
40
  name?: string;
35
41
  path: string;
@@ -37,7 +43,7 @@ export declare class Catalog {
37
43
  exclude: Array<string>;
38
44
  format: FormatterWrapper;
39
45
  templateFile: string;
40
- constructor({ name, path, include, templatePath, format, exclude }: CatalogProps, config: LinguiConfigNormalized);
46
+ constructor({ name, path, include, templatePath, format, exclude }: CatalogProps, config: LinguiConfigNormalized, globPatterns?: CatalogGlobPatterns);
41
47
  getFilename(locale: string): string;
42
48
  make(options: MakeOptions): Promise<AllCatalogsType | false>;
43
49
  makeTemplate(options: MakeTemplateOptions): Promise<CatalogType | false>;
@@ -71,3 +77,4 @@ export declare function cleanObsolete<T extends CatalogType>(messages: T): T;
71
77
  export declare function order<T extends CatalogType>(by: OrderBy, catalog: T): T;
72
78
  export declare function writeCompiled(path: string, locale: string, compiledCatalog: string, namespace?: CompiledCatalogNamespace): Promise<string>;
73
79
  export declare const orderByMessage: OrderByFn;
80
+ export {};
@@ -17,12 +17,19 @@ export class Catalog {
17
17
  exclude;
18
18
  format;
19
19
  templateFile;
20
- constructor({ name, path, include, templatePath, format, exclude = [] }, config) {
20
+ #includePatterns;
21
+ #excludePatterns;
22
+ constructor({ name, path, include, templatePath, format, exclude = [] }, config, globPatterns = { path, include, exclude }) {
21
23
  this.config = config;
22
24
  this.name = name;
23
25
  this.path = normalizeRelativePath(path);
24
26
  this.include = include.map(normalizeRelativePath);
25
27
  this.exclude = [this.localeDir, ...exclude.map(normalizeRelativePath)];
28
+ this.#includePatterns = createCatalogPatterns(this.include, globPatterns.include.map(normalizeRelativePath));
29
+ this.#excludePatterns = createCatalogPatterns(this.exclude, [
30
+ getLocaleDir(normalizeRelativePath(globPatterns.path)),
31
+ ...globPatterns.exclude.map(normalizeRelativePath),
32
+ ]);
26
33
  this.format = format;
27
34
  this.templateFile =
28
35
  templatePath ||
@@ -194,30 +201,54 @@ export class Catalog {
194
201
  async readTemplate() {
195
202
  return await this.format.read(this.templateFile, undefined);
196
203
  }
204
+ /** @internal */
205
+ get sourcePatterns() {
206
+ return {
207
+ include: resolveCatalogPatterns(this.include, this.#includePatterns),
208
+ exclude: resolveCatalogPatterns(this.exclude, this.#excludePatterns),
209
+ };
210
+ }
197
211
  get sourcePaths() {
198
- const includeGlobs = this.include.map((includePath) => {
212
+ const sourcePatterns = this.sourcePatterns;
213
+ const includeGlobs = this.include.map((includePath, index) => {
214
+ const includeGlob = sourcePatterns.include[index];
199
215
  const isDir = isDirectory(includePath);
200
216
  /**
201
217
  * glob library results from absolute patterns such as /foo/* are mounted onto the root setting using path.join.
202
218
  * On windows, this will by default result in /foo/* matching C:\foo\bar.txt.
203
219
  */
204
220
  return isDir
205
- ? normalize(path.resolve(process.cwd(), includePath === "/" ? "" : includePath, "**/*.*"))
206
- : includePath;
221
+ ? normalize(path.resolve(process.cwd(), includePath === "/" ? "" : includeGlob, "**/*.*"))
222
+ : includeGlob;
207
223
  });
208
- return globSync(includeGlobs, { exclude: this.exclude });
224
+ return globSync(includeGlobs, { exclude: sourcePatterns.exclude });
209
225
  }
210
226
  get localeDir() {
211
- const localePatternIndex = this.path.indexOf(LOCALE);
212
- if (localePatternIndex === -1) {
213
- throw Error(`Invalid catalog path: ${LOCALE} variable is missing`);
214
- }
215
- return this.path.substring(0, localePatternIndex);
227
+ return getLocaleDir(this.path);
216
228
  }
217
229
  get locales() {
218
230
  return this.config.locales;
219
231
  }
220
232
  }
233
+ function createCatalogPatterns(values, globs) {
234
+ return values.map((value, index) => ({
235
+ value,
236
+ glob: globs[index] ?? value,
237
+ }));
238
+ }
239
+ function resolveCatalogPatterns(values, patterns) {
240
+ return values.map((value, index) => {
241
+ const pattern = patterns[index];
242
+ return pattern?.value === value ? pattern.glob : value;
243
+ });
244
+ }
245
+ function getLocaleDir(catalogPath) {
246
+ const localePatternIndex = catalogPath.indexOf(LOCALE);
247
+ if (localePatternIndex === -1) {
248
+ throw Error(`Invalid catalog path: ${LOCALE} variable is missing`);
249
+ }
250
+ return catalogPath.substring(0, localePatternIndex);
251
+ }
221
252
  function getTemplatePath(ext, path) {
222
253
  return path.replace(LOCALE_SUFFIX_RE, "messages" + ext);
223
254
  }
@@ -7,8 +7,9 @@ export async function getPathsForExtractWatcher(config) {
7
7
  const paths = [];
8
8
  const ignored = [];
9
9
  catalogs.forEach((catalog) => {
10
- paths.push(...catalog.include);
11
- ignored.push(...catalog.exclude);
10
+ const sourcePatterns = catalog.sourcePatterns;
11
+ paths.push(...sourcePatterns.include);
12
+ ignored.push(...sourcePatterns.exclude);
12
13
  });
13
14
  return { paths, ignored };
14
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/cli",
3
- "version": "6.5.0",
3
+ "version": "6.6.0",
4
4
  "description": "Lingui CLI to extract messages, compile catalogs, and manage translation workflows",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -54,12 +54,12 @@
54
54
  "@babel/generator": "^7.28.5",
55
55
  "@babel/parser": "^7.22.0",
56
56
  "@babel/types": "^7.21.2",
57
- "@lingui/babel-plugin-extract-messages": "6.5.0",
58
- "@lingui/babel-plugin-lingui-macro": "6.5.0",
59
- "@lingui/conf": "6.5.0",
60
- "@lingui/core": "6.5.0",
61
- "@lingui/format-po": "6.5.0",
62
- "@lingui/message-utils": "6.5.0",
57
+ "@lingui/babel-plugin-extract-messages": "6.6.0",
58
+ "@lingui/babel-plugin-lingui-macro": "6.6.0",
59
+ "@lingui/conf": "6.6.0",
60
+ "@lingui/core": "6.6.0",
61
+ "@lingui/format-po": "6.6.0",
62
+ "@lingui/message-utils": "6.6.0",
63
63
  "chokidar": "5.0.0",
64
64
  "cli-table3": "^0.6.5",
65
65
  "commander": "^14.0.2",
@@ -97,5 +97,5 @@
97
97
  "rolldown": "^1.1.1",
98
98
  "vitest": "catalog:"
99
99
  },
100
- "gitHead": "9687149054666bbaf89196573ba597d0d6fd09e4"
100
+ "gitHead": "665a19815378dedd89346bb7707bdb0e28df79e7"
101
101
  }