Skip to content

Commit 2f93068

Browse files
RyanZimMoOx
authored andcommitted
Fixed: Nested import ordering (#236)
Had to edit a test that depended on the old, incorrect behavior Closes #168
1 parent 344528c commit 2f93068

File tree

4 files changed

+8
-20
lines changed

4 files changed

+8
-20
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var joinMedia = require("./lib/join-media")
55
var resolveId = require("./lib/resolve-id")
66
var loadContent = require("./lib/load-content")
77
var parseStatements = require("./lib/parse-statements")
8+
var promiseEach = require("promise-each")
89

910
function AtImport(options) {
1011
options = assign({
@@ -163,7 +164,7 @@ function parseStyles(
163164
) {
164165
var statements = parseStatements(result, styles)
165166

166-
return Promise.all(statements.map(function(stmt) {
167+
return Promise.resolve(statements).then(promiseEach(function(stmt) {
167168
stmt.media = joinMedia(media, stmt.media || [])
168169

169170
// skip protocol base uri (protocol://url) or protocol-relative

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"pkg-resolve": "^0.1.7",
2323
"postcss": "^5.0.14",
2424
"postcss-value-parser": "^3.2.3",
25+
"promise-each": "^2.2.0",
2526
"read-cache": "^1.0.0",
2627
"resolve": "^1.1.7"
2728
},

test/order.js

+4-18
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,13 @@ import compareFixtures from "./helpers/compare-fixtures"
33

44
test(`should order nested imports correctly`, t => {
55
var first = true
6-
var resolve = require("resolve")
6+
var path = require("path")
77

88
return compareFixtures(t, "order", {
99
path: "fixtures/imports",
10-
resolve: (id, base, opts) => {
11-
var resolveOpts = {
12-
basedir: base,
13-
moduleDirectory: [],
14-
paths: opts.path,
15-
extensions: [ ".css" ],
16-
}
17-
18-
return new Promise(function(res, rej) {
19-
var doResolve = () => {
20-
resolve(id, resolveOpts, function(err, path) {
21-
if (err) {
22-
return rej(err)
23-
}
24-
res(path)
25-
})
26-
}
10+
resolve: (id) => {
11+
return new Promise(function(res) {
12+
var doResolve = () => res(path.resolve("fixtures/imports", id))
2713

2814
if (first) {
2915
// Delay the first import so the second gets loaded first

test/plugins.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test("should apply plugins to root", t => {
2929
})
3030
.then(() => {
3131
t.deepEqual(atRules, [ "import" ])
32-
t.deepEqual(rules, [ "bar", "foo" ])
32+
t.deepEqual(rules, [ "foo", "bar" ])
3333
})
3434
})
3535

0 commit comments

Comments
 (0)