headroom.js icon indicating copy to clipboard operation
headroom.js copied to clipboard

Add a composer.json file to make headroom.js installable as part of a drupal module

Open CuriousCactus opened this issue 6 years ago • 8 comments

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"
}

CuriousCactus avatar Jun 14 '19 07:06 CuriousCactus

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

WickyNilliams avatar Aug 12 '19 14:08 WickyNilliams

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?

CuriousCactus avatar Aug 28 '19 10:08 CuriousCactus

Why would you manage JS dependencies with Composer and not NPM?

hacknug avatar Aug 28 '19 11:08 hacknug

That's what I'm wondering too. Why not npm/yarn?

WickyNilliams avatar Aug 28 '19 11:08 WickyNilliams

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...

CuriousCactus avatar Aug 28 '19 12:08 CuriousCactus

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-composer
  • composer require --prefer-dist WickyNilliams/headroom.js: https://drupal.stackexchange.com/questions/260754/how-to-require-a-js-library-in-a-composer-json-file

hacknug avatar Aug 28 '19 15:08 hacknug

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

WickyNilliams avatar Aug 28 '19 15:08 WickyNilliams

@CuriousCactus hey, do you have anything to add?

WickyNilliams avatar Sep 13 '19 15:09 WickyNilliams