Find all NPM bridge enabled vendor packages.

@param Composer  $composer The Composer object for the root project.
@param NpmBridge $bridge   The bridge to use.

@return array<integer,PackageInterface> The list of NPM bridge enabled vendor packages.
162773
public function find(Composer $composer, NpmBridge $bridge): array
    {
        $packages = $composer->getRepositoryManager()->getLocalRepository()
            ->getPackages();

        $dependantPackages = [];

        foreach ($packages as $package) {
            if ($bridge->isDependantPackage($package, false)) {
                $dependantPackages[] = $package;
            }
        }

        return $dependantPackages;
    }
814025
public function activate(Composer $composer, IOInterface $io)
    {
        $this->package = $composer->getPackage();
        $this->io = $io;

        // TODO: get the project root - must be a better way to do this
        $this->projectRoot = realpath(dirname($composer->getConfig()->get('vendor-dir')));
    }
337970
public static function getPackagesAndDependencies($packagesArray)
    {
        foreach ($packagesArray as $key => $value) {
            $packageFile = base_path("/vendor/{$key}/composer.json");

            if ($key !== 'php' && file_exists($packageFile)) {
                $json2 = file_get_contents($packageFile);
                $dependenciesArray = json_decode($json2, true);
                $dependencies = array_key_exists('require', $dependenciesArray) ? $dependenciesArray['require'] : 'No dependencies';
                $devDependencies = array_key_exists('require-dev', $dependenciesArray) ? $dependenciesArray['require-dev'] : 'No dependencies';

                $packages[] = [
                    'name' => $key,
                    'version' => $value,
                    'dependencies' => $dependencies,
                    'dev-dependencies' => $devDependencies
                ];
            }
        }

        return $packages;
    }
131108
private function findPackages($slugs)
    {
        $packages = [];

        foreach ($slugs as $package_slug) {
            $packageDir = $this->workingDir . '/vendor/' . $package_slug .'/';

            if (! is_dir($packageDir)) {
                continue;
            }

            $package = new Package($packageDir);
            $package->findAutoloaders();

            $config = json_decode(file_get_contents($packageDir . 'composer.json'));

            $dependencies = [];
            if (isset($config->require)) {
                $dependencies = array_keys((array)$config->require);
            }

            $package->dependencies = $this->findPackages($dependencies);
            $packages[] = $package;
        }

        return $packages;
    }
864455
protected function getComposer()
    {
        if (!$this->composer) {
            // Set composer environment variables
            putenv('COMPOSER_HOME=' . $this->app['path_resolver']->resolve('%cache%/composer'));

            // Set working directory
            chdir($this->getOptions()->baseDir());

            try {
                // Use the factory to get a new Composer object
                $this->composer = Factory::create($this->getIO(), $this->getOptions()->composerJson()->getPath(), false);
            } catch (\InvalidArgumentException $e) {
                throw new PackageManagerException($e->getMessage(), $e->getCode(), $e);
            } catch (\Exception $e) {
                $this->app['logger.system']->critical($e->getMessage(), ['event' => 'exception', 'exception' => $e]);
                throw $e;
            }

            // Add the event subscriber
            $this->composer->getEventDispatcher()->addSubscriber($this->app['extend.listener']);

            if (!$this->app['extend.manager']->useSsl()) {
                $this->setAllowSslDowngrade(true);
            }
        }

        return $this->composer;
    }
1372162
public static function readFile($package)
    {
        $root = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
        $path = implode(DIRECTORY_SEPARATOR, array($root, $package, 'composer.json'));
        Logger::trace("Reading composer file %s", $path);
        if (file_exists($path)) {
            $composer = json_decode(file_get_contents($path), true);
            if (array_key_exists('require', $composer) && !empty($composer['require'])) {
                $directories = array($package);
                Logger::trace("Checking dependencies for package %s", $package);
                foreach ($composer['require'] as $requirement => $version) {
                    $directories = array_merge(self::readFile($requirement), $directories);
                }
                return $directories;
            } else {
                Logger::trace("Package %s has no dependencies", $package);
                return array($package);
            }
        } else {
            return array();
        }
    }
760750
public function getDependencies($moduleName, $convertPackageNameToNamespace = true)
    {
        $modulePath = $this->getModulePath($moduleName);
        $dependencies = [];

        if ($modulePath) {

            $defaultDependencies = ['melis-core'];
            $dependencies = $defaultDependencies;
            $composerPossiblePath = [$modulePath . '/composer.json'];
            $composerFile = null;

            // search for the composer.json file
            foreach ($composerPossiblePath as $file) {
                if (file_exists($file)) {
                    $composerFile = file_get_contents($file);
                }
            }

            // if composer.json is found
            if ($composerFile) {

                $composer = json_decode($composerFile, true);
                $requires = isset($composer['require']) ? $composer['require'] : null;
                if ($requires) {
                    $requires = array_map(function ($a) {
                        // remove melisplatform prefix
                        return str_replace(['melisplatform/', ' '], '', trim($a));
                    }, array_keys($requires));

                    $dependencies = $requires;
                }
            }

            if ($convertPackageNameToNamespace) {
                $tmpDependencies = [];
                $toolSvc = $this->getServiceLocator()->get('MelisCoreTool');

                foreach ($dependencies as $dependency) {
                    $tmpDependencies[] = ucfirst($toolSvc->convertToNormalFunction($dependency));
                }

                $dependencies = $tmpDependencies;
            }
        }

        return $dependencies;
    }
