diff --git a/package.json b/package.json index 4ed79ce..3e5d1f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/use-config", - "version": "1.0.13", + "version": "1.0.15", "types": "dist/config.d.ts", "scripts": { "build": "npm run clean && tsup", diff --git a/src/env.ts b/src/env.ts index ab3db51..d23ceae 100644 --- a/src/env.ts +++ b/src/env.ts @@ -204,13 +204,26 @@ export const readJsonConfig = (opts?: Omit) => { return {}; } }; + +type ResolvePathOptions = { + meta?: { + url: string; + }; + cwd?: string; +}; /** * 获取相对当前路径的path * @param releactivePath * @returns */ -export const resolvePath = (releactivePath: string = '') => { - const __filename = fileURLToPath(import.meta.url); - const __dirname = path.dirname(__filename); - return path.resolve(__dirname, releactivePath); +export const resolvePath = (releactivePath: string = '', opts?: ResolvePathOptions) => { + if (opts?.meta) { + const __filename = fileURLToPath(opts.meta.url); + const __dirname = path.dirname(__filename); + return path.resolve(__dirname, releactivePath); + } else if (opts?.cwd) { + return path.resolve(opts.cwd, releactivePath); + } else { + return path.resolve(getDirname(), releactivePath); + } };