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

Conversation

sodatea
Copy link
Contributor

@sodatea sodatea commented Mar 12, 2020

Fixes #10544.

Though the EISDIR error code is not mentioned in the POSIX standard,
FreeBSD and memfs both throw this error when trying to run mkdir on
/. So essentially we should treat it the same as EEXIST.

References:

What kind of change does this PR introduce?

A bugfix

Did you add tests for your changes?

I'm not sure how I should add tests, because this issue only happens on BSD systems.

Does this PR introduce a breaking change?

No

What needs to be documented once your changes are merged?

Nothing

Fixes webpack#10544.

Though the `EISDIR` error code is not mentioned in the POSIX standard,
FreeBSD and memfs both throws this error when trying to run `mkdir` on
`/`. So essentially we should treat it the same as `EEXIST`.

References:
* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=59739
* streamich/memfs#326
@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Please add test


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.

@alexander-akait
Copy link
Member

/cc @sodatea friendly ping

@sodatea
Copy link
Contributor Author

sodatea commented Jul 10, 2020

I think I need to work out a more generic way to deal with the root directory case, instead of relying on the error code because different OSes😅
I'll try to fix it this weekend.

@sodatea sodatea changed the title fix: also check for "EISDIR" in mkdirp fix: should not fail when output directory is the root directory Jul 14, 2020
lib/util/fs.js Outdated
@@ -115,6 +115,11 @@ exports.dirname = dirname;
* @returns {void}
*/
const mkdirp = (fs, p, callback) => {
if (path.resolve(p) === path.resolve("/")) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you really need so many path.resolve? They have a performance cost. I think p is always a absolute path anyway. What is about windows absolute paths?

Suggested change
if (path.resolve(p) === path.resolve("/")) {
if (/^(\/|[A-Za-z]:\\?|\\\\[^\\]+\\?)$/.test(p)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will fail edge cases like multiple trailing backslashes (such as C:\\\\).

Though, we can avoid the performance overhead by moving the logic into the error handling part.

@webpack-bot
Copy link
Contributor

@sodatea Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webpack 5 can't set output path to /
4 participants