Skip to content

feat(server): add stdin for API - #2106

Closed
knagaitsev wants to merge 40 commits into
webpack:masterfrom
knagaitsev:stdin-option
Closed

feat(server): add stdin for API#2106
knagaitsev wants to merge 40 commits into
webpack:masterfrom
knagaitsev:stdin-option

Conversation

@knagaitsev

@knagaitsevknagaitsev commented Jul 6, 2019

Copy link
Copy Markdown
Contributor
  • 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

Comment threadlib/Server.js
this.compiler = compiler;
this.options = options;

handleStdin(options);

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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

Comment threadlib/Server.js Outdated
});

process.stdin.resume();
}

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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

@alexander-akaitalexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@codecov

codecovBot commented Jul 7, 2019

Copy link
Copy Markdown

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 FilesCoverage Δ
lib/utils/createConfig.js92.79% <0%> (+1.64%)⬆️
lib/Server.js97.35% <100%> (+0.01%)⬆️
lib/utils/handleStdin.js100% <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

hiroppy commented Jul 7, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@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
Copy Markdown
Member

/cc @Loonride

@knagaitsev

knagaitsev commented Jul 9, 2019

Copy link
Copy Markdown
ContributorAuthor

@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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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

knagaitsev commented Jul 9, 2019

Copy link
Copy Markdown
ContributorAuthor

@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

Copy link
Copy Markdown
ContributorAuthor

/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
Copy Markdown
Contributor

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

@knagaitsevknagaitsev mentioned this pull request Aug 10, 2019
6 tasks
@knagaitsev

Copy link
Copy Markdown
ContributorAuthor

Closing in favor of #2186

@knagaitsevknagaitsev added the gsoc Google Summer of Code label Aug 13, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gsocGoogle 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

@knagaitsev@hiroppy@EslamHiko@alexander-akait