Permalink
Browse files

got remapper (easy api for remapping dependencies working)

  • Loading branch information...
1 parent 455cbc5 commit 6eb25220aa441bcd07a092462055e3c223a3aaa2 @dominictarr committed Nov 30, 2010
View
@@ -3,7 +3,7 @@
/*this passes the test, but is obviously broken!*/
-console.log("LOAD " + __filename)
+//console.log("LOAD " + __filename)
exports.n = function (n){
if(n == 1)
View
@@ -1,6 +1,6 @@
//this is the correct implementation
-console.log("LOAD " + __filename)
+//console.log("LOAD " + __filename)
exports.n = function (n){
return n
View
@@ -1,7 +1,3 @@
-//make_require
-
-
-//exports.useCache = useCache
var internalModuleCache = {}
, debug = require('./common').debug
@@ -14,32 +10,25 @@ var internalModuleCache = {}
exports.makeMake = makeMake
exports.makeRequire = makeRequire
- //exports.useCache = useCache
-
var natives = process.binding('natives'); //refactor this out to call require
// remove this...>>>
function loadNative (id) {
-// console.log("loadNative")
-// console.log(id)
var m = new Module(id);
internalModuleCache[id] = m;
m.require = makeRequire(m,{cache: require.cache})
- /*= function (request){
- console.log("LOAD NATIVE!" + id)
- console.log(request)
- }*/
- var e = m._compile(natives[id], id+".js");
+
+ var e = m._compile(getNative(id), id+".js");
if (e) throw e; // error compiling native module
return m;
}
exports.requireNative = requireNative;//this doesn't appear to be used anywhere....
function requireNative (id) {
- if (internalModuleCache[id]) return internalModuleCache[id].exports;
- if (!natives[id]) throw new Error('No such native module ' + id);
+ if (internalModuleCache.hasOwnProperty(id) && internalModuleCache[id]) return internalModuleCache[id].exports;
+ if (!getNative(id)) throw new Error('No such native module ' + id);
return loadNative(id).exports;
}
@@ -63,11 +52,11 @@ var internalModuleCache = {}
// console.log("CACHE (loadResolvedModule):" + moduleCache)
assert.ok(moduleCache,"loadResolvedModule needs a moduleCache")
// remote this...>>>
- var cachedNative = internalModuleCache[id];
+ var cachedNative = internalModuleCache.hasOwnProperty(id) && internalModuleCache[id];
if (cachedNative) {
return cachedNative;
}
- if (natives[id]) {
+ if (getNative(id)) {
debug('load native module ' + id);
return loadNative(id);
}
@@ -107,16 +96,22 @@ var internalModuleCache = {}
}
function makeMake(tools){
- return function (module) {return makeRequire(module,tools)}
+ return function (module) {
+ //console.log(tools)
+ return makeRequire(module,tools)}
}
+ function getNative(request){
+ return natives.hasOwnProperty(request) && natives[request]
+ }
+
+
function makeRequire(module,tools){
tools = tools || {}//what if I put tools into
tools.resolve = tools.resolve || resolve.resolveModuleFilename
tools.load = tools.load || defaultLoad //(id,filename,parent,makeR,moduleCache)
tools.make = tools.make || makeMake({cache: tools.cache})
-// tools.cache = tools.cache || cache
-// console.log("CACHE (makeRequire):" + tools.cache)
+
assert.ok(tools.cache,"makeRequire needed a tools.cache")
assert.ok(tools.make,"makeRequire needed a tools.make")
View
@@ -1,7 +1,7 @@
var path = require('path')
, resolve = require('./resolve')
- , make_require = require('./loading')
+ , loading = require('./loading')
, assert = require('assert')
var registerExtension = function(){console.log('require.registerExtension() removed. Use require.extensions instead');}
@@ -16,19 +16,19 @@ function useCache(moduleCache) {
newExports[i] = exports[i]
}
newExports.loadModule = function (request,parent,make) {
- return make_require.loadModule(request,parent,make,moduleCache)
+ return loading.loadModule(request,parent,make,moduleCache)
}
newExports.defaultLoad = function (id,filename,parent,make) {
- return make_require.defaultLoad(id,filename,parent,make,moduleCache)
+ return loading.defaultLoad(id,filename,parent,make,moduleCache)
}
newExports.mamake = function (resolve,load,make){
- return make_require.mamake (resolve,load,make,moduleCache)
+ return loading.mamake (resolve,load,make,moduleCache)
}
newExports.makeRequire = function (module,tools){
- return make_require.makeRequire(module,initTools(tools))
+ return loading.makeRequire(module,initTools(tools))
}
newExports.makeMake = function (tools){
- return make_require.makeMake(initTools(tools))
+ return loading.makeMake(initTools(tools))
}
function initTools(tools){
Oops, something went wrong.

0 comments on commit 6eb2522

Please sign in to comment.