Using npm link to develop adapters #332

Closed
adamesque opened this Issue Aug 10, 2012 · 13 comments

Comments

Projects
None yet
9 participants

I'm working on an adapter, and would like to tell my copy of hubot to use my local development version of the adapter.

I've downloaded the hubot .zip & run npm install. bin/hubot works fine.
I can add the current stable npm-hosted version of my adapter to packages.json, and bin/hubot -a myadapter works great.

It seems like I should be able to use npm link to symlink my dev directory (currently identical to the npm version) into hubot, but when I do this and run bin/hubot -a myadapter, I get:

ERROR Cannot load adapter myadapter - Error: Cannot find module 'hubot'

I get the same results with the IRC adapter as well. Add to packages.json & npm install and everything's great. Set up an identical project and npm link a clone from GitHub, and it can't find hubot.

Should this work?

Contributor

iangreenleaf commented Aug 10, 2012

👍, I've run into this a couple times. And it doesn't work to npm install hubot in the adapter directory, because then the two TextMessage classes don't hit equality and so nothing gets through to Hubot.

The part that puzzles me is how the adapter arrangement (`require 'hubot' when hubot is the parent module) does not work when linked, but does work when the package is published. Seems like it should never work, or always work...

Owner

technicalpickles commented Sep 2, 2012

I've seen this too, while trying to test against a npm linkd hubot-scripts. That makes me think it's more npm-weirdness than anything else.

arbales commented Oct 16, 2012

👍 Not really sure how I'm supposed to go about developing adapters given this issue.

Owner

technicalpickles commented Dec 10, 2012

I took another look into this, and was able to reproduce it with hubot-irc and hubot-flowdocks. Steps to reproduce:

  • Download tarball from hubot.github.com
  • Update package.json's hubot to be "hubot": ">= 2.2.0"
  • Add `hubot-irc: ">= 0"
  • Confirm bin/hubot -a irc successfully loads (but fails when HUBOT_IRC things aren't defined)
  • git clone https://github.com/nandub/hubot-irc somewhere
  • npm link in that cloned repository
  • npm link hubot-irc in the new hubot directory
  • confirm bin/hubot -a irc fails not finding hubot

hubot doesn't really use npm directly aside from the dependency management. So, that makes me think it's a more likely a bug with npm than hubot. Not that that helps much, because it means developing hubot adapters is still hard :(

For a short term thing, the only idea that comes to mind would be to fork hubot, and develop it a default adapter (remember to update HUBOT_DEFAULT_ADAPTERS.

Owner

technicalpickles commented Dec 10, 2012

Actually, here's an idea. I'm cc'ing a few hubot adapter maintainers for input.

For the newly cc'd folks… it looks like npm link with a hubot adapter will cause hubot to not be able to require('hubot') in the adapter source, thus making it extremely difficult to develop an adapter. Have any of y'all seen this or found a better way of developing your adapter?

/cc @atmos for hubot-gtalk, @anttipitkanen for hubot-flowdock, @jgable for hubot-irc, @powdahound for hubot-hipchat

jgable commented Dec 10, 2012

I've seen this issue a while back, but didn't comment before.

Here is how I set up my environment for development of an adapter:

  • Download and Extract Hubot 2.3 from the Hubot Downloads page into a directory (e.g. Hubot2)
  • Clone the hubot-irc code from your fork (or straight from https://github.com/nandub/hubot-irc) into a new directory outside of Hubot2, by default it is hubot-irc.
  • Run npm install ../path/to/hubot-irc --save in the extracted Hubot2 directory to add your cloned hubot-irc adapter to your dependencies.
  • Install hubot core dependencies with npm install from the Hubot2 directory
  • Set your environment variables like: (Windows Users substitute set for export)
    • export HUBOT_IRC_NICK="hubot-new"
    • export HUBOT_IRC_ROOMS="#hubot-irc"
    • export HUBOT_IRC_SERVER="irc.freenode.net"
  • Run hubot with bin/hubot -a irc

This way, you can have your adapters repo with your most recent source, and the hubot harness for you to run it with. If you need to update your source, you can do the npm rm hubot-irc and npm install ../path/to/hubot-irc dance again after updating.

@jgable 's approach is pretty much what we use for hubot-flowdock. Occasionally I just set the adapter dependency to point to the Github master (or some development branch) of the adapter.

I wasn't aware npm install could be used on local paths so I was just manually dropping symlinks in my node_modules folders to point to local working copies. Works OK, but always feels dirty.

tombell closed this Jan 10, 2013

arbales commented Jan 11, 2013

Was this closed because the issue was resolved? npm link seems like the right way too approach building adapters, resorting to work around makes me sad emoji cat. (😿)

Contributor

tombell commented Jan 11, 2013

When I tested external adapters when I originally broke them out, I basically just npm install ../some/local/path for testing.

This comment #332 (comment) outlines the exact process I decided on when I broke them out.

Contributor

iangreenleaf commented Jan 11, 2013

I just tested this and it looks like it's resolved in hubot 2.4. I'm very curious about what changed, though.

Contributor

tombell commented Jan 11, 2013

Maybe an update to npm?

sonnyp commented Apr 2, 2014

I tried using symlink/npm link, I get the following error
[Wed Apr 02 2014 20:16:07 GMT+0200 (CEST)] ERROR Cannot load adapter upptalk - Error: Cannot find module 'hubot'

Moving my adapter folder to my hubot node_modules/ folder works though.

hubot 2.7.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment