Skip to content

Commit bf62470

Browse files
authored
redux (#1666)
1 parent b336cb0 commit bf62470

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/build.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {createHash} from "node:crypto";
22
import {existsSync} from "node:fs";
3-
import {access, constants, copyFile, readFile, realpath, stat, writeFile} from "node:fs/promises";
3+
import {access, constants, copyFile, readFile, stat, writeFile} from "node:fs/promises";
44
import {basename, dirname, extname, join} from "node:path/posix";
55
import type {Config} from "./config.js";
66
import {CliError, isEnoent} from "./error.js";
7-
import {getClientPath, maybeStat, prepareOutput, visitMarkdownFiles} from "./files.js";
7+
import {getClientPath, prepareOutput, visitMarkdownFiles} from "./files.js";
88
import {getModuleHash, readJavaScript} from "./javascript/module.js";
99
import {transpileModule} from "./javascript/transpile.js";
1010
import type {Logger, Writer} from "./logger.js";
@@ -359,15 +359,15 @@ export class FileBuildEffects implements BuildEffects {
359359
async copyFile(sourcePath: string, outputPath: string): Promise<void> {
360360
const destination = join(this.outputRoot, outputPath);
361361
this.logger.log(destination);
362-
await noClobber(destination);
363362
await prepareOutput(destination);
363+
if (existsSync(destination)) throw new Error(`file conflict: ${outputPath}`);
364364
await copyFile(sourcePath, destination);
365365
}
366366
async writeFile(outputPath: string, contents: string | Buffer): Promise<void> {
367367
const destination = join(this.outputRoot, outputPath);
368368
this.logger.log(destination);
369-
await noClobber(destination);
370369
await prepareOutput(destination);
370+
if (existsSync(destination)) throw new Error(`file conflict: ${outputPath}`);
371371
await writeFile(destination, contents);
372372
}
373373
async writeBuildManifest(buildManifest: BuildManifest): Promise<void> {
@@ -380,13 +380,3 @@ export class FileBuildEffects implements BuildEffects {
380380
export interface BuildManifest {
381381
pages: {path: string; title: string | null}[];
382382
}
383-
384-
// Asserts that the destination file is not already present. This can happen if
385-
// the same file is referenced with inconsistent naming (e.g. upper vs.
386-
// lowercase), and would result in a broken site.
387-
async function noClobber(path) {
388-
if (await maybeStat(path)) {
389-
const real = (await realpath(path)).slice((await realpath(".")).length + 1);
390-
throw new Error(`${faint("File name conflict over")} ${real}.`);
391-
}
392-
}

0 commit comments

Comments
 (0)