-
Notifications
You must be signed in to change notification settings - Fork 113
Update the composer.lock file to avoid out-of-sync errors #173
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -336,6 +336,8 @@ protected function updateComposerJson() | |
|
|
||
| file_put_contents($filename, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); | ||
|
|
||
| $this->syncComposerLockFile(); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
|
|
@@ -412,4 +414,19 @@ protected function getRemoteFileUrl() | |
| { | ||
| return 'http://symfony.com/download?v=Symfony_Standard_Vendors_'.$this->version; | ||
| } | ||
|
|
||
| /** | ||
| * Updates the 'hash' value stored in composer.lock to avoid out-of-sync | ||
| * problems when the composer.json file contents are changed. | ||
| */ | ||
| private function syncComposerLockFile() | ||
| { | ||
| $composerFileContents = file_get_contents($this->projectDir.'/composer.json'); | ||
| $lockFileContents = json_decode(file_get_contents($this->projectDir.'/composer.lock'), true); | ||
|
|
||
| $hash = md5($composerFileContents); | ||
| $lockFileContents['hash'] = $hash; | ||
|
|
||
| file_put_contents($this->projectDir.'/composer.lock', json_encode($lockFileContents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will throw an error for PHP5.3 because the two constants do not exist. You might better use the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The installer doesn't work with PHP 5.3. We prevent that here: https://github.com/symfony/symfony-installer/blob/master/symfony#L4
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you tested the behavior to be sure the hash is correct?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! Here it is the summarized console output: $ ./symfony new before
Downloading Symfony...
[...]
$ cd before/
$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Warning: The lock file is not up to date with the latest changes in composer.json.
You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Generating autoload files
[...]
$ cd ..
$ ./symfony new after
Downloading Symfony...
[...]
$ cd after
$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
[...]
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome then! 👍 |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did you find this behavior? In Composer itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found it here: https://github.com/composer/composer/blob/69210d5bc130f8cc9f96f99582a041254d7b9833/src/Composer/Factory.php#L309 But to be sure I made an
md5of severalcomposer.jsonfiles and they matched the values stored incomposer.lock.