beberlei / composer-monorepo-plugin Goto Github PK
View Code? Open in Web Editor NEWIntegrates Composer into monolithic repositories with many packages.
License: MIT License
Integrates Composer into monolithic repositories with many packages.
License: MIT License
Can you create a new release/tag for update the package?
In the case below "baz" will not be loaded, if we use --no-dev flag.
{
"deps": ["baz"],
"deps-dev": ["bar"],
"autoload": {
"psr-0": {"Foo\\": "src/main"}
}
}
Currently you have to list all external dependencies together in the shared composer.json
, however this does not make it clear what the needs are for any individual module (subfolder), and may cause the inclusion of unnecessary dependencies when only certain modules are desired.
composer.json
.fiddler.json
file shall support two new sections, require
and require-dev
. These sections contain an array of strings, where each string is the name of a composer-dependency that it relies upon.require
dependency in a fiddler.json
must have a direct corresponding entry in the require
section of composer.json
.require-dev
dependency in a fiddler.json
must have a corresponding entry in the require-dev
or require
sections of composer.json
.require
or require-dev
entry in composer.json
that does not have any corresponding entry somewhere in at least one fiddler.json
file should cause a warning message, since it may indicate an unnecessary or unclear dependency.The benefit of this feature is that it documents how/why certain dependencies are necessary, by associating them with the particular modules that use them.
This second part involves more tinkering with composer-internals and may not be feasible, but I'm writing it out as a "cool to have".
vendor/autoload.php
file shall only try to load assets that are referenced (directly or transitively) via its deps
, require
, or require-dev
sections.composer archive
with issue #18 , and affect what assets are present in the vendor
folder.Running composer update
I'm getting the following error message.
file_get_contents(vendor/beberlei/composer-monorepo-plugin/src/main/Fiddler/../../resources/fiddler-schema.json): failed to open stream: No such file or directory
Hi @beberlei ,
Why are you uploading tar.gz file. May be upload phar itself as you did in first time ?
I am trying to switch from manyrepos to a monorepo and am trying out this plugin. I have several symfony apps and component libraries I am trying to combine. I have got all the autoloading working but am looking for suggestions on using incenteev/composer-parameter-handler.
It looks like my parameters need to be defined in the root composer.json. Should I define all the parameters in a single parameters.yml
and all apps will draw from this global file?
I'm just looking to see if anyone else has come across this and how they solved it.
When trying to install Monorepo Builder, which depends on this project, I'm getting the following error:
PHP Fatal error: Declaration of Monorepo\Composer\EventDispatcher::dispatch(string $eventName, ?Composer\EventDispatcher\Event $event = null) must be compatible with Composer\EventDispatcher\EventDispatcher::dispatch(?string $eventName, ?Composer\EventDispatcher\Event $event = null): int in /home/jschumann/git-wrdsb/wordpress/wordpress/vendor/beberlei/composer-monorepo-plugin/src/main/Monorepo/Composer/EventDispatcher.php on line 9
It says that you should use the path relative to the root of the repo, but this is wrong. the actual expectation is to use 'vendor/'.$composerPackageName
:
target-path
property in the packageI know this is only used for internal proprietary stuff at the moment, but would it be theoretically-possible to implement it as a composer plugin, hooking it up to composer's update/autoload/install events?
I'm having a similar problem at my workplace, where we have some projects that I want to keep separate from a test-suite/reuse perspective, but where people are having problems with the multi-repository approach.
Monorepo plugins knows for every component, which other components depend on it.
That means given a list of changed files, we could return the list of components which need their tests run. This could even be written so that this is easily generated using env variables available to Travis for example, or a git commit range.
I have a multi language repo which looks like this:
- /foo
- monorepo.json
- /php
- composer.json
- lib1
- monorepo.json
- app1
- monorepo.json
- app2
- monorepo.json
- symlink-foo
I'm currently migrating project /foo
to PHP, but it's placement in tree may not be changed, so I need to symlink it to the PHP directory. The composer-monorepo-plugin
root needs to be /php
.
I have a repository with 3 Symfony web apps and a few other own libraries. Until version 0.11 I was able to composer install/update
and monorepo would generate the autoloaders without problems.
Now I'm getting the following error message. Apparently Monorepo is trying to load the Composer classes in a traditional way.
Requiring non-existent composer-package 'vendor/composer-plugin-api' in 'vendor/ocramius/package-versions'. Please ensure it is present in composer.json.
would be nice to see an example to easy adoption for this tool
so that we can test ourselves and see the benefits first hand and
also copy paste and adapt the configuration to our internal or other FOSS projects.
Thanks!
Fiddler should generate vendor/bin/*
binaries when present in dependencies.
Consider the following directory structure:
├── myapp
│ └── fiddler.json
├── composer.json
In composer.json
:
{
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*"
}
}
In myapp/fiddler.json
:
{
"deps": [
"vendor/laravel/framework"
],
"autoload": {
"psr-4": {
"App\\": "app/"
}
}
}
This results in:
[RuntimeException]
Requiring non existant package 'vendor/jeremeamia/superclosure' in 'myapp'.
My app includes laravel/framework
which in turn includes jeremeamia/superclosure
. The path to jeremeamia/superclosure
is vendor/jeremeamia/SuperClosure
. It seems that this can be resolved by changing:
$packages['vendor/' . $name] = $fiddleredComposerJson;
to:
$packages['vendor/' . strtolower($name)] = $fiddleredComposerJson;
in Fiddler\Build
, but I'm not familiar enough with the package yet to know if this causes other issues. Does anyone have any thoughts on this issue? Thanks!
Hi @beberlei ,
I downloaded the fiddler.phar file . And tried with what I understood.
I created the fiddler.json
like
{
"deps": [
"vendor/cakephp/"
],
"autoload": {
"psr-0": {
"Foo\\":"src/"
}
}
}
I have a dependency on cakephp/orm
on the composer.json . Is there anything I missed for the fiddler seems not changing anything. Is that due to the bug you mentioned on the commit ?
Or may be I am missing the whole point on the docs :-/ .
Composer 2.3.4 & PHP 8.1.4
There are some incompatibilities with method signatures.
Fatal error: Declaration of
Monorepo\Composer\EventDispatcher::dispatch($eventName, ?Composer\EventDispatcher\Event $event = null) must be compatible with
Composer\EventDispatcher\EventDispatcher::dispatch(?string $eventName, ?Composer\EventDispatcher\Event $event = null): int
in vendor/beberlei/composer-monorepo-plugin/src/main/Monorepo/Composer/EventDispatcher.php on line 9
Some abstract method are not implemented too:
Composer\Repository\InstalledRepositoryInterface::getDevMode()
In Composer 2, a new magic cmponent composer-runtime-api
was added, that when present generates a magic class Composer\InstalledVersions
that is available in every script. This must be copied to exist in every component.
That is if either the root package, or any dependency of the monorepo package has a dependency on composer-runtime-api
, then Composer\InstalledVersions
must be generated as its done in FilesystemRepository
: https://github.com/composer/composer/blob/master/src/Composer/Repository/FilesystemRepository.php#L130-L138
When i try to define this as vendor, i get the following error by using the autoloader:
"vendor/symfony/phpunit-bridge"
And the error:
Warning: require(/Users/***/vendor/symfony/phpunit-bridge/bootstrap.php): failed to open stream: No such file or directory in /Users/***/fiddlerDemo/components/project_c/vendor/composer/autoload_real.php on line 54
But:
"vendor/symfony/symfony"
works fine for me
Hey,
I would like to share my feedback on this promising tool to manage multiple PHP project in the same repository.
fiddler
)First, I had to change symfony/flex
for symfony/symfony
. Symfony Flex will install all recipe at the monorepo root which is really annoying.
Create the root composer.json
{
"name": "plop/backend",
"require": {
"beberlei/composer-monorepo-plugin": "~0.13",
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/api-pack": "^1.2",
"auth0/jwt-auth-bundle": "^3.0",
"doctrine/doctrine-migrations-bundle": "^2.0",
"league/flysystem-aws-s3-v3": "^1.0",
"oneup/flysystem-bundle": "^3.1",
"ramsey/uuid-doctrine": "^1.5",
"sensio/framework-extra-bundle": "^5.4",
"sentry/sentry-symfony": "^3.1",
"stof/doctrine-extensions-bundle": "^1.3",
"symfony-bundles/redis-bundle": "^2.2",
"symfony/console": "4.3.*",
"symfony/form": "4.3.*",
"symfony/framework-bundle": "4.3.*",
"symfony/http-client": "4.3.*",
"symfony/workflow": "4.3.*",
"symfony/yaml": "4.3.*",
"symfony/symfony": "4.3.*"
},
"require-dev": {
"behat/behat": "^3.5",
"behat/mink": "dev-master",
"behat/mink-browserkit-driver": "dev-master",
"behat/mink-extension": "dev-master",
"behat/symfony2-extension": "^2.1",
"behatch/contexts": "^3.0",
"doctrine/doctrine-fixtures-bundle": "^3.2",
"friendsofphp/php-cs-fixer": "^2.15",
"hautelook/alice-bundle": "^2.5",
"phpstan/phpstan": "^0.11.15",
"phpstan/phpstan-symfony": "^0.11.6",
"symfony/debug-pack": "^1.0",
"symfony/dotenv": "^4.3"
}
}
And configure monorepo.json
into api-*
folders
{
"deps": [
"vendor/api-platform/api-pack",
"vendor/auth0/jwt-auth-bundle",
"vendor/doctrine/doctrine-migrations-bundle",
"vendor/league/flysystem-aws-s3-v3",
"vendor/oneup/flysystem-bundle",
"vendor/ramsey/uuid-doctrine",
"vendor/sensio/framework-extra-bundle",
"vendor/sentry/sentry-symfony",
"vendor/stof/doctrine-extensions-bundle",
"vendor/symfony-bundles/redis-bundle",
"vendor/symfony/console",
"vendor/symfony/dotenv",
"vendor/symfony/form",
"vendor/symfony/framework-bundle",
"vendor/symfony/http-client",
"vendor/symfony/workflow",
"vendor/symfony/yaml",
"vendor/symfony/symfony"
],
"deps-dev": [
"vendor/behat/behat",
"vendor/behat/mink",
"vendor/behat/mink-browserkit-driver",
"vendor/behat/mink-extension",
"vendor/behat/symfony2-extension",
"vendor/behatch/contexts",
"vendor/doctrine/doctrine-fixtures-bundle",
"vendor/friendsofphp/php-cs-fixer",
"vendor/hautelook/alice-bundle",
"vendor/phpstan/phpstan",
"vendor/phpstan/phpstan-symfony",
"vendor/symfony/debug-pack"
],
"autoload": {
"psr-4": {
"App\\": "src/",
"Fixtures\\": "fixtures/"
}
},
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
}
}
}
run composer install
, it detects & generates the subpackage autoload 🎉
Directly through REST client, everything seems to work 👌
I can resolve asset, when I search in autoloader, there is no asset Class loaded. Even if I try to add in monorepo.json : "vendor/symfony/asset"
, it is not resolved. I tried to install it, reference it, ... It is required by api-platform/api-pack
.
Some tests failed. Seems there is some problem with autoload providers for faker in Fixtures, error are not clear on this.
Add to that, I have this when I run any console command:
PHP Warning: Class 'Nette\DI\Config\Adapter' not found in /var/www/vendor/nette/di/src/compatibility.php on line 10
PHP Stack trace:
PHP 1. {main}() /var/www/vendor/behat/behat/bin/behat:0
PHP 2. require() /var/www/vendor/behat/behat/bin/behat:15
PHP 3. require_once() /var/www/api/vendor/autoload.php:5
PHP 4. composerRequireOnce8cfb30f5c45c15f7ff26872515d65e35() /var/www/api/vendor/composer/autoload_real.php:56
PHP 5. require_once() /var/www/api/vendor/composer/autoload_real.php:61
PHP 6. class_alias() /var/www/vendor/nette/di/src/compatibility.php:10
PHP Warning: Class 'Nette\DI\Definitions\Statement' not found in /var/www/vendor/nette/di/src/compatibility.php on line 11
PHP Stack trace:
PHP 1. {main}() /var/www/vendor/behat/behat/bin/behat:0
PHP 2. require() /var/www/vendor/behat/behat/bin/behat:15
PHP 3. require_once() /var/www/api/vendor/autoload.php:5
PHP 4. composerRequireOnce8cfb30f5c45c15f7ff26872515d65e35() /var/www/api/vendor/composer/autoload_real.php:56
PHP 5. require_once() /var/www/api/vendor/composer/autoload_real.php:61
PHP 6. class_alias() /var/www/vendor/nette/di/src/compatibility.php:11
PHP Warning: Class 'Nette\DI\Definitions\ServiceDefinition' not found in /var/www/vendor/nette/di/src/compatibility.php on line 12
PHP Stack trace:
PHP 1. {main}() /var/www/vendor/behat/behat/bin/behat:0
PHP 2. require() /var/www/vendor/behat/behat/bin/behat:15
PHP 3. require_once() /var/www/api/vendor/autoload.php:5
PHP 4. composerRequireOnce8cfb30f5c45c15f7ff26872515d65e35() /var/www/api/vendor/composer/autoload_real.php:56
PHP 5. require_once() /var/www/api/vendor/composer/autoload_real.php:61
PHP 6. class_alias() /var/www/vendor/nette/di/src/compatibility.php:12
Same problem with Nette\DI\Config\Adapter
, seems it has not been included into the autoloader.
$ vendor/bin/phpstan analyse -c phpstan.neon src/ --level=7 --memory-limit=512M
PHP Warning: Class 'Nette\DI\Config\Adapter' not found in /var/www/vendor/nette/di/src/compatibility.php on line 10
PHP Stack trace:
PHP 1. {main}() /var/www/vendor/phpstan/phpstan/bin/phpstan:0
PHP 2. require_once() /var/www/vendor/phpstan/phpstan/bin/phpstan:14
PHP 3. require_once() /var/www/api/vendor/autoload.php:5
PHP 4. composerRequireOnce8cfb30f5c45c15f7ff26872515d65e35() /var/www/api/vendor/composer/autoload_real.php:56
PHP 5. require_once() /var/www/api/vendor/composer/autoload_real.php:61
PHP 6. class_alias() /var/www/vendor/nette/di/src/compatibility.php:10
PHP Warning: Class 'Nette\DI\Definitions\Statement' not found in /var/www/vendor/nette/di/src/compatibility.php on line 11
PHP Stack trace:
PHP 1. {main}() /var/www/vendor/phpstan/phpstan/bin/phpstan:0
PHP 2. require_once() /var/www/vendor/phpstan/phpstan/bin/phpstan:14
PHP 3. require_once() /var/www/api/vendor/autoload.php:5
PHP 4. composerRequireOnce8cfb30f5c45c15f7ff26872515d65e35() /var/www/api/vendor/composer/autoload_real.php:56
PHP 5. require_once() /var/www/api/vendor/composer/autoload_real.php:61
PHP 6. class_alias() /var/www/vendor/nette/di/src/compatibility.php:11
PHP Warning: Class 'Nette\DI\Definitions\ServiceDefinition' not found in /var/www/vendor/nette/di/src/compatibility.php on line 12
PHP Stack trace:
PHP 1. {main}() /var/www/vendor/phpstan/phpstan/bin/phpstan:0
PHP 2. require_once() /var/www/vendor/phpstan/phpstan/bin/phpstan:14
PHP 3. require_once() /var/www/api/vendor/autoload.php:5
PHP 4. composerRequireOnce8cfb30f5c45c15f7ff26872515d65e35() /var/www/api/vendor/composer/autoload_real.php:56
PHP 5. require_once() /var/www/api/vendor/composer/autoload_real.php:61
PHP 6. class_alias() /var/www/vendor/nette/di/src/compatibility.php:12
PHP Fatal error: Cannot redeclare Zend\Diactoros\createUploadedFile() (previously declared in /var/www/vendor/zendframework/zend-diactoros/src/functions/create_uploaded_file.php:19) in /var/www/vendor/zendframework/zend-diactoros/src/functions/create_uploaded_file.php on line 39
PHP Stack trace:
PHP 1. {main}() /var/www/vendor/phpstan/phpstan/bin/phpstan:0
PHP 2. {closure:/var/www/vendor/phpstan/phpstan/bin/phpstan:17-36}() /var/www/vendor/phpstan/phpstan/bin/phpstan:38
PHP 3. require_once() /var/www/vendor/phpstan/phpstan/bin/phpstan:27
PHP 4. ComposerAutoloaderInit43c17f21039003d818a50fbd4ff86312::getLoader() /var/www/vendor/autoload.php:7
PHP 5. composerRequire43c17f21039003d818a50fbd4ff86312() /var/www/vendor/composer/autoload_real.php:56
I think this composer plugin works pretty well but I am stuck with weird cases I need to resolved.
Add to that, I build Docker image to ship my API, is there a command to hard copy dependencies of a specific project into it's vendor folder such as composer monorepo:package-vendor
(to avoid copy all root vendor folder into Docker image).
Let me know if you want another insight!
If you have any tips to fix some issues thanks in advance!
I'm getting this error Fatal error: Class Monorepo\Composer\MonorepoInstalledRepository contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Composer\Repository\InstalledRepositoryInterface::getDevMode) in /var/www/html/vendor/beberlei/composer-monorepo-plugin/src/main/Monorepo/Composer/MonorepoInstalledRepository.php on line 9
when running composer monorepo:build
Composer version 2.2.6 2022-02-04 17:00:38
Currently the Build.php
script uses an absolute path to symlink the binary files. This breaks setups with shared filesystems that maybe mounted on different directories between the hosts (i.e. vagrant shared directories).
It would be nice to be able to use relative paths within the symlink which would solve these issues.
I am currently thinking about adding a $relative
parameter to PHP's symlink/link functions in order to behave analogous to ln -sr TARGET LINKNAME
. Using exec("ln -sr $absolutePath $linkPath")
will yield the correct relative result, but I think this solution is very hacky and not preferable. And using some custom logic to calculate the relative path between the target seems overkill. Not sure what to do best here though.
Hello there,
Your tool seems to be responding to my needs. But actually, there is no indications about how installing it.
Is there an easy way to do it ? Like the same way you install composer, or event like https://github.com/mybuilder/conductor/tree/master/examples/todo ?
This plugin currently does not support specifying a package type:
{
"type": "composer-installer"
}
@beberlei would you consider accepting a PR that add supports for such feature?
Introduced in this commit[0] is a change to use require_once instead of require for files in autoload_files.php. However, this change messes up the order of how files are being loaded. Normally the require('autoload_files.php') is at the end of the getLoader() method, so by the time it's called, all other autoloading is done (classmap has been loaded, etc). Instead, the autoload_files.php is included as soon as the autoload_real.php is included, while the getLoader() method has not been called yet.
So by the time autoload_files.php is called, none of the classes are available yet and you can only run code that does not need to autoload anything.
If any of the files in autoload_files.php want to use a class that's being autoloaded, it's no longer possible.
Is there a specific reason to use require_once specifically over the default composer way?
To reproduce:
"autoload": { "files": [ "my_custom_autoload.php" ] }
Expected: class from vendor dir can be loaded without problem
Result: fatal error because autoloader has not been executed yet.
[0] 86bacda
If you want to produce deployable build artifacts, then just as composer archive
there should be a way to build a tarball or directory of code with all its dependencies inlined into the components vendor/
folder.
Example:
components/Foo/src
components/Foo/web
components/Foo/vendor/autoload.php
vendor/symfony/http-foundation
Should collapse into a build/
dir:
Foo/src
Foo/web
Foo/vendor/autoload.php
Foo/vendor/symfony/http-foundation
I read the blog post today of fiddler and was wondering what is the difference to
https://github.com/Gitsplit/gitsplit
I guess long term git split is the current subtree splitter, but there seems to be a very good
idea on fiddler which is the reuse of the composer autoloading.
So I think some features that automate the handling of the subtree split can be introduced here as well?
This plugin currently does not support specifying binaries:
{
"bin": ["bin/my-script", "bin/my-other-script"]
}
@beberlei would you consider accepting a PR that add supports for such feature?
Like https://github.com/RobLoach/component-installer
[RuntimeException]
Requiring non-existent composer-package 'vendor/composer-plugin-api' in 'vendor/robloach/component-installer'. Please ensure it is present in composer.j
son.
Requires quite some work, does not look like we can be Composer 1 and 2 compatible
Hello, how are you?
I'm having problem using and installing the package after installation with Composer 2.3.5, in version 2.2.5 it works perfectly.
Is anyone else suffering from this?
-- Require step:
composer require beberlei/composer-monorepo-plugin
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^0.17.5 for beberlei/composer-monorepo-plugin
./composer.json has been updated
Running composer update beberlei/composer-monorepo-plugin
Loading composer repositories with package information
Updating dependencies
Lock file operations: 1 install, 0 updates, 0 removals
- Locking beberlei/composer-monorepo-plugin (v0.17.5)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Downloading beberlei/composer-monorepo-plugin (v0.17.5)
- Installing beberlei/composer-monorepo-plugin (v0.17.5): Extracting archive
beberlei/composer-monorepo-plugin contains a Composer plugin which is currently not in your allow-plugins config. See https://getcomposer.org/allow-plugins
Do you trust "beberlei/composer-monorepo-plugin" to execute code and wish to enable it now? (writes "allow-plugins" to composer.json) [y,n,d,?] y
Generating autoload files
Generating autoload files for monorepo sub-packages with dev-dependencies.
PHP Fatal error: Declaration of Monorepo\Composer\EventDispatcher::dispatch($eventName, ?Composer\EventDispatcher\Event $event = null) must be compatible with Composer\EventDispatcher\EventDispatcher::dispatch(?string $eventName, ?Composer\EventDispatcher\Event $event = null): int in /home/marcosmarcolin/PhpstormProjects/Composer/vendor/beberlei/composer-monorepo-plugin/src/main/Monorepo/Composer/EventDispatcher.php on line 9
-- Installation step:
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating autoload files
Generating autoload files for monorepo sub-packages with dev-dependencies.
PHP Fatal error: Declaration of Monorepo\Composer\EventDispatcher::dispatch($eventName, ?Composer\EventDispatcher\Event $event = null) must be compatible with Composer\EventDispatcher\EventDispatcher::dispatch(?string $eventName, ?Composer\EventDispatcher\Event $event = null): int in /home/marcosmarcolin/PhpstormProjects/Composer/vendor/beberlei/composer-monorepo-plugin/src/main/Monorepo/Composer/EventDispatcher.php on line 9
Fatal error: Declaration of Monorepo\Composer\EventDispatcher::dispatch($eventName, ?Composer\EventDispatcher\Event $event = null) must be compatible with Composer\EventDispatcher\EventDispatcher::dispatch(?string $eventName, ?Composer\EventDispatcher\Event $event = null): int in /home/marcosmarcolin/PhpstormProjects/Composer/vendor/beberlei/composer-monorepo-plugin/src/main/Monorepo/Composer/EventDispatcher.php on line 9
I repeat, in version 2.2.5 it works perfectly.
I'm waiting for a return.
Thank you very much in advance.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.