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

Update API #22

Closed
wants to merge 16 commits into from
Closed

Update API #22

wants to merge 16 commits into from

Conversation

demurgos
Copy link
Contributor

@demurgos demurgos commented Sep 18, 2018

This PR is part of the effort to improve Node's support for code coverage (see discussion on c8).

This PR exposes two new functions to support foreground childs:

  • proxy(parent, child) to start forwarding between two existing processes.
  • spawn(file, args, options) as a replacement for the original functions allowing you to pass spawn options.

The original API is still there. The only breaking change is dropping support for unmaintained Node versions (require Node 6+).

The new spawn function would allow to pass the env NODE_V8_COVERAGE variable directly in c8.
There are a few other changes:

  • It always defaults to use the builtin cp.spawn function (even on Windows), you can pass your own function if you want to.
  • It does not take over control flow: it is your responsibility to exit the parent process once the child is closed.

Other comments:

  • I converted the lib to Typescript (for documentation). I also converted the tests to make sure the types work fine.
  • I completed the test suite to reach 100% coverage.
  • From a semver point of view, this is a major version.
  • I update the dependencies.

Discussions:

@demurgos
Copy link
Contributor Author

Closing for now, I'll send smaller PRs.

@demurgos demurgos closed this Sep 18, 2018
Copy link

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please have a look in consideration for your rewrite.

close.then((close) => {
// You can use this handler to perform an action before exiting the
// foreground child.
console.log(close.code);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How's close a function and object at same time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's like most CJS exports: a function with additional properties (fg() and fg.spawn(), signalExit() and signalExit.signals(), etc.).

It boils down to:

const close = () => { ... };
close.code = code;
close.signal = signal;
return close;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, got it. Thanks!

@@ -1,8 +1,8 @@
environment:
matrix:
- nodejs_version: '5'
- nodejs_version: '4'
- nodejs_version: '0.12'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the rationale for dropping support for <6?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Align with Node's support policy by targeting oldest LTS.
  • Use promise-based API out-of-the box (without having to use bluebird)
  • Remove workarounds for old Node versions
  • Refactor the internals to use ES syntax (scoped variables, spread args, arrow functions, etc.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Looks that just this alone should be a different PR/discussion with the maintainers if they are aligned. That way, it becomes more progressive than big-bang.

@@ -0,0 +1,13 @@
declare module "signal-exit" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From our discussion in the channel, I think it's better off dropping off TS from this PR, for now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite this in JS (even not ES6 for now), for backward compatibility.

@@ -0,0 +1,70 @@
import t from "tap";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate out increasing test-coverage as a different PR, but only have tests for the code you've written for the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants