尝试通过TYPO3中的Composer安装自己的扩展

7

我开始学习使用 TYPO3 CMScomposer ... 但是我无法安装自己的分发包。请尝试以下步骤:

composer require stsa/hellotypo3

I've got this error:

[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,并且(为了测试)使用“composer require mask/mask”安装了第三方扩展程序“mask”。它完美地工作。
以下是我上传到packgist的分发扩展的composer.json。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. 我错在哪里了?

3个回答

8

我猜你想要将你的扩展程序作为本地扩展程序仅在一个安装上使用。那么这就是正确的方法:

  1. Create a directory, e.g. packages in your project's root directory.

  2. Move your extension into this directory and name the folder stsa-hellotypo3. The part before the dash is your namespace, the part behind the package name.

  3. Add to your composer.json of your extension the following entry:

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

    Now TYPO3 will use stsa_hellotypo3 as extension key.

  4. Change into your composer.json file in your TYPO3 project root the repositories entry:

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

    composer will look now into the packages folder for packages to install.

  5. Now you can add your extension to the project:

    composer require stsa/hellotypo3:@dev
    

    The extension is symlink'ed as stsa_hellotypo3 in typo3conf/ext/ directory. With the @dev the development version is installed (which you have). you can also add a version entry into your extension's composer.json file, then you can omit the @dev.

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


嗨Chris,今天我已将我的分发包上传到Packgist。https://packagist.org/packages/stsa/hellotypo3?query=hellotypo3。我稍后会尝试它,并参照您的教程,感谢这个时刻。但是,我的composer.json文件正确吗?或者为什么总是出现最小稳定性问题? - user2310852
嗨,Chris,本地安装无法正常工作:Could not find a matching version of package stsa/hellotypo3@dev. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stable). 现在我已经更新了我的分发扩展包,并尝试通过 composer require stsa/hellotypo3 进行安装,但这也失败了..? 我仍然在寻求帮助,以从 packgist 或 github 安装自己的扩展。 - user2310852
如果您的本地composer.json中没有版本,则假定为dev版本。如果您的存储库中没有标签(这是packagist的版本),则也被视为dev版本。因此,如果您查看packagist包,则会发现唯一的版本是dev-master。您可以使用版本“@dev”或“master-dev@dev”来表示您想要的开发版本,而不必全局设置minimum-stability属性。使用composer req stsa/hellotypo3:@dev - Chris
就是这样。谢谢Chris。这些信息应该放在https://composer.typo3.org/上。 - user2310852

3

您可以手动安装本地发行版扩展。您需要在“require-section”中插入扩展,并在您的存储库根目录下的“repositories-section”中添加一个新的包类型composer.json。请参考我的示例:

{
    "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

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

这个可行吗?如果不行抱歉,但希望能帮到你


嗨Rustyjim,感谢你的帮助。不,你的回答并没有帮到我。在此之后,composer.json就不再有效了。我正在查看其他扩展中的composer文件,它看起来和我的一样?! - user2310852

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接