Kaido Kert | f585e26 | 2020-06-08 11:42:28 -0700 | [diff] [blame] | 1 | var require = function (file, cwd) { |
| 2 | var resolved = require.resolve(file, cwd || '/'); |
| 3 | var mod = require.modules[resolved]; |
| 4 | if (!mod) throw new Error( |
| 5 | 'Failed to resolve module ' + file + ', tried ' + resolved |
| 6 | ); |
| 7 | var res = mod._cached ? mod._cached : mod(); |
| 8 | return res; |
| 9 | } |
| 10 | |
| 11 | require.paths = []; |
| 12 | require.modules = {}; |
| 13 | require.extensions = [".js",".coffee"]; |
| 14 | |
| 15 | require._core = { |
| 16 | 'assert': true, |
| 17 | 'events': true, |
| 18 | 'fs': true, |
| 19 | 'path': true, |
| 20 | 'vm': true |
| 21 | }; |
| 22 | |
| 23 | require.resolve = (function () { |
| 24 | return function (x, cwd) { |
| 25 | if (!cwd) cwd = '/'; |
| 26 | |
| 27 | if (require._core[x]) return x; |
| 28 | var path = require.modules.path(); |
| 29 | var y = cwd || '.'; |
| 30 | |
| 31 | if (x.match(/^(?:\.\.?\/|\/)/)) { |
| 32 | var m = loadAsFileSync(path.resolve(y, x)) |
| 33 | || loadAsDirectorySync(path.resolve(y, x)); |
| 34 | if (m) return m; |
| 35 | } |
| 36 | |
| 37 | var n = loadNodeModulesSync(x, y); |
| 38 | if (n) return n; |
| 39 | |
| 40 | throw new Error("Cannot find module '" + x + "'"); |
| 41 | |
| 42 | function loadAsFileSync (x) { |
| 43 | if (require.modules[x]) { |
| 44 | return x; |
| 45 | } |
| 46 | |
| 47 | for (var i = 0; i < require.extensions.length; i++) { |
| 48 | var ext = require.extensions[i]; |
| 49 | if (require.modules[x + ext]) return x + ext; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | function loadAsDirectorySync (x) { |
| 54 | x = x.replace(/\/+$/, ''); |
| 55 | var pkgfile = x + '/package.json'; |
| 56 | if (require.modules[pkgfile]) { |
| 57 | var pkg = require.modules[pkgfile](); |
| 58 | var b = pkg.browserify; |
| 59 | if (typeof b === 'object' && b.main) { |
| 60 | var m = loadAsFileSync(path.resolve(x, b.main)); |
| 61 | if (m) return m; |
| 62 | } |
| 63 | else if (typeof b === 'string') { |
| 64 | var m = loadAsFileSync(path.resolve(x, b)); |
| 65 | if (m) return m; |
| 66 | } |
| 67 | else if (pkg.main) { |
| 68 | var m = loadAsFileSync(path.resolve(x, pkg.main)); |
| 69 | if (m) return m; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return loadAsFileSync(x + '/index'); |
| 74 | } |
| 75 | |
| 76 | function loadNodeModulesSync (x, start) { |
| 77 | var dirs = nodeModulesPathsSync(start); |
| 78 | for (var i = 0; i < dirs.length; i++) { |
| 79 | var dir = dirs[i]; |
| 80 | var m = loadAsFileSync(dir + '/' + x); |
| 81 | if (m) return m; |
| 82 | var n = loadAsDirectorySync(dir + '/' + x); |
| 83 | if (n) return n; |
| 84 | } |
| 85 | |
| 86 | var m = loadAsFileSync(x); |
| 87 | if (m) return m; |
| 88 | } |
| 89 | |
| 90 | function nodeModulesPathsSync (start) { |
| 91 | var parts; |
| 92 | if (start === '/') parts = [ '' ]; |
| 93 | else parts = path.normalize(start).split('/'); |
| 94 | |
| 95 | var dirs = []; |
| 96 | for (var i = parts.length - 1; i >= 0; i--) { |
| 97 | if (parts[i] === 'node_modules') continue; |
| 98 | var dir = parts.slice(0, i + 1).join('/') + '/node_modules'; |
| 99 | dirs.push(dir); |
| 100 | } |
| 101 | |
| 102 | return dirs; |
| 103 | } |
| 104 | }; |
| 105 | })(); |
| 106 | |
| 107 | require.alias = function (from, to) { |
| 108 | var path = require.modules.path(); |
| 109 | var res = null; |
| 110 | try { |
| 111 | res = require.resolve(from + '/package.json', '/'); |
| 112 | } |
| 113 | catch (err) { |
| 114 | res = require.resolve(from, '/'); |
| 115 | } |
| 116 | var basedir = path.dirname(res); |
| 117 | |
| 118 | var keys = (Object.keys || function (obj) { |
| 119 | var res = []; |
| 120 | for (var key in obj) res.push(key) |
| 121 | return res; |
| 122 | })(require.modules); |
| 123 | |
| 124 | for (var i = 0; i < keys.length; i++) { |
| 125 | var key = keys[i]; |
| 126 | if (key.slice(0, basedir.length + 1) === basedir + '/') { |
| 127 | var f = key.slice(basedir.length); |
| 128 | require.modules[to + f] = require.modules[basedir + f]; |
| 129 | } |
| 130 | else if (key === basedir) { |
| 131 | require.modules[to] = require.modules[basedir]; |
| 132 | } |
| 133 | } |
| 134 | }; |
| 135 | |
| 136 | require.define = function (filename, fn) { |
| 137 | var dirname = require._core[filename] |
| 138 | ? '' |
| 139 | : require.modules.path().dirname(filename) |
| 140 | ; |
| 141 | |
| 142 | var require_ = function (file) { |
| 143 | return require(file, dirname) |
| 144 | }; |
| 145 | require_.resolve = function (name) { |
| 146 | return require.resolve(name, dirname); |
| 147 | }; |
| 148 | require_.modules = require.modules; |
| 149 | require_.define = require.define; |
| 150 | var module_ = { exports : {} }; |
| 151 | |
| 152 | require.modules[filename] = function () { |
| 153 | require.modules[filename]._cached = module_.exports; |
| 154 | fn.call( |
| 155 | module_.exports, |
| 156 | require_, |
| 157 | module_, |
| 158 | module_.exports, |
| 159 | dirname, |
| 160 | filename |
| 161 | ); |
| 162 | require.modules[filename]._cached = module_.exports; |
| 163 | return module_.exports; |
| 164 | }; |
| 165 | }; |
| 166 | |
| 167 | if (typeof process === 'undefined') process = {}; |
| 168 | |
| 169 | if (!process.nextTick) process.nextTick = (function () { |
| 170 | var queue = []; |
| 171 | var canPost = typeof window !== 'undefined' |
| 172 | && window.postMessage && window.addEventListener |
| 173 | ; |
| 174 | |
| 175 | if (canPost) { |
| 176 | window.addEventListener('message', function (ev) { |
| 177 | if (ev.source === window && ev.data === 'browserify-tick') { |
| 178 | ev.stopPropagation(); |
| 179 | if (queue.length > 0) { |
| 180 | var fn = queue.shift(); |
| 181 | fn(); |
| 182 | } |
| 183 | } |
| 184 | }, true); |
| 185 | } |
| 186 | |
| 187 | return function (fn) { |
| 188 | if (canPost) { |
| 189 | queue.push(fn); |
| 190 | window.postMessage('browserify-tick', '*'); |
| 191 | } |
| 192 | else setTimeout(fn, 0); |
| 193 | }; |
| 194 | })(); |
| 195 | |
| 196 | if (!process.title) process.title = 'browser'; |
| 197 | |
| 198 | if (!process.binding) process.binding = function (name) { |
| 199 | if (name === 'evals') return require('vm') |
| 200 | else throw new Error('No such module') |
| 201 | }; |
| 202 | |
| 203 | if (!process.cwd) process.cwd = function () { return '.' }; |
| 204 | |
| 205 | require.define("path", function (require, module, exports, __dirname, __filename) { |
| 206 | function filter (xs, fn) { |
| 207 | var res = []; |
| 208 | for (var i = 0; i < xs.length; i++) { |
| 209 | if (fn(xs[i], i, xs)) res.push(xs[i]); |
| 210 | } |
| 211 | return res; |
| 212 | } |
| 213 | |
| 214 | // resolves . and .. elements in a path array with directory names there |
| 215 | // must be no slashes, empty elements, or device names (c:\) in the array |
| 216 | // (so also no leading and trailing slashes - it does not distinguish |
| 217 | // relative and absolute paths) |
| 218 | function normalizeArray(parts, allowAboveRoot) { |
| 219 | // if the path tries to go above the root, `up` ends up > 0 |
| 220 | var up = 0; |
| 221 | for (var i = parts.length; i >= 0; i--) { |
| 222 | var last = parts[i]; |
| 223 | if (last == '.') { |
| 224 | parts.splice(i, 1); |
| 225 | } else if (last === '..') { |
| 226 | parts.splice(i, 1); |
| 227 | up++; |
| 228 | } else if (up) { |
| 229 | parts.splice(i, 1); |
| 230 | up--; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // if the path is allowed to go above the root, restore leading ..s |
| 235 | if (allowAboveRoot) { |
| 236 | for (; up--; up) { |
| 237 | parts.unshift('..'); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | return parts; |
| 242 | } |
| 243 | |
| 244 | // Regex to split a filename into [*, dir, basename, ext] |
| 245 | // posix version |
| 246 | var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/; |
| 247 | |
| 248 | // path.resolve([from ...], to) |
| 249 | // posix version |
| 250 | exports.resolve = function() { |
| 251 | var resolvedPath = '', |
| 252 | resolvedAbsolute = false; |
| 253 | |
| 254 | for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) { |
| 255 | var path = (i >= 0) |
| 256 | ? arguments[i] |
| 257 | : process.cwd(); |
| 258 | |
| 259 | // Skip empty and invalid entries |
| 260 | if (typeof path !== 'string' || !path) { |
| 261 | continue; |
| 262 | } |
| 263 | |
| 264 | resolvedPath = path + '/' + resolvedPath; |
| 265 | resolvedAbsolute = path.charAt(0) === '/'; |
| 266 | } |
| 267 | |
| 268 | // At this point the path should be resolved to a full absolute path, but |
| 269 | // handle relative paths to be safe (might happen when process.cwd() fails) |
| 270 | |
| 271 | // Normalize the path |
| 272 | resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) { |
| 273 | return !!p; |
| 274 | }), !resolvedAbsolute).join('/'); |
| 275 | |
| 276 | return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.'; |
| 277 | }; |
| 278 | |
| 279 | // path.normalize(path) |
| 280 | // posix version |
| 281 | exports.normalize = function(path) { |
| 282 | var isAbsolute = path.charAt(0) === '/', |
| 283 | trailingSlash = path.slice(-1) === '/'; |
| 284 | |
| 285 | // Normalize the path |
| 286 | path = normalizeArray(filter(path.split('/'), function(p) { |
| 287 | return !!p; |
| 288 | }), !isAbsolute).join('/'); |
| 289 | |
| 290 | if (!path && !isAbsolute) { |
| 291 | path = '.'; |
| 292 | } |
| 293 | if (path && trailingSlash) { |
| 294 | path += '/'; |
| 295 | } |
| 296 | |
| 297 | return (isAbsolute ? '/' : '') + path; |
| 298 | }; |
| 299 | |
| 300 | |
| 301 | // posix version |
| 302 | exports.join = function() { |
| 303 | var paths = Array.prototype.slice.call(arguments, 0); |
| 304 | return exports.normalize(filter(paths, function(p, index) { |
| 305 | return p && typeof p === 'string'; |
| 306 | }).join('/')); |
| 307 | }; |
| 308 | |
| 309 | |
| 310 | exports.dirname = function(path) { |
| 311 | var dir = splitPathRe.exec(path)[1] || ''; |
| 312 | var isWindows = false; |
| 313 | if (!dir) { |
| 314 | // No dirname |
| 315 | return '.'; |
| 316 | } else if (dir.length === 1 || |
| 317 | (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) { |
| 318 | // It is just a slash or a drive letter with a slash |
| 319 | return dir; |
| 320 | } else { |
| 321 | // It is a full dirname, strip trailing slash |
| 322 | return dir.substring(0, dir.length - 1); |
| 323 | } |
| 324 | }; |
| 325 | |
| 326 | |
| 327 | exports.basename = function(path, ext) { |
| 328 | var f = splitPathRe.exec(path)[2] || ''; |
| 329 | // TODO: make this comparison case-insensitive on windows? |
| 330 | if (ext && f.substr(-1 * ext.length) === ext) { |
| 331 | f = f.substr(0, f.length - ext.length); |
| 332 | } |
| 333 | return f; |
| 334 | }; |
| 335 | |
| 336 | |
| 337 | exports.extname = function(path) { |
| 338 | return splitPathRe.exec(path)[3] || ''; |
| 339 | }; |
| 340 | |
| 341 | }); |
| 342 | |
| 343 | require.define("vm", function (require, module, exports, __dirname, __filename) { |
| 344 | var Object_keys = function (obj) { |
| 345 | if (Object.keys) return Object.keys(obj) |
| 346 | else { |
| 347 | var res = []; |
| 348 | for (var key in obj) res.push(key) |
| 349 | return res; |
| 350 | } |
| 351 | }; |
| 352 | |
| 353 | var forEach = function (xs, fn) { |
| 354 | if (xs.forEach) return xs.forEach(fn) |
| 355 | else for (var i = 0; i < xs.length; i++) { |
| 356 | fn(xs[i], i, xs); |
| 357 | } |
| 358 | }; |
| 359 | |
| 360 | var Script = exports.Script = function NodeScript (code) { |
| 361 | if (!(this instanceof Script)) return new Script(code); |
| 362 | this.code = code; |
| 363 | }; |
| 364 | |
| 365 | var iframe = document.createElement('iframe'); |
| 366 | if (!iframe.style) iframe.style = {}; |
| 367 | iframe.style.display = 'none'; |
| 368 | |
| 369 | var iframeCapable = true; // until proven otherwise |
| 370 | if (navigator.appName === 'Microsoft Internet Explorer') { |
| 371 | var m = navigator.appVersion.match(/\bMSIE (\d+\.\d+);/); |
| 372 | if (m && parseFloat(m[1]) <= 9.0) { |
| 373 | iframeCapable = false; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | Script.prototype.runInNewContext = function (context) { |
| 378 | if (!context) context = {}; |
| 379 | |
| 380 | if (!iframeCapable) { |
| 381 | var keys = Object_keys(context); |
| 382 | var args = []; |
| 383 | for (var i = 0; i < keys.length; i++) { |
| 384 | args.push(context[keys[i]]); |
| 385 | } |
| 386 | |
| 387 | var fn = new Function(keys, 'return ' + this.code); |
| 388 | return fn.apply(null, args); |
| 389 | } |
| 390 | |
| 391 | document.body.appendChild(iframe); |
| 392 | |
| 393 | var win = iframe.contentWindow |
| 394 | || (window.frames && window.frames[window.frames.length - 1]) |
| 395 | || window[window.length - 1] |
| 396 | ; |
| 397 | |
| 398 | forEach(Object_keys(context), function (key) { |
| 399 | win[key] = context[key]; |
| 400 | iframe[key] = context[key]; |
| 401 | }); |
| 402 | |
| 403 | if (win.eval) { |
| 404 | // chrome and ff can just .eval() |
| 405 | var res = win.eval(this.code); |
| 406 | } |
| 407 | else { |
| 408 | // this works in IE9 but not anything newer |
| 409 | iframe.setAttribute('src', |
| 410 | 'javascript:__browserifyVmResult=(' + this.code + ')' |
| 411 | ); |
| 412 | if ('__browserifyVmResult' in win) { |
| 413 | var res = win.__browserifyVmResult; |
| 414 | } |
| 415 | else { |
| 416 | iframeCapable = false; |
| 417 | res = this.runInThisContext(context); |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | forEach(Object_keys(win), function (key) { |
| 422 | context[key] = win[key]; |
| 423 | }); |
| 424 | |
| 425 | document.body.removeChild(iframe); |
| 426 | |
| 427 | return res; |
| 428 | }; |
| 429 | |
| 430 | Script.prototype.runInThisContext = function () { |
| 431 | return eval(this.code); // maybe... |
| 432 | }; |
| 433 | |
| 434 | Script.prototype.runInContext = function (context) { |
| 435 | // seems to be just runInNewContext on magical context objects which are |
| 436 | // otherwise indistinguishable from objects except plain old objects |
| 437 | // for the parameter segfaults node |
| 438 | return this.runInNewContext(context); |
| 439 | }; |
| 440 | |
| 441 | forEach(Object_keys(Script.prototype), function (name) { |
| 442 | exports[name] = Script[name] = function (code) { |
| 443 | var s = Script(code); |
| 444 | return s[name].apply(s, [].slice.call(arguments, 1)); |
| 445 | }; |
| 446 | }); |
| 447 | |
| 448 | exports.createScript = function (code) { |
| 449 | return exports.Script(code); |
| 450 | }; |
| 451 | |
| 452 | exports.createContext = Script.createContext = function (context) { |
| 453 | // not really sure what this one does |
| 454 | // seems to just make a shallow copy |
| 455 | var copy = {}; |
| 456 | forEach(Object_keys(context), function (key) { |
| 457 | copy[key] = context[key]; |
| 458 | }); |
| 459 | return copy; |
| 460 | }; |
| 461 | |
| 462 | }); |
| 463 | |
| 464 | require.define("/entry.js", function (require, module, exports, __dirname, __filename) { |
| 465 | var vm = require('vm'); |
| 466 | |
| 467 | $(function () { |
| 468 | var res = vm.runInNewContext('a + 5', { a : 100 }); |
| 469 | $('#res').text(res); |
| 470 | }); |
| 471 | |
| 472 | }); |
| 473 | require("/entry.js"); |