i18next-cli 1.57.0 → 1.58.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/README.md CHANGED
@@ -143,6 +143,7 @@ npx i18next-cli extract [options]
143
143
  - `--sync-primary`: Sync primary language values with default values from code
144
144
  - `--sync-all`: Sync primary language values with default values from code AND clear synced keys in all other locales (implies `--sync-primary`)
145
145
  - `--trust-derived`: When used with `--sync-primary` or `--sync-all`, also trust defaults inferred from keys such as `t('Hello')` or `keyPrefix`-derived values. This keeps the default sync behavior strict unless you opt in.
146
+ - `--with-types`: After extraction (and on every re-run in `--watch` mode), regenerate the TypeScript definitions whenever translation files changed. Avoids the need to run `extract -w` and `types -w` as two separate processes.
146
147
  - `--quiet`: Suppress spinner and non-essential output (for CI or scripting)
147
148
 
148
149
  ### Spinner and Logger Output Control
@@ -194,6 +195,9 @@ npx i18next-cli extract --sync-all --trust-derived
194
195
 
195
196
  # Combine options for optimal development workflow
196
197
  npx i18next-cli extract --sync-primary --watch
198
+
199
+ # Keep TypeScript definitions in sync from a single process (no separate `types -w` needed)
200
+ npx i18next-cli extract --watch --with-types
197
201
  ```
198
202
 
199
203
  ### `status [locale]`
package/dist/cjs/cli.js CHANGED
@@ -32,7 +32,7 @@ const program = new commander.Command();
32
32
  program
33
33
  .name('i18next-cli')
34
34
  .description('A unified, high-performance i18next CLI.')
35
- .version('1.57.0'); // This string is replaced with the actual version at build time by rollup
35
+ .version('1.58.0'); // This string is replaced with the actual version at build time by rollup
36
36
  // new: global config override option
37
37
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
38
38
  program
@@ -44,6 +44,7 @@ program
44
44
  .option('--sync-primary', 'Sync primary language values with default values from code.')
45
45
  .option('--sync-all', 'Sync primary language values with default values from code AND clear synced keys in all other locales.')
46
46
  .option('--trust-derived', 'When used with --sync-primary or --sync-all, also trust defaults inferred from keys (including keyPrefix-derived values).')
47
+ .option('--with-types', 'After extraction, regenerate TypeScript definitions (runs the types generator) when translation files changed.')
47
48
  .option('-q, --quiet', 'Suppress spinner and output')
48
49
  .action(async (options) => {
49
50
  try {
@@ -72,6 +73,11 @@ program
72
73
  if (hasErrors && !options.watch) {
73
74
  process.exit(1);
74
75
  }
76
+ // Re-generate TypeScript definitions in the same process so consumers
77
+ // don't have to wire a second watcher (avoids the chokidar mid-write race).
78
+ if (options.withTypes && anyFileUpdated && !options.dryRun) {
79
+ await typesGenerator.runTypesGenerator(config$1, { quiet: !!options.quiet });
80
+ }
75
81
  return anyFileUpdated;
76
82
  };
77
83
  // Run the extractor once initially
@@ -138,7 +144,12 @@ program
138
144
  const expandedTypes = await expandGlobs(config$1.types?.input || []);
139
145
  const ignoredTypes = [...toArray(config$1.extract?.ignore)].filter(Boolean);
140
146
  const watchTypes = expandedTypes.filter(f => !ignoredTypes.some(g => minimatch.minimatch(f, g, { dot: true })));
141
- const watcher = chokidar.watch(watchTypes, { persistent: true });
147
+ // awaitWriteFinish avoids triggering mid-write when another process (e.g. `extract -w`)
148
+ // is rewriting the same translation files. See i18next/i18next-cli#257.
149
+ const watcher = chokidar.watch(watchTypes, {
150
+ persistent: true,
151
+ awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 },
152
+ });
142
153
  watcher.on('change', path => {
143
154
  console.log(`\nFile changed: ${path}`);
144
155
  run();
package/dist/esm/cli.js CHANGED
@@ -30,7 +30,7 @@ const program = new Command();
30
30
  program
31
31
  .name('i18next-cli')
32
32
  .description('A unified, high-performance i18next CLI.')
33
- .version('1.57.0'); // This string is replaced with the actual version at build time by rollup
33
+ .version('1.58.0'); // This string is replaced with the actual version at build time by rollup
34
34
  // new: global config override option
35
35
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
36
36
  program
@@ -42,6 +42,7 @@ program
42
42
  .option('--sync-primary', 'Sync primary language values with default values from code.')
43
43
  .option('--sync-all', 'Sync primary language values with default values from code AND clear synced keys in all other locales.')
44
44
  .option('--trust-derived', 'When used with --sync-primary or --sync-all, also trust defaults inferred from keys (including keyPrefix-derived values).')
45
+ .option('--with-types', 'After extraction, regenerate TypeScript definitions (runs the types generator) when translation files changed.')
45
46
  .option('-q, --quiet', 'Suppress spinner and output')
46
47
  .action(async (options) => {
47
48
  try {
@@ -70,6 +71,11 @@ program
70
71
  if (hasErrors && !options.watch) {
71
72
  process.exit(1);
72
73
  }
74
+ // Re-generate TypeScript definitions in the same process so consumers
75
+ // don't have to wire a second watcher (avoids the chokidar mid-write race).
76
+ if (options.withTypes && anyFileUpdated && !options.dryRun) {
77
+ await runTypesGenerator(config, { quiet: !!options.quiet });
78
+ }
73
79
  return anyFileUpdated;
74
80
  };
75
81
  // Run the extractor once initially
@@ -136,7 +142,12 @@ program
136
142
  const expandedTypes = await expandGlobs(config.types?.input || []);
137
143
  const ignoredTypes = [...toArray(config.extract?.ignore)].filter(Boolean);
138
144
  const watchTypes = expandedTypes.filter(f => !ignoredTypes.some(g => minimatch(f, g, { dot: true })));
139
- const watcher = chokidar.watch(watchTypes, { persistent: true });
145
+ // awaitWriteFinish avoids triggering mid-write when another process (e.g. `extract -w`)
146
+ // is rewriting the same translation files. See i18next/i18next-cli#257.
147
+ const watcher = chokidar.watch(watchTypes, {
148
+ persistent: true,
149
+ awaitWriteFinish: { stabilityThreshold: 200, pollInterval: 50 },
150
+ });
140
151
  watcher.on('change', path => {
141
152
  console.log(`\nFile changed: ${path}`);
142
153
  run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.57.0",
3
+ "version": "1.58.0",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAoBnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AAkZ7B,OAAO,EAAE,OAAO,EAAE,CAAA"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAoBnC,QAAA,MAAM,OAAO,SAAgB,CAAA;AA8Z7B,OAAO,EAAE,OAAO,EAAE,CAAA"}