| 229 | } |
| 230 | |
| 231 | private async deleteRemovedFiles( |
| 232 | targetDir: string, |
| 233 | previousSourceFiles: Set<string>, |
| 234 | currentSourceFiles: Set<string>, |
| 235 | result: SyncResult, |
| 236 | ): Promise<void> { |
| 237 | for (const relativePath of previousSourceFiles) { |
| 238 | if (currentSourceFiles.has(relativePath)) { |
| 239 | continue |
| 240 | } |
| 241 | |
| 242 | const targetPath = path.join(targetDir, relativePath) |
| 243 | |
| 244 | try { |
| 245 | if (!fs.existsSync(targetPath)) { |
| 246 | continue |
| 247 | } |
| 248 | |
| 249 | const stats = await fs.promises.stat(targetPath) |
| 250 | if (!stats.isFile()) { |
| 251 | continue |
| 252 | } |
| 253 | |
| 254 | await fs.promises.unlink(targetPath) |
| 255 | result.deleted.push(relativePath) |
| 256 | } catch (error) { |
| 257 | result.errors.push( |
| 258 | `${relativePath}: ${error instanceof Error ? error.message : String(error)}`, |
| 259 | ) |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |