Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drupal vendor directory not discovered #15

Closed
chx opened this issue Mar 21, 2019 · 17 comments

Comments

Projects
None yet
7 participants
@chx
Copy link

commented Mar 21, 2019

I downloaded drupal-check.phar , doing php drupal-check.phar -V results in Drupal Check 1.0.5. But when I attempt to run it from docroot I get a Could not find autoload file. error message. I did an ln -s ../vendor which made it work. We have a drupal-project install with docroot and vendor in the repo root. Running from the repo didn't fix this.

Thanks for super useful utility!

@mglaman

This comment has been minimized.

Copy link
Owner

commented Mar 21, 2019

Weird! We're using webflo/drupal-finder. Given the path it should try to locate Drupal by traversing up the directory tree.

For example drupal-check /path/to/drupal8/web/modules/contrib/address would/should go:

  • drupal8/web/modules/contrib/address
  • drupal8/web/modules/contrib
  • drupal8/web/modules
  • drupal8/web
  • drupal8

That's what this should be doing:

        $drupalFinder = new DrupalFinder();
        $path = realpath($input->getArgument('path'));
        if (!$path || !file_exists($path)) {
            $output->writeln(sprintf('<error>%s does not exist</error>', $input->getArgument('path')));
            return 1;
        }
        $drupalFinder->locateRoot($path);
        $this->drupalRoot = $drupalFinder->getDrupalRoot();
        $this->vendorRoot = $drupalFinder->getVendorDir();
        if (!$this->drupalRoot) {
            $output->writeln('Unable to determine the Drupal root');
            return 1;
        }

Can you run with -vvv? That will expose this output

        $output->writeln(sprintf('<info>Current working directory: %s', getcwd()), OutputInterface::VERBOSITY_DEBUG);
        $output->writeln(sprintf('<info>Using Drupal root: %s</info>', $this->drupalRoot), OutputInterface::VERBOSITY_DEBUG);
        $output->writeln(sprintf('<info>Using vendor root: %s</info>', $this->vendorRoot), OutputInterface::VERBOSITY_DEBUG);

It will help debug DrupalFinder's output

@chx

This comment has been minimized.

Copy link
Author

commented Mar 21, 2019

✗ php drupal-check.phar -vvv modules/custom
Current working directory: /mnt/c/www/d8smartsheetweb/docroot
Using Drupal root: /mnt/c/www/d8smartsheetweb/docroot
Using vendor root: /mnt/c/www/d8smartsheetweb/docroot/vendor
Could not find autoload file.
✗ cd ..
✗ php docroot/drupal-check.phar -vvv docroot/modules/custom
Current working directory: /mnt/c/www/d8smartsheetweb
Using Drupal root: /mnt/c/www/d8smartsheetweb/docroot
Using vendor root: /mnt/c/www/d8smartsheetweb/docroot/vendor
Could not find autoload file.

The correct path is /mnt/c/www/d8smartsheetweb/vendor

@mglaman

This comment has been minimized.

Copy link
Owner

commented Mar 21, 2019

Thanks! I need to add testing. TravisCI makes pipelines difficult, so I might need to switch to CircleCI so I can run better integration tests. That is very odd. I will give it a shot on an Acquia style project.

@mglaman mglaman added the bug label Mar 21, 2019

@mglaman mglaman changed the title vendor hardwired Drupal vendor directory not discovered Mar 21, 2019

@mglaman

This comment has been minimized.

Copy link
Owner

commented Mar 25, 2019

Oh wait is this a non-Composer build? Like normal Drupal where vendor is in the HTTP docroot?

Sorry I missed

The correct path is /mnt/c/www/d8smartsheetweb/vendor

@mglaman

This comment has been minimized.

Copy link
Owner

commented Apr 2, 2019

I have not been able to reproduce this despite trying several Drupal project setups

@grahl

This comment has been minimized.

Copy link

commented Apr 13, 2019

Same here, with a blt 9.2.3 project and the global composer package. The vendor symlink did not work for me but downloading the phar did.

@Sutharsan

This comment has been minimized.

Copy link

commented Apr 15, 2019

Same error here. With

  • composer build project based on drupal-composer
  • vendor directory outside of the docroot
  • using webflo/drupal-finder (1.1.0)
  • drupal-finder executed from docroot (or .. or ../vendor)

The error message is

Composer autoload file not found.
You need to run 'composer install'.

Running php /usr/local/bin/drupal-check.phar modules/custom (from docroot) does work. But autoloading still fails.

