src/util/npm-helper.js
function cachePackage(packageName, packageVersion) {
    //todo Market-Injection
  // WEEK_HOOK
  if(packageName !== "judpack-android" && packageName !== "judpack-ios") {
    packageName = JudMarket.info(packageName)
  }
  else {
    packageName = { fullname: packageName}
  }

    return Q(packageName).then(function (data) {
      packageName=data.fullname;

      // npm.config.set('registry','http://registry.npm.alibaba-inc.com');
      /*if(data.p){
        npm.config.set('registry','http://registry.npm.alibaba-inc.com');
      }
      else{
        npm.config.delete('registry');
      }*/
        var registry=data.p?'http://registry.npm.alibaba-inc.com':'http://registry.npm.taobao.org/';
        var cacheDir = path.join(util.libDirectory, 'npm_cache');

        // If already cached, use that rather than calling 'npm cache add' again.
        var packageCacheDir = path.resolve(cacheDir, packageName, packageVersion);
        var packageTGZ = path.resolve(packageCacheDir, 'package.tgz');
        if (util.existsSync(packageTGZ)) {
            return unpack.unpackTgz(packageTGZ, path.resolve(packageCacheDir, 'package'));
        }

        // Load with NPM configuration
        return loadWithSettingsThenRestore({'cache': cacheDir,"registry":registry},
            function () {
                // Invoke NPM Cache Add
                return Q.ninvoke(npm.commands, 'cache', ['add', (packageName + '@' + packageVersion)]).then(
                    function (info) {
                        var packageDir = path.resolve(npm.cache, info.name, info.version, 'package');
                        var packageTGZ = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
                        return unpack.unpackTgz(packageTGZ, packageDir);
                    }
                );
            }
        );
    });
}
function cachePackage(packageName, packageVersion) {
    //todo Market-Injection
  // WEEK_HOOK
  if(packageName !== "judpack-android" && packageName !== "judpack-ios") {
    packageName = JudMarket.info(packageName)
  }
  else {
    packageName = { fullname: packageName}
  }

    return Q(packageName).then(function (data) {
      packageName=data.fullname;

      // npm.config.set('registry','http://registry.npm.alibaba-inc.com');
      /*if(data.p){
        npm.config.set('registry','http://registry.npm.alibaba-inc.com');
      }
      else{
        npm.config.delete('registry');
      }*/
        var registry=data.p?'http://registry.npm.alibaba-inc.com':'http://registry.npm.taobao.org/';
        var cacheDir = path.join(util.libDirectory, 'npm_cache');

        // If already cached, use that rather than calling 'npm cache add' again.
        var packageCacheDir = path.resolve(cacheDir, packageName, packageVersion);
        var packageTGZ = path.resolve(packageCacheDir, 'package.tgz');
        if (util.existsSync(packageTGZ)) {
            return unpack.unpackTgz(packageTGZ, path.resolve(packageCacheDir, 'package'));
        }

        // Load with NPM configuration
        return loadWithSettingsThenRestore({'cache': cacheDir,"registry":registry},
            function () {
                // Invoke NPM Cache Add
                return Q.ninvoke(npm.commands, 'cache', ['add', (packageName + '@' + packageVersion)]).then(
                    function (info) {
                        var packageDir = path.resolve(npm.cache, info.name, info.version, 'package');
                        var packageTGZ = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
                        return unpack.unpackTgz(packageTGZ, packageDir);
                    }
                );
            }
        );
    });
}
function cachePackage ( packageName , packageVersion ) { //todo Market-Injection // WEEK_HOOK if ( packageName !== "judpack-android" && packageName !== "judpack-ios" ) { packageName = JudMarket . info ( packageName ) } else { packageName = { fullname : packageName } } return Q ( packageName ) . then ( function ( data ) { packageName = data . fullname ; // npm.config.set('registry','http://registry.npm.alibaba-inc.com'); /*if(data.p){
        npm.config.set('registry','http://registry.npm.alibaba-inc.com');
      }
      else{
        npm.config.delete('registry');
      }*/ var registry = data . p ? 'http://registry.npm.alibaba-inc.com' : 'http://registry.npm.taobao.org/' ; var cacheDir = path . join ( util . libDirectory , 'npm_cache' ) ; // If already cached, use that rather than calling 'npm cache add' again. var packageCacheDir = path . resolve ( cacheDir , packageName , packageVersion ) ; var packageTGZ = path . resolve ( packageCacheDir , 'package.tgz' ) ; if ( util . existsSync ( packageTGZ ) ) { return unpack . unpackTgz ( packageTGZ , path . resolve ( packageCacheDir , 'package' ) ) ; } // Load with NPM configuration return loadWithSettingsThenRestore ( { 'cache' : cacheDir , "registry" : registry } , function ( ) { // Invoke NPM Cache Add return Q . ninvoke ( npm . commands , 'cache' , [ 'add' , ( packageName + '@' + packageVersion ) ] ) . then ( function ( info ) { var packageDir = path . resolve ( npm . cache , info . name , info . version , 'package' ) ; var packageTGZ = path . resolve ( npm . cache , info . name , info . version , 'package.tgz' ) ; return unpack . unpackTgz ( packageTGZ , packageDir ) ; } ) ; } ) ; } ) ; }
Invokes "npm cache add," and then returns a promise that resolves to a directory containing the downloaded,
or cached package.
@param packageName - name of an npm package
@param packageVersion - requested version (not a version range)
Invokes npm cache add and then returns a promise that resolves to a directory containing the downloaded or cached package .