diff --git a/.yarn/versions/514f08ee.yml b/.yarn/versions/514f08ee.yml new file mode 100644 index 000000000000..0d8dee7aa000 --- /dev/null +++ b/.yarn/versions/514f08ee.yml @@ -0,0 +1,33 @@ +releases: + "@yarnpkg/cli": patch + "@yarnpkg/core": patch + +declined: + - "@yarnpkg/plugin-compat" + - "@yarnpkg/plugin-constraints" + - "@yarnpkg/plugin-dlx" + - "@yarnpkg/plugin-essentials" + - "@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/nm" + - "@yarnpkg/pnpify" + - "@yarnpkg/sdks" diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/add.test.ts.snap b/packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/add.test.ts.snap index ff68d6385ecf..c1259dcf86ba 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/add.test.ts.snap +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/add.test.ts.snap @@ -16,3 +16,19 @@ Object { ", } `; + +exports[`Commands add it should not clean the cache when cache lives inside the project but global cache is set 1`] = ` +Object { + "code": 0, + "stderr": "", + "stdout": "➤ YN0000: ┌ Resolution step +➤ YN0000: └ Completed +➤ YN0000: ┌ Fetch step +➤ YN0013: │ no-deps@npm:2.0.0 can't be found in the cache and will be fetched from the remote registry +➤ YN0000: └ Completed +➤ YN0000: ┌ Link step +➤ YN0000: └ Completed +➤ YN0000: Done +", +} +`; diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/commands/add.test.ts b/packages/acceptance-tests/pkg-tests-specs/sources/commands/add.test.ts index f58499b935de..a21eb62cfe3c 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/commands/add.test.ts +++ b/packages/acceptance-tests/pkg-tests-specs/sources/commands/add.test.ts @@ -564,6 +564,31 @@ describe(`Commands`, () => { expect(postUpgradeCache.find(entry => entry.includes(`no-deps-npm-2.0.0`))).toBeDefined(); })); + test(`it should not clean the cache when cache lives inside the project but global cache is set`, makeTemporaryEnv({ + dependencies: { + [`no-deps`]: `1.0.0`, + }, + }, async ({path, run, source}) => { + const env = { + YARN_ENABLE_GLOBAL_CACHE: `true`, + YARN_GLOBAL_FOLDER: `${path}/global`, + }; + await run(`install`, {env}); + + const preUpgradeCache = await xfs.readdirPromise(`${path}/global/cache` as PortablePath); + + expect(preUpgradeCache.find(entry => entry.includes(`no-deps-npm-1.0.0`))).toBeDefined(); + + const {code, stdout, stderr} = await run(`add`, `no-deps@2.0.0`, {env}); + + await expect({code, stdout, stderr}).toMatchSnapshot(); + + const postUpgradeCache = await xfs.readdirPromise(`${path}/global/cache` as PortablePath); + + expect(postUpgradeCache.find(entry => entry.includes(`no-deps-npm-1.0.0`))).toBeDefined(); + expect(postUpgradeCache.find(entry => entry.includes(`no-deps-npm-2.0.0`))).toBeDefined(); + })); + test(`it should not clean the cache when cache lives outside the project`, makeTemporaryEnv({ dependencies: { [`no-deps`]: `1.0.0`, diff --git a/packages/yarnpkg-core/sources/Project.ts b/packages/yarnpkg-core/sources/Project.ts index 883cb3f65db9..1b34b11110cf 100644 --- a/packages/yarnpkg-core/sources/Project.ts +++ b/packages/yarnpkg-core/sources/Project.ts @@ -1839,6 +1839,9 @@ export class Project { } async cacheCleanup({cache, report}: InstallOptions) { + if (this.configuration.get(`enableGlobalCache`)) + return; + const PRESERVED_FILES = new Set([ `.gitignore`, ]);