Skip to content

Commit

Permalink
Fixed: Nested import ordering (#236)
Browse files Browse the repository at this point in the history
Had to edit a test that depended on the old, incorrect behavior

Closes #168
  • Loading branch information
RyanZim authored and MoOx committed Nov 3, 2016
1 parent 344528c commit 2f93068
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var joinMedia = require("./lib/join-media")
var resolveId = require("./lib/resolve-id")
var loadContent = require("./lib/load-content")
var parseStatements = require("./lib/parse-statements")
var promiseEach = require("promise-each")

function AtImport(options) {
options = assign({
Expand Down Expand Up @@ -163,7 +164,7 @@ function parseStyles(
) {
var statements = parseStatements(result, styles)

return Promise.all(statements.map(function(stmt) {
return Promise.resolve(statements).then(promiseEach(function(stmt) {
stmt.media = joinMedia(media, stmt.media || [])

// skip protocol base uri (protocol://url) or protocol-relative
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"pkg-resolve": "^0.1.7",
"postcss": "^5.0.14",
"postcss-value-parser": "^3.2.3",
"promise-each": "^2.2.0",
"read-cache": "^1.0.0",
"resolve": "^1.1.7"
},
Expand Down
22 changes: 4 additions & 18 deletions test/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,13 @@ import compareFixtures from "./helpers/compare-fixtures"

test(`should order nested imports correctly`, t => {
var first = true
var resolve = require("resolve")
var path = require("path")

return compareFixtures(t, "order", {
path: "fixtures/imports",
resolve: (id, base, opts) => {
var resolveOpts = {
basedir: base,
moduleDirectory: [],
paths: opts.path,
extensions: [ ".css" ],
}

return new Promise(function(res, rej) {
var doResolve = () => {
resolve(id, resolveOpts, function(err, path) {
if (err) {
return rej(err)
}
res(path)
})
}
resolve: (id) => {
return new Promise(function(res) {
var doResolve = () => res(path.resolve("fixtures/imports", id))

if (first) {
// Delay the first import so the second gets loaded first
Expand Down
2 changes: 1 addition & 1 deletion test/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test("should apply plugins to root", t => {
})
.then(() => {
t.deepEqual(atRules, [ "import" ])
t.deepEqual(rules, [ "bar", "foo" ])
t.deepEqual(rules, [ "foo", "bar" ])
})
})

Expand Down

0 comments on commit 2f93068

Please sign in to comment.