symfony / webpack-encore-bundle

Symfony integration with Webpack Encore!
https://symfony.com/webpack-encore
MIT License
939 stars 83 forks source link

recipe update not working #215

Closed ehymel closed 1 year ago

ehymel commented 1 year ago

After updating to version 2.0, the command composer recipes indicates there is an updated recipe to run. Doing so fails:

$ composer recipes:update
Which outdated recipe would you like to update? (default: 0)
  [0] symfony/webpack-encore-bundle
 >
  Updating recipe for symfony/webpack-encore-bundle...

There was an error applying the recipe update patch
Command "git update-index --refresh" failed: "". Output: "templates/base.html.twig: needs update
".

Update the recipe by re-installing the latest version with:
  composer recipes:install symfony/webpack-encore-bundle --force -v

When I run the suggested command, it reverts my app.js, package.json, and webpack.config.js files to what I assume are the default files, thus losing all the changes needed for my application.

weaverryan commented 1 year ago

Hmm. Ok, 2 things are happening here:

1) Command "git update-index --refresh" failed: "". Output: "templates/base.html.twig: needs update

That looks weird - that shouldn't be a failure that we have. However, I can't repeat it locally. Was your templates/base.html.twig file somehow modified... or in a conflicted state... or anything weird when you ran this command? It shouldn't be possible, but that's generally what that needs update error means. I can't figure out why that would happen normally.

2) When I run the suggested command, it reverts my app.js, package.json, and webpack.config.js files

This is actually ok - just revert those changes. It is, unfortunately, going to be a weird recipe update because we moved some files in the recipe to a different recipe. So when you update, it looks to Flex like those files were deleted from this recipe. More details here - https://github.com/symfony/webpack-encore-bundle/releases/tag/v2.0.0

ehymel commented 1 year ago

On point 2... thanks, noted.

For point 1... My templates/base.html.twig file is not in a conflicted state that I can see.

The update script (whether using the straight recipes:update command or the recipes:install --force version) makes only two changes, both of which created odd changes with duplicated lines and wrong indentation. The change are in the {% block stylesheets %} and {% block javascripts %} sections, like so...

From this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %}{% endblock %}</title>

    {% block stylesheets %}
        {{ encore_entry_link_tags('app') }}
    {% endblock %}

    {% block javascripts %}
        {{ encore_entry_script_tags('app') }}
    {% endblock %}
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>

to this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %}{% endblock %}</title>

    {% block stylesheets %}
            {{ encore_entry_link_tags('app') }}
        {{ encore_entry_link_tags('app') }}
    {% endblock %}

    {% block javascripts %}
            {{ encore_entry_script_tags('app') }}
        {{ encore_entry_script_tags('app') }}
    {% endblock %}
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>

This is not a huge deal and I can fix/ignore the issue given your clarification on point 2. Thanks very much.

weaverryan commented 1 year ago

Hmm, I think those duplications are also another, unfortunate, result of how I moved the recipes around. I'm not sure why the patch failed, but I think those also need to be ignored.

I wish we could have reorganized the recipes in a way that did NOT cause these problems, but it wasn't possible. This issue will likely be referenced by others who have the same questions.