i18next-cli 0.9.13 → 0.9.15
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/CHANGELOG.md +9 -1
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/config.js +1 -1
- package/dist/cjs/heuristic-config.js +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/config.js +1 -1
- package/dist/esm/heuristic-config.js +1 -1
- package/package.json +2 -1
- package/src/cli.ts +1 -1
- package/src/config.ts +64 -4
- package/src/heuristic-config.ts +9 -0
- package/types/config.d.ts +1 -1
- package/types/config.d.ts.map +1 -1
- package/types/heuristic-config.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,10 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [1.0.0](https://github.com/i18next/i18next-cli/compare/v0.9.
|
|
8
|
+
## [1.0.0](https://github.com/i18next/i18next-cli/compare/v0.9.15...v1.0.0) - 2025-xx-yy
|
|
9
9
|
|
|
10
10
|
- not yet released
|
|
11
11
|
|
|
12
|
+
## [0.9.15](https://github.com/i18next/i18next-cli/compare/v0.9.14...v0.9.15) - 2025-09-28
|
|
13
|
+
|
|
14
|
+
- **Config Loader:** Fixed a tricky crash that occurred when loading an `i18next.config.ts` file with dependencies that use certain module patterns (e.g., `zod`). This was resolved by disabling `jiti`'s CJS/ESM interoperability layer to ensure modules are imported reliably. [#8](https://github.com/i18next/i18next-cli/issues/8)
|
|
15
|
+
|
|
16
|
+
## [0.9.14](https://github.com/i18next/i18next-cli/compare/v0.9.13...v0.9.14) - 2025-09-28
|
|
17
|
+
|
|
18
|
+
- **Config Loader:** Added support for TypeScript path aliases in the `i18next.config.ts` file. The tool now automatically finds and parses your project's `tsconfig.json` (searching upwards from the current directory), allowing you to use aliases like `@/...` to import shared settings or constants into your configuration. [#7](https://github.com/i18next/i18next-cli/issues/7)
|
|
19
|
+
|
|
12
20
|
## [0.9.13](https://github.com/i18next/i18next-cli/compare/v0.9.12...v0.9.13) - 2025-09-27
|
|
13
21
|
|
|
14
22
|
- **Linter & Extractor:** Fixed a parser crash that occurred when analyzing TypeScript files containing decorator syntax. Both the `lint` and `extract` commands will now correctly process files that use decorators. [#6](https://github.com/i18next/i18next-cli/issues/6)
|
package/dist/cjs/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var e=require("commander"),t=require("chokidar"),o=require("glob"),n=require("chalk"),i=require("./config.js"),a=require("./heuristic-config.js"),r=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var c=require("./types-generator.js"),s=require("./syncer.js"),l=require("./migrator.js"),u=require("./init.js"),d=require("./linter.js"),g=require("./status.js"),p=require("./locize.js");const f=new e.Command;f.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("0.9.
|
|
2
|
+
"use strict";var e=require("commander"),t=require("chokidar"),o=require("glob"),n=require("chalk"),i=require("./config.js"),a=require("./heuristic-config.js"),r=require("./extractor/core/extractor.js");require("node:path"),require("node:fs/promises"),require("jiti");var c=require("./types-generator.js"),s=require("./syncer.js"),l=require("./migrator.js"),u=require("./init.js"),d=require("./linter.js"),g=require("./status.js"),p=require("./locize.js");const f=new e.Command;f.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("0.9.15"),f.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").action(async e=>{const a=await i.ensureConfig(),c=async()=>{const t=await r.runExtractor(a);e.ci&&t&&(console.error(n.red.bold("\n[CI Mode] Error: Translation files were updated. Please commit the changes.")),console.log(n.yellow("💡 Tip: Tired of committing JSON files? locize syncs your team automatically => https://www.locize.com/docs/getting-started")),console.log(` Learn more: ${n.cyan("npx i18next-cli locize-sync")}`),process.exit(1))};if(await c(),e.watch){console.log("\nWatching for changes...");t.watch(await o.glob(a.extract.input),{ignored:/node_modules/,persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),c()})}}),f.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(e,t)=>{let o=await i.loadConfig();if(!o){console.log(n.blue("No config file found. Attempting to detect project structure..."));const e=await a.detectConfig();e||(console.error(n.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${n.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(n.green("Project structure detected successfully!")),o=e}await g.runStatus(o,{detail:e,namespace:t.namespace})}),f.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async e=>{const n=await i.ensureConfig(),a=()=>c.runTypesGenerator(n);if(await a(),e.watch){console.log("\nWatching for changes...");t.watch(await o.glob(n.types?.input||[]),{persistent:!0}).on("change",e=>{console.log(`\nFile changed: ${e}`),a()})}}),f.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const e=await i.ensureConfig();await s.runSyncer(e)}),f.command("migrate-config").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async()=>{await l.runMigrator()}),f.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(u.runInit),f.command("lint").description("Find potential issues like hardcoded strings in your codebase.").action(async()=>{let e=await i.loadConfig();if(!e){console.log(n.blue("No config file found. Attempting to detect project structure..."));const t=await a.detectConfig();t||(console.error(n.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${n.cyan("npx i1e-toolkit init")}`),process.exit(1)),console.log(n.green("Project structure detected successfully!")),e=t}await d.runLinter(e)}),f.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async e=>{const t=await i.ensureConfig();await p.runLocizeSync(t,e)}),f.command("locize-download").description("Download all translations from your locize project.").action(async e=>{const t=await i.ensureConfig();await p.runLocizeDownload(t,e)}),f.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async e=>{const t=await i.ensureConfig();await p.runLocizeMigrate(t,e)}),f.parse(process.argv);
|
package/dist/cjs/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("node:path"),r=require("node:url"),
|
|
1
|
+
"use strict";var e=require("node:path"),r=require("node:url"),t=require("node:fs/promises"),n=require("jiti"),o=require("jsonc-parser"),i=require("inquirer"),a=require("chalk"),c=require("./init.js"),s=require("./utils/logger.js");const u=["i18next.config.ts","i18next.config.js","i18next.config.mjs","i18next.config.cjs"];async function l(i=new s.ConsoleLogger){const a=await async function(){for(const r of u){const n=e.resolve(process.cwd(),r);try{return await t.access(n),n}catch{}}return null}();if(!a)return null;try{let c;if(a.endsWith(".ts")){const r=await async function(){try{const r=await async function(){let r=process.cwd();for(;;){const n=e.join(r,"tsconfig.json");try{return await t.access(n),n}catch{const t=e.dirname(r);if(t===r)return null;r=t}}}();if(!r)return{};const n=await t.readFile(r,"utf-8"),i=o.parse(n),a=i.compilerOptions?.paths,c=i.compilerOptions?.baseUrl||".";if(!a)return{};const s={};for(const[r,t]of Object.entries(a))if(Array.isArray(t)&&t.length>0){const n=r.replace("/*",""),o=e.resolve(process.cwd(),c,t[0].replace("/*",""));s[n]=o}return s}catch(e){return{}}}(),i=n.createJiti(process.cwd(),{alias:r,interopDefault:!1}),s=await i.import(a,{default:!0});c=s}else{const e=r.pathToFileURL(a).href,t=await import(`${e}?t=${Date.now()}`);c=t.default}return c?(c.extract||={},c.extract.primaryLanguage||=c.locales[0]||"en",c.extract.secondaryLanguages||=c.locales.filter(e=>e!==c.extract.primaryLanguage),c):(i.error(`Error: No default export found in ${a}`),null)}catch(e){return i.error(`Error loading configuration from ${a}`),i.error(e),null}}exports.defineConfig=function(e){return e},exports.ensureConfig=async function(e=new s.ConsoleLogger){let r=await l();if(r)return r;const{shouldInit:t}=await i.prompt([{type:"confirm",name:"shouldInit",message:a.yellow("Configuration file not found. Would you like to create one now?"),default:!0}]);if(t){if(await c.runInit(),e.info(a.green("Configuration created. Resuming command...")),r=await l(),r)return r;e.error(a.red("Error: Failed to load configuration after creation. Please try running the command again.")),process.exit(1)}else e.info("Operation cancelled. Please create a configuration file to proceed."),process.exit(0)},exports.loadConfig=l;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=require("glob"),e=require("node:fs/promises"),n=require("node:path");const o=["public/locales/dev/*.json","locales/dev/*.json","src/locales/dev/*.json","src/assets/locales/dev/*.json","app/i18n/locales/dev/*.json","src/i18n/locales/dev/*.json","public/locales/en/*.json","locales/en/*.json","src/locales/en/*.json","src/assets/locales/en/*.json","app/i18n/locales/en/*.json","src/i18n/locales/en/*.json","public/locales/en-*/*.json","locales/en-*/*.json","src/locales/en-*/*.json","src/assets/locales/en-*/*.json","app/i18n/locales/en-*/*.json","src/i18n/locales/en-*/*.json"];exports.detectConfig=async function(){for(const l of o){const o=await s.glob(l,{ignore:"node_modules/**"});if(o.length>0){const s=o[0],l=n.dirname(n.dirname(s)),t=n.extname(s);let a="json";".ts"===t?a="ts":".js"===t&&(a="js");try{let s=(await e.readdir(l)).filter(s=>/^(dev|[a-z]{2}(-[A-Z]{2})?)$/.test(s));if(s.length>0)return s.sort(),s.includes("dev")&&(s=["dev",...s.filter(s=>"dev"!==s)]),s.includes("en")&&(s=["en",...s.filter(s=>"en"!==s)]),{locales:s,extract:{input:["src/**/*.{js,jsx,ts,tsx}","app/**/*.{js,jsx,ts,tsx}","pages/**/*.{js,jsx,ts,tsx}","components/**/*.{js,jsx,ts,tsx}"],output:n.join(l,"{{language}}",`{{namespace}}${t}`),outputFormat:a,primaryLanguage:s.includes("en")?"en":s[0]}}}catch{continue}}}return null};
|
package/dist/esm/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as o}from"commander";import t from"chokidar";import{glob as e}from"glob";import i from"chalk";import{ensureConfig as n,loadConfig as a}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as r}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as s}from"./types-generator.js";import{runSyncer as l}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as p}from"./init.js";import{runLinter as d}from"./linter.js";import{runStatus as f}from"./status.js";import{runLocizeSync as g,runLocizeDownload as u,runLocizeMigrate as y}from"./locize.js";const w=new o;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("0.9.
|
|
2
|
+
import{Command as o}from"commander";import t from"chokidar";import{glob as e}from"glob";import i from"chalk";import{ensureConfig as n,loadConfig as a}from"./config.js";import{detectConfig as c}from"./heuristic-config.js";import{runExtractor as r}from"./extractor/core/extractor.js";import"node:path";import"node:fs/promises";import"jiti";import{runTypesGenerator as s}from"./types-generator.js";import{runSyncer as l}from"./syncer.js";import{runMigrator as m}from"./migrator.js";import{runInit as p}from"./init.js";import{runLinter as d}from"./linter.js";import{runStatus as f}from"./status.js";import{runLocizeSync as g,runLocizeDownload as u,runLocizeMigrate as y}from"./locize.js";const w=new o;w.name("i18next-cli").description("A unified, high-performance i18next CLI.").version("0.9.15"),w.command("extract").description("Extract translation keys from source files and update resource files.").option("-w, --watch","Watch for file changes and re-run the extractor.").option("--ci","Exit with a non-zero status code if any files are updated.").action(async o=>{const a=await n(),c=async()=>{const t=await r(a);o.ci&&t&&(console.error(i.red.bold("\n[CI Mode] Error: Translation files were updated. Please commit the changes.")),console.log(i.yellow("💡 Tip: Tired of committing JSON files? locize syncs your team automatically => https://www.locize.com/docs/getting-started")),console.log(` Learn more: ${i.cyan("npx i18next-cli locize-sync")}`),process.exit(1))};if(await c(),o.watch){console.log("\nWatching for changes...");t.watch(await e(a.extract.input),{ignored:/node_modules/,persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),c()})}}),w.command("status [locale]").description("Display translation status. Provide a locale for a detailed key-by-key view.").option("-n, --namespace <ns>","Filter the status report by a specific namespace").action(async(o,t)=>{let e=await a();if(!e){console.log(i.blue("No config file found. Attempting to detect project structure..."));const o=await c();o||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i18next-cli init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),e=o}await f(e,{detail:o,namespace:t.namespace})}),w.command("types").description("Generate TypeScript definitions from translation resource files.").option("-w, --watch","Watch for file changes and re-run the type generator.").action(async o=>{const i=await n(),a=()=>s(i);if(await a(),o.watch){console.log("\nWatching for changes...");t.watch(await e(i.types?.input||[]),{persistent:!0}).on("change",o=>{console.log(`\nFile changed: ${o}`),a()})}}),w.command("sync").description("Synchronize secondary language files with the primary language file.").action(async()=>{const o=await n();await l(o)}),w.command("migrate-config").description("Migrate a legacy i18next-parser.config.js to the new format.").action(async()=>{await m()}),w.command("init").description("Create a new i18next.config.ts/js file with an interactive setup wizard.").action(p),w.command("lint").description("Find potential issues like hardcoded strings in your codebase.").action(async()=>{let o=await a();if(!o){console.log(i.blue("No config file found. Attempting to detect project structure..."));const t=await c();t||(console.error(i.red("Could not automatically detect your project structure.")),console.log(`Please create a config file first by running: ${i.cyan("npx i1e-toolkit init")}`),process.exit(1)),console.log(i.green("Project structure detected successfully!")),o=t}await d(o)}),w.command("locize-sync").description("Synchronize local translations with your locize project.").option("--update-values","Update values of existing translations on locize.").option("--src-lng-only","Check for changes in source language only.").option("--compare-mtime","Compare modification times when syncing.").option("--dry-run","Run the command without making any changes.").action(async o=>{const t=await n();await g(t,o)}),w.command("locize-download").description("Download all translations from your locize project.").action(async o=>{const t=await n();await u(t,o)}),w.command("locize-migrate").description("Migrate local translation files to a new locize project.").action(async o=>{const t=await n();await y(t,o)}),w.parse(process.argv);
|
package/dist/esm/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{resolve as r}from"node:path";import{pathToFileURL as
|
|
1
|
+
import{resolve as r,join as t,dirname as o}from"node:path";import{pathToFileURL as n}from"node:url";import{access as e,readFile as i}from"node:fs/promises";import{createJiti as a}from"jiti";import{parse as c}from"jsonc-parser";import s from"inquirer";import f from"chalk";import{runInit as l}from"./init.js";import{ConsoleLogger as u}from"./utils/logger.js";const p=["i18next.config.ts","i18next.config.js","i18next.config.mjs","i18next.config.cjs"];function m(r){return r}async function d(s=new u){const f=await async function(){for(const t of p){const o=r(process.cwd(),t);try{return await e(o),o}catch{}}return null}();if(!f)return null;try{let l;if(f.endsWith(".ts")){const n=await async function(){try{const n=await async function(){let r=process.cwd();for(;;){const n=t(r,"tsconfig.json");try{return await e(n),n}catch{const t=o(r);if(t===r)return null;r=t}}}();if(!n)return{};const a=await i(n,"utf-8"),s=c(a),f=s.compilerOptions?.paths,l=s.compilerOptions?.baseUrl||".";if(!f)return{};const u={};for(const[t,o]of Object.entries(f))if(Array.isArray(o)&&o.length>0){const n=t.replace("/*",""),e=r(process.cwd(),l,o[0].replace("/*",""));u[n]=e}return u}catch(r){return{}}}(),s=a(process.cwd(),{alias:n,interopDefault:!1}),u=await s.import(f,{default:!0});l=u}else{const r=n(f).href,t=await import(`${r}?t=${Date.now()}`);l=t.default}return l?(l.extract||={},l.extract.primaryLanguage||=l.locales[0]||"en",l.extract.secondaryLanguages||=l.locales.filter(r=>r!==l.extract.primaryLanguage),l):(s.error(`Error: No default export found in ${f}`),null)}catch(r){return s.error(`Error loading configuration from ${f}`),s.error(r),null}}async function g(r=new u){let t=await d();if(t)return t;const{shouldInit:o}=await s.prompt([{type:"confirm",name:"shouldInit",message:f.yellow("Configuration file not found. Would you like to create one now?"),default:!0}]);if(o){if(await l(),r.info(f.green("Configuration created. Resuming command...")),t=await d(),t)return t;r.error(f.red("Error: Failed to load configuration after creation. Please try running the command again.")),process.exit(1)}else r.info("Operation cancelled. Please create a configuration file to proceed."),process.exit(0)}export{m as defineConfig,g as ensureConfig,d as loadConfig};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{glob as s}from"glob";import{readdir as e}from"node:fs/promises";import{dirname as n,extname as o,join as
|
|
1
|
+
import{glob as s}from"glob";import{readdir as e}from"node:fs/promises";import{dirname as n,extname as o,join as l}from"node:path";const t=["public/locales/dev/*.json","locales/dev/*.json","src/locales/dev/*.json","src/assets/locales/dev/*.json","app/i18n/locales/dev/*.json","src/i18n/locales/dev/*.json","public/locales/en/*.json","locales/en/*.json","src/locales/en/*.json","src/assets/locales/en/*.json","app/i18n/locales/en/*.json","src/i18n/locales/en/*.json","public/locales/en-*/*.json","locales/en-*/*.json","src/locales/en-*/*.json","src/assets/locales/en-*/*.json","app/i18n/locales/en-*/*.json","src/i18n/locales/en-*/*.json"];async function c(){for(const c of t){const t=await s(c,{ignore:"node_modules/**"});if(t.length>0){const s=t[0],c=n(n(s)),a=o(s);let r="json";".ts"===a?r="ts":".js"===a&&(r="js");try{let s=(await e(c)).filter(s=>/^(dev|[a-z]{2}(-[A-Z]{2})?)$/.test(s));if(s.length>0)return s.sort(),s.includes("dev")&&(s=["dev",...s.filter(s=>"dev"!==s)]),s.includes("en")&&(s=["en",...s.filter(s=>"en"!==s)]),{locales:s,extract:{input:["src/**/*.{js,jsx,ts,tsx}","app/**/*.{js,jsx,ts,tsx}","pages/**/*.{js,jsx,ts,tsx}","components/**/*.{js,jsx,ts,tsx}"],output:l(c,"{{language}}",`{{namespace}}${a}`),outputFormat:r,primaryLanguage:s.includes("en")?"en":s[0]}}}catch{continue}}}return null}export{c as detectConfig};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "i18next-cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.15",
|
|
4
4
|
"description": "A unified, high-performance i18next CLI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"i18next-resources-for-ts": "1.7.4",
|
|
76
76
|
"inquirer": "12.9.6",
|
|
77
77
|
"jiti": "2.6.0",
|
|
78
|
+
"jsonc-parser": "3.3.1",
|
|
78
79
|
"ora": "9.0.0",
|
|
79
80
|
"swc-walk": "1.0.0"
|
|
80
81
|
}
|
package/src/cli.ts
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { resolve } from 'node:path'
|
|
1
|
+
import { resolve, join, dirname } from 'node:path'
|
|
2
2
|
import { pathToFileURL } from 'node:url'
|
|
3
|
-
import { access } from 'node:fs/promises'
|
|
3
|
+
import { access, readFile } from 'node:fs/promises'
|
|
4
4
|
import { createJiti } from 'jiti'
|
|
5
|
+
import { parse } from 'jsonc-parser'
|
|
5
6
|
import inquirer from 'inquirer'
|
|
6
7
|
import chalk from 'chalk'
|
|
7
8
|
import type { I18nextToolkitConfig, Logger } from './types'
|
|
@@ -92,7 +93,12 @@ export async function loadConfig (logger: Logger = new ConsoleLogger()): Promise
|
|
|
92
93
|
|
|
93
94
|
// Use jiti for TypeScript files, native import for JavaScript
|
|
94
95
|
if (configPath.endsWith('.ts')) {
|
|
95
|
-
const
|
|
96
|
+
const aliases = await getTsConfigAliases()
|
|
97
|
+
const jiti = createJiti(process.cwd(), {
|
|
98
|
+
alias: aliases,
|
|
99
|
+
interopDefault: false,
|
|
100
|
+
})
|
|
101
|
+
|
|
96
102
|
const configModule = await jiti.import(configPath, { default: true })
|
|
97
103
|
config = configModule
|
|
98
104
|
} else {
|
|
@@ -120,7 +126,7 @@ export async function loadConfig (logger: Logger = new ConsoleLogger()): Promise
|
|
|
120
126
|
}
|
|
121
127
|
|
|
122
128
|
/**
|
|
123
|
-
*
|
|
129
|
+
* Ensures a configuration exists, prompting the user to create one if necessary.
|
|
124
130
|
* This function is a wrapper around loadConfig that provides an interactive fallback.
|
|
125
131
|
*
|
|
126
132
|
* @returns A promise that resolves to a valid configuration object.
|
|
@@ -157,3 +163,57 @@ export async function ensureConfig (logger: Logger = new ConsoleLogger()): Promi
|
|
|
157
163
|
process.exit(0)
|
|
158
164
|
}
|
|
159
165
|
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Searches upwards from the current directory to find the tsconfig.json file.
|
|
169
|
+
* @returns The full path to the tsconfig.json file, or null if not found.
|
|
170
|
+
*/
|
|
171
|
+
async function findTsConfigFile (): Promise<string | null> {
|
|
172
|
+
let currentDir = process.cwd()
|
|
173
|
+
while (true) {
|
|
174
|
+
const tsConfigPath = join(currentDir, 'tsconfig.json')
|
|
175
|
+
try {
|
|
176
|
+
await access(tsConfigPath)
|
|
177
|
+
return tsConfigPath
|
|
178
|
+
} catch {
|
|
179
|
+
// File not found, move to parent directory
|
|
180
|
+
const parentDir = dirname(currentDir)
|
|
181
|
+
if (parentDir === currentDir) {
|
|
182
|
+
// Reached the root of the file system
|
|
183
|
+
return null
|
|
184
|
+
}
|
|
185
|
+
currentDir = parentDir
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Parses the project's tsconfig.json to extract path aliases for jiti.
|
|
192
|
+
* @returns A record of aliases for jiti's configuration.
|
|
193
|
+
*/
|
|
194
|
+
async function getTsConfigAliases (): Promise<Record<string, string>> {
|
|
195
|
+
try {
|
|
196
|
+
const tsConfigPath = await findTsConfigFile()
|
|
197
|
+
if (!tsConfigPath) return {}
|
|
198
|
+
|
|
199
|
+
const tsConfigStr = await readFile(tsConfigPath, 'utf-8')
|
|
200
|
+
const tsConfig = parse(tsConfigStr)
|
|
201
|
+
const paths = tsConfig.compilerOptions?.paths
|
|
202
|
+
const baseUrl = tsConfig.compilerOptions?.baseUrl || '.'
|
|
203
|
+
if (!paths) return {}
|
|
204
|
+
|
|
205
|
+
const aliases: Record<string, string> = {}
|
|
206
|
+
for (const [alias, aliasPaths] of Object.entries(paths as Record<string, string[]>)) {
|
|
207
|
+
if (Array.isArray(aliasPaths) && aliasPaths.length > 0) {
|
|
208
|
+
// Convert "@/*": ["./src/*"] to "@": "./src"
|
|
209
|
+
const key = alias.replace('/*', '')
|
|
210
|
+
const value = resolve(process.cwd(), baseUrl, aliasPaths[0].replace('/*', ''))
|
|
211
|
+
aliases[key] = value
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return aliases
|
|
215
|
+
} catch (e) {
|
|
216
|
+
// Return empty if tsconfig doesn't exist or fails to parse
|
|
217
|
+
return {}
|
|
218
|
+
}
|
|
219
|
+
}
|
package/src/heuristic-config.ts
CHANGED
|
@@ -10,12 +10,21 @@ const HEURISTIC_PATTERNS = [
|
|
|
10
10
|
'src/locales/dev/*.json',
|
|
11
11
|
'src/assets/locales/dev/*.json',
|
|
12
12
|
'app/i18n/locales/dev/*.json',
|
|
13
|
+
'src/i18n/locales/dev/*.json',
|
|
13
14
|
|
|
14
15
|
'public/locales/en/*.json',
|
|
15
16
|
'locales/en/*.json',
|
|
16
17
|
'src/locales/en/*.json',
|
|
17
18
|
'src/assets/locales/en/*.json',
|
|
18
19
|
'app/i18n/locales/en/*.json',
|
|
20
|
+
'src/i18n/locales/en/*.json',
|
|
21
|
+
|
|
22
|
+
'public/locales/en-*/*.json',
|
|
23
|
+
'locales/en-*/*.json',
|
|
24
|
+
'src/locales/en-*/*.json',
|
|
25
|
+
'src/assets/locales/en-*/*.json',
|
|
26
|
+
'app/i18n/locales/en-*/*.json',
|
|
27
|
+
'src/i18n/locales/en-*/*.json',
|
|
19
28
|
]
|
|
20
29
|
|
|
21
30
|
/**
|
package/types/config.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare function defineConfig(config: I18nextToolkitConfig): I18nextToolk
|
|
|
40
40
|
*/
|
|
41
41
|
export declare function loadConfig(logger?: Logger): Promise<I18nextToolkitConfig | null>;
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Ensures a configuration exists, prompting the user to create one if necessary.
|
|
44
44
|
* This function is a wrapper around loadConfig that provides an interactive fallback.
|
|
45
45
|
*
|
|
46
46
|
* @returns A promise that resolves to a valid configuration object.
|
package/types/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAc3D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAE,MAAM,EAAE,oBAAoB,GAAG,oBAAoB,CAEhF;AAqBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,UAAU,CAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CA2C5G;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAAE,MAAM,GAAE,MAA4B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8BvG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"heuristic-config.d.ts","sourceRoot":"","sources":["../src/heuristic-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"heuristic-config.d.ts","sourceRoot":"","sources":["../src/heuristic-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AA0BnD;;;;;;GAMG;AACH,wBAAsB,YAAY,IAAK,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAC,CAuDnF"}
|