i18next-cli 1.74.1 → 1.74.2

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/cjs/cli.js CHANGED
@@ -37,7 +37,7 @@ const program = new commander.Command();
37
37
  program
38
38
  .name('i18next-cli')
39
39
  .description('A unified, high-performance i18next CLI.')
40
- .version('1.74.1') // This string is replaced with the actual version at build time by rollup
40
+ .version('1.74.2') // This string is replaced with the actual version at build time by rollup
41
41
  .addHelpText('after', '\nUsing an AI coding agent? Install the i18next-localization skill: npx skills add i18next/i18next-cli\n');
42
42
  // new: global config override option
43
43
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
@@ -132,6 +132,39 @@ function isExtExplicitlyInInputPatterns(ext, input) {
132
132
  return new RegExp(`[{,*]${escaped}[},*]|[.]${escaped}(?:[^a-z]|$)`).test(p);
133
133
  });
134
134
  }
135
+ const extractionSiteRegexes = new WeakMap();
136
+ /**
137
+ * Cheap textual test for anything the extraction walk can turn into a key: a call
138
+ * to a configured function (`t(`, `i18n.t(`, `t?.(`, `t<Ns>(`, `new TranslatedError(`, a
139
+ * `t(` comment), or a mention of what binds a translation function under any name
140
+ * (useTranslation-style hooks, getFixedT, TFunction params) or of a Trans component.
141
+ * A false positive only costs a parse; a false negative would drop keys.
142
+ *
143
+ * @internal
144
+ */
145
+ function mayContainExtractionSite(code, config) {
146
+ let re = extractionSiteRegexes.get(config);
147
+ if (!re) {
148
+ const calls = new Set(['t']);
149
+ const names = new Set(['getFixedT', 'TFunction']);
150
+ for (const fn of config.extract.functions || ['t', '*.t']) {
151
+ // 'tProps.*' matches any `tProps.<x>(` call, so the prefix is what to look for
152
+ if (fn.endsWith('.*'))
153
+ names.add(fn.slice(0, -2).split('.').pop());
154
+ else
155
+ calls.add(fn.split('.').pop());
156
+ }
157
+ for (const hook of config.extract.useTranslationNames || ['useTranslation', 'getT', 'useT']) {
158
+ names.add(typeof hook === 'string' ? hook : hook.name);
159
+ }
160
+ for (const component of config.extract.transComponents || ['Trans'])
161
+ names.add(component.split('.').pop());
162
+ const alt = (set) => [...set].map(s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
163
+ re = new RegExp(`(?<!\\w)(?:(?:${alt(calls)})\\s*(?:\\?\\.\\s*)?[(<]|(?:${alt(names)})(?![\\w$]))`);
164
+ extractionSiteRegexes.set(config, re);
165
+ }
166
+ return re.test(code);
167
+ }
135
168
  /**
136
169
  * Processes an individual source file for translation key extraction.
137
170
  *
@@ -197,6 +230,11 @@ async function processFile(file, plugins, astVisitors, pluginContext, config, lo
197
230
  }
198
231
  return;
199
232
  }
233
+ // A file that mentions no translation function, hook or component cannot yield
234
+ // a key, so skip the parse and walk (#297). The pre-scan has already harvested
235
+ // its constants and types for the other files. onVisitNode plugins see every node.
236
+ if (!plugins.some(p => p.onVisitNode) && !mayContainExtractionSite(code, config))
237
+ return;
200
238
  // When a plugin transformed a non-native file, always use tsx so SWC can
201
239
  // handle TypeScript syntax that the plugin may have extracted from the file.
202
240
  const effectiveExt = (!isNativeExt && wasTransformedByPlugin) ? '.tsx' : fileExt;
@@ -140,13 +140,16 @@ async function processSourceFiles(config) {
140
140
  const userIgnore = Array.isArray(config.extract.ignore)
141
141
  ? config.extract.ignore
142
142
  : config.extract.ignore ? [config.extract.ignore] : [];
143
- return await glob.glob(config.extract.input, {
143
+ const files = await glob.glob(config.extract.input, {
144
144
  // Combine default ignore patterns with user-configured ones
145
145
  ignore: [...defaultIgnore, ...userIgnore],
146
146
  cwd: process.cwd(),
147
147
  // A directory named e.g. `abc.tsx` matches the input globs
148
148
  nodir: true,
149
149
  });
150
+ // glob's order is not stable across runs, and when two call sites give one key
151
+ // different defaults the file visited first wins, so sort for reproducible output (#296)
152
+ return files.sort();
150
153
  }
151
154
 
152
155
  exports.findKeys = findKeys;
package/dist/esm/cli.js CHANGED
@@ -31,7 +31,7 @@ const program = new Command();
31
31
  program
32
32
  .name('i18next-cli')
33
33
  .description('A unified, high-performance i18next CLI.')
34
- .version('1.74.1') // This string is replaced with the actual version at build time by rollup
34
+ .version('1.74.2') // This string is replaced with the actual version at build time by rollup
35
35
  .addHelpText('after', '\nUsing an AI coding agent? Install the i18next-localization skill: npx skills add i18next/i18next-cli\n');
36
36
  // new: global config override option
37
37
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
@@ -130,6 +130,39 @@ function isExtExplicitlyInInputPatterns(ext, input) {
130
130
  return new RegExp(`[{,*]${escaped}[},*]|[.]${escaped}(?:[^a-z]|$)`).test(p);
131
131
  });
132
132
  }
133
+ const extractionSiteRegexes = new WeakMap();
134
+ /**
135
+ * Cheap textual test for anything the extraction walk can turn into a key: a call
136
+ * to a configured function (`t(`, `i18n.t(`, `t?.(`, `t<Ns>(`, `new TranslatedError(`, a
137
+ * `t(` comment), or a mention of what binds a translation function under any name
138
+ * (useTranslation-style hooks, getFixedT, TFunction params) or of a Trans component.
139
+ * A false positive only costs a parse; a false negative would drop keys.
140
+ *
141
+ * @internal
142
+ */
143
+ function mayContainExtractionSite(code, config) {
144
+ let re = extractionSiteRegexes.get(config);
145
+ if (!re) {
146
+ const calls = new Set(['t']);
147
+ const names = new Set(['getFixedT', 'TFunction']);
148
+ for (const fn of config.extract.functions || ['t', '*.t']) {
149
+ // 'tProps.*' matches any `tProps.<x>(` call, so the prefix is what to look for
150
+ if (fn.endsWith('.*'))
151
+ names.add(fn.slice(0, -2).split('.').pop());
152
+ else
153
+ calls.add(fn.split('.').pop());
154
+ }
155
+ for (const hook of config.extract.useTranslationNames || ['useTranslation', 'getT', 'useT']) {
156
+ names.add(typeof hook === 'string' ? hook : hook.name);
157
+ }
158
+ for (const component of config.extract.transComponents || ['Trans'])
159
+ names.add(component.split('.').pop());
160
+ const alt = (set) => [...set].map(s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
161
+ re = new RegExp(`(?<!\\w)(?:(?:${alt(calls)})\\s*(?:\\?\\.\\s*)?[(<]|(?:${alt(names)})(?![\\w$]))`);
162
+ extractionSiteRegexes.set(config, re);
163
+ }
164
+ return re.test(code);
165
+ }
133
166
  /**
134
167
  * Processes an individual source file for translation key extraction.
135
168
  *
@@ -195,6 +228,11 @@ async function processFile(file, plugins, astVisitors, pluginContext, config, lo
195
228
  }
196
229
  return;
197
230
  }
231
+ // A file that mentions no translation function, hook or component cannot yield
232
+ // a key, so skip the parse and walk (#297). The pre-scan has already harvested
233
+ // its constants and types for the other files. onVisitNode plugins see every node.
234
+ if (!plugins.some(p => p.onVisitNode) && !mayContainExtractionSite(code, config))
235
+ return;
198
236
  // When a plugin transformed a non-native file, always use tsx so SWC can
199
237
  // handle TypeScript syntax that the plugin may have extracted from the file.
200
238
  const effectiveExt = (!isNativeExt && wasTransformedByPlugin) ? '.tsx' : fileExt;
@@ -138,13 +138,16 @@ async function processSourceFiles(config) {
138
138
  const userIgnore = Array.isArray(config.extract.ignore)
139
139
  ? config.extract.ignore
140
140
  : config.extract.ignore ? [config.extract.ignore] : [];
141
- return await glob(config.extract.input, {
141
+ const files = await glob(config.extract.input, {
142
142
  // Combine default ignore patterns with user-configured ones
143
143
  ignore: [...defaultIgnore, ...userIgnore],
144
144
  cwd: process.cwd(),
145
145
  // A directory named e.g. `abc.tsx` matches the input globs
146
146
  nodir: true,
147
147
  });
148
+ // glob's order is not stable across runs, and when two call sites give one key
149
+ // different defaults the file visited first wins, so sort for reproducible output (#296)
150
+ return files.sort();
148
151
  }
149
152
 
150
153
  export { findKeys };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.74.1",
3
+ "version": "1.74.2",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -56,37 +56,37 @@
56
56
  "@rollup/plugin-terser": "^1.0.0",
57
57
  "@rollup/plugin-typescript": "^12.3.0",
58
58
  "@types/inquirer": "^9.0.10",
59
- "@types/node": "^26.2.0",
60
- "@types/react": "^19.2.18",
61
- "@typescript-eslint/parser": "^8.67.0",
62
- "@vitest/coverage-v8": "^4.1.11",
59
+ "@types/node": "^26.6.3",
60
+ "@types/react": "^19.3.0",
61
+ "@typescript-eslint/parser": "^8.70.1",
62
+ "@vitest/coverage-v8": "^5.0.2",
63
63
  "eslint": "^9.39.5",
64
64
  "eslint-import-resolver-typescript": "^4.4.5",
65
65
  "eslint-plugin-import": "^2.32.0",
66
- "memfs": "^4.68.1",
66
+ "memfs": "^4.79.0",
67
67
  "neostandard": "^0.13.0",
68
- "react": "^19.2.8",
69
- "rollup": "^4.62.4",
68
+ "react": "^19.3.0",
69
+ "rollup": "^4.63.5",
70
70
  "typescript": "^6.0.3",
71
- "unplugin-swc": "^1.5.11",
72
- "vitest": "^4.1.11"
71
+ "unplugin-swc": "^2.0.0",
72
+ "vitest": "^5.0.2"
73
73
  },
74
74
  "dependencies": {
75
75
  "@croct/json5-parser": "^0.2.2",
76
- "@swc/core": "^1.16.1",
76
+ "@swc/core": "^1.16.2",
77
77
  "chokidar": "^5.0.0",
78
78
  "commander": "^15.0.0",
79
79
  "execa": "^10.0.1",
80
80
  "glob": "^13.0.6",
81
- "i18next": "^26.4.0",
82
- "i18next-resources-for-ts": "^2.1.0",
83
- "inquirer": "^14.1.0",
81
+ "i18next": "^26.4.2",
82
+ "i18next-resources-for-ts": "^2.1.1",
83
+ "inquirer": "^14.2.2",
84
84
  "jiti": "^2.7.0",
85
85
  "jsonc-parser": "^3.3.1",
86
- "magic-string": "^1.2.2",
86
+ "magic-string": "^1.4.2",
87
87
  "minimatch": "^10.2.6",
88
88
  "ora": "^9.4.1",
89
- "react-i18next": "^17.0.12",
90
- "yaml": "^2.9.0"
89
+ "react-i18next": "^17.0.15",
90
+ "yaml": "^2.9.1"
91
91
  }
92
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"extractor.d.ts","sourceRoot":"","sources":["../../../src/extractor/core/extractor.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,M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