Skip to content

Commit 70302f4

Browse files
committed
feat: migrate plugin to postcss 8
1 parent fa392e6 commit 70302f4

7 files changed

+64
-28
lines changed

.babelrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
"plugins": [
2020
"@babel/plugin-transform-runtime",
2121
"add-module-exports"
22-
]
22+
],
23+
"comments": false
2324
}

package-lock.json

+32-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
"property"
3737
],
3838
"dependencies": {
39-
"@babel/runtime": "^7.7.2",
40-
"postcss": "^7.0.21"
39+
"@babel/runtime": "^7.7.2"
4140
},
4241
"devDependencies": {
4342
"@babel/cli": "^7.7.0",
@@ -66,8 +65,12 @@
6665
"husky": "^3.0.9",
6766
"lint-staged": "^9.4.3",
6867
"nyc": "^14.1.1",
68+
"postcss": "^8.2.5",
6969
"rimraf": "^3.0.0"
7070
},
71+
"peerDependencies": {
72+
"postcss": "^8.2.5"
73+
},
7174
"ava": {
7275
"require": [
7376
"@babel/register"

readme.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
# postcss-map-get <a href="https://github.com/postcss/postcss"><img align="left" height="49" title="PostCSS" src="http://postcss.github.io/postcss/logo.svg"></a>
2+
23
> [PostCSS](https://github.com/postcss/postcss) plugin to transform SASS Function [map-get](http://sass-lang.com/documentation/Sass/Script/Functions.html#map_get-instance_method).
34
45
[![Travis Build Status](https://img.shields.io/travis/Scrum/postcss-map-get/master.svg?style=flat-square&label=unix)](https://travis-ci.org/Scrum/postcss-map-get)[![node](https://img.shields.io/node/v/postcss-map-get.svg?maxAge=2592000&style=flat-square)]()[![npm version](https://img.shields.io/npm/v/postcss-map-get.svg?style=flat-square)](https://www.npmjs.com/package/postcss-map-get)[![Dependency Status](https://david-dm.org/scrum/postcss-map-get.svg?style=flat-square)](https://david-dm.org/scrum/postcss-map-get)[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg?style=flat-square)](https://github.com/sindresorhus/xo)[![Coveralls status](https://img.shields.io/coveralls/Scrum/postcss-map-get.svg?style=flat-square)](https://coveralls.io/r/Scrum/postcss-map-get)
56

67
[![npm downloads](https://img.shields.io/npm/dm/postcss-map-get.svg?style=flat-square)](https://www.npmjs.com/package/postcss-map-get)[![npm](https://img.shields.io/npm/dt/postcss-map-get.svg?style=flat-square)](https://www.npmjs.com/package/postcss-map-get)
78

8-
99
## Why?
10+
1011
Adds the ability to use sass like Map Function [map-get](http://sass-lang.com/documentation/Sass/Script/Functions.html#map_get-instance_method).
1112

1213
## Install
1314

1415
```bash
15-
$ npm install postcss-map-get
16+
$ npm install postcss postcss-map-get
1617
```
1718

1819
> **Note:** This project is compatible with node v8+
@@ -38,11 +39,13 @@ var output = postcss()
3839

3940
console.log(output);
4041
```
42+
4143
> Returns the value in a map associated with the given key. If the map doesn't have such a key, returns null.
4244
43-
# Example
45+
## Example
4446

4547
*input.css*
48+
4649
```css
4750
body {
4851
background: map-get((
@@ -64,7 +67,9 @@ body {
6467
max-width: 100%;
6568
}
6669
```
70+
6771
*output.css*
72+
6873
```css
6974
body {
7075
background: #fff;

src/index.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
import postcss from 'postcss';
21
import processValue from './process-value';
32
import {METHOD} from './constant';
43

5-
export default postcss.plugin('postcss-map-get', () => {
6-
return nodes => {
7-
nodes.walkDecls(decl => {
4+
const plugin = () => {
5+
return {
6+
postcssPlugin: 'postcss-map-get',
7+
8+
Declaration(decl) {
89
let {value} = decl;
910

1011
if (value.includes(METHOD)) {
1112
decl.value = processValue(decl.value);
1213
}
13-
});
14+
},
1415

15-
nodes.walkAtRules(rules => {
16-
const {params: parameters} = rules;
16+
AtRule(atRule) {
17+
const {params: parameters} = atRule;
1718

1819
if (parameters.includes(METHOD)) {
19-
rules.params = processValue(parameters);
20+
atRule.params = processValue(parameters);
2021
}
21-
});
22+
}
2223
};
23-
});
24+
};
25+
26+
plugin.postcss = true;
27+
28+
export default plugin;

src/process-value.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default function (value) {
9393
mapString += output.content;
9494
position = output.position;
9595

96-
// resolve the desidered requested key
96+
// resolve the desired requested key
9797
let keyString = '';
9898

9999
// indicates if we found the come which separate map and requested key:

test/test.plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ test('it should remove line breaks and space from map key only', t => {
7070
const expected = '.foo {border: 1px solid black}';
7171
const value = '.foo {border: map-get((\n border: 1px solid black), border)}';
7272
t.is(processing(value), expected);
73-
});
73+
});

0 commit comments

Comments
 (0)