laravel / valet

A more enjoyable local development experience for Mac.
https://laravel.com/docs/valet
MIT License
2.52k stars 698 forks source link

My extensions all stopped working after upgrading to v4 #1453

Closed vesper8 closed 1 year ago

vesper8 commented 1 year ago

Description

I made a post about two years ago https://github.com/laravel/valet/issues/1067

In which I asked how it would be possible to append a path to the url when using valet open and I received lots of good responses which all revolved around creating an extension to accommodate this.

@drbyte gave me an excellent snippet of code that I've used ever since https://github.com/laravel/valet/issues/1067#issuecomment-859213590

<?php

use function Valet\output;

$app->command('open [domain] [-a|--append=]', function ($domain = null, $append = null) {
    $url = "http://".($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld'];
    if (!empty($append)) $url .= $append;
    CommandLine::runAsUser("open ".escapeshellarg($url));
})->descriptions('Open the site for the current (or specified) directory in your browser', [
    'domain' => 'Domain to open',
    '--append' => 'Optional URI to [append]',
]);

Now I just upgraded to v4 and noticed my extensions stopped working. I don't actually see any notes in the v4 release saying that extensions were affected, I do notice that extensions are no longer mentioned in the Laravel docs.

Was this dropped? Is there a workaround?

I want to be able to alias a command such as nova which will use valet open to open the current site and append /nova/resources/users to the opened URL.

Would love to know how I can continue to achieve this feature that I use multiple times a day.

Many thanks

Steps To Reproduce

See above

Diagnosis

not relevant

drbyte commented 1 year ago

In the rebuild of Valet for v4, support for Extensions was set aside in the interest of getting the core functionality released.

drbyte commented 1 year ago

You can manually reinstate the Extensions feature with a direct edit to the Valet source files, as shown below.

  1. Keep your Extensions in ~/.config/valet/Extensions directory.
  2. Edit ~/.composer/vendor/laravel/valet/cli/valet.app as shown here:
    
    require_once __DIR__.'/app.php';
    +
    +$extensions = glob(VALET_HOME_PATH . '/Extensions/*.php');
    +foreach ($extensions as $extension) {
    +    require_once $extension;
    +}

/**

Since the affected file won't likely be touched by most future minor releases, you probably won't have to redo this very often. But you probably will be prompted by Composer to keep/delete/stash your changes every time you run composer global update to upgrade your Valet. Just choose "stash", and it should successfully stash and pull and unstash the updates without difficulty, since this file is unlikely to be touched.

Your existing Extensions for Valet 3 will most likely work fine on Valet 4, unless they were using features of $app that have changed over time. Again, unlikely.

AND, as before, any Extensions that add commands whose names match (ie: clash with) Valet's own commands, will replace Valet's originals with yours. Not recommended. But if you were doing that before, you may want to upgrade your commands to newer syntax/features in cli/app.php and re-apply your customizations.

And if your custom commands had cloned any Valet commands and then added/changed functionality of them, double-check the originals to see if there are any updates to apply to your cloned commands.

vesper8 commented 1 year ago

Thank you so much @drbyte !

It would be nice if extensions could be reinstated.. especially if doing so is as simple as suggested above..

driesvints commented 1 year ago

Right now we don't have any plans to reinstate those sorry. But it seems to be easy to do so yourself 👍