PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 20, 2022

[FIXED] How to force Composer to download a local package?

 May 20, 2022     composer-php, php     No comments   

Issue

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?


Solution

"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"
}


Answered By - Marcin Orlowski
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing