New: nodepath option for the path#534
New: nodepath option for the path#534gyandeeps wants to merge 1 commit intoshelljs:masterfrom gyandeeps:issue469
nodepath option for the path#534Conversation
| var shellMethods = Object.create(shell); | ||
| var PATH = 'PATH'; | ||
|
|
||
| // windows calls it's path 'Path' usually, but this is not guaranteed. |
There was a problem hiding this comment.
I believe we can rely on process.env to have case-insensitive keys, so process.env.PATH should always work.
process.env isn't a real JS object. See atom/atom#11302 as an example of this.
There was a problem hiding this comment.
I saw npm doing this that why I did it to make sure we are cross platform
There was a problem hiding this comment.
Hmmm could you link me to the line in npm? I know that process.env is case-insensitive on my Windows machine. Perhaps it's not the case for everyone?
I would imagine things would get very broken in NodeJS if process.env were case-sensitive on Windows. Perhaps that's the case for older versions of Node?
There was a problem hiding this comment.
There was a problem hiding this comment.
thumbsup means keep the change or remove it? because this change is tied with the below function which we are talking abt also.
There was a problem hiding this comment.
I posted a follow up comment. It looks to me like they're making a PR to add this to the documentation (I didn't read the PR yet, so I could be mistaken). This seems to indicate that this is the intended behavior on Node on Windows.
My guess is that process.env has always had case-insensitive keys on Windows, but it was just never documented. I think it's ok to rely on that (unless we hear otherwise).
There was a problem hiding this comment.
@nfischer let me know whatever you thoughts are on this and I will react accordingly. Thanks
There was a problem hiding this comment.
@gyandeeps let's go for the simpler approach, process.env.PATH. Thanks
There was a problem hiding this comment.
Apparently this is not true. I use windows 10 and when I use windows default cmd then its called Path but if I run using git bash then its called PATH.
Thats why I see test fail on windows.
There was a problem hiding this comment.
@gyandeeps if this is not the case, then it would be good to chime in on nodejs/node#9157 and the corresponding pull request before Node 7 gets incorrect documentation.
As for this PR, let's go with your initial approach. Sorry for the confusion.
src/common.js
Outdated
| globOptions: {}, | ||
| maxdepth: 255 | ||
| maxdepth: 255, | ||
| nodepath: false |
There was a problem hiding this comment.
Could you add a trailing comma? We don't enforce it via linting, but it's something we're trying to move toward to keep diffs simple.
src/common.js
Outdated
| var env = objectAssign({}, process.env); | ||
|
|
||
| if (config.nodepath) { | ||
| env[PATH] += (process.platform === 'win32' ? ';' : ':') + path.join(process.cwd(), 'node_modules', '.bin') + (process.platform === 'win32' ? ';' : ':'); |
There was a problem hiding this comment.
Could you change this to path.delimiter?
Also, I don't think we always want a trailing delimiter, so you can get rid of the second (process.platform === 'win32' ? ';' : ':'). Please correct me if Windows differs from Unix on this point.
src/common.js
Outdated
| return env; | ||
| }; | ||
|
|
||
| exports.getPathFromEnv = function (env) { |
There was a problem hiding this comment.
I don't think we need this, since we can just use process.env.PATH to retrieve the value.
There was a problem hiding this comment.
At some places in the code base we have used process.env.path || process.env.Path || process.env.PATH; to get the correct path. I just made a function to keep it at one spot.
There was a problem hiding this comment.
Yeah, I saw that. I think that wasn't actually necessary for us to do. We should probably convert everything to process.env.PATH for the sake of consistency.
Plus, we would run into issues if someone on unix ever did export path=foo (totally valid for a user to do, but it would provide incorrect results for which()).
There was a problem hiding this comment.
I am hearing get rid of this change and the above logic and just make it use process.env.PATH, correct?
Will make the change then.
There was a problem hiding this comment.
Yeah. Let's try that. If things break on Appveyor, then we can revert back to this.
|
Let's add a test in |
|
@nfischer All the work has been done. Some of things to note:
|
|
|
Thanks @nfischer . I think PR is ready. Let me know if you have any suggestions. |
|
@gyandeeps I'll take a look later today. If you can, please chime in on nodejs/node#9157, since that just added got merged into official node documentation, and it disagrees with your observations on |
|
@gyandeeps Sorry for the late reply. I got a bit distracted with #512 Here's my thoughts on this PR:
Instead of having code to get We can write a setter for Let me know what your thoughts are for this approach. The downside is that this modifies a global, but the option is likely not going to be used often, and I can't think of a use for this option where modifying the PATH that way would be dangerous. Although admittedly, that approach wouldn't be anything the users wouldn't be able to do themselves, so perhaps it's best to leave the code as-is. |
|
|
||
| // windows calls it's path 'Path' usually, but this is not guaranteed. | ||
| if (process.platform === 'win32') { | ||
| PATH_IDENTIFIER = 'Path'; |
There was a problem hiding this comment.
Is this line necessary? It'll get overridden in the loop below.
|
My thoughts:
|
|
@gyandeeps sorry for taking so long to get back. Let's hold off on this, since I'm not completely sure what the best approach is, or if this is something we should delegate to ShellJS users instead. I'm marking this as something to look into once we get closer to v0.8. @freitagbr feel free to chime in with your thoughts on this feature. |
|
After some thought, this is probably the wrong approach to solve this problem. I think it's better to leave this to users, since it can easily be solved outside of ShellJS. |
This what i am thinking for
nodepathconfig option. This works as i have tried it.Its getting difficult to test since when you run
npm testto run the unit test. NPM already adds the./node_modules/.binto the $PATH.I will work on the tests but I wanted to know whether I am heading in the right direction.