@clemens-tolboom

This comment has been minimized.

Copy link

commented Apr 16, 2019

I guess the autoload.php is the global composer. Adding some test code to drupal-check

$composerAutoloadFile = __DIR__ . '/vendor/autoload.php';
//$composerAutoloadFile = realpath(__DIR__ . '/../../../vendor/autoload.php');

echo "File:     " . __FILE__ . PHP_EOL;
echo "Dir:      " . __DIR__ . PHP_EOL;
echo "Composer: " . $composerAutoloadFile . PHP_EOL;

if (file_exists($composerAutoloadFile)) {
    require $composerAutoloadFile;
} else {
    echo "Could not find my own composer autoload file in $composerAutoloadFile." . PHP_EOL;
    echo "You need to run 'composer install'." . PHP_EOL;
    exit(1);
}

gives

drupal clemens$ drupal-check -vvv web/core/modules/node/
File:     /Users/clemens/.composer/vendor/mglaman/drupal-check/drupal-check
Dir:      /Users/clemens/.composer/vendor/mglaman/drupal-check
Composer: /Users/clemens/.composer/vendor/mglaman/drupal-check/vendor/autoload.php
Could not find my own composer autoload file in /Users/clemens/.composer/vendor/mglaman/drupal-check/vendor/autoload.php.
You need to run 'composer install'.

then changing

//$composerAutoloadFile = __DIR__ . '/vendor/autoload.php';
$composerAutoloadFile = realpath(__DIR__ . '/../../../vendor/autoload.php');

makes the tool run but fail to load the .neon files.

drupal clemens$ drupal-check -vvv web/core/modules/node/
File:     /Users/clemens/.composer/vendor/mglaman/drupal-check/drupal-check
Dir:      /Users/clemens/.composer/vendor/mglaman/drupal-check
Composer: /Users/clemens/.composer/vendor/autoload.php
File:     /Users/clemens/.composer/vendor/mglaman/drupal-check/drupal-check
Dir:      /Users/clemens/.composer/vendor/mglaman/drupal-check
Composer: /Users/clemens/.composer/vendor/autoload.php
Current working directory: /Users/clemens/Sites/drupal/d8/drupal
Using Drupal root: /Users/clemens/Sites/drupal/d8/drupal/web
Using vendor root: /Users/clemens/Sites/drupal/d8/drupal/vendor
Using autoloader: /Users/clemens/Sites/drupal/d8/drupal/vendor/autoload.php
PHP Fatal error:  Uncaught Nette\FileNotFoundException: File '/Users/clemens/.composer/vendor/mglaman/drupal-check/src/Command/../../phpstan/../vendor/mglaman/phpstan-drupal/extension.neon' is missing or is not readable. in /Users/clemens/.composer/vendor/nette/di/src/DI/Config/Loader.php:44
Stack trace:

Trying to fix for the *.neon files did not fix the overal

includes:
	- ../../phpstan-drupal/extension.neon
	- ../../phpstan-drupal-deprecations/rules_and_deprecations_testing.neon 
	- base_config.neon
	- junit_formatter.neon

as that ended up into

PHP Fatal error:  Uncaught Nette\DI\ServiceCreationException: Multiple services of type PHPStan\Drupal\ServiceMap found: 128, 131 in /Users/clemens/.composer/vendor/nette/di/src/DI/ContainerBuilder.php:242
Stack trace:
#0 /Users/clemens/.composer/vendor/nette/di/src/DI/Helpers.php(120): Nette\DI\ContainerBuilder->getByType('PHPStan\\Drupal\\...', false)
#1 /Users/clemens/.composer/vendor/nette/di/src/DI/ContainerBuilder.php(641): Nette\DI\Helpers::autowireArguments(Object(ReflectionMethod), Array, Object(Nette\DI\ContainerBuilder))
#2 /Users/clemens/.composer/vendor/nette/di/src/DI/ContainerBuilder.php(577): Nette\DI\ContainerBuilder->completeStatement(Object(Nette\DI\Statement))
#3 /Users/clemens/.composer/vendor/nette/di/src/DI/PhpGenerator.php(47): Nette\DI\ContainerBuilder->complete()
#4 /Users/clemens/.composer/vendor/nette/di/src/DI/Compiler.php(257): Nette\DI\PhpGenerator->generate('Container_5a2e3...')
#5 /Users/clemens/.composer/vendor/nette/di/src/DI/Compiler.php(177): Nette\DI\Compiler->generateCode()
#6 /Users/clem in /Users/clemens/.composer/vendor/nette/di/src/DI/Helpers.php on line 122

