18

I'm trying to create a local repository to test a composer project but

composer create-project --repository-url=/path/to/packages.json vendor/project-name

fails with

[UnexpectedValueException]

Unknown package has no name defined [...]

My packages.json is:

{
  "packages": {
    "vendor/project-name": {
      "dev-master": {
        "name": "vendor/project-name",
        "type": "project",
        "version": "dev-master",
        "source": {
          "url": "/path/to/project/.git",
          "type": "git"
        }
      }
    }
  }
}

As for composer's guide, this should be enough.

Any clue?

Utaal
  • 8,484
  • 4
  • 28
  • 37

1 Answers1

22

Execute this and tell me if it works for you too:

mkdir /tmp/project-name
cd /tmp/project-name
git init
vim (or whatever you like) packages.json

Paste and save:

{
    "package": {
        "name": "vendor/project-name",
        "version": "1.0.0",
        "source": {
          "url": "/tmp/project-name/.git",
          "type": "git",
          "reference": "master"
        }
    }
}

Execute:

echo '{ "name": "test/test", "version": "1.0.0", "dist": { "url": "http://dummy.com/dummy.zip", "type": "zip" } }' > composer.json

git add packages.json composer.json
git commit -a -m "first commit"

And then create your package:

composer create-project --repository-url=/tmp/project-name/packages.json vendor/project-name
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • Sorry it took so long, that worked beautifully! Where did you get the alternative syntax for a single package? And, by the way, even if you don't check in `packages.json` it still works and it doesn't include the repository definition in the generated project (where it doesn't belong). – Utaal May 13 '13 at 15:40
  • However this only works for a single package and I still can't make it work with the format described in the guide. – Utaal May 13 '13 at 15:56
  • Was literally by trial and error. After digging the sintax a lot I got back to your json, trying to understand wich "package name" it was talking about and I started to deleting things from it to have a smaller one, with just one package. And, believe me, "package" (singular) was a typo, that made me LOL. I think a word with people at Composer can give some light to the packages problem, there is surely something wrong in there. – Antonio Carlos Ribeiro May 14 '13 at 00:11
  • 1
    I've had a second look to the composer source and this is due to undocumented behavior when you select a local repo (see https://github.com/composer/composer/pull/1899). Actually, as long as a single package is listed, the contents of the outermost json key ("package" in your case) is ignored. If more than one package is present than you need to have the package name (as explained in the PR) or the search will fail. I'll wait for comments/merge of the PR and add an explanatory answer. – Utaal May 14 '13 at 16:01