Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
8280272
feat: Clean cache command
d3xter666 May 22, 2026
1971750
refactor: Use single place for DB manipulation
d3xter666 May 29, 2026
637f2b5
refactor: Simplify cache clean
d3xter666 May 29, 2026
d302ef6
refactor: Position correctly the CacheCleanup
d3xter666 May 29, 2026
0c16994
refactor: Add confirmation dialog for the cache clean command
d3xter666 May 29, 2026
b0c3f3b
refactor: Rename cacheVersionDir
d3xter666 May 29, 2026
21e2e89
refactor: Restore location of CacheCleanup
d3xter666 May 29, 2026
329ba63
fix: Clean only current cache version
d3xter666 May 29, 2026
884d024
refactor: Simplify CacheCleanup
d3xter666 May 29, 2026
046c401
test: Improve coverage
d3xter666 May 29, 2026
b53c357
refactor: CLI package orchestrates cache cleanup
d3xter666 May 29, 2026
81c130a
refactor: Add skip confirmation option
d3xter666 Jun 1, 2026
21b5277
fix: Windows paths for tests
d3xter666 Jun 1, 2026
406058d
refactor: Use yesno package for CLI confirmation
d3xter666 Jun 2, 2026
5b099ce
refactor: Simplify cleanup meta structure
d3xter666 Jun 2, 2026
2f4e7a0
fix: Add guard to not accidently create a new DB
d3xter666 Jun 2, 2026
6b92cbd
refactor: Reuse meta from installers in cache cleanup
d3xter666 Jun 2, 2026
9558e61
refactor: Cleanup details
d3xter666 Jun 2, 2026
cfde118
fix: Respect datadir config
d3xter666 Jun 2, 2026
086c9e3
docs: Update cache clean --help CLI information
d3xter666 Jun 2, 2026
a51c16d
refactor: Cleanup confirmation revised
d3xter666 Jun 9, 2026
6fa610a
refactor: Revise actual cleanup UX
d3xter666 Jun 9, 2026
4ee4e5f
fix: Docs generation failure
d3xter666 Jun 9, 2026
5c2cac8
fix: Respect cleanup locking
d3xter666 Jun 9, 2026
5045721
refactor: Redundant cleanup summary
d3xter666 Jun 9, 2026
b38256f
fix: Cache locking race condition
d3xter666 Jun 10, 2026
132a7e2
test: Fix race condition expectations
d3xter666 Jun 10, 2026
84d590b
refactor: Cleanups
d3xter666 Jun 10, 2026
73cd772
refactor: Naming of locks
d3xter666 Jun 10, 2026
8c73b1e
docs: Update documentation to respect recent changes
d3xter666 Jun 11, 2026
6c9872d
revert: Redundant maven installer locks
d3xter666 Jun 12, 2026
0501f1b
refactor: Use pacote's internals for its own cleanup
d3xter666 Jun 12, 2026
cb1f1d4
revert: NPM Install sync. It's now redundant
d3xter666 Jun 12, 2026
6f02c79
docs: No mention of "incremental build"
d3xter666 Jun 12, 2026
6391071
refactor: Avoid hardcoded values
d3xter666 Jun 12, 2026
016bd18
feat: Add cleanup lock for "ui5 serve"
d3xter666 Jun 15, 2026
137360d
refactor: Move server lock into the server package and reuse in cli
d3xter666 Jun 17, 2026
f5e5d86
refactor: Data dir is resolved centrally via util
d3xter666 Jun 18, 2026
b7817b1
fix: Remove redundant lock cleanups after server close
d3xter666 Jun 18, 2026
970156f
refactor: Revise locks destinations and messages
d3xter666 Jun 19, 2026
de109a2
refactor: Lock full build, so that it does not run into timing problems
d3xter666 Jun 19, 2026
9fce7eb
refactor: Avoid cache cleanup + build race conditions
d3xter666 Jun 19, 2026
c2db60e
refactor: Cleanups
d3xter666 Jun 19, 2026
d258614
refactor: Use the common test/tmp dir
d3xter666 Jun 22, 2026
4e36bd0
refactor: Move server lock to the ProjectGraph.serve
d3xter666 Jun 22, 2026
2c534e3
refactor: Rename getDefaultUi5DataDir to resolveUi5DataDir
d3xter666 Jun 22, 2026
40a861e
refactor: Do not pass dir (cwd) as argument to resolveUi5DataDir
d3xter666 Jun 22, 2026
bbecbd6
refactor: Cleanup of redundant lock watchers
d3xter666 Jun 22, 2026
937acfb
refactor: Cleanup of ProjectGraph
d3xter666 Jun 22, 2026
596f898
refactor: Acquire locks in the project builder & server
d3xter666 Jun 22, 2026
873712e
test: Fix stubs
d3xter666 Jun 22, 2026
486340b
test: Update lock util tests
d3xter666 Jun 22, 2026
9b333b9
test: Server integration
d3xter666 Jun 22, 2026
6d87bf6
refactor: DB size optimization
d3xter666 Jun 22, 2026
0d446a6
refactor: Split cache command into logical chunks
d3xter666 Jun 23, 2026
49c560d
refactor: Consolidate common logic for CacheManager
d3xter666 Jun 23, 2026
40c19a4
refactor: Consolidate repetative code
d3xter666 Jun 23, 2026
c8b4484
refactor: Lock cleanups
d3xter666 Jun 23, 2026
e71b97d
test: Cleanup of repetative cases
d3xter666 Jun 23, 2026
df56779
refactor: Provide dataDir to the buildServer
d3xter666 Jun 23, 2026
abeb88d
refactor: Enhance locks
d3xter666 Jun 23, 2026
6b80d8b
refactor: Cleanup locks for wrong places
d3xter666 Jun 24, 2026
2276a08
refactor: Locks for ProjectGraph
d3xter666 Jun 25, 2026
07cffbc
test: Fix unstable tests
d3xter666 Jun 25, 2026
5cac4c7
docs: JSDoc updates
d3xter666 Jun 26, 2026
98389e5
fix: Separate async & sync dir creation
d3xter666 Jun 26, 2026
a31c263
refactor: Add ui5DataDir as required in ProjectGraph's constructor
d3xter666 Jun 26, 2026
0630e18
refactor: Give a name for the graph's internal locking method
d3xter666 Jun 26, 2026
747e1e0
refactor: Move locks to the specific lock points
d3xter666 Jun 26, 2026
db6b3de
feat: ProjectGraph's lock now has a tolerance to wat for the cache cl…
d3xter666 Jun 26, 2026
0491e72
refactor: Cache clean now first renames the framework dir and then wi…
d3xter666 Jun 28, 2026
630324f
docs: Explain why we lock the graph in enrichProjectGraph
d3xter666 Jun 29, 2026
63bd310
docs: Correctly address params in JSDoc
d3xter666 Jun 29, 2026
807a7b2
docs: Refactor _preventCacheClean JSDoc block
d3xter666 Jun 29, 2026
5595e41
refactor: Explicit destruction of the ProjectGraph where needed
d3xter666 Jun 29, 2026
82f5009
fix: Protect _preventCacheClean from overwriting the locks
d3xter666 Jun 29, 2026
0d0f10a
docs: Update LOCK_REFRESH_INTERVAL_MS description
d3xter666 Jun 29, 2026
a2dda60
refactor: Try to explain better orphaned + framework dirs cleanup order
d3xter666 Jun 29, 2026
11c7157
refactor: Optimize lock.js
d3xter666 Jun 29, 2026
cde5eb4
refactor: Fix wrong case for isCacheDbAvailable
d3xter666 Jun 29, 2026
c8bb468
refactor: Resolve internally getLockDir in hasActiveLocks & remove r…
d3xter666 Jun 29, 2026
adca562
refactor: Promisify per module
d3xter666 Jun 29, 2026
eb4c950
refactor: Consolidate *Ui5DataDir implementation
d3xter666 Jun 29, 2026
ea52640
test: Fix failing CI tests because of a missing stub
d3xter666 Jun 29, 2026
cb4c899
refactor: Lock on cache clean command
d3xter666 Jun 29, 2026
b0d1d94
refactor: Always release the cache clean lock
d3xter666 Jun 29, 2026
3097cdf
docs: Update comments
d3xter666 Jun 29, 2026
3d51af4
refactor: Reorganize output information
d3xter666 Jun 29, 2026
3fb827c
fix: Adjust comments & wrongly called method
d3xter666 Jun 29, 2026
5fc6c4c
fix: Await synchronization callback
d3xter666 Jun 29, 2026
87ea214
revert: Restore Troubleshooting guide after merge conflict
d3xter666 Jun 29, 2026
4ecb384
refactor: No braceless returns
d3xter666 Jun 29, 2026
c9e191e
refactor: Prevent clean cache only after sealed
d3xter666 Jun 29, 2026
4778dbb
revert: Wiped out documentation
d3xter666 Jun 29, 2026
5cbce64
docs: Update Troubleshooting to reflect orphaned branches
d3xter666 Jun 29, 2026
31ab373
docs: Update CLI information to reflect orphaned branches
d3xter666 Jun 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions internal/documentation/docs/pages/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,25 @@ Only remove these directories when no UI5 CLI process and no `@ui5/*` API consum

