Skip to content

Commit e0ecb03

Browse files
committed
fix: #1703 loading adapter by name
1 parent 0a8e9db commit e0ecb03

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/Robot.mjs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ class Robot {
491491
return
492492
}
493493
this.logger.debug(`Loading adapter ${adapterPath ?? 'from npmjs:'} ${this.adapterName}`)
494-
const ext = path.extname(adapterPath ?? '') ?? '.mjs'
494+
const ext = path.extname(adapterPath ?? '')
495495
try {
496496
if (Array.from(HUBOT_DEFAULT_ADAPTERS).indexOf(this.adapterName) > -1) {
497497
this.adapter = await this.requireAdapterFrom(path.resolve(path.join(__dirname, 'adapters', `${this.adapterName}.mjs`)))
@@ -500,16 +500,7 @@ class Robot {
500500
} else if (['.mjs'].includes(ext)) {
501501
this.adapter = await this.importAdapterFrom(path.resolve(adapterPath))
502502
} else {
503-
const adapterPathInCurrentWorkingDirectory = this.adapterName
504-
try {
505-
this.adapter = await this.requireAdapterFrom(adapterPathInCurrentWorkingDirectory)
506-
} catch (err) {
507-
if (err.name === 'SyntaxError') {
508-
this.adapter = await this.importAdapterFrom(adapterPathInCurrentWorkingDirectory)
509-
} else {
510-
throw err
511-
}
512-
}
503+
this.adapter = await this.importFromRepo(this.adapterName)
513504
}
514505
} catch (error) {
515506
this.logger.error(`Cannot load adapter ${adapterPath ?? '[no path set]'} ${this.adapterName} - ${error}`)
@@ -526,6 +517,10 @@ class Robot {
526517
return await (await import(forImport)).default.use(this)
527518
}
528519

520+
async importFromRepo (adapterPath) {
521+
return await (await import(adapterPath)).default.use(this)
522+
}
523+
529524
// Public: Help Commands for Running Scripts.
530525
//
531526
// Returns an Array of help commands for running scripts.

0 commit comments

Comments
 (0)