lib/bundleLocator.js
function (dir, _depth) {
        var self = this,
            pkg,
            seed,
            seeds = [],
            subdirs;

        _depth = _depth || 0;

        try {
            pkg = require(libpath.resolve(dir, 'package.json'));
            // top level package doesn't require a locator flag in package.json
            if ((0 === _depth) && (!pkg.locator)) {
                pkg.locator = {};
            }
            seed = this._makeBundleSeed(dir, libpath.basename(dir), DEFAULT_VERSION, pkg);
            if (seed.options) {
                seed.npmDepth = _depth;
                seeds.push(seed);
            }
        } catch (packageErr) {
            // Some build environments leave extraneous directories in
            // node_modules and we should ignore them gracefully.
            // (trello board:Modown card:124)
            if ('MODULE_NOT_FOUND' !== packageErr.code) {
                throw packageErr;
            }
            return seeds;
        }

        if (_depth < this._options.maxPackageDepth) {
            try {
                subdirs = libfs.readdirSync(libpath.join(dir, 'node_modules'));
            } catch (readdirErr) {
                if ('ENOENT' === readdirErr.code) {
                    // missing node_modules/ directory is OK
                    return seeds;
                }
                throw readdirErr;
            }
            subdirs.reduce(function (memo, subdir) {
                return memo.concat(
                    '@' === subdir.substring(0, 1) ?
                        libfs.readdirSync(libpath.join(dir, 'node_modules', subdir)).map(function (scopeddir) {
                            return libpath.join(subdir, scopeddir);
                        }) :
                        [subdir]
                );
            }, []).forEach(function (subdir) {
                var subpkgResults;
                if ('.' === subdir.substring(0, 1)) {
                    return;
                }
                subpkgResults = self._walkNPMTree(libpath.join(dir, 'node_modules', subdir), _depth + 1);
                // merge in found packages
                if (subpkgResults && subpkgResults.length) {
                    seeds = seeds.concat(subpkgResults);
                }
            });
        }
        return seeds;
    }
function (dir, _depth) {
        var self = this,
            pkg,
            seed,
            seeds = [],
            subdirs;

        _depth = _depth || 0;

        try {
            pkg = require(libpath.resolve(dir, 'package.json'));
            // top level package doesn't require a locator flag in package.json
            if ((0 === _depth) && (!pkg.locator)) {
                pkg.locator = {};
            }
            seed = this._makeBundleSeed(dir, libpath.basename(dir), DEFAULT_VERSION, pkg);
            if (seed.options) {
                seed.npmDepth = _depth;
                seeds.push(seed);
            }
        } catch (packageErr) {
            // Some build environments leave extraneous directories in
            // node_modules and we should ignore them gracefully.
            // (trello board:Modown card:124)
            if ('MODULE_NOT_FOUND' !== packageErr.code) {
                throw packageErr;
            }
            return seeds;
        }

        if (_depth < this._options.maxPackageDepth) {
            try {
                subdirs = libfs.readdirSync(libpath.join(dir, 'node_modules'));
            } catch (readdirErr) {
                if ('ENOENT' === readdirErr.code) {
                    // missing node_modules/ directory is OK
                    return seeds;
                }
                throw readdirErr;
            }
            subdirs.reduce(function (memo, subdir) {
                return memo.concat(
                    '@' === subdir.substring(0, 1) ?
                        libfs.readdirSync(libpath.join(dir, 'node_modules', subdir)).map(function (scopeddir) {
                            return libpath.join(subdir, scopeddir);
                        }) :
                        [subdir]
                );
            }, []).forEach(function (subdir) {
                var subpkgResults;
                if ('.' === subdir.substring(0, 1)) {
                    return;
                }
                subpkgResults = self._walkNPMTree(libpath.join(dir, 'node_modules', subdir), _depth + 1);
                // merge in found packages
                if (subpkgResults && subpkgResults.length) {
                    seeds = seeds.concat(subpkgResults);
                }
            });
        }
        return seeds;
    }
Walks a directory and returns a list of metadata about locator packages
installed in that directory (including the package for the directory itself).
@private
@method _walkNPMTree
@param {string} dir Directory to walk.
@param {integer} _depth [internal] Depth of the directory being walked.
Internally used for recursion.
@return {Array} information about locator packages in the directory.
If the directory is not an NPM package then it returns undefined value.