grasmash / composerize-drupal

Convert a non-Composer-managed Drupal application (e.g., one created via tarball) to a Composer-managed Drupal application.
MIT License
125 stars 20 forks source link

Undefined index: version #10

Closed berenddeboer closed 5 years ago

berenddeboer commented 5 years ago

When running this I get:

composer composerize-drupal --composer-root=/home/berend/src/tmp/docroot --drupal-root=/home/berend/src/tmp/docroot/
Created composer.json

  [ErrorException]          
  Undefined index: version  

composerize-drupal [--composer-root COMPOSER-ROOT] [--drupal-root DRUPAL-ROOT] [--exact-versions] [--no-update]

And annoyingly removes all my composer.json files.

I've tried the patch which described a similar situation, but that didn't help nor give me any more information.

berenddeboer commented 5 years ago

Some more info: this happened to me with the link_css module where I had installed the git version, i.e. not installed using composer require.

MCDELTAT commented 5 years ago

This is affecting me as well and I would appreciate some feedback. I'm currently stuck because trying to install the drupal/smtp module fails with the following error:

  Problem 1
    - remove drupal/drupal dev-8084_smtp_emails|remove drupal/core 8.6.1
    - don't install drupal/core 8.6.1|remove drupal/drupal dev-8084_smtp_emails
    - don't install drupal/core 8.6.1|remove drupal/drupal dev-8084_smtp_emails
    - Installation request for drupal/drupal dev-8084_smtp_emails -> satisfiable by drupal/drupal[dev-8084_smtp_emails].
    - Installation request for drupal/core (locked at 8.6.1, required as ^8.6) -> satisfiable by drupal/core[8.6.1].

We've seen this error before and it's because the template for the site was originally created with the drupal/drupal method and needs to be brought over. So I can't install the module and then this won't let me update to a good working state.

Running composer composerize-drupal --no-update produces this error:

[ErrorException]          
  Undefined index: version 

Here's my original composer.json file:

{
    "name": "drupal/drupal",
    "description": "Drupal is an open source content management platform powering millions of websites and applications.",
    "type": "project",
    "license": "GPL-2.0-or-later",
    "require": {
        "composer/installers": "^1.0.24",
        "wikimedia/composer-merge-plugin": "^1.4",
        "drupal/socialfeed": "^1.0@beta",
        "drupal/socialmediafeed": "1.x-dev",
        "drupal/social_feed_fetcher": "^1.0@beta",
        "drupal/geolocation": "2.x-dev",
    "drupal/core": "^8.6",
        "drush/drush": "^9.4",
        "drupal/view_unpublished": "^1.0@alpha"
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "config": {
        "preferred-install": "dist",
        "autoloader-suffix": "Drupal8"
    },
    "extra": {
        "_readme": [
            "By default Drupal loads the autoloader from ./vendor/autoload.php.",
            "To change the autoloader you can edit ./autoload.php.",
            "This file specifies the packages.drupal.org repository.",
            "You can read more about this composer repository at:",
            "https://www.drupal.org/node/2718229"
        ],
        "merge-plugin": {
            "include": [
                "core/composer.json",
        "modules/contrib/datatables/composer.json"
            ],
            "recurse": true,
            "replace": false,
            "merge-extra": false
        },
        "installer-paths": {
            "core": ["type:drupal-core"],
            "modules/contrib/{$name}": ["type:drupal-module"],
            "profiles/contrib/{$name}": ["type:drupal-profile"],
            "themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"],
            "modules/custom/{$name}": ["type:drupal-custom-module"],
            "themes/custom/{$name}": ["type:drupal-custom-theme"]
        }
    },
    "autoload": {
        "psr-4": {
            "Drupal\\Core\\Composer\\": "core/lib/Drupal/Core/Composer"
        }
    },
    "scripts": {
        "pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
        "post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
        "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
        "drupal-phpunit-upgrade-check": "Drupal\\Core\\Composer\\Composer::upgradePHPUnit",
        "drupal-phpunit-upgrade": "@composer update phpunit/phpunit --with-dependencies --no-progress",
        "phpcs": "phpcs --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --",
        "phpcbf": "phpcbf --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --"
    },
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ]
}

@seldeak you've been super helpful with issue like this in the past. Ideas?

MCDELTAT commented 5 years ago

Hope everyone had a good new year. I managed to resolve my issue, but this should remain open.

I tried to figure out at what point this script was stopping, and so compared it against a site where this was working. It made it's way through creating a composer.json in the subfolders, and reorganizing the root composer.json. The only major thing that was missing was the contents of my require block, which I manually copied back from the contents of my last push on Github. After that, I can build my site successfully and pass all of the tests. More importantly it allowed me to run composer require drupal/smtp without getting an error, so I'm grateful for that. I can try to get more information if possible, but can't submit a PR until I'm more certain what the issue is.

grasmash commented 5 years ago

Resolved in https://github.com/grasmash/composerize-drupal/commit/0fdd38ffee99373ceb32df91c9c8f5e4106b1c68

This was caused by the geolocation module in your case. Since it is a dev version, it has no version listed in its yaml file. I've added support for dev versions.

MCDELTAT commented 5 years ago

@grasmash Thanks so much. Will keep recommending the tool where it fits.