drupal-composer/drupal-project

Why does installing extra modules always reinstalls Drupal 7?

csandanov opened this issue · 1 comments

Perhaps this is a behaviour by design but I've recently stumbled upon a related issue with newer composer and decided to clarify.

I've installed this composer project with a slightly modifier composer.json:

{
    "name": "drupal-composer/drupal-project",
    "description": "Project template for Drupal 7 projects with composer",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "authors": [
        {
            "name": "",
            "role": ""
        }
    ],
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/7"
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "ext-curl": "*",
        "ext-gd": "*",
        "ext-json": "*",
        "ext-openssl": "*",
        "ext-pdo": "*",
        "ext-xml": "*",
        "composer/installers": "^1.9",
        "composer/semver": "^1.4",
        "cweagans/composer-patches": "^1.7",
        "drupal-composer/preserve-paths": "^0.1.6",
        "drupal/composer_autoloader": "^1.0",
        "drupal/drupal": "7.81",
        "drush/drush": "^8.0",
        "symfony/filesystem": "~2.7 || ^3",
        "webflo/drupal-finder": "^1.2.1"
    },
    "conflict": {
        "drupal/core": "8.*"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "sort-packages": true
    },
    "autoload": {
        "classmap": [
            "scripts/composer/ScriptHandler.php"
        ]
    },
    "scripts": {
        "pre-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "pre-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "post-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ],
        "post-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ],
        "post-create-project-cmd": [
            "DrupalProject\\composer\\ScriptHandler::removeInternalFiles"
        ]
    },
    "extra": {
        "installer-paths": {
            "web/": [
                "type:drupal-core"
            ],
            "web/profiles/{$name}/": [
                "type:drupal-profile"
            ],
            "web/sites/all/drush/{$name}/": [
                "type:drupal-drush"
            ],
            "web/sites/all/libraries/{$name}/": [
                "type:drupal-library"
            ],
            "web/sites/all/modules/contrib/{$name}/": [
                "type:drupal-module"
            ],
            "web/sites/all/themes/contrib/{$name}/": [
                "type:drupal-theme"
            ]
        },
        "patches-install-hooks": true,
        "patches": {
            "cweagans/composer-patches": {
                "Call the preserve paths hooks": "https://github.com/jcnventura/composer-patches/compare/1.x...jcnventura:fix-preserve-paths.diff"
            },
            "drupal/drupal": {
                "Redirect to install.php": "https://gist.githubusercontent.com/csandanov/72d6e5d9bfd857491a87fa9131e5728c/raw/bff270bea6f5a05779a4fcd5a570dc3e36bb25ca/drupal-7-install-php-redirect.patch"
            }
        },
        "preserve-paths": [
            "web/sites"
        ]
    }
}

If I install additional module in this composer projects it deletes ./web and re-downloads it again:

$ composer require -n -vvv drupal/redis
Reading ./composer.json (/var/www/html/composer.json)
Loading config file ./composer.json (/var/www/html/composer.json)
Checked CA file /etc/ssl/certs/ca-certificates.crt: valid
Executing command (/var/www/html): git branch -a --no-color --no-abbrev -v
Executing command (/var/www/html): git describe --exact-match --tags
Executing command (CWD): git --version
Executing command (/var/www/html): git log --pretty="%H" -n1 HEAD --no-show-signature
Executing command (/var/www/html): hg branch
Executing command (/var/www/html): fossil branch list
Executing command (/var/www/html): fossil tag list
Executing command (/var/www/html): svn info --xml
Reading /home/wodby/.composer/composer.json
Loading config file /home/wodby/.composer/composer.json (/home/wodby/.composer/composer.json)
Reading /var/www/html/vendor/composer/installed.json
Reading /home/wodby/.composer/vendor/composer/installed.json
Loading plugin Composer\Installers\Plugin (from composer/installers)
Loading plugin cweagans\Composer\Patches (from cweagans/composer-patches)
Loading plugin DrupalComposer\PreservePaths\Plugin (from drupal-composer/preserve-paths)
Running 2.0.14 (2021-05-21 17:03:37) with PHP 7.4.20 on Linux / 5.10.25-linuxkit
Downloading https://packages.drupal.org/7/packages.json
[200] https://packages.drupal.org/7/packages.json
Writing /home/wodby/.composer/cache/repo/https---packages.drupal.org-7/packages.json into cache
Downloading https://packages.drupal.org/files/packages/7/p2/drupal/redis.json
Downloading https://packages.drupal.org/files/packages/7/p2/drupal/redis~dev.json
[200] https://packages.drupal.org/files/packages/7/p2/drupal/redis.json
Writing /home/wodby/.composer/cache/repo/https---packages.drupal.org-7/provider-drupal~redis.json into cache
[200] https://packages.drupal.org/files/packages/7/p2/drupal/redis~dev.json
Writing /home/wodby/.composer/cache/repo/https---packages.drupal.org-7/provider-drupal~redis~dev.json into cache
Using version ^3.18 for drupal/redis
./composer.json has been updated
Reading ./composer.json (/var/www/html/composer.json)
Loading config file ./composer.json (/var/www/html/composer.json)
Executing command (/var/www/html): git branch -a --no-color --no-abbrev -v
Executing command (/var/www/html): git describe --exact-match --tags
Executing command (/var/www/html): git log --pretty="%H" -n1 HEAD --no-show-signature
Executing command (/var/www/html): hg branch
Executing command (/var/www/html): fossil branch list
Executing command (/var/www/html): fossil tag list
Executing command (/var/www/html): svn info --xml
Reading /home/wodby/.composer/composer.json
Loading config file /home/wodby/.composer/composer.json (/home/wodby/.composer/composer.json)
Reading /var/www/html/vendor/composer/installed.json
Reading /home/wodby/.composer/vendor/composer/installed.json
Loading plugin Composer\Installers\Plugin_composer_tmp0 (from composer/installers)
Loading plugin cweagans\Composer\Patches_composer_tmp1 (from cweagans/composer-patches)
Loading plugin DrupalComposer\PreservePaths\Plugin_composer_tmp2 (from drupal-composer/preserve-paths)
Running composer update drupal/redis
Reading ./composer.lock (/var/www/html/composer.lock)
> pre-update-cmd: cweagans\Composer\Patches_composer_tmp1->checkPatches
Gathering patches for root package.
Removing package cweagans/composer-patches so that it can be re-installed and re-patched.
Unloading plugin cweagans\Composer\Patches_composer_tmp1
Uninstalling plugin cweagans\Composer\Patches_composer_tmp1
  - Removing cweagans/composer-patches (1.7.0)
