-
-
Notifications
You must be signed in to change notification settings - Fork 105
Add return promise to the Module.runMain() branch. #172
Conversation
Any guidance on unit tests would be appreciated. |
index.js
Outdated
} | ||
}) | ||
}) | ||
}) | ||
} else if (!existing && argv.nodeArg && argv.nodeArg.length) { |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I shifted to opting-in to running in the same process since that is prickly.
test/index.js
Outdated
return child.spawn('node', [ | ||
NPX_ESC, '--quiet', 'echo-cli', 'hewwo' | ||
], {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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ideas on why the res.stdout
is empty on Windows?
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.
it shouldn't have been? /cc @noahleigh
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 think the switch to running in a child
process in the current PR state has smth to do with it.
parse-args.js
Outdated
@@ -208,6 +208,10 @@ function yargsParser (argv, defaultNpm) { | |||
describe: Y()`Ignores existing binaries in $PATH, or in the local project. This forces npx to do a temporary install and use the latest version.`, | |||
type: 'boolean' | |||
}) | |||
.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
test/index.js
Outdated
return child.spawn('node', [ | ||
NPX_ESC, '--quiet', 'echo-cli', 'hewwo' | ||
], {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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it shouldn't have been? /cc @noahleigh
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.
👍 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-process
opt-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-process
the user could opt-in tochild
process.Update:
Flipped to adding a
--always-spawn
option.