GithubHelp home page GithubHelp logo

Comments (4)

Flickwire avatar Flickwire commented on August 22, 2024

Separately, though related, is the case of 'provides' type requirements, such as php-http/client-implementation. Obviously these should be excluded (as presumably a providing package is being required somewhere and will be picked up by Strauss separately), and this can be done manually in the strauss configuration for the root package, but skipping these automagically would be nice, though I am not sure how possible this is.

from strauss.

BrianHenryIE avatar BrianHenryIE commented on August 22, 2024

Looks like the Packagist API will help address packages like league/omnipay.

Probably by doing ~ if(!file_exists(...)), which would also work with other non-standard package types, but I haven't looked at any yet.

I didn't notice that Strauss handles the provides key of packages. It's certainly not explicitly doing so, but maybe they're being pulled in via Composer\Package\PackageInterface::getRequires(). There are already default exclusions for psr* and ext-* which I'd expected would be expanded.

I'm busy for the next week but will take a look into this afterwards.

from strauss.

BrianHenryIE avatar BrianHenryIE commented on August 22, 2024

OK, I've a branch with passing tests:
https://github.com/BrianHenryIE/strauss/blob/meta-packages/tests/Issues/StraussIssue22Test.php

It's reading the meta package from composer.lock (which I looked for before but thought it wasn't there!) and is ignoring the virtual package.

There some code duplication that needs to be tidied up:

/**
* 2. Built flat list of packages and dependencies.
*
* 2.1 Initiate getting dependencies for the project composer.json.
*
* @see Compose::flatDependencyTree
*/
protected function buildDependencyList()
{
$requiredPackageNames = $this->config->getPackages();
$virtualPackages = array(
'php-http/client-implementation'
);
// Unset PHP, ext-*, ...
$removePhpExt = function ($element) use ($virtualPackages) {
return !(
0 === strpos($element, 'ext')
|| 'php' === $element
|| in_array($element, $virtualPackages)
);
};
$requiredPackageNames = array_filter($requiredPackageNames, $removePhpExt);
foreach ($requiredPackageNames as $requiredPackageName) {
$packageComposerFile = $this->workingDir . $this->config->getVendorDirectory()
. $requiredPackageName . DIRECTORY_SEPARATOR . 'composer.json';
if (!file_exists($packageComposerFile)) {
$composerLock = json_decode(file_get_contents($this->workingDir . 'composer.lock'));
$requiredPackageComposerJson = null;
foreach ($composerLock->packages as $packageJson) {
if ($requiredPackageName === $packageJson->name) {
$requiredPackageComposerJson = $packageJson;
break;
}
}
$tempComposerFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $requiredPackageName . DIRECTORY_SEPARATOR . time();
mkdir($tempComposerFile, 0777, true);
$requiredPackageComposerJsonString = json_encode($requiredPackageComposerJson);
$tempComposerFile = $tempComposerFile . DIRECTORY_SEPARATOR . 'composer.json';
$result = file_put_contents($tempComposerFile, $requiredPackageComposerJsonString);
if (false == $result) {
throw new Exception();
}
$packageComposerFile = $tempComposerFile;
}
$overrideAutoload = isset($this->config->getOverrideAutoload()[$requiredPackageName])
? $this->config->getOverrideAutoload()[$requiredPackageName]
: null;
$requiredComposerPackage = new ComposerPackage($packageComposerFile, $overrideAutoload);
$this->flatDependencyTree[$requiredComposerPackage->getName()] = $requiredComposerPackage;
$this->getAllDependencies($requiredComposerPackage);
}
}
/**
* 2.2 Recursive function to get dependencies.
*
* @param ComposerPackage $requiredDependency
*/
protected function getAllDependencies(ComposerPackage $requiredDependency): void
{
$excludedPackagesNames = $this->config->getExcludePackagesFromPrefixing();
$requiredPackageNames = $requiredDependency->getRequiresNames();
$virtualPackageNames = array(
'php-http/client-implementation'
);
// Unset PHP, ext-*, ...
$removePhpExt = function ($element) use ($excludedPackagesNames, $virtualPackageNames) {
return !(
0 === strpos($element, 'ext')
|| 'php' === $element
|| in_array($element, $excludedPackagesNames)
|| in_array($element, $virtualPackageNames)
);
};
$requiredPackageNames = array_filter($requiredPackageNames, $removePhpExt);
foreach ($requiredPackageNames as $dependencyName) {
$overrideAutoload = isset($this->config->getOverrideAutoload()[$dependencyName])
? $this->config->getOverrideAutoload()[$dependencyName]
: null;
$packageComposerFile = $this->workingDir . $this->config->getVendorDirectory()
. $dependencyName . DIRECTORY_SEPARATOR . 'composer.json';
if (!file_exists($packageComposerFile)) {
$composerLock = json_decode(file_get_contents($this->workingDir . 'composer.lock'));
$requiredPackageComposerJson = null;
foreach ($composerLock->packages as $packageJson) {
if ($dependencyName === $packageJson->name) {
$requiredPackageComposerJson = $packageJson;
break;
}
}
$tempComposerFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $dependencyName . DIRECTORY_SEPARATOR . time();
mkdir($tempComposerFile, 0777, true);
$requiredPackageComposerJsonString = json_encode($requiredPackageComposerJson);
$tempComposerFile = $tempComposerFile . DIRECTORY_SEPARATOR . 'composer.json';
$result = file_put_contents($tempComposerFile, $requiredPackageComposerJsonString);
if (false == $result) {
throw new Exception();
}
$packageComposerFile = $tempComposerFile;
}
$dependencyComposerPackage = new ComposerPackage($packageComposerFile, $overrideAutoload);
$this->flatDependencyTree[$dependencyName] = $dependencyComposerPackage;
$this->getAllDependencies($dependencyComposerPackage);
}
}

And it needs a test with a package that requires a virtual package. And needs to be tested on Windows.

from strauss.

BrianHenryIE avatar BrianHenryIE commented on August 22, 2024

I pushed some more changes to the branch. I don't foresee any more. Once I get a chance to write a few lines in the README I'll merge and push a new release to Packagist.

from strauss.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.