Skip to content

Commit 0af84be

Browse files
Copilothotlong
andcommitted
refactor: address code review feedback for removeDirRecursive
- Add comprehensive JSDoc with @param and @throws - Add error context for failing subdirectories - Keep fs.rmdirSync for directory removal (most reliable approach) Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent e0ef84d commit 0af84be

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/spec/scripts/build-schemas.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ function writeFileWithRetry(filePath: string, content: string, retries = MAX_RET
7777
/**
7878
* Recursively remove directory with retry logic
7979
* More robust than fs.rmSync for handling ENOTEMPTY errors in CI
80+
*
81+
* @param dirPath - The path to the directory to remove
82+
* @param retries - Maximum number of retry attempts (default: MAX_RETRIES)
83+
* @throws {Error} When directory cannot be removed after all retries are exhausted
8084
*/
8185
function removeDirRecursive(dirPath: string, retries = MAX_RETRIES): void {
8286
for (let attempt = 0; attempt < retries; attempt++) {
@@ -94,7 +98,11 @@ function removeDirRecursive(dirPath: string, retries = MAX_RETRIES): void {
9498

9599
if (entry.isDirectory()) {
96100
// Recursively remove subdirectory
97-
removeDirRecursive(fullPath, retries);
101+
try {
102+
removeDirRecursive(fullPath, retries);
103+
} catch (error) {
104+
throw new Error(`Failed to remove subdirectory ${fullPath}: ${error}`);
105+
}
98106
} else {
99107
// Remove file with retry
100108
for (let fileRetry = 0; fileRetry < retries; fileRetry++) {
@@ -112,6 +120,7 @@ function removeDirRecursive(dirPath: string, retries = MAX_RETRIES): void {
112120
}
113121

114122
// Now remove the empty directory
123+
// Using rmdirSync for removing empty directories (works reliably across Node versions)
115124
fs.rmdirSync(dirPath);
116125
return; // Success
117126

0 commit comments

Comments
 (0)