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
fix node_modules problem #1
Conversation
|
||
|
||
// Now try to require the adapter from userland dependencies (node_modules of the sails app). | ||
var adapter; | ||
try { | ||
adapter = require(adapterPackagePath); | ||
adapter = require(adapterPackageName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that this would prevent users from running npm install sails-mysql
to install the mysql adapter in their apps-- but maybe I'm missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you can install whatever you wish and it will load just fine. What's the difference between: require('package')
and require('./some/folder/node_modules/package')
.
If package
is installed on project root e.g. ./
, ./some/folder/app.js
will go up and will find the package
so we're good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stanislavromanov If I'm understanding you correctly, there's still a problem (at least with the versions of Node and NPM I've used in the past). If code in sails-hook-orm
(a dependency of sails
, which is a dependency of your project) attempts to require('sails-mysql')
, then Node will look at the dependencies of sails-hook-orm
-- in its node_modules folder. And like you're saying, it will continue to look at higher and higher level directories that have a package.json, attempting to find the dependency. But for some reason or another, this just doesn't work, at least not on all versions of Node/NPM that we support (I started off trying to do it that way, and only changed it after it didn't work for some developers. I had to do the same thing for generators, view engines, hooks, socket.io adapters, and connect session adapters.)
All that said, it may be that this is fixed now on all versions of NPM/Node in common use today (i.e. Node >=0.10 and NPM >= 2.0). If that's the case, then we just need some more test cases that verify that this works (Travis can take care of testing on multiple versions of Node-- I'll make sure I push up a travis.yml file for this repo). I'd love to be able to simplify this code throughout the framework!
Okey, I get it that it will not work on old versions, however: Wouldn't it be wise to just drop support for 0.* versions of node and start supporting LTS 4.4.7? |
@stanislavromanov as much as I'd love to be able to do that, there are a lot of folks still using Node 0.10. I think the right thing to do here might be just to support and document a different default approach. I.e. instead of providing the string package name, providing the actual already-required reference. We'd still need to support the existing behavior, but anywhere throughout Sails we support providing a package name, we could change it to allow providing the already-required package itself. (The one exception will still be generators, where that isn't really an option-- but it should work everywhere else, and we already support that approach in some places) |
Well it's fine by me because I already cloned it and using my fork. The question I want to ask tho: If people do not bother to update their Node from 0.1 to stable LTS 4.x why are you so sure they would update their Sails.js? :) |
@stanislavromanov As I was experimenting with this, I was just reminded of another time where this matters: when you're developing using |
@stanislavromanov One last important consideration is which installed module this actually grabs. The only sure-fire way to use require this way and still know what version you're getting is to include that version as a dependency (and obviously sails-hook-orm can't include every Sails adapter on NPM as a dependency.) I think the right solution here is for sails-hook-orm to expect us to pass in the already-required adapter in our config (and also to maintain backwards compatibility for the current approach). |
Hi guys, |
@cubico Gotcha. OK, so thankfully this is possible now (whereas it wasn't a few months ago), and it's one of the main reasons I pulled out Here's how to do it:
Then, if you lift your app, Sails should attempt to load your fork of the orm hook instead of the built-in version (because sails-hook-orm has Hope that helps! |
+1. Thanks @mikermcneil ! I found a easy way in order to use the correct version of waterline without the waterline dependencies in sails-hook-orm module ( but I must remember not run npm again :D)
... and seems it works for me. May be this is a PR and the solution is delete the dependency of waterline from package.json of this module. It is possible? Some "official" tests about this? |
@cubico glad you got it sorted! The issue we're stuck with is still npm 2 vs. npm 3. Since waterline is being required from sails-hook-orm, the semver range indicated in sails-hook-orm's package.json will be used to find it. And while we might be able to use some fanciness to make this work (manually resolving dir paths), it always ends up being npm-version dependent (since where your dependencies are installed varies). So far, the cleanest way to allow for this without causing cross-platform issues has been to allow installing different hooks.
|
@cubico @stanislavromanov btw I recently was working on this in sails-generate, and here's what I did there: https://github.com/balderdashy/sails-generate/blob/ee251bdceaa2d918e2db40a5476723f5e4100032/lib/load-generator-def.js Also, for some more background on the NPM version discrepancies, see https://github.com/balderdashy/sails-generate/blob/ee251bdceaa2d918e2db40a5476723f5e4100032/lib/core-generators/new/after.js#L80-L255 |
Fixes part of balderdashy/sails#3732