Skip to content

Commit

Permalink
fix: check resolved config file existence before loading
Browse files Browse the repository at this point in the history
otherwise throw an error in all other cases
  • Loading branch information
pi0 committed Apr 20, 2022
1 parent 4aac712 commit dda579d
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/loader.ts
@@ -1,4 +1,4 @@
import { promises as fsp } from 'fs'
import { existsSync, promises as fsp } from 'fs'
import os from 'os'
import { resolve, extname, dirname } from 'pathe'
import createJiti from 'jiti'
Expand Down Expand Up @@ -176,18 +176,13 @@ async function resolveConfig (source: string, opts: LoadConfigOptions): Promise<
const res: ResolvedConfig = { config: {}, cwd }
try {
res.configFile = jiti.resolve(resolve(cwd, source), { paths: [cwd] })
res.config = jiti(res.configFile)
if (typeof res.config === 'function') {
res.config = await res.config()
}
} catch (err) {
if (
err.code === 'MODULE_NOT_FOUND' &&
String(err).includes(opts.configFile)
) {
return res
}
throw err
} catch (_err) { }
if (!existsSync(res.configFile)) {
return res
}
res.config = jiti(res.configFile)
if (typeof res.config === 'function') {
res.config = await res.config()
}
return res
}

0 comments on commit dda579d

Please sign in to comment.