Skip to content

Instantly share code, notes, and snippets.

@guest271314
Last active February 12, 2024 07:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guest271314/aaaea08acf371725f0c61ac0ba3a424c to your computer and use it in GitHub Desktop.
Save guest271314/aaaea08acf371725f0c61ac0ba3a424c to your computer and use it in GitHub Desktop.
Delete Deno global cache directories
const decoder = new TextDecoder();
const command = new Deno.Command(Deno.execPath(), {
args: [
"info",
"--json",
],
});
const { code, stdout, stderr } = await command.output();
// https://tc39.es/ecma262/multipage/structured-data.html#sec-json.parse
// 11.b. Let rootName be the empty String.
const cacheDirs = [
"modulesCache",
"npmCache",
"typescriptCache",
"registryCache",
"",
];
const entries = Object.values(
JSON.parse(
decoder.decode(stdout),
(k, v) => cacheDirs.includes(k) ? v : void 0,
),
);
for (const path of entries) {
try {
const file = await Deno.stat(path).catch(() => {});
if (file) {
for await (const entry of Deno.readDir(path)) {
await Deno.remove(`${path}/${entry.name}`, { recursive: true });
}
}
} catch (e) {
console.log(e, path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment