Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
Support PostCSS 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Semigradsky committed Jan 31, 2021
1 parent fefab08 commit 3de1907
Show file tree
Hide file tree
Showing 6 changed files with 3,069 additions and 29 deletions.
5 changes: 2 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"presets": [
["env", {
["@babel/preset-env", {
"targets": {
"node": 4
"node": 10
}
}]
],
"plugins": [
"add-module-exports"
]
}
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
language: node_js

node_js:
- 6
- 14
- 12
- 10

install:
- npm install --ignore-scripts
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@ http://dev.w3.org/csswg/selectors-4/#negation
## Installation

```console
$ npm install postcss-selector-not
$ npm install postcss postcss-selector-not
```

## Usage

```js
var postcss = require("postcss")

var output = postcss()
.use(require("postcss-selector-not"))
.process(require("fs").readFileSync("input.css", "utf8"))
.css
```

Using this `input.css`:

```css
Expand Down
23 changes: 13 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,25 @@
"dist"
],
"dependencies": {
"balanced-match": "^1.0.0",
"postcss": "^7.0.2"
"balanced-match": "^1.0.0"
},
"peerDependencies": {
"postcss": "^8.1.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-plugin-add-module-exports": "^1.0.0",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"eslint": "^5.6.0",
"tape": "^4.9.1"
"@babel/core": "^7.11.6",
"@babel/cli": "^7.11.6",
"@babel/preset-env": "^7.11.5",
"@babel/register": "^7.11.5",
"eslint": "^7.9.0",
"postcss": "^8.1.0",
"tape": "^5.0.1"
},
"scripts": {
"lint": "eslint ./src/*.js ./test/*.js",
"tape": "tape -r babel-register test/*.js",
"tape": "tape -r @babel/register test/*.js",
"test": "npm run lint && npm run babelify && npm run tape",
"babelify": "babel src --out-dir dist",
"prepublish": "npm run babelify"
"prepublishOnly": "npm run babelify"
}
}
13 changes: 8 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import postcss from "postcss"
import list from "postcss/lib/list"

import balancedMatch from "balanced-match"
Expand Down Expand Up @@ -52,14 +51,18 @@ function locatePseudoClass(selector, pseudoClass) {

function explodeSelectors(pseudoClass) {
return () => {
return (css) => {
css.walkRules(rule => {
return {
postcssPlugin: "postcss-selector-not",
Rule: (rule) => {
if (rule.selector && rule.selector.indexOf(pseudoClass) > -1) {
rule.selector = explodeSelector(pseudoClass, rule.selector)
}
})
},
}
}
}

export default postcss.plugin("postcss-selector-not", explodeSelectors(":not"))
const creator = explodeSelectors(":not")
creator.postcss = true

export default creator
Loading

0 comments on commit 3de1907

Please sign in to comment.