Skip to content

Commit b8655ff

Browse files
committed
Update project configuration
1 parent be6c841 commit b8655ff

5 files changed

Lines changed: 76 additions & 27 deletions

File tree

.appveyor.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://www.appveyor.com/docs/appveyor-yml
2+
3+
environment:
4+
matrix:
5+
- nodejs_version: 4
6+
7+
version: "{build}"
8+
build: off
9+
deploy: off
10+
11+
install:
12+
- ps: Install-Product node $env:nodejs_version
13+
- npm install --ignore-scripts
14+
15+
test_script:
16+
- node --version
17+
- npm --version
18+
- cmd: "npm test"

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
node_modules
2+
index.*.js
23
package-lock.json
4+
*.log*
5+
*.result.css
36
.*
47
!.appveyor.yml
58
!.editorconfig
69
!.gitignore
10+
!.rollup.js
711
!.tape.js
812
!.travis.yml
9-
*.log*
10-
*.result.css

.rollup.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import babel from 'rollup-plugin-babel';
2+
3+
export default {
4+
input: 'index.js',
5+
output: [
6+
{ file: 'index.cjs.js', format: 'cjs' },
7+
{ file: 'index.es.js', format: 'es' }
8+
],
9+
plugins: [
10+
babel({
11+
presets: [
12+
['env', { modules: false, targets: { node: 4 } }]
13+
]
14+
})
15+
]
16+
};

index.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
'use strict';
2-
3-
// external tooling
4-
const postcss = require('postcss');
5-
const transform = require('postcss-nesting/lib/transform');
1+
import postcss from 'postcss';
2+
import nesting from 'postcss-nesting';
63

74
// extend at-rule match
85
const extendMatch = /^(extend)$/i;
@@ -11,13 +8,13 @@ const extendMatch = /^(extend)$/i;
118
const functionalSelectorMatch = /(^|[^\w-])(%[_a-zA-Z]+[_a-zA-Z0-9-]*)([^\w-]|$)/i;
129

1310
// plugin
14-
module.exports = postcss.plugin('postcss-extend-rule', (rawopts) => {
11+
export default postcss.plugin('postcss-extend-rule', rawopts => {
1512
// options ( onFunctionalSelector, onRecursiveExtend, onUnusedExtend)
1613
const opts = Object(rawopts);
1714

1815
return (root, result) => {
1916
// for each extend at-rule
20-
root.walkAtRules(extendMatch, (extendAtRule) => {
17+
root.walkAtRules(extendMatch, extendAtRule => {
2118
// do not revisit visited extend at-rules
2219
if (!extendAtRule.__extendAtRuleVisited) {
2320
extendAtRule.__extendAtRuleVisited = true;
@@ -35,7 +32,7 @@ module.exports = postcss.plugin('postcss-extend-rule', (rawopts) => {
3532

3633
// transform any nesting at-rules
3734
extendingRules.forEach(
38-
(extendingRule) => {
35+
extendingRule => {
3936
transform(extendingRule);
4037

4138
extendingRule.walk(transform);
@@ -67,7 +64,7 @@ module.exports = postcss.plugin('postcss-extend-rule', (rawopts) => {
6764
}
6865
});
6966

70-
root.walkRules(functionalSelectorMatch, (functionalRule) => {
67+
root.walkRules(functionalSelectorMatch, functionalRule => {
7168
// manage encountered functional selectors
7269
const functionalSelectorMessage = `Encountered functional selector "${functionalRule.selector}"`;
7370

@@ -82,17 +79,25 @@ module.exports = postcss.plugin('postcss-extend-rule', (rawopts) => {
8279
};
8380
});
8481

82+
function transform(node) {
83+
return nesting()({
84+
walk(transformer) {
85+
return transformer(node)
86+
}
87+
});
88+
}
89+
8590
function getExtendingRules(selectorIdMatch, extendAtRule) {
8691
// extending rules
8792
const extendingRules = [];
8893

8994
// for each rule found from root of the extend at-rule with a matching selector identifier
90-
extendAtRule.root().walkRules(selectorIdMatch, (matchingRule) => {
95+
extendAtRule.root().walkRules(selectorIdMatch, matchingRule => {
9196
// nesting selectors for the selectors matching the selector identifier
9297
const nestingSelectors = matchingRule.selectors.filter(
93-
(selector) => selectorIdMatch.test(selector)
98+
selector => selectorIdMatch.test(selector)
9499
).map(
95-
(selector) => selector.replace(selectorIdMatch, '$1&$3')
100+
selector => selector.replace(selectorIdMatch, '$1&$3')
96101
).join(',');
97102

98103
// matching rule’s cloned nodes
@@ -127,7 +132,7 @@ function getExtendingRules(selectorIdMatch, extendAtRule) {
127132
function getSelectorIdMatch(selectorIds) {
128133
// escape the contents of the selector id to avoid being parsed as regex
129134
const escapedSelectorIds = postcss.list.comma(selectorIds).map(
130-
(selectorId) => selectorId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
135+
selectorId => selectorId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
131136
).join('|');
132137

133138
// selector unattached to an existing selector

package.json

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,40 @@
77
"repository": "jonathantneal/postcss-extend-rule",
88
"homepage": "https://github.com/jonathantneal/postcss-extend-rule#readme",
99
"bugs": "https://github.com/jonathantneal/postcss-extend-rule/issues",
10-
"main": "index.js",
10+
"main": "index.cjs.js",
11+
"module": "index.es.js",
1112
"files": [
12-
"index.js"
13+
"index.cjs.js",
14+
"index.es.js"
1315
],
1416
"scripts": {
15-
"clean": "git clean -X -d -f",
16-
"prepublish": "npm test",
17+
"prepublishOnly": "npm test",
18+
"pretest": "rollup -c .rollup.js --silent",
1719
"test": "echo 'Running tests...'; npm run test:js && npm run test:tape",
18-
"test:js": "eslint *.js --cache --ignore-pattern .gitignore",
20+
"test:js": "eslint *.js --cache --ignore-path .gitignore --quiet",
1921
"test:tape": "postcss-tape"
2022
},
2123
"engines": {
2224
"node": ">=4.0.0"
2325
},
2426
"dependencies": {
25-
"postcss": "^6.0.11",
26-
"postcss-nesting": "^4.2.1"
27+
"postcss": "^6.0.22",
28+
"postcss-nesting": "^5.0.0"
2729
},
2830
"devDependencies": {
29-
"eslint": "^4.7.1",
30-
"eslint-config-dev": "2.0.0",
31-
"postcss-tape": "2.1.0",
32-
"pre-commit": "^1.2.2"
31+
"babel-core": "^6.26.3",
32+
"babel-eslint": "^8.2.3",
33+
"babel-preset-env": "^1.7.0",
34+
"eslint": "^4.19.1",
35+
"eslint-config-dev": "^2.0.0",
36+
"postcss-tape": "^2.2.0",
37+
"pre-commit": "^1.2.2",
38+
"rollup": "^0.59.4",
39+
"rollup-plugin-babel": "^3.0.4"
3340
},
3441
"eslintConfig": {
35-
"extends": "dev"
42+
"extends": "dev",
43+
"parser": "babel-eslint"
3644
},
3745
"keywords": [
3846
"postcss",

0 commit comments

Comments
 (0)