Skip to content

Commit

Permalink
feat(cli): optimize ecosystem module resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 23, 2020
1 parent 533f4de commit ed505b1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/koishi-cli/src/worker.ts
Expand Up @@ -28,7 +28,7 @@ const cwd = process.cwd()
function loadEcosystem (type: string, name: string) {
const modules = [resolve(cwd, name)]
const prefix = `koishi-${type}-`
if (name.includes(prefix)) {
if (name.includes(prefix) || name.startsWith('.')) {
modules.unshift(name)
} else {
const index = name.lastIndexOf('/')
Expand All @@ -37,7 +37,11 @@ function loadEcosystem (type: string, name: string) {
for (const name of modules) {
try {
return require(name)
} catch {}
} catch (error) {
if (error.code !== 'MODULE_NOT_FOUND') {
throw error
}
}
}
throw new Error(`cannot resolve ${type} ${name}`)
}
Expand Down

0 comments on commit ed505b1

Please sign in to comment.