fxpio / composer-asset-plugin

NPM/Bower Dependency Manager for Composer
MIT License
893 stars 156 forks source link

Composer 1.9.0: "No valid bower.json was found" when referencing a branch of a cloned repository #332

Closed holtkamp closed 5 years ago

holtkamp commented 5 years ago

With composer 1.9.0 the following works to install a Bower asset from the master branch of a cloned repository:

{
  "config": {
    "fxp-asset": {
      "repositories": [
        {
          "type": "bower-vcs",
          "name": "bower-asset/jquery-stickytabs",
          "url": "https://github.com/holtkamp/jquery-stickytabs.git"
        }
      ]
    }
  },
  "require": {
    "bower-asset/jquery-stickytabs": "*"
  }
}

However, when trying to reference a specific branch patch-uri-fragment-path on that cloned repository using:

{
  "config": {
    "fxp-asset": {
      "repositories": [
        {
          "type": "bower-vcs",
          "name": "bower-asset/jquery-stickytabs",
          "url": "https://github.com/holtkamp/jquery-stickytabs.git"
        }
      ]
    }
  },
  "require": {
    "bower-asset/jquery-stickytabs": "dev-patch-uri-fragment-path"
  }
}

This results in the following error:

composer update --verbose -vv
    1/3:    http://repo.packagist.org/p/provider-latest$bb5803e90585dc9753ce76480a758859888a3b49034076d30104f950cd3d2b86.json
    2/3:    http://repo.packagist.org/p/provider-2019-07$a036542a7710ed8c42db9f0682d46ba025321775fa541cbe25f8d27f51e145e7.json
    3/3:    http://repo.packagist.org/p/provider-2019-04$47bedf3b64484cf35917ab1ed67fbbfc654faa1e41d698f69764fb0b2953fa03.json
    Finished: success: 3, skipped: 0, failure: 0, total: 3
Adding VCS repository bower-asset/jquery-stickytabs
Loading composer repositories with package information

  [Composer\Repository\InvalidRepositoryException]                                                                                            
  No valid bower.json was found in any branch or tag of https://github.com/holtkamp/jquery-stickytabs.git, could not load a package from it.  

Exception trace:
 () at /Users/MyName/.composer/vendor/fxp/composer-asset-plugin/Repository/AssetVcsRepository.php:44
 Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository->initialize() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/src/Composer/Repository/ArrayRepository.php:185
 Composer\Repository\ArrayRepository->getPackages() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/src/Composer/DependencyResolver/Pool.php:104
 Composer\DependencyResolver\Pool->addRepository() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/src/Composer/Installer.php:379
 Composer\Installer->doInstall() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/src/Composer/Installer.php:229
 Composer\Installer->run() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/src/Composer/Command/UpdateCommand.php:163
 Composer\Command\UpdateCommand->execute() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/vendor/symfony/console/Command/Command.php:245
 Symfony\Component\Console\Command\Command->run() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/vendor/symfony/console/Application.php:835
 Symfony\Component\Console\Application->doRunCommand() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/vendor/symfony/console/Application.php:185
 Symfony\Component\Console\Application->doRun() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/src/Composer/Console/Application.php:267
 Composer\Console\Application->doRun() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/src/Composer/Console/Application.php:106
 Composer\Console\Application->run() at phar:///usr/local/Cellar/composer/1.9.0/bin/composer/bin/composer:61
 require() at /usr/local/Cellar/composer/1.9.0/bin/composer:24

When rolling back to Composer 1.8.6 using composer self-update 1.8.6 installing that specific branch works again.

I had a look at the CHANGELOG of Composer and it seems nothing relevant changed with version 1.9.0: https://github.com/composer/composer/blob/master/CHANGELOG.md

What could be the cause of not being able to install a specific branch?

stefangr commented 5 years ago

The src/Composer/Repository/VcsRepository.php (in composer 1.9.0) dropped the verbose property and replaced it with the isVerbose and isVeryVerbose properties.

The Fxp\Composer\AssetPlugin\Repository\AssetVcsRepository still tries to read the verbose property, but because of that an ErrorException is triggered and caught in that class on line 59. https://github.com/fxpio/composer-asset-plugin/blob/9dd0e63d5ba5451993f1779529d61e316d5d4c99/Repository/AssetVcsRepository.php#L59 Because of that it can not complete the initTags and initBranches methods, which result in the exception.

holtkamp commented 5 years ago

Nice analysis @stefangr! Catching an Exception and "doing nothing" is always a tricky approach 🤓 .

https://github.com/composer/composer/commit/8288d2c456287d4ec2d746db1d285d6bd82d52ec#diff-83a02563c016f80c204feea10392f659 indeed resulted in the new properties you described: https://github.com/composer/composer/blob/8288d2c456287d4ec2d746db1d285d6bd82d52ec/src/Composer/Repository/VcsRepository.php#L33-L34

I think this can be appoached on two ways:

francoispluchino commented 5 years ago

Maybe replace now the catch exception with the class \Exception by \RuntimeException. TransportException used by RemoteFilesystem extends \RuntimeException and all vcs drivers use the \RuntimeException class.

holtkamp commented 5 years ago

https://github.com/fxpio/composer-asset-plugin/issues/332#issuecomment-519501124

Yea mean this in addition to adding support for the new properties isVerbose and isVeryVerbose, right?

francoispluchino commented 5 years ago

Yes, off course.

holtkamp commented 5 years ago

And what approach as suggested in https://github.com/fxpio/composer-asset-plugin/issues/332#issuecomment-519479151 would you prefer?

The deprecated verbose property is (at least) used here:

  1. https://github.com/fxpio/composer-asset-plugin/blob/9dd0e63d5ba5451993f1779529d61e316d5d4c99/Repository/AssetVcsRepository.php#L79
  2. https://github.com/fxpio/composer-asset-plugin/blob/9dd0e63d5ba5451993f1779529d61e316d5d4c99/Repository/AssetVcsRepository.php#L99
  3. https://github.com/fxpio/composer-asset-plugin/blob/9dd0e63d5ba5451993f1779529d61e316d5d4c99/Repository/AssetVcsRepository.php#L157
francoispluchino commented 5 years ago

I will replace $this->verbose by $this->io->isVerbose(), because $io is present since the first version, and $verbose or $isVerbose store this value. However, it is not the only bug with the last 1.9.0 version.

francoispluchino commented 5 years ago

Compatibility with Composer 1.9 added by a5679e481c94e609c5c360cd05bf06058d9eb370.