【问题标题】:Composer run-script of nested packages嵌套包的 Composer 运行脚本
【发布时间】:2018-03-27 21:51:57
【问题描述】:

我有没有代码但有依赖列表的作曲家项目。我想运行composer install 来下载所有依赖包,然后在每个包中运行一些 bash 命令。

我的 composer.json:

{
	"name": "testmain/testmain",
	"description": "testmain",
	"minimum-stability": "dev",
	"repositories": [{
			"type": "package",
			"package": {
				"name": "testsub/testsub1",
				"description": "testsub/testsub1",
				"version": "master",
				"source": {
					"url": "https://github.com/testsub/testsub1",
					"type": "git",
					"reference": "master"
				},
				"scripts": {
					"post-install-cmd": [
						"make",
						"make install"
					]
				}
			}
		},

		{
			"type": "package",
			"package": {
				"name": "testsub/testsub2",
				"description": "testsub/testsub2",
				"version": "master",
				"source": {
					"url": "https://github.com/testsub/testsub2",
					"type": "git",
					"reference": "master"
				},
				"scripts": {
					"post-install-cmd": [
						"make",
						"make install"
					]
				}
			}
		}
	],
	"require": {
		"testsub/testsub1": "master",
		"testsub/testsub2": "master"
	}
}

问题在于运行scripts 嵌套包序列,所有脚本都被作曲家忽略。

谢谢!

【问题讨论】:

标签: git composer-php


【解决方案1】:

正如 Tomas 所说,自动调用非 ROOT 脚本是不可能的。但是您可以让用户手动调用它们。这并非适用于所有情况,但适用于其他情况。

如果你在vendor/johndoe/mypackage/composer.json中有以下内容:

"scripts": {
    "nameOfScript": "\\johndoe\\mypackage\\Scripts::invoke"
}

在根目录的composer.json 中放入以下内容:

"scripts": {
    "myFancyScript": [
        "@putenv COMPOSER=vendor/johndoe/mypackage/composer.json",
        "@composer nameOfScript"
    ]
}

然后用户可以从你的根目录调用composer myFancyScript,并执行包@​​987654327@中的静态函数invoke()

【讨论】:

    【解决方案2】:

    不幸的是,不可能执行任何非ROOT脚本(即非root composer.json),如documentation中所述:

    注意:仅执行根包的 composer.json 中定义的脚本。如果根包的依赖项指定了它自己的脚本,Composer 不会执行那些额外的脚本。

    【讨论】:

      猜你喜欢
      • 2014-02-10
      • 1970-01-01
      • 2016-02-06
      • 2023-03-29
      • 2012-10-16
      • 1970-01-01
      • 2013-06-17
      • 2016-11-16
      相关资源
      最近更新 更多