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

resolve.getNpmPaths - nvm prefix #59

Closed
mklabs opened this issue May 1, 2016 · 6 comments
Closed

resolve.getNpmPaths - nvm prefix #59

mklabs opened this issue May 1, 2016 · 6 comments

Comments

@mklabs
Copy link
Contributor

mklabs commented May 1, 2016

Might be related to #52


I'm running into an issue when trying to load installed generators with env#getGeneratorsMeta(), and I think it's related to nvm and npm prefix being different than the defaults.

My test sample is something like:

var env = require('yeoman-environment').createEnv();
env.lookup((err) => {
  console.log(env.getGeneratorsMeta());
});

Looking at the getNpmPaths() method, I can see that $NODE_PATH is used when defined, and I can get the env lookup working with:

NODE_PATH="/home/user/.nvm/versions/nodes/v6.0.0/lib/node_modules" node test.js

My question is, would you agree on adding the result of npm prefix to the lookup paths automatically ?

env.lookup() is asynchronous, so we might be able to introduce a call to .exec('npm prefix -g') if you don't mind the performance penalty it might introduce.

Alternatively, if you don't want it to be the default behavior, would it be possible to define custom paths? something like:

// env.lookup([paths, ], cb);

env.lookup(['/home/user/.nvm/versions/node/v6.0.0/lib/node_modules'], function() {});

Either way, it would fix the lookup for nvm installed yeoman and generators. This doesn't apply when yeoman-environment is installed globally, yo works fine in this case.

@mklabs
Copy link
Contributor Author

mklabs commented May 1, 2016

$NVM_PATH can also be used if defined in environment variables, might avoid spawning npm to run npm prefix

@SBoudrias
Copy link
Member

Yeah, spawning a command is really, but reallllly SLOW. It's not a good option.

I'm okay with using $NVM_PATH

@mklabs
Copy link
Contributor Author

mklabs commented May 1, 2016

Great! I'll probably send you a PR with this update.

@mklabs
Copy link
Contributor Author

mklabs commented May 1, 2016

btw, really good job on extracting the environment in its own lib, very pleasant to work with and useful

@SBoudrias
Copy link
Member

Thanks!

Also, FWIW, issues might arise more often now that npm behavior is to flatten dependencies. Right now we're always loading {yeoman-environment root}/../../../.. as the global search path (yeoman-environment -> yo -> global root), but now that assumption might be wrong.

@mklabs
Copy link
Contributor Author

mklabs commented May 1, 2016

yep, I had some issues with yo npm linked, but using the NODE_PATH trick I was able to work around.

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

No branches or pull requests

2 participants