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

feat(server): add stdin for API #2106

Closed
wants to merge 40 commits into from

Conversation

knagaitsev
Copy link
Collaborator

@knagaitsev knagaitsev commented Jul 6, 2019

  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

Yes

Motivation / Use-Case

fixes #1712

This makes stdin an option for both CLI and API, and helps in moving configuration changes out of the CLI for CLI refactor.

Breaking Changes

None

Additional Info

@@ -58,6 +59,8 @@ class Server {
this.compiler = compiler;
this.options = options;

handleStdin(options);
Copy link
Member

Choose a reason for hiding this comment

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

hm, why we need it here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@evilebottnawi Do you think no helper would be better? I just thought having helper would be cleaner

Copy link
Member

Choose a reason for hiding this comment

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

i think we need this inside server file, it is logic for CLI only

lib/Server.js Outdated
});

process.stdin.resume();
}
Copy link
Member

Choose a reason for hiding this comment

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

No, i don't mean we don't need help, i just answer why we use this here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@evilebottnawi The goal is to make this option not CLI-only. As mentioned in #1712 it is desired for this to be possible.

Also this is beneficial because I want to reduce what the CLI does as much as possible for the refactor.

Copy link
Member

Choose a reason for hiding this comment

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

👍

alexander-akait
alexander-akait previously approved these changes Jul 6, 2019
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

/cc @hiroppy

@codecov
Copy link

codecov bot commented Jul 7, 2019

Codecov Report

Merging #2106 into master will increase coverage by 0.19%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2106      +/-   ##
==========================================
+ Coverage   92.56%   92.76%   +0.19%     
==========================================
  Files          33       34       +1     
  Lines        1265     1271       +6     
  Branches      361      362       +1     
==========================================
+ Hits         1171     1179       +8     
+ Misses         87       85       -2     
  Partials        7        7
Impacted Files Coverage Δ
lib/utils/createConfig.js 92.79% <0%> (+1.64%) ⬆️
lib/Server.js 97.35% <100%> (+0.01%) ⬆️
lib/utils/handleStdin.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b79f523...b35e8ac. Read the comment docs.

@hiroppy
Copy link
Member

hiroppy commented Jul 7, 2019

I think tests on Mac will be broken by these changes.

FAIL test/cli/cli.test.js (102.875s)
  ● CLI › --stdin without stdin end should time out

    Timeout - Async callback was not invoked within the 60000ms timeout specified by jest.setTimeout.Error: 

      119 |   });
      120 | 
    > 121 |   it('--stdin without stdin end should time out', (done) => {
          |   ^
      122 |     const configPath = resolve(
      123 |       __dirname,
      124 |       '../fixtures/simple-config/webpack.config.js'

      at Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Suite.it (test/cli/cli.test.js:121:3)
      at Object.describe (test/cli/cli.test.js:17:1)

@EslamHiko
Copy link
Member

@Loonride since you are testing after calling the helper, that ensures that process.stdin.resume() has been called I think you can check for this flag process.stdin._readableState.paused it's false when stdin is enabled. instead of waiting for it to time out.

@alexander-akait
Copy link
Member

/cc @Loonride

@knagaitsev
Copy link
Collaborator Author

knagaitsev commented Jul 9, 2019

@EslamHiko I'm not seeing the process.stdin._readableState.paused on Windows 7, Node v8.10.0, so I'm not sure if that is the right flag to look at. But good suggestion, I will see if something else from _readableState can be used to check this

Edit: also it would time out without stdin option so probably not a good test.

@knagaitsev
Copy link
Collaborator Author

I stuck with a solution of waiting for a timeout, because working with child process stdin seemed unreliable when I tried to use stdin.isPaused().

@knagaitsev
Copy link
Collaborator Author

Oddly inconsistent behavior with execa where timedOut is undefined on MacOS. Seeing if checking for failed property will work on both. Possibly an execa issue?

@alexander-akait
Copy link
Member

@Loonride looks like problem on execa side? Can you try next version of execa, maybe they fixed this, if it is works we can minimum required nodejs version for devDependcies to 8.9 and describe this in Contributing guide

@knagaitsev
Copy link
Collaborator Author

knagaitsev commented Jul 9, 2019

@Loonride looks like problem on execa side? Can you try next version of execa, maybe they fixed this, if it is works we can minimum required nodejs version for devDependcies to 8.9 and describe this in Contributing guide

@evilebottnawi why node 8.9? It looks like tests are passing in node 6, and the upgrade seems to have solved it.

Edit: or possibly not, some MacOS still not passing

@knagaitsev knagaitsev closed this Jul 24, 2019
@knagaitsev knagaitsev reopened this Jul 24, 2019
@knagaitsev
Copy link
Collaborator Author

/cc @hiroppy @evilebottnawi I finally resolved the hanging test issues. I found that on some OS/node versions process.stdin.resume() and process.stdin.pause() behave differently, which made testing tough. The squash before merge would clean up this messy history, correct?

@hiroppy
Copy link
Member

hiroppy commented Jul 24, 2019

@Loonride Thanks. Yep, so don't worry.

@knagaitsev
Copy link
Collaborator Author

Closing in favor of #2186

@knagaitsev knagaitsev closed this Aug 10, 2019
@knagaitsev knagaitsev added the gsoc Google Summer of Code label Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gsoc Google Summer of Code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature request] --stdin as option in config
4 participants