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

[console] Error when using with Composer 2.1.3

Open SOMERSOFTAndrewCrook opened this issue 2 years ago • 0 comments

Problem/Motivation

On composer install Composer 2.1.3 creates this drupal file in bin-dir directory as follows

#!/usr/bin/env php
<?php

/**
 * Proxy PHP file generated by Composer
 *
 * This file includes the referenced bin path (../drupal/console/bin/drupal) using eval to remove the shebang if present
 *
 * @generated
 */

$binPath = realpath(__DIR__ . "/" . '../drupal/console/bin/drupal');
$contents = file_get_contents($binPath);
$contents = preg_replace('{^#!/.+\r?\n<\?(php)?}', '', $contents, 1, $replaced);
if ($replaced) {
    $contents = strtr($contents, array(
        '__FILE__' => var_export($binPath, true),
        '__DIR__' => var_export(dirname($binPath), true),
    ));

    eval($contents);
    exit(0);
}
include $binPath;

The issue is that the drupal file then includes drupal.php which is not found on include_path nor in the current directory

#!/usr/bin/env php
<?php

require 'drupal.php';

This then fails when running bin-dir/drupal

docker@cli:/var/www$ composer show | grep drupal/console
drupal/console                            1.9.7              The Drupal CLI. A tool to generate boilerplate code, interact with and debug Drupal.
drupal/console-core                       1.9.7              Drupal Console Core
drupal/console-en                         v1.9.7             Drupal Console English Language
drupal/console-extend-plugin              0.9.5              Drupal Console Extend Plugin

Solution

Apply patch file to update drupal.php.

diff --git a/bin/drupal b/bin/drupal
index 54109783..042424e2 100755
--- a/bin/drupal
+++ b/bin/drupal
@@ -1,4 +1,4 @@
 #!/usr/bin/env php
 <?php
 
-require 'drupal.php';
+require __DIR__ . '/drupal.php';

SOMERSOFTAndrewCrook avatar Jul 06 '21 17:07 SOMERSOFTAndrewCrook