UNPKG

3.52 kBJavaScriptView Raw
1// modules are defined as an array
2// [ module function, map of requireuires ]
3//
4// map of requireuires is short require name -> numeric require
5//
6// anything defined in a previous bundle is accessed via the
7// orig method which is the requireuire for previous bundles
8
9(function outer (modules, cache, entry) {
10 // Save the require from previous bundle to this closure if any
11 var previousRequire = typeof require == "function" && require;
12
13 function findProxyquireifyName() {
14 var deps = Object.keys(modules)
15 .map(function (k) { return modules[k][1]; });
16
17 for (var i = 0; i < deps.length; i++) {
18 var pq = deps[i]['proxyquireify'];
19 if (pq) return pq;
20 }
21 }
22
23 var proxyquireifyName = findProxyquireifyName();
24
25 function newRequire(name, jumped){
26 // Find the proxyquireify module, if present
27 var pqify = (proxyquireifyName != null) && cache[proxyquireifyName];
28
29 // Proxyquireify provides a separate cache that is used when inside
30 // a proxyquire call, and is set to null outside a proxyquire call.
31 // This allows the regular caching semantics to work correctly both
32 // inside and outside proxyquire calls while keeping the cached
33 // modules isolated.
34 // When switching from one proxyquire call to another, it clears
35 // the cache to prevent contamination between different sets
36 // of stubs.
37 var currentCache = (pqify && pqify.exports._cache) || cache;
38
39 if(!currentCache[name]) {
40 if(!modules[name]) {
41 // if we cannot find the the module within our internal map or
42 // cache jump to the current global require ie. the last bundle
43 // that was added to the page.
44 var currentRequire = typeof require == "function" && require;
45 if (!jumped && currentRequire) return currentRequire(name, true);
46
47 // If there are other bundles on this page the require from the
48 // previous one is saved to 'previousRequire'. Repeat this as
49 // many times as there are bundles until the module is found or
50 // we exhaust the require chain.
51 if (previousRequire) return previousRequire(name, true);
52 var err = new Error('Cannot find module \'' + name + '\'');
53 err.code = 'MODULE_NOT_FOUND';
54 throw err;
55 }
56 var m = currentCache[name] = {exports:{}};
57
58 // The normal browserify require function
59 var req = function(x){
60 var id = modules[name][1][x];
61 return newRequire(id ? id : x);
62 };
63
64 // The require function substituted for proxyquireify
65 var moduleRequire = function(x){
66 var pqify = (proxyquireifyName != null) && cache[proxyquireifyName];
67 // Only try to use the proxyquireify version if it has been `require`d
68 if (pqify && pqify.exports._proxy) {
69 return pqify.exports._proxy(req, x);
70 } else {
71 return req(x);
72 }
73 };
74
75 modules[name][0].call(m.exports,moduleRequire,m,m.exports,outer,modules,currentCache,entry);
76 }
77 return currentCache[name].exports;
78 }
79 for(var i=0;i<entry.length;i++) newRequire(entry[i]);
80
81 // Override the current require with this new one
82 return newRequire;
83})