lib/pym.js
function _resolvePackagePathSync(base, relativePath) {
    var originalBase = base;
    if (!(base in packagePathCache)) {
        packagePathCache[base] = {};
    }

    var cache = packagePathCache[base];
    if (relativePath in cache) {
        return cache[relativePath];
    }

    var packagePath;
    if (relativePath[0] === '.' || relativePath[0] === '/') {
        packagePath = resolve(base, relativePath);
        if (existsSync(packagePath)) {
            packagePath = realpathSync(packagePath);
            cache[relativePath] = packagePath;
            return packagePath;
        }
    } else {
        var newBase;
        while (base) {
            packagePath = resolve(base, 'node_modules', relativePath);
            if (existsSync(packagePath)) {
                packagePath = realpathSync(packagePath);
                cache[relativePath] = packagePath;
                return packagePath;
            }
            newBase = resolve(base, '..');
            if (base === newBase) {
                break;
            }
            base = newBase;
        }
    }

    var err = new Error('Can\'t find "' + relativePath + '" relative to "' + originalBase + '"');
    err.code = 'ENOENT';
    throw err;
}
function _resolvePackagePathSync(base, relativePath) {
    var originalBase = base;
    if (!(base in packagePathCache)) {
        packagePathCache[base] = {};
    }

    var cache = packagePathCache[base];
    if (relativePath in cache) {
        return cache[relativePath];
    }

    var packagePath;
    if (relativePath[0] === '.' || relativePath[0] === '/') {
        packagePath = resolve(base, relativePath);
        if (existsSync(packagePath)) {
            packagePath = realpathSync(packagePath);
            cache[relativePath] = packagePath;
            return packagePath;
        }
    } else {
        var newBase;
        while (base) {
            packagePath = resolve(base, 'node_modules', relativePath);
            if (existsSync(packagePath)) {
                packagePath = realpathSync(packagePath);
                cache[relativePath] = packagePath;
                return packagePath;
            }
            newBase = resolve(base, '..');
            if (base === newBase) {
                break;
            }
            base = newBase;
        }
    }

    var err = new Error('Can\'t find "' + relativePath + '" relative to "' + originalBase + '"');
    err.code = 'ENOENT';
    throw err;
}
function _resolvePackagePathSync ( base , relativePath ) { var originalBase = base ; if ( ! ( base in packagePathCache ) ) { packagePathCache [ base ] = { } ; } var cache = packagePathCache [ base ] ; if ( relativePath in cache ) { return cache [ relativePath ] ; } var packagePath ; if ( relativePath [ 0 ] === '.' || relativePath [ 0 ] === '/' ) { packagePath = resolve ( base , relativePath ) ; if ( existsSync ( packagePath ) ) { packagePath = realpathSync ( packagePath ) ; cache [ relativePath ] = packagePath ; return packagePath ; } } else { var newBase ; while ( base ) { packagePath = resolve ( base , 'node_modules' , relativePath ) ; if ( existsSync ( packagePath ) ) { packagePath = realpathSync ( packagePath ) ; cache [ relativePath ] = packagePath ; return packagePath ; } newBase = resolve ( base , '..' ) ; if ( base === newBase ) { break ; } base = newBase ; } } var err = new Error ( 'Can\'t find "' + relativePath + '" relative to "' + originalBase + '"' ) ; err . code = 'ENOENT' ; throw err ; }
Node style package resolving so that plugins' package.json can be found relative to the config file
It's not the full node require system algorithm, but it's the 99% case
This throws, make sure to wrap in try..catch
@private
@param {string} base - base path
@param {string} relativePath
Node style package resolving so that plugins package . json can be found relative to the config file It s not the full node require system algorithm but it s the 99% case This throws make sure to wrap in try .. catch