676 lines
19 KiB
JavaScript
676 lines
19 KiB
JavaScript
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;
|
|
}
|
|
var __require = require;
|
|
|
|
require.paths = [];
|
|
require.modules = {};
|
|
require.extensions = [".js",".coffee"];
|
|
|
|
require.resolve = (function () {
|
|
var core = {
|
|
'assert': true,
|
|
'events': true,
|
|
'fs': true,
|
|
'path': true,
|
|
'vm': true
|
|
};
|
|
|
|
return function (x, cwd) {
|
|
if (!cwd) cwd = '/';
|
|
|
|
if (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);
|
|
|
|
Object.keys(require.modules)
|
|
.forEach(function (x) {
|
|
if (x.slice(0, basedir.length + 1) === basedir + '/') {
|
|
var f = x.slice(basedir.length);
|
|
require.modules[to + f] = require.modules[basedir + f];
|
|
}
|
|
else if (x === basedir) {
|
|
require.modules[to] = require.modules[basedir];
|
|
}
|
|
})
|
|
;
|
|
};
|
|
|
|
if (typeof process === 'undefined') process = {};
|
|
|
|
if (!process.nextTick) process.nextTick = function (fn) {
|
|
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.modules["path"] = function () {
|
|
var module = { exports : {} };
|
|
var exports = module.exports;
|
|
var __dirname = ".";
|
|
var __filename = "path";
|
|
|
|
var require = function (file) {
|
|
return __require(file, ".");
|
|
};
|
|
|
|
require.resolve = function (file) {
|
|
return __require.resolve(name, ".");
|
|
};
|
|
|
|
require.modules = __require.modules;
|
|
__require.modules["path"]._cached = module.exports;
|
|
|
|
(function () {
|
|
// 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(resolvedPath.split('/').filter(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(path.split('/').filter(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(paths.filter(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] || '';
|
|
};
|
|
;
|
|
}).call(module.exports);
|
|
|
|
__require.modules["path"]._cached = module.exports;
|
|
return module.exports;
|
|
};
|
|
|
|
require.modules["/node_modules/traverse/package.json"] = function () {
|
|
var module = { exports : {} };
|
|
var exports = module.exports;
|
|
var __dirname = "/node_modules/traverse";
|
|
var __filename = "/node_modules/traverse/package.json";
|
|
|
|
var require = function (file) {
|
|
return __require(file, "/node_modules/traverse");
|
|
};
|
|
|
|
require.resolve = function (file) {
|
|
return __require.resolve(name, "/node_modules/traverse");
|
|
};
|
|
|
|
require.modules = __require.modules;
|
|
__require.modules["/node_modules/traverse/package.json"]._cached = module.exports;
|
|
|
|
(function () {
|
|
module.exports = {"name":"traverse","version":"0.4.4","description":"Traverse and transform objects by visiting every node on a recursive walk","author":"James Halliday","license":"MIT/X11","main":"./index","repository":{"type":"git","url":"http://github.com/substack/js-traverse.git"},"devDependencies":{"expresso":"0.7.x"},"scripts":{"test":"expresso"}};
|
|
}).call(module.exports);
|
|
|
|
__require.modules["/node_modules/traverse/package.json"]._cached = module.exports;
|
|
return module.exports;
|
|
};
|
|
|
|
require.modules["/node_modules/traverse/index.js"] = function () {
|
|
var module = { exports : {} };
|
|
var exports = module.exports;
|
|
var __dirname = "/node_modules/traverse";
|
|
var __filename = "/node_modules/traverse/index.js";
|
|
|
|
var require = function (file) {
|
|
return __require(file, "/node_modules/traverse");
|
|
};
|
|
|
|
require.resolve = function (file) {
|
|
return __require.resolve(name, "/node_modules/traverse");
|
|
};
|
|
|
|
require.modules = __require.modules;
|
|
__require.modules["/node_modules/traverse/index.js"]._cached = module.exports;
|
|
|
|
(function () {
|
|
module.exports = Traverse;
|
|
function Traverse (obj) {
|
|
if (!(this instanceof Traverse)) return new Traverse(obj);
|
|
this.value = obj;
|
|
}
|
|
|
|
Traverse.prototype.get = function (ps) {
|
|
var node = this.value;
|
|
for (var i = 0; i < ps.length; i ++) {
|
|
var key = ps[i];
|
|
if (!Object.hasOwnProperty.call(node, key)) {
|
|
node = undefined;
|
|
break;
|
|
}
|
|
node = node[key];
|
|
}
|
|
return node;
|
|
};
|
|
|
|
Traverse.prototype.set = function (ps, value) {
|
|
var node = this.value;
|
|
for (var i = 0; i < ps.length - 1; i ++) {
|
|
var key = ps[i];
|
|
if (!Object.hasOwnProperty.call(node, key)) node[key] = {};
|
|
node = node[key];
|
|
}
|
|
node[ps[i]] = value;
|
|
return value;
|
|
};
|
|
|
|
Traverse.prototype.map = function (cb) {
|
|
return walk(this.value, cb, true);
|
|
};
|
|
|
|
Traverse.prototype.forEach = function (cb) {
|
|
this.value = walk(this.value, cb, false);
|
|
return this.value;
|
|
};
|
|
|
|
Traverse.prototype.reduce = function (cb, init) {
|
|
var skip = arguments.length === 1;
|
|
var acc = skip ? this.value : init;
|
|
this.forEach(function (x) {
|
|
if (!this.isRoot || !skip) {
|
|
acc = cb.call(this, acc, x);
|
|
}
|
|
});
|
|
return acc;
|
|
};
|
|
|
|
Traverse.prototype.deepEqual = function (obj) {
|
|
if (arguments.length !== 1) {
|
|
throw new Error(
|
|
'deepEqual requires exactly one object to compare against'
|
|
);
|
|
}
|
|
|
|
var equal = true;
|
|
var node = obj;
|
|
|
|
this.forEach(function (y) {
|
|
var notEqual = (function () {
|
|
equal = false;
|
|
//this.stop();
|
|
return undefined;
|
|
}).bind(this);
|
|
|
|
//if (node === undefined || node === null) return notEqual();
|
|
|
|
if (!this.isRoot) {
|
|
/*
|
|
if (!Object.hasOwnProperty.call(node, this.key)) {
|
|
return notEqual();
|
|
}
|
|
*/
|
|
if (typeof node !== 'object') return notEqual();
|
|
node = node[this.key];
|
|
}
|
|
|
|
var x = node;
|
|
|
|
this.post(function () {
|
|
node = x;
|
|
});
|
|
|
|
var toS = function (o) {
|
|
return Object.prototype.toString.call(o);
|
|
};
|
|
|
|
if (this.circular) {
|
|
if (Traverse(obj).get(this.circular.path) !== x) notEqual();
|
|
}
|
|
else if (typeof x !== typeof y) {
|
|
notEqual();
|
|
}
|
|
else if (x === null || y === null || x === undefined || y === undefined) {
|
|
if (x !== y) notEqual();
|
|
}
|
|
else if (x.__proto__ !== y.__proto__) {
|
|
notEqual();
|
|
}
|
|
else if (x === y) {
|
|
// nop
|
|
}
|
|
else if (typeof x === 'function') {
|
|
if (x instanceof RegExp) {
|
|
// both regexps on account of the __proto__ check
|
|
if (x.toString() != y.toString()) notEqual();
|
|
}
|
|
else if (x !== y) notEqual();
|
|
}
|
|
else if (typeof x === 'object') {
|
|
if (toS(y) === '[object Arguments]'
|
|
|| toS(x) === '[object Arguments]') {
|
|
if (toS(x) !== toS(y)) {
|
|
notEqual();
|
|
}
|
|
}
|
|
else if (x instanceof Date || y instanceof Date) {
|
|
if (!(x instanceof Date) || !(y instanceof Date)
|
|
|| x.getTime() !== y.getTime()) {
|
|
notEqual();
|
|
}
|
|
}
|
|
else {
|
|
var kx = Object.keys(x);
|
|
var ky = Object.keys(y);
|
|
if (kx.length !== ky.length) return notEqual();
|
|
for (var i = 0; i < kx.length; i++) {
|
|
var k = kx[i];
|
|
if (!Object.hasOwnProperty.call(y, k)) {
|
|
notEqual();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
return equal;
|
|
};
|
|
|
|
Traverse.prototype.paths = function () {
|
|
var acc = [];
|
|
this.forEach(function (x) {
|
|
acc.push(this.path);
|
|
});
|
|
return acc;
|
|
};
|
|
|
|
Traverse.prototype.nodes = function () {
|
|
var acc = [];
|
|
this.forEach(function (x) {
|
|
acc.push(this.node);
|
|
});
|
|
return acc;
|
|
};
|
|
|
|
Traverse.prototype.clone = function () {
|
|
var parents = [], nodes = [];
|
|
|
|
return (function clone (src) {
|
|
for (var i = 0; i < parents.length; i++) {
|
|
if (parents[i] === src) {
|
|
return nodes[i];
|
|
}
|
|
}
|
|
|
|
if (typeof src === 'object' && src !== null) {
|
|
var dst = copy(src);
|
|
|
|
parents.push(src);
|
|
nodes.push(dst);
|
|
|
|
Object.keys(src).forEach(function (key) {
|
|
dst[key] = clone(src[key]);
|
|
});
|
|
|
|
parents.pop();
|
|
nodes.pop();
|
|
return dst;
|
|
}
|
|
else {
|
|
return src;
|
|
}
|
|
})(this.value);
|
|
};
|
|
|
|
function walk (root, cb, immutable) {
|
|
var path = [];
|
|
var parents = [];
|
|
var alive = true;
|
|
|
|
return (function walker (node_) {
|
|
var node = immutable ? copy(node_) : node_;
|
|
var modifiers = {};
|
|
|
|
var keepGoing = true;
|
|
|
|
var state = {
|
|
node : node,
|
|
node_ : node_,
|
|
path : [].concat(path),
|
|
parent : parents[parents.length - 1],
|
|
key : path.slice(-1)[0],
|
|
isRoot : path.length === 0,
|
|
level : path.length,
|
|
circular : null,
|
|
update : function (x, stopHere) {
|
|
if (!state.isRoot) {
|
|
state.parent.node[state.key] = x;
|
|
}
|
|
state.node = x;
|
|
if (stopHere) keepGoing = false;
|
|
},
|
|
'delete' : function () {
|
|
delete state.parent.node[state.key];
|
|
},
|
|
remove : function () {
|
|
if (Array.isArray(state.parent.node)) {
|
|
state.parent.node.splice(state.key, 1);
|
|
}
|
|
else {
|
|
delete state.parent.node[state.key];
|
|
}
|
|
},
|
|
before : function (f) { modifiers.before = f },
|
|
after : function (f) { modifiers.after = f },
|
|
pre : function (f) { modifiers.pre = f },
|
|
post : function (f) { modifiers.post = f },
|
|
stop : function () { alive = false },
|
|
block : function () { keepGoing = false }
|
|
};
|
|
|
|
if (!alive) return state;
|
|
|
|
if (typeof node === 'object' && node !== null) {
|
|
state.isLeaf = Object.keys(node).length == 0;
|
|
|
|
for (var i = 0; i < parents.length; i++) {
|
|
if (parents[i].node_ === node_) {
|
|
state.circular = parents[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
state.isLeaf = true;
|
|
}
|
|
|
|
state.notLeaf = !state.isLeaf;
|
|
state.notRoot = !state.isRoot;
|
|
|
|
// use return values to update if defined
|
|
var ret = cb.call(state, state.node);
|
|
if (ret !== undefined && state.update) state.update(ret);
|
|
state.keys = null;
|
|
if (modifiers.before) modifiers.before.call(state, state.node);
|
|
|
|
if (!keepGoing) return state;
|
|
|
|
if (typeof state.node == 'object'
|
|
&& state.node !== null && !state.circular) {
|
|
parents.push(state);
|
|
|
|
var keys = state.keys || Object.keys(state.node);
|
|
keys.forEach(function (key, i) {
|
|
path.push(key);
|
|
|
|
if (modifiers.pre) modifiers.pre.call(state, state.node[key], key);
|
|
|
|
var child = walker(state.node[key]);
|
|
if (immutable && Object.hasOwnProperty.call(state.node, key)) {
|
|
state.node[key] = child.node;
|
|
}
|
|
|
|
child.isLast = i == keys.length - 1;
|
|
child.isFirst = i == 0;
|
|
|
|
if (modifiers.post) modifiers.post.call(state, child);
|
|
|
|
path.pop();
|
|
});
|
|
parents.pop();
|
|
}
|
|
|
|
if (modifiers.after) modifiers.after.call(state, state.node);
|
|
|
|
return state;
|
|
})(root).node;
|
|
}
|
|
|
|
Object.keys(Traverse.prototype).forEach(function (key) {
|
|
Traverse[key] = function (obj) {
|
|
var args = [].slice.call(arguments, 1);
|
|
var t = Traverse(obj);
|
|
return t[key].apply(t, args);
|
|
};
|
|
});
|
|
|
|
function copy (src) {
|
|
if (typeof src === 'object' && src !== null) {
|
|
var dst;
|
|
|
|
if (Array.isArray(src)) {
|
|
dst = [];
|
|
}
|
|
else if (src instanceof Date) {
|
|
dst = new Date(src);
|
|
}
|
|
else if (src instanceof Boolean) {
|
|
dst = new Boolean(src);
|
|
}
|
|
else if (src instanceof Number) {
|
|
dst = new Number(src);
|
|
}
|
|
else if (src instanceof String) {
|
|
dst = new String(src);
|
|
}
|
|
else {
|
|
dst = Object.create(Object.getPrototypeOf(src));
|
|
}
|
|
|
|
Object.keys(src).forEach(function (key) {
|
|
dst[key] = src[key];
|
|
});
|
|
return dst;
|
|
}
|
|
else return src;
|
|
}
|
|
;
|
|
}).call(module.exports);
|
|
|
|
__require.modules["/node_modules/traverse/index.js"]._cached = module.exports;
|
|
return module.exports;
|
|
};
|