react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / node_modules / commoner / node_modules / glob / common.js
81164 viewsexports.alphasort = alphasort1exports.alphasorti = alphasorti2exports.isAbsolute = process.platform === "win32" ? absWin : absUnix3exports.setopts = setopts4exports.ownProp = ownProp5exports.makeAbs = makeAbs6exports.finish = finish7exports.mark = mark89function ownProp (obj, field) {10return Object.prototype.hasOwnProperty.call(obj, field)11}1213var path = require("path")14var minimatch = require("minimatch")15var Minimatch = minimatch.Minimatch1617function absWin (p) {18if (absUnix(p)) return true19// pull off the device/UNC bit from a windows path.20// from node's lib/path.js21var splitDeviceRe =22/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/23var result = splitDeviceRe.exec(p)24var device = result[1] || ''25var isUnc = device && device.charAt(1) !== ':'26var isAbsolute = !!result[2] || isUnc // UNC paths are always absolute2728return isAbsolute29}3031function absUnix (p) {32return p.charAt(0) === "/" || p === ""33}3435function alphasorti (a, b) {36return a.toLowerCase().localeCompare(b.toLowerCase())37}3839function alphasort (a, b) {40return a.localeCompare(b)41}424344function setopts (self, pattern, options) {45if (!options)46options = {}4748// base-matching: just use globstar for that.49if (options.matchBase && -1 === pattern.indexOf("/")) {50if (options.noglobstar) {51throw new Error("base matching requires globstar")52}53pattern = "**/" + pattern54}5556self.pattern = pattern57self.strict = options.strict !== false58self.dot = !!options.dot59self.mark = !!options.mark60self.nodir = !!options.nodir61if (self.nodir)62self.mark = true63self.sync = !!options.sync64self.nounique = !!options.nounique65self.nonull = !!options.nonull66self.nosort = !!options.nosort67self.nocase = !!options.nocase68self.stat = !!options.stat69self.noprocess = !!options.noprocess7071self.maxLength = options.maxLength || Infinity72self.cache = options.cache || Object.create(null)73self.statCache = options.statCache || Object.create(null)74self.symlinks = options.symlinks || Object.create(null)7576self.changedCwd = false77var cwd = process.cwd()78if (!ownProp(options, "cwd"))79self.cwd = cwd80else {81self.cwd = options.cwd82self.changedCwd = path.resolve(options.cwd) !== cwd83}8485self.root = options.root || path.resolve(self.cwd, "/")86self.root = path.resolve(self.root)87if (process.platform === "win32")88self.root = self.root.replace(/\\/g, "/")8990self.nomount = !!options.nomount9192self.minimatch = new Minimatch(pattern, options)93self.options = self.minimatch.options94}9596function finish (self) {97var nou = self.nounique98var all = nou ? [] : Object.create(null)99100for (var i = 0, l = self.matches.length; i < l; i ++) {101var matches = self.matches[i]102if (!matches) {103if (self.nonull) {104// do like the shell, and spit out the literal glob105var literal = self.minimatch.globSet[i]106if (nou)107all.push(literal)108else109all[literal] = true110}111} else {112// had matches113var m = Object.keys(matches)114if (nou)115all.push.apply(all, m)116else117m.forEach(function (m) {118all[m] = true119})120}121}122123if (!nou)124all = Object.keys(all)125126if (!self.nosort)127all = all.sort(self.nocase ? alphasorti : alphasort)128129// at *some* point we statted all of these130if (self.mark) {131for (var i = 0; i < all.length; i++) {132all[i] = self._mark(all[i])133}134if (self.nodir) {135all = all.filter(function (e) {136return !(/\/$/.test(e))137})138}139}140141self.found = all142}143144function mark (self, p) {145var c = self.cache[p]146var m = p147if (c) {148var isDir = c === 'DIR' || Array.isArray(c)149var slash = p.slice(-1) === '/'150151if (isDir && !slash)152m += '/'153else if (!isDir && slash)154m = m.slice(0, -1)155156if (m !== p) {157self.statCache[m] = self.statCache[p]158self.cache[m] = self.cache[p]159}160}161162return m163}164165// lotta situps...166function makeAbs (self, f) {167var abs = f168if (f.charAt(0) === "/") {169abs = path.join(self.root, f)170} else if (exports.isAbsolute(f)) {171abs = f172} else if (self.changedCwd) {173abs = path.resolve(self.cwd, f)174}175return abs176}177178179