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

Publish assets with Composer hook #554

Closed
driesvints opened this issue Mar 21, 2019 · 23 comments
Closed

Publish assets with Composer hook #554

driesvints opened this issue Mar 21, 2019 · 23 comments

Comments

@driesvints
Copy link
Member

We're currently getting a lot of issues where people forgot to update their Horizon assets. Technically it should be possible for us to implement a Composer hook in the composer.json command that runs php artisan horizon:assets so updated assets get published.

@drbyte
Copy link

drbyte commented Mar 21, 2019

It may be similarly prudent to specifically mention appropriate upgrade steps in the docs at
https://laravel.com/docs/5.8/horizon#installation

@driesvints
Copy link
Member Author

@drbyte I was thinking to do that first but if we can automate this then this is unnecessary.

@drbyte
Copy link

drbyte commented Mar 21, 2019

True, but docs also help with troubleshooting when automation goes awry. :)

@driesvints
Copy link
Member Author

Yeah, true. You can send in a PR if you want :)

@drbyte
Copy link

drbyte commented Mar 21, 2019

Done

@barryvdh
Copy link
Contributor

barryvdh commented Sep 9, 2019

What do you think about something like this? laravel/telescope#729

Eg. show a warning when the assets are out-of-date. Still requires a manual step but at least people are warned.

I don't think composer hooks work for non-root projects.

@driesvints
Copy link
Member Author

Hmm I'm not sure if something like that should make its way into the actual UI.

I don't think composer hooks work for non-root projects.

Yeah I'm not sure either. I need to look into this but bit swamped atm.

@barryvdh
Copy link
Contributor

barryvdh commented Sep 9, 2019

Yeah the alternative is not publishing it, but loading the assets through a controller, example: https://github.com/fruitcake/laravel-telescope-toolbar/blob/master/src/Http/Controllers/ToolbarController.php#L67-L86

@barryvdh
Copy link
Contributor

barryvdh commented Sep 9, 2019

Hmm I'm not sure if something like that should make its way into the actual UI.

Why shouldn't it make the way into the UI? It's only visible when it's outdated and a relatively simple check to prevent common errors.

@driesvints
Copy link
Member Author

driesvints commented Sep 9, 2019

Because you're displaying an implementation detail in an app. Imo the app shouldn't have any knowledge about how the ui is build. This is a slippery slope imo.

@fgilio
Copy link

fgilio commented Sep 9, 2019

I personally don't find it bad for the UI to help with this. But of course, if this can be avoided altogether that would be the best solution.
Maybe adding a command similar to php artisan package:discover but that takes care of re publishing all packages assets. It would only work out of the box for new Laravel installs.

@driesvints
Copy link
Member Author

I still think we can solve this with Composer hooks.

@barryvdh
Copy link
Contributor

barryvdh commented Sep 9, 2019

https://getcomposer.org/doc/articles/scripts.md

Note: Only scripts defined in the root package's composer.json are executed. If a dependency of the root package specifies its own scripts, Composer does not execute those additional scripts.

@driesvints
Copy link
Member Author

I was more thinking of setting a hook on the composer.json of the app itself. Like a note in the docs to add it to your composer.json

@barryvdh
Copy link
Contributor

Yeah you can do that, but it will publish for all updates (not just this one). Not that it matters much.

@driesvints
Copy link
Member Author

@barryvdh you can filter by service provider or tag

@barryvdh
Copy link
Contributor

Oh yeah I mean you can just put php artisan horizon:assets in there:

"scripts": {
    "post-update-cmd": [
        "@php artisan horizon:assets"
    ]
}

But it will publish on each composer update, not just for when Horizon updates (but it also doesn't changes much when its not updated).

@driesvints
Copy link
Member Author

ah yeah. Gotcha. I indeed think it's not that big of a deal if you're not overriding anything. If you're overriding the templates you probably don't want to add it.

@barryvdh
Copy link
Contributor

So, no interest in adding a warning like in Telescope?

@mpskovvang
Copy link

mpskovvang commented Apr 7, 2020

@driesvints Did you find any downsides from automatically publishing the assets when updating the package? I'm one of them constantly forgetting doing so manually and first notices in production and has to redeploy.

Perhaps the post-package-update script could be useful? Apparently, it only fires when the package itself is updated?

@drbyte
Copy link

drbyte commented Apr 7, 2020

I've been doing this the same way Livewire suggests it, by hooking post-autoload-dump:
"@php artisan vendor:publish --force --tag=livewire:assets --ansi"

@driesvints
Copy link
Member Author

@drbyte yeah I saw that as well. Might be a good solution.

@driesvints
Copy link
Member Author

I've opted for the suggestion by @drbyte to note this in the docs of Horizon and Telescope: laravel/docs#6230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants