fix(core): throw error if build folder already exists on initial clean (#9112)

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
thedevwonder 2023-06-30 21:28:24 +05:30 committed by GitHub
parent c8e7ce33f5
commit 8ea1945f35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,7 @@
// More context: https://github.com/facebook/docusaurus/pull/1839
import path from 'path';
import fs from 'fs-extra';
import {sync as delSync} from 'del';
import type {Compiler, Stats} from 'webpack';
@ -152,6 +153,17 @@ export default class CleanWebpackPlugin {
return;
}
if (
// eslint-disable-next-line no-restricted-properties
fs.pathExistsSync(this.outputPath) &&
// eslint-disable-next-line no-restricted-properties
fs.statSync(this.outputPath).isFile()
) {
throw new Error(
`A file '${this.outputPath}' already exists. Docusaurus needs this directory to save the build output. Either remove/change the file or choose a different build directory via '--out-dir'.`,
);
}
this.initialClean = true;
this.removeFiles(this.cleanOnceBeforeBuildPatterns);