Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/long-dolls-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'rock': patch
'create-rock': patch
---

feat: add ccache support in clean command
32 changes: 29 additions & 3 deletions packages/cli/src/lib/plugins/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const CLEANUP_TASK_NAMES = [
'android',
'gradle',
'cocoapods',
'ccache',
'metro',
'watchman',
'node_modules',
Expand Down Expand Up @@ -97,6 +98,20 @@ function hasMetroProject(projectRoot: string): boolean {
return false;
}

/**
* Checks if ccache is installed on the system.
* @returns Promise that resolves to true if ccache is available, false otherwise
*/
async function isCCacheInstalled(): Promise<boolean> {
try {
await spawn('which', ['ccache']);
return true;
} catch (error) {
logger.debug(`Failed to find ccache binary: ${error}`);
return false;
}
}

/**
* Cleans temporary directories that match a given pattern.
* @param pattern - The pattern to match temporary directory names
Expand Down Expand Up @@ -135,10 +150,10 @@ function cleanDirectories(directories: string[], baseDir: string): void {
* @param options - Clean options that affect task creation
* @returns Array of cleanup tasks with their configurations
*/
function createCleanupTasks(
async function createCleanupTasks(
projectRoot: string,
options: CleanOptions,
): CleanupTask[] {
): Promise<CleanupTask[]> {
const tasks: CleanupTask[] = [];

// Android cleanup
Expand Down Expand Up @@ -207,6 +222,17 @@ function createCleanupTasks(
},
});

const hasCCache = await isCCacheInstalled();
// CCache cleanup (only if ccache is installed)
tasks.push({
name: 'ccache',
description: '[C/C++] CCache compiler cache',
enabled: hasCCache,
action: async () => {
await spawn('ccache', ['--clear']);
},
});

// Watchman cleanup (only for Metro projects)
const hasMetro = hasMetroProject(projectRoot);
tasks.push({
Expand Down Expand Up @@ -302,7 +328,7 @@ function createCleanupTasks(
* @param options - Clean options that determine which tasks to run
*/
async function cleanProject(projectRoot: string, options: CleanOptions) {
const tasks = createCleanupTasks(projectRoot, options);
const tasks = await createCleanupTasks(projectRoot, options);

let selectedTasks: CleanupTask[];
const availableTasks = tasks.filter((task) => task.enabled);
Expand Down