Skip to content

Commit 4013e3f

Browse files
committed
[#278] Added support for Asset packagist.
1 parent 0404d8a commit 4013e3f

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ jobs:
6363
- name: Validate composer.json structure
6464
run: composer normalize --dry-run
6565

66+
- name: Require bower-asset
67+
run: |
68+
test ! -d web/libraries/dropzone
69+
composer require bower-asset/dropzone
70+
test -d web/libraries/dropzone
71+
6672
# @see https://www.drupal.org/node/3176567
6773
- name: Install testing dependency
6874
if: ${{ matrix.php-versions == '8.1' }}

README.md

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,50 @@ cd some-dir
5050
composer require drupal/devel
5151
```
5252

53+
### Adding libraries
54+
55+
You can manage front-end asset libraries with Composer thanks to the
56+
[asset-packagist repository](https://asset-packagist.org/). Composer will detect
57+
and install new versions of a library that meet the stated constraints.
58+
59+
```bash
60+
composer require bower-asset/dropzone
61+
```
62+
63+
### Custom installation paths for libraries
64+
65+
The installation path of a specific library can be controlled by adding it to
66+
the `extra.installer-paths` configuration preceding `web/libraries/{$name}`.
67+
For example, the `chosen` Drupal module expects the `chosen` library to be
68+
located on `web/libraries/chosen`, but `composer require npm-asset/chosen-js`
69+
installs the library into `web/libraries/chosen-js`. The following configuration
70+
overrides installation it into the expected directory:
71+
72+
```json
73+
{
74+
"extra": {
75+
"installer-paths": {
76+
"web/libraries/chosen": [
77+
"npm-asset/chosen-js"
78+
],
79+
"web/libraries/{$name}": [
80+
"type:drupal-library",
81+
"type:npm-asset",
82+
"type:bower-asset"
83+
]
84+
}
85+
}
86+
}
87+
```
88+
89+
For more details, see https://asset-packagist.org/site/about
90+
5391
### Updating Drupal Core
5492

5593
This project will attempt to keep all of your Drupal Core files up-to-date; the
5694
project [drupal/core-composer-scaffold](https://github.com/drupal/core-composer-scaffold)
57-
is used to ensure that your scaffold files are updated every time `drupal/core`
58-
is updated.
95+
is used to ensure that your scaffold files are updated every time `drupal/core`
96+
is updated.
5997

6098
If you customize any of the "scaffolding" files (commonly `.htaccess`),
6199
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
86124
### Should I commit the scaffolding files?
87125

88126
The [Drupal Composer Scaffold](https://github.com/drupal/core-composer-scaffold)
89-
plugin can download the scaffold files (like `index.php`, `update.php` etc.) to
90-
the `web` directory of your project. If you have not customized those files you
91-
could choose to not check them into your version control system (e.g. git).
92-
If that is the case for your project, it might be convenient to automatically
93-
run the drupal-scaffold plugin after every install or update of your project.
94-
You can achieve that by registering `@composer drupal:scaffold` as `post-install`
127+
plugin can download the scaffold files (like `index.php`, `update.php` etc.) to
128+
the `web` directory of your project. If you have not customized those files you
129+
could choose to not check them into your version control system (e.g. git).
130+
If that is the case for your project, it might be convenient to automatically
131+
run the drupal-scaffold plugin after every install or update of your project.
132+
You can achieve that by registering `@composer drupal:scaffold` as `post-install`
95133
and `post-update` command in your `composer.json`:
96134

97135
```json
@@ -113,7 +151,7 @@ If you need to apply patches, you can do so with the
113151
[composer-patches](https://github.com/cweagans/composer-patches) plugin included
114152
in this project.
115153

116-
To add a patch to Drupal module `foobar`, insert the `patches` section in the
154+
To add a patch to Drupal module `foobar`, insert the `patches` section in the
117155
`extra` section of `composer.json`:
118156

119157
```json
@@ -134,14 +172,14 @@ when resolving dependencies:
134172
2. The `config.platform` version value in `composer.json`.
135173

136174
The purpose of `require.php` is to set the minimum PHP language requirements
137-
for a package. For example, the minimum version required for Drupal 10.0 is
175+
for a package. For example, the minimum version required for Drupal 10.0 is
138176
`8.0.2` or above, which can be specified as `>=8`.
139177

140178
The purpose of `config.platform` is to set the PHP language requirements for the
141179
specific instance of the package running in the current environment. For
142-
example, while the minimum version required for Drupal 10 is `8.0.2` or above,
143-
the actual PHP version on the hosting provider could be `8.1.0`. The value of
144-
this field should provide your exact version of PHP with all 3 parts of the
180+
example, while the minimum version required for Drupal 10 is `8.0.2` or above,
181+
the actual PHP version on the hosting provider could be `8.1.0`. The value of
182+
this field should provide your exact version of PHP with all 3 parts of the
145183
version.
146184

147185
#### Which versions to specify in my Drupal site?
@@ -150,8 +188,8 @@ This project includes `drupal/core` which already has `require.php` added. Your
150188
would inherit that constraint. There is no need to add `require.php` to your
151189
`composer.json`.
152190

153-
`config.platform` is a platform-specific. It is recommended to specify
154-
`config.platform` as a _specific version_ (e.g.`8.1.19`) constraint to ensure
191+
`config.platform` is a platform-specific. It is recommended to specify
192+
`config.platform` as a _specific version_ (e.g.`8.1.19`) constraint to ensure
155193
that only the package versions supported by your current environment are used.
156194

157195
```json

composer.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"drupal/core-composer-scaffold": "^10.2.0",
1616
"drupal/core-recommended": "^10.2.0",
1717
"drush/drush": "^12.4.3",
18+
"oomphinc/composer-installers-extender": "^2.0",
1819
"vlucas/phpdotenv": "^5.1",
1920
"webflo/drupal-finder": "^1.2"
2021
},
@@ -29,6 +30,10 @@
2930
{
3031
"type": "composer",
3132
"url": "https://packages.drupal.org/8"
33+
},
34+
{
35+
"type": "composer",
36+
"url": "https://asset-packagist.org"
3237
}
3338
],
3439
"minimum-stability": "dev",
@@ -48,6 +53,7 @@
4853
"dealerdirect/phpcodesniffer-composer-installer": true,
4954
"drupal/core-composer-scaffold": true,
5055
"ergebnis/composer-normalize": true,
56+
"oomphinc/composer-installers-extender": true,
5157
"php-http/discovery": true,
5258
"phpstan/extension-installer": true
5359
},
@@ -66,7 +72,9 @@
6672
"type:drupal-core"
6773
],
6874
"web/libraries/{$name}": [
69-
"type:drupal-library"
75+
"type:drupal-library",
76+
"type:bower-asset",
77+
"type:npm-asset"
7078
],
7179
"web/modules/contrib/{$name}": [
7280
"type:drupal-module"
@@ -81,6 +89,10 @@
8189
"type:drupal-drush"
8290
]
8391
},
92+
"installer-types": [
93+
"bower-asset",
94+
"npm-asset"
95+
],
8496
"patchLevel": {
8597
"drupal/core": "-p2"
8698
},

0 commit comments

Comments
 (0)