尝试在 TYPO3 中通过 composer 安装我自己的扩展

Try to install my own extension via composer in TYPO3

我使用 TYPO3 CMScomposer 的第一步...但是我无法安装自己的分发包。尝试:

composer require stsa/hellotypo3

我遇到了这个错误:

[InvalidArgumentException]                                                                                           
 Could not find a version of package stsa/hellotypo3 matching your minimum-stability (stable). Require it with an explicit version constraint allowing its desired stability.

我已经通过 Composer 安装了 TYPO3 9.5.1 并且(为了测试)安装了第三方扩展,例如 maskcomposer require mask/mask。它完美运行。

这是我的 composer.json 分发扩展,我已经上传到 packgist。 json-文件有效,但必须有某物。错了..

{
    "name": "stsa/hellotypo3",
    "type": "typo3-cms-extension",
    "description": "FLUID Templates & TypoScript",
    "homepage": "https://www.hello.de/",
    "keywords": [
        "TYPO3",
        "CMS",
        "extension"
    ],
    "authors": [
        {
            "name": "Stsa",
            "email": "contact@hello.de",
            "role": "Developer",
            "homepage": "https://www.hello.de/"
        }
    ],
    "license": [
        "GPL-2.0-or-later"
    ],
    "require": {
        "typo3/cms-core": "^9.5"
    },
    "autoload": {
        "psr-4": {
            "Stsa\Hellotypo3\": "Classes/"
        }
    },
    "replace": {
        "hellotypo3": "self.version",
        "typo3-ter/hellotypo3": "self.version"
    }
}

不可能..它不适合那个。我也尝试设置 "minimum-stability": "stable"。但老实说,我不知道我能做什么..?!有人能帮我吗?谢谢。

编辑 1:今天我在 packgist 更新了我自己的扩展。 vendor/name.

现在必须可用

编辑 2:现在我通过 sitepackagebuilder 进行了测试扩展,上传到 git,提交给 packgist。尝试通过 composer require hellotypo3de/hellotest 安装 .. 仍然是相同的错误警告:Could not find a version of package hellotypo3de/hellotest matching your minimum-stability (stable). Require it with an explicit version constraint allowing its desired stability. ..?!我的错误在哪里?

"require": {
        "typo3/cms-core:^9.5"
    },

有用吗?如果不是很抱歉,但希望对您有所帮助

我假设您只想在一个安装中使用您的扩展程序作为本地扩展程序。这就是要走的路:

  1. 创建一个目录,例如packages 在项目的根目录中。

  2. 将您的扩展程序移至此目录并将文件夹命名为 stsa-hellotypo3。破折号前的部分是你的命名空间,包名后面的部分。

  3. 将以下条目添加到您的扩展程序的 composer.json 中:

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

    现在TYPO3将使用stsa_hellotypo3作为扩展键。

  4. 在您的 TYPO3 项目根目录中更改 composer.json 文件 repositories 条目:

    "repositories": [
        {
            "type": "path",
            "url": "packages/*"
        },
        {
            "type": "composer",
            "url": "https://composer.typo3.org/"
        }
    ],
    

    composer 现在将在 packages 文件夹中寻找要安装的包。

  5. 现在您可以将扩展添加到项目中:

    composer require stsa/hellotypo3:@dev
    

    扩展在 typo3conf/ext/ 目录中被符号链接为 stsa_hellotypo3。使用 @dev 安装开发版本(你有)。您还可以在扩展的 composer.json 文件中添加一个版本条目,然后您可以省略 @dev.

如果您这样做,则不必将扩展程序的自动加载信息添加到根 composer.json 文件中。

可以手动安装本地分发扩展。您必须在 "require-section" 处插入您的扩展,并在您的根目录 composer.json 中的 "repositories-section" 处添加一个新类型的包。看我的例子:

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://composer.typo3.org/"
        },
        {
            "type":"package",
            "package": {
              "name": "stsa/hellotypo3",
              "version":"master",
              "source": {
                  "url": "https://github.com/name/hellotypo3-distribution.git",
                  "type": "git",
                  "reference":"dev-master"
                }
            }
        }
    ],
    "name": "typo3/cms-base-distribution",
    "description" : "TYPO3 CMS Base Distribution",
    "license": "GPL-2.0-or-later",
    "config": {
        "platform": {
            "php": "7.2"
        }
    },
    "require": {
        "helhum/typo3-console": "^5.5.5",
        "typo3/minimal": "^9.5",
        "typo3/cms-about": "^9.5",
        "typo3/cms-adminpanel": "^9.5",
        "typo3/cms-belog": "^9.5",
        "typo3/cms-beuser": "^9.5",
        "typo3/cms-felogin": "^9.5",
        "typo3/cms-fluid-styled-content": "^9.5",
        "typo3/cms-form": "^9.5",
        "typo3/cms-impexp": "^9.5",
        "typo3/cms-info": "^9.5",
        "typo3/cms-redirects": "^9.5",
        "typo3/cms-reports": "^9.5",
        "typo3/cms-rte-ckeditor": "^9.5",
        "typo3/cms-setup": "^9.5",
        "typo3/cms-seo": "^9.5",
        "typo3/cms-sys-note": "^9.5",
        "typo3/cms-t3editor": "^9.5",
        "typo3/cms-tstemplate": "^9.5",
        "typo3/cms-viewpage": "^9.5",
        "stsa/hellotypo3": "dev-master"
    },
    "scripts":{
        "typo3-cms-scripts": [
            "typo3cms install:fixfolderstructure",
            "typo3cms install:generatepackagestates"
        ],
        "post-autoload-dump": [
            "@typo3-cms-scripts"
        ]
    },
    "extra": {
        "typo3/cms": {
            "cms-package-dir": "{$vendor-dir}/typo3/cms",
            "web-dir": "public"
        }
    }
}

dev-master这里很重要!

您的扩展程序中的 composer.json 如下所示:

{
    "name": "stsa/hellotypo3",
    "type": "typo3-cms-extension",
    "description": "FLUID Templates & TypoScript",
    "homepage": "https://www.hellotypo3.de/",
    "keywords": [
        "TYPO3",
        "CMS",
        "extension"
    ],
    "authors": [
        {
            "name": "StSa",
            "email": "hello@hellotypo3.de",
            "role": "Developer",
            "homepage": "https://www.hellotypo3.de/"
        }
    ],
    "license": [
        "GPL-2.0-or-later"
    ],
    "require": {
        "typo3/cms-core": "^9.5"
    },
    "autoload": {
        "psr-4": {
            "Stsa\Hellotypo3\": "Classes/"
        }
    },
    "replace": {
        "hellotypo3": "self.version",
        "typo3-ter/hellotypo3": "self.version"
    },
    "extra": {
        "typo3/cms": {
            "extension-key": "hellotypo3"
        }
    }
}

或者你可以从 packgist 安装你的扩展,但不要忘记:

composer require stsa/hellotypo3:master-dev@dev

composer req stsa/hellotypo3:@dev