       after: config.after ? []
       vendorConvention: (config.vendorConvention ? -> no)
       bowerMapping: config.bowerMapping ? {}
-    files.slice().sort (a, b) -> sortBowerComponents cfg, a, b
+    files.slice().sort (a, b) -> sortByBefore cfg, a, b
   else
     files
 

    indexOfA - indexOfB
  else
    sortByAfter config, a, b

sortBowerComponents = (config, a, b) ->
  aLevel = config.bowerMapping[a]
  bLevel = config.bowerMapping[b]
  if aLevel? and not bLevel?
    -1
  else if not aLevel? and bLevel?
    1
  else if aLevel? and bLevel?
    bLevel - aLevel
  else
    sortByBefore config, a, b

# Sorts by pattern.
#

    # these two items.
    sortAlphabetically a, b

sortBowerComponents = (config, a, b) ->
  aLevel = config.bowerMapping[a]
  bLevel = config.bowerMapping[b]
  if aLevel? and not bLevel?
    -1
  else if not aLevel? and bLevel?
    1
  else if aLevel? and bLevel?
    bLevel - aLevel
  else
    sortByVendor config, a, b

# Items wasn't found in config.before, try to find then in
# config.after.
# Item that config.after contains would have lower sorting index.
