Scaffold Append Fails When Appended File Is Empty File

Created on 9 March 2023, about 2 years ago

Problem/Motivation

A developer had a file they had wanting the 'drupal-scaffold" to append to another core file. When they no longer needed that stuff appended, they updated the append file to be empty. The scaffold still included the old contents of the append file in error.

Steps to reproduce

I needed to add some code to the robots.txt file. So I created a file in the location assets/my-robots-additions.txt and added this to my composer.json file:

    "extra": {
        "drupal-scaffold": {
            "file-mapping": {
                "[web-root]/robots.txt": {
                    "append": "assets/my-robots-additions.txt"
                }
            }
        }
    }

When I run composer install, it adds the line(s) I had in the append file to the robots.txt file.

After a while, the extra line(s) were no longer needed. So just removed the lines in the append file. I did not change the composer.json, but the assets/my-robots-additions.txt was updated to empty.

The next time I run composer install, the contents of the robots.txt file does not change. The append file is empty, but the scaffolded file still has the lines that are no longer in the append file.

Workaround

If I remove the lines that says to append in the composer.json and run composer install, then it removes the appended data.

Or if I update the append file to include something (a comment, some other content, etc.) then it also works.

Proposed resolution

It would be helpful if the scaffold would work with an empty file to be appended. I haven't dug into the code, so I'm not sure how that can be changed.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

9.5

Component
ComposerΒ  β†’

Last updated about 11 hours ago

No maintainer
Created by

πŸ‡ΊπŸ‡ΈUnited States dandaman

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @dandaman
  • πŸ‡©πŸ‡ͺGermany hchonov πŸ‡ͺπŸ‡ΊπŸ‡©πŸ‡ͺπŸ‡§πŸ‡¬

    I can only confirm the issue as it happened to me as well.

  • Assigned to nlisgo
  • πŸ‡¬πŸ‡§United Kingdom nlisgo

    OK. So, I have been able to recreate this issue. It seems that when you empty the file assets/my-robots-additions.txt file completely (no spaces, no new lines) then it is treated as if no change was made to the file.

    The problem is with drupal/core-composer-scaffold. It is successful detecting all changes to scaffolding files except when it is completely empty.

    Adding needs test.

    Also, I would like to help with this one so I will assign to me for now.

    I'm not sure if the component "composer" is appropriate. I checked recent commits on this project and they have been either "base system" or "other".

  • πŸ‡¬πŸ‡§United Kingdom nlisgo

    I confirm this is also an issue with standard file mappings:

        "extra": {
            "drupal-scaffold": {
                "file-mapping": {
                    "[web-root]/robots.txt": "assets/my-robots-complete.txt"
                }
            }
        }
    

    If you modify the file assets/my-robots-complete.txt it will update but if you empty it completely it won't.

  • Pipeline finished with Failed
    about 17 hours ago
    Total: 386s
    #475747
  • πŸ‡¬πŸ‡§United Kingdom nlisgo
  • πŸ‡¬πŸ‡§United Kingdom nlisgo

    My comment in #5 should not be a distraction. It's a valuable observation but should lead to a different issue being raised. It is a separate operation to the one flagged in this issue.

  • Pipeline finished with Canceled
    about 11 hours ago
    Total: 149s
    #475987
  • πŸ‡¬πŸ‡§United Kingdom nlisgo

    Test has been added

  • Pipeline finished with Success
    about 11 hours ago
    Total: 1873s
    #475990
Production build 0.71.5 2024