-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add special handling for spawning npm
#12
Conversation
@@ -133,6 +133,32 @@ function wrap (argv, env, workingDir) { | |||
options.envPairs.push((isWindows ? 'Path=' : 'PATH=') + workingDir) | |||
} | |||
|
|||
if (file === 'npm') { |
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.
I'd be tempted to isolate this logic in a helper function, I find it's a good way to keep icky code like this isolated so that people can just concentrate on the inputs and outputs.
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.
You’re right – I’ll move the code for looking up npmPath
into its own function. I’d like to keep the rest in place, if you don’t mind, because it resembles what happens in the blocks for handling file === 'sh' || …
and file === 'node' || …
.
@addaleax looking solid 👍 I'm noticing on AppVeyor, as with your other pull request, we're failing on just |
Sounds good – this repo never passed on AppVeyor with Node v0.10, btw. |
Updated with your suggestion 😄 |
First off, great find, and good job digging through the weeds to figure out the case where this is failing. However, adding a special case for a bin named "npm" is not the right fix here. Something is going wrong with the Usually I dig into this sort of issue by adding a bunch of logging in the guts of spawn-wrap. But if you can provide a limited test-case, I'll probably have some time to dig in myself in the next few weeks. |
Aha! Ok, forget what I said in my previous comment. Spawn-wrap doesn't do shebang reading or evaluating. I was misremembering :) I'm still not quite convinced this is worth special-casing, but I'm less unconvinced. Here's what's going on in spawn-wrap, and the choice to be made. Spawn-wrap works by doing 2 things:
If you have a file that is invoked without calling spawn or exec with node, either via However, if the shebang is an absolute path to a specific node binary, then the There are two other cases where you'll escape the wrap:
In those two cases, The question is whether this third case, of spawning a script with an explicit shebang, should be covered. I'm on the fence. In all three (explicit node binary call, modifying the On the other hand, the person who wrote that shebang is far away, and you're deciding to wrap your test call on your computer, so your intent matters more. To do this right, we'd have to do the following for any program before deciding not to wrap it:
I don't see how to do this without doing synchronous IO in an otherwise async function. But this program does a bit of that anyway, and it's gonna be pretty fast. (If you're using spawn-wrap on a production server to run npm test, you have bigger problems, most likely!) |
Can y'all check if the patch in #13 fixes the issue as well? I'm still not sure if this is a rare enough case to just go ahead and look for the name "npm", but reading the file's shebang takes care of any other cases like this one. |
@isaacs Not sure whether you’ve read in the mentioned nyc issue – Its actually even a bit of a combination of the edge cases you mentioned (fixed executable in the shebang + modifying But either way, I think closing this PR in favour of one of the others is a good idea 😄 |
@addaleax @isaacs this sounds smart to me, and we can perhaps rollback #12 if the change to node lands. My only comment is, would it be worth using an approach like head rather than readFileSync, I imagine this might be a slight performance boost especially if people are instrumenting large files -- or am I micro-optimizing? I know the AVA folks are performance concious. |
@addaleax if you rebase with master when you update this pull, appveyor should be passing now (I just removed Node 0.10). |
@bcoe I think I’d have used something like And yup, I’ll add your test from #14 to this. I’d like to rename the file to |
@addaleax seems reasonable to me, do we need to read the file? you don't think it's enough that the bin is |
Okay, so, the (new) AppVeyor tests are failing, and I haven’t done much Windows development in a long time… maybe one of you could take a look at it? |
As laid out in istanbuljs/nyc#190, spawn-wrap’ing `npm` does currently not work when using the `npm` binary that comes bundled with Node.js. This adds special handler code for the case that `npm` is the program that should be executed, looking for the `npm` executable in PATH using `which` and invoking the shim with it as an argument.
Ignore that, everything seems fine now. |
@bcoe The “new problem” mentioned in istanbuljs/nyc#190 with recursive |
As laid out in istanbuljs/nyc#190, spawn-wrap’ing
npm
does currently not work when using thenpm
binary that comes bundled with Node.js.This adds special handler code for the case that
npm
is the program that should be executed, looking for thenpm
executable in PATH and invoking the shim with it as an argument./cc @bcoe