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

feat: add corepack cleanup command #363

Merged
merged 9 commits into from
Feb 12, 2024
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ Note that those commands still check whether the local project is configured for
the given package manager (ie you won't be able to run `corepack yarn install`
on a project where the `packageManager` field references `pnpm`).

### `corepack cache clean`

Clears the local `COREPACK_HOME` cache directory.

### `corepack cache clear`

Clears the local `COREPACK_HOME` cache directory.

### `corepack enable [... name]`

| Option | Description |
Expand Down
23 changes: 23 additions & 0 deletions sources/commands/Cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Command} from 'clipanion';
import fs from 'fs';

import {getInstallFolder} from '../folderUtils';
import type {Context} from '../main';

export class CacheCommand extends Command<Context> {
static paths = [
[`cache`, `clean`],
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
[`cache`, `clear`],
];

static usage = Command.Usage({
description: `Cleans Corepack cache`,
details: `
Removes Corepack cache directory from your local disk.
`,
});

async execute() {
await fs.promises.rm(getInstallFolder(), {recursive: true, force: true});
}
}
2 changes: 2 additions & 0 deletions sources/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {BaseContext, Builtins, Cli, Command, Option, UsageError} from 'clipanion
import {version as corepackVersion} from '../package.json';

import {Engine} from './Engine';
import {CacheCommand} from './commands/Cache';
import {DisableCommand} from './commands/Disable';
import {EnableCommand} from './commands/Enable';
import {InstallGlobalCommand} from './commands/InstallGlobal';
Expand Down Expand Up @@ -117,6 +118,7 @@ export async function runMain(argv: Array<string>) {
cli.register(Builtins.HelpCommand);
cli.register(Builtins.VersionCommand);

cli.register(CacheCommand);
cli.register(DisableCommand);
cli.register(EnableCommand);
cli.register(InstallGlobalCommand);
Expand Down