jeichorn/composer-monorepo-plugin 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jeichorn/composer-monorepo-plugin

Composer 安装命令:

composer require jeichorn/composer-monorepo-plugin

包简介

README 文档

README

Build Status

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:

Forked

This is a forked version of the original https://github.com/beberlei/composer-monorepo-plugin, since it was no longer under active development

Installation

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

$ composer require jeichorn/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
  • bin-deploy-method - symlink|copy, the standard method symlink, deploys vendor/bin scripts as symlinks to the parent vendor/bin. This breaks cases where you want to use the autoload ands its dependencies in a child repo. Copy copies the bins into vendor/bin in the child and then symlinks them so standard script discovery works.

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

jeichorn/composer-monorepo-plugin 适用场景与选型建议

jeichorn/composer-monorepo-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 96.5k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 06 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 jeichorn/composer-monorepo-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jeichorn/composer-monorepo-plugin 我们能提供哪些服务?
定制开发 / 二次开发

基于 jeichorn/composer-monorepo-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 96.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 43
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-06-14