react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / glob / common.js
80708 viewsexports.alphasort = alphasort1exports.alphasorti = alphasorti2exports.isAbsolute = process.platform === "win32" ? absWin : absUnix3exports.setopts = setopts4exports.ownProp = ownProp5exports.makeAbs = makeAbs6exports.finish = finish7exports.mark = mark8exports.isIgnored = isIgnored9exports.childrenIgnored = childrenIgnored1011function ownProp (obj, field) {12return Object.prototype.hasOwnProperty.call(obj, field)13}1415var path = require("path")16var minimatch = require("minimatch")17var Minimatch = minimatch.Minimatch1819function absWin (p) {20if (absUnix(p)) return true21// pull off the device/UNC bit from a windows path.22// from node's lib/path.js23var splitDeviceRe =24/^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/25var result = splitDeviceRe.exec(p)26var device = result[1] || ''27var isUnc = device && device.charAt(1) !== ':'28var isAbsolute = !!result[2] || isUnc // UNC paths are always absolute2930return isAbsolute31}3233function absUnix (p) {34return p.charAt(0) === "/" || p === ""35}3637function alphasorti (a, b) {38return a.toLowerCase().localeCompare(b.toLowerCase())39}4041function alphasort (a, b) {42return a.localeCompare(b)43}4445function setupIgnores (self, options) {46self.ignore = options.ignore || []4748if (!Array.isArray(self.ignore))49self.ignore = [self.ignore]5051if (self.ignore.length) {52self.ignore = self.ignore.map(ignoreMap)53}54}5556function ignoreMap (pattern) {57var gmatcher = null58if (pattern.slice(-3) === '/**') {59var gpattern = pattern.replace(/(\/\*\*)+$/, '')60gmatcher = new Minimatch(gpattern, { nonegate: true })61}6263return {64matcher: new Minimatch(pattern, { nonegate: true }),65gmatcher: gmatcher66}67}6869function setopts (self, pattern, options) {70if (!options)71options = {}7273// base-matching: just use globstar for that.74if (options.matchBase && -1 === pattern.indexOf("/")) {75if (options.noglobstar) {76throw new Error("base matching requires globstar")77}78pattern = "**/" + pattern79}8081self.pattern = pattern82self.strict = options.strict !== false83self.realpath = !!options.realpath84self.realpathCache = options.realpathCache || Object.create(null)85self.follow = !!options.follow86self.dot = !!options.dot87self.mark = !!options.mark88self.nodir = !!options.nodir89if (self.nodir)90self.mark = true91self.sync = !!options.sync92self.nounique = !!options.nounique93self.nonull = !!options.nonull94self.nosort = !!options.nosort95self.nocase = !!options.nocase96self.stat = !!options.stat97self.noprocess = !!options.noprocess9899self.maxLength = options.maxLength || Infinity100self.cache = options.cache || Object.create(null)101self.statCache = options.statCache || Object.create(null)102self.symlinks = options.symlinks || Object.create(null)103104setupIgnores(self, options)105106self.changedCwd = false107var cwd = process.cwd()108if (!ownProp(options, "cwd"))109self.cwd = cwd110else {111self.cwd = options.cwd112self.changedCwd = path.resolve(options.cwd) !== cwd113}114115self.root = options.root || path.resolve(self.cwd, "/")116self.root = path.resolve(self.root)117if (process.platform === "win32")118self.root = self.root.replace(/\\/g, "/")119120self.nomount = !!options.nomount121122self.minimatch = new Minimatch(pattern, options)123self.options = self.minimatch.options124}125126function finish (self) {127var nou = self.nounique128var all = nou ? [] : Object.create(null)129130for (var i = 0, l = self.matches.length; i < l; i ++) {131var matches = self.matches[i]132if (!matches || Object.keys(matches).length === 0) {133if (self.nonull) {134// do like the shell, and spit out the literal glob135var literal = self.minimatch.globSet[i]136if (nou)137all.push(literal)138else139all[literal] = true140}141} else {142// had matches143var m = Object.keys(matches)144if (nou)145all.push.apply(all, m)146else147m.forEach(function (m) {148all[m] = true149})150}151}152153if (!nou)154all = Object.keys(all)155156if (!self.nosort)157all = all.sort(self.nocase ? alphasorti : alphasort)158159// at *some* point we statted all of these160if (self.mark) {161for (var i = 0; i < all.length; i++) {162all[i] = self._mark(all[i])163}164if (self.nodir) {165all = all.filter(function (e) {166return !(/\/$/.test(e))167})168}169}170171if (self.ignore.length)172all = all.filter(function(m) {173return !isIgnored(self, m)174})175176self.found = all177}178179function mark (self, p) {180var abs = makeAbs(self, p)181var c = self.cache[abs]182var m = p183if (c) {184var isDir = c === 'DIR' || Array.isArray(c)185var slash = p.slice(-1) === '/'186187if (isDir && !slash)188m += '/'189else if (!isDir && slash)190m = m.slice(0, -1)191192if (m !== p) {193var mabs = makeAbs(self, m)194self.statCache[mabs] = self.statCache[abs]195self.cache[mabs] = self.cache[abs]196}197}198199return m200}201202// lotta situps...203function makeAbs (self, f) {204var abs = f205if (f.charAt(0) === '/') {206abs = path.join(self.root, f)207} else if (exports.isAbsolute(f)) {208abs = f209} else if (self.changedCwd) {210abs = path.resolve(self.cwd, f)211} else if (self.realpath) {212abs = path.resolve(f)213}214return abs215}216217218// Return true, if pattern ends with globstar '**', for the accompanying parent directory.219// Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents220function isIgnored (self, path) {221if (!self.ignore.length)222return false223224return self.ignore.some(function(item) {225return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path))226})227}228229function childrenIgnored (self, path) {230if (!self.ignore.length)231return false232233return self.ignore.some(function(item) {234return !!(item.gmatcher && item.gmatcher.match(path))235})236}237238239