postcss-url
Advanced tools
Comparing version 6.0.2 to 6.0.3
@@ -0,1 +1,5 @@ | ||
# 6.0.3 - 2017-04-04 | ||
Fixed: hash url error | ||
([#89](https://github.com/postcss/postcss-url/issues/89)) | ||
# 6.0.2 - 2017-04-04 | ||
@@ -2,0 +6,0 @@ Fixed: match options before analyzing |
{ | ||
"name": "postcss-url", | ||
"version": "6.0.2", | ||
"version": "6.0.3", | ||
"description": "PostCSS plugin to rebase or inline on url().", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -64,9 +64,11 @@ 'use strict'; | ||
const replaceUrl = (url, dir, options, result, decl) => { | ||
const asset = prepareAsset(url, dir, options.basePath); | ||
const asset = prepareAsset(url, dir, decl); | ||
const relativeToRoot = path.relative(process.cwd(), asset.absolutePath); | ||
const matchedOptions = matchOptions(relativeToRoot, options); | ||
if (!matchedOptions) return; | ||
const isFunction = typeof matchedOptions.url === 'function'; | ||
if (!isFunction && isUrlShouldBeIgnored(url, matchedOptions)) return; | ||
@@ -118,3 +120,3 @@ | ||
}); | ||
} | ||
}; | ||
}); | ||
@@ -121,0 +123,0 @@ |
@@ -19,12 +19,8 @@ 'use strict'; | ||
/** | ||
* Check if url is absolute, hash or data-uri | ||
* | ||
* @param {String} assetUrl | ||
* @param {PostcssUrl~Options} options | ||
* @returns {Boolean} | ||
*/ | ||
const isUrlShouldBeIgnored = (assetUrl, options) => { | ||
const isUrlWithoutPathname = (assetUrl) => { | ||
return assetUrl[0] === '#' | ||
|| assetUrl.indexOf('%23') === 0 | ||
|| (assetUrl[0] === '/' && !options.basePath) | ||
|| assetUrl.indexOf('data:') === 0 | ||
@@ -35,2 +31,13 @@ || /^[a-z]+:\/\//.test(assetUrl); | ||
/** | ||
* Check if url is absolute, hash or data-uri | ||
* | ||
* @param {String} assetUrl | ||
* @param {PostcssUrl~Options} options | ||
* @returns {Boolean} | ||
*/ | ||
const isUrlShouldBeIgnored = (assetUrl, options) => { | ||
return isUrlWithoutPathname(assetUrl) || (assetUrl[0] === '/' && !options.basePath); | ||
}; | ||
/** | ||
* @param {String} baseDir - absolute target path | ||
@@ -54,2 +61,11 @@ * @param {String} assetsPath - extend asset path, can be absolute path | ||
/** | ||
* Stylesheet file path from decl | ||
* | ||
* @param {Decl} decl | ||
* @returns {String} | ||
*/ | ||
const getPathDeclFile = (decl) => | ||
decl.source && decl.source.input && decl.source.input.file; | ||
/** | ||
* Stylesheet file dir from decl | ||
@@ -61,3 +77,3 @@ * | ||
const getDirDeclFile = (decl) => { | ||
const filename = decl.source && decl.source.input && decl.source.input.file; | ||
const filename = getPathDeclFile(decl); | ||
@@ -92,7 +108,11 @@ return filename ? path.dirname(filename) : process.cwd(); | ||
* @param {PostcssUrl~Dir} dir | ||
* @param {Decl} decl | ||
* @returns {PostcssUrl~Asset} | ||
*/ | ||
const prepareAsset = (assetUrl, dir) => { | ||
const prepareAsset = (assetUrl, dir, decl) => { | ||
const parsedUrl = url.parse(assetUrl); | ||
const absolutePath = path.join(dir.file, parsedUrl.pathname); | ||
const pathname = !isUrlWithoutPathname(assetUrl) ? parsedUrl.pathname : null; | ||
const absolutePath = pathname | ||
? path.join(dir.file, pathname) | ||
: getPathDeclFile(decl); | ||
@@ -114,2 +134,3 @@ return { | ||
getDirDeclFile, | ||
getPathDeclFile, | ||
getTargetDir, | ||
@@ -116,0 +137,0 @@ getPathByBasePath, |
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
29765
523