Skip to content
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
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
Expand Up @@ -253,6 +253,23 @@ describe(`Commands`, () => {
}),
);

test(
`it should not upgrade the existing dependency in the current project for preferReuse`,
makeTemporaryEnv({
devDependencies: {
[`no-deps`]: `1.0.0`,
},
}, {preferReuse: true}, async ({path, run, source}) => {
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/plugin-essentials",
"description": "If true, `yarn add` will attempt to reuse the most common dependency range in other workspaces.",
"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
18 changes: 11 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((strategy): strategy is suggestUtils.Strategy => typeof strategy !== `undefined`);

const maxResults = interactive
? Infinity
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-essentials/sources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ declare module '@yarnpkg/core' {
// One in packages/plugin-essentials and one virtual package.
// Defining this property with two different enum instances leads to a compiler error.
defaultSemverRangePrefix: `^` | `~` | ``;
preferReuse: boolean;
}
}

Expand All @@ -125,6 +126,12 @@ const plugin: Plugin = {
values: [`^`, `~`, ``],
default: suggestUtils.Modifier.CARET,
},

preferReuse: {
description: `If true, \`yarn add\` will attempt to reuse the most common dependency range in other workspaces.`,
type: SettingsType.BOOLEAN,
default: false,
},
},
commands: [
cleanCache,
Expand Down