Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 13 commits into from
Jun 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading