Add the given modules to a package json's dependencies.
15340
function addModulesToPackageJson(externalModules, packageJson, pathToPackageRoot) {
  _.forEach(externalModules, externalModule => {
    const splitModule = _.split(externalModule, '@');
    // If we have a scoped module we have to re-add the @
    if (_.startsWith(externalModule, '@')) {
      splitModule.splice(0, 1);
      splitModule[0] = '@' + splitModule[0];
    }
    let moduleVersion = _.join(_.tail(splitModule), '@');
    // We have to rebase file references to the target package.json
    moduleVersion = rebaseFileReferences(pathToPackageRoot, moduleVersion);
    packageJson.dependencies = packageJson.dependencies || {};
    packageJson.dependencies[_.first(splitModule)] = moduleVersion;
  });
}
217586
def import_submodules(module):
    """"""
    submodules = {}
    for loader, name, ispkg in pkgutil.iter_modules(module.__path__,
                                                    module.__name__ + '.'):
        try:
            submodule = import_module(name)
        except ImportError as e:
            # FIXME: Make the errors non-fatal (do we want that?).
            logging.warning("Error importing %s", name)
            logging.exception(e)
        else:
            parent, child = name.rsplit('.', 1)
            submodules[child] = submodule
    return submodules
952928
public void addImportedPackages(String[] imports) {
        if (imports == null) { return; }

        for (String imported : imports) {
            this.mImports.add(imported);
        }
    }
1289907
protected static function updatePackages($dev = true)
    {
        if (! file_exists(base_path('package.json'))) {
            return;
        }

        $configurationKey = $dev ? 'devDependencies' : 'dependencies';

        $packages = json_decode(file_get_contents(base_path('package.json')), true);

        $packages[$configurationKey] = static::updatePackageArray(
            array_key_exists($configurationKey, $packages) ? $packages[$configurationKey] : [],
            $configurationKey
        );

        ksort($packages[$configurationKey]);

        file_put_contents(
            base_path('package.json'),
            json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).PHP_EOL
        );
    }
967950
function writePackageJson (devDependencies) {
  debug('input devDependencies: %o', devDependencies)

  if (!lodash.isPlainObject(devDependencies)) {
    debug('devDependencies isn\'t plain object, return')
    // 不报错
    return Promise.resolve()
  }

  const baseDir = getBaseDir()
  const pkgPath = path.join(baseDir, 'package.json')

  debug(`package.json: ${pkgPath}`)

  if (!fs.existsSync(pkgPath)) {
    debug(`file not exists: ${pkgPath}, return`)
    return Promise.resolve()
  }

  let content

  try {
    content = JSON.parse(fs.readFileSync(pkgPath))
  } catch (error) {
    debug('parse package.json error')
    return Promise.resolve()
  }

  content.devDependencies = sort(Object.assign(
    {},
    content.devDependencies || {},
    devDependencies
  ))

  return writeJsonFile(pkgPath, content, {
    detectIndent: true
  })
}
767123
def _import_submodules(package_name):
    
    package = sys.modules[package_name]
    out = {}
    for loader, name, is_pkg in pkgutil.walk_packages(package.__path__):
        try:
            #module = importlib.import_module('{}.{}'.format(package_name, name))
            module = importlib.import_module('.{}'.format(name), package=package_name)
            out[name] = module
        except:
            continue
    return out
1167687
async function mergePackageJsons () {
    // transform our package.json incase we need to replace variables
    const rawJson = await template.generate({
      directory: `${ignite.ignitePluginPath()}/boilerplate`,
      template: 'package.json.ejs',
      props: props
    })
    const newPackageJson = JSON.parse(rawJson)

    // read in the react-native created package.json
    const currentPackage = filesystem.read('package.json', 'json')

    // deep merge, lol
    const newPackage = pipe(
      assoc(
        'dependencies',
        merge(currentPackage.dependencies, newPackageJson.dependencies)
      ),
      assoc(
        'devDependencies',
        merge(currentPackage.devDependencies, newPackageJson.devDependencies)
      ),
      assoc('scripts', merge(currentPackage.scripts, newPackageJson.scripts)),
      merge(
        __,
        omit(['dependencies', 'devDependencies', 'scripts'], newPackageJson)
      )
    )(currentPackage)

    // write this out
    filesystem.write('package.json', newPackage, { jsonIndent: 2 })
  }
892825
def _installed_packages(self) -> Generator[str, None, None]:
        """"""
        with (self._build_dir / 'package.json').open('r') as f:
            packages = json.load(f)
        yield from packages['dependencies'].keys()
