• Stars
    star
    305
  • Rank 136,879 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 9 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Integrates Composer into monolithic repositories with many packages.

Composer Monorepo Plugin

Note: this project is still experimental. Please provide feedback!

This plugin adds support for Monorepos when using Composer package manager. It introduces a maintainable approach to managing dependencies for multiple packages in a single repository, without losing the benefits of having explicit dependencies for each separate package.

Repositories managed with this plugin contain two kinds of packages:

  1. Composer packages defined by a single global composer.json with all external dependencies at the root of the repository.
  2. Many monorepo packages in sub-folders of the project, each with its own monorepo.json, a simplified composer.json file.

Dependencies in monorepos can be either a third party Composer package that is listed in the composer.json or a monorepo package contained in the project.

This plugins build step generates autoloaders with vendor/autoload.php files for each package with access to the explicitly specified dependencies only.

The following steps are performed by this plugin when building the autoloads:

  1. It detects monorepo.json files in subdirectories excluding vendor/ and marks them as roots of packages.
  2. It then fetches all composer packages from the locally installed packages.
  3. Finally for each package with monorepo.json it generates a vendor/autoload.php file using all the dependencies defined in that package from either other monorepo packages or regular Composer packages.

This plugin draws inspiration from Google Blaze/Bazel and Facebook Buck implementing a single monolithic repository for whole projects/company. It's the missing piece for the monolithic repository workflow using PHP and Composer.

More details about reasoning on Gregory Szorc's blog:

Backwards Incompatible Changes in v0.12

In v0.12 we removed the fiddler script and the possibility to build a PHAR archive. This project is now a first-class composer plugin only and requires Composer v1.1+ for the composer monorepo: commands to be available.

The fiddler.json files must be renamed to monorepo.json.

Use v0.11.6 or lower if you don't want to break this in your project yet.

Installation

Add the composer monorepo plugin to your root composer.json with:

$ composer require beberlei/composer-monorepo-plugin

It will be automatically added as a Composer plugin.

Usage

Whenever Composer generates autoload files (during install, update or dump-autoload) it will find all sub-directories with monorepo.json files and generate sub-package autoloaders for them.

You can execute the autoload generation step for just the subpackages by calling:

$ composer monorepo:build

You create a composer.json file in the root of your project and use this single source of vendor libraries across all of your own packages.

This sounds counter-intuitive to the Composer approach at first, but it simplifies dependency management for a big project massively. Usually if you are using a composer.json per package, you have mass update sprees where you upate some basic library like "symfony/dependency-injection" in 10-20 packages or worse, have massively out of date packages and many different versions everywhere.

Then, each of your own package contains a monorepo.json using almost the same syntax as Composer:

{
    "deps": [
        "components/Foo",
        "vendor/symfony/symfony"
    ],
    "autoload": {
        "psr-0": {"Foo\\": "src/"}
    }
}

You can then run composer dump-autoload in the root directory next to composer.json and this plugin will detect all packages, generate a custom autoloader for each one by simulating composer dump-autoload as if a composer.json were present in the subdirectory.

This plugin will resolve all dependencies (without version constraints, because it is assumed the code is present in the correct versions in a monolithic repository).

Package names in deps are the relative directory names from the project root, not Composer package names.

You can just require "vendor/autoload.php; in every package as if you were using Composer. Only autoloads from the monorepo.json are included, which means all dependencies must be explicitly specified.

Configuration Schema monorepo.json

For each package in your monolithic repository you have to add monorepo.json that borrows from composer.json format. The following keys are usable:

  • autoload - configures the autoload settings for the current package classes and files.
  • autoload-dev - configures dev autoload requirements. Currently always evalauted.
  • deps - configures the required dependencies in an array (no key-value pairs with versions) using the relative path to the project root directory as a package name.
  • deps-dev - configures the required dev dependencies
  • replace - configures the packages's replacements.

Git Integration for Builds

In a monorepo, for every git commit range you want to know which components changed. You can test with the git-changed? command:

composer monorepo:git-changed? components/foo $TRAVIS_COMMIT_RANGE
if [ $? -eq 0 ]; then ant build fi

More Repositories

1

assert

Thin assertion library for use in libraries and business-model
PHP
2,407
star
2

DoctrineExtensions

A set of Doctrine 2 extensions
PHP
1,956
star
3

litecqrs-php

Small convention based CQRS library for PHP
PHP
553
star
4

metrics

Simple library that abstracts different metrics collectors. I find this necessary to have a consistent and simple metrics (functional) API that doesn't cause vendor lock-in.
PHP
316
star
5

porpaginas

A simple abstraction for paginated and non-paginated results
PHP
159
star
6

AcmePizzaBundle

Acme Form Experimental Bundle
PHP
131
star
7

