Browse files

add ignore parameter to resolve callback

If ignore is specified, required will not process dependencies for the
returned path.
  • Loading branch information...
1 parent a096427 commit 340a0098f8cbc6466566abb65b55300b5fb24478 @defunctzombie committed Feb 22, 2013
Showing with 15 additions and 2 deletions.
  1. +2 −1 README.md
  2. +13 −1 index.js
View
3 README.md
@@ -60,7 +60,8 @@ Each object in the array takes the following form:
// function(id, parent, cb);
// id is the string for the call to require
// parent is an object describing the calling file { filename: String, paths: [] }
- // callback (err, '/path/to/resolved/file.js')
+ // callback (err, '/path/to/resolved/file.js' [, ignore])
+ // if ignore is true, required will not try to process the resulting path for deps
resolve: null,
// optional replacement for builtin detection of requires
View
14 index.js
@@ -34,7 +34,7 @@ function from_source(source, parent, opt, cb) {
var native = natives[id];
- var resolve = opt.resolve(req, parent, function(err, full_path) {
+ var resolve = opt.resolve(req, parent, function(err, full_path, ignore) {
if (err) {
return cb(err);
}
@@ -63,6 +63,18 @@ function from_source(source, parent, opt, cb) {
'required from ' + parent.filename));
}
+ // ignore indicates we should not process dependencies for this file
+ // this is useful if we don't care about certain files being handled further
+ // we still want the dependency added to the deps of the file we processed
+ // but do not process this file or it's deps
+ if (ignore) {
+ result.push({
+ id: id,
+ filename: full_path
+ });
+ return next();
+ }
+
var paths = parent.paths.concat(node_module_paths(full_path));
var new_parent = {

0 comments on commit 340a009

Please sign in to comment.