[Pkg-javascript-commits] [node-browser-pack] 35/141: Jump to root require if not found. With this it shouldn't matter in which order multiple bundles are added to the dom. If local require fails to find the module from its map it jumps the to current root require in the global scope and works its way back down from there.

Bastien Roucariès rouca at moszumanska.debian.org
Thu May 4 10:23:22 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-browser-pack.

commit 2c68dcb216f0b59110b944b463a5df0ba90cc8ff
Author: Esa-Matti Suuronen <esa-matti at suuronen.org>
Date:   Sun Mar 24 17:55:25 2013 +0200

    Jump to root require if not found.
    With this it shouldn't matter in which order multiple bundles are added
    to the dom. If local require fails to find the module from its map it
    jumps the to current root require in the global scope and works its way
    back down from there.
    
    Should fix https://github.com/substack/node-browserify/issues/341
---
 prelude.js | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/prelude.js b/prelude.js
index c0c462c..342840d 100644
--- a/prelude.js
+++ b/prelude.js
@@ -8,21 +8,24 @@
 // orig method which is the requireuire for previous bundles
 
 (function(parent_req, modules, cache, entry) {
-    function require(name){
+    function inner_req(name, jumped){
         if(!cache[name]) {
             if(!modules[name]) {
-                // if we cannot find the item within our internal map revert to parent
+                // if we cannot find the item within our internal map jump to
+                // current root require go all requires down from there
+                var rootRequire = typeof require == "function" && require;
+                if (!jumped && rootRequire) return rootRequire(name, true);
                 if (parent_req) return parent_req(name);
                 throw new Error('Cannot find module \'' + name + '\'');
             }
             var m = cache[name] = {exports:{}};
             modules[name][0](function(x){
                 var id = modules[name][1][x];
-                return require(id ? id : x);
+                return inner_req(id ? id : x);
             },m,m.exports);
         }
         return cache[name].exports
     }
-    for(var i=0;i<entry.length;i++) require(entry[i]);
-    return require;
+    for(var i=0;i<entry.length;i++) inner_req(entry[i]);
+    return inner_req;
 })

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-browser-pack.git



More information about the Pkg-javascript-commits mailing list