devclean-cache 0.0.0-stage → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +185 -2
- package/README.zh-CN.md +142 -0
- package/SECURITY.md +33 -0
- package/dist/adapters.d.ts +25 -0
- package/dist/adapters.js +258 -0
- package/dist/clean.d.ts +16 -0
- package/dist/clean.js +35 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +447 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +109 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +7 -0
- package/dist/report-html.d.ts +7 -0
- package/dist/report-html.js +256 -0
- package/dist/report.d.ts +36 -0
- package/dist/report.js +109 -0
- package/dist/scan.d.ts +37 -0
- package/dist/scan.js +66 -0
- package/dist/tui.d.ts +25 -0
- package/dist/tui.js +113 -0
- package/dist/util/format.d.ts +14 -0
- package/dist/util/format.js +71 -0
- package/dist/util/fs.d.ts +37 -0
- package/dist/util/fs.js +192 -0
- package/package.json +55 -5
package/dist/adapters.js
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export function detectEnv() {
|
|
4
|
+
const home = os.homedir();
|
|
5
|
+
return {
|
|
6
|
+
platform: process.platform,
|
|
7
|
+
home,
|
|
8
|
+
localAppData: process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"),
|
|
9
|
+
appData: process.env.APPDATA || path.join(home, "AppData", "Roaming"),
|
|
10
|
+
vars: process.env,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const isWin = (env) => env.platform === "win32";
|
|
14
|
+
const isMac = (env) => env.platform === "darwin";
|
|
15
|
+
// Build paths with the semantics of the target platform, not the host, so the
|
|
16
|
+
// same environment object produces the same paths on any machine.
|
|
17
|
+
const envPath = (env) => (isWin(env) ? path.win32 : path.posix);
|
|
18
|
+
const joinPath = (env, ...parts) => envPath(env).join(...parts);
|
|
19
|
+
function platformPath(env, win, mac, linux) {
|
|
20
|
+
if (isWin(env))
|
|
21
|
+
return win;
|
|
22
|
+
if (isMac(env))
|
|
23
|
+
return mac;
|
|
24
|
+
return linux;
|
|
25
|
+
}
|
|
26
|
+
export const ADAPTERS = [
|
|
27
|
+
{
|
|
28
|
+
id: "npm",
|
|
29
|
+
name: "npm cache",
|
|
30
|
+
risk: "low",
|
|
31
|
+
note: "Downloaded package tarballs. npm re-downloads what it needs.",
|
|
32
|
+
paths(env) {
|
|
33
|
+
const base = env.vars.npm_config_cache ||
|
|
34
|
+
platformPath(env, joinPath(env, env.localAppData, "npm-cache"), joinPath(env, env.home, ".npm"), joinPath(env, env.home, ".npm"));
|
|
35
|
+
return [joinPath(env, base, "_cacache")];
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "pnpm",
|
|
40
|
+
name: "pnpm store",
|
|
41
|
+
risk: "low",
|
|
42
|
+
note: "Content-addressed package store shared by your pnpm projects.",
|
|
43
|
+
paths(env) {
|
|
44
|
+
return [
|
|
45
|
+
platformPath(env, joinPath(env, env.localAppData, "pnpm", "store"), joinPath(env, env.home, "Library", "pnpm", "store"), joinPath(env, env.home, ".local", "share", "pnpm", "store")),
|
|
46
|
+
];
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: "yarn",
|
|
51
|
+
name: "Yarn cache",
|
|
52
|
+
risk: "low",
|
|
53
|
+
note: "Yarn's global package cache.",
|
|
54
|
+
paths(env) {
|
|
55
|
+
return [
|
|
56
|
+
platformPath(env, joinPath(env, env.localAppData, "Yarn", "Cache"), joinPath(env, env.home, "Library", "Caches", "Yarn"), joinPath(env, env.home, ".cache", "yarn")),
|
|
57
|
+
];
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "bun",
|
|
62
|
+
name: "Bun cache",
|
|
63
|
+
risk: "low",
|
|
64
|
+
note: "Bun's install cache.",
|
|
65
|
+
paths(env) {
|
|
66
|
+
return [joinPath(env, env.home, ".bun", "install", "cache")];
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "pip",
|
|
71
|
+
name: "pip cache",
|
|
72
|
+
risk: "low",
|
|
73
|
+
note: "Python wheel and HTTP cache. pip re-downloads on demand.",
|
|
74
|
+
paths(env) {
|
|
75
|
+
return [
|
|
76
|
+
platformPath(env, joinPath(env, env.localAppData, "pip", "Cache"), joinPath(env, env.home, "Library", "Caches", "pip"), joinPath(env, env.home, ".cache", "pip")),
|
|
77
|
+
];
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: "uv",
|
|
82
|
+
name: "uv cache",
|
|
83
|
+
risk: "low",
|
|
84
|
+
note: "uv's package and wheel cache.",
|
|
85
|
+
paths(env) {
|
|
86
|
+
return [
|
|
87
|
+
platformPath(env, joinPath(env, env.localAppData, "uv", "cache"), joinPath(env, env.home, "Library", "Caches", "uv"), joinPath(env, env.home, ".cache", "uv")),
|
|
88
|
+
];
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: "cargo",
|
|
93
|
+
name: "Cargo registry",
|
|
94
|
+
risk: "low",
|
|
95
|
+
note: "Crates downloaded by Cargo. Rebuilt from crates.io when needed.",
|
|
96
|
+
paths(env) {
|
|
97
|
+
return [joinPath(env, env.home, ".cargo", "registry"), joinPath(env, env.home, ".cargo", "git")];
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "go",
|
|
102
|
+
name: "Go build cache",
|
|
103
|
+
risk: "low",
|
|
104
|
+
note: "Compiled package cache used by the Go toolchain.",
|
|
105
|
+
paths(env) {
|
|
106
|
+
return [
|
|
107
|
+
platformPath(env, joinPath(env, env.localAppData, "go-build"), joinPath(env, env.home, "Library", "Caches", "go-build"), joinPath(env, env.home, ".cache", "go-build")),
|
|
108
|
+
];
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "gradle",
|
|
113
|
+
name: "Gradle caches",
|
|
114
|
+
risk: "low",
|
|
115
|
+
note: "Dependency and build caches under ~/.gradle/caches.",
|
|
116
|
+
paths(env) {
|
|
117
|
+
return [joinPath(env, env.home, ".gradle", "caches")];
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
id: "maven",
|
|
122
|
+
name: "Maven repo",
|
|
123
|
+
risk: "medium",
|
|
124
|
+
note: "Local Maven repository. Safe to delete, but large to re-download.",
|
|
125
|
+
paths(env) {
|
|
126
|
+
return [joinPath(env, env.home, ".m2", "repository")];
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: "playwright",
|
|
131
|
+
name: "Playwright browsers",
|
|
132
|
+
risk: "low",
|
|
133
|
+
note: "Browser binaries downloaded by Playwright. Reinstall with npx playwright install.",
|
|
134
|
+
paths(env) {
|
|
135
|
+
return [
|
|
136
|
+
platformPath(env, joinPath(env, env.localAppData, "ms-playwright"), joinPath(env, env.home, "Library", "Caches", "ms-playwright"), joinPath(env, env.home, ".cache", "ms-playwright")),
|
|
137
|
+
];
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: "puppeteer",
|
|
142
|
+
name: "Puppeteer browsers",
|
|
143
|
+
risk: "low",
|
|
144
|
+
note: "Chrome builds downloaded by Puppeteer.",
|
|
145
|
+
paths(env) {
|
|
146
|
+
return [joinPath(env, env.home, ".cache", "puppeteer")];
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: "huggingface",
|
|
151
|
+
name: "Hugging Face models",
|
|
152
|
+
risk: "medium",
|
|
153
|
+
note: "Model and dataset cache. Deleted models are re-downloaded on next use.",
|
|
154
|
+
paths(env) {
|
|
155
|
+
if (env.vars.HF_HOME)
|
|
156
|
+
return [joinPath(env, env.vars.HF_HOME, "hub")];
|
|
157
|
+
return [joinPath(env, env.home, ".cache", "huggingface", "hub")];
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: "ollama",
|
|
162
|
+
name: "Ollama models",
|
|
163
|
+
risk: "high",
|
|
164
|
+
note: "Downloaded local LLM weights. Deleting forces a full re-pull.",
|
|
165
|
+
paths(env) {
|
|
166
|
+
const list = [joinPath(env, env.home, ".ollama", "models")];
|
|
167
|
+
if (!isWin(env) && !isMac(env))
|
|
168
|
+
list.push("/usr/share/ollama/.ollama/models");
|
|
169
|
+
return list;
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: "lmstudio",
|
|
174
|
+
name: "LM Studio models",
|
|
175
|
+
risk: "high",
|
|
176
|
+
note: "Downloaded local LLM weights. Deleting forces a full re-download.",
|
|
177
|
+
paths(env) {
|
|
178
|
+
return [joinPath(env, env.home, ".lmstudio", "models"), joinPath(env, env.home, ".cache", "lm-studio", "models")];
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
id: "nuget",
|
|
183
|
+
name: "NuGet packages",
|
|
184
|
+
risk: "medium",
|
|
185
|
+
note: "Global package folder shared by .NET projects. dotnet restore fetches it again.",
|
|
186
|
+
paths(env) {
|
|
187
|
+
return [joinPath(env, env.home, ".nuget", "packages")];
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: "conda",
|
|
192
|
+
name: "Conda packages",
|
|
193
|
+
risk: "medium",
|
|
194
|
+
note: "Package archives extracted into conda environments. Existing envs may share these files.",
|
|
195
|
+
paths(env) {
|
|
196
|
+
const roots = ["miniconda3", "anaconda3", "miniforge3", "mambaforge"];
|
|
197
|
+
const list = roots.map((root) => joinPath(env, env.home, root, "pkgs"));
|
|
198
|
+
list.push(joinPath(env, env.localAppData, "conda", "pkgs"));
|
|
199
|
+
return list;
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: "sbt",
|
|
204
|
+
name: "sbt / Ivy cache",
|
|
205
|
+
risk: "low",
|
|
206
|
+
note: "Scala and Java dependencies downloaded by sbt.",
|
|
207
|
+
paths(env) {
|
|
208
|
+
return [joinPath(env, env.home, ".ivy2", "cache"), joinPath(env, env.home, ".sbt", "boot")];
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
id: "deno",
|
|
213
|
+
name: "Deno cache",
|
|
214
|
+
risk: "low",
|
|
215
|
+
note: "Remote modules and generated types. Fetched again on next run.",
|
|
216
|
+
paths(env) {
|
|
217
|
+
const dir = env.vars.DENO_DIR ||
|
|
218
|
+
platformPath(env, joinPath(env, env.localAppData, "deno"), joinPath(env, env.home, "Library", "Caches", "deno"), joinPath(env, env.home, ".cache", "deno"));
|
|
219
|
+
return [dir];
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: "cypress",
|
|
224
|
+
name: "Cypress binary cache",
|
|
225
|
+
risk: "low",
|
|
226
|
+
note: "Downloaded Cypress app binaries. Reinstalled by cypress install.",
|
|
227
|
+
paths(env) {
|
|
228
|
+
return [
|
|
229
|
+
platformPath(env, joinPath(env, env.localAppData, "Cypress", "Cache"), joinPath(env, env.home, "Library", "Caches", "Cypress"), joinPath(env, env.home, ".cache", "Cypress")),
|
|
230
|
+
];
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: "electron",
|
|
235
|
+
name: "Electron cache",
|
|
236
|
+
risk: "low",
|
|
237
|
+
note: "Electron runtime downloads used by electron-builder and electron.",
|
|
238
|
+
paths(env) {
|
|
239
|
+
return [
|
|
240
|
+
platformPath(env, joinPath(env, env.localAppData, "electron", "Cache"), joinPath(env, env.home, "Library", "Caches", "electron"), joinPath(env, env.home, ".cache", "electron")),
|
|
241
|
+
];
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
id: "composer",
|
|
246
|
+
name: "Composer cache",
|
|
247
|
+
risk: "low",
|
|
248
|
+
note: "PHP package archives downloaded by Composer.",
|
|
249
|
+
paths(env) {
|
|
250
|
+
return [
|
|
251
|
+
platformPath(env, joinPath(env, env.localAppData, "Composer", "Cache"), joinPath(env, env.home, "Library", "Caches", "composer"), joinPath(env, env.home, ".cache", "composer")),
|
|
252
|
+
];
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
];
|
|
256
|
+
export function adapterById(id) {
|
|
257
|
+
return ADAPTERS.find((adapter) => adapter.id === id);
|
|
258
|
+
}
|
package/dist/clean.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ScanItem } from "./scan.js";
|
|
2
|
+
export interface CleanOutcome {
|
|
3
|
+
item: ScanItem | {
|
|
4
|
+
path: string;
|
|
5
|
+
name: string;
|
|
6
|
+
bytes: number;
|
|
7
|
+
};
|
|
8
|
+
ok: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
}
|
|
11
|
+
/** Refuse to delete anything that is not a known cache or project artifact. */
|
|
12
|
+
export declare function isSafeTarget(target: string, knownCachePaths: Set<string>): boolean;
|
|
13
|
+
export declare function cleanItems(items: Array<Pick<ScanItem, "path" | "name" | "bytes">>, knownCachePaths: Set<string>, onItem?: (outcome: CleanOutcome) => void): Promise<{
|
|
14
|
+
freed: number;
|
|
15
|
+
outcomes: CleanOutcome[];
|
|
16
|
+
}>;
|
package/dist/clean.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { PROJECT_ARTIFACTS, removePath } from "./util/fs.js";
|
|
3
|
+
function normalize(target) {
|
|
4
|
+
const resolved = path.resolve(target);
|
|
5
|
+
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
6
|
+
}
|
|
7
|
+
/** Refuse to delete anything that is not a known cache or project artifact. */
|
|
8
|
+
export function isSafeTarget(target, knownCachePaths) {
|
|
9
|
+
const resolved = path.resolve(target);
|
|
10
|
+
const key = normalize(resolved);
|
|
11
|
+
for (const known of knownCachePaths) {
|
|
12
|
+
if (normalize(known) === key)
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return PROJECT_ARTIFACTS.has(path.basename(resolved));
|
|
16
|
+
}
|
|
17
|
+
export async function cleanItems(items, knownCachePaths, onItem) {
|
|
18
|
+
let freed = 0;
|
|
19
|
+
const outcomes = [];
|
|
20
|
+
for (const item of items) {
|
|
21
|
+
if (!isSafeTarget(item.path, knownCachePaths)) {
|
|
22
|
+
const outcome = { item, ok: false, error: "refused: not a recognized cache path" };
|
|
23
|
+
outcomes.push(outcome);
|
|
24
|
+
onItem?.(outcome);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const error = await removePath(item.path);
|
|
28
|
+
const outcome = { item, ok: error === null, error: error ?? undefined };
|
|
29
|
+
if (outcome.ok)
|
|
30
|
+
freed += item.bytes;
|
|
31
|
+
outcomes.push(outcome);
|
|
32
|
+
onItem?.(outcome);
|
|
33
|
+
}
|
|
34
|
+
return { freed, outcomes };
|
|
35
|
+
}
|
package/dist/cli.d.ts
ADDED