Skip to content

Commit

Permalink
fix: #1703 loading adapter by name
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyguerra committed Nov 13, 2023
1 parent 0a8e9db commit e0ecb03
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/Robot.mjs
Expand Up @@ -491,7 +491,7 @@ class Robot {
return
}
this.logger.debug(`Loading adapter ${adapterPath ?? 'from npmjs:'} ${this.adapterName}`)
const ext = path.extname(adapterPath ?? '') ?? '.mjs'
const ext = path.extname(adapterPath ?? '')
try {
if (Array.from(HUBOT_DEFAULT_ADAPTERS).indexOf(this.adapterName) > -1) {
this.adapter = await this.requireAdapterFrom(path.resolve(path.join(__dirname, 'adapters', `${this.adapterName}.mjs`)))
Expand All @@ -500,16 +500,7 @@ class Robot {
} else if (['.mjs'].includes(ext)) {
this.adapter = await this.importAdapterFrom(path.resolve(adapterPath))
} else {
const adapterPathInCurrentWorkingDirectory = this.adapterName
try {
this.adapter = await this.requireAdapterFrom(adapterPathInCurrentWorkingDirectory)
} catch (err) {
if (err.name === 'SyntaxError') {
this.adapter = await this.importAdapterFrom(adapterPathInCurrentWorkingDirectory)
} else {
throw err
}
}
this.adapter = await this.importFromRepo(this.adapterName)
}
} catch (error) {
this.logger.error(`Cannot load adapter ${adapterPath ?? '[no path set]'} ${this.adapterName} - ${error}`)
Expand All @@ -526,6 +517,10 @@ class Robot {
return await (await import(forImport)).default.use(this)
}

async importFromRepo (adapterPath) {
return await (await import(adapterPath)).default.use(this)
}

// Public: Help Commands for Running Scripts.
//
// Returns an Array of help commands for running scripts.
Expand Down

0 comments on commit e0ecb03

Please sign in to comment.