diff --git a/.yarn/versions/c6c3dd7a.yml b/.yarn/versions/c6c3dd7a.yml new file mode 100644 index 000000000000..b3aacffd1f6d --- /dev/null +++ b/.yarn/versions/c6c3dd7a.yml @@ -0,0 +1,34 @@ +releases: + "@yarnpkg/cli": minor + "@yarnpkg/core": minor + "@yarnpkg/plugin-essentials": minor + +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" diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/cache/clean.test.js b/packages/acceptance-tests/pkg-tests-specs/sources/commands/cache/clean.test.js index dbfabc0935f1..1c584dcdeb62 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/cache/clean.test.js +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/cache/clean.test.js @@ -37,5 +37,16 @@ describe(`Commands`, () => { expect(xfs.existsSync(`${path}/.yarn/cache`)).toEqual(false); expect(xfs.existsSync(`${path}/.yarn/global/cache`)).toEqual(false); })); + + test(`it should follow the enableCacheClean configuration`, makeTemporaryEnv({ + dependencies: { + [`no-deps`]: `1.0.0`, + }, + }, { + enableCacheClean: false, + }, async ({path, run, source}) => { + await run(`install`); + await expect(run(`cache`, `clean`)).rejects.toThrowError(); + })); }); }); diff --git a/packages/plugin-essentials/sources/commands/cache/clean.ts b/packages/plugin-essentials/sources/commands/cache/clean.ts index 81a8f2d0e6c9..5d515495bc31 100644 --- a/packages/plugin-essentials/sources/commands/cache/clean.ts +++ b/packages/plugin-essentials/sources/commands/cache/clean.ts @@ -1,7 +1,7 @@ import {BaseCommand} from '@yarnpkg/cli'; import {Configuration, Cache, StreamReport, Hooks} from '@yarnpkg/core'; import {xfs} from '@yarnpkg/fslib'; -import {Command, Option, Usage} from 'clipanion'; +import {Command, Option, Usage, UsageError} from 'clipanion'; // eslint-disable-next-line arca/no-default-export export default class CacheCleanCommand extends BaseCommand { @@ -34,6 +34,10 @@ export default class CacheCleanCommand extends BaseCommand { async execute() { const configuration = await Configuration.find(this.context.cwd, this.context.plugins); + + if (!configuration.get(`enableCacheClean`)) + throw new UsageError(`Cache cleaning is currently disabled. To enable it, set \`enableCacheClean: true\` in your configuration file. Note: Cache cleaning is typically not required and should be avoided when using Zero-Installs.`); + const cache = await Cache.find(configuration); const report = await StreamReport.start({ diff --git a/packages/yarnpkg-core/sources/Configuration.ts b/packages/yarnpkg-core/sources/Configuration.ts index 241f9bb9f1e3..0b76f83918a9 100644 --- a/packages/yarnpkg-core/sources/Configuration.ts +++ b/packages/yarnpkg-core/sources/Configuration.ts @@ -567,6 +567,11 @@ export const coreDefinitions: {[coreSettingName: string]: SettingsDefinition} = type: SettingsType.BOOLEAN, default: false, }, + enableCacheClean: { + description: `If false, disallows the \`cache clean\` command`, + type: SettingsType.BOOLEAN, + default: true, + }, checksumBehavior: { description: `Enumeration defining what to do when a checksum doesn't match expectations`, type: SettingsType.STRING,