Install plugins using NPM

@param  {String|String[]} packages - name of packages
@param  {Function} [callback]
554166
function npmInstall(packages, callback) {
  callback = utils.defineCallback(callback);
  if (_.isString(packages)) {
    packages = [ packages ];
  }
  return npm.load({
    loglevel: "silent",
    prefix: tmpDir,
  }, function(loadErr) {
    if (loadErr) {
      return callback(new errors.NpmLoadError(loadErr));
    }
    npm.commands.install(packages, function(installErr) {
      if (installErr) {
        return callback(new errors.NpmInstallError(installErr));
      }
      ncp(tmpDir + "/node_modules/", pluginsDir, function(copyError) {
        if (copyError) {
          return callback(new errors.PluginsMoveFromTempError(copyError));
        }
        return callback(null);
      }); // ncp
    }); // npm.commands.install
  }); // npm.load
}
66859
private void add(String packages) {
    if (packages != null) {
      String[] split = packages.split(",|;| ");
      for (int i = 0; i < split.length; i++) {
        String pkg = split[i].trim();
        if (!pkg.isEmpty()) {
          packageSet.add(pkg);
        }
      }
    }
  }
1271370
function listPlugins(callback) {
  callback = utils.defineCallback(callback);
  return fs.readdir(pluginsDir, function(readdirErr, files) {
    if (readdirErr) {
      return callback(new errors.PluginsListingError(readdirErr));
    }
    var fullpath, pkg;
    var descriptors = [ ];
    files.forEach(function (file) {
      fullpath = path.join(pluginsDir, file, "package.json");
      try {
        pkg = require(fullpath);
        descriptors.push({
          name: pkg.name,
          version: pkg.version || "",
          description: pkg.description || "",
          author: pkg.author || "",
          icon: pkg.icon || "",
          homepage: pkg.homepage || "",
        });
    } catch (requireErr) {
        /*
        * we shall ignore this error and only list those plugins
        * we can load
        */
      }
    });
    return callback(null, descriptors);
  });
}
1255346
function loadModules() {
  const nodeModulesPath = path.join(process.cwd(), plugin.config.modulesPath);

  return plugin.myrmex.fire('beforeNodeModulesLoad')
  .then(() => {
    // Retrieve paths of all node packages
    return Promise.promisify(fs.readdir)(nodeModulesPath);
  })
  .then(subdirs => {
    // Load all packages configurations
    const nodeModulePromises = [];
    _.forEach(subdirs, (subdir) => {
      const nodeModulePath = path.join(nodeModulesPath, subdir);
      // subdir is the name of the package, so we pass it as the second argument
      nodeModulePromises.push(loadNodeModule(nodeModulePath, subdir));
    });
    return Promise.all(nodeModulePromises);
  })
  .then(nodeModules => {
    // This event allows to inject code to add or delete or alter node modules configurations
    return plugin.myrmex.fire('afterNodeModulesLoad', nodeModules);
  })
  .spread(nodeModules => {
    return Promise.resolve(nodeModules);
  })
  .catch(e => {
    // In case the project does not have any node package yet, an exception will be thrown
    // We silently ignore it
    if (e.code === 'ENOENT' && path.basename(e.path) === 'modules') {
      return Promise.resolve([]);
    }
    return Promise.reject(e);
  });
}
1314565
function setup (mode, callback) {
  copy(testPackageSrc, testPackageRnd, { overwrite: true }, function (err) {
    if (err)
      return callback(err)

    copy.copyDeps(testPackageRnd, callback)
  })
}
40465
function createPackageJson(plugin_path) {
    var pluginInfo = new PluginInfo(plugin_path);

    var defaults = {
        id:pluginInfo.id,
        version:pluginInfo.version,
        description:pluginInfo.description,
        license:pluginInfo.license,
        keywords:pluginInfo.getKeywordsAndPlatforms(),
        repository:pluginInfo.repo,
        bugs:pluginInfo.issue,
        engines:pluginInfo.getEngines(),
        platforms: pluginInfo.getPlatformsArray()
    };

    fs.writeFile(path.join(__dirname,'defaults.json'), JSON.stringify(defaults), 'utf8', function (err) {
        if (err) throw err;
        events.emit('verbose', 'defaults.json created from plugin.xml');
        var initFile = require.resolve('./init-defaults');
        var dir = process.cwd();

        init(dir, initFile, {}, function (err, data) {
            if(err) throw err;
            events.emit('verbose', 'Package.json successfully created');
        });
    });
    return Q();
}
936008
function installMutations(modules, enclosingFolder) {
  makeFolderLibraryIfNotExist(enclosingFolder);
  if (modules.length === 0) {
    return new Promise(resolve => resolve({}));
  }

  return npm.install(modules, {
    cwd: pathToMutations(enclosingFolder),
    save: true
  });
}
899916
function npmInstall(requires, done) {
    var npmBin = path.join(path.dirname(process.argv[0]), 'npm');
    if (process.platform === 'win32') { npmBin += '.cmd'; }
    async.forEachSeries(requires, function(module, next) {
      // skip existing modules
      if (grunt.file.exists(path.join('./node_modules/' + module))) {
        grunt.log.writeln(String('Module "' + module + '" already installed, skipping.').cyan);
        return next();
      }
      grunt.log.writeln('npm install ' + module + ' --save');
      // spawn npm install
      var s = grunt.util.spawn({
        cmd: npmBin,
        args: ['install', module, '--save']
      }, next);
      // write output
      s.stdout.on('data', function(buf) { grunt.log.write(String(buf)); });
      s.stderr.on('data', function(buf) { grunt.log.write(String(buf)); });
    }, done);
  }
