Skip to content

Commit 77f7320

Browse files
committed
refactor: Simplify cache clean
1 parent 55a613f commit 77f7320

2 files changed

Lines changed: 21 additions & 52 deletions

File tree

packages/project/lib/cache/CacheCleanup.js

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,6 @@ async function getDirectorySize(dirPath) {
3232
return total;
3333
}
3434

35-
/**
36-
* Clean a single directory by removing it entirely.
37-
*
38-
* @param {string} dirPath Absolute path to directory
39-
* @param {string} displayPath Path to display in results
40-
* @param {string} type Type of cache entry
41-
* @returns {Promise<Array<{path: string, type: string, size: number}>>} Removed entries
42-
*/
43-
async function cleanDirectory(dirPath, displayPath, type) {
44-
const removed = [];
45-
try {
46-
await fs.access(dirPath);
47-
} catch {
48-
return removed;
49-
}
50-
51-
const size = await getDirectorySize(dirPath);
52-
try {
53-
await fs.rm(dirPath, {recursive: true, force: true});
54-
removed.push({path: displayPath, type, size});
55-
} catch {
56-
// Skip on failure
57-
}
58-
return removed;
59-
}
60-
6135
/**
6236
* Clean build cache directory by clearing all records from the SQLite database.
6337
*
@@ -102,7 +76,11 @@ async function cleanBuildCache(buildCacheDir) {
10276
}
10377

10478
/**
105-
* Scans the UI5 data directory and removes all cache entries.
79+
* Cleans cache directories for framework libraries and incremental build cache.
80+
*
81+
* Removes:
82+
* - framework/ directory: All UI5 framework libraries, download cache, staging files, and locks
83+
* - buildCache/ entries: Clears database records (preserves database files)
10684
*
10785
* @param {object} options
10886
* @param {string} options.ui5DataDir Resolved absolute path to UI5 data directory
@@ -112,33 +90,24 @@ async function cleanBuildCache(buildCacheDir) {
11290
export async function cleanCache({ui5DataDir}) {
11391
const allRemoved = [];
11492

115-
// Clean framework packages
116-
allRemoved.push(...await cleanDirectory(
117-
path.join(ui5DataDir, "framework", "packages"),
118-
"framework/packages",
119-
"framework"
120-
));
121-
122-
// Clean cacache
123-
allRemoved.push(...await cleanDirectory(
124-
path.join(ui5DataDir, "framework", "cacache"),
125-
"framework/cacache",
126-
"cacache"
127-
));
93+
// Clean entire framework directory (packages, cacache, staging, locks, etc.)
94+
const frameworkDir = path.join(ui5DataDir, "framework");
95+
try {
96+
await fs.access(frameworkDir);
97+
const size = await getDirectorySize(frameworkDir);
98+
await fs.rm(frameworkDir, {recursive: true, force: true});
99+
allRemoved.push({
100+
path: "framework",
101+
type: "framework",
102+
size
103+
});
104+
} catch {
105+
// Framework directory doesn't exist or couldn't be removed
106+
}
128107

129-
// Clean build cache (special: clears DB records, not files)
108+
// Clean build cache (clears DB records, preserves files)
130109
allRemoved.push(...await cleanBuildCache(path.join(ui5DataDir, "buildCache")));
131110

132-
// Clean misc dirs
133-
const miscDirs = [
134-
["framework/staging", "staging"],
135-
["framework/locks", "locks"],
136-
["server", "server"],
137-
];
138-
for (const [rel, type] of miscDirs) {
139-
allRemoved.push(...await cleanDirectory(path.join(ui5DataDir, rel), rel, type));
140-
}
141-
142111
const totalSize = allRemoved.reduce((sum, entry) => sum + entry.size, 0);
143112
return {
144113
entries: allRemoved,

packages/project/test/lib/cache/CacheCleanup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ test("cleanCache: clean all removes framework packages", async (t) => {
6464
t.true(result.totalCount >= 1);
6565
const frameworkEntries = result.entries.filter((e) => e.type === "framework");
6666
t.is(frameworkEntries.length, 1);
67-
t.is(frameworkEntries[0].path, "framework/packages");
67+
t.is(frameworkEntries[0].path, "framework");
6868
});
6969

7070
// ===== cleanCache: build cache (full clean) =====

0 commit comments

Comments
 (0)