Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

modules folder name is configurable #32

Merged
merged 1 commit into from

2 participants

@mafintosh

Make the name of the modules folder configurable to something other than node_modules by setting opts.modules.
This allows you to use the node resolve algorithm to resolve all kinds of crazy stuff like config files, templates etc.

var resolve = require('resolve');
// use config instead of node_modules and find the nearest config file
var configPath = resolve('test', {
    modules: 'config',
    extensions: ['json']
});
// use views for our templates
var templatePath = resolve('my-template', {
    modules: 'views',
    extensions: ['html']
});
@substack substack merged commit d65a422 into from
@substack
Owner

Published in 0.5.0. I renamed opts.modules to opts.moduleDirectory to be a bit more descriptive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 1, 2013
  1. @mafintosh
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 4 deletions.
  1. +3 −2 lib/async.js
  2. +3 −2 lib/sync.js
View
5 lib/async.js
@@ -23,6 +23,7 @@ module.exports = function resolve (x, opts, cb) {
var extensions = opts.extensions || [ '.js' ];
var y = opts.basedir || path.dirname(caller());
+ var modules = opts.modules || 'node_modules';
opts.paths = opts.paths || [];
@@ -127,10 +128,10 @@ module.exports = function resolve (x, opts, cb) {
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
- if (parts[i] === 'node_modules') continue;
+ if (parts[i] === modules) continue;
var dir = path.join(
path.join.apply(path, parts.slice(0, i + 1)),
- 'node_modules'
+ modules
);
if (!parts[0].match(/([A-Za-z]:)/)) {
dir = '/' + dir;
View
5 lib/sync.js
@@ -16,6 +16,7 @@ module.exports = function (x, opts) {
var extensions = opts.extensions || [ '.js' ];
var y = opts.basedir || path.dirname(caller());
+ var modules = opts.modules || 'node_modules';
opts.paths = opts.paths || [];
@@ -83,10 +84,10 @@ module.exports = function (x, opts) {
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
- if (parts[i] === 'node_modules') continue;
+ if (parts[i] === modules) continue;
var dir = path.join(
path.join.apply(path, parts.slice(0, i + 1)),
- 'node_modules'
+ modules
);
if (!parts[0].match(/([A-Za-z]:)/)) {
dir = '/' + dir;
Something went wrong with that request. Please try again.