Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoclean local cache folder #372

Merged
merged 6 commits into from
Aug 22, 2019
Merged

Autoclean local cache folder #372

merged 6 commits into from
Aug 22, 2019

Conversation

deini
Copy link
Member

@deini deini commented Aug 21, 2019

What's the problem this PR addresses?
Autoclean local cache

How did you fix it?
Added a Cache cleanup step to install, which should work on install, add, up, remove.

Which packages would need a new release (if any)?

  • berry-core

Have you run yarn version [major|minor|patch] --deferred in those packages?

  • Yes

Closes #247, #228

packages/berry-core/sources/Project.ts Show resolved Hide resolved
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: ┌ Cache cleanup step
➤ YN0054: │ skipping cleanup since cache folder is not inside project folder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥕 incentive to use local cache

Copy link
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions but it's pretty good already 👍

A followup might be to update yarn cache clean to follow a similar architecture (although it'll require to add an option to the cache to prevent it from fetching the files if they don't already exist, so it should be done in a different PR).

@@ -1142,6 +1143,10 @@ export class Project {
await this.linkEverything(opts);
});

await opts.report.startTimerPromise(`Cache cleanup step`, async() => {
await this.cacheCleanup(opts);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be done in the fetch step, right after fetchEverything. I'd like to keep the number of steps low because it's easier to teach, and less verbose in terms of output 🤔

return;

if (!isFolderInside(cachePath, this.cwd))
return report.reportInfo(MessageName.CACHE_OUTSIDE_PROJECT, `skipping cleanup since cache folder is not inside project folder`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahah yeah incentive, but at the same time if they've explicitly configured the cache to be stored elsewhere then I think we should trust that they know what they're doing and keep our "verbosity budget" low 😄

@@ -1252,6 +1257,35 @@ export class Project {
await workspace.persistManifest();
}
}

async cacheCleanup({cache, report}: InstallOptions) {
const cachePath = cache.cwd;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rather use cache.cwd when we need it? It's what we're doing in the rest of the code with things like workspace.cwd etc.

packages/berry-core/sources/Project.ts Outdated Show resolved Hide resolved
packages/berry-core/sources/Project.ts Show resolved Hide resolved

await run(`install`, {env});

expect(await readdir(sharedCachePath)).toMatchSnapshot();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to avoid using snapshots if possible - can you replace the readdir snapshots by a number of files check?

@@ -18,3 +18,9 @@ export function getDefaultGlobalFolder() {
export function getHomeFolder() {
return NodeFS.toPortablePath(homedir() || '/usr/local/share');
}

export function isFolderInside(target: PortablePath, parent: PortablePath) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if Node would accept a PR to add a similar function to path ...

Copy link
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! 🎉

}, async ({path, run, source}) => {
const sharedCachePath = await createTemporaryFolder();
const env = {
YARN_CACHE_FOLDER: sharedCachePath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fyi (not a blocker), it also can be done by writing a .yarnrc.yml file into path. We do this in a few other places (mainly for the plugins).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Upgrading a package should delete obsolete archives
2 participants