Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid our devDependencies when requiring 'hubot' #138

Closed
wants to merge 1 commit into from

Conversation

lilyball
Copy link
Contributor

@lilyball lilyball commented Jan 6, 2015

Because we have hubot in our devDependencies, if these dependencies are
installed, require 'hubot' will pick up the local version of hubot instead
of the one that the robot is running from. This means that our emitted
TextMessages won't trigger any TextListeners installed by scripts (since
that uses instanceof).

Implement a workaround that avoids loading 'hubot' from our local node_modules
folder if possible. It first tries finding 'hubot' without our node_modules,
and if that fails, it walks up the module parent tree until it finds a module
outside our directory tree and tries again from that spot. This means it works
correctly even if hubot-slack is installed with npm link. It falls back to a
normal require 'hubot' if all else fails, which allows the test suite to
work.

This is an alternative to PR #137.

Because we have hubot in our devDependencies, if these dependencies are
installed, `require 'hubot'` will pick up the local version of hubot
instead of the one that the robot is running from. This means that our
emitted `TextMessage`s won't trigger any `TextListener`s installed by
scripts (since that uses `instanceof`).

Implement a workaround that avoids loading 'hubot' from our local
node_modules folder if possible. It first tries finding 'hubot' without
our node_modules, and if that fails, it walks up the module parent tree
until it finds a module outside our directory tree and tries again from
that spot. This means it works correctly even if hubot-slack is
installed with `npm link`. It falls back to a normal `require 'hubot'`
if all else fails, which allows the test suite to work.
@technicalpickles
Copy link
Contributor

What you are looking for is peerDependency. That will use the hubot dependency that is installed alongside hubot-slack in the project's node_modules

@lilyball
Copy link
Contributor Author

lilyball commented Jan 6, 2015

I think we need to adopt peerDependency, but that doesn't actually solve the problem. peerDependency is purely a npm thing, it doesn't affect node.js's resolve rules, and we still need the devDependency in order to run npm test.

@johnagan
Copy link

johnagan commented Jun 27, 2016

👋 @kballard Thank you for putting in so much effort on fixing this here and #137. @DEGoodmanWilson and I are still catching-up on these PRs, so excuse me if I missed some of the discussions, but I'm curious your thoughts on using

"devDependencies": {
  "hubot": "file:../hubot"
}

@UncannyBingo
Copy link

TBH, I'm not in love with this solution or #137 . But, believe you me, I feel your pain, acutely, having run into precisely these issues myself trying to build and test hubot-slack using npm link.

I find it curious that other Hubot adapters don't list Hubot as a devDependency, and am trying to figure out how that even works.

So, I'm meditating on this PR and #137 for a bit…please know we're paying attention and thinking on these things, and thank you for all the thought you've put into this issue as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants