Skip to content

Commit 2019dd3

Browse files
authored
don't clobber an existing file when building the site (#1374)
closes #1367 supersedes #1369 supersedes #1373 redux (#1666)
1 parent e467a6b commit 2019dd3

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/build.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {createHash} from "node:crypto";
2+
import {existsSync} from "node:fs";
23
import {copyFile, readFile, rm, stat, writeFile} from "node:fs/promises";
34
import {basename, dirname, extname, join} from "node:path/posix";
45
import type {Config} from "./config.js";
@@ -424,12 +425,14 @@ export class FileBuildEffects implements BuildEffects {
424425
const destination = join(this.outputRoot, outputPath);
425426
this.logger.log(destination);
426427
await prepareOutput(destination);
428+
if (existsSync(destination)) throw new Error(`file conflict: ${outputPath}`);
427429
await copyFile(sourcePath, destination);
428430
}
429431
async writeFile(outputPath: string, contents: string | Buffer): Promise<void> {
430432
const destination = join(this.outputRoot, outputPath);
431433
this.logger.log(destination);
432434
await prepareOutput(destination);
435+
if (existsSync(destination)) throw new Error(`file conflict: ${outputPath}`);
433436
await writeFile(destination, contents);
434437
}
435438
async writeBuildManifest(buildManifest: BuildManifest): Promise<void> {

0 commit comments

Comments
 (0)