Skip to content

feat!: enable interactivity by default when possible #5562

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

Open
wants to merge 1 commit 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/db5a0b98.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
releases:
"@yarnpkg/cli": major
"@yarnpkg/core": major
"@yarnpkg/plugin-essentials": major

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: 0 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ packageExtensions:

pnpEnableEsmLoader: true

preferInteractive: true

supportedArchitectures:
cpu:
- x64
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Yarn now accepts sponsorships! Please give a look at our [OpenCollective](https:
- Plugins cannot access the internal copy of Yup anymore (use [Typanion](https://github.com/arcanis/typanion) instead)
- Yarn will no longer remove the old Yarn 2.x `.pnp.js` file when migrating.
- The `--assume-fresh-project` flag of `yarn init` has been removed.
- Yarn is now interactive by default whenever possible:
- The `--interactive` flag is no longer needed for `yarn add` and `yarn up`.
- Yarn will never be interactive in CI environments or outside of a TTY.
- You can always set `preferInteractive: false` to prevent Yarn from being implicitly interactive.

### **API Changes**

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 @@ -132,7 +132,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,
});
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 @@ -161,7 +161,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
14 changes: 13 additions & 1 deletion packages/yarnpkg-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {UsageError}
import {parse as parseDotEnv} from 'dotenv';
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 @@ -299,7 +300,8 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
preferInteractive: {
description: `If true, the CLI will automatically use the interactive mode when called from a TTY`,
type: SettingsType.BOOLEAN,
default: false,
default: !isCI,
defaultText: `<dynamic>`,
},
preferTruncatedLines: {
description: `If true, the CLI will truncate lines that would go beyond the size of the terminal`,
Expand Down Expand Up @@ -613,6 +615,9 @@ export interface ConfigurationValueMap {
enableMotd: boolean;
enableProgressBars: boolean;
enableTimers: boolean;
/**
* @internal Prefer using `Configuration#isInteractive`.
*/
preferInteractive: boolean;
preferTruncatedLines: boolean;
progressBarStyle: string | undefined;
Expand Down Expand Up @@ -1719,6 +1724,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`);
}

async refreshPackageExtensions() {
this.packageExtensions = new Map();
const packageExtensions = this.packageExtensions;
Expand Down