Skip to content

Commit

Permalink
don't clobber an existing file when building the site (#1374)
Browse files Browse the repository at this point in the history
closes #1367
supersedes #1369
supersedes #1373

redux (#1666)
  • Loading branch information
Fil authored Sep 17, 2024
1 parent e467a6b commit 2019dd3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {createHash} from "node:crypto";
import {existsSync} from "node:fs";
import {copyFile, readFile, rm, stat, writeFile} from "node:fs/promises";
import {basename, dirname, extname, join} from "node:path/posix";
import type {Config} from "./config.js";
Expand Down Expand Up @@ -424,12 +425,14 @@ export class FileBuildEffects implements BuildEffects {
const destination = join(this.outputRoot, outputPath);
this.logger.log(destination);
await prepareOutput(destination);
if (existsSync(destination)) throw new Error(`file conflict: ${outputPath}`);
await copyFile(sourcePath, destination);
}
async writeFile(outputPath: string, contents: string | Buffer): Promise<void> {
const destination = join(this.outputRoot, outputPath);
this.logger.log(destination);
await prepareOutput(destination);
if (existsSync(destination)) throw new Error(`file conflict: ${outputPath}`);
await writeFile(destination, contents);
}
async writeBuildManifest(buildManifest: BuildManifest): Promise<void> {
Expand Down

0 comments on commit 2019dd3

Please sign in to comment.