Skip to content

Commit

Permalink
feat: add corepack cache command (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Feb 12, 2024
1 parent 12f1c31 commit f442366
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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`],
[`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

0 comments on commit f442366

Please sign in to comment.