lib/pym.js
function _resolvePackageSync(base, relativePath) {
    var packageJsonPath;
    var packagePath;

    // try to fetch node package
    try {
        packageJsonPath = _resolvePackagePathSync(base, PATH.join(relativePath, 'package.json'));
        packagePath = dirname(packageJsonPath);
    } catch (err) {
        if (err.code !== 'ENOENT') {
            throw err;
        }

        // try to resolve package itself
        packagePath = _resolvePackagePathSync(base, relativePath);
    }

    // compiling resolved metadata
    var packageJson = packageJsonPath && require(packageJsonPath) || {};
    var metadata = packageJson.pym || {};

    metadata.interface =
        metadata.interface ||
        packageJson.pym ? 'pym' :
        packageJson.plugin ? 'architect' :
        // what 'bout amd?
        'commonjs';

    // load package itself
    var packageMainPath;
    var nodeModule;
    switch (metadata.interface) {
        case 'pym':
            packageMainPath = PATH.join(packagePath, metadata.main || packageJson.main);
            nodeModule = require(packageMainPath);
            metadata.provides = metadata.provides || nodeModule.provides || [];
            metadata.consumes = metadata.consumes || nodeModule.consumes || [];
            metadata.packagePath = packagePath;
            metadata.exports = nodeModule;
            break;
        case 'architect':
            var pluginData = packageJson.plugin || {};
            nodeModule = require(packagePath);
            metadata.provides = pluginData.provides || nodeModule.provides || [];
            metadata.consumes = pluginData.consumes || nodeModule.consumes || [];
            metadata.packagePath = packagePath;
            metadata.exports = _wrapToArchitect(nodeModule, metadata);
            break;
        default:
            throw new Error('Unsupported package format ' + relativePath);
    }

    return metadata;
}
function _resolvePackageSync(base, relativePath) {
    var packageJsonPath;
    var packagePath;

    // try to fetch node package
    try {
        packageJsonPath = _resolvePackagePathSync(base, PATH.join(relativePath, 'package.json'));
        packagePath = dirname(packageJsonPath);
    } catch (err) {
        if (err.code !== 'ENOENT') {
            throw err;
        }

        // try to resolve package itself
        packagePath = _resolvePackagePathSync(base, relativePath);
    }

    // compiling resolved metadata
    var packageJson = packageJsonPath && require(packageJsonPath) || {};
    var metadata = packageJson.pym || {};

    metadata.interface =
        metadata.interface ||
        packageJson.pym ? 'pym' :
        packageJson.plugin ? 'architect' :
        // what 'bout amd?
        'commonjs';

    // load package itself
    var packageMainPath;
    var nodeModule;
    switch (metadata.interface) {
        case 'pym':
            packageMainPath = PATH.join(packagePath, metadata.main || packageJson.main);
            nodeModule = require(packageMainPath);
            metadata.provides = metadata.provides || nodeModule.provides || [];
            metadata.consumes = metadata.consumes || nodeModule.consumes || [];
            metadata.packagePath = packagePath;
            metadata.exports = nodeModule;
            break;
        case 'architect':
            var pluginData = packageJson.plugin || {};
            nodeModule = require(packagePath);
            metadata.provides = pluginData.provides || nodeModule.provides || [];
            metadata.consumes = pluginData.consumes || nodeModule.consumes || [];
            metadata.packagePath = packagePath;
            metadata.exports = _wrapToArchitect(nodeModule, metadata);
            break;
        default:
            throw new Error('Unsupported package format ' + relativePath);
    }

    return metadata;
}
function _resolvePackageSync ( base , relativePath ) { var packageJsonPath ; var packagePath ; // try to fetch node package try { packageJsonPath = _resolvePackagePathSync ( base , PATH . join ( relativePath , 'package.json' ) ) ; packagePath = dirname ( packageJsonPath ) ; } catch ( err ) { if ( err . code !== 'ENOENT' ) { throw err ; } // try to resolve package itself packagePath = _resolvePackagePathSync ( base , relativePath ) ; } // compiling resolved metadata var packageJson = packageJsonPath && require ( packageJsonPath ) || { } ; var metadata = packageJson . pym || { } ; metadata . interface = metadata . interface || packageJson . pym ? 'pym' : packageJson . plugin ? 'architect' : // what 'bout amd? 'commonjs' ; // load package itself var packageMainPath ; var nodeModule ; switch ( metadata . interface ) { case 'pym' : packageMainPath = PATH . join ( packagePath , metadata . main || packageJson . main ) ; nodeModule = require ( packageMainPath ) ; metadata . provides = metadata . provides || nodeModule . provides || [ ] ; metadata . consumes = metadata . consumes || nodeModule . consumes || [ ] ; metadata . packagePath = packagePath ; metadata . exports = nodeModule ; break ; case 'architect' : var pluginData = packageJson . plugin || { } ; nodeModule = require ( packagePath ) ; metadata . provides = pluginData . provides || nodeModule . provides || [ ] ; metadata . consumes = pluginData . consumes || nodeModule . consumes || [ ] ; metadata . packagePath = packagePath ; metadata . exports = _wrapToArchitect ( nodeModule , metadata ) ; break ; default : throw new Error ( 'Unsupported package format ' + relativePath ) ; } return metadata ; }
Loads a module, getting metadata from either it's package.json
or export object.
@private
@param {string} base
@param {string} relativePath
@returns {Object}
- {string[]} provides
- {string[]} consumes
- {string} packagePath
- {string}
Loads a module getting metadata from either it s package . json or export object .