Skip to content

Commit

Permalink
fix(core): skip cache cleanup when enableGlobalCache is true (#4402)
Browse files Browse the repository at this point in the history
* skip cache cleanup when enableGlobalCache is true

* patch notes

* chore: versions

* move guard

* only move enableGlobalCache check

* missed this in cleanup

* Update Project.ts

Co-authored-by: merceyz <[email protected]>
Co-authored-by: Maël Nison <[email protected]>
  • Loading branch information
3 people authored Apr 28, 2022
1 parent 0eb915f commit 8e0c4b8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .yarn/versions/514f08ee.yml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
",
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -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`, `[email protected]`, {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`,
Expand Down
3 changes: 3 additions & 0 deletions packages/yarnpkg-core/sources/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1839,6 +1839,9 @@ export class Project {
}

async cacheCleanup({cache, report}: InstallOptions) {
if (this.configuration.get(`enableGlobalCache`))
return;

const PRESERVED_FILES = new Set([
`.gitignore`,
]);
Expand Down

0 comments on commit 8e0c4b8

Please sign in to comment.