1

I am trying to create a custom vendor package but have not yet put the package on packagist. According to the docs, the package can be loaded from git (vcs) instead of packagist: https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository

The yii2 project (although don't think framework matters) I have created package inside vendor folder:

foundationize/yii2-foundation (folder structure is as above, I have quadruple-checked).

My root public_html/composer.json has following entries:

"minimum-stability": "dev",
    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": ">=2.0.5",
        "yiisoft/yii2-swiftmailer": "*",
        "foundationize/yii2-foundation": "dev-master" 
    },

My package composer file, vendor/foundationize/yii2-foundation/composer.json looks like:

{
    "name": "foundationize/yii2-foundation",
    "description": "The Foundation extension for the Yii2 framework",
    "keywords": ["yii2", "foundation"],
    "type": "yii2-extension",
    "license": "BSD-3-Clause",
    "support": {
        "issues": "https://github.com/foundationize/yii2-foundation/issues",
        "wiki": "https://github.com/foundationize/yii2-foundation/wiki",
        "source": "https://github.com/foundationize/yii2-foundation.git"
    },
    "authors": [
        {
            "name": "gvanto",
            "email": "gvanto@hotmail.com",
            "homepage": "http://foundationize.com"
        }
    ],
    "require": {
        "yiisoft/yii2": "*"
    },
    "autoload": {
        "psr-4": {
            "foundationize\\foundation\\": ""
        }
    },
    "repositories": [
        {
            "packagist": false,
            "type": "vcs",
            "url": "https://github.com/foundationize/yii2-foundation.git"           
        }
    ]       
}

When I run composer install (or update), I keep getting error below:

Your requirements could not be resolved to an installable set of packages.

Problem 1 - The requested package foundationize/yii2-foundation could not be found in any version, there may be a typo in the package name.

Potential causes:

Read https://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

I have googled it high and low, read the docs can't seem to get it to work (always the same error, which I actually think would be more useful if it said either the package was not found OR the incorrect package version was found).

yivi
  • 42,438
  • 18
  • 116
  • 138
gvanto
  • 1,936
  • 3
  • 21
  • 26

3 Answers3

5

You have to add the repositories entry to your root composer.json file. Otherwise, Composer does not know where to search for your package.

xabbuh
  • 5,801
  • 16
  • 18
  • Thanks xabbuh this seemed to work better ... thank you! What I don't get is how (if the repositories source is in the root composer.json) composer knows which package to get from the vcs source and which from packagist? I only want the one package (foundationize/yii2-foundation) to be found on github (custom source), not the other packages .. – gvanto Jan 01 '16 at 00:41
  • Composer will only use other sources than Packagist for a package if you configured a repository that contains information about it and for which the version constraint is satisfied. So if you only add the GitHub repository for the `foundationize/yii2-foundation` package, all other packages will be loaded through Packagist. – xabbuh Jan 01 '16 at 09:19
  • "So if you only add the GitHub repository for the foundationize/yii2-foundation package" -> but i am not: I'm putting it in root - that's what I mean, since I'm specifying the 'repositories' field under the ROOT (not the package itself), how is this source tied/linked to this package? is it by name? Would have expected to be able to specify a (overridden if you will) source for a package in the package's composer.json file (not the root) ... sorry for confusion I don't think the composer docs are too clear about this – gvanto Jan 03 '16 at 20:57
  • What I meant is that the GitHub repository that you added to your `composer.json` file is https://github.com/foundationize/yii2-foundation.git which only defines the `foundationize/yii2-foundation`. Composer will clone that repository, check its `composer.json` file and therefore will know that this package is located in that repository (because of the `name` key in the configuration). – xabbuh Jan 03 '16 at 21:30
  • OK seems like a slightly reversed way of doing things (wouldn't it be easier if I told composer where to find the source for this package directly instead?) but I'm sure there's a reason they doing it that way. Thanks xabbuh for the help! – gvanto Jan 04 '16 at 22:01
1

Had a similar problem to this and it was because I was running composer in the /web directory in the new Drupal structure. When I ran it in the root all was fine. Annoyingly, you need to run Drush in /web

james-geldart
  • 709
  • 7
  • 9
0

Since Laravel version 5.5 there is a Package Auto-Discovery feature, so there is no need to add service provider. All you need to register package like this:

composer require barryvdh/laravel-debugbar:dev-master

You can find more info in these articles:

https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518 https://divinglaravel.com/laravels-package-auto-discovery

Uros
  • 2,099
  • 7
  • 23
  • 50