less-loader
Advanced tools
Comparing version 7.0.0 to 7.0.1
@@ -5,2 +5,9 @@ # Changelog | ||
### [7.0.1](https://github.com/webpack-contrib/less-loader/compare/v7.0.0...v7.0.1) (2020-09-03) | ||
### Bug Fixes | ||
* normalize `sources` in source maps ([877d99a](https://github.com/webpack-contrib/less-loader/commit/877d99a380deac92e07c41429a9b0c5f0bba2710)) | ||
## [7.0.0](https://github.com/webpack-contrib/less-loader/compare/v6.2.0...v7.0.0) (2020-08-25) | ||
@@ -7,0 +14,0 @@ |
@@ -24,3 +24,3 @@ "use strict"; | ||
function lessLoader(source) { | ||
async function lessLoader(source) { | ||
const options = (0, _loaderUtils.getOptions)(this); | ||
@@ -33,2 +33,10 @@ (0, _schemaUtils.default)(_options.default, options, { | ||
const lessOptions = (0, _utils.getLessOptions)(this, options); | ||
const useSourceMap = typeof options.sourceMap === 'boolean' ? options.sourceMap : this.sourceMap; | ||
if (useSourceMap) { | ||
lessOptions.sourceMap = { | ||
outputSourceFiles: true | ||
}; | ||
} | ||
let data = source; | ||
@@ -40,26 +48,37 @@ | ||
_less.default.render(data, lessOptions).then(({ | ||
css, | ||
map, | ||
imports | ||
}) => { | ||
imports.forEach(item => { | ||
if ((0, _utils.isUnsupportedUrl)(item)) { | ||
return; | ||
} // `less` return forward slashes on windows when `webpack` resolver return an absolute windows path in `WebpackFileManager` | ||
// Ref: https://github.com/webpack-contrib/less-loader/issues/357 | ||
let result; | ||
this.addDependency(_path.default.normalize(item)); | ||
}); | ||
callback(null, css, typeof map === 'string' ? JSON.parse(map) : map); | ||
}).catch(lessError => { | ||
if (lessError.filename) { | ||
try { | ||
result = await _less.default.render(data, lessOptions); | ||
} catch (error) { | ||
if (error.filename) { | ||
// `less` return forward slashes on windows when `webpack` resolver return an absolute windows path in `WebpackFileManager` | ||
// Ref: https://github.com/webpack-contrib/less-loader/issues/357 | ||
this.addDependency(_path.default.normalize(lessError.filename)); | ||
this.addDependency(_path.default.normalize(error.filename)); | ||
} | ||
callback(new _LessError.default(lessError)); | ||
callback(new _LessError.default(error)); | ||
return; | ||
} | ||
const { | ||
css, | ||
imports | ||
} = result; | ||
imports.forEach(item => { | ||
if ((0, _utils.isUnsupportedUrl)(item)) { | ||
return; | ||
} // `less` return forward slashes on windows when `webpack` resolver return an absolute windows path in `WebpackFileManager` | ||
// Ref: https://github.com/webpack-contrib/less-loader/issues/357 | ||
this.addDependency(_path.default.normalize(item)); | ||
}); | ||
let map = typeof result.map === 'string' ? JSON.parse(result.map) : result.map; | ||
if (map && useSourceMap) { | ||
map = (0, _utils.normalizeSourceMap)(map, this.rootContext); | ||
} | ||
callback(null, css, map); | ||
} | ||
@@ -66,0 +85,0 @@ |
@@ -19,9 +19,9 @@ "use strict"; | ||
static getFileExcerptIfPossible(lessErr) { | ||
if (typeof lessErr.extract === 'undefined') { | ||
static getFileExcerptIfPossible(lessError) { | ||
if (typeof lessError.extract === 'undefined') { | ||
return []; | ||
} | ||
const excerpt = lessErr.extract.slice(0, 2); | ||
const column = Math.max(lessErr.column - 1, 0); | ||
const excerpt = lessError.extract.slice(0, 2); | ||
const column = Math.max(lessError.column - 1, 0); | ||
@@ -28,0 +28,0 @@ if (typeof excerpt[0] === 'undefined') { |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.isUnsupportedUrl = isUnsupportedUrl; | ||
exports.normalizeSourceMap = normalizeSourceMap; | ||
@@ -25,5 +26,5 @@ var _path = _interopRequireDefault(require("path")); | ||
const isModuleImport = /^~([^/]+|[^/]+\/|@[^/]+[/][^/]+|@[^/]+\/?|@[^/]+[/][^/]+\/)$/; // `[drive_letter]:\` + `\\[server]\[sharename]\` | ||
const IS_SPECIAL_MODULE_IMPORT = /^~[^/]+$/; // `[drive_letter]:\` + `\\[server]\[sharename]\` | ||
const isNativeWin32Path = /^[a-zA-Z]:[/\\]|^\\\\/i; | ||
const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i; | ||
/** | ||
@@ -46,3 +47,3 @@ * Creates a Less plugin that uses webpack's resolving engine that is provided by the loaderContext. | ||
supports(filename) { | ||
if (filename[0] === '/' || isNativeWin32Path.test(filename)) { | ||
if (filename[0] === '/' || IS_NATIVE_WIN32_PATH.test(filename)) { | ||
return true; | ||
@@ -97,3 +98,3 @@ } | ||
try { | ||
if (isModuleImport.test(filename)) { | ||
if (IS_SPECIAL_MODULE_IMPORT.test(filename)) { | ||
const error = new Error(); | ||
@@ -166,10 +167,2 @@ error.type = 'Next'; | ||
}); | ||
const useSourceMap = typeof loaderOptions.sourceMap === 'boolean' ? loaderOptions.sourceMap : loaderContext.sourceMap; | ||
if (useSourceMap) { | ||
lessOptions.sourceMap = { | ||
outputSourceFiles: true | ||
}; | ||
} | ||
return lessOptions; | ||
@@ -179,4 +172,4 @@ } | ||
function isUnsupportedUrl(url) { | ||
// Is Windows paths `c:\` | ||
if (/^[a-zA-Z]:\\/.test(url)) { | ||
// Is Windows path | ||
if (IS_NATIVE_WIN32_PATH.test(url)) { | ||
return false; | ||
@@ -188,2 +181,18 @@ } // Scheme: https://tools.ietf.org/html/rfc3986#section-3.1 | ||
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(url); | ||
} | ||
function normalizeSourceMap(map) { | ||
const newMap = map; // map.file is an optional property that provides the output filename. | ||
// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it. | ||
// eslint-disable-next-line no-param-reassign | ||
delete newMap.file; // eslint-disable-next-line no-param-reassign | ||
newMap.sourceRoot = ''; // `less` returns POSIX paths, that's why we need to transform them back to native paths. | ||
// eslint-disable-next-line no-param-reassign | ||
newMap.sources = newMap.sources.map(source => { | ||
return _path.default.normalize(source); | ||
}); | ||
return newMap; | ||
} |
{ | ||
"name": "less-loader", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "A Less loader for webpack. Compiles Less to CSS.", | ||
@@ -47,8 +47,8 @@ "license": "MIT", | ||
"loader-utils": "^2.0.0", | ||
"schema-utils": "^2.7.0" | ||
"schema-utils": "^2.7.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.10.4", | ||
"@babel/core": "^7.10.4", | ||
"@babel/preset-env": "^7.10.4", | ||
"@babel/cli": "^7.11.5", | ||
"@babel/core": "^7.11.5", | ||
"@babel/preset-env": "^7.11.5", | ||
"@commitlint/cli": "^10.0.0", | ||
@@ -62,3 +62,3 @@ "@commitlint/config-conventional": "^10.0.0", | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.3.1", | ||
"eslint": "^7.8.1", | ||
"eslint-config-prettier": "^6.11.0", | ||
@@ -71,6 +71,6 @@ "eslint-plugin-import": "^2.22.0", | ||
"less": "^3.12.2", | ||
"lint-staged": "^10.2.11", | ||
"lint-staged": "^10.3.0", | ||
"memfs": "^3.2.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.1.0", | ||
"prettier": "^2.1.1", | ||
"standard-version": "^9.0.0", | ||
@@ -77,0 +77,0 @@ "strip-ansi": "^6.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41346
275
Updatedschema-utils@^2.7.1