Ensure the destination directory exists when using an AppendOp over an existing ReplaceOp

Created on 30 July 2021, almost 3 years ago
Updated 15 February 2023, over 1 year ago

Problem/Motivation

With drupal/core-composer-scaffold, when you use a specific file mapping in your project's composer.json, you can replace all the ReplaceOp happening inside a sub folder. When that is the case, the subfolder is not created and it can prevent other op like AppendOp to work

Steps to reproduce

Use the following composer.json and run composer install (you also need to have a assets/default-settings-php-additions.txt file at the root of your project):

{
    "name": "drupal/recommended-project",
    "description": "Project template for Drupal projects with a relocated document root",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "homepage": "https://www.drupal.org/project/drupal",
    "support": {
        "docs": "https://www.drupal.org/docs/user_guide/en/index.html",
        "chat": "https://www.drupal.org/node/314178"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^2.0",
        "drupal/core-composer-scaffold": "^10.0",
        "drupal/core-project-message": "^10.0",
        "drupal/core-recommended": "^10.0"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "stable",
    "prefer-stable": true,
    "config": {
        "allow-plugins": {
            "composer/installers": true,
            "drupal/core-composer-scaffold": true,
            "drupal/core-project-message": true,
            "phpstan/extension-installer": true,
            "dealerdirect/phpcodesniffer-composer-installer": true
        },
        "sort-packages": true
    },
    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "web/"
            },
            "file-mapping": {
                "[web-root]/.csslintrc": false,
                "[web-root]/.eslintignore": false,
                "[web-root]/.eslintrc.json": false,
                "[web-root]/.ht.router.php": false,
                "[web-root]/example.gitignore": false,
                "[web-root]/INSTALL.txt": false,
                "[web-root]/README.md": false,
                "[web-root]/update.php": false,
                "[web-root]/web.config": false,
                "[web-root]/sites/README.txt": false,
                "[web-root]/sites/development.services.yml": false,
                "[web-root]/sites/example.settings.local.php": false,
                "[web-root]/sites/example.sites.php": false,
                "[web-root]/sites/default/default.services.yml": false,
                "[web-root]/modules/README.txt": false,
                "[web-root]/profiles/README.txt": false,
                "[web-root]/themes/README.txt": false,
                "[web-root]/sites/default/default.settings.php": {
                    "mode": "append",
                    "append": "assets/default-settings-php-additions.txt"
                }
            }
        },
        "installer-paths": {
            "web/core": [
                "type:drupal-core"
            ],
            "web/libraries/{$name}": [
                "type:drupal-library"
            ],
            "web/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "web/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "web/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "web/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "web/profiles/custom/{$name}": [
                "type:drupal-custom-profile"
            ],
            "web/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        },
        "drupal-core-project-message": {
            "include-keys": [
                "homepage",
                "support"
            ],
            "post-create-project-cmd-message": [
                "<bg=blue;fg=white>                                                         </>",
                "<bg=blue;fg=white>  Congratulations, you’ve installed the Drupal codebase  </>",
                "<bg=blue;fg=white>  from the drupal/recommended-project template!          </>",
                "<bg=blue;fg=white>                                                         </>",
                "",
                "<bg=yellow;fg=black>Next steps</>:",
                "  * Install the site: https://www.drupal.org/docs/installing-drupal",
                "  * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
                "  * Get support: https://www.drupal.org/support",
                "  * Get involved with the Drupal community:",
                "      https://www.drupal.org/getting-involved",
                "  * Remove the plugin that prints this message:",
                "      composer remove drupal/core-project-message"
            ]
        }
    }
}

You will get the following error :

Proposed resolution

The attached MR

Remaining tasks

Review, discussions and validation

πŸ› Bug report
Status

Needs work

Version

10.0 ✨

Component
ComposerΒ  β†’

Last updated about 20 hours ago

No maintainer
Created by

πŸ‡¨πŸ‡­Switzerland epieddy

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Can the MR please be updated for D10
    Also appears there was a test failure that will have to be addressed

    Since this is a bug wonder if it will need a test case.

  • πŸ‡¨πŸ‡­Switzerland epieddy

    I updated the issue description to match Drupal 10.0.x (the issue is still present with 10.0.3)

  • Status changed to Needs review over 1 year ago
  • πŸ‡¨πŸ‡­Switzerland epieddy

    I've updated the MR to Drupal Core 10.0.x and all the tests passes.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Convinced more this will need a test case.

    Also issue summary should be updated with proposed solution.

Production build 0.69.0 2024