I have so far been able to publish my package on packagist.
From my repository, http://github.com/pbalan/directory-parser
I followed How to create a library to be used by composer autoloading?
When I try to install the same using composer, I am unable to do so.
Composer fails saying:
Loading composer repositories with package information
Reading composer.json of pbalan/directory-parser (0.0.1)
Importing tag 0.0.1 (0.0.1.0)
Reading composer.json of pbalan/directory-parser (master)
Importing branch master (dev-master)
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package pbalan/directory-parser 1.0.0 could not be found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
Here's my composer I have in my github repository:
{
"name" : "pbalan/directory-parser",
"description" : "DirectoryParser",
"license": "MIT",
"keywords" : ["DirectoryParser"],
"homepage" : "https://github.com/pbalan/directory-parser",
"authors" : [
{
"name" : "prashant"
}
],
"autoload" : {
"psr-0" : {"src" : ""}
},
"require" : {
"php": ">=5.3.3"
}
}
And I am trying to install in a fresh directory using this composer.json:
{
"name" : "pbalan/directory-parser",
"description" : "DirectoryParser",
"license": "MIT",
"keywords" : ["DirectoryParser"],
"homepage" : "https://github.com/pbalan/directory-parser",
"authors" : [
{
"name" : "prashant"
}
],
"repositories": [
{
"type": "vcs",
"url": "http://github.com/pbalan/directory-parser.git"
}
],
"require" : {
"php": ">=5.3.3",
"pbalan/directory-parser": "dev-master"
}
}
I changed my composer.json now to a point where I have no errors, however I am not able to install the package and just install autoloader files.
How could I get my package installed?
Please help!
The problem is probably that you are re-using the name of your package in the second composer.json.
Simply use this as the composer.json for your empty directory:
{
"require": {
"php": ">=5.3.3",
"pbalan/directory-parser": "dev-master"
}
}
That's all! You don't need all the extra information such as name, description etc. unless you are creating another library that should be available on Packagist as well.
Related
I'm trying to develop a PHP library (called foo/bar) using Composer in dir /work/a with the composer.json contents:
{
"name": "foo/bar",
"require": {
"php": ">=7.2"
}
}
/work/a is a git project and I'm on the branch mybranch
I'm trying to use this lib in another project locally (called testing/foobar) using Composer in dir work/b with the composer.json contents:
{
"name": "testing/foobar",
"type": "project",
"repositories": [
{
"type": "vcs",
"url": "/work/a"
}
],
"require": {
"php": "^7.4",
"foo/bar": "mybranch"
}
}
When running $ composer install in /work/b I get the error:
[UnexpectedValueException]
Could not parse version constraint mybranch: Invalid version string "mybranch"
You have to prefix your branch name with dev-, so your branch name will have to be dev-mybranch.
Loading a package from a VCS repository
...
In composer.json, you should prefix your custom branch name with "dev-".
...
Also check this Q/A "Composer require branch name".
Change branch name to have dev- prefix, add it to /work/b project:
{
"name": "testing/foobar",
"type": "project",
"repositories": [
{
"type": "vcs",
"url": "/work/a"
}
],
"require": {
"php": "^7.4",
"foo/bar": "dev-mybranch"
}
}
Run composer install:
❯ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing foo/bar (dev-mybranch 85c97b7): Cloning 85c97b7b23 from cache
Writing lock file
Generating autoload files
Let's say we have the following directory structure, we assume my-package also exists on Packagist:
- apps
\_ my-app
\_ composer.json
- packages
\_ my-package
\_ composer.json
To add my/package as a dependency of my-app, the documentation states we can use the following configuration:
{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package"
}
],
"require": {
"my/package": "*"
}
}
However when I composer update, the dependency is still downloaded from Packagist. So, to see, I disabled Packagist.org:
{
"repositories": [
{
"type": "path",
"url": "../../packages/my-package",
"packagist.org": false
}
],
"require": {
"my/package": "*"
}
}
I cleared the cache with composer clearcache, removed my/package with composer remove my/package and installed it again with composer require my/package --prefer-source (I didn't understand if --prefer-source is for vcs only). The downloaded package is still not the local one. How to force composer to use the local one?
"require": {
"my/package": "*"
}
In case of VCS or path repository types, you need to specify version of the package you request. So instead of using *, as you have currently, use #dev:
"require": {
"my/package": "#dev"
}
For
composer --version
Composer version 2.0.14
in composer.json file
"require": {
"my/package": "dev-master"
}
I am in the process in developing my first package. The package is working.
Now I want to use Laravels Collective's HTML in my package (dependencies).
Therefor I added this to the package's composer file:
(this composer.json is in the root of the package: /packages/vendor/package)
{
"name": "vendor/package",
"description": "",
"license": "MIT",
"authors": [
{
"name": "firstname lastname",
"email": "info#domain.nl"
}
],
"minimum-stability": "stable",
"require": {
"twbs/bootstrap": "dev-master",
"laravelcollective/html": "5.3.*"
}
}
I've included the package in Laravel's own composer.json:
...
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Vendor\\Package\\": "packages/vendor/package/src"
}
},
...
When I do composer update the dependencies of the package are not updated. What am I missing here?
You have to define a local composer repository if your package is not uploaded to packagist.org yet. Inside Laravels' application composer.json add a local repository like this:
"repositories": [
{
"type": "path",
"url": "/full/or/relative/path/to/development/my-package"
}
],
"require": {
"my-package": "*"
}
You have to define the package src directory inside the package composer.json and not inside the Laravels' own composer.json. Try and define it like this inside packages' composer.json:
"require" : {
"twbs/bootstrap": "dev-master",
"laravelcollective/html": "5.3.*"
},
"autoload" : {
"psr-4" : {
"PackageNamespace\\PackageClass\\" : "src/"
}
},
UPDATE
In order to do a proper package development, you have to keep your package files at some directory other than /vendor/ composer directory. The main reason is that the developer can delete the entire /vendor directory if there might be conflict problems or for cleaning up and setting up everything under composer /vendor path. I use a very simple method and I keep my own packages at:
<application>/dev/packages/<package-namespace>/<package-name>
You have to initialize a git at your package for composer to recognize the repository. To make a git package, go at your package location and run the following commands:
cd <application>/dev/packages/<package-namespace>/<package-name>
git init
git add *
git commit -m "Initial commit"
You may also have to set the git config user.name and git config user.email before commit, for the git to be able to recognize someone and allow the local commits:
git config user.email "you#example.com"
git config user.name "Your Name"
In my example, the namespace is lytr and the package name is testpkg.
The <application>/dev/packages/<package-namespace>/<package-name>/composer.json (<application>/dev/packages/lytr/testpkg) will look like this:
{
"name" : "lytr/testpkg",
"description" : "Test package of Lytr",
"keywords" : [
"test",
"package"
],
"license" : "MIT",
"require" : {
"twbs/bootstrap" : "dev-master",
"laravelcollective/html" : "5.3.*"
},
"autoload" : {
"psr-0" : {
"Lytr\\TestPkg\\" : "src"
}
},
"extra" : {
"branch-alias" : {
"dev-master" : "1.0-dev"
}
},
"minimum-stability" : "dev"
}
Then at your application <application>/composer.json you'll have a local git repository and your package like this:
"repositories": [
{
"type": "path",
"url": "<full-application-path>/dev/packages/lytr/testpkg"
}
],
"require" : {
"lytr/testpkg": "*"
},
"minimum-stability": "dev",
I include "minimum-stability": "dev", because we are using master-dev versions. Then after running the composer update command only having the "twbs/bootstrap" : "dev-master", at the package requirements, we'll see the following output on the console window:
And after we change the package composer.json and require the "laravelcollective/html" : "5.3.*",, we do a composer update and we see composer installs the laravelcollective/html package properly:
I know this might look confusing and somehow overkill, but this is a proper way for developing packages for composer. You can also have your packages at a git repository and make composer clone that repository instead of your local files. When you're done developing the package and you release it under https://packagist.org/, then you will just have to require your package as any other normal package without the repositories and all the local git thing. Remember, you are at development phase of your package and not at production.
I have been trying to create a simple composer package. But I'm stuck with the following issue. Dont know how to resolve this.
[InvalidArgumentException]
Could not find package sarav/sample-package at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
Package Url : https://packagist.org/packages/sarav/sample-package
I ran the following composer command
composer require sarav/sample-package
My composer contents
{
"name": "sarav/sample-package",
"description": "Sample package",
"type": "Library",
"license": "MIT",
"authors": [
{
"name": "Sarav",
"email": "me#sarav.co"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-0": {
"Sarav": "src/"
}
}
}
Your package config looks good to me, but your Git repo doesn't have any tagged versions.
Use git tag v1.0.0 or whatever version is appropriate, then git push origin --tags to update on GitHub.
Alternatively, you can go without tagged versions by specifying the master branch when you require the package, like so:
composer require sarav/sample-package dev-master
You can require any branch in this manner, but the dev- prefix is mandatory.
I am trying to create a new composer library package.
I created the composer.json file using the
composer.phar create-project xlix vendor/xlix/xlix 0.3
command.
In the filesystem the file composer.json exists under vendor/xlix/xlix and for testing purposes I copied it to vendor/xlix.
The composer.json file content is the following:
{
"name": "xlix/xlix",
"type": "library",
"description": "XLIX package",
"keywords": ["core"],
"homepage": "http://myhomepage",
"license": "GPL",
"authors": [
{
"name": "Florian Kasper",
"email": "florian.kasper#mymail"
}
],
"require": {
"php": ">=5.2.4"
},
"autoload": {
"psr-0" : {
"Xlix\\Bundle" : "lib/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0"
}
}
}
Then I tried the following commands:
git:(master) ✗ php composer.phar require xlix/xlix
git:(master) ✗ php composer.phat require vendor/xlix
...
git:(master) ✗ php composer.phar install vendor/xlix
git:(master) ✗ php composer.phar install xlix/xlix
...
Every time the same output:
Please provide a version constraint for the xlix/xlix requirement: *
composer.json has been updated
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package xlix/xlix could not be found in any version, there may be a typo in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
In my ROOTDIR/composer.json file the package is registered in the require section.
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"kriswallsmith/assetic": "1.1.*#dev",
"xlix/xlix": ">=0.*"
Now I am on the edge of despair an don't know what to do anymore.
Question:
Are there any mistakes I've made or is there anything i missed?
Packages live on the internet, not on your filesystem.
Composer searches by default for a package called xlix/xlix on packagist and that does not exists. You can add more package repositories by using the repositories configuration, more about that in the documentation.
So, in order to require your package with composer you need to upload your xlix directory somewhere.
I don't see what you are trying to do in the lxix directory? You are in the lxix package, why do you want to require it in the same package? It looks like you don't understand what those commands do and how composer works. Maybe a good read in their own documentation -- or some other tutorials about Composer (like the one on nettuts+) -- will help you to get a better understanding of composer.