Socket
Socket
Sign inDemoInstall

resolve-url-loader

Package Overview
Dependencies
31
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.0 to 1.6.0

60

index.js

@@ -36,18 +36,19 @@ /*

// however we need to match to the sass-loader and it does not do so
var loader = this,
filePath = loader.context,
outputPath = path.resolve(loader.options.output.path);
var loader = this,
filePath = loader.context,
outputPath = path.resolve(loader.options.output.path),
contextPath = path.resolve(loader.options.context);
// prefer loader query, else options object, else default values
var options = defaults(loaderUtils.parseQuery(loader.query), loader.options[camelcase(PACKAGE_NAME)], {
absolute : false,
sourceMap : false,
fail : false,
silent : false,
keepQuery : false,
root : null
absolute : false,
sourceMap: false,
fail : false,
silent : false,
keepQuery: false,
root : null
});
// validate root directory
var resolvedRoot = (typeof options.root === 'string') && path.resolve(options.root),
var resolvedRoot = (typeof options.root === 'string') && path.resolve(options.root) || undefined,
isValidRoot = resolvedRoot && fs.existsSync(resolvedRoot);

@@ -62,12 +63,27 @@ if (options.root && !isValidRoot) {

// incoming source-map
var sourceMapConsumer, contentWithMap;
var sourceMapConsumer, contentWithMap, sourceRoot;
if (sourceMap) {
// sass-loader outputs source-map sources relative to output directory so start our search there
// expect sass-loader@>=4.0.0
// sourcemap sources relative to context path
try {
relativeToAbsolute(sourceMap.sources, outputPath, resolvedRoot);
} catch (exception) {
return handleException('source-map error', exception.message);
relativeToAbsolute(sourceMap.sources, contextPath, resolvedRoot);
}
catch (unused) {
// fallback to sass-loader@<4.0.0
// sourcemap sources relative to output path
try {
relativeToAbsolute(sourceMap.sources, outputPath, resolvedRoot);
}
catch (exception) {
return handleException('source-map error', exception.message);
}
}
// There are now absolute paths in the source map so we don't need it anymore
// However, later when we go back to relative paths, we need to add it again
sourceRoot = sourceMap.sourceRoot;
sourceMap.sourceRoot = undefined;
// prepare the adjusted sass source-map for later look-ups

@@ -105,4 +121,7 @@ sourceMapConsumer = new SourceMapConsumer(sourceMap);

// source-map sources seem to be relative to the file being processed
absoluteToRelative(reworked.map.sources, filePath);
absoluteToRelative(reworked.map.sources, path.resolve(filePath, sourceRoot || '.'));
// Set source root again
reworked.map.sourceRoot = sourceRoot;
// need to use callback when there are multiple arguments

@@ -118,9 +137,10 @@ loader.callback(null, reworked.code, reworked.map);

* Push an error for the given exception and return the original content.
* @param {string} label
* @param {string|Error} exception
* @param {string} label Summary of the error
* @param {string|Error} [exception] Optional extended error details
* @returns {string} The original CSS content
*/
function handleException(label, exception) {
var rest = (typeof exception === 'string') ? [exception] : (exception instanceof Error) ? [exception.message,
exception.stack.split('\n')[1].trim()] : [];
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 ');

@@ -127,0 +147,0 @@ if (options.fail) {

@@ -21,3 +21,3 @@ 'use strict';

var basePath = base(startPath, uri, limit);
return !!basePath && path.resolve(basePath, uri);
return !!basePath && path.resolve(basePath, uri) || null;
}

@@ -24,0 +24,0 @@

@@ -7,3 +7,4 @@ /*

var path = require('path');
var path = require('path'),
urix = require('urix');

@@ -48,3 +49,5 @@ var findFile = require('./find-file');

if (basePath) {
array[i] = path.resolve(basePath, location);
// rework-css uses urix internally. If we don't convert the path here, the paths are messed up
// with the conversion relative urls are set correctly
array[i] = urix(path.resolve(basePath, location));
return basePath;

@@ -51,0 +54,0 @@ }

{
"name": "resolve-url-loader",
"version": "1.5.0",
"version": "1.6.0",
"description": "Webpack loader that resolves relative paths in url() statements based on the original source file",

@@ -35,4 +35,5 @@ "main": "index.js",

"rework-visit": "^1.0.0",
"source-map": "^0.1.43"
"source-map": "^0.1.43",
"urix": "^0.1.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc