i18next-cli 1.47.9 → 1.47.10

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
@@ -249,7 +249,7 @@ npx i18next-cli lint
249
249
 
250
250
  ### `instrument`
251
251
 
252
- Scans your source code for hardcoded user-facing strings and instruments them with i18next translation calls. This is useful for adding i18next instrumentation to an existing codebase that wasn't built with internationalization in mind.
252
+ Scans your source code for hardcoded user-facing strings and instruments them with i18next translation calls. This is useful for adding i18next instrumentation to an existing codebase that wasn't built with internationalization in mind. You can see this in action in [this video](https://youtu.be/aWZnZXwGg34) or in [this blog post](https://www.locize.com/blog/i18next-cli-instrument).
253
253
 
254
254
  > **⚠️ First-Step Tool:** The `instrument` command uses heuristic-based detection and is designed as a **first pass** to identify and suggest transformation candidates. It will **not catch 100% of cases**, and you should expect both false positives and false negatives. Always review the suggested transformations carefully before committing them to your codebase. Think of it as an intelligent code assistant, not an automated compiler.
255
255
 
package/dist/cjs/cli.js CHANGED
@@ -31,7 +31,7 @@ const program = new commander.Command();
31
31
  program
32
32
  .name('i18next-cli')
33
33
  .description('A unified, high-performance i18next CLI.')
34
- .version('1.47.9'); // This string is replaced with the actual version at build time by rollup
34
+ .version('1.47.10'); // This string is replaced with the actual version at build time by rollup
35
35
  // new: global config override option
36
36
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
37
37
  program
@@ -7,29 +7,37 @@ var inquirer = require('inquirer');
7
7
  var node_path = require('node:path');
8
8
 
9
9
  /**
10
- * Verifies that the locize-cli tool is installed and accessible.
10
+ * Resolves the locize-cli executable to use.
11
11
  *
12
- * @throws Exits the process with error code 1 if locize-cli is not found
12
+ * Tries, in order:
13
+ * 1. A locally / globally installed `locize` binary
14
+ * 2. Falls back to `npx locize-cli` so it can be fetched on demand
13
15
  *
14
- * @example
15
- * ```typescript
16
- * await checkLocizeCliExists()
17
- * // Continues execution if locize-cli is available
18
- * // Otherwise exits with installation instructions
19
- * ```
16
+ * If neither works the process exits with an error.
17
+ *
18
+ * @returns An object with `cmd` (the executable) and `prefixArgs` (extra args
19
+ * to prepend before the locize sub-command, e.g. `['locize-cli']`
20
+ * when running through npx).
20
21
  */
