postcss-prefix-selector
Advanced tools
Comparing version
94
index.js
@@ -1,2 +0,2 @@ | ||
module.exports = function postcssPrefixSelector(options) { | ||
const prefixPlugin = (options = {}) => { | ||
const prefix = options.prefix; | ||
@@ -9,52 +9,52 @@ const prefixWithSpace = /\s+$/.test(prefix) ? prefix : `${prefix} `; | ||
return function (root) { | ||
if ( | ||
ignoreFiles.length && | ||
root.source.input.file && | ||
isFileInArray(root.source.input.file, ignoreFiles) | ||
) { | ||
return; | ||
} | ||
if ( | ||
includeFiles.length && | ||
root.source.input.file && | ||
!isFileInArray(root.source.input.file, includeFiles) | ||
) { | ||
return; | ||
} | ||
return { | ||
postcssPlugin: 'postcss-prefix-selector', | ||
prepare(result) { | ||
const root = result.root; | ||
const file = root.source.input.file; | ||
root.walkRules((rule) => { | ||
const keyframeRules = [ | ||
'keyframes', | ||
'-webkit-keyframes', | ||
'-moz-keyframes', | ||
'-o-keyframes', | ||
'-ms-keyframes', | ||
]; | ||
if (rule.parent && keyframeRules.includes(rule.parent.name)) { | ||
// Skip ignored or non included files | ||
if (ignoreFiles.length && file && isFileInArray(file, ignoreFiles)) { | ||
return; | ||
} else if (includeFiles.length && file && !isFileInArray(file, includeFiles)) { | ||
return; | ||
} | ||
rule.selectors = rule.selectors.map((selector) => { | ||
if (options.exclude && excludeSelector(selector, options.exclude)) { | ||
return selector; | ||
} | ||
return { | ||
Rule(rule, { result }) { | ||
const keyframeRules = [ | ||
'keyframes', | ||
'-webkit-keyframes', | ||
'-moz-keyframes', | ||
'-o-keyframes', | ||
'-ms-keyframes', | ||
]; | ||
if (options.transform) { | ||
return options.transform( | ||
prefix, | ||
selector, | ||
prefixWithSpace + selector, | ||
root.source.input.file, | ||
rule | ||
); | ||
if (rule.parent && keyframeRules.includes(rule.parent.name)) { | ||
return; | ||
} | ||
rule.selectors = rule.selectors.map((selector) => { | ||
if (options.exclude && excludeSelector(selector, options.exclude)) { | ||
return selector; | ||
} | ||
if (options.transform) { | ||
return options.transform( | ||
prefix, | ||
selector, | ||
prefixWithSpace + selector, | ||
root.source.input.file, | ||
rule | ||
); | ||
} | ||
return prefixWithSpace + selector; | ||
}); | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
return prefixWithSpace + selector; | ||
}); | ||
}); | ||
}; | ||
}; | ||
function isFileInArray(file, arr) { | ||
@@ -78,2 +78,6 @@ return arr.some((ruleOrString) => { | ||
}); | ||
} | ||
}; | ||
prefixPlugin.postcss = true | ||
module.exports = prefixPlugin; |
{ | ||
"name": "postcss-prefix-selector", | ||
"description": "Prefix all CSS rules with a selector", | ||
"version": "1.16.1", | ||
"version": "2.0.0", | ||
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)", | ||
@@ -10,8 +10,8 @@ "contributors": [ | ||
"license": "MIT", | ||
"repository": "RadValentin/postcss-prefix-selector", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/RadValentin/postcss-prefix-selector.git" | ||
}, | ||
"bugs": "https://github.com/RadValentin/postcss-prefix-selector/issues", | ||
"homepage": "https://github.com/RadValentin/postcss-prefix-selector", | ||
"peerDependencies": { | ||
"postcss": ">4 <9" | ||
}, | ||
"devDependencies": { | ||
@@ -26,2 +26,5 @@ "husky": "^8.0.3", | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.0.0" | ||
}, | ||
"scripts": { | ||
@@ -28,0 +31,0 @@ "test": "mocha", |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
11199
2.85%68
1.49%0
-100%