From f442366c1c00d0c3f388b757c3797504f9a6b62e Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 13 Feb 2024 00:40:32 +0100 Subject: [PATCH] feat: add `corepack cache` command (#363) --- README.md | 8 ++++++++ sources/commands/Cache.ts | 23 +++++++++++++++++++++++ sources/main.ts | 2 ++ 3 files changed, 33 insertions(+) create mode 100644 sources/commands/Cache.ts diff --git a/README.md b/README.md index 52806c6f3..5e00c175f 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/sources/commands/Cache.ts b/sources/commands/Cache.ts new file mode 100644 index 000000000..9f32d7616 --- /dev/null +++ b/sources/commands/Cache.ts @@ -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 { + 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}); + } +} diff --git a/sources/main.ts b/sources/main.ts index 9b880ee05..c9a3b9456 100644 --- a/sources/main.ts +++ b/sources/main.ts @@ -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'; @@ -117,6 +118,7 @@ export async function runMain(argv: Array) { cli.register(Builtins.HelpCommand); cli.register(Builtins.VersionCommand); + cli.register(CacheCommand); cli.register(DisableCommand); cli.register(EnableCommand); cli.register(InstallGlobalCommand);