resolve-url-loader
Advanced tools
Comparing version 1.4.0 to 1.4.1
23
index.js
@@ -47,3 +47,3 @@ /* | ||
var resolvedRoot = (typeof options.root === 'string') && path.resolve(options.root), | ||
isValidRoot = !!resolvedRoot && fs.existsSync(resolvedRoot); | ||
isValidRoot = resolvedRoot && fs.existsSync(resolvedRoot); | ||
if (options.root && !isValidRoot) { | ||
@@ -92,3 +92,3 @@ return handleException('"root" option does not resolve to a valid path'); | ||
catch (exception) { | ||
return handleException('CSS error', exception.message); | ||
return handleException('CSS error', exception); | ||
} | ||
@@ -112,7 +112,10 @@ | ||
* Push an error for the given exception and return the original content. | ||
* @param {...string} messages | ||
* @param {string} label | ||
* @param {string|Error} exception | ||
* @returns {string} The original CSS content | ||
*/ | ||
function handleException() { | ||
var message = ' resolve-url-loader cannot operate: ' + Array.prototype.slice.call(arguments).join(' '); | ||
function handleException(label, exception) { | ||
var rest = (typeof exception === 'string') ? [exception] : (exception instanceof Error) ? [exception.message, | ||
exception.stack.split('\n')[1].trim()] : []; | ||
var message = ' resolve-url-loader cannot operate: ' + [label].concat(rest).filter(Boolean).join('\n '); | ||
if (options.fail) { | ||
@@ -132,2 +135,3 @@ loader.emitError(message); | ||
function reworkPlugin(stylesheet) { | ||
var URL_STATEMENT_REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g; | ||
@@ -146,11 +150,12 @@ // visit each node (selector) in the stylesheet recursively using the official utility method | ||
function eachDeclaration(declaration) { | ||
var URL_STATEMENT_REGEX = /(url\s*\()\s*(?:(['"])((?:(?!\2).)*)(\2)|([^'"](?:(?!\)).)*[^'"]))\s*(\))/g; | ||
if (declaration.value) { | ||
var isValid = declaration.value && (declaration.value.indexOf('url') >= 0), | ||
directory; | ||
if (isValid) { | ||
// reverse the original source-map to find the original sass file | ||
var startPosApparent = declaration.position.start, | ||
startPosOriginal = sourceMapConsumer && sourceMapConsumer.originalPositionFor(startPosApparent), | ||
directory = startPosOriginal && startPosOriginal.source && path.dirname(startPosOriginal.source); | ||
startPosOriginal = sourceMapConsumer && sourceMapConsumer.originalPositionFor(startPosApparent); | ||
// we require a valid directory for the specified file | ||
directory = startPosOriginal && startPosOriginal.source && path.dirname(startPosOriginal.source); | ||
if (directory) { | ||
@@ -157,0 +162,0 @@ |
{ | ||
"name": "resolve-url-loader", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Webpack loader that resolves relative paths in url() statements based on the original source file", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
21068
374