124059
public function sync($listener, $vendor, $package = null)
    {
        $roles = [];
        $name = $this->getExtension($vendor, $package)->get('name');
        $acl = $this->acl->get($name);

        if (is_null($acl)) {
            return $listener->aclVerificationFailed();
        }

        foreach ($this->model->all() as $role) {
            $roles[] = $role->name;
        }

        $acl->roles()->attach($roles);

        $acl->sync();

        return $listener->syncSucceed(new Fluent(compact('vendor', 'package', 'name')));
    }
482864
public function onPostPackageEvent(\Composer\Installer\PackageEvent $event)
    {
        $package = $this->getDrupalPackage($event->getOperation());
        if ($package) {
            if (!$this->isPackageSupported($package)) {
                $this->unsupportedPackages[$package->getName()] = $package;
            }
        }
    }
1142981
public function addPackageFromComposerFiles($composers)
    {
        settype($composers, 'array');
        foreach($composers as $file)
        {
            $data = (array)json_decode(file_get_contents($file));

            if (isset($data['type']) && $data['type'] == 'anahita-extension') {
                if (!isset($data['extension-source'])) {
                    $data['extension-source'] = 'src';
                }

                $data['extension-source'] = realpath(dirname($file).'/src');

                if (is_readable($data['extension-source'])) {
                    $parts = array_filter(explode('/', @$data['name']));
                    $name = strtolower(pick(@$parts[1], basename(dirname($file))));
                    $vendor = strtolower(pick(@$parts[0], $name));
                    $this[] = new Package(array(
                        'composer_file' => $file,
                        'name' => $name,
                        'vendor' => $vendor,
                        'source' => $data['extension-source']
                    ));
                }
            }
        }
    }
1234507
private function getDepRepos(Composer $composer)
    {
        $depRepos = [];
        if (\is_array($this->depRepositories)) {
            $rm = $composer->getRepositoryManager();
            foreach ($this->depRepositories as $index => $repoConfig) {
                $name = \is_int($index) && isset($repoConfig['url']) ? $repoConfig['url'] : $index;
                $type = $repoConfig['type'] ?? '';
                $depRepos[$index] = $rm->createRepository($type, $repoConfig, $name);
            }
        }

        return $depRepos;
    }
739279
private function loadComposerPackages()
    {
        $repository = $this->composer->getRepositoryManager()->getLocalRepository();
        $packages = array();

        foreach ($repository->getPackages() as $package) {
            /* @var PackageInterface $package */
            $packages[$package->getName()] = $package;
        }

        return $packages;
    }
292246
private function getPackageNameByComposerName($composerPackageName)
    {
        foreach ($this->config->all() as $key => $configItem) {
            if ($configItem['name'] == $composerPackageName) {
                return $key;
            }
        }
    }
479731
protected function getPackages()
    {
        $translator = $this->container->get('translator');
        $errorMessage = $translator->trans('settings.version.error_parsing_composer');

        $composerPath = $this->getLockPath();
        if (!file_exists($composerPath)) {
            throw new ParseException(
                $translator->trans('settings.version.composer_lock_not_found')
            );
        }

        $json = file_get_contents($composerPath);
        $result = json_decode($json, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new ParseException($errorMessage.' (#'.json_last_error().')');
        }

        if (array_key_exists('packages', $result) && is_array($result['packages'])) {
            return $result['packages'];
        }

        // No package list in JSON structure
        throw new ParseException($errorMessage);
    }
926814
protected static function getPatchedDependencyConstraints(RootPackageInterface $root_package) {
    $required = $root_package->getRequires();
    $extra = $root_package->getExtra();
    $patched = $extra['patches'];
    return array_intersect_key($required, $patched);
  }
253973
private function getSupportedPackages(array $packages)
    {
        $supported_packages = [];
        foreach ($packages as $package) {
            /* @var $package \Composer\Package\PackageInterface */
            if ($this->supportsPackage($package)) {
                $supported_packages[] = $package;
            }
        }
        return $supported_packages;
    }
1022259
public function getInstallPath(PackageInterface $package)
    {
        $type = $package->getType();
        if (substr($type, 0, strlen(self::NAME)) !== self::NAME) {
            throw new InvalidArgumentException(
                'Sorry the package type of this package is not yet supported.'
            );
        }

        $subPackageType = substr($type, strlen(self::NAME) + 1);

        $prettyName = $package->getPrettyName();
        if (strpos($prettyName, '/') !== false) {
            list($vendor, $name) = explode('/', $prettyName);
        } else {
            $vendor = '';
            $name = $prettyName;
        }

        $extra = $package->getExtra();
        if (!empty($extra['installer-name'])) {
            $name = $extra['installer-name'];
        }

        $availableVars = compact('name', 'vendor', 'type');

        if ($this->composer->getPackage()) {
            $extra = $this->composer->getPackage()->getExtra();
            if (!empty($extra['installer-paths'])) {
                $customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type, $vendor);
                if (!empty($customPath)) {
                    return $this->templatePath($customPath, $availableVars);
                }
            }
        }

        $locations = self::LOCATIONS;
        if (!isset($locations[$subPackageType])) {
            throw new InvalidArgumentException(sprintf('Sub-package type "%s" is not supported', $type));
        }

        return $this->templatePath($locations[$subPackageType], $availableVars);
    }