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

Fixing global add in linux root folder #1029 #1344

Merged
merged 6 commits into from
Oct 31, 2016
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* @flow */

const userHome = require('user-home');
const path = require('path');
let userHome = require('user-home');
if (process.platform === 'linux' && process.env.USER === 'root') {
userHome = path.resolve(process.execPath, '..', '..', 'lib');
Copy link
Member

@Daniel15 Daniel15 Oct 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes an assumption about where Node.js is installed, which could vary based on the environment (eg. /usr/bin/node if the user installed it via a package manager, /usr/local/bin/node or /opt/nodejs/ or really anything else if they compiled it themselves or used something like nvm).

If you want to use /usr/local/lib/ then it's probably best to just hard-code that here. Don't use /usr/lib as that's purely for libraries managed by the system.

I think /usr/local/share/ is actually the right place for global Node.js modules as they're not native code and are thus platform-independent. Either /usr/local/share or /usr/local/lib is fine though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to understand...
When you say that I made an assumption (e.g. /usr/bin/node) you're talking about this variable process.execPath which contains the path to node bin, right?
So, if I have a custom node location, it will contain another path and this path.resolve(process.execPath, '..', '..', 'lib'); creates a bug.
That's it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :) What I mean is that for example, what if Node.js is installed at /opt/node/versions/6.91/? Then ../../lib will resolve to /opt/node/lib which is probably not what you want.

}

type Env = {[key: string]: ?string};

Expand Down