Permalink
Browse files

getting ready to publish

  • Loading branch information...
1 parent 300005d commit 81bdfc2e2d772cc945494cee43ae2a5a034067ae @dominictarr committed Jan 22, 2011
Showing with 59 additions and 18 deletions.
  1. +35 −13 README.markdown
  2. +20 −0 package.json
  3. +1 −1 remapper.js
  4. +1 −1 test/.helper/remap-helper.js
  5. +1 −1 test/remapper.depends.asynct.js
  6. +1 −2 test/remapper.remaps.asynct.js
View
@@ -5,10 +5,44 @@ open up node's module loading code and gives you control of what is happening.
##basic examples##
+load a module, but replace specific modules with a different implementation:
+
+ var Remapper = require ('remap')
+ , remapper = new Remapper(module,{
+ 'path/module-a':'newpath/module-b'
+ //, ...
+ })
+ remapper.require('path/module-a') // will load 'newpath/module-b' instead.
+
+remapper can also tell you the dependency tree of the module's it's loaded.
+
+ remapper.depends
+
+will give something like:
+
+ { module:
+ { dependency:
+ { another: {}
+ , etc:{}
+ }
+ }
+ }
+
+## reloading a module multiple times ##
+
+ var newCache = {}
+ , modules = require ('remap/modules').useCache(newCache)
+ , require2 = modules.makeRequire(module) //must pass in your module.
+ , x = require2('xzy')
+
+ //now x will be cached in newCache, not require.cache
+
+## advanced usage ##
+
var modules = require ('remap/modules')
, require2 = modules.makeRequire(module) //must pass in your module.
- var x require2('path/to/module/x')
+ var x = require2('path/to/module/x')
x is the same as if you loaded it with require()
x can load sub modules, and will see a require function.
@@ -36,18 +70,6 @@ to functions to use for the main parts of require's task:
}
}
-also, there is remap/remapper, which eases the pain for some tasks:
-
- var remapper = new Remapper(module,{
- 'path/module-a':'newpath/module-b'
- //, ...
- })
- remapper.require('path/module-a') // will load 'newpath/module-b' instead.
-
-remapper can also tell you the dependency tree of the module's it's loaded.
-
- remapper.depends
-
this was composed by copy/pasting from github.com/ry/node/src/node.js and spliting it into multiple modules, adding exports, refactoring, testing and adding as little as possible.
I'll be the first to admit that alot of the code in here is a bit ugly,
View
@@ -0,0 +1,20 @@
+{
+ "name": "remap",
+ "description": "inject wrappers, mocks and new modules through 'require'",
+ "version": "0.0.0",
+ "homepage": "https://github.com/dominictarr/remap",
+ "repository": "git://github.com/dominictarr/remap.git",
+ "author": "Dominic Tarr <dominic.tarr@gmail.com>",
+ "main":"remapper",
+ "modules":{
+ "loading":"./loading"
+ , "modules":"./modules"
+ , "resolve":"./resolve"
+ },
+ "directories": {
+ "lib":"./"
+ },
+ "engines": {
+ "node": "*"
+ }
+}
View
@@ -5,8 +5,8 @@ var modules = require('remap/modules')
, log = console.log
, inspect = require('inspect')
, assert = require('assert')
-module.exports = Remapper
+module.exports = Remapper
function Remapper (_module,remaps){
var self = this
@@ -11,7 +11,7 @@ var a_fn = 'remap/test/.examples/a'
, e_fn = 'remap/test/.examples/e'
, describe = require('should').describe
, inspect = require('util').inspect //require('inspect')
- , traverser = require('traverser/traverser2')
+ , traverser = require('traverser')
function branches(depends){
@@ -9,7 +9,7 @@ var Remapper = require('remap/remapper')
, describe = require('should').describe
, helper = require('./.helper/helper')
, inspect = require('util').inspect //require('inspect')
- , log = require('logger')
+ , log = console.log
, a_fn = 'remap/test/.examples/a'
, b_fn = 'remap/test/.examples/b'
, c_fn = 'remap/test/.examples/c'
@@ -16,8 +16,7 @@ var Remapper = require('remap/remapper')
, describe = require('should').describe
, helper = require('./.helper/helper')
, inspect = require('util').inspect //require('inspect')
- , traverser = require('traverser/traverser2')
- , log = require('logger')
+ , traverser = require('traverser')
, a_fn = 'remap/test/.examples/a'
, b_fn = 'remap/test/.examples/b'
, c_fn = 'remap/test/.examples/c'

0 comments on commit 81bdfc2

Please sign in to comment.