Sha256: c7d0200ec3d2b83adea3d960b9431f0f9720cd8498c34c882cc735a703906696

Contents?: true

Size: 1.23 KB

Versions: 104

Compression:

Stored size: 1.23 KB

Contents

var path = require('path');
var parse = path.parse || require('path-parse');

var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
    var prefix = '/';
    if ((/^([A-Za-z]:)/).test(absoluteStart)) {
        prefix = '';
    } else if ((/^\\\\/).test(absoluteStart)) {
        prefix = '\\\\';
    }

    var paths = [absoluteStart];
    var parsed = parse(absoluteStart);
    while (parsed.dir !== paths[paths.length - 1]) {
        paths.push(parsed.dir);
        parsed = parse(parsed.dir);
    }

    return paths.reduce(function (dirs, aPath) {
        return dirs.concat(modules.map(function (moduleDir) {
            return path.resolve(prefix, aPath, moduleDir);
        }));
    }, []);
};

module.exports = function nodeModulesPaths(start, opts, request) {
    var modules = opts && opts.moduleDirectory
        ? [].concat(opts.moduleDirectory)
        : ['node_modules'];

    if (opts && typeof opts.paths === 'function') {
        return opts.paths(
            request,
            start,
            function () { return getNodeModulesDirs(start, modules); },
            opts
        );
    }

    var dirs = getNodeModulesDirs(start, modules);
    return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
};

Version data entries

104 entries across 96 versions & 14 rubygems

Version Path
enju_library-0.3.8 spec/dummy/node_modules/resolve/lib/node-modules-paths.js
condenser-0.3 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
ilog-0.4.1 node_modules/resolve/lib/node-modules-paths.js
ilog-0.4.0 node_modules/resolve/lib/node-modules-paths.js
ilog-0.3.3 node_modules/resolve/lib/node-modules-paths.js
condenser-0.2 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
condenser-0.1 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
condenser-0.0.12 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
condenser-0.0.11 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
condenser-0.0.10 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
condenser-0.0.9 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
condenser-0.0.8 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
learn_create-0.0.22 lib/templates/javascript_lab_template/node_modules/resolve/lib/node-modules-paths.js
jester-data-8.0.0 node_modules/resolve/lib/node-modules-paths.js
ezii-os-5.2.1 node_modules/resolve/lib/node-modules-paths.js
ezii-os-2.0.1 node_modules/resolve/lib/node-modules-paths.js
ezii-os-1.1.0 node_modules/resolve/lib/node-modules-paths.js
ezii-os-1.0.0 node_modules/resolve/lib/node-modules-paths.js
condenser-0.0.7 lib/condenser/processors/node_modules/resolve/lib/node-modules-paths.js
ezii-os-0.0.0.1.0 node_modules/resolve/lib/node-modules-paths.js