php-rfc-watch

Interactive voting results for PHP RFC process.
HTML
127
star
8

zf-doctrine

A Zend Framework 1.x and Doctrine 1.2 Integration - UNMAINTAINED
PHP
102
star
9

netbeans-php-enhancements

Netbeans PHP Enhancements, such as PHP Code Sniffer Support
Java
102
star
10

fastcgi-serve

Small webserver to use in front of fast-cgi servers (php-fpm, hhvm, ...)
Go
92
star
11

symfony-minimal-distribution

This contains the code from my blog post http://whitewashing.de/2014/10/26/symfony_all_the_things_web.html
PHP
67
star
12

bankaccount

Sample application used for PHPUnit training.
PHP
46
star
13

vim-php-refactor

Some simple vim refactoring functions for your PHP code
Vim Script
40
star
14

xdebug-trace-gui

Fork of Trace GUI by Thomas Hambach
PHP
35
star
15

license-manager

License Switch Project - Helping open source projects to switch licenses
CSS
34
star
16

Doctrine-Workflow

A Doctrine 2 persistence layer for ezcWorkflow
PHP
33
star
17

DoctrineCodeGenerator

Prototype of an AST based Event Driven CodeGenerator
PHP
31
star
18

http-client-middleware

Missing interfaces for HTTP-Client middlewares using PSR-7 messages.
PHP
28
star
19

Doctrine-ActiveEntity

ActiveRecord ORM (Mod) on top of Doctrine2
PHP
25
star
20

env

PHP PECL extension for loading 12factor env variables from a file
C
24
star
21

Whitewashing

Symfony2 Bundle that powers the www.whitewashing.de blog
PHP
23
star
22

azure-blob-storage

Small platform-independent library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
PHP
22
star
23

WhitewashingZFMvcCompatBundle

PHP
21
star
24

zelten

A social network website based on tent.io protocol
JavaScript
17
star
25

TentPHP

A Tent.io client written in PHP
PHP
16
star
26

githubpr_to_jira

Converts Github PR to Jira Issues
PHP
16
star
27

pearanha

Pearanha is deprecated, use Composer intead
PHP
15
star
28

context

DEPRECATED
PHP
15
star
29

WhitewashingLogglyBundle

loggly.com logger for Monolog integrated into Symfony2 - not really maintained anymore
PHP
15
star
30

php-compiletime-poc

Extension that counts the time spent in PHP file compilation during the execution of a script
C
13
star
31

php-ast-tracer-poc

C
13
star
32

doctrine-example-app

Example App Setup for Training/Workshops
PHP
13
star
33

dbdeploy-php

DBDeploy PHP clone
PHP
12
star
34

ZendNavigationBundle

A Zend Navigation Bundle for Symfony2
PHP
11
star
35

phpricot

A forgiving HTML Parsing library written in PHP
PHP
11
star
36

hdrhistogram-php

A PHP extension wrapper for the C hdrhistogram API.
C
10
star
37

symfony-azure-edition

Symfony2 on Windows Azure Edition
PHP
10
star
38

ReviewSquawkBundle

Symfony2 app that provides a static-code-analysis as a service platform
JavaScript
9
star
39

ZetaBundle

A Zeta Components Bundle for Symfony2
PHP
8
star
40

websocket-proxy-example

Example Go microservice that acts as a Websocket proxy for other server applications
Go
6
star
41

stdlib

Some fun
PHP
6
star
42

compilefile-ext

C
5
star
43

php8-benchmark-doctrine

PHP
5
star
44

Zend_Db-Adapter-for-ext-mysql

Legacy applications often work with ext/mysql all over the place. This Zend_Db adapter allows to share the resources and benefit from Zend_Db.
PHP
5
star
45

ZetaWorkflowCouchDB

Zeta Components CouchDB Backend for Workflow
PHP
4
star
46

php-overload-poc

C
4
star
47

php-couch-content-repository

PHP
3
star
48

flow3-doctrine2

prototype hack for doctrine2 as persistence manager for flow3
PHP
3
star
49

funcall

Fork of the pecl extension "funcall"
C
3
star
50

redmine_gherkinviewer

Redmine Plugin: Display feature files from project repository directly in a "Features" tab in the project.
Ruby
3
star
51

AzureTaskDemoBundle

Demo bundle for Azure Functionality with a Symfony+Doctrine application
JavaScript
2
star
52

beberlei

1
star
53

deprecations

PHP
1
star
54

pecl_http

PHP
1
star
55

cj-push-server

PubSubHubBub Server in Clojure
Clojure
1
star
56

interrupt-sampler-poc

C
1
star
57

hdrhistogram-php-stubs

Adding support for hdrhistogram in IDEs and Scrutinizer
PHP
1
star