澄清 composer.json 中 TYPO3 扩展的替换和额外部分

Clarification of replace and extra sections in composer.json for TYPO3 extensions

更新2020 年 8 月 17 日):部分 "my_ext_key": "self.version" 不再出现在较新的示例或 helhum/composer.json。请参阅下面的说明。


周围有几个 composer.json 的 TYPO3 示例。有些包括一个替换部分,内容如下:


替换为:

"replace": {
    "my_ext_key": "self.version",
    "typo3-ter/my-ext-key": "self.version"
},

"replace": {
    "vendorname/my-extension": "self.version",
    "typo3-ter/my-extension": "self.version"
},

https://wiki.typo3.org/Composer#Extension_key_.2F_composer_name

和/或额外部分

"extra": {
    "typo3/cms": {
        "extension-key": "extension_key"
    }
}

这些部分何时需要,它们的作用是什么以及推荐的内容(对于 TYPO3 扩展)?特定于这些部分的 TYPO3 版本之间是否存在差异?


具体来说:

  1. 替换示例中的第二行

    "typo3-ter/my-ext-key": "self.version"
    

    例如,如果扩展在 TER 中发布并且是 可以从 composer.typo3.org 获得,我猜。如果扩展只是 可通过 packagist 获得,包含它并没有真正的意义。

  2. 关于第一行replace,什么时候需要,它有什么作用?

    "my_ext_key": "self.version",
    

    通常,替换它用于替换一些其他包,例如作为替代品,例如 here. This section was available in a previous example composer.json but has now been removed (see helhum/composer.json). Also, it would now cause a warning on composer validate, see also comment。旧的 TYPO3 版本是否仍然需要它?

  3. 额外部分将扩展键(带下划线)映射到包名称(带破折号)。但是,这已经是默认设置。那么,什么时候需要或可以将其完全删除?

official composer documentation for replace 所述:

Lists packages that are replaced by this package. This allows you to fork a package, publish it under a different name with its own version numbers, while packages requiring the original package continue to work with your fork because it replaces the original package.

This is also useful for packages that contain sub-packages, for example the main symfony/symfony package contains all the Symfony Components which are also available as individual packages. If you require the main package it will automatically fulfill any requirement of one of the individual components, since it replaces them.

Caution is advised when using replace for the sub-package purpose explained above. You should then typically only replace using self.version as a version constraint, to make sure the main package only replaces the sub-packages of that exact version, and not any other version, which would be incorrect.

更多 TYPO3 related explanation of the composer.json replace property Helhum 提供了解释:

The replace property MUST be provided if the composer package name part does not match the extension name and is highly recommended thus SHOULD be provided in any case. If it is provided, the first replace value MUST match exactly the extension key and the second replace value SHOULD match the TER package key (extension key prefixed with “typo3-ter/” and with underscores (_) replaced with dashes (-). The version constraint MUST exactly be self.version

有关其他信息,请点击链接,因为它们包含更多信息。