Skip to content

Commit f442366

Browse files
authored
feat: add corepack cache command (#363)
1 parent 12f1c31 commit f442366

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ Note that those commands still check whether the local project is configured for
124124
the given package manager (ie you won't be able to run `corepack yarn install`
125125
on a project where the `packageManager` field references `pnpm`).
126126

127+
### `corepack cache clean`
128+
129+
Clears the local `COREPACK_HOME` cache directory.
130+
131+
### `corepack cache clear`
132+
133+
Clears the local `COREPACK_HOME` cache directory.
134+
127135
### `corepack enable [... name]`
128136

129137
| Option | Description |

sources/commands/Cache.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {Command} from 'clipanion';
2+
import fs from 'fs';
3+
4+
import {getInstallFolder} from '../folderUtils';
5+
import type {Context} from '../main';
6+
7+
export class CacheCommand extends Command<Context> {
8+
static paths = [
9+
[`cache`, `clean`],
10+
[`cache`, `clear`],
11+
];
12+
13+
static usage = Command.Usage({
14+
description: `Cleans Corepack cache`,
15+
details: `
16+
Removes Corepack cache directory from your local disk.
17+
`,
18+
});
19+
20+
async execute() {
21+
await fs.promises.rm(getInstallFolder(), {recursive: true, force: true});
22+
}
23+
}

sources/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {BaseContext, Builtins, Cli, Command, Option, UsageError} from 'clipanion
33
import {version as corepackVersion} from '../package.json';
44

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

121+
cli.register(CacheCommand);
120122
cli.register(DisableCommand);
121123
cli.register(EnableCommand);
122124
cli.register(InstallGlobalCommand);

0 commit comments

Comments
 (0)