Skip to content

util.join() doesn't handle absolute path on Windows correctly #355

Open
@mutoo

Description

@mutoo

We use the Webpack pipeline on Windows with sass-loader, postcss-loader, and css-loader. Then we found the generated source paths went crazy: F:\Projects\web-project-boilerplate\src\scss\index.scss just becomes F:/Projects/web-project-boilerplate/src/scss/F:/Projects/web-project-boilerplate/src/scss/F:/Projects/web-project-boilerplate/src/scss/index.scss.

As I followed the codebase in the pipeline, I noticed that the sass-loader use relative path, then the postcss-loader and css-loader turn to use absolute path for "sources" field in the sourceMap. In addition, the absolute path on Windows starts with a symbol of the disk driver, e.g. F: in our case. When it comes to sourceMap's util.join(), it only detects absolute path starts with /

const joined = aPath.charAt(0) === "/"

So it joins multiple paths across the loaders.

Also, the util.isAbsolute doesn't deal with the Windows absolute path as well.

return aPath.charAt(0) === "/" || urlRegexp.test(aPath);

Appendix:
Here is a case of how expressjs test the absolute path:

exports.isAbsolute = function(path){
  if ('/' === path[0]) return true;
  if (':' === path[1] && ('\\' === path[2] || '/' === path[2])) return true; // Windows device path
  if ('\\\\' === path.substring(0, 2)) return true; // Microsoft Azure absolute path
};

I'm not sure we need to handle the azure absolute path, but I would be better if we had window device path included.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    featNew feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions