This commit is contained in:
2026-01-12 01:25:41 +08:00
parent 65ccab2177
commit 4c3be1a4a4
2 changed files with 7 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/use-config", "name": "@kevisual/use-config",
"version": "1.0.23", "version": "1.0.24",
"types": "dist/config.d.ts", "types": "dist/config.d.ts",
"scripts": { "scripts": {
"build": "npm run clean && code-builder build --dts", "build": "npm run clean && code-builder build --dts",

View File

@@ -132,7 +132,7 @@ export const getConfigFile = (opts?: ConfigOpts) => {
if (lastLast) return lastLastPath; if (lastLast) return lastLastPath;
return ''; return '';
}; };
type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions }; type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions, quite?: boolean };
/** /**
* 初始化配置, 不会把配置内容挂载到全局 * 初始化配置, 不会把配置内容挂载到全局
* @param opts 配置选项 * @param opts 配置选项
@@ -143,8 +143,9 @@ type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions };
* @returns 配置 * @returns 配置
*/ */
export const getConfig = (opts?: GetConfigOpts): Config => { export const getConfig = (opts?: GetConfigOpts): Config => {
let quiet = opts?.quite ?? true;
if (opts?.dotenvOpts) { if (opts?.dotenvOpts) {
const prased = dotenv.config({ quiet: true, ...opts.dotenvOpts }).parsed as Config; const prased = dotenv.config({ quiet, ...opts.dotenvOpts }).parsed as Config;
if (prased) { if (prased) {
return prased; return prased;
} else { } else {
@@ -153,7 +154,9 @@ export const getConfig = (opts?: GetConfigOpts): Config => {
} }
// 配置读取路径3级判断 // 配置读取路径3级判断
const filePath = getConfigFile(opts); const filePath = getConfigFile(opts);
if (!quiet) {
console.log('config pathname:', filePath); console.log('config pathname:', filePath);
}
if (!filePath) { if (!filePath) {
throw new Error('未找到配置文件'); throw new Error('未找到配置文件');
} }