4

I've created my yii2 extension. I keep it on my private git server. I managed the extension to be downloaded through composer using following code:

"repositories": [
    {
        "type": "package",
        "package": {
            "name": "author/yii2-user",
            "version": "dev-master",
            "source": {
                "url": "ssh://[email protected]/srv/git/user.git",
                "type": "git",
                "reference": "origin/master"
            }
        }
    }
],

and "author/yii2-user": "*", in require section. It all works fine but there is one problem. After downloading extension, composer should add it to the yiisoft\extension.php file but it's not being added.

In my extension I have composer.json file like this:

{
"name": "author/yii2-user",
"description": "Auth and user manager for our apps",
"keywords": ["yii", "admin", "auth"],
"type": "yii2-extension",
"support": {
    "issues": "",
    "source": ""
},
"authors": [
    {
        "name": "j2",
        "email": "[email protected]"
    }
],
"require": {
    "yiisoft/yii2": "*",
    "yiisoft/yii2-bootstrap": "*"
},
"autoload": {
    "psr-4": {
        "author\\user\\": ""
    }
}

}

I'm trying to find a solution but it's a hard one.

1 Answer 1

9

Don't use the "type": "package" repository if you have the source code under your own control. Every info you have to add there can be figured out by Composer itself if you use the "type": "vcs" repository and give the URL of the source code server.

The correct way would be:

"repositories": [
    {
        "type": "vcs",
        "url": "ssh://[email protected]/srv/git/user.git"
    }
],

The Composer scans this repository for a composer.json, parses it and then knows all the metadata like name, type (probably important if you want to install it as a yii extension), version or branch etc.

The package type does only exist to allow anybody who needs one particular software which is not maintained anymore and therefore a missing composer.json will never be added and/or registration at packagist.org will never be happening to substitute this lack of information. Don't use it for your own software, ever.

Sign up to request clarification or add additional context in comments.

1 Comment

I changed vcs to git to make it more accurate. Thanx!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.