Skip to content
Open
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
11 changes: 8 additions & 3 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ module.exports = (patterns = [], options = {}) ->
file.relative

rank = (s) ->
for matcher, index in matchers
return index if matcher.match s
indexes = matchers.map (matcher, index) ->
if matcher.match s then index else undefined
.filter (index) ->
index?

return matchers.length
if indexes.length
indexes[indexes.length - 1]
else
matchers.length

onEnd = ->
sort.inplace files, (a, b) ->
Expand Down
30 changes: 30 additions & 0 deletions test/tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,36 @@ describe "gulp-order", ->
stream.write newFile("b.css", path.join(cwd, "scripts/"))
stream.end()

it "order file by last matched index", (done) ->
stream = order(["vendor/**/*", "vendor/**/foo/**/*"])

files = []
stream.on "data", files.push.bind(files)
stream.on "end", ->
expect(files.length).to.equal 8
relatives = files.map (file) -> file.relative
expect(relatives).to.equal [
"vendor/a.js"
"vendor/b.js"
"vendor/bar/a.js"
"vendor/bar/b.js"
"vendor/bar/foo/a.js"
"vendor/bar/foo/b.js"
"vendor/foo/a.js"
"vendor/foo/b.js"
]
done()

stream.write newFile("vendor/bar/a.js")
stream.write newFile("vendor/bar/b.js")
stream.write newFile("vendor/bar/foo/a.js")
stream.write newFile("vendor/bar/foo/b.js")
stream.write newFile("vendor/foo/a.js")
stream.write newFile("vendor/foo/b.js")
stream.write newFile("vendor/a.js")
stream.write newFile("vendor/b.js")
stream.end()

it "warns on relative paths in order list", ->
expect ->
order(['./user.js'])
Expand Down