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

Removing a provider breaks Acorn until removing the packages cache #270

Closed
retlehs opened this issue Feb 10, 2023 · 4 comments · Fixed by #295
Closed

Removing a provider breaks Acorn until removing the packages cache #270

retlehs opened this issue Feb 10, 2023 · 4 comments · Fixed by #295
Labels
bug Something isn't working

Comments

@retlehs
Copy link
Member

retlehs commented Feb 10, 2023

Adding and then removing a service provider breaks Acorn until the packages cache is removed:

  1. composer require spatie/laravel-ignition
  2. wp acorn package:discover
  3. composer remove spatie/laravel-ignition

Error:

In Application.php line 354:

  Skipping provider [Spatie\LaravelIgnition\IgnitionServiceProvider] because it does not exist.

Workaround:

  1. rm cache/acorn/framework/cache/packages.php
  2. wp acorn optimize
@retlehs retlehs added the bug Something isn't working label Feb 10, 2023
@yCodeTech
Copy link

yCodeTech commented Apr 25, 2023

Can we get this fixed ASAP please. I'm pretty sure wp acorn optimize:clear should remove all files in the cache including the packages.php and services.php, currently it doesn't remove those files. This needs resolving.

@dsturm
Copy link
Contributor

dsturm commented Apr 25, 2023

Hej @yCodeTech, please feel free to open a PR on this, so one can review it.

@yCodeTech
Copy link

@dsturm I'm not skilled in this type of development, so I can not fix it and submit a pr.

@chrillep
Copy link
Contributor

chrillep commented Jun 18, 2023

did some digging and laravels default method is not invoking a new Process of the command via cli. Its removing the cache files in the same instance.

https://github.com/laravel/framework/blob/e217dca49e20cd2840970f8d307c8392012bc5be/src/Illuminate/Foundation/ComposerScripts.php#L48-L69

While acorn is initiating new Process of wp acorn cli command. It fails returning exit code 1. Since the Provider may have been removed when executing.

$console->clearCompiled();

/**
* Execute acorn clear-compiled command.
*
* @return int
*/
public function clearCompiled(): int
{
return $this->acorn('clear-compiled');
}

/**
* Execute acorn command.
*
* @param array $command
* @return int
*/
public function acorn($command): int
{
$command = array_merge($this->findWpCli(), ['acorn'], (array) $command);
return $this->getProcess($command)->run();
}

Possible solution.

Reuse laravels method and make sure

getCachedConfigPath() resolves to
{projectpath}/storage/framework/cache/config.php

getCachedServicesPath() resolves to
{projectpath}/storage/framework/cache/services.php

getCachedPackagesPath() resolves to
{projectPath}/storage/framework/cache/packages.php

instead of
{projectpath}/bootstrap/cache/config.php
{projectpath}/bootstrap/cache/services.php
{projectPath}/bootstrap/cache/packages.php

/src/Roots/Acorn/ComposerScripts.php

<?php

namespace Roots\Acorn;

use Illuminate\Foundation\ComposerScripts as FoundationComposerScripts;

class ComposerScripts extends FoundationComposerScripts
{
    /**
     * Clear the cached Laravel bootstrapping files.
     *
     * @return void
     */
    protected static function clearCompiled()
    {
        $laravel = new \Roots\Acorn\Application(getcwd(), ['bootstrap' => getcwd() .'/storage/framework']);
        
        if (is_file($configPath = $laravel->getCachedConfigPath())) {
            @unlink($configPath);
        }

        if (is_file($servicesPath = $laravel->getCachedServicesPath())) {
            @unlink($servicesPath);
        }

        if (is_file($packagesPath = $laravel->getCachedPackagesPath())) {
            @unlink($packagesPath);
        }

    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants