Skip to content

Commit 6aaa8db

Browse files
committed
Merge pull request #147 from postcss/transform
Extended transform support
2 parents 74879af + 40cdbf6 commit 6aaa8db

13 files changed

+43
-26
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ postcssImport({
4141
})
4242
```
4343

44+
- Changed: support promise in `transform` option and `undefined` result will be skipped
45+
([#147](https://github.com/postcss/postcss-import/pull/147))
46+
4447
# 7.1.3 - 2015-11-05
4548

4649
- Fixed: ensure node 0.12 compatibility, round 2

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ _Note: nested `@import` will additionally benefit of the relative dirname of imp
109109
Type: `Function`
110110
Default: `null`
111111

112-
A function to transform the content of imported files. Take one argument (file content) & should return the modified content.
112+
A function to transform the content of imported files. Take one argument (file content) and should return the modified content or promise with it.
113+
`undefined` result will be skipped.
113114

114115
#### `plugins`
115116

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,15 @@ function loadImportContent(
284284

285285
return Promise.resolve(options.load(filename, options))
286286
.then(function(content) {
287-
if (typeof options.transform === "function") {
288-
content = options.transform(content, filename)
287+
if (typeof options.transform !== "function") {
288+
return content
289289
}
290-
290+
return Promise.resolve(options.transform(content, filename, options))
291+
.then(function(transformed) {
292+
return typeof transformed === "string" ? transformed : content
293+
})
294+
})
295+
.then(function(content) {
291296
if (content.trim() === "") {
292297
result.warn(filename + " is empty", { node: atRule })
293298
return

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
},
2525
"devDependencies": {
2626
"ava": "^0.8.0",
27-
"css-whitespace": "^1.1.1",
2827
"eslint": "^1.1.0",
2928
"postcss-scss": "^0.1.3"
3029
},

test/fixtures/imports/foo.styl

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "foo"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
transformed-content {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "foo"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo{}

test/fixtures/transform.css

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)