headroom.js
headroom.js copied to clipboard
Add a composer.json file to make headroom.js installable as part of a drupal module
I created a fork of this repo so I could add a composer.json file, so that it can be correctly installed using composer for use with this Drupal module.
The issue discussing this is here.
The user would then need to add the code below to their project's composer.json file.
(replace curiouscactus with wickynilliams if you accept this pull request, both in the code below and in the composer.json file I added)
"repositories": [
{
"type": "vcs",
"url": "https://github.com/CuriousCactus/headroomjs"
}
],
"require": {
"curiouscactus/headroomjs": "v0.9.5",
"drupal/headroomjs": "^1.0@beta"
}
Hmm is this necessary? Why is there a need for explicit support for drupal? Excuse my ignorance, I'm totally unfamliar with Drupal and its ecosystem
Sorry for the slow reply. This is not strictly a Drupal-specific change. It allows headroom.js to be required using composer, (a common php package manager), so that php projects can declare a dependency on it. Does that make sense?
Why would you manage JS dependencies with Composer and not NPM?
That's what I'm wondering too. Why not npm/yarn?
An issue on the Drupal project (https://www.drupal.org/project/headroomjs/issues/3019252) implied that this was the way to do it, but on reflection I wonder if the main aim was to make it install to a /libraries folder, rather than /node-modules. Their installation process is quite manual (https://www.drupal.org/project/headroomjs) and I was attempting to make it more standard, but maybe I went about it the wrong way...
Not sure I understand how Drupal deals with this 100% but it seems like this would require dist/ to be published on the repo so we don't need the headroom.js you added at the root of the project.
Still not 100% sure this is the way to go. Some things online seem to show it's possible to install dependencies directly from NPM/GitHub via something like this:
composer require npm-asset/headroom.js: https://lightning.acquia.com/blog/round-your-front-end-javascript-libraries-composercomposer require --prefer-dist WickyNilliams/headroom.js: https://drupal.stackexchange.com/questions/260754/how-to-require-a-js-library-in-a-composer-json-file
I'd rather find a solution that doesn't involve adding new config files to the repo.
Is the goal here to simplify installing the drupal headroom project? If so, I would recommend changing the install steps to avoid getting and extracting a zip from github, and instead get all the (published) files from unpkg.com:
- https://unpkg.com/headroom.js/dist/headroom.js
- https://unpkg.com/headroom.js/dist/jQuery.headroom.js
@CuriousCactus hey, do you have anything to add?