#### Resolution

To free disk space, remove the relevant subdirectory.

To only remove framework downloads:
Use the dedicated cache clean command, which safely removes all cached data:

```sh
rm -rf ~/.ui5/framework/
ui5 cache clean
```

To only remove the build cache:
This will display the cache location, the amount of data that will be removed, and ask for confirmation before proceeding. To skip the confirmation prompt (e.g. in CI environments), use the `--yes` flag:

```sh
rm -rf ~/.ui5/buildCache/
ui5 cache clean --yes
```

The command removes the following cached data:
- **UI5 Framework packages** — downloaded UI5 library files (`~/.ui5/framework/`)
- **Build cache (DB)** — build data (`~/.ui5/buildCache/`)
- **Orphaned framework data** — incomplete framework directories left over from previously interrupted clean operations (`~/.ui5/.framework_to_delete_*/`)

Any missing framework dependencies will be downloaded again during the next UI5 CLI invocation.

::: info
If you have configured a custom data directory via `UI5_DATA_DIR` or `ui5 config set ui5DataDir`, replace `~/.ui5/` with that path. See [Changing UI5 CLI's Data Directory](#changing-ui5-cli-s-data-directory).
:::
Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

324 changes: 324 additions & 0 deletions packages/cli/lib/cli/commands/cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
import chalk from "chalk";
import path from "node:path";
import process from "node:process";
import baseMiddleware from "../middlewares/base.js";
import {resolveUi5DataDir} from "@ui5/project/utils/dataDir";
import {acquireLock, CLEANUP_LOCK_NAME, getLockDir, hasActiveLocks} from "@ui5/project/utils/lock";
import * as frameworkCache from "@ui5/project/ui5Framework/cache";
import CacheManager from "@ui5/project/build/cache/CacheManager";

const cacheCommand = {
command: "cache",
describe: "Manage the UI5 CLI cache (downloaded framework packages and build data)",
middlewares: [baseMiddleware],
handler: handleCache
};

cacheCommand.builder = function(cli) {
return cli
.demandCommand(1, "Command required. Available command is 'clean'")
.command("clean", "Remove all cached UI5 data", {
Comment thread
d3xter666 marked this conversation as resolved.
handler: handleCache,
builder: function(yargs) {
return yargs
.option("yes", {
alias: "y",
describe: "Skip the confirmation prompt, e.g. for use in CI pipelines",
default: false,
type: "boolean",
})
.example("$0 cache clean",
"Remove all cached UI5 data after confirming the prompt")
.example("$0 cache clean --yes",
"Remove all cached UI5 data without confirmation (e.g. in CI)")
.example("UI5_DATA_DIR=/custom/path $0 cache clean",
"Remove cached data from a non-default UI5 data directory")
.epilogue(
"The cache is stored in the UI5 data directory (default: ~/.ui5).\n" +
"Override the location with the UI5_DATA_DIR environment variable or\n" +
"the 'ui5 config set ui5DataDir' configuration option (see 'ui5 config --help').\n\n" +
"The following cache types are removed:\n" +
" UI5 Framework packages Downloaded UI5 library files " +
"(~/.ui5/framework/)\n" +
" Build cache (DB) Build data " +
"(~/.ui5/buildCache/)\n" +
" Orphaned framework data Incomplete directories from previously interrupted cleans\n" +
" (~/.ui5/.framework_to_delete_*/)"
);
},
middlewares: [baseMiddleware],
});
};

const LABEL_FRAMEWORK = "UI5 Framework packages";
const LABEL_BUILD = "Build cache (DB)";
// Pad labels to equal width for two-column alignment
const LABEL_WIDTH = Math.max(LABEL_FRAMEWORK.length, LABEL_BUILD.length);

/**
* Format a byte size as a human-readable string.
*
* @param {number} bytes Size in bytes
* @returns {string} Formatted size string
*/
function formatSize(bytes) {
if (bytes < 1024) {
return `${bytes} B`;
} else if (bytes < 1024 * 1024) {
return `${(bytes / 1024).toFixed(1)} KB`;
} else if (bytes < 1024 * 1024 * 1024) {
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
}

/**
* Format framework cache stats as a human-readable detail string.
* E.g. "1,189 versions of 155 libraries" or "1 version of 1 library".
*
* @param {number} libraryCount
* @param {number} versionCount
* @returns {string}
*/
function formatFrameworkStats(libraryCount, versionCount) {
const v = `${versionCount.toLocaleString("en-US")} ${versionCount === 1 ? "version" : "versions"}`;
const l = `${libraryCount.toLocaleString("en-US")} ${libraryCount === 1 ? "library" : "libraries"}`;
return `${v} of ${l}`;
}

/**
* Pad a label to the shared column width.
*
* @param {string} label
* @returns {string}
*/
function padLabel(label) {
return label.padEnd(LABEL_WIDTH);
}

/**
* Display information about the cached data that will be removed,
* including the absolute paths and details about the framework and build caches,
* and any orphaned staging directories from previously interrupted clean operations.
*
* @param {object} data
* @param {object|null} data.frameworkInfo
* @param {object|null} data.buildInfo
* @param {string|null} data.frameworkAbsPath
* @param {string|null} data.buildAbsPath
* @param {number} data.buildPreSize
* @param {Array<{absPath: string, libraryCount: number, versionCount: number}>} data.orphanedInfo
*/
async function displayCacheInfo({
frameworkInfo,
buildInfo,
frameworkAbsPath,
buildAbsPath,
buildPreSize,
orphanedInfo,
}) {
// Display items that will be removed
process.stderr.write(chalk.bold("\nThe following cached data will be removed:\n\n"));
if (frameworkInfo) {
const detail = formatFrameworkStats(frameworkInfo.libraryCount, frameworkInfo.versionCount);
process.stderr.write(
` ${chalk.yellow("•")} ${padLabel(LABEL_FRAMEWORK)} ${frameworkAbsPath} (${detail})\n`
);
}
if (buildInfo) {
const detail = buildPreSize > 0 ? formatSize(buildPreSize) : "";
process.stderr.write(
` ${chalk.yellow("•")} ${padLabel(LABEL_BUILD)} ${buildAbsPath} (${detail})\n`
);
}
if (orphanedInfo && orphanedInfo.length > 0) {
process.stderr.write(
` ${chalk.yellow("•")} ${chalk.bold("Orphaned framework data")}` +
` (incomplete previous clean — ` +
`${orphanedInfo.length} director${orphanedInfo.length === 1 ? "y" : "ies"})\n`
);
for (const orphan of orphanedInfo) {
const detail = formatFrameworkStats(orphan.libraryCount, orphan.versionCount);
process.stderr.write(` ${chalk.dim(orphan.absPath)} (${detail})\n`);
}
}
process.stderr.write("\n");
}

/**
* Display the result of the cache cleanup operation,
* including which caches were removed and their details,
* and any orphaned staging directories that were also cleaned up.
*
* @param {object} data
* @param {object|null} data.frameworkResult
* @param {object|null} data.buildResult
* @param {string|null} data.frameworkAbsPath
* @param {string|null} data.buildAbsPath
* @param {number} data.buildPreSize
* @param {Array<{absPath: string, libraryCount: number, versionCount: number}>} data.orphanedInfoWithAbsPaths
*/
async function displayCleanupResult({
frameworkResult,
buildResult,
frameworkAbsPath,
buildAbsPath,
buildPreSize,
orphanedInfoWithAbsPaths,
}) {
process.stderr.write("\n");
if (frameworkResult && frameworkAbsPath) {
const detail = formatFrameworkStats(
frameworkResult.libraryCount,
frameworkResult.versionCount,
);
process.stderr.write(
`${chalk.green("✓")} Removed ${chalk.bold(LABEL_FRAMEWORK)}` +
` (${frameworkAbsPath} · ${detail})\n`,
);
}
if (orphanedInfoWithAbsPaths && orphanedInfoWithAbsPaths.length > 0) {
process.stderr.write(
`${chalk.green("✓")} Removed ${chalk.bold("Orphaned framework data")}` +
` (${orphanedInfoWithAbsPaths.length}` +
` director${orphanedInfoWithAbsPaths.length === 1 ? "y" : "ies"})\n`
);
for (const orphan of orphanedInfoWithAbsPaths) {
const detail = formatFrameworkStats(orphan.libraryCount, orphan.versionCount);
process.stderr.write(` ${chalk.dim(orphan.absPath)} (${detail})\n`);
}
}
if (buildResult) {
// Use pre-clean size so the number matches what was shown before confirmation
const detail = buildPreSize > 0 ? formatSize(buildPreSize) : "";
process.stderr.write(
`${chalk.green("✓")} Removed ${chalk.bold(LABEL_BUILD)}` +
` (${buildAbsPath}${detail ? ` · ${detail}` : ""})\n`,
);
}

// Success summary
const cleaned = [];
if (frameworkResult) {
cleaned.push(LABEL_FRAMEWORK);
}
if (orphanedInfoWithAbsPaths && orphanedInfoWithAbsPaths.length > 0) {
cleaned.push("Orphaned framework data");
}
if (buildResult) {
cleaned.push(LABEL_BUILD);
}
process.stderr.write(
`\n${chalk.green("Success:")} Cleaned ${cleaned.join(" and ")}\n`,
);
}

/**
* Prompt the user for confirmation before proceeding with cache cleanup.
*
* @param {Yargs.Arguments} argv
* @returns {Promise<boolean>} Confirmation result
*/
async function getConfirmation(argv) {
if (argv.yes) {
return true;
}
const {default: yesno} = await import("yesno");
return yesno({
question: "Do you want to continue? (y/N)",
defaultValue: false
});
}

async function handleCache(argv) {
const ui5DataDir = await resolveUi5DataDir();
const lockDir = getLockDir(ui5DataDir);
const lockPath = path.join(lockDir, CLEANUP_LOCK_NAME);

// Acquire first, then check — ensures concurrent framework operations will see
// the cleanup lock and abort before the actual cleanup.
const releaseCleanupLock = await acquireLock(lockPath);

try {
// Abort early if a lock is active — before prompting the user.
if (await hasActiveLocks(ui5DataDir, {exclude: CLEANUP_LOCK_NAME})) {
process.stderr.write(
`${chalk.red("Error:")} A UI5 server or build process is currently running. ` +
"Cannot clean the cache while it is in use. " +
"Please stop all running 'ui5 serve' or wait for 'ui5 build' processes to finish.\n"
);
process.exitCode = 1;
return;
}

process.stderr.write(`Checking cache at ${chalk.bold(ui5DataDir)} …\n`);

const [frameworkInfo, buildInfo, orphanedInfo] = await Promise.all([
frameworkCache.getCacheInfo(ui5DataDir),
CacheManager.getCacheInfo(ui5DataDir),
frameworkCache.getOrphanedInfo(ui5DataDir),
]);

if (!frameworkInfo && !buildInfo && orphanedInfo.length === 0) {
process.stderr.write("Nothing to clean\n");
return;
}

// Compute absolute paths once — producers return relative sub-path segments
const frameworkAbsPath = frameworkInfo ? path.join(ui5DataDir, frameworkInfo.path) : null;
const buildAbsPath = buildInfo ? path.join(ui5DataDir, buildInfo.path) : null;
const buildPreSize = buildInfo?.size ?? 0;
const preCleanOrphanedInfo = orphanedInfo.map(
(o) => ({...o, absPath: path.join(ui5DataDir, o.path)})
);

await displayCacheInfo({
frameworkInfo,
buildInfo,
frameworkAbsPath,
buildAbsPath,
buildPreSize,
orphanedInfo: preCleanOrphanedInfo,
});

const confirmed = await getConfirmation(argv);
if (!confirmed) {
process.stderr.write("Cancelled\n");
return;
}

const [frameworkResult, buildResult] = await Promise.all([
frameworkCache.cleanCache(ui5DataDir),
CacheManager.cleanCache(ui5DataDir),
]);

// Release the lock. Critical sections are done.
// The finally block will call releaseCleanupLock() again, which is a no-op (idempotent).
releaseCleanupLock();

// Clean additional resources that are safe to run outside the lock.
// For the framework cache this handles orphaned staging dirs from previous
// interrupted cleans. These are fully independent of any active operation.
const [additionalFrameworkResult] = await Promise.all([
frameworkCache.cleanAdditional(ui5DataDir),
// The same interface. No-op
CacheManager.cleanAdditional(ui5DataDir),
]);
const orphanedInfoWithAbsPaths = additionalFrameworkResult.map(
(o) => ({...o, absPath: path.join(ui5DataDir, o.path)})
);

await displayCleanupResult({
frameworkResult,
buildResult,
frameworkAbsPath,
buildAbsPath,
buildPreSize,
orphanedInfoWithAbsPaths,
});
} finally {
releaseCleanupLock();
}
}

export default cacheCommand;
3 changes: 3 additions & 0 deletions packages/cli/lib/cli/commands/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ tree.handler = async function(argv) {
`Dependency graph generation took ${chalk.bold(elapsedTime)}`));
process.stderr.write("\n");
}

// Release the process-coordination lock held by the graph
graph.destroy();
};

async function getElapsedTime(startTime) {
Expand Down
Loading
Loading