mirror of
https://github.com/status-im/sourcecred.git
synced 2025-01-11 05:06:57 +00:00
86c1b2e068
Test Plan: Run `mkdir /tmp/out; cd /tmp/out; python -m SimpleHTTPServer`. In another shell, run `./scripts/build_static_site.sh --target /tmp/out`. Then, `curl localhost:8000`. Before this commit, this would have yielded an `OSError` because the cwd of the Python process had been removed. As of this commit, it works fine. Also, run `git grep -c rimraf` and note only `yarn.lock:15`. wchargin-branch: webpack-empty-build-directory
39 lines
1.3 KiB
JavaScript
39 lines
1.3 KiB
JavaScript
// @flow
|
|
|
|
const fs = require("fs-extra");
|
|
const path = require("path");
|
|
|
|
// Note: the following type-import just resolves to `any`.
|
|
/*:: import type {Compiler} from "webpack"; */
|
|
|
|
module.exports = class RemoveBuildDirectoryPlugin {
|
|
apply(compiler /*: Compiler */) {
|
|
if (compiler.hooks) {
|
|
console.warn(
|
|
"" +
|
|
"You appear to be running Webpack >= 4. " +
|
|
"The RemoveBuildDirectoryPlugin should be forward-compatible, " +
|
|
"but you should update it to use the new APIs. See " +
|
|
"<https://github.com/webpack/webpack/releases/tag/v4.0.0-beta.0> " +
|
|
"for details."
|
|
);
|
|
}
|
|
compiler.plugin("compile", () => {
|
|
const outputPath = compiler.options.output.path;
|
|
// If a build config has no `output.path` property, and no
|
|
// `--output-path` is passed on the command line, then Webpack
|
|
// will default to building into the current directory. Removing
|
|
// the whole Git repository would be mighty rude, so we protect
|
|
// against that case.
|
|
if (fs.existsSync(path.join(outputPath, ".git"))) {
|
|
throw new Error(
|
|
"Refusing to remove build directory with a Git repository: " +
|
|
outputPath
|
|
);
|
|
}
|
|
console.warn("Removing contents of build directory: " + outputPath);
|
|
fs.emptyDirSync(outputPath);
|
|
});
|
|
}
|
|
};
|