484522
public void installApp(Functions.Func callback) {
        if (isPwaSupported()) {
            appInstaller = new AppInstaller(callback);
            appInstaller.prompt();
        }
    }
545350
function Package(name)
    {
        var dotBowerJson = Package._readBowerJson(name) || {};
        var overrides = globalOverrides[name] || {};

        this.name         = name;
        this.installed    = !! dotBowerJson.name;
        this.main         = overrides.main || dotBowerJson.main || [];
        this.dependencies = overrides.dependencies || dotBowerJson.dependencies || [];
    }
982669
function(callback) {
    var packages = Object.keys(this.packageToVersions);
    async.parallel(packages.map(function(package) {
      var packageRootUrl = url.resolve(this.master, package);
      return this.downloadPackageRootObject.bind(this, package, packageRootUrl);
    }.bind(this)), function(err) {
      return callback && callback(err);
    });
  }
1203846
function (packages) {
  var resolvedPackages = {};

  _.forOwn(packages, function (definition, packageName) {
    if (!definition) return;

    var git = definition.git;
    if (!git) return;

    var repo = resolvedPackages[git] = resolvedPackages[git] || {};

    // If no branch provided - checkout origin HEAD and
    // don't show 'detached HEAD' notification
    branch = definition.branch || '-q origin';
    // If no version provided - pull HEAD
    version = definition.version || 'HEAD';
    repo[branch] = repo[branch] || {};
    repo[branch][version] = repo[branch][version] || {};
    repo[branch][version][packageName] = definition.path || '';
  });

  return resolvedPackages;
}
924883
function init (options) {
  if (typeof options === 'string') {
    options = { base: options }
  }

  options = options || {}

  // There is probably 99% chance that the project root directory in located
  // above the node_modules directory
  var base = nodePath.resolve(
    options.base || nodePath.join(__dirname, '../..')
  )
  var packagePath = base.replace(/\/package\.json$/, '') + '/package.json'

  try {
    var npmPackage = require(packagePath)
  } catch (e) {
    // Do nothing
  }

  if (typeof npmPackage !== 'object') {
    throw new Error('Unable to read ' + packagePath)
  }

  //
  // Import aliases
  //

  var aliases = npmPackage._moduleAliases || {}

  for (var alias in aliases) {
    if (aliases[alias][0] !== '/') {
      aliases[alias] = nodePath.join(base, aliases[alias])
    }
  }

  addAliases(aliases)

  //
  // Register custom module directories (like node_modules)
  //

  if (npmPackage._moduleDirectories instanceof Array) {
    npmPackage._moduleDirectories.forEach(function (dir) {
      if (dir === 'node_modules') return

      var modulePath = nodePath.join(base, dir)
      addPath(modulePath)
    })
  }
}
1255898
function resolvePackage(packageName) {
    try {
      // First, try to use require.resolve to find the package.
      // We add /package.json and then dirname the result because require.resolve follows the `main`
      // property in package.json to produce a path to a file deep inside the package, and we want
      // the path to the top-level directory.
      // This branch handles packages being symlinked into node_modules, for example with
      // `npm link` or in sku's test cases.
      const result = path.dirname(
        resolve(`${packageName}/package.json`, { paths: [cwd()] }),
      );
      debug(`Resolved ${packageName} to ${result}`);
      return result;
    } catch (error) {
      if (error.code === 'MODULE_NOT_FOUND') {
        const dependencies = getProjectDependencies(fs.readFileSync);

        if (!dependencies[packageName]) {
          // If it's not we can safely return a naive local path, which prevents webpack from
          // throwing config schema errors when this function is used to configure a loader.
          // This branch handles the scenario where we're trying to resolve a design system module because
          // it's in the default list of compilePackages, but it's not actually being used in the project.
          const localPackage = path.join(cwd(), 'node_modules', packageName);
          debug(`Resolved unused package ${packageName} to ${localPackage}`);
          return localPackage;
        }
      }

      // We've gotten this far because the package is listed as a project dependency and can't be
      // resolved, or because the error is not ENOENT. In either case we want to throw.
      throw error;
    }
  }
447193
function loadAndInstall() {
    meta = { packages: target };
    exports.load(function (err) {
      if (err) {
        return callback(err);
      }

      installAll(target);
    });
  }
26348
def install(self, name=None, prefix=None, pkgs=None, dep=True,
                channels=None, token=None):
        
        logger.debug(str((prefix, pkgs, channels)))

        # TODO: Fix temporal hack
        if not pkgs or not isinstance(pkgs, (list, tuple, str)):
            raise TypeError('must specify a list of one or more packages to '
                            'install into existing environment')

        cmd_list = ['install', '--yes', '--json', '--force-pscheck']
        if name:
            cmd_list.extend(['--name', name])
        elif prefix:
            cmd_list.extend(['--prefix', prefix])
        else:
            # Just install into the current environment, whatever that is
            pass

        # TODO: Check if correct
        if channels:
            cmd_list.extend(['--override-channels'])

            for channel in channels:
                cmd_list.extend(['--channel'])
                channel = self.parse_token_channel(channel, token)
                cmd_list.extend([channel])

        # TODO: Fix temporal hack
        if isinstance(pkgs, (list, tuple)):
            cmd_list.extend(pkgs)
        elif isinstance(pkgs, str):
            cmd_list.extend(['--file', pkgs])

        if not dep:
            cmd_list.extend(['--no-deps'])

        return self._call_and_parse(cmd_list)
1128410
function installAll(deps) {
    npm.commands.install(dir, deps, function (err) {
      if (err) {
        return callback(err);
      }

      haibu.emit('npm:install:success', 'info', meta);
      callback(null, deps);
    });
  }