Skip to content

Commit 1905706

Browse files
committed
[#278] Added support for Asset packagist.
1 parent 13ac14d commit 1905706

File tree

3 files changed

+69
-13
lines changed

3 files changed

+69
-13
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
- name: Override Drupal version to dev for testing dev releases
6773
if: matrix.drupal-release == 'dev'
6874
run: |

README.md

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies with [Composer](https://getcomposer.org/).
99
## What does the template do?
1010

1111
* Drupal will be installed in the `web` directory.
12-
* Generated composer autoloader `vendor/autoload.php` is used instead of
12+
* Generated composer autoloader `vendor/autoload.php` is used instead of
1313
`web/vendor/autoload.php` provided by Drupal core.
1414
* Modules (packages of type `drupal-module`) will be placed in `web/modules/contrib` directory.
1515
* Themes (packages of type `drupal-theme`) will be placed in `web/themes/contrib` directory.
@@ -47,12 +47,50 @@ cd some-dir
4747
composer require drupal/devel
4848
```
4949

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

5290
This project will attempt to keep all of your Drupal Core files up-to-date; the
5391
project [drupal/core-composer-scaffold](https://github.com/drupal/core-composer-scaffold)
54-
is used to ensure that your scaffold files are updated every time `drupal/core`
55-
is updated.
92+
is used to ensure that your scaffold files are updated every time `drupal/core`
93+
is updated.
5694

5795
If you customize any of the "scaffolding" files (commonly `.htaccess`),
5896
you may need to merge conflicts if any of your modified files are updated in a
@@ -63,7 +101,7 @@ Follow the steps below to update your Drupal core files.
63101
1. Run `composer update "drupal/core-*" --with-dependencies` to update Drupal Core and its dependencies.
64102
2. Run `git diff` to determine if any of the scaffolding files have changed.
65103
Review the files for any changes and restore any customizations to
66-
`.htaccess` or `robots.txt`.
104+
`.htaccess` or `robots.txt`.
67105
3. Commit everything all together in a single commit, so `web` will remain in
68106
sync with the `core` when checking out branches or running `git bisect`.
69107
4. In the event that there are non-trivial conflicts in step 2, you may wish
@@ -83,12 +121,12 @@ workarounds if a project decides to do it anyway](https://getcomposer.org/doc/fa
83121
### Should I commit the scaffolding files?
84122

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

94132
```json
@@ -110,7 +148,7 @@ If you need to apply patches, you can do so with the
110148
[composer-patches](https://github.com/cweagans/composer-patches) plugin included
111149
in this project.
112150

113-
To add a patch to Drupal module `foobar`, insert the `patches` section in the
151+
To add a patch to Drupal module `foobar`, insert the `patches` section in the
114152
`extra` section of `composer.json`:
115153

116154
```json
@@ -137,7 +175,7 @@ for a package. For example, the minimum version required for Drupal 11.0 is
137175
The purpose of `config.platform` is to set the PHP language requirements for the
138176
specific instance of the package running in the current environment. For
139177
example, while the minimum version required for Drupal 11 is `8.3` or above,
140-
the actual PHP version on the hosting provider could be `8.3.1`. The value of
178+
the actual PHP version on the hosting provider could be `8.3.1`. The value of
141179
this field should provide your exact version of PHP with all 3 parts of the
142180
version.
143181

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": "^11@alpha",
1616
"drupal/core-recommended": "^11@alpha",
1717
"drush/drush": "^13@beta",
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)