Add composer.json file for better local development experience

Created on 28 March 2025, 5 days ago

Problem/Motivation

When developing custom modules there are several scenarios that require the developer to add a composer.json file to their module. Some of these scenarios depend upon whether the custom module is intended to be contributed back to the community as a project on drupal.org. Here are some reasons for creating a composer.json file

https://www.drupal.org/docs/develop/using-composer/add-a-composerjson-file β†’

Steps to reproduce

Proposed resolution

Add a composer.json file

Remaining tasks

Approve and merge

User interface changes

N/A

API changes

N/A

Data model changes

N/A

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ

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

Comments & Activities

  • Issue created by @trackleft2
  • πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ

    While working on other issues I found that this module does not contain a composer.json which makes it difficult to work in the way that I would like to locally. For example here is my .lando.yml file:

    name: media_migration
    recipe: drupal10
    config:
      php: '8.3'
      via: apache:2.4
      webroot: web
      database: mariadb:10.6
      xdebug: false
    services:
      database:
        type: compose
        services:
          image: mariadb:10.6
          command: docker-entrypoint.sh mariadbd
          restart: always
          ports:
            - '3306'
          environment:
            MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 'true'
            MARIADB_DATABASE: drupal10
            MYSQL_DATABASE: drupal10
            MARIADB_USER: drupal10
            MARIADB_PASSWORD: drupal10
      appserver:
        overrides:
          environment:
            SIMPLETEST_DB: 'mysql://drupal10:drupal10@database/drupal10'
            SIMPLETEST_BASE_URL: 'http://appserver'
          volumes:
            # Don't share our host working directory as /app. We want /app empty for composer.
            - /app
            # Instead share our host working directory as a standalone package.
            - .:/usr/local/media_migration
        build:
          # Create a new Drupal project and use the module as a non-packagist repository.
          - composer create-project --dev drupal/recommended-project:11.1.x /app
          - composer config extra.enable-patching true
          - composer config extra.composer-exit-on-patch-failure true
          - composer config allow-plugins.cweagans/composer-patches true
          - composer require cweagans/composer-patches
          - composer config minimum-stability dev
          - composer config allow-plugins.phpstan/extension-installer true
          - composer require --dev drupal/core-dev:^11.1 drush/drush phpspec/prophecy-phpunit:* phpstan/extension-installer mglaman/phpstan-drupal phpstan/phpstan-deprecation-rules drupal/config_inspector drupal/devel drupal/gin
          - composer config repositories.localdev path /usr/local/media_migration && composer require drupal/media_migration:\*@dev
      node:
        type: node:20
        build:
          - yarn install
      chromedriver:
        type: compose
        services:
          image: seleniarm/standalone-chromium:4.1.4-20220429
          command: /opt/bin/entry_point.sh
    tooling:
      # Provide a command to install Drupal.
      install:
        service: appserver
        cmd:
          - /app/vendor/bin/drush --root=/app/web site:install --account-mail=noreply@example.com --account-name=admin --account-pass=admin --db-url=mysql://drupal10:drupal10@database:3306/drupal10 -y --verbose
          - /app/vendor/bin/drush en -y media_migration devel config_inspector
      # Provide Drush tooling to automatically know the Drupal root.
      drush:
        service: appserver
        cmd: /app/vendor/bin/drush --root=/app/web
      phpcs:
        service: appserver
        cmd: /app/vendor/bin/phpcs -s --colors --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/contrib/media_migration
      # Provide PHPCBF tooling to fix coding standards.
      phpcbf:
        service: appserver
        cmd: /app/vendor/bin/phpcbf -s --colors --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/contrib/media_migration
      # Provide phpstan tooling to check for code quality and deprecated code.
      phpstan:
        service: appserver
        cmd: /app/vendor/bin/phpstan analyse --configuration web/modules/contrib/media_migration/phpstan.neon web/modules/contrib/media_migration
      # Provide phpunit tooling to run unit tests.
      phpunit:
        service: appserver
        cmd: /app/vendor/bin/phpunit --configuration /app/web/core/phpunit.xml.dist --bootstrap /app/web/core/tests/bootstrap.php /app/web/modules/contrib/media_migration
      yarn:
        service: node
        cmd: yarn
      eslint:
        service: node
        cmd: yarn run eslint --color
    
    
  • πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ
  • πŸ‡ΊπŸ‡ΈUnited States trackleft2 Tucson, AZ πŸ‡ΊπŸ‡Έ

    Oops, I saw the composer.json when I downloaded the repo.

Production build 0.71.5 2024