Skip to content

Fall back to parent directory if composer.json not found in module directory #8990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 2, 2017
Merged

Fall back to parent directory if composer.json not found in module directory #8990

merged 10 commits into from
Aug 2, 2017

Conversation

schmengler
Copy link
Contributor

@schmengler schmengler commented Mar 23, 2017

Description

This change allows modules to follow the pds/skeleton standard and have their source code in a src subdirectory of the repository.

Manual testing scenarios

  1. create a module with composer.json and registration.php in the root directory and source code in src

    registration.php

    \Magento\Framework\Component\ComponentRegistrar::register(
        \Magento\Framework\Component\ComponentRegistrar::MODULE,
        'Vendor_Module',
        __DIR__ . '/src'
    );
    

    composer.json

      "autoload": {
        "files": [
          "registration.php"
        ],
        "psr-4": {
          "Vendor\\Module\\": "src"
        }
      },
      "suggest": {
        "vendor/module-sample-data": "Sample Data version:1.0.0"
      },
    
  2. call bin/magento sampledata:deploy and see if vendor/module-sample-data is going to be installed.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

Kept in constructor for backwards compatibility
…ample data suggestions

This allows modules to follow the pds/skeleton standard and have their source code in a 'src' subdirectory of the repository
@schmengler
Copy link
Contributor Author

Another case where Magento reads composer.json files from modules is \Magento\Framework\Module\PackageInfo. This is a bit more complicated to change and test, so it would be a different PR

@fooman
Copy link
Contributor

fooman commented Mar 24, 2017

hey @schmengler love the direction of this PR. It is currently already possible to have the code under src/ with the registration file sitting under src/registration.php and then reference it from a root composer.json file as src/registration.php. The only place where this falls over as you mentioned is in \Magento\Framework\Module\PackageInfo (I currently solve it by providing an alternative src/composer.json which is not ideal).

I had looked into this here #3400. My current thought to solve this across the board would be to add a new optional param to \Magento\Framework\Component\ComponentRegistrar::register() which holds the composer.json file location which can then be used in PackageInfo to find the correct file. If empty it's assumed to be in the same folder as registration.php (aka current behaviour).

@schmengler
Copy link
Contributor Author

@fooman Good idea with the optional parameter, that would give even more flexibility! Putting registration.php in src was my first approach too but I remember this caused trouble because of assumptions in Magento. Duplicating composer.json is a workaround but that cannot be the solution

@okorshenko okorshenko self-assigned this Jul 17, 2017
@okorshenko okorshenko added this to the July 2017 milestone Jul 17, 2017
@okorshenko
Copy link
Contributor

Hi @schmengler thank you for your contribution. Could you please fix broken static tests. Also we are getting Fatal error with this changes.
PHP Fatal error: Uncaught Error: Cannot instantiate interface Magento\Framework\Filesystem\DriverInterface
Could you please verify your changes. Thank you

@okorshenko okorshenko modified the milestones: July 2017, August 2017 Aug 1, 2017
@magento-team magento-team merged commit c053bcc into magento:develop Aug 2, 2017
magento-team pushed a commit that referenced this pull request Aug 2, 2017
magento-team pushed a commit that referenced this pull request Aug 2, 2017
magento-team pushed a commit that referenced this pull request Aug 2, 2017
@Ctucker9233
Copy link

@magento-team can this be ported to 2.2?

magento-devops-reposync-svc pushed a commit that referenced this pull request Jun 25, 2024
@fooman fooman removed their assignment Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants