Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
23 changes: 23 additions & 0 deletions .yarn/versions/efc24e59.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": minor
"@yarnpkg/plugin-essentials": minor

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@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/core"
- "@yarnpkg/doctor"
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Filename, PortablePath, ppath, xfs} from '@yarnpkg/fslib';
import {yarn} from 'pkg-tests-core';

const {
tests: {getPackageDirectoryPath},
Expand Down Expand Up @@ -253,6 +254,24 @@ describe(`Commands`, () => {
}),
);

test(
`it should not upgrade the existing dependency in the current project for preferReuse`,
makeTemporaryEnv({
devDependencies: {
[`no-deps`]: `1.0.0`,
},
}, async ({path, run, source}) => {
await yarn.writeConfiguration(path, {preferReuse: true});
await run(`add`, `no-deps`);

await expect(xfs.readJsonPromise(`${path}/package.json` as PortablePath)).resolves.toMatchObject({
devDependencies: {
[`no-deps`]: `1.0.0`,
},
});
}),
);

test(
`it should add a new peer dependency to the current project`,
makeTemporaryEnv({}, async ({path, run, source}) => {
Expand Down
6 changes: 6 additions & 0 deletions packages/gatsby/static/configuration/yarnrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,12 @@
"type": "boolean",
"default": false
},
"preferReuse": {
"_package": "@yarnpkg/core",
"description": "If true, `yarn add` command will reuse the most common dependency range in other workspaces (if pertinent).",
"type": "boolean",
"default": false
},
"preferTruncatedLines": {
"_package": "@yarnpkg/core",
"description": "If true, Yarn will truncate lines that would go beyond the size of the terminal. If progress bars are disabled, lines will never be truncated. Forgettable lines (e.g. the fetch step logs) are always truncated.",
Expand Down
22 changes: 15 additions & 7 deletions packages/plugin-essentials/sources/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,23 @@ export default class AddCommand extends BaseCommand {

const fixed = this.fixed;
const interactive = this.interactive ?? configuration.get(`preferInteractive`);
const reuse = interactive || configuration.get(`preferReuse`);

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

const strategies = [
...interactive ? [
suggestUtils.Strategy.REUSE,
] : [],
reuse ?
suggestUtils.Strategy.REUSE
: undefined,

suggestUtils.Strategy.PROJECT,
...this.cached ? [
suggestUtils.Strategy.CACHE,
] : [],

this.cached ?
suggestUtils.Strategy.CACHE
: undefined,

suggestUtils.Strategy.LATEST,
];
].filter(isStrategy);

const maxResults = interactive
? Infinity
Expand Down Expand Up @@ -323,6 +327,10 @@ export default class AddCommand extends BaseCommand {
}
}

function isStrategy(strategy?: suggestUtils.Strategy): strategy is suggestUtils.Strategy {
return typeof strategy !== `undefined`;
}

function suggestTarget(workspace: Workspace, ident: Ident, {dev, peer, preferDev, optional}: {dev: boolean, peer: boolean, preferDev: boolean, optional: boolean}) {
const hasRegular = workspace.manifest[suggestUtils.Target.REGULAR].has(ident.identHash);
const hasDev = workspace.manifest[suggestUtils.Target.DEVELOPMENT].has(ident.identHash);
Expand Down
5 changes: 5 additions & 0 deletions packages/yarnpkg-core/sources/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} =
type: SettingsType.BOOLEAN,
default: false,
},
preferReuse: {
description: `If true, the CLI will use the hightest version of existing, latest for new dependencies`,
type: SettingsType.BOOLEAN,
default: false,
},
preferTruncatedLines: {
description: `If true, the CLI will truncate lines that would go beyond the size of the terminal`,
type: SettingsType.BOOLEAN,
Expand Down