21
- async function checkLocizeCliExists() {
22
+ async function resolveLocizeBin() {
23
+ // 1. Try a locally / globally installed binary
22
24
  try {
23
25
  await execa.execa('locize', ['--version']);
26
+ return { cmd: 'locize', prefixArgs: [] };
24
27
  }
25
- catch (error) {
26
- if (error.code === 'ENOENT') {
27
- console.error(node_util.styleText('red', 'Error: `locize-cli` command not found.'));
28
- console.log(node_util.styleText('yellow', 'Please install it globally to use the Locize integration:'));
29
- console.log(node_util.styleText('cyan', 'npm install -g locize-cli'));
30
- process.exit(1);
31
- }
28
+ catch {
29
+ // not found continue
30
+ }
31
+ // 2. Fall back to npx
32
+ try {
33
+ console.log(node_util.styleText('yellow', '`locize` command not found – trying npx...'));
34
+ await execa.execa('npx', ['locize-cli', '--version']);
35
+ return { cmd: 'npx', prefixArgs: ['locize-cli'] };
32
36
  }
37
+ catch {
38
+ // npx also failed
39
+ }
40
+ return null;
33
41
  }
34
42
  /**
35
43
  * Interactive setup wizard for configuring Locize credentials.
@@ -236,14 +244,23 @@ function buildArgs(command, config, cliOptions) {
236
244
  * ```
237
245
  */
238
246
  async function runLocizeCommand(command, config, cliOptions = {}) {
239
- await checkLocizeCliExists();
247
+ const resolved = await resolveLocizeBin();
248
+ if (!resolved) {
249
+ console.error(node_util.styleText('red', 'Error: `locize-cli` command not found.'));
250
+ console.log(node_util.styleText('yellow', 'Please install it to use the Locize integration:'));
251
+ console.log(node_util.styleText('cyan', ' npm install -g locize-cli'));
252
+ console.log(node_util.styleText('yellow', 'Or make sure npx is available so it can be fetched on demand.'));
253
+ process.exit(1);
254
+ return;
255
+ }
256
+ const { cmd, prefixArgs } = resolved;
240
257
  const spinner = ora(`Running 'locize ${command}'...\n`).start();
241
258
  let effectiveConfig = config;
242
259
  try {
243
260
  // 1. First attempt
244
- const initialArgs = buildArgs(command, effectiveConfig, cliOptions);
245
- console.log(node_util.styleText('cyan', `\nRunning 'locize ${maskArgs(initialArgs).join(' ')}'...`));
246
- const result = await execa.execa('locize', initialArgs, { stdio: 'pipe' });
261
+ const initialArgs = [...prefixArgs, ...buildArgs(command, effectiveConfig, cliOptions)];
262
+ console.log(node_util.styleText('cyan', `\nRunning 'locize ${maskArgs(initialArgs.slice(prefixArgs.length)).join(' ')}'...`));
263
+ const result = await execa.execa(cmd, initialArgs, { stdio: 'pipe' });
247
264
  spinner.succeed(node_util.styleText('green', `'locize ${command}' completed successfully.`));
248
265
  if (result?.stdout)
249
266
  console.log(result.stdout); // Print captured output on success
@@ -259,9 +276,9 @@ async function runLocizeCommand(command, config, cliOptions = {}) {
259
276
  spinner.start('Retrying with new credentials...');
260
277
  try {
261
278
  // 3. Retry attempt, rebuilding args with the NOW-UPDATED currentConfig object
262
- const retryArgs = buildArgs(command, effectiveConfig, cliOptions);
263
- console.log(node_util.styleText('cyan', `\nRunning 'locize ${maskArgs(retryArgs).join(' ')}'...`));
264
- const result = await execa.execa('locize', retryArgs, { stdio: 'pipe' });
279
+ const retryArgs = [...prefixArgs, ...buildArgs(command, effectiveConfig, cliOptions)];
280
+ console.log(node_util.styleText('cyan', `\nRunning 'locize ${maskArgs(retryArgs.slice(prefixArgs.length)).join(' ')}'...`));
281
+ const result = await execa.execa(cmd, retryArgs, { stdio: 'pipe' });
265
282
  spinner.succeed(node_util.styleText('green', 'Retry successful!'));
266
283
  if (result?.stdout)
267
284
  console.log(result.stdout);
package/dist/esm/cli.js CHANGED
@@ -29,7 +29,7 @@ const program = new Command();
29
29
  program
30
30
  .name('i18next-cli')
31
31
  .description('A unified, high-performance i18next CLI.')
32
- .version('1.47.9'); // This string is replaced with the actual version at build time by rollup
32
+ .version('1.47.10'); // This string is replaced with the actual version at build time by rollup
33
33
  // new: global config override option
34
34
  program.option('-c, --config <path>', 'Path to i18next-cli config file (overrides detection)');
35
35
  program
@@ -5,29 +5,37 @@ import inquirer from 'inquirer';
5
5
  import { sep, resolve } from 'node:path';
6
6
 
7
7
  /**
8
- * Verifies that the locize-cli tool is installed and accessible.
8
+ * Resolves the locize-cli executable to use.
9
9
  *
10
- * @throws Exits the process with error code 1 if locize-cli is not found
10
+ * Tries, in order:
11
+ * 1. A locally / globally installed `locize` binary
12
+ * 2. Falls back to `npx locize-cli` so it can be fetched on demand
11
13
  *
12
- * @example
13
- * ```typescript
14
- * await checkLocizeCliExists()
15
- * // Continues execution if locize-cli is available
16
- * // Otherwise exits with installation instructions
17
- * ```
14
+ * If neither works the process exits with an error.
15
+ *
16
+ * @returns An object with `cmd` (the executable) and `prefixArgs` (extra args
17
+ * to prepend before the locize sub-command, e.g. `['locize-cli']`
18
+ * when running through npx).
18
19
  */
19
- async function checkLocizeCliExists() {
20
+ async function resolveLocizeBin() {
21
+ // 1. Try a locally / globally installed binary
20
22
  try {
21
23
  await execa('locize', ['--version']);
24
+ return { cmd: 'locize', prefixArgs: [] };
22
25
  }
23
- catch (error) {
24
- if (error.code === 'ENOENT') {
25
- console.error(styleText('red', 'Error: `locize-cli` command not found.'));
26
- console.log(styleText('yellow', 'Please install it globally to use the Locize integration:'));
27
- console.log(styleText('cyan', 'npm install -g locize-cli'));
28
- process.exit(1);
29
- }
26
+ catch {
27
+ // not found continue
28
+ }
29
+ // 2. Fall back to npx
30
+ try {
31
+ console.log(styleText('yellow', '`locize` command not found – trying npx...'));
32
+ await execa('npx', ['locize-cli', '--version']);
33
+ return { cmd: 'npx', prefixArgs: ['locize-cli'] };
30
34
  }
35
+ catch {
36
+ // npx also failed
37
+ }
38
+ return null;
31
39
  }
32
40
  /**
33
41
  * Interactive setup wizard for configuring Locize credentials.
@@ -234,14 +242,23 @@ function buildArgs(command, config, cliOptions) {
234
242
  * ```
235
243
  */
236
244
  async function runLocizeCommand(command, config, cliOptions = {}) {
237
- await checkLocizeCliExists();
245
+ const resolved = await resolveLocizeBin();
246
+ if (!resolved) {
247
+ console.error(styleText('red', 'Error: `locize-cli` command not found.'));
248
+ console.log(styleText('yellow', 'Please install it to use the Locize integration:'));
249
+ console.log(styleText('cyan', ' npm install -g locize-cli'));
250
+ console.log(styleText('yellow', 'Or make sure npx is available so it can be fetched on demand.'));
251
+ process.exit(1);
252
+ return;
253
+ }
254
+ const { cmd, prefixArgs } = resolved;
238
255
  const spinner = ora(`Running 'locize ${command}'...\n`).start();
239
256
  let effectiveConfig = config;
240
257
  try {
241
258
  // 1. First attempt
242
- const initialArgs = buildArgs(command, effectiveConfig, cliOptions);
243
- console.log(styleText('cyan', `\nRunning 'locize ${maskArgs(initialArgs).join(' ')}'...`));
244
- const result = await execa('locize', initialArgs, { stdio: 'pipe' });
259
+ const initialArgs = [...prefixArgs, ...buildArgs(command, effectiveConfig, cliOptions)];
260
+ console.log(styleText('cyan', `\nRunning 'locize ${maskArgs(initialArgs.slice(prefixArgs.length)).join(' ')}'...`));
261
+ const result = await execa(cmd, initialArgs, { stdio: 'pipe' });
245
262
  spinner.succeed(styleText('green', `'locize ${command}' completed successfully.`));
246
263
  if (result?.stdout)
247
264
  console.log(result.stdout); // Print captured output on success
@@ -257,9 +274,9 @@ async function runLocizeCommand(command, config, cliOptions = {}) {
257
274
  spinner.start('Retrying with new credentials...');
258
275
  try {
259
276
  // 3. Retry attempt, rebuilding args with the NOW-UPDATED currentConfig object
260
- const retryArgs = buildArgs(command, effectiveConfig, cliOptions);
261
- console.log(styleText('cyan', `\nRunning 'locize ${maskArgs(retryArgs).join(' ')}'...`));
262
- const result = await execa('locize', retryArgs, { stdio: 'pipe' });
277
+ const retryArgs = [...prefixArgs, ...buildArgs(command, effectiveConfig, cliOptions)];
278
+ console.log(styleText('cyan', `\nRunning 'locize ${maskArgs(retryArgs.slice(prefixArgs.length)).join(' ')}'...`));
279
+ const result = await execa(cmd, retryArgs, { stdio: 'pipe' });
263
280
  spinner.succeed(styleText('green', 'Retry successful!'));
264
281
  if (result?.stdout)
265
282
  console.log(result.stdout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "i18next-cli",
3
- "version": "1.47.9",
3
+ "version": "1.47.10",
4
4
  "description": "A unified, high-performance i18next CLI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +1 @@
1
- {"version":3,"file":"locize.d.ts","sourceRoot":"","sources":["../src/locize.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AA8RnD,eAAO,MAAM,aAAa,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAiD,CAAA;AAC7H,eAAO,MAAM,iBAAiB,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAqD,CAAA;AACrI,eAAO,MAAM,gBAAgB,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAoD,CAAA"}
1
+ {"version":3,"file":"locize.d.ts","sourceRoot":"","sources":["../src/locize.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAgTnD,eAAO,MAAM,aAAa,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAiD,CAAA;AAC7H,eAAO,MAAM,iBAAiB,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAqD,CAAA;AACrI,eAAO,MAAM,gBAAgB,GAAI,QAAQ,oBAAoB,EAAE,aAAa,GAAG,kBAAoD,CAAA"}