vaimo/composer-repository-bundle

允许从具有多个子文件夹的存储库或tarball包安装包

安装次数: 37,599

依赖者: 0

建议者: 0

安全: 0

星标: 9

关注者: 12

分支: 2

开放问题: 0

类型:composer-plugin

1.7.2 2022-05-04 14:26 UTC

README

Latest Stable Version Total Downloads Daily Downloads Minimum PHP Version License

允许从包含多个包或声明项目内部某些文件夹作为本地存储库的存储库或zip文件安装composer包。

简而言之:它消除了将每个本地包声明为PATH存储库的需要,并允许用户从远程.zip文件(通过下载它们并注册它们作为PATH存储库)安装东西。

有关最近更改的更多信息,请参阅这里

概述

可以在项目的composer.json中定义环境变量作为键值对。

{
    "_ignoreme": "this is the main level of composer.json",
  
    "extra": {
        "bundles": {},
        "bundles-package": {}
    }
}

这些值将声明为系统级使用。该模块的主要思想是在标志设置未适当暴露给最终用户的情况下,为任何composer插件提供预配置任何标志的方法。

快速入门

如果您想使本地文件夹表现得像是一个包存储库。

  1. require this plugin composer require vaimo/composer-repository-bundle
  2. 配置它(见上文)
  3. 在modules/mypackage下添加模块,并添加一个composer.json文件(假设composer.json中的包名为myvendor/module-mypackage)。
  4. 使用composer require myvendor/module-mypackage:dev-my-bundle安装它
{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": "modules"
        }
    }
}

安装将从声明的包中执行...

modules/module1
modules/module2
...

如果您想镜像文件而不是使用默认的sym-linked,请配置您的包的部署模式。

如果您计划将本地包分组到不同的子文件夹中,请使用路径定义中的通配符

配置:添加包定义

可以针对zip文件进行操作...

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": {
                "url": "https://github.com/magento-research/pwa-studio/archive/master.tar.gz"
            }
        }
    }
}

同样也可以针对存储库进行操作(在这种情况下,需要分支名称或更改集引用)

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": {
                "url": "git@github.com:magento-research/pwa-studio.git",
                "reference": "9c6dfcc955df4b88218cd6c0eb6d0260df27117d"
            }
        }
    }
}

配置:将本地目录作为存储库

该插件还可以用于配置本地项目内嵌的包文件夹,其中模块将变得可安装。

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": {
                "source": "modules"
            }
        }
    }
}

这允许任何模块从/modules安装。请注意,来自这种本地包的模块默认会使用符号链接而不是镜像,但可以通过定义安装模式来强制它们也进行镜像。有关如何从捆绑的存储库安装包的更多信息,请参阅安装指南

上述(由于它的最小化设置)也可以配置为

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": "modules"
        }
    }
}

配置:部署模式

默认情况下,模块会自行决定如何部署包。

  • symlink - 当包位于项目根目录下时进行(包是项目的一部分)。
  • mirror - 当包位于composer包缓存中时进行(包是全局composer的一部分)。

开发者可以通过在包配置中提供模式来覆盖此设置。

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": {
                "source": "modules",
                "mode": "mirror"
            }
        }
    }
}

配置:按供应商分组

默认情况下,将从您指向包的主级别路径包含所有包。这可以通过在路径定义中使用GLOB模式来更改。

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": {
                "source": "modules/*"
            }
        }
    }
}

此配置将使您能够定义以下格式的文件夹中的包...

modules/myvendor/module1
modules/myvendor/module2
modules/othervendor/module2
...

配置:定义包子文件夹作为存储库根目录

默认情况下,捆绑包存储库将把捆绑包主级别的每个子文件夹视为潜在的安装包,如果包存在于某个子文件夹中,则可以定义相对路径。

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": {
                "url": "https://github.com/magento-research/pwa-studio/archive/master.tar.gz",
                "paths": ["packages"]
            }
        }
    }
}

配置:包模板

如果捆绑包中的一些可安装的子文件夹不是直接可安装的(缺少composer.json),捆绑包插件将创建缺失的包定义。唯一的要求是包。

如果需要定义composer.json的特殊部分,可以在'extra-package'下声明,格式与声明正常包配置的格式相同。内容将用作生成的包定义的默认值。

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles-package": {
            "autoload": {
                "files": ["registration.php"]
            }
        }
    }
}

配置:捆绑包下载的自定义目标路径

如果您希望捆绑包下载到目录的根目录,请为它配置一个目标文件夹。

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "my-bundle": {
                "url": "https://github.com/magento-research/pwa-studio/archive/master.tar.gz",
                "paths": ["packages"],
                "target": "pwa-studio"
            }
        }
    }
}

请注意,在这种情况下,包安装将导致包被符号链接而不是镜像。

用法:从捆绑包安装包

在开始从注册的捆绑包安装包之前,请确保您已单独安装了此插件。

在composer.json中注册捆绑包后,用户可以像安装任何其他composer包一样安装它们。请注意,忽略包版本,使用dev-bundle。

composer require magento/theme-frontend-venia:'dev-my-bundle'

请注意,'composer require'命令有些特殊,添加模块到存储库时需要使用非版本字符串。

约束将根据捆绑包存储库名称生成,因此如果您想将包作为"dev-local"要求,请使用以下内容

{
    "_ignoreme": "this is the main level of composer.json",
    
    "extra": {
        "bundles": {
            "local": {
                "source": "modules"
            }
        }
    }
}

请注意,此配置将使用/modules文件夹作为捆绑包存储库,并且可以使用以下内容安装那里的包

composer require vaimo/some-package:'dev-local' 

用法:更新包

Composer运行将提供每个文件内容的MD5指纹,因此更新包(如果它没有被符号链接到vendor)。可以通过仅运行正常的composer update命令来完成。

composer update vaimo/some-package

开发:调试

如果包不能变成可安装的,建议开发者以详细模式运行require命令。

composer require vaimo/some-package:'dev-local' -vvv

这应该会显示类似于以下内容的输出(如果一切配置正确)

Registering package endpoints
  - Including vaimo/some-package (e9db459e445a5fa10d4c6ff264332815)
    ~ Bundle: local

如果在控制台输出中未看到类似的内容,则捆绑包文件夹中的包对Composer不可见。