Skip to content

Commit a9c6105

Browse files
committed
Merge pull request #107 from postcss/async-only
Use async mode only
2 parents 430fc34 + a61081b commit a9c6105

File tree

4 files changed

+23
-55
lines changed

4 files changed

+23
-55
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- Removed: async mode/option
2+
([#107](https://github.com/postcss/postcss-import/pull/107))
3+
14
# 7.1.3 - 2015-11-05
25

36
- Fixed: ensure node 0.12 compatibility, round 2

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ var atImport = require("postcss-import")
3939
var css = fs.readFileSync("css/input.css", "utf8")
4040

4141
// process css
42-
var output = postcss()
42+
postcss()
4343
.use(atImport())
4444
.process(css, {
4545
// `from` option is required so relative import can work from input dirname
4646
from: "css/input.css"
4747
})
48-
.css
48+
.then(function (result) {
49+
var output = result.css
4950

50-
console.log(output)
51+
console.log(output)
52+
})
5153
```
5254

5355
Using this `input.css`:
@@ -102,15 +104,6 @@ Default: `process.cwd()` or _dirname of [the postcss `from`](https://github.com/
102104
A string or an array of paths in where to look for files.
103105
_Note: nested `@import` will additionally benefit of the relative dirname of imported files._
104106

105-
#### `async`
106-
107-
Type: `Boolean`
108-
Default: `false`
109-
110-
Allow to enable PostCSS async API usage. Before enabling this, check that your
111-
runner allow async usage.
112-
_Note: this is not enabling async fs read yet._
113-
114107
#### `transform`
115108

116109
Type: `Function`
@@ -187,13 +180,15 @@ It's equivalent to `onImport` with the following code:
187180
var postcss = require("postcss")
188181
var atImport = require("postcss-import")
189182

190-
var css = postcss()
183+
postcss()
191184
.use(atImport({
192185
path: ["src/css"]
193186
transform: require("css-whitespace")
194187
}))
195188
.process(cssString)
196-
.css
189+
.then(function (result) {
190+
var css = result.css
191+
})
197192
```
198193

199194
---

index.js

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var warnNodesMessage =
3131
function AtImport(options) {
3232
options = assign({
3333
root: process.cwd(),
34-
async: false,
3534
path: [],
3635
skipDuplicates: true,
3736
}, options || {})
@@ -98,11 +97,7 @@ function AtImport(options) {
9897
}
9998
}
10099

101-
if (options.async) {
102-
return parsedStylesResult.then(onParseEnd)
103-
}
104-
// else (!options.async)
105-
onParseEnd()
100+
return parsedStylesResult.then(onParseEnd)
106101
}
107102
}
108103

@@ -156,11 +151,7 @@ function parseStyles(
156151
}, atRule.source)
157152
})
158153

159-
if (options.async) {
160-
return Promise.all(importResults)
161-
}
162-
// else (!options.async)
163-
// nothing
154+
return Promise.all(importResults)
164155
}
165156

166157
/**
@@ -377,21 +368,15 @@ function readImportedContent(
377368
processor
378369
)
379370

380-
if (options.async) {
381-
return parsedResult.then(function() {
382-
return processor.process(newStyles)
383-
})
384-
.then(function(newResult) {
385-
result.messages = result.messages.concat(newResult.messages)
386-
})
387-
.then(function() {
388-
insertRules(atRule, parsedAtImport, newStyles)
389-
})
390-
}
391-
// else (!options.async)
392-
var newResult = processor.process(newStyles)
393-
result.messages = result.messages.concat(newResult.messages)
394-
insertRules(atRule, parsedAtImport, newStyles)
371+
return parsedResult.then(function() {
372+
return processor.process(newStyles)
373+
})
374+
.then(function(newResult) {
375+
result.messages = result.messages.concat(newResult.messages)
376+
})
377+
.then(function() {
378+
insertRules(atRule, parsedAtImport, newStyles)
379+
})
395380
}
396381

397382
/**

test/index.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,3 @@ test("plugins option", function(t) {
362362
t.pass("should remain silent when value is an empty array")
363363
})
364364
})
365-
366-
test("sync", function(t) {
367-
var css = "body{}"
368-
t.equal(
369-
postcss()
370-
.use(atImport())
371-
.process(css)
372-
.css
373-
,
374-
css,
375-
"should still work sync"
376-
)
377-
378-
t.end()
379-
})

0 commit comments

Comments
 (0)