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

Expose the ChildProcess constructor #1751

Closed
isaacs opened this issue May 20, 2015 · 16 comments
Closed

Expose the ChildProcess constructor #1751

isaacs opened this issue May 20, 2015 · 16 comments
Labels
child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js.

Comments

@isaacs
Copy link
Contributor

isaacs commented May 20, 2015

So I don't have to do stuff like this: https://github.com/isaacs/spawn-wrap/blob/master/index.js#L33-L38

@evanlucas
Copy link
Contributor

Is there any reason it is not currently exposed?

@piscisaureus
Copy link
Contributor

Prior discussion: nodejs/node-v0.x-archive#2419

@isaacs
Copy link
Contributor Author

isaacs commented May 20, 2015

In the last 3 years, I've changed my mind on this, having had to jump through hoops to get at ChildProcess. It's not like it's actually hidden or private anyway, so we may as well save me the exec syscall to get it.

@evanlucas
Copy link
Contributor

Thanks. Since we now we have internal modules, would it be worth refactoring ChildProcess into an internal module that is used by child_process and can be exposed via the --expose-internals flag?

@isaacs
Copy link
Contributor Author

isaacs commented May 20, 2015

@evanlucas It's not an "internal module", though. It's a class in JavaScript-land. I need access to it in non---expose-internals code, and I can get it, but the fact that it's not exposed nicely makes that unpleasant.

@piscisaureus
Copy link
Contributor

I think one of the problems is that the signature of the ChildProcess
constructor is internal / unspecified.

On Wed, May 20, 2015 at 3:07 PM, isaacs notifications@github.com wrote:

@evanlucas https://github.com/evanlucas It's not an "internal module",
though. It's a class in JavaScript-land. I need access to it in non-
--expose-internals code, and I can get it, but the fact that it's not
exposed nicely makes that unpleasant.


Reply to this email directly or view it on GitHub
#1751 (comment).

@vkurchatkin
Copy link
Contributor

@isaacs can't you just wrap exports.spawn?

@evanlucas
Copy link
Contributor

@isaacs good point.

@isaacs
Copy link
Contributor Author

isaacs commented May 20, 2015

@vkurchatkin No. I'd have to also wrap exports.exec, exports.fork, etc.

@piscisaureus Ok, so, let's specify it :) It hasn't changed since (at least) 0.8, I think it's relatively stable at this point.

@chrisdickinson
Copy link
Contributor

I'd support throwing the class into an internal module and then exposing it through the public child_process – it'd be a nice way to trim down on file length, plus we could take some of the sundry internal functions and expose them on the internal module so we can test 'em.

@isaacs
Copy link
Contributor Author

isaacs commented May 20, 2015

@chrisdickinson I still need to be able to get at the class for spawn-wrap, though. Wherever the code lives, assert(child_process.spawn(..) instanceof child_process.ChildProcess) should be valid.

@chrisdickinson
Copy link
Contributor

@isaacs Oh yeah, you would be able to – via require('child_process').ChildProcess – but this is an approach we could take to make sure we've got adequate coverage on the class before exposing it.

Edit: to be clear, I'm suggesting that we rip ChildProcess out of lib/child_process.js, throw it and the private functions it depends on into an internal module, then replace it in lib/child_process.js with var ChildProcess = exports.ChildProcess = require('internal/child_process'); so we can expand test coverage on it, which reduces risk for exposing it to the world.

@brendanashworth brendanashworth added child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js. labels May 20, 2015
@Fishrock123
Copy link
Contributor

Edit: to be clear, I'm suggesting that we rip ChildProcess out of lib/child_process.js, throw it and the private functions it depends on into an internal module, then replace it in lib/child_process.js with var ChildProcess = exports.ChildProcess = require('internal/child_process'); so we can expand test coverage on it, which reduces risk for exposing it to the world.

Since we aren't exposing the private stuff anyway, I see no benefit to this?

EDIT:

and expose them on the internal module so we can test 'em.

Missed that, sorry. Yeah, +1

@isaacs
Copy link
Contributor Author

isaacs commented May 21, 2015

@chrisdickinson That sounds ideal.

evanlucas added a commit to evanlucas/node that referenced this issue May 28, 2015
Creates two new internal modules (child_process and socket_list) for
better readability.

Exposes the ChildProcess constructor from the child_process module so
one can now `require(‘child_process’).ChildProcess`

Fixes: nodejs#1751
PR-URL: nodejs#1760
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
@evanlucas
Copy link
Contributor

Closed via #1760

@sindresorhus
Copy link

I made a quick polyfill for anyone needing to support older Node.js versions too: https://github.com/sindresorhus/child-process-ctor

andrewdeandrade pushed a commit to andrewdeandrade/node that referenced this issue Jun 3, 2015
Creates two new internal modules (child_process and socket_list) for
better readability.

Exposes the ChildProcess constructor from the child_process module so
one can now `require(‘child_process’).ChildProcess`

Fixes: nodejs/node#1751
PR-URL: nodejs/node#1760
Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. feature request Issues that request new features to be added to Node.js.
Projects
None yet
Development

No branches or pull requests

8 participants