Skip to content

Commit

Permalink
fix(core): throw error if build folder already exists on initial clean (
Browse files Browse the repository at this point in the history
#9112)

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
  • Loading branch information
thedevwonder and Josh-Cena authored Jun 30, 2023
1 parent c8e7ce3 commit 8ea1945
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/docusaurus/src/webpack/plugins/CleanWebpackPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8ea1945

Please sign in to comment.