892172
function visitPackageJSON(folderPath)
{
  let files = fs.readdirSync(folderPath);
  for (var i in files) {
    let name = files[i];
    let filePath = path.join(folderPath, files[i]);
    if(fs.statSync(filePath).isDirectory()) {
      visitPackageJSON(filePath);
    } else {
      if (name === 'package.json') {
        try {
          patchPackageJSON_preNodeGyp_modulePath(filePath);
        } catch (e) {
          console.warn(
            'Failed to patch the file : "' +
            filePath +
            '". The following error was thrown: ' +
            JSON.stringify(e)
          );
        }
      }
    }
  }
}
53405
def _add_dependency(self, module, mn):
        
        _debug.debug("_add_dependency:module=%s", mn)

        if _is_streamsx_module(module):
            _debug.debug("_add_dependency:streamsx module=%s", mn)
            return False

        if _is_builtin_module(module):
            _debug.debug("_add_dependency:builtin module=%s", mn)
            return False

        if not self._include_module(module, mn):
          #print ("ignoring dependencies for {0} {1}".format(module.__name__, module))
          return False

        package_name = _get_package_name(module)
        top_package_name = module.__name__.split('.')[0]

        if package_name and top_package_name in sys.modules:
            # module is part of a package
            # get the top-level package
            top_package = sys.modules[top_package_name]

            if "__path__" in top_package.__dict__:
                # for regular packages, there is one top-level directory
                # for namespace packages, there can be more than one.
                # they will be merged in the bundle
                seen_non_site_package = False
                for top_package_path in reversed(list(top_package.__path__)):
                    top_package_path = os.path.abspath(top_package_path)
                    if 'site-packages' in top_package_path:
                        continue
                    seen_non_site_package = True
                    self._add_package(top_package_path)
                if not seen_non_site_package:
                    _debug.debug("_add_dependency:site-packages path module=%s", mn)
                    return False
            elif hasattr(top_package, '__file__'):
                # package that is an individual python file with empty __path__
                if 'site-packages' in top_package.__file__:
                    _debug.debug("_add_dependency:site-packages module=%s", mn)
                    return False
                self._add_package(os.path.abspath(top_package.__file__))
        elif hasattr(module, '__file__'):
            # individual Python module
            module_path = os.path.abspath(module.__file__)
            if 'site-packages' in module_path:
                _debug.debug("_add_dependency:site-packages module=%s", mn)
                return False
            self._modules.add(module_path)
            
        self._processed_modules.add(module)
        return True
973251
def install_json_params(self):
        """"""
        if not self._install_json_params:
            for param in self.install_json.get('params') or []:
                self._install_json_params[param.get('name')] = param
        return self._install_json_params
831859
function dependencyLink (pkg, cb) {
  var dependencies = path.join(npm.dir, pkg.name, pkg.version, "node_modules")
    , depBin = path.join(npm.dir, pkg.name, pkg.version, "dep-bin")
  asyncMap(pkg._resolvedDeps, function (dep, cb) {
    log.silly(dep, "dependency")
    var fromRoot = path.join(npm.dir, dep.name, dep.version)
      , dependsOn = path.join( npm.dir, pkg.name, pkg.version
                             , "dependson", dep.name + "@" + dep.version
                             )
    link(fromRoot, dependsOn, cb)
  }, function (dep, cb) {
    var depDir = path.join(npm.dir, dep.name, dep.version, "package")
    readJson(path.join(depDir, "package.json"), function (er, dep) {
      if (er) return cb(er)
      loadPackageDefaults(dep, function (er, dep) {
        if (er) return cb(er)
        asyncMap([dep], function (dep) {
          var toLib = path.join(dependencies, dep.name)
          linkModules(dep, toLib, cb)
        }, function (dep, cb) {
          // link the bins to this pkg's "dep-bin" folder.
          linkBins(dep, depBin, false, cb)
        }, cb)
      })
    })
  }, cb)
}
668275
def _fix_deps_repos(self, dependencies):
        
        requires = []
        for dep in dependencies:
            if dep in self.repo_pkg_names:
                requires.append(dep)
        return requires
518624
def update(self, *pkgs, **kwargs):
        """"""
        cmd_list = ['update', '--json', '--yes']

        if not pkgs and not kwargs.get('all'):
            raise TypeError("Must specify at least one package to update, or "
                            "all=True.")

        cmd_list.extend(
            self._setup_install_commands_from_kwargs(
                kwargs,
                ('dry_run', 'no_deps', 'override_channels',
                 'no_pin', 'force', 'all', 'use_index_cache', 'use_local',
                 'alt_hint')))

        cmd_list.extend(pkgs)

        return self._call_and_parse(cmd_list, abspath=kwargs.get('abspath',
                                                                 True))
1217179
def dependencies(self, name=None, prefix=None, pkgs=None, channels=None,
                     dep=True):
        """"""
        if not pkgs or not isinstance(pkgs, (list, tuple)):
            raise TypeError('must specify a list of one or more packages to '
                            'install into existing environment')

        cmd_list = ['install', '--dry-run', '--json', '--force-pscheck']

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

        if name:
            cmd_list.extend(['--name', name])
        elif prefix:
            cmd_list.extend(['--prefix', prefix])
        else:
            pass

        cmd_list.extend(pkgs)

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

            for channel in channels:
                cmd_list.extend(['--channel'])
                cmd_list.extend([channel])

        return self._call_and_parse(cmd_list)
914572
function basePackageJson (opts) {
  opts = opts || {}
  const _name = opts.name || '<name>'
  const _version = opts.version || '1.0.0'
  const _private = opts.private || false

  var called = false

  return from({ objectMode: true }, function (size, next) {
    if (called) return next(null, null)

    const res = { name: _name, version: _version }
    if (_private) res.private = true
    res.scripts = {}
    res.dependencies = {}
    res.devDependencies = {}

    called = true
    next(null, res)
  })
}
1026005
function (module_name, module_folder, callback) {
    var module_folder = path.resolve(module_folder)
    var module_packaged = _load_package(module_folder);

    var module_dependencies = _.d.get(module_packaged, "/dependencies");
    if (!module_dependencies) {
        return callback();
    }

    module_dependencies = _.keys(module_dependencies);

    var _install_next = function() {
        if (module_dependencies.length === 0) {
            return callback();
        }

        var dname = module_dependencies.pop();
        var dependency_folder = path.join(module_folder, "node_modules", dname);
        var dependency_homestard = _load_homestar(dependency_folder);

        var is_module = _.d.get(dependency_homestard, "/module", false);
        if (!is_module) {
            return _install_next();
        }

        console.log("- found dependency:", dname);
        _install(dname, function() {
            try {
                console.log("- cleanup");
                console.log("  path:", dependency_folder);
                _rmdirSync(dependency_folder);
            } catch (x) {
            }

            _install_next();
        });
    }

    _install_next();
}