Amazebot / bbot

An adaptable conversation engine for building bespoke bots.
MIT License
55 stars 2 forks source link

Resolver not finding the (rocketchat) adapter #112

Open madskaddie opened 5 years ago

madskaddie commented 5 years ago

Context: I''m trying to use the bbot in a package of a "mono-repo" with lerna + yarn Problem: The adapter is not found

Require stack:
-  /.../js/node_modules/bbot/dist/lib/adapter.js
-  /.../js/node_modules/bbot/dist/index.js
- /.../js/packages/workshoper-bot/lib/workshoper-bot.js

I have debugged a bit and spotted a problem in the resolving mechanism:

resolver.paths values:

// resolver.paths ->
[
  'src',
  'dist',
  '/.../js/packages/workshoper-bot',
  '/.../js/packages/workshoper-bot/node_modules/bbot/dist',
  '/.../js/packages/workshoper-bot/lib/node_modules',
  '/.../js/packages/workshoper-bot/node_modules',
  '/.../js/src/js/packages/node_modules',
  '/.../js/node_modules',
  ...
]

bbot/dist is only in the 4th entry and wrong for my setup. For my setup to work, i should be '/.../js/node_modules/bb/dist', since I'm sharing the node_modules directory in the lerna (root) directory I've changed the dist/lib/adapter.js to test and it worked as I expected


    if (require.main)
        resolver.paths = resolver.paths.concat(...require.main.paths.map(x=>x+'/bbot/dist')); //Added map here
    try {
        adapterPath = require.resolve(adapterPath, resolver);
        return require(adapterPath).use(bot);
    }
    catch (err) {
        bot.logger.error(`[adapter] loading failed: ${err.message}`);
        throw err;
    }