Executing command (CWD): rm -rf '/var/www/html/vendor/cweagans/composer-patches'
Removing package drupal/drupal so that it can be re-installed and re-patched.
  - Removing drupal/drupal (7.81.0)
Executing command (CWD): rm -rf 'web'
Deleting web/ - deleted
> pre-update-cmd: DrupalProject\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Downloading https://packages.drupal.org/7/packages.json
[200] https://packages.drupal.org/7/packages.json
Writing /home/wodby/.composer/cache/repo/https---packages.drupal.org-7/packages.json into cache
Reading /home/wodby/.composer/cache/repo/https---packages.drupal.org-7/provider-drupal~redis.json from cache
Downloading https://packages.drupal.org/files/packages/7/p2/drupal/redis.json if modified
Reading /home/wodby/.composer/cache/repo/https---packages.drupal.org-7/provider-drupal~redis~dev.json from cache
Downloading https://packages.drupal.org/files/packages/7/p2/drupal/redis~dev.json if modified
[304] https://packages.drupal.org/files/packages/7/p2/drupal/redis~dev.json
[304] https://packages.drupal.org/files/packages/7/p2/drupal/redis.json
Updating dependencies
Generating rules
Resolving dependencies through SAT
Looking at all rules.

Dependency resolution completed in 0.001 seconds
Analyzed 151 packages to resolve dependencies
Analyzed 202 rules to resolve dependencies
Lock file operations: 1 install, 0 updates, 0 removals
Installs: drupal/redis:3.18.0
  - Locking drupal/redis (3.18.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Reading ./composer.lock (/var/www/html/composer.lock)
Package operations: 3 installs, 0 updates, 0 removals
Installs: cweagans/composer-patches:1.7.0, drupal/drupal:7.81.0, drupal/redis:3.18.0
  - Downloading cweagans/composer-patches (1.7.0)
Downloading https://api.github.com/repos/cweagans/composer-patches/zipball/ae02121445ad75f4eaff800cc532b5e6233e2ddf
  - Downloading drupal/drupal (7.81.0)
Downloading https://ftp.drupal.org/files/projects/drupal-7.81.zip
  - Downloading drupal/redis (3.18.0)
Downloading https://ftp.drupal.org/files/projects/redis-7.x-3.18.zip
[200] https://ftp.drupal.org/files/projects/redis-7.x-3.18.zip
Writing /home/wodby/.composer/cache/files/drupal/redis/0d6f0a8d597d8339c8a3b5f41c1911127394be1c.zip into cache from /var/www/html/vendor/composer/tmp-97c790771a96a0ceec4911d14ac54fb3.zip
[302] https://api.github.com/repos/cweagans/composer-patches/zipball/ae02121445ad75f4eaff800cc532b5e6233e2ddf
Following redirect (1) https://codeload.github.com/cweagans/composer-patches/legacy.zip/ae02121445ad75f4eaff800cc532b5e6233e2ddf
[200] https://ftp.drupal.org/files/projects/drupal-7.81.zip
Writing /home/wodby/.composer/cache/files/drupal/drupal/7e3a5b801c90222e7dfab472c1ffaaf77ab0c4c0.zip into cache from /var/www/html/vendor/composer/tmp-436a25b634328b86beb6a4ce947d3826.zip
[200] https://codeload.github.com/cweagans/composer-patches/legacy.zip/ae02121445ad75f4eaff800cc532b5e6233e2ddf
Writing /home/wodby/.composer/cache/files/cweagans/composer-patches/5b4c5bf2f828875dd013dfc62fcd65f410c18371.zip into cache from /var/www/html/vendor/composer/tmp-cd1fb312626fbd84afcd02c7aeedbf8f
> pre-package-install: DrupalComposer\PreservePaths\Plugin_composer_tmp2->prePackage
  - Installing cweagans/composer-patches (1.7.0): Extracting archive
Executing async command (CWD): unzip -qq  '/var/www/html/vendor/composer/tmp-cd1fb312626fbd84afcd02c7aeedbf8f' -d '/var/www/html/vendor/composer/d45a8e49'
Executing command (CWD): rm -rf '/var/www/html/vendor/cweagans/composer-patches'
Executing command (CWD): rm -rf '/var/www/html/vendor/composer/d45a8e49'
Loading plugin cweagans\Composer\Patches_composer_tmp3 (from cweagans/composer-patches)
> post-package-install: cweagans\Composer\Patches_composer_tmp3->postInstall
No patches found for cweagans/composer-patches.
> post-package-install: DrupalComposer\PreservePaths\Plugin_composer_tmp2->postPackage
> pre-package-install: DrupalComposer\PreservePaths\Plugin_composer_tmp2->prePackage
> pre-package-install: cweagans\Composer\Patches_composer_tmp3->gatherPatches
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
Found 1 patches for cweagans/composer-patches.
Found 1 patches for drupal/drupal.
  - Installing drupal/drupal (7.81.0): Extracting archive
Executing async command (CWD): unzip -qq  '/var/www/html/vendor/composer/tmp-436a25b634328b86beb6a4ce947d3826.zip' -d '/var/www/html/vendor/composer/1d708f53'
> pre-package-install: DrupalComposer\PreservePaths\Plugin_composer_tmp2->prePackage
> pre-package-install: cweagans\Composer\Patches_composer_tmp3->gatherPatches
Patches already gathered. Skipping
  - Installing drupal/redis (3.18.0): Extracting archive
Executing async command (CWD): unzip -qq  '/var/www/html/vendor/composer/tmp-97c790771a96a0ceec4911d14ac54fb3.zip' -d '/var/www/html/vendor/composer/4f26e819'
Executing command (CWD): rm -rf 'web/sites/all/modules/contrib/redis'
Executing command (CWD): rm -rf '/var/www/html/vendor/composer/4f26e819'
Executing command (CWD): rm -rf '/var/www/html/vendor/composer/1d708f53'
> post-package-install: cweagans\Composer\Patches_composer_tmp3->postInstall
  - Applying patches for drupal/drupal
    https://gist.githubusercontent.com/csandanov/72d6e5d9bfd857491a87fa9131e5728c/raw/bff270bea6f5a05779a4fcd5a570dc3e36bb25ca/drupal-7-install-php-redirect.patch (Redirect to install.php)
Downloading https://gist.githubusercontent.com/csandanov/72d6e5d9bfd857491a87fa9131e5728c/raw/bff270bea6f5a05779a4fcd5a570dc3e36bb25ca/drupal-7-install-php-redirect.patch
patch '-p1' --no-backup-if-mismatch -d 'web/' < '/tmp/60bef9891a512.patch'
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d 'web/' < '/tmp/60bef9891a512.patch'
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- includes/bootstrap.inc	(revision f1c0124ff5118a1b66bff99fb45bd5c3ed5acbab)
|+++ includes/bootstrap.inc	(revision )
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
patch unexpectedly ends in middle of line

1 out of 1 hunk ignored

patch '-p0' --no-backup-if-mismatch -d 'web/' < '/tmp/60bef9891a512.patch'
Executing command (CWD): patch '-p0' --no-backup-if-mismatch -d 'web/' < '/tmp/60bef9891a512.patch'
patching file includes/bootstrap.inc
patch unexpectedly ends in middle of line

Hunk #1 succeeded at 2761 with fuzz 1 (offset 16 lines).


> post-package-install: DrupalComposer\PreservePaths\Plugin_composer_tmp2->postPackage
Files of installed package were overwritten with preserved path /var/www/html/web/sites!
> post-package-install: cweagans\Composer\Patches_composer_tmp3->postInstall
No patches found for drupal/redis.
> post-package-install: DrupalComposer\PreservePaths\Plugin_composer_tmp2->postPackage
Downloading https://packagist.org/downloads/
Downloading https://packages.drupal.org/7/downloads
[200] https://packages.drupal.org/7/downloads
[201] https://packagist.org/downloads/
Generating autoload files
16 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> post-update-cmd: DrupalProject\composer\ScriptHandler::createRequiredFiles
Created a sites/default/files directory with chmod 0777

With the newer composer 2.1.1+ it also deletes ./web but for some reason doesn't re-download it without reporting any errors, I reported this as a bug at composer/composer#9952

Why does it deletes and re-downloads it in the first place despite me not changing composer.json?

It's a bug, fix discussed in cweagans/composer-patches#363