Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- Removed: async mode/option
([#107](https://github.com/postcss/postcss-import/pull/107))

# 7.1.3 - 2015-11-05

- Fixed: ensure node 0.12 compatibility, round 2
Expand Down
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ var atImport = require("postcss-import")
var css = fs.readFileSync("css/input.css", "utf8")

// process css
var output = postcss()
postcss()
.use(atImport())
.process(css, {
// `from` option is required so relative import can work from input dirname
from: "css/input.css"
})
.css
.then(function (result) {
var output = result.css

console.log(output)
console.log(output)
})
```

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

#### `async`

Type: `Boolean`
Default: `false`

Allow to enable PostCSS async API usage. Before enabling this, check that your
runner allow async usage.
_Note: this is not enabling async fs read yet._

#### `transform`

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

var css = postcss()
postcss()
.use(atImport({
path: ["src/css"]
transform: require("css-whitespace")
}))
.process(cssString)
.css
.then(function (result) {
var css = result.css
})
```

---
Expand Down
37 changes: 11 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var warnNodesMessage =
function AtImport(options) {
options = assign({
root: process.cwd(),
async: false,
path: [],
skipDuplicates: true,
}, options || {})
Expand Down Expand Up @@ -98,11 +97,7 @@ function AtImport(options) {
}
}

if (options.async) {
return parsedStylesResult.then(onParseEnd)
}
// else (!options.async)
onParseEnd()
return parsedStylesResult.then(onParseEnd)
}
}

Expand Down Expand Up @@ -156,11 +151,7 @@ function parseStyles(
}, atRule.source)
})

if (options.async) {
return Promise.all(importResults)
}
// else (!options.async)
// nothing
return Promise.all(importResults)
}

/**
Expand Down Expand Up @@ -377,21 +368,15 @@ function readImportedContent(
processor
)

if (options.async) {
return parsedResult.then(function() {
return processor.process(newStyles)
})
.then(function(newResult) {
result.messages = result.messages.concat(newResult.messages)
})
.then(function() {
insertRules(atRule, parsedAtImport, newStyles)
})
}
// else (!options.async)
var newResult = processor.process(newStyles)
result.messages = result.messages.concat(newResult.messages)
insertRules(atRule, parsedAtImport, newStyles)
return parsedResult.then(function() {
return processor.process(newStyles)
})
.then(function(newResult) {
result.messages = result.messages.concat(newResult.messages)
})
.then(function() {
insertRules(atRule, parsedAtImport, newStyles)
})
}

/**
Expand Down
15 changes: 0 additions & 15 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,3 @@ test("plugins option", function(t) {
t.pass("should remain silent when value is an empty array")
})
})

test("sync", function(t) {
var css = "body{}"
t.equal(
postcss()
.use(atImport())
.process(css)
.css
,
css,
"should still work sync"
)

t.end()
})