Why pulling package from packagist is failing? - composer-php

I have forked a repository to make some changes in it. Here is my repo
https://github.com/vinsaj9/scrypt
and it has tags too. It is linked with packagist
https://packagist.org/packages/vinsaj9/scrypt
Now, I am getting following error
"The requested package vinsaj9/scrypt could not be found in any
version, there may be a typo in the package name"
when I am trying to pull it through this composer setting
{
"name": "test/test",
"description": "test",
"type": "project",
"version": "0.0.1",
"license": "OSL-3.0",
"require": {
"vinsaj9/scrypt": "*"
},
"minimum-stability": "dev",
"prefer-stable": true
}

As Hakre mentioned in his comment to my question. After uploading package to https://packagist.org/ you need to wait for some hours. In my case it was not updated even after 4 hours and reason could be that I was keep making changes in the repo, creating new releases and tags in the process of debugging my problem.

Related

Project Structure with composer

I'm trying to create a project with composer-file.
Reason is primarily a dependency which I never want to upload to git.
My intended structure is this:
project-root-folder
- project-sub-folder(s)
- vendor (with required dependencies)
- index.php
- composer.json
- README.md
But the installed structure using composer is this:
project-root-folder
- vendor
- vendor/composer
- vendor/smarty (dependency)
- vendor/my-project
- composer.json
I know that there are special installers for many different projects, I just don't understand that an installer is required to get the intended structure and also not how to do it without a special installer.
This is the content of one composer file I tried:
{
"name": "wdb/tutorial-oop",
"require": {
"smarty/smarty": "~3.1"
}
}
When I tried this composer-json content in a local file and just extecute composer install I get the same structure:
{
"require": {
"wdb/tutorial-oop": "dev-master"
}
}
So my question is, how a composer file has to look that the project structure is created like I described in the top of this question. The basic problem is that I don't want my project being installed as dependency in the vendor-directory but in the root of the project folder, and additionally that I don't want to use the composer autoloader.
Edit:
On request here my full composer file inside the project root:
{
"name": "wdb/tutorial-oop",
"type": "project",
"description": "Your package description goes here",
"keywords": ["oop","mvc","tutorial"],
"homepage": "https://barlians.com",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "David Bruchmann",
"email": "david.bruchmann#gmail.com",
"homepage": "https://barlians.com",
"role": "Author, Developer"
}
],
"support": {
"email": "david.bruchmann#gmail.com"
},
"require": {
"smarty/smarty": "~3.1"
}
}
You're installing your project in incorrect way. The composer require command is for installing dependencies, so they're installed to the vendor directory.
For installing a project you should use the create-project command:
composer create-project wdb/tutorial-oop

Why I can't use composer require {packageName} successfully?

I'm learn how to create Laravel packages, And I wrote a package here: noahprot/fillindata
Then I submit it to packagist
And I have set a lastest release in github
And the Packagist show like this:
Already show the latest release
Then I use Laravel CLI Tool create a new laravel project, I want try to use this package, and I use composer require noahprot/fillindata
But the result like this:
[InvalidArgumentException]
Could not find a version of package noahprot/fillindata matching your
minimum-stability (dev). Require it with an explicit version con
straint allowing its desired stability.
my package's composer.json file like this:
{
"name": "noahprot/fillindata",
"License": "MIT",
"description": "take the csv file fill into database table",
"authors": [
{
"name": "Noah Prot",
"email": "mylovewangjian#gmail.com"
}
],
"autoload": {
"psr-4": {
"NeoLee\\Fillindata\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"NoahProt\\Fillindata\\FillindataServiceProvider"
]
}
},
"require": {}
}
I make some try like:
add "minimum-stability": "dev" to composer.json, but failed,
even I edit to "stable", but failed too;
I have no idea for this situation now;
Guys, Please Help me, and give some advice, please!
Thank you everyone!
It seems that Packagist have some cache-related problems, see this issue. Mirror you're using probably have some outdated packages info. At this point you can do only two things:
Wait until packages data on mirror will be refreshed.
Report your case (see this comment).

Composer only finds latest version (tag) of Gitlab hosted package

I have created a package with some annotated tags for versioning (1.0.0, 1.0.1, 1.1.0 and 2.0.0). This package lives on own hosting (so not via Packagist)
When trying to require the package, composer only finds the 2.0.0 version and fails on any other version requirement.
Composer.php file of project using package
{
"name": "projectname",
"description": "Description.",
"keywords": ["keys"],
"license": "Licence",
"type": "project",
"require": {
...
"space/package-name": "~1.0" // Also tried 1.0.0, 1.0.*, ~1.0#dev - only 2.0.0 works
}
"repositories": [
...
{
"type": "git",
"url": "git#gitlab.com:space/package-name.git" // Make sure package is found on specific hosting
}
],
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
On running composer show "space/package-name" I get versions: * 2.0.0. So upon update, composer produces the following error:
The requested package space/package-name ~1.0 exists as name/package-
name[2.0.0, dev-master] but these are rejected by your constraint.
It looks like composer is no able to find any other version than the latest, any way of fixing this?
Things already checked:
The package does not contain a version in the composer.json (that might conflict with the git tag)
Used tags are annotated tags and are pushed to the repo.
Updates:
Might be a Gitlab - Composer issue, see this comment.
Gitlab doesn't always provide tag info when Composer tries to read the repo.
Solution: also add version info in composer.json:
{
"name": "package/name",
"version": "1.0.0",
...
}
This will be readable by composer. Careful: Git tags must match versioning info in composer.json! (might cause errors otherwise)

composer create-project without the need to have internet access

From my understanding, the following command will go to internet to download some files (such as the https://packageist.org/packages.json).
composer create-project laravel/laravel MyProject --prefer-dist
Is it possible to download all the required files so that the above command do not require internet access? (meaning that it will use local drive for to create the project.)
You can setup local mirror for any packages you want. Alternatively, you could just create batch script (shell script) which would copy whole project from any local computer or from local directory on the same machine.
"repositories": [
{
"type": "composer",
"url": "http://localhost:4680"
}
],
You won't require internet connection only if requested package is available in your local cache.
Despite of that, offline mode is something that was requested some time ago.
https://github.com/composer/composer/issues/2244
You can use the repositories key in your composer.json file -
{
"name": "atefth/project",
"description": "Test project",
"license": "MIT",
"authors": [
{
"name": "Atef Haque",
"email": "atefth#gmail.com"
}
],
"minimum-stability": "dev",
"repositories": [
{
"type": "vcs",
"url": "../package"
}
],
"require": {
"atefth/package": "*"
}
}
You need to download all your dependencies inside the ../package directory

packagist / composer - Assign a version number

I have people using my pacakgist library.
I want to make sure that their composer.json version requirement stated as "dev-master" will not get updated when they run composer update... as I have changed the underlying architecture of the package.
How do I assign a new versioning to my new update? so that they have to explicitly say I want v1.01
I currently have the composer.json as:
{
"name": ...,
"type": "library",
"description": ...,
"keywords": ...
"homepage": ...,
"license": "MIT",
"authors": [
...
],
"require": {
"php": ">=5.3.0"
},
"autoload": {
"classmap": ["Models/"]
}
}
The composer documentation recommends specifying the version using a VCS tag. With git this looks like
git tag -a 1.0.0 -m 'Your tag message'
This will tag the HEAD of your current branch with the version 1.0.0. Then do
git push --tags
Once your package gets crawled again, the version should be available on packagist.

Resources