Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-css-urls

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-css-urls - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

changelog.md

9

package.json
{
"name": "grunt-css-urls",
"description": "Grunt task to make css urls relative to a main css file with @import rules",
"version": "0.1.5",
"version": "0.2.0",
"homepage": "https://github.com/Ideame/grunt-css-urls",

@@ -18,8 +18,11 @@ "author": {

"engines": {
"node": "*"
"node": ">=0.8.0"
},
"devDependencies": {
"grunt": "~0.3.17"
"grunt": "~0.4.0"
},
"peerDependencies": {
"grunt": "~0.4.0"
},
"keywords": ["grunt", "css", "bundling"]
}

@@ -150,10 +150,2 @@ grunt-css-urls

Changelog
---------
#### v1.3
* Ignore -moz urls like => url('xbl.xml#wordwrap');
* Ignore empty urls
License

@@ -160,0 +152,0 @@ -------

@@ -12,45 +12,49 @@ /*

grunt.registerMultiTask("cssUrls", "Parses a given main css file with @import rules, iterates through them replacing url() relative references with a relative url to the main css file.", function() {
var importFile = this.file.src;
grunt.registerMultiTask("cssUrls", "Parses a given main css file with @import rules, iterates through them replacing url() relative references with a relative url to the main css file.", function () {
var writeln = (this.data.safe) ? grunt.logwriteln : grunt.fail.warn ;
this.files.forEach(function(file) {
var contents = file.orig.src.filter(function(filepath) {
if (!grunt.file.exists(filepath)) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
}
}).map(function(filepath) {
var baseDir = path.dirname(path.join(process.cwd(), filepath));
var importContents = grunt.file.read(filepath);
if (!fs.existsSync(this.file.src)){
return writeln("Specified file not found: " + this.file.src);
}
importContents.replace(/@import\s+'([^']+)/gim, function(match, location){
location = location.replace(/'|"/g, '');
var filename = path.resolve(path.dirname(filepath), location);
var content = grunt.file.read(filename).toString(); // sometimes css is interpreted as object
var baseDir = path.dirname(grunt.file.expandFileURLs(this.file.src)[0]).replace('file://', '');
var importContents = grunt.file.read(importFile);
grunt.log.writeln('Parsing "' + location + '"...');
importContents.replace(/@import\s+'([^']+)/gim, function(match, location){
location = location.replace(/'|"/g, '');
var filename = path.resolve(path.dirname(importFile), location );
var content = grunt.file.read(filename).toString(); // sometimes css is interpreted as object
var css = content.replace(/url(?:\s+)?\(([^\)]+)\)/igm, function(match, url){
url = url.replace(/'|"/g, '');
grunt.log.writeln('Parsing "' + location + '"...');
if (/^\//.test(url)) {
grunt.log.writeln(" - Absolute urls are not supported, url ignored => " + url);
return url;
}
if (/^(\s+)?$/.test(url)) {
grunt.log.writeln(" - Empty urls are not supported, url ignored => " + url);
return url;
}
var css = content.replace(/url(?:\s+)?\(([^\)]+)\)/igm, function(match, url){
url = url.replace(/'|"/g, '');
if (/#/.test(url) && !/\?#iefix|svg#/.test(url)) {
grunt.log.writeln(" - Anchors not allowed, url ignored => " + url);
return url;
}
if (/^\//.test(url)) {
grunt.log.writeln(" - Absolute urls are not supported, url ignored => " + url);
return url;
}
if (/^(\s+)?$/.test(url)) {
grunt.log.writeln(" - Empty urls are not supported, url ignored => " + url);
return url;
}
var newUrl = path.resolve(path.dirname(filename), url ).replace(baseDir, '.');
return util.format("url(%s)", newUrl);
});
if (/#/.test(url) && !/\?#iefix|svg#/.test(url)) {
grunt.log.writeln(" - Anchors not allowed, url ignored => " + url);
return url;
}
var newUrl = path.resolve(path.dirname(filename), url ).replace(baseDir, '.');
return util.format("url(%s)", newUrl);
grunt.file.write(filename, css);
});
});
grunt.file.write(filename, css);
});
});
};
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc