Skip to content

Commit dda579d

Browse files
committed
fix: check resolved config file existence before loading
otherwise throw an error in all other cases
1 parent 4aac712 commit dda579d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/loader.ts

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promises as fsp } from 'fs'
1+
import { existsSync, promises as fsp } from 'fs'
22
import os from 'os'
33
import { resolve, extname, dirname } from 'pathe'
44
import createJiti from 'jiti'
@@ -176,18 +176,13 @@ async function resolveConfig (source: string, opts: LoadConfigOptions): Promise<
176176
const res: ResolvedConfig = { config: {}, cwd }
177177
try {
178178
res.configFile = jiti.resolve(resolve(cwd, source), { paths: [cwd] })
179-
res.config = jiti(res.configFile)
180-
if (typeof res.config === 'function') {
181-
res.config = await res.config()
182-
}
183-
} catch (err) {
184-
if (
185-
err.code === 'MODULE_NOT_FOUND' &&
186-
String(err).includes(opts.configFile)
187-
) {
188-
return res
189-
}
190-
throw err
179+
} catch (_err) { }
180+
if (!existsSync(res.configFile)) {
181+
return res
182+
}
183+
res.config = jiti(res.configFile)
184+
if (typeof res.config === 'function') {
185+
res.config = await res.config()
191186
}
192187
return res
193188
}

0 commit comments

Comments
 (0)