Skip to content

Commit

Permalink
chore: refactor to remove mixin pattern (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Apr 4, 2022
1 parent 0967900 commit 23678ea
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ const defaultRules = [
// There may be others, but :?|<> are handled by node-tar
const nameIsBadForWindows = file => /\*/.test(file)

// a decorator that applies our custom rules to an ignore walker
const npmWalker = Class => class Walker extends Class {
class Walker extends IgnoreWalker {
constructor (opt) {
opt = opt || {}

Expand Down Expand Up @@ -397,11 +396,19 @@ const npmWalker = Class => class Walker extends Class {
}

sort (a, b) {
return sort(a, b)
// optimize for compressibility
// extname, then basename, then locale alphabetically
// https://twitter.com/isntitvacant/status/1131094910923231232
const exta = path.extname(a).toLowerCase()
const extb = path.extname(b).toLowerCase()
const basea = path.basename(a).toLowerCase()
const baseb = path.basename(b).toLowerCase()

return exta.localeCompare(extb, 'en') ||
basea.localeCompare(baseb, 'en') ||
a.localeCompare(b, 'en')
}
}

class Walker extends npmWalker(IgnoreWalker) {
globFiles (pattern, cb) {
glob(pattern, { dot: true, cwd: this.path, nocase: true }, cb)
}
Expand Down Expand Up @@ -430,19 +437,5 @@ const walk = (options, callback) => {
return callback ? p.then(res => callback(null, res), callback) : p
}

// optimize for compressibility
// extname, then basename, then locale alphabetically
// https://twitter.com/isntitvacant/status/1131094910923231232
const sort = (a, b) => {
const exta = path.extname(a).toLowerCase()
const extb = path.extname(b).toLowerCase()
const basea = path.basename(a).toLowerCase()
const baseb = path.basename(b).toLowerCase()

return exta.localeCompare(extb, 'en') ||
basea.localeCompare(baseb, 'en') ||
a.localeCompare(b, 'en')
}

module.exports = walk
walk.Walker = Walker

0 comments on commit 23678ea

Please sign in to comment.