Composer clones from cache instead of repo - caching

I have two projects I am working on, both were setup as git repos, both use composer.
First project uses second as a library.
I configured composer.json in the following way:
... "repositories": [
{"type": "composer", "url":"http://composer.myrepourl.com/repo/private/"},
]
"require": {
"second/second": "dev-B-3"
} ...
There was no problem pulling the project from a repository for the first time. However now I made some changes in second project, pushed to the repo and now want to have them in first project, but for some reason composer pulls from the cache.
I ran composer clear-cache. I tried deleting: vendor folder, /home/user/.composer/cache, cache inside container /root/.composer/, but it still finds a way to clone the second project from cache instead of pulling it from repo.
Any ideas on how to force composer to always pull from repo instead of cloning from cache?

Run
$ composer install --prefer-source
Alternatively, specify your preferred installation method in composer.json generally:
{
"config": {
"preferred-install": "source"
}
}
or specifically for the desired dependency
generally:
{
"config": {
"preferred-install": {
"vendor/package": "source",
"*": "dist"
}
}
}
For reference, see:
https://getcomposer.org/doc/03-cli.md#install
https://getcomposer.org/doc/06-config.md#preferred-install

you should run
composer clear-cache
then
composer update --prefer-source

Ok I have found a solution:
sudo rm -r /home/user/project/vendor
cd %wherever_your_docker_is%
docker-compose stop
docker-compose rm
docker-compose up -d
composer update

Related

Laravel Nova tool wouldn't update if symlink is set to true on composer.json

So I am running into a weird issue. I used Laravel Nova (2) command to generate a tool. It sits at ./nova-components/CustomNovaDashboard. In order for the deployment to work on Laravel Vapor, I had to add the below to my parent composer.json.
{
"type": "path",
"url": "./nova-components/CustomNovaDashboard",
"options": {
"symlink": false
}
}
This above allows the code to get deployed, because the absence of symlink in options would otherwise throw the following error:
include(/tmp/vendor/composer/../acme/custom-nova-dashboard/src/ToolServiceProvider.php): failed to open stream: No such file or directory
But the problem now is that when I run npm run watch inside ./nova-components/CustomNovaDashboard, the code in development never updates, because somehow there is a copy of the code that sits in vendor/acme/custom-nova-dashboard that doesn't pick up the changes.
How can I solve this?
I found a solution, it was quite simple.
In my vapor.yml, I had to add COMPOSER_MIRROR_PATH_REPOS=1 before composer install.
build:
- 'COMPOSER_MIRROR_PATH_REPOS=1 composer install'
- 'php artisan event:cache'
- 'npm ci && npm run dev && rm -rf node_modules'
This ensures the symbolic link generated by nova:tool works on dev and prod similarly.
Just don't forget to set "symlink": true in your composer.json. Or leave it as is originally generated by the nova:tool command.

How to use global composer.json when create project in Composer?

I have add the following config, and if I reqiure global package, all is Okey. Every packages will be installed from mirrors.aliyun.com
composer global config repo.packagist composer https://mirrors.aliyun.com/composer/
and content from ~/.composer/composer.json
{
"require": {
"laravel/installer": "^4.0",
"laravel/valet": "^2.11"
},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
}
}
}
But if I create project with composer like this, I found package downloading from https://repo.packagist.org/packages.json
composer create-project --prefer-dist laravel/laravel sample.com -vvv
I need to download from mirror, but the config in global composer.json is ignored, anyone knows why is that?
Here is some related logs
Reading /Users/jack/.composer/composer.json
Loading config file /Users/jack/.composer/config.json
Loading config file /Users/jack/.composer/auth.json
Loading config file /Users/jack/.composer/composer.json
Loading config file /Users/jack/.composer/auth.json
Reading /Users/jack/.composer/auth.json
Reading /Users/jack/.composer/vendor/composer/installed.json
Creating a "laravel/laravel" project at "./sample.com"
Downloading https://repo.packagist.org/packages.json
UPDATE # 19:55
I add --repository parameter, then the laravel/laravel template is downloaded from mirror repository
composer create-project laravel/laravel sample.com --prefer-dist --repository=https://mirrors.aliyun.com/composer/ -vvv
But after downloading laravel/laravel, still download from Packagist, here are some related logs
Reading /Users/cuimingda/.composer/composer.json
Loading config file /Users/cuimingda/.composer/config.json
Loading config file /Users/cuimingda/.composer/auth.json
Loading config file /Users/cuimingda/.composer/composer.json
Loading config file /Users/cuimingda/.composer/auth.json
Reading /Users/cuimingda/.composer/auth.json
Reading /Users/cuimingda/.composer/vendor/composer/installed.json
Creating a "laravel/laravel" project at "./api.mingda.net"
Downloading https://mirrors.aliyun.com/composer/packages.json
Installing laravel/laravel (v7.25.0)
Created project in /Users/cuimingda/Sites/api.mingda.net
Reading ./composer.json
Reading /Users/cuimingda/.composer/composer.json
Loading config file /Users/cuimingda/.composer/config.json
Loading config file /Users/cuimingda/.composer/auth.json
Loading config file /Users/cuimingda/.composer/composer.json
Loading config file /Users/cuimingda/.composer/auth.json
Reading /Users/cuimingda/.composer/auth.json
Reading /Users/cuimingda/.composer/vendor/composer/installed.json
> post-root-package-install: #php -r "file_exists('.env') || copy('.env.example', '.env');"
Executing command (CWD): '/usr/local/Cellar/php/7.4.8/bin/php' -d allow_url_fopen='1' -d disable_functions='' -d memory_limit='1536M' -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Downloading https://repo.packagist.org/packages.json
I just found the answer myself.
DO NOT USE the follow methods to set mirror, because they will modify ~/.composer/composer.json, and composer.json will not work when create project
composer global config repo.packagist composer https://mirrors.aliyun.com/composer/
RIGHT WAY - Manually put the following code to ~/.composer/config.json, and whether composer global require or composer create-project, they all will fetch files from mirror site, not packagist.org
{
"config": {},
"repositories": [
{
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
},
{
"packagist": false
}
]
}
There is no need to add any repositories related configto ~/.composer/composer.json
{
"require": {
"laravel/installer": "^4.0",
"laravel/valet": "^2.11"
}
}

