Cannot use scoped npm packages as adapters
sorx00 opened this issue · comments
Hello!
I have created the adapter and published it in a private npm repository as a scoped package. But it turned out that scoped packages cannot be loaded by loadAdapter method. Because the prefix "hubot-" is added to the passed adapter name.
To use custom npm repository I've edited .npmrc file:
@mycompany:registry=http://repo.mycompany.domain/repository/
registry=https://registry.npmjs.org/
When I run Hubot with the name of adapter passed along with the scope name, it is distorting:
> bin/hubot --adapter @mycompany/adapter
...
ERROR Cannot load adapter @mycompany/adapter - Error: Cannot find module 'hubot-@mycompany/adapter'
I think we need to make some of these changes to the loadAdapter
method:
const path = Array.from(HUBOT_DEFAULT_ADAPTERS).indexOf(adapter) !== -1
? `${this.adapterPath}/${adapter}`
: `${adapter.split("/").reverse().slice(1).reverse().join("/")}/hubot-${adapter.split("/").slice(-1)}`
As a workaround I download the package manually and create a simlink for it in node_modules
:
ln -s @mycompany/hubot-adapter node_modules/hubot-adapter
It is possible to install package under a custom alias:
npm install <alias>@npm:<name>
So you could do something like:
npm install hubot-mycompany@npm:@mycompany/adapter
bin/hubot --adapter mycompany
Thanks a lot, @levenleven! Somehow I missed this opportunity.