diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 675722f37..8c38ab803 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,12 @@ jobs: - name: Validate composer.json structure run: composer normalize --dry-run + - name: Require bower-asset + run: | + test ! -d web/libraries/dropzone + composer require bower-asset/dropzone + test -d web/libraries/dropzone + # @see https://www.drupal.org/node/3176567 - name: Install testing dependency if: ${{ matrix.php-versions == '8.1' }} diff --git a/README.md b/README.md index 962e82219..86fb96aac 100644 --- a/README.md +++ b/README.md @@ -50,12 +50,50 @@ cd some-dir composer require drupal/devel ``` +### Adding libraries + +You can manage front-end asset libraries with Composer thanks to the +[asset-packagist repository](https://asset-packagist.org/). Composer will detect +and install new versions of a library that meet the stated constraints. + +```bash +composer require bower-asset/dropzone +``` + +### Custom installation paths for libraries + +The installation path of a specific library can be controlled by adding it to +the `extra.installer-paths` configuration preceding `web/libraries/{$name}`. +For example, the `chosen` Drupal module expects the `chosen` library to be +located on `web/libraries/chosen`, but `composer require npm-asset/chosen-js` +installs the library into `web/libraries/chosen-js`. The following configuration +overrides installation it into the expected directory: + +```json +{ + "extra": { + "installer-paths": { + "web/libraries/chosen": [ + "npm-asset/chosen-js" + ], + "web/libraries/{$name}": [ + "type:drupal-library", + "type:npm-asset", + "type:bower-asset" + ] + } + } +} +``` + +For more details, see https://asset-packagist.org/site/about + ### Updating Drupal Core This project will attempt to keep all of your Drupal Core files up-to-date; the project [drupal/core-composer-scaffold](https://github.com/drupal/core-composer-scaffold) -is used to ensure that your scaffold files are updated every time `drupal/core` -is updated. +is used to ensure that your scaffold files are updated every time `drupal/core` +is updated. If you customize any of the "scaffolding" files (commonly `.htaccess`), you may need to merge conflicts if any of your modified files are updated in a @@ -86,12 +124,12 @@ workarounds if a project decides to do it anyway](https://getcomposer.org/doc/fa ### Should I commit the scaffolding files? The [Drupal Composer Scaffold](https://github.com/drupal/core-composer-scaffold) -plugin can download the scaffold files (like `index.php`, `update.php` etc.) to -the `web` directory of your project. If you have not customized those files you -could choose to not check them into your version control system (e.g. git). -If that is the case for your project, it might be convenient to automatically -run the drupal-scaffold plugin after every install or update of your project. -You can achieve that by registering `@composer drupal:scaffold` as `post-install` +plugin can download the scaffold files (like `index.php`, `update.php` etc.) to +the `web` directory of your project. If you have not customized those files you +could choose to not check them into your version control system (e.g. git). +If that is the case for your project, it might be convenient to automatically +run the drupal-scaffold plugin after every install or update of your project. +You can achieve that by registering `@composer drupal:scaffold` as `post-install` and `post-update` command in your `composer.json`: ```json @@ -113,7 +151,7 @@ If you need to apply patches, you can do so with the [composer-patches](https://github.com/cweagans/composer-patches) plugin included in this project. -To add a patch to Drupal module `foobar`, insert the `patches` section in the +To add a patch to Drupal module `foobar`, insert the `patches` section in the `extra` section of `composer.json`: ```json @@ -134,14 +172,14 @@ when resolving dependencies: 2. The `config.platform` version value in `composer.json`. The purpose of `require.php` is to set the minimum PHP language requirements -for a package. For example, the minimum version required for Drupal 10.0 is +for a package. For example, the minimum version required for Drupal 10.0 is `8.0.2` or above, which can be specified as `>=8`. The purpose of `config.platform` is to set the PHP language requirements for the specific instance of the package running in the current environment. For -example, while the minimum version required for Drupal 10 is `8.0.2` or above, -the actual PHP version on the hosting provider could be `8.1.0`. The value of -this field should provide your exact version of PHP with all 3 parts of the +example, while the minimum version required for Drupal 10 is `8.0.2` or above, +the actual PHP version on the hosting provider could be `8.1.0`. The value of +this field should provide your exact version of PHP with all 3 parts of the version. #### Which versions to specify in my Drupal site? @@ -150,8 +188,8 @@ This project includes `drupal/core` which already has `require.php` added. Your would inherit that constraint. There is no need to add `require.php` to your `composer.json`. -`config.platform` is a platform-specific. It is recommended to specify -`config.platform` as a _specific version_ (e.g.`8.1.19`) constraint to ensure +`config.platform` is a platform-specific. It is recommended to specify +`config.platform` as a _specific version_ (e.g.`8.1.19`) constraint to ensure that only the package versions supported by your current environment are used. ```json diff --git a/composer.json b/composer.json index 5859756f6..d7e5ec803 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "drupal/core-composer-scaffold": "^10.2.0", "drupal/core-recommended": "^10.2.0", "drush/drush": "^12.4.3", + "oomphinc/composer-installers-extender": "^2.0", "vlucas/phpdotenv": "^5.1", "webflo/drupal-finder": "^1.2" }, @@ -29,6 +30,10 @@ { "type": "composer", "url": "https://packages.drupal.org/8" + }, + { + "type": "composer", + "url": "https://asset-packagist.org" } ], "minimum-stability": "dev", @@ -48,6 +53,7 @@ "dealerdirect/phpcodesniffer-composer-installer": true, "drupal/core-composer-scaffold": true, "ergebnis/composer-normalize": true, + "oomphinc/composer-installers-extender": true, "php-http/discovery": true, "phpstan/extension-installer": true }, @@ -66,7 +72,9 @@ "type:drupal-core" ], "web/libraries/{$name}": [ - "type:drupal-library" + "type:drupal-library", + "type:bower-asset", + "type:npm-asset" ], "web/modules/contrib/{$name}": [ "type:drupal-module" @@ -81,6 +89,10 @@ "type:drupal-drush" ] }, + "installer-types": [ + "bower-asset", + "npm-asset" + ], "patchLevel": { "drupal/core": "-p2" },