Composer: nothing to install or update

I want install this.
I installed composer, set the environment variable path in w10.
Edit the composer.json located in this folder:
C:\Bitnami\wampstack-5.5.29-1\php\PEAR
with this content:
{
"name":"amazonwebservices/aws-sdk-for-php",
"description":"AWS SDK for PHP",
"keywords":["aws","amazon","sdk","s3","ec2","dynamodb"],
"type":"library",
"license":"Apache-2.0",
"authors":[
{
"name":"Amazon Web Services",
"homepage":"http://aws.amazon.com"
}
],
"homepage": "http://aws.amazon.com/sdkforphp/",
"require":{
"php":">=5.2.0"
},
"autoload":{
"classmap": [
"authentication/",
"extensions/",
"lib/",
"services/",
"utilities/",
"sdk.class.php"
]
}
}
{
"require": {
"katzgrau/klogger": "dev-master"
}
}
but when I execute this command in my console:
composer require katzgrau/klogger:dev-master
I get:
nothing to install or update
what I did wrong?
You are reusing the composer.json file of "aws-sdk-for-php".
That is probably not your project. And you are in the wrong folder (PEAR).
Don't copy and paste composer.json files... anyway:
Create a new project folder
then simply run composer require katzgrau/klogger:1.2.0
You'll get all dependencies fetched into the vendor folder and a fresh composer.json file for your project.

Composer fails executing app/console cache:clear on symfony 3

I cant run composer install because it fails when executing the post-install-cmd-scripts.
The reason is Symfony 3 moved the console app from the app folder to a bin folder.
I have tried composer clear-cache and composer self-update, so I can verify that I'm running the latest version of composer without any luck... Can anyone help me?
Results from composer diagnose
composer diagnose
Checking composer.json: FAIL
Defining autoload.psr-4 with an empty namespace prefix is a bad idea for performance
require.symfony/symfony : unbound version constraints (dev-master) should be avoided
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking composer version: OK
Edit:
Added my composer.json file: Pastie
Extra's part:
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
}
}
Error from Composer:
Could not open input file: app/console
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
Could not open input file: app/console
.
Manuall test of bin/composer cache:clear:
bin/console cache:clear
// Clearing the cache for the dev environment with debug true
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.
The problem repo: https://bitbucket.org/Richardh87/messenger
Had the same problem. Found that var directory was missing.
Adding var directory to project root dir solved this for me. It looks like symfony 3 tries to use old project structure if var folder is missing. Hope this can help someone.
try
sudo rm -rf vendor/*
sudo rm -rf composer.lock
then run
composer install
again
Check the extra config key in the composer.json files names as symfony-bin-dir.
So check that the composer contain the correct configuration key, as example:
composer.json
....
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
....
Changing the gitignore worked for me, like this:
# Cache and logs (Symfony3)
/var/cache/*
/var/logs/*
!var/cache/.gitkeep
!var/logs/.gitkeep
# Parameters
/app/config/parameters.yml
/app/config/parameters.ini
# Managed by Composer
/app/bootstrap.php.cache
/var/bootstrap.php.cache
/bin/*
!bin/console
!bin/symfony_requirements
/vendor/
# Assets and user uploads
/web/bundles/
/web/uploads/
# Assets managed by Bower
/web/assets/vendor/
# PHPUnit
/app/phpunit.xml
/phpunit.xml
# Build data
/build/
# Composer PHAR
/composer.phar

Setting up alias for master branch in composer

I am trying to package a module for use with composer. I have a valid composer file and I am able to install it with composer, but only when I specify that it should use dev releases (via the "#dev" version directive or minimum stability dev). I am having trouble packaging my repo so that it is seen as a master release.
I found a composer document about aliases that seems to be made for my case, but I cant get it working. Heres the relevant portion of my composer.json:
"extra": {
"branch-alias": {
"dev-master": "1.0"
}
}
Also for reference heres the require from my main projects composer file:
"require": {
"misterglass/kohana-twig" : "1.*"
},
And the actual error from composer is:
Problem 1
- The requested package misterglass/kohana-twig 1.* could not be found.
According to some helpful people on the #composer IRC channel, aliases are just to associate different versions to each other, and not to assign stability.
In order to for composer to consider it stable, you need to add a tag, which you can do on the command line or by creating a release in github.

Resources