我想做什么
我正在尝试使用Composer管理Drupal 8及其模块。以下是我想做的:
- 尽可能使用模块/库的最新稳定版本,除非在少数情况下我明确声明其他情况。
(为什么? 因为偶尔 Drupal 模块的稳定版本会损坏,但它在 dev
中是固定的,所以在这些情况下,我只需要dev
版本,直到新版本发布。
这是我composer.json
的一个例子:
"require": {
"composer/installers": "^1.0.21@stable",
"wikimedia/composer-merge-plugin": "~1.3@stable",
"cweagans/composer-patches": "~1.0@stable",
"behat/mink-selenium2-driver": "^1.3@stable",
"drupal/drupal-extension": "^3.1@stable",
"drupal/bootstrap": "8.3.*@dev",
"drupal/address": ">=8.1.0-beta2@beta",
"drupal/advagg": ">=8.2.0-beta2@beta",
},
"replace": {
"drupal/core": "~8.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
我想要 Bootstrap 的开发版本("drupal/bootstrap": "8.3.*@dev"
),但因为我设置了 prefer-stable: true
,所以我得到了最新的 Bootstrap alpha,而不是开发版本。
如果我设置prefer-stable: false
,那么所有的依赖项都会切换到开发版本(Symfony,Twig等)。
我阅读了这篇关于作曲家版本控制的文章,但我找不到解决问题的方法。
编辑:请注意,此composer.json
需要Drupal packagist存储库:
"repositories": [
{
"type": "composer",
"url": "https://packagist.drupal-composer.org"
}
],
以下是完整的composer.json
:
{
"name": "drupal/drupal",
"description": "Drupal is an open source content management platform powering millions of websites and applications.",
"type": "project",
"license": "GPL-2.0+",
"version": "8.0.3",
"repositories": [
{
"type": "composer",
"url": "https://packagist.drupal-composer.org"
}
],
"require": {
"composer/installers": "^1.0.21",
"wikimedia/composer-merge-plugin": "~1.3",
"cweagans/composer-patches": "~1.0",
"behat/mink-selenium2-driver": "^1.3",
"drupal/drupal-extension": "^3.1",
"drupal/address": "8.1.0-beta2",
"drupal/advagg": "8.2.0-beta2",
"drupal/bootstrap": "8.3.*@dev"
},
"replace": {
"drupal/core": "~8.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"preferred-install": "dist",
"autoloader-suffix": "Drupal8"
},
"extra": {
"_readme": [
"By default Drupal loads the autoloader from ./vendor/autoload.php.",
"To change the autoloader you can edit ./autoload.php."
],
"merge-plugin": {
"include": [
"core/composer.json"
],
"recurse": false,
"replace": false,
"merge-extra": false
},
"patches": {
"drupal/smtp": {
"Remove install config" : "https://www.drupal.org/files/issues/remove_install-2651434-2.patch"
}
}
},
"autoload": {
"psr-4": {
"Drupal\Core\Composer\": "core/lib/Drupal/Core/Composer"
}
},
"scripts": {
"pre-autoload-dump": "Drupal\Core\Composer\Composer::preAutoloadDump",
"post-autoload-dump": "Drupal\Core\Composer\Composer::ensureHtaccess",
"post-package-install": "Drupal\Core\Composer\Composer::vendorTestCodeCleanup",
"post-package-update": "Drupal\Core\Composer\Composer::vendorTestCodeCleanup"
}
}
首先,您作为示例给出的composer.json
无效:
- 不允许
- 在节的最后一行使用逗号。
-
drupal/bootstrap
,drupal/address
和drupal/advagg
在Packagist找不到。
实现以下目标
尽可能使用模块/库的最新稳定版本,除非在少数情况下我明确声明其他情况。
您只需要设置"minimum-stability": "stable"
这意味着仅获取稳定版本。并将 @dev
标志用于您提到的明确少数情况。 在这种情况下不需要prefer-stable
。
让我们以以下composer.json
为例。这将仅安装所列软件包的稳定版本:
{
"require": {
"composer/installers": "^1.0.21",
"wikimedia/composer-merge-plugin": "~1.3",
"cweagans/composer-patches": "~1.0",
"behat/mink-selenium2-driver": "^1.3",
"drupal/drupal-extension": "^3.1",
},
"minimum-stability": "stable"
}
如果您现在将require
部分的第一行从
"composer/installers": "^1.0.21",
自
"composer/installers": "^1.0.21@dev",
它将仅安装除 composer/installers
之外的所有列出的软件包的稳定版本。由于 @dev
标志覆盖"minimum-stability": "stable"
因此将仅下载此包的开发版本。
Drupal Packagist 的另一个最小示例:
{
"require": {
"composer/installers": "^1.0.21",
"wikimedia/composer-merge-plugin": "~1.3",
"cweagans/composer-patches": "~1.0",
"behat/mink-selenium2-driver": "^1.3",
"drupal/drupal-extension": "^3.1",
"drupal/bootstrap": "8.3.*@dev"
},
"replace": {
"drupal/core": "~8.0"
},
"minimum-stability": "stable",
"repositories": [
{
"type": "composer",
"url": "http://packagist.drupal-composer.org"
}
]
}
我只用上面的composer.json
使用了一个空文件夹,我跑composer install
.(对于您的项目,您可以在运行 composer install
之前完全删除 vendor/
文件夹并删除composer.lock
。之前做备份!
它安装了最新的开发版本的drupal/bootstrap
,您可以从下面的控制台输出中看到:
- Installing drupal/bootstrap (dev-8.x-3.x 6a37bf5) Cloning 6a37bf5977c54dde4fe58f40118a8c71ce7e145a
如果将已安装版本的哈希6a37bf5977c54dde4fe58f40118a8c71ce7e145a
与 http://cgit.drupalcode.org/bootstrap/log/的源代码进行比较,您可以看到它安装了最新版本(此时Issue #2672514 by neardark: update documentation
)。