less.js
less.js copied to clipboard
inconsistent paths after `render` in `imports` on windows and linux
In less-loader we have custom FileManager plugin (https://github.com/webpack-contrib/less-loader/blob/master/src/utils.js#L27).
Algorithm (https://github.com/webpack-contrib/less-loader/blob/master/src/utils.js#L87):
- try to load less file using built-in
FileManager, if it is fail - try to load less file using webpack resolver
We have a code:
@import '~bootstrap-less-port/less/bootstrap.less'; // means load from `node_modules`
So less failed to resolve, and webpack resolver return C:\path\to\projects\node_modules\bootstrap-less-port\less\bootstrap.less
No problems on this step. Compilation works fine.
After render (https://github.com/webpack-contrib/less-loader/blob/master/src/index.js#L38), we adding all resolved files to watcher (for recompilation them after change). But imports on windows contains forward slashes:
[
'C:/Users/IEUser/test-webpack-watch/node_modules/bootstrap-less-port/less/bootstrap.less',
'C:\\Users\\IEUser\\test-webpack-watch\\node_modules\\bootstrap-less-port\\less\\_functions.less',
// ...
]
On linux and macos no problems:
[
'/home/evilebottnawi/IdeaProjects/test-webpack-watch/node_modules/bootstrap-less-port/less/bootstrap.less',
'/home/evilebottnawi/IdeaProjects/test-webpack-watch/node_modules/bootstrap-less-port/less/_functions.less',
// ...
]
If we change source code to:
@import '../node_modules/bootstrap-less-port/less/bootstrap.less';
We don't have this problem.
Ref: https://github.com/webpack-contrib/less-loader/issues/357
Reproducible repo:
https://github.com/Kukkimonsuta/test-webpack-watch
Just add console.log here https://github.com/webpack-contrib/less-loader/blob/master/src/index.js#L38
Same problem for catch(error) in chain render.then().catch(error), error.filename contains forward slashes
What happens with:
@import 'bootstrap-less-port/less/bootstrap.less'
?
All fine, but the problem is not in @import, the problem - when you return absolute windows path to FileManager it is always put invalid slashes in imports
This would be something for a proficient Windows user to take on. Unfortunately, we can't really run automated tests on this because those are done in Linux environments. I assume there's probably a simple way / Node utility to normalize Windows paths.
@matthew-dean we can automate tests using github-actions on linux and on windows and on macos, for node we can use something like path.normalize
@evilebottnawi If you know how to do that, great! PRs welcome!