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

fix: only enable interactivity if stdin is a TTY too #6437

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .yarn/versions/d5fa480f.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch
"@yarnpkg/plugin-essentials": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
1 change: 1 addition & 0 deletions packages/plugin-essentials/sources/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export default class AddCommand extends BaseCommand {
const fixed = this.fixed;
const interactive = configuration.isInteractive({
interactive: this.interactive,
stdin: this.context.stdin,
stdout: this.context.stdout,
});
const reuse = interactive || configuration.get(`preferReuse`);
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-essentials/sources/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export default class UpCommand extends BaseCommand {
const fixed = this.fixed;
const interactive = configuration.isInteractive({
interactive: this.interactive,
stdin: this.context.stdin,
stdout: this.context.stdout,
});

Expand Down
9 changes: 6 additions & 3 deletions packages/yarnpkg-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {UsageError}
import {parse as parseDotEnv} from 'dotenv';
import {builtinModules} from 'module';
import pLimit, {Limit} from 'p-limit';
import {PassThrough, Writable} from 'stream';
import {WriteStream} from 'tty';
import {PassThrough, Readable, Writable} from 'stream';
import {ReadStream, WriteStream} from 'tty';

import {CorePlugin} from './CorePlugin';
import {Manifest, PeerDependencyMeta} from './Manifest';
Expand Down Expand Up @@ -1790,7 +1790,10 @@ export class Configuration {
return {os, cpu, libc};
}

isInteractive({interactive, stdout}: {interactive?: boolean, stdout: Writable}): boolean {
isInteractive({interactive, stdin, stdout}: {interactive?: boolean, stdin: Readable, stdout: Writable}): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

This is a breaking change.

Copy link
Member Author

@paul-soporan paul-soporan Aug 11, 2024

Choose a reason for hiding this comment

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

🤔 Indeed, didn't realize 4.4.0 was released with the previous PR.

Given the fact that GH code search doesn't return anything for configuration.isInteractive and the change has only been out for one week, I'd say there's about a 0% chance that anybody is using it and would prefer to land this change before anybody gets the chance to use it, even though it's theoretically a breaking change.

Copy link
Member

Choose a reason for hiding this comment

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

It's probably fine but could we make it optional with a TODO note to fix it for the next major?

if (!(stdin as ReadStream).isTTY)
return false;

if (!(stdout as WriteStream).isTTY)
return false;

Expand Down