kalessil/production-dependencies-guard

防止将开发包添加到 require-section(应该是 require-dev)

安装: 929 669

依赖者: 2

建议者: 0

安全: 0

星标: 87

关注者: 6

分支: 2

开放问题: 4

类型:composer-plugin

dev-master 2021-06-11 06:14 UTC

This package is auto-updated.

Last update: 2024-09-11 13:01:18 UTC


README

防止开发包被添加到 require 中并进入生产环境。在实际应用中防止例如调试工具栏部署到生产环境中。

此外,您还可以配置保护器以拒绝缺少/不合适的许可证、废弃或描述中提及 debug 的包,并基于 composer.lock(更深入的分析)分析包。

安装

composer require --dev kalessil/production-dependencies-guard:dev-master

配置

在顶级 composer.json 文件中可以启用额外的保护器检查

{
    "name": "...",

    "extra": {
        "production-dependencies-guard": [
            "check-lock-file",
            "check-description",
            "check-license",
            "check-abandoned",
            
            "white-list:vendor/package-one",
            "white-list:vendor/package-two",
            
            "accept-license:MIT",
            "accept-license:proprietary"
        ]
    }
}
  • white-list:... 将包添加到白名单,即使违反规定也不会报告
  • check-lock-file 使用 composer.lock 而不是 composer.json,允许更深入的依赖分析
  • check-description 启用描述和关键词分析(搜索 debug),允许检测自定义开发包
  • check-abandoned 启用废弃包检查
  • check-license 启用许可证检查(包必须提供许可证信息)
  • accept-license:... 指定应接受哪些许可证(如果省略设置,则接受任何许可证,包括专有许可证)

用法

当包添加到您的 composer.json 文件的 require-dev 部分时("kalessil/production-dependencies-guard": "dev-master"),它将 阻止将开发包添加到 require 部分。由于开发包没有安全保证(不是为生产使用而设计的,仅用于开发目的),这也提高了您应用程序的安全性。

composer require --dev kalessil/production-dependencies-guard:dev-master

composer require phpunit/phpunit:*
# it should be `composer require --dev phpunit/phpunit:*` here

将会引发错误(获利!)

./composer.json has been updated

Installation failed, reverting ./composer.json to its original content.

[RuntimeException]                                                                   
  Dependencies guard has found violations in require-dependencies (source: manifest):  
   - phpunit/phpunit: dev-package-name

稳定性

此包仅在其 dev-master 版本中可用:根据包的目的。