(targetPath)
| 127 | * @param targetPath The path to the file or directory to remove. |
| 128 | */ |
| 129 | const removeFileOrDirectory = async (targetPath) => { |
| 130 | try { |
| 131 | const stats = await fsp.lstat(targetPath) |
| 132 | |
| 133 | // Fail silently if the file or directory does not exist |
| 134 | if (!stats) { |
| 135 | return |
| 136 | } |
| 137 | |
| 138 | if (stats.isDirectory()) { |
| 139 | // If the target is a directory, recursively remove all its contents |
| 140 | const entries = await fsp.readdir(targetPath, { withFileTypes: true }) |
| 141 | await Promise.all( |
| 142 | entries.map(async (entry) => { |
| 143 | const fullPath = path.join(targetPath, entry.name) |
| 144 | await removeFileOrDirectory(fullPath) |
| 145 | }), |
| 146 | ) |
| 147 | await fsp.rmdir(targetPath) |
| 148 | } else { |
| 149 | // If the target is a file, delete it |
| 150 | await fsp.unlink(targetPath) |
| 151 | } |
| 152 | } catch (error) { |
| 153 | // Handle errors, such as 'ENOENT' (no such file or directory) |
| 154 | if (error.code !== 'ENOENT') { |
| 155 | throw error |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Loads YAML content with specified options. |
no outgoing calls
no test coverage detected
searching dependent graphs…