fix tips
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/use-config",
|
||||
"version": "1.0.23",
|
||||
"version": "1.0.24",
|
||||
"types": "dist/config.d.ts",
|
||||
"scripts": {
|
||||
"build": "npm run clean && code-builder build --dts",
|
||||
|
||||
@@ -132,7 +132,7 @@ export const getConfigFile = (opts?: ConfigOpts) => {
|
||||
if (lastLast) return lastLastPath;
|
||||
return '';
|
||||
};
|
||||
type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions };
|
||||
type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions, quite?: boolean };
|
||||
/**
|
||||
* 初始化配置, 不会把配置内容挂载到全局
|
||||
* @param opts 配置选项
|
||||
@@ -143,8 +143,9 @@ type GetConfigOpts = ConfigOpts & { dotenvOpts?: dotenv.DotenvConfigOptions };
|
||||
* @returns 配置
|
||||
*/
|
||||
export const getConfig = (opts?: GetConfigOpts): Config => {
|
||||
let quiet = opts?.quite ?? true;
|
||||
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) {
|
||||
return prased;
|
||||
} else {
|
||||
@@ -153,7 +154,9 @@ export const getConfig = (opts?: GetConfigOpts): Config => {
|
||||
}
|
||||
// 配置读取路径,3级判断
|
||||
const filePath = getConfigFile(opts);
|
||||
if (!quiet) {
|
||||
console.log('config pathname:', filePath);
|
||||
}
|
||||
if (!filePath) {
|
||||
throw new Error('未找到配置文件');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user