Can't get composer “path” repository to work

2019-04-03 12:41发布

I have a directory structure like so:

composer.json < Main
  packages/
    balunker/
      testpackage/
        composer.json < Package
        src/
          TestPackage.php

The main composer.json looks like this:

{
    "name": "vagrant/composer-test",
    "repositories": [
        {
             "type": "path",
            "url": "packages/*/*"
        }
    ],
    "require": {
        "balunker/testpackage": "*"
    }
}

While the package composer.json looks like so:

{
  "name": "balunker/testpackage",
  "autoload": {
    "psr-4": {
      "Balunker\\": "src/"
    }
  }
}

On composer update I simple get a message that the package could not be resolved. No symlinks are created and no package is installed. I have literally spent half of my day figuring this out, without any success.

I also uploaded a composer update -vvv verbose output of this: http://pastebin.com/mMRHsACk.

My composer version is the latest (as of 20th of April 2016 at 2:39pm UTC) and all of this is running inside Vagrant (Debian).

ANY recommendation from hereon is greatly appreciated. I really don't know what else to do any more.

3条回答
Anthone
2楼-- · 2019-04-03 13:20

What worked for me was very similar to the above, but I had to specifically target the branch I was developing on.

Assuming code in directory /newapp on the same level as /app, and a branch named feature/the-new-package:

"repositories": [
  {
    "type": "path",
    "url": "newapp"
  }
],
"require": {
  "package/newapp": "dev-feature/the-new-package"
},

\* did not work, neither did dev-master. It had to be dev-feature/the-new-package.

查看更多
何必那么认真
3楼-- · 2019-04-03 13:26

I posted the issue on Github as well and it turns out that the documentation is a little misleading. It says:

{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/my-package"
        }
    ],
    "require": {
        "my/package": "*"
    }
}

However, if you just have a local repo without releases, you have to use:

{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/my-package"
        }
    ],
    "require": {
        "my/package": "dev-master"
    }
}

The version dev-master is the key here (given that you are working on the master branch). This was mildly infuriating, but thanks to some helpful composer contributors, I could finally get a grip on this.

I hope this may help somebody in the future.

Good luck!

查看更多
爷、活的狠高调
4楼-- · 2019-04-03 13:40

For future Googlers, add your version to the composer.json and then require the package with the --prefer-source option.

For example: composer require your-vendor/package:1.0.* --prefer-source

查看更多
登录 后发表回答