Skip to content

fix(cli): always disable interactive mode in non-TTYs #6419

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

Merged
merged 2 commits into from
Jul 29, 2024
Merged
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/34e33c5b.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"
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Yarn now accepts sponsors! Please take a look at our [OpenCollective](https://op
Features in `master` can be tried out by running `yarn set version from sources` in your project.
:::

- Fixes `preferInteractive` forcing interactive mode in non-TTY environments.

## 4.1.0

- Tweaks `-,--verbose` in `yarn workspaces foreach`; `-v` will now only print the prefixes, `-vv` will be necessary to also print the timings.
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-essentials/sources/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ export default class AddCommand extends BaseCommand {
});

const fixed = this.fixed;
const interactive = this.interactive ?? configuration.get(`preferInteractive`);
const interactive = configuration.isInteractive({
interactive: this.interactive,
stdout: this.context.stdout,
Copy link
Member

Choose a reason for hiding this comment

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

Isn't it stdin that has to be interactive?

});
const reuse = interactive || configuration.get(`preferReuse`);

const modifier = suggestUtils.getModifier(this, project);
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-essentials/sources/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export default class UpCommand extends BaseCommand {
});

const fixed = this.fixed;
const interactive = this.interactive ?? configuration.get(`preferInteractive`);
const interactive = configuration.isInteractive({
interactive: this.interactive,
stdout: this.context.stdout,
});

const modifier = suggestUtils.getModifier(this, project);

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

import {CorePlugin} from './CorePlugin';
import {Manifest, PeerDependencyMeta} from './Manifest';
Expand Down Expand Up @@ -313,6 +314,9 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
default: !isCI,
defaultText: `<dynamic>`,
},
/**
* @internal Prefer using `Configuration#isInteractive`.
*/
preferInteractive: {
description: `If true, the CLI will automatically use the interactive mode when called from a TTY`,
type: SettingsType.BOOLEAN,
Expand Down Expand Up @@ -1786,6 +1790,13 @@ export class Configuration {
return {os, cpu, libc};
}

isInteractive({interactive, stdout}: {interactive?: boolean, stdout: Writable}): boolean {
if (!(stdout as WriteStream).isTTY)
return false;

return interactive ?? this.get(`preferInteractive`);
}

private packageExtensions: PackageExtensions | null = null;

/**
Expand Down
Loading