Static build of browserify.
authorDavid Schoonover <dsc@wikimedia.org>
Tue, 10 Jul 2012 12:48:38 +0000 (05:48 -0700)
committerDavid Schoonover <dsc@wikimedia.org>
Tue, 10 Jul 2012 12:48:38 +0000 (05:48 -0700)
static/vendor/browserify.js [new file with mode: 0644]

diff --git a/static/vendor/browserify.js b/static/vendor/browserify.js
new file mode 100644 (file)
index 0000000..ad964ea
--- /dev/null
@@ -0,0 +1,11511 @@
+var require = function (file, cwd) {
+    var resolved = require.resolve(file, cwd || '/');
+    var mod = require.modules[resolved];
+    if (!mod) throw new Error(
+        'Failed to resolve module ' + file + ', tried ' + resolved
+    );
+    var res = mod._cached ? mod._cached : mod();
+    return res;
+}
+
+require.paths = [];
+require.modules = {};
+require.extensions = [".js",".coffee"];
+
+require._core = {
+    'assert': true,
+    'events': true,
+    'fs': true,
+    'path': true,
+    'vm': true
+};
+
+require.resolve = (function () {
+    return function (x, cwd) {
+        if (!cwd) cwd = '/';
+        
+        if (require._core[x]) return x;
+        var path = require.modules.path();
+        var y = cwd || '.';
+        
+        if (x.match(/^(?:\.\.?\/|\/)/)) {
+            var m = loadAsFileSync(path.resolve(y, x))
+                || loadAsDirectorySync(path.resolve(y, x));
+            if (m) return m;
+        }
+        
+        var n = loadNodeModulesSync(x, y);
+        if (n) return n;
+        
+        throw new Error("Cannot find module '" + x + "'");
+        
+        function loadAsFileSync (x) {
+            if (require.modules[x]) {
+                return x;
+            }
+            
+            for (var i = 0; i < require.extensions.length; i++) {
+                var ext = require.extensions[i];
+                if (require.modules[x + ext]) return x + ext;
+            }
+        }
+        
+        function loadAsDirectorySync (x) {
+            x = x.replace(/\/+$/, '');
+            var pkgfile = x + '/package.json';
+            if (require.modules[pkgfile]) {
+                var pkg = require.modules[pkgfile]();
+                var b = pkg.browserify;
+                if (typeof b === 'object' && b.main) {
+                    var m = loadAsFileSync(path.resolve(x, b.main));
+                    if (m) return m;
+                }
+                else if (typeof b === 'string') {
+                    var m = loadAsFileSync(path.resolve(x, b));
+                    if (m) return m;
+                }
+                else if (pkg.main) {
+                    var m = loadAsFileSync(path.resolve(x, pkg.main));
+                    if (m) return m;
+                }
+            }
+            
+            return loadAsFileSync(x + '/index');
+        }
+        
+        function loadNodeModulesSync (x, start) {
+            var dirs = nodeModulesPathsSync(start);
+            for (var i = 0; i < dirs.length; i++) {
+                var dir = dirs[i];
+                var m = loadAsFileSync(dir + '/' + x);
+                if (m) return m;
+                var n = loadAsDirectorySync(dir + '/' + x);
+                if (n) return n;
+            }
+            
+            var m = loadAsFileSync(x);
+            if (m) return m;
+        }
+        
+        function nodeModulesPathsSync (start) {
+            var parts;
+            if (start === '/') parts = [ '' ];
+            else parts = path.normalize(start).split('/');
+            
+            var dirs = [];
+            for (var i = parts.length - 1; i >= 0; i--) {
+                if (parts[i] === 'node_modules') continue;
+                var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
+                dirs.push(dir);
+            }
+            
+            return dirs;
+        }
+    };
+})();
+
+require.alias = function (from, to) {
+    var path = require.modules.path();
+    var res = null;
+    try {
+        res = require.resolve(from + '/package.json', '/');
+    }
+    catch (err) {
+        res = require.resolve(from, '/');
+    }
+    var basedir = path.dirname(res);
+    
+    var keys = (Object.keys || function (obj) {
+        var res = [];
+        for (var key in obj) res.push(key)
+        return res;
+    })(require.modules);
+    
+    for (var i = 0; i < keys.length; i++) {
+        var key = keys[i];
+        if (key.slice(0, basedir.length + 1) === basedir + '/') {
+            var f = key.slice(basedir.length);
+            require.modules[to + f] = require.modules[basedir + f];
+        }
+        else if (key === basedir) {
+            require.modules[to] = require.modules[basedir];
+        }
+    }
+};
+
+require.define = function (filename, fn) {
+    var dirname = require._core[filename]
+        ? ''
+        : require.modules.path().dirname(filename)
+    ;
+    
+    var require_ = function (file) {
+        return require(file, dirname)
+    };
+    require_.resolve = function (name) {
+        return require.resolve(name, dirname);
+    };
+    require_.modules = require.modules;
+    require_.define = require.define;
+    var module_ = { exports : {} };
+    
+    require.modules[filename] = function () {
+        require.modules[filename]._cached = module_.exports;
+        fn.call(
+            module_.exports,
+            require_,
+            module_,
+            module_.exports,
+            dirname,
+            filename
+        );
+        require.modules[filename]._cached = module_.exports;
+        return module_.exports;
+    };
+};
+
+if (typeof process === 'undefined') process = {};
+
+if (!process.nextTick) process.nextTick = (function () {
+    var queue = [];
+    var canPost = typeof window !== 'undefined'
+        && window.postMessage && window.addEventListener
+    ;
+    
+    if (canPost) {
+        window.addEventListener('message', function (ev) {
+            if (ev.source === window && ev.data === 'browserify-tick') {
+                ev.stopPropagation();
+                if (queue.length > 0) {
+                    var fn = queue.shift();
+                    fn();
+                }
+            }
+        }, true);
+    }
+    
+    return function (fn) {
+        if (canPost) {
+            queue.push(fn);
+            window.postMessage('browserify-tick', '*');
+        }
+        else setTimeout(fn, 0);
+    };
+})();
+
+if (!process.title) process.title = 'browser';
+
+if (!process.binding) process.binding = function (name) {
+    if (name === 'evals') return require('vm')
+    else throw new Error('No such module')
+};
+
+if (!process.cwd) process.cwd = function () { return '.' };
+
+require.define("path", function (require, module, exports, __dirname, __filename) {
+function filter (xs, fn) {
+    var res = [];
+    for (var i = 0; i < xs.length; i++) {
+        if (fn(xs[i], i, xs)) res.push(xs[i]);
+    }
+    return res;
+}
+
+// resolves . and .. elements in a path array with directory names there
+// must be no slashes, empty elements, or device names (c:\) in the array
+// (so also no leading and trailing slashes - it does not distinguish
+// relative and absolute paths)
+function normalizeArray(parts, allowAboveRoot) {
+  // if the path tries to go above the root, `up` ends up > 0
+  var up = 0;
+  for (var i = parts.length; i >= 0; i--) {
+    var last = parts[i];
+    if (last == '.') {
+      parts.splice(i, 1);
+    } else if (last === '..') {
+      parts.splice(i, 1);
+      up++;
+    } else if (up) {
+      parts.splice(i, 1);
+      up--;
+    }
+  }
+
+  // if the path is allowed to go above the root, restore leading ..s
+  if (allowAboveRoot) {
+    for (; up--; up) {
+      parts.unshift('..');
+    }
+  }
+
+  return parts;
+}
+
+// Regex to split a filename into [*, dir, basename, ext]
+// posix version
+var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
+
+// path.resolve([from ...], to)
+// posix version
+exports.resolve = function() {
+var resolvedPath = '',
+    resolvedAbsolute = false;
+
+for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
+  var path = (i >= 0)
+      ? arguments[i]
+      : process.cwd();
+
+  // Skip empty and invalid entries
+  if (typeof path !== 'string' || !path) {
+    continue;
+  }
+
+  resolvedPath = path + '/' + resolvedPath;
+  resolvedAbsolute = path.charAt(0) === '/';
+}
+
+// At this point the path should be resolved to a full absolute path, but
+// handle relative paths to be safe (might happen when process.cwd() fails)
+
+// Normalize the path
+resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
+    return !!p;
+  }), !resolvedAbsolute).join('/');
+
+  return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
+};
+
+// path.normalize(path)
+// posix version
+exports.normalize = function(path) {
+var isAbsolute = path.charAt(0) === '/',
+    trailingSlash = path.slice(-1) === '/';
+
+// Normalize the path
+path = normalizeArray(filter(path.split('/'), function(p) {
+    return !!p;
+  }), !isAbsolute).join('/');
+
+  if (!path && !isAbsolute) {
+    path = '.';
+  }
+  if (path && trailingSlash) {
+    path += '/';
+  }
+  
+  return (isAbsolute ? '/' : '') + path;
+};
+
+
+// posix version
+exports.join = function() {
+  var paths = Array.prototype.slice.call(arguments, 0);
+  return exports.normalize(filter(paths, function(p, index) {
+    return p && typeof p === 'string';
+  }).join('/'));
+};
+
+
+exports.dirname = function(path) {
+  var dir = splitPathRe.exec(path)[1] || '';
+  var isWindows = false;
+  if (!dir) {
+    // No dirname
+    return '.';
+  } else if (dir.length === 1 ||
+      (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
+    // It is just a slash or a drive letter with a slash
+    return dir;
+  } else {
+    // It is a full dirname, strip trailing slash
+    return dir.substring(0, dir.length - 1);
+  }
+};
+
+
+exports.basename = function(path, ext) {
+  var f = splitPathRe.exec(path)[2] || '';
+  // TODO: make this comparison case-insensitive on windows?
+  if (ext && f.substr(-1 * ext.length) === ext) {
+    f = f.substr(0, f.length - ext.length);
+  }
+  return f;
+};
+
+
+exports.extname = function(path) {
+  return splitPathRe.exec(path)[3] || '';
+};
+
+});
+
+require.define("/node_modules/seq/package.json", function (require, module, exports, __dirname, __filename) {
+module.exports = {"main":"./index.js"}
+});
+
+require.define("/node_modules/seq/index.js", function (require, module, exports, __dirname, __filename) {
+var EventEmitter = require('events').EventEmitter;
+var Hash = require('hashish');
+var Chainsaw = require('chainsaw');
+
+var slice = [].slice;
+
+module.exports = Seq;
+function Seq (xs) {
+    if (xs && !Array.isArray(xs) || arguments.length > 1) {
+        throw new Error('Optional argument to Seq() is exactly one Array');
+    }
+    
+    var ch = Chainsaw(function (saw) {
+        builder.call(this, saw, xs || []);
+    });
+    
+    process.nextTick(function () {
+        ch['catch'](function (err) {
+            console.error(err.stack ? err.stack : err)
+        });
+    });
+    return ch;
+}
+
+Seq.ap = Seq; // for compatability with versions <0.3
+
+function builder (saw, xs) {
+    var context = {
+        dead : false,
+        vars : {},
+        args : {},
+        stack : xs,
+        error : null
+    };
+    context.stack_ = context.stack;
+    
+    function die(){
+        context.dead = true;
+        saw.step = saw.actions.length+1;
+    }
+    context.die = die;
+    
+    function action (step, key, start, finish){
+        var cb = function (err) {
+            var args = slice.call(arguments, 1);
+            if (context.dead) {
+                saw.step = saw.actions.length+1;
+            } else if (err) {
+                context.error = { message : err, key : key };
+                saw.jump(lastPar);
+                saw.down('catch');
+                finish();
+            } else {
+                if (typeof key == 'number') {
+                    context.stack_[key] = args[0];
+                    context.args[key] = args;
+                } else {
+                    context.stack_.push.apply(context.stack_, args);
+                    if (key !== undefined) {
+                        context.vars[key] = args[0];
+                        context.args[key] = args;
+                    }
+                }
+                if (finish) finish(args, key);
+            }
+        };
+        Hash(context).forEach(function (v,k) { cb[k] = v });
+        
+        cb.into = function (k) {
+            key = k;
+            return cb;
+        };
+        
+        cb.next = function (err, xs) {
+            context.stack_.push.apply(context.stack_, xs);
+            cb.apply(cb, [err].concat(context.stack));
+        };
+        
+        cb.pass = function (err) {
+            cb.apply(cb, [err].concat(context.stack));
+        };
+        
+        cb.ok = cb.bind(cb, null);
+        
+        cb.die = function (){
+            die();
+            return cb;
+        };
+        
+        start.apply(cb, context.stack);
+    }
+    
+    var running = 0;
+    var errors = 0;
+    
+    this.seq = function (key, cb) {
+        var bound = slice.call(arguments, 2);
+        
+        if (typeof key === 'function') {
+            if (arguments.length > 1) bound.unshift(cb);
+            cb = key;
+            key = undefined;
+        }
+        
+        if (context.error) saw.next()
+        else if (running === 0) {
+            action(saw.step, key,
+                function () {
+                    context.stack_ = [];
+                    var args = slice.call(arguments);
+                    args.unshift.apply(args, bound.map(function (arg) {
+                        return arg === Seq ? this : arg
+                    }, this));
+                    
+                    cb.apply(this, args);
+                }, function () {
+                    context.stack = context.stack_;
+                    saw.next()
+                }
+            );
+        }
+    };
+    
+    var lastPar = null;
+    this.par = function (key, cb) {
+        lastPar = saw.step;
+        
+        if (running == 0) {
+            // empty the active stack for the first par() in a chain
+            context.stack_ = [];
+        }
+        
+        var bound = slice.call(arguments, 2);
+        if (typeof key === 'function') {
+            if (arguments.length > 1) bound.unshift(cb);
+            cb = key;
+            key = context.stack_.length;
+            context.stack_.push(null);
+        }
+        var cb_ = function () {
+            var args = slice.call(arguments);
+            args.unshift.apply(args, bound.map(function (arg) {
+                return arg === Seq ? this : arg
+            }, this));
+            
+            cb.apply(this, args);
+        };
+        
+        running ++;
+        
+        var step = saw.step;
+        process.nextTick(function () {
+            action(step, key, cb_, function (args) {
+                if (!args) errors ++;
+                
+                running --;
+                if (running == 0) {
+                    context.stack = context.stack_.slice();
+                    saw.step = lastPar;
+                    if (errors > 0) saw.down('catch');
+                    errors = 0;
+                    saw.next();
+                }
+            });
+        });
+        saw.next();
+    };
+    
+    [ 'seq', 'par' ].forEach(function (name) {
+        this[name + '_'] = function (key) {
+            var args = slice.call(arguments);
+            
+            var cb = typeof key === 'function'
+                ? args[0] : args[1];
+            
+            var fn = function () {
+                var argv = slice.call(arguments);
+                argv.unshift(this);
+                cb.apply(this, argv);
+            };
+            
+            if (typeof key === 'function') {
+                args[0] = fn;
+            }
+            else {
+                args[1] = fn;
+            }
+            
+            this[name].apply(this, args);
+        };
+    }, this);
+    
+    this['catch'] = function (cb) {
+        if (context.error) {
+            cb.call(context, context.error.message, context.error.key);
+            context.error = null;
+        }
+        saw.next();
+    };
+    
+    this.forEach = function (limit, cb) {
+        if (cb === undefined) { cb = limit; limit = null; }
+        
+        this.seq(function (){
+            if (context.stack.length === 0)
+                return this(null);
+            
+            var xs       = context.stack.slice()
+            ,   len      = xs.length
+            ,   active   = 0
+            ,   finished = 0
+            ,   queue    = []
+            ,   visitor
+            ;
+            
+            context.stack_ = xs.slice();
+            
+            if (!limit || limit <= 0)
+                visitor = function (x, i){
+                    action(saw.step, i, function (){
+                        cb.call(this, x, i);
+                        if (i === len - 1)
+                            saw.next();
+                    });
+                }
+            else
+                visitor = function eachCall(x, i){
+                    if (active >= limit)
+                        return queue.push(eachCall.bind(this, x, i));
+                    
+                    active++;
+                    action(saw.step, i,
+                        function (){ cb.call(this, x, i); },
+                        function (){
+                            active--;
+                            finished++;
+                            if (queue.length > 0)
+                                queue.shift()();
+                            else if (i === len - 1)
+                                saw.next();
+                        }
+                    );
+                };
+            
+            xs.forEach(visitor);
+        });
+    };
+    
+    this.seqEach = function (cb) {
+        this.seq(function () {
+            context.stack_ = context.stack.slice();
+            var xs = context.stack.slice();
+            if (xs.length === 0) this(null);
+            else (function next (i) {
+                action(
+                    saw.step, i,
+                    function () { cb.call(this, xs[i], i) },
+                    function (args) {
+                        if (!args || i === xs.length - 1) saw.next();
+                        else next(i + 1);
+                    }
+                );
+            }).bind(this)(0);
+        });
+    };
+    
+    this.parEach = function (limit, cb) {
+        var xs = context.stack.slice();
+        if (cb === undefined) { cb = limit; limit = xs.length }
+        context.stack_ = [];
+        
+        var active = 0;
+        var finished = 0;
+        var queue = [];
+        
+        if (xs.length === 0) saw.next()
+        else xs.forEach(function call (x, i) {
+            if (active >= limit) {
+                queue.push(call.bind(this, x, i));
+            }
+            else {
+                active ++;
+                action(saw.step, i,
+                    function () {
+                        cb.call(this, x, i);
+                    },
+                    function () {
+                        active --;
+                        finished ++;
+                        if (queue.length > 0) queue.shift()();
+                        else if (finished === xs.length) {
+                            saw.next();
+                        }
+                    }
+                );
+            }
+        });
+    };
+    
+    this.parMap = function (limit, cb) {
+        var res = [];
+        var len = context.stack.length;
+        if (cb === undefined) { cb = limit; limit = len }
+        var res = [];
+        
+        Seq()
+            .extend(context.stack)
+            .parEach(limit, function (x, i) {
+                var self = this;
+                
+                var next = function () {
+                    res[i] = arguments[1];
+                    self.apply(self, arguments);
+                };
+                
+                next.stack = self.stack;
+                next.stack_ = self.stack_;
+                next.vars = self.vars;
+                next.args = self.args;
+                next.error = self.error;
+                
+                next.into = function (key) {
+                    return function () {
+                        res[key] = arguments[1];
+                        self.apply(self, arguments);
+                    };
+                };
+                
+                next.ok = function () {
+                    var args = slice.call(arguments);
+                    args.unshift(null);
+                    return next.apply(next, args);
+                };
+                
+                cb.apply(next, arguments);
+            })
+            .seq(function () {
+                context.stack = res;
+                saw.next();
+            })
+        ;
+    };
+    
+    this.seqMap = function (cb) {
+        var res = [];
+        var lastIdx = context.stack.length - 1;
+        
+        this.seqEach(function (x, i) {
+            var self = this;
+            
+            var next = function () {
+                res[i] = arguments[1];
+                if (i === lastIdx)
+                    context.stack = res;
+                self.apply(self, arguments);
+            };
+            
+            next.stack = self.stack;
+            next.stack_ = self.stack_;
+            next.vars = self.vars;
+            next.args = self.args;
+            next.error = self.error;
+            
+            next.into = function (key) {
+                return function () {
+                    res[key] = arguments[1];
+                    if (i === lastIdx)
+                        context.stack = res;
+                    self.apply(self, arguments);
+                };
+            };
+            
+            next.ok = function () {
+                var args = slice.call(arguments);
+                args.unshift(null);
+                return next.apply(next, args);
+            };
+            
+            cb.apply(next, arguments);
+        });
+    };
+    
+    /**
+     * Consumes any errors that occur in `cb`. Calls to `this.into(i)` will place
+     * that value, if accepted by the filter, at the index in the results as
+     * if it were the i-th index before filtering. (This means it will never 
+     * override another value, and will only actually appear at i if the filter
+     * accepts all values before i.)
+     */
+    this.parFilter = function (limit, cb) {
+        var res = [];
+        var len = context.stack.length;
+        if (cb === undefined) { cb = limit; limit = len }
+        var res = [];
+        
+        Seq()
+            .extend(context.stack)
+            .parEach(limit, function (x, i) {
+                var self = this;
+                
+                var next = function (err, ok) {
+                    if (!err && ok)
+                        res.push([i, x]);
+                    arguments[0] = null; // discard errors
+                    self.apply(self, arguments);
+                };
+                
+                next.stack = self.stack;
+                next.stack_ = self.stack_;
+                next.vars = self.vars;
+                next.args = self.args;
+                next.error = self.error;
+                
+                next.into = function (key) {
+                    return function (err, ok) {
+                        if (!err && ok)
+                            res.push([key, x]);
+                        arguments[0] = null; // discard errors
+                        self.apply(self, arguments);
+                    };
+                };
+                
+                next.ok = function () {
+                    var args = slice.call(arguments);
+                    args.unshift(null);
+                    return next.apply(next, args);
+                };
+                
+                cb.apply(next, arguments);
+            })
+            .seq(function () {
+                context.stack = res.sort().map(function(pair){ return pair[1]; });
+                saw.next();
+            })
+        ;
+    };
+    
+    /**
+     * Consumes any errors that occur in `cb`. Calls to `this.into(i)` will place
+     * that value, if accepted by the filter, at the index in the results as
+     * if it were the i-th index before filtering. (This means it will never 
+     * override another value, and will only actually appear at i if the filter
+     * accepts all values before i.)
+     */
+    this.seqFilter = function (cb) {
+        var res = [];
+        var lastIdx = context.stack.length - 1;
+        
+        this.seqEach(function (x, i) {
+            var self = this;
+            
+            var next = function (err, ok) {
+                if (!err && ok)
+                    res.push([i, x]);
+                if (i === lastIdx)
+                    context.stack = res.sort().map(function(pair){ return pair[1]; });
+                arguments[0] = null; // discard errors
+                self.apply(self, arguments);
+            };
+            
+            next.stack = self.stack;
+            next.stack_ = self.stack_;
+            next.vars = self.vars;
+            next.args = self.args;
+            next.error = self.error;
+            
+            next.into = function (key) {
+                return function (err, ok) {
+                    if (!err && ok)
+                        res.push([key, x]);
+                    if (i === lastIdx)
+                        context.stack = res.sort().map(function(pair){ return pair[1]; });
+                    arguments[0] = null; // discard errors
+                    self.apply(self, arguments);
+                };
+            };
+            
+            next.ok = function () {
+                var args = slice.call(arguments);
+                args.unshift(null);
+                return next.apply(next, args);
+            };
+            
+            cb.apply(next, arguments);
+        });
+    };
+    
+    [ 'forEach', 'Each', 'Map', 'Filter' ]
+        .forEach(function (name){
+            var isForEach = !!(name === 'forEach')
+            ,   method ;
+            
+            // the seq functions are straight-forward, other than skipping forEach
+            if (!isForEach) {
+                method = 'seq'+name;
+                this[method+'_'] = function (cb) {