How to develop a dependent composer package without the need to commit or publish changes?

前端 未结 1 1087
北恋
北恋 2021-01-16 16:39

I have an application A which has a composer.json file defining a dependency on package P, which is my own new shiny package. My package P has a composer.json file, which de

相关标签:
1条回答
  • 2021-01-16 17:01

    The solution I use when I'm in a situation where I need to work on multiple packages at the same time, is to register each package locally and after composer install or after first composer update I remove that package from vendor directory and symlink it to location where I store the local "WIP" version.

    For example:

    • In composer.json I require my_vendor/packageA, which is registered locally inside ~/.composer/config.json.
    • I execute composer update my_vendor/packageA to make composer aware of my new package.
    • After composer finishes installing my package:
      • cd vendor/my_vendor && rm -rf packageA && ln -s ../../../packageA .

    Which will leave me with something like:

    • working_dir/
      • packageA/ (this is where I work on packageA)
      • projectA/
        • app
        • src
        • vendor/
          • vendor1/
          • vendor2/
          • my_vendor/
            • packageA -> ../../../packageA

    This allows me:

    • To change packageA even from inside my vendor dir
    • I don't need to commit to packageA before I can use those changes inside my projectA.

    When packageA will be stable enough, the symlink will be removed and everything will come back to normal, using the version from VCS/packagist.

    I tried different solutions over the time and I found that the above works best for me.

    An alternative solution which I use when I can, is to register PSR-0 directories manually, for each prefix:

    <?php
    
    $autoloader = require_once __DIR__.'/vendor/autoload.php';
    $autoloader->add('MyVendor\\Dummy\\', '/path/to/dummy-component/src');
    
    // now you can use MyVendor\Dummy as normal.
    

    Note: For PSR-4 there is addPsr4() method.

    0 讨论(0)
提交回复
热议问题