Skip to content

Commit

Permalink
Port to PostCSS 8 API.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer committed Sep 28, 2020
1 parent 5eb09c7 commit 1aa612d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 274 deletions.
54 changes: 29 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
var postcss = require('postcss');
var bug4 = require('./bugs/bug4');
var bug6 = require('./bugs/bug6');
var bug81a = require('./bugs/bug81a');
Expand All @@ -12,30 +11,35 @@ var doNothingValues = [
'unset'
];

module.exports = postcss.plugin('postcss-flexbugs-fixes', function(opts) {
module.exports = function(opts) {
var options = Object.assign({ bug4: true, bug6: true, bug81a: true }, opts);

return function(css) {
css.walkDecls(function(d) {
if (d.value.indexOf('var(') > -1) {
return;
}
if (d.value === 'none') {
return;
}
var values = postcss.list.space(d.value);
if (doNothingValues.indexOf(d.value) > 0 && values.length === 1) {
return;
}
if (options.bug4) {
bug4(d);
}
if (options.bug6) {
bug6(d);
}
if (options.bug81a) {
bug81a(d);
}
});
return {
postcssPlugin: 'postcss-flexbugs-fixes',
Once: function(css, postcss) {
css.walkDecls(function(d) {
if (d.value.indexOf('var(') > -1) {
return;
}
if (d.value === 'none') {
return;
}
var values = postcss.list.space(d.value);
if (doNothingValues.indexOf(d.value) > 0 && values.length === 1) {
return;
}
if (options.bug4) {
bug4(d);
}
if (options.bug6) {
bug6(d);
}
if (options.bug81a) {
bug81a(d);
}
})
}
};
});
};

module.exports.postcss = true;
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
"repository": {
"type": "git",
"url": "https://github.com/luisrudge/postcss-flexbugs-fixes.git"
},
"dependencies": {
"postcss": "^7.0.26"
},
},
"main": "index.js",
"files": [
"bugs",
"index.js"
],
"devDependencies": {
"postcss": "^8.1.0",
"chai": "^4.2.0",
"gulp": "^4.0.2",
"gulp-eslint": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion specs/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var plugin = require('../');

module.exports = function(input, output, opts, done) {
postcss([plugin(opts)])
.process(input)
.process(input, {from: undefined})
.then(function(result) {
expect(result.css).to.eql(output);
expect(result.warnings()).to.be.empty;
Expand Down

0 comments on commit 1aa612d

Please sign in to comment.