drupal-project icon indicating copy to clipboard operation
drupal-project copied to clipboard

ScriptHandler execution fails while running composer commands with --no-install flag

Open bhanu951 opened this issue 4 years ago • 0 comments

Issue :

ScriptHandler execution fails while running composer commands with --no-install flag

Use case :

If I wanted to add additional modules or any other packages without actually downloading them I execute the composer commands with --no-install flag.

For example if I wanted to add devel module to the project and update composer.lock file I execute the following command

composer require --dev --no-install 'drupal/devel:^4.1'

But as the required classes are not present ScriptHandler currently throws error


$ composer require --dev --no-install 'drupal/devel:^4.1'
./composer.json has been updated
Running composer update drupal/devel
> DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies
Lock file operations: 154 installs, 0 updates, 0 removals
  - Locking asm89/stack-cors (1.3.0)
  - Locking behat/mink (v1.8.1)
  - Locking behat/mink-browserkit-driver (v1.3.4)
...........
...........
  - Locking webflo/drupal-finder (1.2.2)
  - Locking webmozart/assert (1.10.0)
  - Locking webmozart/path-util (2.3.0)
  - Locking zaporylie/composer-drupal-optimizations (1.2.0)
Writing lock file
51 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.
Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
> DrupalProject\composer\ScriptHandler::createRequiredFiles
PHP Fatal error:  Uncaught Error: Class 'DrupalFinder\DrupalFinder' not found in C:\xampp\htdocs\drupal-project\scripts\composer\ScriptHandler.php:21
Stack trace:
#0 phar://C:/Users/<username>/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(341): DrupalProject\composer\ScriptHandler::createRequiredFiles(Object(Composer\Script\Event))
#1 phar://C:/Users/<username>/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(220): Composer\EventDispatcher\EventDispatcher->executeEventPhpScript('DrupalProject\\c...', 'createRequiredF...', Object(Composer\Script\Event))
#2 phar://C:/Users/<username>/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(102): Composer\EventDispatcher\EventDispatcher->doDispatch(Object(Composer\Script\Event))
#3 phar://C:/Users/<username>/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/Installer.php(341): Composer\EventDispatcher\EventDispatcher->dispatchScript('post-update-cmd', true in C:\xampp\htdocs\drupal-project\scripts\composer\ScriptHandler.php on line 21

Fatal error: Uncaught Error: Class 'DrupalFinder\DrupalFinder' not found in C:\xampp\htdocs\drupal-project\scripts\composer\ScriptHandler.php:21
Stack trace:
#0 phar://C:/Users/<username>/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(341): DrupalProject\composer\ScriptHandler::createRequiredFiles(Object(Composer\Script\Event))
#1 phar://C:/Users/<username>/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(220): Composer\EventDispatcher\EventDispatcher->executeEventPhpScript('DrupalProject\\c...', 'createRequiredF...', Object(Composer\Script\Event))
#2 phar://C:/Users/<username>/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(102): Composer\EventDispatcher\EventDispatcher->doDispatch(Object(Composer\Script\Event))
#3 phar://C:/Users/<username>/AppData/Local/ComposerSetup/bin/composer.phar/src/Composer/Installer.php(341): Composer\EventDispatcher\EventDispatcher->dispatchScript('post-update-cmd', true in C:\xampp\htdocs\drupal-project\scripts\composer\ScriptHandler.php on line 21

Proposed Solution:

To fix this check for class existence and execute the script in ScriptHandler file. If needed throw a notice stating class not exist hence skipped execution of script.

bhanu951 avatar Jun 09 '21 03:06 bhanu951