postcss-import
Advanced tools
Comparing version 5.1.1 to 5.2.0
@@ -0,1 +1,6 @@ | ||
# 5.2.0 - 2015-04-15 | ||
- Added: [glob](https://www.npmjs.com/package/glob) pattern are now supported if `glob` option is set to true ([#34](https://github.com/postcss/postcss-import/pull/34)) | ||
- Added: plugin can now be added to PostCSS without calling it as a function ([#27](https://github.com/postcss/postcss-import/pull/27)) | ||
# 5.1.1 - 2015-04-10 | ||
@@ -2,0 +7,0 @@ |
49
index.js
@@ -14,2 +14,3 @@ "use strict"; | ||
var hash = require("string-hash") | ||
var glob = require("glob") | ||
@@ -28,2 +29,5 @@ /** | ||
module.exports = AtImport | ||
module.exports.postcss = function(styles) { | ||
return module.exports()(styles) | ||
} | ||
@@ -86,3 +90,10 @@ /** | ||
var imports = [] | ||
styles.eachAtRule("import", function checkAtRule(atRule) {imports.push(atRule)}) | ||
styles.eachAtRule("import", function checkAtRule(atRule) { | ||
if (options.glob && glob.hasMagic(atRule.params)) { | ||
imports = parseGlob(atRule, options, imports) | ||
} | ||
else { | ||
imports.push(atRule) | ||
} | ||
}) | ||
imports.forEach(function(atRule) { | ||
@@ -96,2 +107,38 @@ helpers.try(function transformAtImport() { | ||
/** | ||
* parse glob patterns (for relative paths only) | ||
* | ||
* @param {Object} atRule | ||
* @param {Object} options | ||
* @param {Array} imports | ||
*/ | ||
function parseGlob(atRule, options, imports) { | ||
var globPattern = atRule.params.replace(/"/g, "") | ||
var files = [] | ||
var dir = options.source && options.source.input && options.source.input.file ? | ||
path.dirname(path.resolve(options.root, options.source.input.file)) : | ||
options.root | ||
options.path.forEach(function(p) { | ||
p = path.resolve(dir, p) | ||
var globbed = glob.sync(path.join(p, globPattern)) | ||
globbed.forEach(function(file) { | ||
file = path.relative(p, file) | ||
files.push(file) | ||
}); | ||
}); | ||
files.forEach(function(file) { | ||
var deglobbedAtRule = atRule.clone({ | ||
params: "\"" + file + "\"" | ||
}) | ||
if (deglobbedAtRule.source && deglobbedAtRule.source.input && deglobbedAtRule.source.input.css) { | ||
deglobbedAtRule.source.input.css = atRule.source.input.css.replace(globPattern, file) | ||
} | ||
atRule.parent.insertBefore(atRule, deglobbedAtRule) | ||
imports.push(deglobbedAtRule) | ||
}); | ||
atRule.removeSelf() | ||
return imports; | ||
} | ||
/** | ||
* put back at the top ignored url (absolute url) | ||
@@ -98,0 +145,0 @@ * |
{ | ||
"name": "postcss-import", | ||
"version": "5.1.1", | ||
"version": "5.2.0", | ||
"description": "PostCSS plugin to import CSS files", | ||
@@ -26,2 +26,3 @@ "keywords": [ | ||
"clone": "^0.1.17", | ||
"glob": "^5.0.1", | ||
"postcss": "^4.0.2", | ||
@@ -28,0 +29,0 @@ "postcss-message-helpers": "^2.0.0", |
@@ -117,2 +117,9 @@ # postcss-import [![Travis Build Status](https://travis-ci.org/postcss/postcss-import.svg)](https://travis-ci.org/postcss/postcss-import) [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/u8l6u3lr6s5u5tpi?svg=true)](https://ci.appveyor.com/project/MoOx/postcss-import) | ||
#### `glob` | ||
Type: `Boolean` | ||
Default: `false` | ||
Set to `true` if you want @import rules to parse glob patterns. | ||
#### Example with some options | ||
@@ -119,0 +126,0 @@ |
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
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
21243
356
155
6
+ Addedglob@^5.0.1
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedglob@5.0.15(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)