Fatal error: Uncaught Nette\DI\ServiceCreationException: Multiple services of type PHPStan\Drupal\ServiceMap found: 128, 131 in /Users/clemens/.composer/vendor/nette/di/src/DI/ContainerBuilder.php:242
Stack trace:
#0 /Users/clemens/.composer/vendor/nette/di/src/DI/Helpers.php(120): Nette\DI\ContainerBuilder->getByType('PHPStan\\Drupal\\...', false)
#1 /Users/clemens/.composer/vendor/nette/di/src/DI/ContainerBuilder.php(641): Nette\DI\Helpers::autowireArguments(Object(ReflectionMethod), Array, Object(Nette\DI\ContainerBuilder))
#2 /Users/clemens/.composer/vendor/nette/di/src/DI/ContainerBuilder.php(577): Nette\DI\ContainerBuilder->completeStatement(Object(Nette\DI\Statement))
#3 /Users/clemens/.composer/vendor/nette/di/src/DI/PhpGenerator.php(47): Nette\DI\ContainerBuilder->complete()
#4 /Users/clemens/.composer/vendor/nette/di/src/DI/Compiler.php(257): Nette\DI\PhpGenerator->generate('Container_5a2e3...')
#5 /Users/clemens/.composer/vendor/nette/di/src/DI/Compiler.php(177): Nette\DI\Compiler->generateCode()
#6 /Users/clem in /Users/clemens/.composer/vendor/nette/di/src/DI/Helpers.php on line 122

Hope that helps?

@cloudstrife602

This comment has been minimized.

Copy link

commented Apr 18, 2019

I'm having a similar issue with a globally installed drupal-check. Whether I use composer require mglaman/drupal-check or via cgr with cgr require mglaman/drupal-check I get the same issue.

@mglaman

This comment has been minimized.

Copy link
Owner

commented Apr 18, 2019

Can you all please try the Phar? Composer global packages are just a nightmare.

@clemens-tolboom

This comment has been minimized.

Copy link

commented Apr 20, 2019

Can you all please try the Phar? Composer global packages are just a nightmare.

Maybe its best then to update the README.md as it offers 3 different ways and I prefer composer over phar so waisted your (and my) time :-)

I did composer global remove drupal-check then

d8 $ drupal-check.phar modules/contrib/external_entities/
\Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.

I have a git checkout of D8 which is not as per your instructions (composer create-project). I'm out for now.

@Sutharsan

This comment has been minimized.

Copy link

commented Apr 20, 2019

@mglaman

Can you all please try the Phar?

I have, with the above result. How to debug further?

@mglaman

This comment has been minimized.

Copy link
Owner

commented Apr 27, 2019

  • Global require has been fixed.
  • \Drupal::$container issue was fixed in phpstan-drupal and needs to be released.
@mglaman

This comment has been minimized.

Copy link
Owner

commented Apr 27, 2019

I'm closing this. As I think the root problem was drupal-check's own autoloader detection and I was assuming it had trouble finding Drupal's.

1.0.8 fixes composer global require installs.

@mglaman mglaman closed this Apr 27, 2019

@Johnzzon

This comment has been minimized.

Copy link

commented Apr 29, 2019

I have a somewhat similar problem. I'm trying to run drupal-check against modules inside a profile, which is required via composer.

$ drupal-check -vvv web/profiles/contrib/some-profile/modules
Current working directory: /some-project
Using Drupal root: /some-project/web/profiles/contrib/some-profile/web
Using vendor root: /some-project/web/profiles/contrib/some-profile/vendor

I'm guessing this comes from locating root from the path argument. Is it possible that drupal-check can locate root from the current directory from where we run the command instead?

$drupalFinder->locateRoot($path);

Maybe it's an issue with drupal-finder? Not sure how it determines the profile as root.

@Johnzzon

This comment has been minimized.

Copy link

commented Apr 29, 2019

I just tried changing to $drupalFinder->locateRoot(getcwd()); and that seems to work for me.

$ drupal-check -vvv web/profiles/contrib/some-profile/modules
Current working directory: /some-project
Using Drupal root: /some-project/web
Using vendor root: /some-project/vendor
Using autoloader: /some-project/vendor/autoload.php
@mglaman

This comment has been minimized.

Copy link
Owner

commented Apr 29, 2019

@Johnzzon can you open a new issue? I'd very curious why it thought the profile was the webroot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.