Socket
Socket
Sign inDemoInstall

postcss-url

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-url - npm Package Compare versions

Comparing version 6.0.4 to 6.1.0

7

CHANGELOG.md

@@ -0,2 +1,9 @@

# 6.1.0 - 2017-05-13
Changed: filter functions access to asset object
Added: support crypto hash function methods
Added: support for postcss's dependency messaging
# 6.0.4 - 2017-04-06
Fixed: prepare asset without file path in decl

@@ -3,0 +10,0 @@ ([#94](https://github.com/postcss/postcss-url/issues/94))

2

package.json
{
"name": "postcss-url",
"version": "6.0.4",
"version": "6.1.0",
"description": "PostCSS plugin to rebase or inline on url().",

@@ -5,0 +5,0 @@ "keywords": [

@@ -8,2 +8,3 @@ 'use strict';

const getPathDeclFile = paths.getPathDeclFile;
const getDirDeclFile = paths.getDirDeclFile;

@@ -66,5 +67,4 @@ const prepareAsset = paths.prepareAsset;

const asset = prepareAsset(url, dir, decl);
const relativeToRoot = path.relative(process.cwd(), asset.absolutePath);
const matchedOptions = matchOptions(relativeToRoot, options);
const matchedOptions = matchOptions(asset, options);

@@ -80,4 +80,9 @@ if (!matchedOptions) return;

const warn = (message) => decl.warn(result, message);
const addDependency = (file) => result.messages.push({
type: 'dependency',
file,
parent: getPathDeclFile(decl)
});
return urlProcessor(asset, dir, matchedOptions, decl, warn, result);
return urlProcessor(asset, dir, matchedOptions, decl, warn, result, addDependency);
};

@@ -84,0 +89,0 @@

'use strict';
const crypto = require('crypto');
const xxh = require('xxhashjs');

@@ -26,3 +27,14 @@ const HEXBASE = 16;

return getxxhash(content, options);
if (options.method.indexOf('xxhash') === 0) {
return getxxhash(content, options);
}
try {
const hashFunc = crypto.createHash(options.method);
return hashFunc.update(content)
.digest('hex');
} catch (e) {
return null;
}
};

@@ -33,5 +45,11 @@

const hash = getHash(content, options);
let hash = getHash(content, options);
if (hash == null) {
// bad hash method; fallback to defaults
// TODO: warning/error reporting?
hash = getHash(content, defaultHashOptions);
}
return options.shrink ? hash.substr(0, options.shrink) : hash;
};
'use strict';
const minimatch = require('minimatch');
const path = require('path');
/**
* Returns wether the given filename matches the given pattern
* Returns whether the given asset matches the given pattern
* Allways returns true if the given pattern is empty
*
* @param {String} filename the processed filename
* @param {PostcssUrl~Asset} asset the processed asset
* @param {String|RegExp|Function} pattern A minimatch string,
* regular expression or function to test the filename
* regular expression or function to test the asset
*
* @returns {Boolean}
*/
const matchesFilter = (filename, pattern) => {
const matchesFilter = (asset, pattern) => {
const relativeToRoot = path.relative(process.cwd(), asset.absolutePath);
if (typeof pattern === 'string') {
pattern = minimatch.filter(pattern);
return pattern(relativeToRoot);
}
if (pattern instanceof RegExp) {
return pattern.test(filename);
return pattern.test(relativeToRoot);
}
if (pattern instanceof Function) {
return pattern(filename);
return pattern(asset);
}

@@ -34,14 +39,14 @@

*
* @param {String} filepath - relative to project (process.cwd) asset path
* @param {PostcssUrl~Asset} asset
* @param {PostcssUrl~Options|PostcssUrl~Options[]} options
* @returns {PostcssUrl~Options|undefined}
*/
const matchOptions = (filepath, options) => {
const matchOptions = (asset, options) => {
if (!options) return;
if (Array.isArray(options)) {
return options.find((option) => matchesFilter(filepath, option.filter));
return options.find((option) => matchesFilter(asset, option.filter));
}
if (!matchesFilter(filepath, options.filter)) return;
if (!matchesFilter(asset, options.filter)) return;

@@ -48,0 +53,0 @@ return options;

@@ -29,8 +29,10 @@ 'use strict';

* @param {PostcssUrl~Option} options
* @param {PostscssUrl~Decl} decl
* @param {PostcssUrl~Decl} decl
* @param {Function} warn
* @param {Result} result
* @param {Function} addDependency
*
* @returns {String|Undefined}
*/
module.exports = function processCopy(asset, dir, options, decl, warn) {
module.exports = function processCopy(asset, dir, options, decl, warn, result, addDependency) {
if (!options.assetsPath && dir.from === dir.to) {

@@ -63,3 +65,5 @@ warn('Option `to` of postcss is required, ignoring');

addDependency(file.path);
return `${newRelativeAssetPath}${asset.search}${asset.hash}`;
};

@@ -38,6 +38,8 @@ 'use strict';

* @param {Function} warn
* @param {Result} result
* @param {Function} addDependency
*
* @returns {String|Undefined}
*/
module.exports = function(asset, dir, options, decl, warn) {
module.exports = function(asset, dir, options, decl, warn, result, addDependency) {
const file = getFile(asset, options, dir, warn);

@@ -73,2 +75,4 @@

addDependency(file.path);
const encodedStr = encodeFile(file, encodeType);

@@ -75,0 +79,0 @@

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