嵌套包的 Composer 运行脚本

adi*_*div 8 git composer-php

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

我的作曲家.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"
	}
}
Run Code Online (Sandbox Code Playgroud)

问题在于scripts嵌套包的运行顺序,所有脚本都被 Composer 忽略。

谢谢!

Tom*_*uba 9

不幸的composer.json,如文档中所述,无法执行任何非 ROOT脚本(即非 root 用户):

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


Pet*_*ter 5

正如 Tomas 所说,不可能自动调用非 ROOT 脚本。但您可以允许用户手动调用它们。这并不适用于所有情况,但在其他情况下却很好。

如果您有以下内容vendor/johndoe/mypackage/composer.json

"scripts": {
    "nameOfScript": "\\johndoe\\mypackage\\Scripts::invoke"
}
Run Code Online (Sandbox Code Playgroud)

composer.json您的根目录中放置以下内容:

"scripts": {
    "myFancyScript": [
        "@putenv COMPOSER=vendor/johndoe/mypackage/composer.json",
        "@composer nameOfScript"
    ]
}
Run Code Online (Sandbox Code Playgroud)

然后用户可以从根目录调用并执行包中的composer myFancyScript静态函数。invoke()johndoe/mypackage