Last active
February 12, 2024 07:53
-
-
Save guest271314/aaaea08acf371725f0c61ac0ba3a424c to your computer and use it in GitHub Desktop.
Delete Deno global cache directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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