Skip to content

fix(output-file-system): change from backslash to forward slash in join #804

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

Closed
wants to merge 1 commit into from

Conversation

soilSpoon
Copy link

@soilSpoon soilSpoon commented Dec 21, 2020

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

In webpack, if there is a join method of outputFileSystem, use the join method. However, if you use the join method in windows os, a problem occurs when the path is relative.
Ex)
before join:
/app/js
after join:
\app\join

If it changes as above, the following error occurs.

D:\foo\node_modules\webpack\lib\util\fs.js:141
                throw new Error(
                ^

Error: \js\app.js is neither a posix nor a windows path, and there is no 'dirname' method defined in the file system
    at dirname (D:\foo\node_modules\webpack\lib\util\fs.js:141:9)
    at D:\foo\node_modules\webpack\lib\Compiler.js:790:19
    at arrayIterator (D:\foo\node_modules\neo-async\async.js:3467:9)
    at timesSync (D:\foo\node_modules\neo-async\async.js:2297:7)
    at Object.eachLimit (D:\foo\node_modules\neo-async\async.js:3463:5)
    at emitFiles (D:\foo\node_modules\webpack\lib\Compiler.js:536:13)
    at D:\foo\node_modules\webpack\lib\util\fs.js:182:5
    at Immediate.<anonymous> (D:\foo\node_modules\memfs\lib\volume.js:684:17)
    at processImmediate (internal/timers.js:461:21)

This PR solves that problem.

Breaking Changes

The join method of outputFileSystem returns all backslashes replaced with slashes.

Additional Info

https://github.com/webpack/webpack/blob/master/lib/util/fs.js#L133-L145

@soilSpoon soilSpoon requested a review from hiroppy as a code owner December 21, 2020 18:03
@codecov
Copy link

codecov bot commented Dec 21, 2020

Codecov Report

Merging #804 (093b4d5) into master (7a888f8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #804   +/-   ##
=======================================
  Coverage   99.22%   99.23%           
=======================================
  Files          10       10           
  Lines         259      261    +2     
  Branches       83       83           
=======================================
+ Hits          257      259    +2     
  Misses          2        2           
Impacted Files Coverage Δ
src/utils/setupOutputFileSystem.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a888f8...093b4d5. Read the comment docs.

@alexander-akait
Copy link
Member

alexander-akait commented Dec 21, 2020

Please provide a problem

@alexander-akait
Copy link
Member

Also this code for webpack@4

@@ -27,7 +27,9 @@ export default function setupOutputFileSystem(context) {
} else {
outputFileSystem = createFsFromVolume(new Volume());
// TODO: remove when we drop webpack@4 support
outputFileSystem.join = path.join.bind(path);
const newPath = Object.assign({}, path);
newPath.join = (...files) => path.join(...files).replace(/[\\/]+/g, '/');
Copy link
Member

Choose a reason for hiding this comment

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

Using regexp to change \ on / is bad idea

Copy link
Author

Choose a reason for hiding this comment

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

Suggested change
newPath.join = (...files) => path.join(...files).replace(/[\\/]+/g, '/');
newPath.join = (...files) => path.join(...files).replaceAll('\\', '/');

Would this be better?

@soilSpoon
Copy link
Author

soilSpoon commented Dec 21, 2020

Please provide a problem

@alexander-akait Can you please let me know what more explanations are needed?

@soilSpoon soilSpoon changed the title fix(outputFileSystem): change from backslash to forward slash in join fix(output-file-system): change from backslash to forward slash in join Dec 22, 2020
@alexander-akait
Copy link
Member

Please show me a problem why you need to change it

@alexander-akait
Copy link
Member

Simple reproducible test repo

@soilSpoon
Copy link
Author

@alexander-akait Sorry i think i was mistaken

@soilSpoon soilSpoon closed this Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants