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: should not fail when output directory is the root directory #10545

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/util/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ exports.dirname = dirname;
const mkdirp = (fs, p, callback) => {
fs.mkdir(p, err => {
if (err) {
if (path.resolve(p) === path.resolve("/")) {
// whatever the error code is, calling mkdirp on the root directory should not throw
callback();
return;
}

if (err.code === "ENOENT") {
const dir = dirname(fs, p);
if (dir === p) {
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/output/root-dir/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it("should compile", done => {
done();
});
8 changes: 8 additions & 0 deletions test/configCases/output/root-dir/test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require("path");
const outputDirectory = __dirname.replace("configCases", "js/config");

module.exports = {
findBundle: function() {
return [path.relative(outputDirectory, "/tmp/bundle.js")];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I return an absolute path here directly, the _require function in ConfigTestCases.test.js would require the bundle directly, making it lack of essential context utilities like the it function.

So the only workaround I found is to calculate the relative path of /tmp/bundle.js.

}
};
7 changes: 7 additions & 0 deletions test/configCases/output/root-dir/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
entry: "./index.js",
output: {
path: "/",
filename: "tmp/bundle.js"
}
};