Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit 0e9483d

Browse files
Support PostCSS 8 (#2)
1 parent b3cf37e commit 0e9483d

3 files changed

Lines changed: 47 additions & 37 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules
77
!.travis.yml
88
*.log*
99
*.result.css
10+
/index.*

index.js

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,47 @@
1-
// tooling
2-
const postcss = require('postcss');
1+
const creator = () => {
2+
// side properties
3+
const properties = ['top', 'right', 'bottom', 'left'];
34

4-
// side properties
5-
const properties = ['top', 'right', 'bottom', 'left'];
5+
return {
6+
postcssPlugin: 'postcss-inset',
7+
Declaration: {
8+
'inset': (decl, { list }) => {
9+
// space-separated side values (top, right, bottom, left)
10+
const values = list.space(decl.value);
611

7-
// inset plugin
8-
module.exports = postcss.plugin('postcss-inset', () => (root) => {
9-
root.walkDecls('inset', (decl) => {
10-
// space-separated side values (top, right, bottom, left)
11-
const values = postcss.list.space(decl.value);
12+
// conditionally add a right value
13+
if (values.length === 1) {
14+
values.push(values[0]);
15+
}
1216

13-
// conditionally add a right value
14-
if (values.length === 1) {
15-
values.push(values[0]);
16-
}
17+
// conditionally add a bottom value
18+
if (values.length === 2) {
19+
values.push(values[0]);
20+
}
1721

18-
// conditionally add a bottom value
19-
if (values.length === 2) {
20-
values.push(values[0]);
21-
}
22+
// conditionally add a left value
23+
if (values.length === 3) {
24+
values.push(values[1]);
25+
}
2226

23-
// conditionally add a left value
24-
if (values.length === 3) {
25-
values.push(values[1]);
26-
}
27+
// only transform up to 4 side values
28+
if (values.length === 4) {
29+
// for each side property
30+
properties.forEach((property, index) => {
31+
// create a new declaration for the side
32+
decl.cloneBefore({
33+
prop: property,
34+
value: values[index]
35+
});
36+
});
37+
}
2738

28-
// only transform up to 4 side values
29-
if (values.length === 4) {
30-
// for each side property
31-
properties.forEach((property, index) => {
32-
// create a new declaration for the side
33-
decl.cloneBefore({
34-
prop: property,
35-
value: values[index]
36-
});
37-
});
39+
decl.remove();
40+
},
3841
}
42+
}
43+
}
44+
45+
creator.postcss = true
3946

40-
decl.remove();
41-
});
42-
});
47+
export default creator

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
"repository": "jonathantneal/postcss-inset",
88
"homepage": "https://github.com/jonathantneal/postcss-inset#readme",
99
"bugs": "https://github.com/jonathantneal/postcss-inset/issues",
10-
"main": "index.js",
10+
"main": "index.cjs.js",
11+
"module": "index.es.mjs",
1112
"files": [
12-
"index.js"
13+
"index.js",
14+
"index.cjs.js",
15+
"index.es.mjs"
1316
],
1417
"scripts": {
1518
"clean": "git clean -X -d -f",
19+
"build": "rollup index.js --file index.cjs.js --format cjs --exports default && rollup index.js --file index.es.mjs --format es --exports default",
1620
"prepublish": "npm test",
1721
"test": "echo 'Running tests...'; npm run test:js && npm run test:tape",
1822
"test:js": "eslint *.js --cache --ignore-pattern .gitignore",
@@ -22,7 +26,7 @@
2226
"node": ">=4.0.0"
2327
},
2428
"dependencies": {
25-
"postcss": "^6.0.1"
29+
"postcss": "^8.2.0"
2630
},
2731
"devDependencies": {
2832
"eslint": "^3.19.0",

0 commit comments

Comments
 (0)