How to get Composer to leave a package alone

composer-php, php

Solution

I figured out how to do this.

What you want to do is create an artifact directory.

Thus in your main composer.json file you need to do something like this:

"repositories": [
    {
        "type": "artifact",
        "url": "custom/artifact/"
    },
    ..........

the url var should be the file path to the zip files relative to composer.json file.

Now you only need to add a composer.json file with a name and version to a zip file.

If the package already contains a composer.json file you only need to add a version.

example: vendor-package-1.0.zip needs a composer.json file with:

{
    "version": "1.0",
    "name": "vendor/package",
    "type": "library",
    ........... etc
}

It is important to define the version in the composer.json file or it will not find it.

Now you call this package by version from your projects composer file:

"require": {
    "vendor/package": "1.0",

Now you can create and update files in your package without the worry that some online change or offline server will cause any problems.

As long as the version stays the same it should leave your files alone.

The good thing is that files added or removed will still update the autoloaders as specified in the zip package's composer.json file.

Problem

I have two packages that was pulled to my project with composer. I don't want to have composer pull updates on these packages from anywhere and don't want composer to try and override my files with any repository. If I remove the packages from my composer.json file it deletes the packages an removes the autoloaders. How do I get composer to leave the packages alone and allow me to work on the code without losing the files or autoloaders on update.

Original source