Permalink
Browse files

prepare for publish

  • Loading branch information...
1 parent 81bdfc2 commit 090b892e2de915823fbffac85a67ca0643e4e6d2 @dominictarr committed Jan 23, 2011
Showing with 16 additions and 110 deletions.
  1. +8 −11 loading.js
  2. +0 −12 module.js
  3. +3 −0 package.json
  4. +3 −35 remapper.js
  5. +2 −3 resolve.js
  6. +0 −49 test/unused/resolve.resolver.asynct.js
View
@@ -11,7 +11,6 @@ var internalModuleCache = {}
exports.makeRequire = makeRequire
var natives = process.binding('natives'); //refactor this out to call require
- // remove this...>>>
function loadNative (id) {
@@ -48,11 +47,9 @@ var internalModuleCache = {}
};
function loadResolvedModule (id,filename,parent,makeR,moduleCache){
-// console.log("::::::::: load " + id + "::::::::::")
- //moduleCache = moduleCache || cache
-// console.log("CACHE (loadResolvedModule):" + moduleCache)
+
assert.ok(moduleCache,"loadResolvedModule needs a moduleCache")
- // remote this...>>>
+
var cachedNative = internalModuleCache.hasOwnProperty(id) && internalModuleCache[id];
if (cachedNative) {
return cachedNative;
@@ -63,15 +60,15 @@ var internalModuleCache = {}
}
var cachedModule = moduleCache[filename];
-// console.log("cached?:" + (!!cachedModule));
+
if (cachedModule) return cachedModule;
var module = new Module(id, parent);
makeR = makeR || makeMake({cache:moduleCache})
moduleCache[filename] = module;
-// console.log("STORE in cache:" + filename);
+
module.require = makeR.call(module,module);//intercepts creation of require so it can me remapped. called as module, to pass old test.
module.load(filename);
@@ -108,9 +105,9 @@ var internalModuleCache = {}
function makeRequire(module,tools){
- tools = tools || {}//what if I put tools into
+ tools = tools || {}
tools.resolve = tools.resolve || resolve.resolveModuleFilename
- tools.load = tools.load || defaultLoad //(id,filename,parent,makeR,moduleCache)
+ tools.load = tools.load || defaultLoad
tools.make = tools.make || makeMake({cache: tools.cache})
assert.ok(tools.cache,"makeRequire needed a tools.cache")
@@ -130,9 +127,9 @@ var internalModuleCache = {}
function finishRequire(newRequire){
newRequire.paths = resolve.modulePaths;
newRequire.main = process.mainModule;
- // Enable support to add extra extension types
+
newRequire.extensions = require.extensions;
- // TODO: Insert depreciation warning
+
newRequire.registerExtension = require.registerExtension;
newRequire.cache = tools.cache;
return newRequire;
View
@@ -50,9 +50,6 @@ module.exports = Module
// remove shebang
content = content.replace(/^\#\!.*/, '');
-// var newRequire = self.makeRequire ? self.makeRequire(self) : require('./make_require').makeRequire(self)//the cache has to get in here.
- //why not use assign require to module?
-
var dirname = path.dirname(filename);
if (contextLoad) {
@@ -125,12 +122,3 @@ module.exports = Module
process.dlopen(filename, module.exports);
};
-/*
- // bootstrap main module.
- exports.runMain = function () {
- // Load the main module--the command line argument.
- process.mainModule = new Module(".");
- process.mainModule.load(process.argv[1]);
- };*/
-// exports.useCache = useCache
-
View
@@ -6,6 +6,9 @@
"repository": "git://github.com/dominictarr/remap.git",
"author": "Dominic Tarr <dominic.tarr@gmail.com>",
"main":"remapper",
+ "dependencies":{
+ "traverser": '*'
+ }
"modules":{
"loading":"./loading"
, "modules":"./modules"
View
@@ -3,7 +3,6 @@
var modules = require('remap/modules')
, resolve = require('remap/resolve')
, log = console.log
- , inspect = require('inspect')
, assert = require('assert')
module.exports = Remapper
@@ -22,9 +21,6 @@ function Maker (depends,loaded,remaps){
request = remaps[request]
}
var resolved = resolve.resolveModuleFilename(request,module)
- //log(resolved[0])
-
- //if the remap is absolute, it may need to be re-resolved.
if(remaps.hasOwnProperty(resolved[0]) && remaps[resolved[0]])
return resolve.resolveModuleFilename(remaps[resolved[0]],module)
@@ -33,48 +29,20 @@ function Maker (depends,loaded,remaps){
}
self.load = function (id, filename, parent, makeR ){
- /*
- when a file is loaded,
- */
- /*
-// if(!loaded[id]) { loaded[id] = {} }
- //if this is the first time the module is loaded,
- //it will not have a record yet.
-
- //wait untill defaultLoad returns, make will have created the record.
-
-
-// if(loaded[parent.id]) { loaded[parent.id][id] = loaded[id] }
-*/
var newModule = modules.defaultLoad(id, filename, parent, makeR)
-// log("LOAD",parent.id, "->",id)
- //..make doesn't get called if it's a native module.
if(!loaded[id])
loaded[id] = {} //should only happen when it's a native module
-// assert.notEqual(loaded[id],null, "SHOULD have record for " + id + "")
-// if(parent != _module) {
assert.notEqual(loaded[parent.id],null, "SHOULD have record for parent " + parent.id + "")
- //check that loaded[id] exists, and
- //set loaded[parent.id][id] = loaded[id]
loaded[parent.id][id] = loaded[id]
-// loaded[id] = {}
-// }
return newModule
}
self.make = function (thisModule){
-// log("MAKE",thisModule.id)
var id = thisModule.id
- // assert.equal(loaded[id],null, "should NOT have record for " + id + " yet.")
loaded[id] = {}
- //depends[id] = loaded[id]
-
- //when a file is first loaded,
- //create an empty record in loaded under thisModule.id
- //there should not already be a record there.
return modules.makeMake(new Maker(loaded[id],loaded,remaps))(thisModule)
}
@@ -86,10 +54,10 @@ function Maker (depends,loaded,remaps){
* depends is easier to spell than dependencies
*/
- self.depends = {} //the
+ self.depends = {}
self.depends[_module.id] = {}
- self.loaded = {} //the
- self.remaps = remaps || {} //the
+ self.loaded = {}
+ self.remaps = remaps || {}
self.loaded[_module.id] = self.depends[_module.id]
self.require = make()
View
@@ -147,7 +147,7 @@ which is initialized with optionally paths, parent module, extensions, local dir
//who calls findModulePath? only resolveModuleFilename
/*
- modulePathWalk is a little strange... i havn't seen anyone using node_modules directories.
+ modulePathWalk is a little strange... i havn't seen anyone using node_modules directories. (correction, they're used by npm)
it has the effect of adding ./node_modules to the path, ahead of the default paths.
*/
@@ -234,7 +234,6 @@ which is initialized with optionally paths, parent module, extensions, local dir
exports.resolveModuleFilename = resolveModuleFilename
function resolveModuleFilename (request, parent,_extensions) {
- // console.log("natives['" + request + "'] == " + !!getNative(request))
if (natives.hasOwnProperty(request) && getNative(request)) return [request, request];//fs http net, etc.
var resolvedModule = resolveModuleLookupPaths(request, parent),
@@ -245,7 +244,7 @@ which is initialized with optionally paths, parent module, extensions, local dir
debug("looking for " + JSON.stringify(id) + " in " + JSON.stringify(paths));
var filename = findModulePath(request, paths,_extensions);
if (!filename) {
-// console.log(extensions);
+
throw new Error("Cannot find module '" + request + "', from: " + path.dirname(parent.filename));
}
return [id, filename];
@@ -1,49 +0,0 @@
-var resolve = require('remap/resolve')
- , log = console.log
- , path = require('path')
-exports['Resolver() creates instance of Resolver'] = function (test){
- var r = resolve.Resolver()
-
- test.ok(r instanceof resolve.Resolver,"expected instance of Resolver, got :" + r)
- test.finish()
-}
-
-exports['Resolver can be initialised with extensions and paths'] = function (test){
-
- var opts =
- { parent: module
- , paths: [__dirname]
- , extensions: ['.js']
- }
- , r = resolve.Resolver(opts)
-
- test.equal(r.parent, module)
- test.deepEqual(r.paths, [__dirname])
- test.deepEqual(r.extensions, ['.js'])
-
- test.finish()
-}
-
-exports ['Resolver can resolve this file, same as require.resolve'] = function (test){
- var r = resolve.Resolver({parent: module})
- , r2 = resolve.Resolver({paths:[]})
- , r3 = resolve.Resolver({paths:[__dirname]})
- , files =
- ['./resolve.resolver.asynct'
- ,'../index'
- ,'remap']
- test.deepEqual(r2.paths, [])
-
- files.forEach(function(e){
- test.equal(r.resolve(e)[1],require.resolve(e))
-
- test.throws(function(){test.equal(r2.resolve(e)[1],null)})
-
- test.equal(r3.resolve(e)[1],require.resolve(e))
- });
-
- //but not if there are no paths
-
- test.finish()
-}
-

0 comments on commit 090b892

Please sign in to comment.