postcss-mixins
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,4 @@ | ||
## 2.1 | ||
* Add CSS files support for mixins from dir (by Jed Mao). | ||
## 2.0 | ||
@@ -2,0 +5,0 @@ * `mixinsDir` loads JSON mixins too (by Jed Mao). |
30
index.js
@@ -5,2 +5,3 @@ var postcss = require('postcss'); | ||
var globby = require('globby'); | ||
var fs = require('fs'); | ||
@@ -137,2 +138,7 @@ var stringToAtRule = function (str, obj) { | ||
var requireCss = function (filename) { | ||
var source = fs.readFileSync(filename); | ||
return postcss.parse(source); | ||
}; | ||
module.exports = postcss.plugin('postcss-mixins', function (opts) { | ||
@@ -151,3 +157,3 @@ if ( typeof opts === 'undefined' ) opts = { }; | ||
globs = opts.mixinsDir.map(function (dir) { | ||
return path.join(dir, '*.{json,js}'); | ||
return path.join(dir, '*.{js,json,css}'); | ||
}); | ||
@@ -159,6 +165,18 @@ } | ||
return function (css, result) { | ||
var discoverMixins = function (atrule) { | ||
if ( atrule.name === 'mixin' ) { | ||
insertMixin(result, mixins, atrule, opts); | ||
} else if ( atrule.name === 'define-mixin' ) { | ||
defineMixin(result, mixins, atrule); | ||
} | ||
}; | ||
return globby(globs).then(function (files) { | ||
files.forEach(function (file) { | ||
var name = path.basename(file, path.extname(file)); | ||
var ext = path.extname(file); | ||
var name = path.basename(file, ext); | ||
file = path.join(cwd, path.relative(cwd, file)); | ||
if (ext === '.css') { | ||
requireCss(file).walkAtRules(discoverMixins); | ||
return; | ||
} | ||
mixins[name] = { mixin: require(file) }; | ||
@@ -173,11 +191,5 @@ }); | ||
css.walkAtRules(function (rule) { | ||
if ( rule.name === 'mixin' ) { | ||
insertMixin(result, mixins, rule, opts); | ||
} else if ( rule.name === 'define-mixin' ) { | ||
defineMixin(result, mixins, rule); | ||
} | ||
}); | ||
css.walkAtRules(discoverMixins); | ||
}); | ||
}; | ||
}); |
{ | ||
"name": "postcss-mixins", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "PostCSS plugin for mixins", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18827
164
2