Skip to content

feat: skip stdin resuming in watch mode - #2410

Merged
guybedford merged 4 commits into
rollup:masterfrom
kvet:skip-tty-check
Aug 24, 2018
Merged

feat: skip stdin resuming in watch mode#2410
guybedford merged 4 commits into
rollup:masterfrom
kvet:skip-tty-check

Conversation

@kvet

@kvet kvet commented Aug 15, 2018

Copy link
Copy Markdown
Contributor

This PR contains:

  • bugfix
  • feature
  • refactor
  • tests
  • documentation
  • metadata

Breaking Changes?

  • yes
  • no

If yes, please describe the breakage.

Please Describe Your Changes

Solving the following problem: #1919

@shellscape

Copy link
Copy Markdown
Contributor

I think there are a few questions that need answering before this is merged:

  • Do we really want to remove this otherwise valuable check for all environments?
  • Would it be wiser path be to provide an override option to pass that check?
  • The declaration for isTTY is const isTTY = Boolean(process.stderr.isTTY);. Can that instead be overridden by the environments needing it to be?

It would appear that it could be overridden:

→ node
> process.stderr.isTTY
true
> process.stderr.isTTY = false
false
> process.stderr.isTTY
false

@kvet

kvet commented Aug 15, 2018

Copy link
Copy Markdown
Contributor Author

It sounds strange. Why do I need to override something if I already run rollup in watch mode?

I think that the issue may be treated as a bug. Watch mode is not running correctly in different environments. So, I think a user should use normal mode when it is needed instead of relying on this check.

@shellscape

shellscape commented Aug 15, 2018

Copy link
Copy Markdown
Contributor

I think that the issue may be treated as a bug. Watch mode is not running correctly in different environments.

That makes the assumption that all environments are equal. But that is not the case, and not a correct assumption.

So, I think a user should use normal mode when it is needed instead of relying on this check.

There are differences in what the Node API will support between environments that are TTY and non-TTY. It's an important distinction when dealing with console output. This commit 0295c5b implemented the check you are now seeking to revert, and from the code it looks like there was specific intent to that addition.

The fact of the matter here is that executing this in a non-TTY environment can have unpredictable consequences. There's no reason that every executable out there should test their environment for support API when the isTTY property is there for that purpose. As such, when running an executable in an environment that is not TTY, it's not reasonable to expect an executable to make that consideration. Rather, the environment should be altered, if it can support the same interfaces.

In my opinion (other maintainers may feel differently) the end goal of this PR would be better suited as a contribution to the Lerna project, to simulate TTY support. Or the suggested workarounds in local setups. I don't believe this is a good change that will benefit users as a whole; conversely, only a select niche of users, and will likely introduce a regression for other users.

You can read more about the differences in TTY and non-TTY environments here: https://books.google.com/books?id=FZcQAwAAQBAJ&pg=PA73&lpg=PA73&dq=node+istty&source=bl&ots=P9Ox_cheVQ&sig=ZR9t_p-AIC2_W1Jk04Hz0zKhosQ&hl=en&sa=X&ved=2ahUKEwjLy6eN4u_cAhWGtlMKHTOhDy44ChDoATABegQICRAB#v=onepage&q=node%20istty&f=false

Comment thread bin/src/run/watch.ts Outdated

case 'END':
if (!silent && isTTY) {
if (!silent) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems this check was initially added exactly for TTY support - #1574.

Can you perhaps explain why you think this should be the other way around?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I mean this line was initially added exactly for Lerna support :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread bin/src/run/watch.ts
if (!process.stdin.isTTY) {
process.stdin.on('end', close); // in case we ever support stdin!
process.stdin.resume();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a bug fix, independent of the above? Or are both changes needed for the lerna support?

@guybedford

Copy link
Copy Markdown
Contributor

Lerna should work out of the box definitely, would be great to follow what is needed here further.

@kvet kvet changed the title feat: skip tty check in watch mode feat: skip stdin resuming in watch mode Aug 16, 2018
@kvet

kvet commented Aug 16, 2018

Copy link
Copy Markdown
Contributor Author

I found the original PR that broke my project: #1774. This causes the 'end' event to be triggered in lerna. So rollup stops watching changes.

In webpack a such check is in condition that becomes true when specific option is set: https://github.com/webpack/webpack-cli/blob/master/bin/cli.js#L516. But I didn't find this option in the webpack docs. However, the default value of this option is false.

@guybedford

Copy link
Copy Markdown
Contributor

@kvet thanks for tracking this down, this seems good to me.

As for the use case of rollup/rollup-watch#30, surely that is just persistent: false? Or is there more at play?

Regardless I think we should merge this then come back to that.

@guybedford guybedford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for making it minimal!

@lukastaegert lukastaegert 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.

Not 100% sure this is the proper solution but I agree that having Lerna working is probably more important.

@guybedford
guybedford merged commit acb1bbf into rollup:master Aug 24, 2018
hieuxlu added a commit to hieuxlu/create-react-app that referenced this pull request Mar 24, 2020
jakesgordon added a commit to jakesgordon/rollup that referenced this pull request Apr 10, 2020
This is necessary when rollup is used as the front end for an Elixir
Phoenix application. In dev mode, the phoenix watchers run the rollup
command as a child process and the underlying erlang port mechanism
assumes that the child process closes when the parent stdin is
closed. Without this fix the old zombie processes never close and
accumulate as you stop and start in development mode.

This was discussed and fixed in 2017 in the original rollup-watcher
repository:

  * rollup/rollup-watch#30 (comment)
  * https://github.com/rollup/rollup-watch/pull/57/files

It appears to then have been removed as a side effect of another change

  * rollup#2410

Finally, was requested back in a PR that never got merged because of
some doubt around the need to hide it behind a CLI flag

  * https://github.com/rollup/rollup/pull/2653/files

For reference, webpack implements this hidden behind the --watch-stdin
CLI flag.
lukastaegert added a commit that referenced this pull request Apr 12, 2020
* Ensure --watch mode exits correctly when stdin is closed.

This is necessary when rollup is used as the front end for an Elixir
Phoenix application. In dev mode, the phoenix watchers run the rollup
command as a child process and the underlying erlang port mechanism
assumes that the child process closes when the parent stdin is
closed. Without this fix the old zombie processes never close and
accumulate as you stop and start in development mode.

This was discussed and fixed in 2017 in the original rollup-watcher
repository:

  * rollup/rollup-watch#30 (comment)
  * https://github.com/rollup/rollup-watch/pull/57/files

It appears to then have been removed as a side effect of another change

  * #2410

Finally, was requested back in a PR that never got merged because of
some doubt around the need to hide it behind a CLI flag

  * https://github.com/rollup/rollup/pull/2653/files

For reference, webpack implements this hidden behind the --watch-stdin
CLI flag.

* Add a test that times out without this change

Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
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.

4 participants