Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer dump-autoload with repository path #5520

Closed
7elix opened this issue Jul 16, 2016 · 9 comments
Closed

Composer dump-autoload with repository path #5520

7elix opened this issue Jul 16, 2016 · 9 comments
Labels

Comments

@7elix
Copy link

7elix commented Jul 16, 2016

With the following composer.json:

{
    "repositories": {
        {
            "type": "path",
            "url": "local-folder/local-composer-package"
        },
    }
}

With recent changes in local-folder/local-composer-package/composer.json concerning autoload section with classmap.

When I run this command:

composer update
or
composer dump-autoload

I assume new autoload configuration is read and put into vendor/composer/autoload_classmap.php

But the changes from local-folder/local-composer-package/composer.json are not re-read and put into project autoload configuration.

Only removal of target symlink and composer update brings new classmap autoload php file.

@alcohol
Copy link
Member

alcohol commented Jul 18, 2016

Your composer.json example is invalid. But I will assume you actually have a working valid composer.json on your local environment.

As far as I know, changes in autoload definitions should be detected immediately.

@7elix
Copy link
Author

7elix commented Jul 18, 2016

Thanks for your feedback!!

My composer files were valid and validated.
I created a git repository with demo bash script in order to easily review the issue.

Feel free to clone

  • git clone https://github.com/7elix/5520-composer
  • run ./demo-change-folder.sh

and observe that the psr4-autoloading file did not change.
Neither with composer dump-autoload nor with composer update.

Hope that there is no problem with composer Repository within composer based project.

Thanks you very much for helping me out here!
Much appreciated.

Repository url: https://github.com/7elix/5520-composer

@alcohol
Copy link
Member

alcohol commented Jul 18, 2016

Your example scenario is wrong for several reasons:

  • Your requirement refers to a specific version. Change it to "*" instead, or "dev-master".
  • The source path is wrong. You use "Repository", but in the composer.json you specify "repository".
  • You don't run a composer update either. Composer reads the autoload definition from the .lock file generated. This is not re-generated simply because you run dump-autoload (as far as I know).
  • I doubt your path repository actually has a "version" attribute in its composer.json. But if it really does, it most likely should not be there.
  • Your repositories definition should be an array as far as I know, not an object.

@alcohol
Copy link
Member

alcohol commented Jul 18, 2016

After fixing the various issues with your example scenario, I

  • ran a composer install
  • modified the psr4 definition of the "phorax/demo-package" composer.json
  • ran a composer update phorax/demo-package

and the result was as expected, the psr4 autoload file was updated.

I think there is simply a mismatch between your expectations, and how the path repository actually works. Could you elaborate on what your expectations are?

@7elix
Copy link
Author

7elix commented Jul 18, 2016

Thank you very much.
I updated the Repository according to your hints:

That version is tagged with comment-4 (https://github.com/7elix/5520-composer/releases/tag/comment-4) git tag.

Alright, now to my expectation:

Situation

That project with root composer json and local Repository with path definition is set up. Composer validate does not find any errors and composer install creates the local symlink within vendor/phorax/demo-package as expected. composer update does not find any updates thus composer.lock is not changed. All fine.

Action

Now changes within package happen: e.g. "Classes/" sub-directory is moved to "src/" and the package composer.json file is adapted accordingly.

Commands:

  • mv "Repository/demo-package/Classes/" "Repository/demo-package/src/"
  • sed -i.bak "s/Classes/src/g" "Repository/demo-package/composer.json"

At his point the composer package has been changed and new autoloading information is present that were not yet registered in the project / root composer. In order to transport these changes from the composer package into the root composer:

  • I run composer update on project root but the autoload changes are not registered in vendor/composer/autoload_psr4.php
  • I run composer update phorax/demo-package on project root but the autoload files are still not updates to reflect the new src path
  • Also composer dump-autoload on project root does not re-create the autoload files to reflect the new src path

The line
'Phorax\\DemoPackage\\' => array($vendorDir . '/phorax/demo-package/Classes')

is not changed into
'Phorax\\DemoPackage\\' => array($vendorDir . '/phorax/demo-package/src')

Work-around

By removing the vendor directory and running composer install the autoload files are re-written based on the current package composer.json file.

THANKS for your time and support! 🌞

@7elix
Copy link
Author

7elix commented Jul 18, 2016

Also the composer info is not updates yet:

➜ ~/Sites/5520-composer (master) composer info phorax/demo-package

name     : phorax/demo-package
descrip. : Demo pachage in sub-directory
keywords : 
versions : * 1.2.3
type     : library
license  : GPL2+
source   : []  
dist     : [path] repository/demo-package aa61c1251f805436bc062ab582ca9bff0a39d0e7
names    : phorax/demo-package

autoload
psr-4
Phorax\DemoPackage\ => Classes/

to display src/ as PSR-4 autoload directory.

@alcohol
Copy link
Member

alcohol commented Jul 19, 2016

You still have a few issues in your example repo:

  • require dev-master instead of *, or allow minimum-stability "dev"
  • remove the .lock file (it contains invalid data which confuses composer)
  • your .sh script does not do a composer update after modifying the composer.json of the subpackage

If you remove the lock file and apply the following patch, everything works as expected.

diff --git i/composer.json w/composer.json
index ca3bf7a..c018f87 100644
--- i/composer.json
+++ w/composer.json
@@ -15,6 +15,6 @@
         }
     ],
     "require": {
-        "phorax/demo-package": "*"
+        "phorax/demo-package": "dev-master"
     }
 }
diff --git i/demo-change-folder.sh w/demo-change-folder.sh
index b4b12fe..2c14202 100755
--- i/demo-change-folder.sh
+++ w/demo-change-folder.sh
@@ -14,16 +14,10 @@ then
        echo "Replacing autoload section in package composer.json"
        sed -i.bak "s/Classes/src/g" "Repository/demo-package/composer.json"

-       echo "Running composer dump-autoload (no-change)"
-       composer dump-autoload
+       echo "Running composer update"
+       composer update

        echo "PSR-4 autoload *after"
        cat "vendor/composer/autoload_psr4.php"

-       echo "Running composer upload (no-change)"
-       composer dump-autoload
-
-       echo "PSR-4 autoload *after"
-       cat "vendor/composer/autoload_psr4.php"
-
-fi
\ No newline at end of file
+fi

@7elix
Copy link
Author

7elix commented Jul 19, 2016

Thanks!

I have set the composer package requirement to "dev-master" instead of "*" and now the "composer update" command also updates the autoload-information.

Summary

  • do not use package version number in composer.json with repository type path
  • require package version "dev-master" even with repository type path and without vcs

I updated the code in case anyone else stumbles upon this.

-> Thank you very much!
Please post the link to your amazon wishlist!

@7elix 7elix closed this as completed Jul 19, 2016
@alcohol
Copy link
Member

alcohol commented Jul 19, 2016

I don't actually have an amazon wishlist... but @Seldaek does. You can find a link to it here. Considering all the work and time he has put into Composer, he probably deserves it more than me anyway :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants