Add return promise to the Module.runMain() branch.#172
Add return promise to the Module.runMain() branch.#172zkat merged 1 commit intozkat:latestfrom jdalton:run-main
Conversation
|
Any guidance on unit tests would be appreciated. |
| }) | ||
| }) | ||
| }) | ||
| } else if (!existing && argv.nodeArg && argv.nodeArg.length) { |
There was a problem hiding this comment.
The setImmediate use here is just to get it off the synchronous beforeExit event loop.
It could be a setTimeout of 0 or process.nextTick.
There was a problem hiding this comment.
I shifted to opting-in to running in the same process since that is prickly.
| ], {stdio: 'pipe'}).then(res => { | ||
| t.equal(res.stdout.trim(), 'hewwo') | ||
| t.equal(res.stdout.trim(), isWindows ? '' : 'hewwo') | ||
| t.end() |
There was a problem hiding this comment.
Any ideas on why the res.stdout is empty on Windows?
There was a problem hiding this comment.
it shouldn't have been? /cc @noahleigh
There was a problem hiding this comment.
I think the switch to running in a child process in the current PR state has smth to do with it.
| }) | ||
| .option('in-process', { | ||
| describe: Y()`Allow the command to be executed in the same process as npx instead of a child process.`, | ||
| type: 'boolean' |
There was a problem hiding this comment.
in re opt-in, I think this should default to true -- that way, it won't be a breaking change, and this has been part of npx for a while, so I'd rather not start spawning processes here.
There was a problem hiding this comment.
What do you think about flipping the new option to being child which enforces the child process branch? I kind of dig that approach since the in-process option is more of a suggestion if it's doable (no nodeArg or shell or other stuff) where the child--always-spawn option is explicit and can happen 💯of the time.
| ], {stdio: 'pipe'}).then(res => { | ||
| t.equal(res.stdout.trim(), 'hewwo') | ||
| t.equal(res.stdout.trim(), isWindows ? '' : 'hewwo') | ||
| t.end() |
There was a problem hiding this comment.
it shouldn't have been? /cc @noahleigh
zkat
left a comment
There was a problem hiding this comment.
👍 nice. This will be useful, specially for libnpx users. This feature was definitely optimized for plain npx usage.
|
Thanks @zkat! Would you like a follow-up PR for a unit test? |
|
@jdalton If you want, give it a shot! -- but if it's too tricky to write a test for, don't worry about it. I mainly want to unblock you right now though :) |
|
After pulling down these changes to my local repo on my Windows 10 machine, I tested it with: After the packages were installed, it launched my text editor with the Line 291 in 13fea31 The cmd here is just a .js file with no mention of the node binary that lives in process.argv[0] to actually run it.
I assume this isn't the intended behavior? |
|
No that's not intended. Ohno. I'll try and fix it once I've got my laptop out again. |
|
actually I've no idea why this is happening, right now lol |
|
@zkat Line 273 in 13fea31 Which means when it comes time to run a command in a new process: Line 291 in 13fea31 cmd and opts look like:
I think they should look like this: Which is what the code within that first condition block does (more or less) |
|
@noahleigh Does #174 resolve the problem? |
add --always-spawn to opt out of process takeover optimization feature Credit: @jdalton PR-URL: zkat/npx#172
add --always-spawn to opt out of process takeover optimization feature Credit: @jdalton PR-URL: zkat/npx#172
This PR adds an
in-processopt-in to avoid defaulting to running in the same process asnpx. Running in process causes the promise to resolve quicker and creates problems with packages that tie-in toprocess.on('exit')or callprocess.exit(). Related to npm/npm#20303.Update:
I can also flip this so instead of opting-in to
in-processthe user could opt-in tochildprocess.Update:
Flipped to adding a
--always-spawnoption.