Ocramius / PackageVersions

:package: Composer addon to efficiently get installed packages' version numbers
MIT License
3.22k stars 67 forks source link

Fails when using composer install --no-scripts #18

Closed nicwortel closed 8 years ago

nicwortel commented 8 years ago

The Versions class is not installed (and therefore calling it causes fatal errors) when dependencies are installed using composer install --no-scripts (which is, as far as I'm aware, not that uncommon in deployment scripts).

I found out because I wanted to deploy a project to production, but the deployment failed on executing the Doctrine migrations:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Fatal error: Class 'PackageVersions\Versions' not found

I propose the following solution to catch cases where the Versions class has not been generated:

  1. Let the Installer create a seperate php file that returns an array;
  2. Commit the Versions class, which requires the above file but calls the Installer when it does not exist.

In the meanwhile, the only way for me to get Doctrine Migrations working again was by explicitly requiring "ocramius/proxy-manager": "^1.0" in my project's composer.lock, in order to downgrade to a version of the proxy manager that does not require this package.

nicwortel commented 8 years ago

Related to https://github.com/Ocramius/ProxyManager/issues/294

Ocramius commented 8 years ago

What I might do is adding an autoloader (at the end of the autoloader stack) that catches attempts to load the PackageVersions\Versions.php and tries to write it to disk (and if it fails, just uses an eval() or a temporary file).

Out of my scope for now, though: I will consider it for when I got time to tinker around the lib again.

Ocramius commented 8 years ago

Reminder btw: don't deploy with composer install --no-scripts. Instead, deploy a zip package with all deps (or an RPM).

nicwortel commented 8 years ago

@Ocramius thank you for the fast response! The autoloader approach actually sounds more elegant than my own.

Reminder btw: don't deploy with composer install --no-scripts. Instead, deploy a zip package with all deps (or an RPM).

I don't run Composer on the server, but on my local machine as part of a Phing build. However, since I use --no-dev I need to add --no-scripts as well, otherwise the scripts will cause fatal errors because they run in dev mode (and Phing does not seem to enable setting the SYMFONY_ENV=prod environment variable).

If I'm just missing something or if there is a better way to do this, please let me know!

Ocramius commented 8 years ago

Uh... I would expect dev deps to only be used during a composer update. Something is quite wrong with the setup there, but I don't have an idea if this is how symfony does stuff, usually..

black-snow commented 8 years ago

Getting this even without --no-scripts. $ composer install

[ErrorException]
file_put_contents(/xyz/vendor/ocramius/package-versions/src/PackageVersions/Versions.php): failed to open stream: No such file or
directory

There's nothing funny w/ my composer.json; it was generated via composer init.

composer --version
Composer version 1.1.2 2016-05-31 19:48:11
php -v
PHP 7.0.7 (cli) (built: May 27 2016 11:13:44) ( NTS )

Mac OS X

KatharinaSt commented 8 years ago

I get the same error using "composer install" (without parameters) and PHP 7.0.8:

"..." "Generating autoload files" "[ErrorException]" "file_put_contents(/path/to/vendor/ocramius/package-versions/src/PackageVersions/Versions.php): failed to open stream: No such file or directory"

My context: Symfony 2.7

Ocramius commented 8 years ago

Run it with -vvv please On 12 Jul 2016 5:59 p.m., "KatharinaSt" notifications@github.com wrote:

I get the same error using "composer install" (without parameters) and PHP 7.0.8:

"..." "Generating autoload files" "[ErrorException]" "file_put_contents(/path/to/vendor/ocramius/package-versions/src/PackageVersions/Versions.php): failed to open stream: No such file or directory"

My context: Symfony 2.7

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Ocramius/PackageVersions/issues/18#issuecomment-232094290, or mute the thread https://github.com/notifications/unsubscribe/AAJakAdKIY08WtN2J3Kaw46KuHqdyuvwks5qU7n5gaJpZM4Idgqf .

Ocramius commented 8 years ago

Provided a fix via #33, please review.