composer-link icon indicating copy to clipboard operation
composer-link copied to clipboard

Link specified packages automatically from the extra section in composer.json

Open Andrii-Antoniuk opened this issue 10 months ago • 3 comments

Hello!

First of all - thank you for creating & maintaining this amazing package! 🥳

I'd like to keep the linked-packages.json inside the version control system, but I don't want to add to vcs any files inside vendor folder (as during installation if hash mismatches it will change files anyways, AFAIK).

For this I believe that $storageFile can be defined as following:

 $storageFile = dirname($this->composer->getConfig()->get('vendor-dir')) . DIRECTORY_SEPARATOR . 'linked-packages.json';

Was this ever considered or are there any reasons why not to? Could be a config if needed, or just keep it there. This will help with automation of setup, since 0 extra steps would be needed to re-link packages on every environment/local setup.

Andrii-Antoniuk avatar Feb 11 '25 17:02 Andrii-Antoniuk

Hey,

I think this is a bit related to https://github.com/SanderSander/composer-link/issues/20 The issue is a bit old, and the content a bit outdated and I had time to think it a bit more out.

But I do understand the need to be able to always link specified packages from source control. (For example setting up development environments quickly for multiple developers, or whatever else).

The file linked-packages.json was simply created to store data somewhere and was not intended to be commit in source control, and I rather keep it that way because in the future it can happen that it will contain data that could break another environment when commited in source control. (Think about absolute paths etc, what already is possible for packages that are linked with composer global link).

But that doesn't make it impossible to get what we want ;).

I was thinking about defining packages in composer.json itself that should be linked automatically.

Something in the lines of:

{
  "require-dev": {
    "sandersander/composer-link": "^0.5"
  },
  "config": {
    "allow-plugins": {
      "sandersander/composer-link": true
    }
  },
  "extra": {
    "link": {
      "paths": [
        "../package-a",
        "../package-b"
      ]
    }
  }
}
}

This makes sure that on a composer install everything is linked and with a composer install --no-dev nothing would be linked.

This also gives the developer freedom over his environment and the ability to simple unlink a package through the command line, but without changing the composer.json because it will be registered in locked-packages.json on his environment.

SanderSander avatar Feb 11 '25 20:02 SanderSander

Yes, that's also exactly what I'm thinking about as well. Sure, I agree that the format doesn't really matter, only the end feature 🫡🙃

Since, for example, cweagans composer patches are also using extra that should be fine to use, mb with package name ("composer-link") so won't be confused/conflicted

Thanks for the reply, hopefully we get it as part of future releases, will follow the repo 🫡🙂

For now, I created a patch for my needs with exact code from issue

Andrii-Antoniuk avatar Feb 11 '25 20:02 Andrii-Antoniuk

You're lucky because I need this feature as well 🙈 I hope to have this in 0.5.1 this week.

SanderSander avatar Feb 11 '25 20:02 SanderSander