Skip to content

Commit 26f6aa7

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

File tree

3 files changed

+102
-37
lines changed

3 files changed

+102
-37
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: 83 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ 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.
14-
* Modules (packages of type `drupal-module`) will be placed in `web/modules/contrib` directory.
15-
* Themes (packages of type `drupal-theme`) will be placed in `web/themes/contrib` directory.
16-
* Profiles (packages of type `drupal-profile`) will be placed in `web/profiles/contrib` directory.
14+
* Modules (packages of type `drupal-module`) will be placed
15+
in `web/modules/contrib` directory.
16+
* Themes (packages of type `drupal-theme`) will be placed
17+
in `web/themes/contrib` directory.
18+
* Profiles (packages of type `drupal-profile`) will be placed
19+
in `web/profiles/contrib` directory.
1720
* Creates default writable versions of `settings.php` and `services.yml`.
1821
* Creates `web/sites/default/files` directory.
1922
* Drush is installed for use as `vendor/bin/drush`.
@@ -22,9 +25,10 @@ dependencies with [Composer](https://getcomposer.org/).
2225
## Installing
2326

2427
> [!NOTE]
25-
> The instructions below refer to the [global Composer installation](https://getcomposer.org/doc/00-intro.md#globally).
26-
You might need to replace `composer` with `php composer.phar` (or similar)
27-
for your setup.
28+
> The instructions below refer to
29+
> the [global Composer installation](https://getcomposer.org/doc/00-intro.md#globally).
30+
> You might need to replace `composer` with `php composer.phar` (or similar)
31+
> for your setup.
2832
2933
Create your project:
3034

@@ -47,29 +51,70 @@ cd some-dir
4751
composer require drupal/devel
4852
```
4953

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

5294
This project will attempt to keep all of your Drupal Core files up-to-date; the
5395
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.
96+
is used to ensure that your scaffold files are updated every time `drupal/core`
97+
is updated.
5698

5799
If you customize any of the "scaffolding" files (commonly `.htaccess`),
58100
you may need to merge conflicts if any of your modified files are updated in a
59101
new release of Drupal core.
60102

61103
Follow the steps below to update your Drupal core files.
62104

63-
1. Run `composer update "drupal/core-*" --with-dependencies` to update Drupal Core and its dependencies.
105+
1. Run `composer update "drupal/core-*" --with-dependencies` to update Drupal
106+
Core and its dependencies.
64107
2. Run `git diff` to determine if any of the scaffolding files have changed.
65108
Review the files for any changes and restore any customizations to
66-
`.htaccess` or `robots.txt`.
109+
`.htaccess` or `robots.txt`.
67110
3. Commit everything all together in a single commit, so `web` will remain in
68111
sync with the `core` when checking out branches or running `git bisect`.
69112
4. In the event that there are non-trivial conflicts in step 2, you may wish
70113
to perform these steps on a branch, and use `git merge` to combine the
71114
updated core files with your customized files. This facilitates the use
72-
of a [three-way merge tool such as kdiff3](http://www.gitshah.com/2010/12/how-to-setup-kdiff-as-diff-tool-for-git.html). This setup is not necessary if your changes are simple;
115+
of
116+
a [three-way merge tool such as kdiff3](http://www.gitshah.com/2010/12/how-to-setup-kdiff-as-diff-tool-for-git.html).
117+
This setup is not necessary if your changes are simple;
73118
keeping all of your modifications at the beginning or end of the file is a
74119
good strategy to keep merges easy.
75120

@@ -83,24 +128,25 @@ workarounds if a project decides to do it anyway](https://getcomposer.org/doc/fa
83128
### Should I commit the scaffolding files?
84129

85130
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`
131+
plugin can download the scaffold files (like `index.php`, `update.php` etc.) to
132+
the `web` directory of your project. If you have not customized those files you
133+
could choose to not check them into your version control system (e.g. git).
134+
If that is the case for your project, it might be convenient to automatically
135+
run the drupal-scaffold plugin after every install or update of your project.
136+
You can achieve that by registering `@composer drupal:scaffold`
137+
as `post-install`
92138
and `post-update` command in your `composer.json`:
93139

94140
```json
95141
"scripts": {
96-
"post-install-cmd": [
97-
"@composer drupal:scaffold",
98-
"..."
99-
],
100-
"post-update-cmd": [
101-
"@composer drupal:scaffold",
102-
"..."
103-
]
142+
"post-install-cmd": [
143+
"@composer drupal:scaffold",
144+
"..."
145+
],
146+
"post-update-cmd": [
147+
"@composer drupal:scaffold",
148+
"..."
149+
]
104150
},
105151
```
106152

@@ -110,23 +156,24 @@ If you need to apply patches, you can do so with the
110156
[composer-patches](https://github.com/cweagans/composer-patches) plugin included
111157
in this project.
112158

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

116162
```json
117163
"extra": {
118-
"patches": {
119-
"drupal/foobar": {
120-
"Patch description": "URL or local path to patch"
121-
}
122-
}
164+
"patches": {
165+
"drupal/foobar": {
166+
"Patch description": "URL or local path to patch"
167+
}
168+
}
123169
}
124170
```
125171

126172
### How do I specify a PHP version?
127173

128174
There are 2 places where Composer will be looking for PHP version requirements
129175
when resolving dependencies:
176+
130177
1. The `require.php` version value in `composer.json`.
131178
2. The `config.platform` version value in `composer.json`.
132179

@@ -137,7 +184,7 @@ for a package. For example, the minimum version required for Drupal 11.0 is
137184
The purpose of `config.platform` is to set the PHP language requirements for the
138185
specific instance of the package running in the current environment. For
139186
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
187+
the actual PHP version on the hosting provider could be `8.3.1`. The value of
141188
this field should provide your exact version of PHP with all 3 parts of the
142189
version.
143190

@@ -153,8 +200,8 @@ that only the package versions supported by your current environment are used.
153200

154201
```json
155202
"config": {
156-
"platform": {
157-
"php": "8.3.1"
158-
}
203+
"platform": {
204+
"php": "8.3.1"
205+
}
159206
},
160207
```

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)