1
1
import { createHash } from "node:crypto" ;
2
2
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" ;
4
4
import { basename , dirname , extname , join } from "node:path/posix" ;
5
5
import type { Config } from "./config.js" ;
6
6
import { CliError , isEnoent } from "./error.js" ;
7
- import { getClientPath , maybeStat , prepareOutput , visitMarkdownFiles } from "./files.js" ;
7
+ import { getClientPath , prepareOutput , visitMarkdownFiles } from "./files.js" ;
8
8
import { getModuleHash , readJavaScript } from "./javascript/module.js" ;
9
9
import { transpileModule } from "./javascript/transpile.js" ;
10
10
import type { Logger , Writer } from "./logger.js" ;
@@ -359,15 +359,15 @@ export class FileBuildEffects implements BuildEffects {
359
359
async copyFile ( sourcePath : string , outputPath : string ) : Promise < void > {
360
360
const destination = join ( this . outputRoot , outputPath ) ;
361
361
this . logger . log ( destination ) ;
362
- await noClobber ( destination ) ;
363
362
await prepareOutput ( destination ) ;
363
+ if ( existsSync ( destination ) ) throw new Error ( `file conflict: ${ outputPath } ` ) ;
364
364
await copyFile ( sourcePath , destination ) ;
365
365
}
366
366
async writeFile ( outputPath : string , contents : string | Buffer ) : Promise < void > {
367
367
const destination = join ( this . outputRoot , outputPath ) ;
368
368
this . logger . log ( destination ) ;
369
- await noClobber ( destination ) ;
370
369
await prepareOutput ( destination ) ;
370
+ if ( existsSync ( destination ) ) throw new Error ( `file conflict: ${ outputPath } ` ) ;
371
371
await writeFile ( destination , contents ) ;
372
372
}
373
373
async writeBuildManifest ( buildManifest : BuildManifest ) : Promise < void > {
@@ -380,13 +380,3 @@ export class FileBuildEffects implements BuildEffects {
380
380
export interface BuildManifest {
381
381
pages : { path : string ; title : string | null } [ ] ;
382
382
}
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