zodiacmedia / drupal-libraries-installer

Install Drupal libraries via a simple listing in your composer.json file
https://packagist.org/packages/zodiacmedia/drupal-libraries-installer
5 stars 6 forks source link

Support short hash in composer install #6

Closed h1nds1ght closed 2 years ago

h1nds1ght commented 2 years ago

Under https://github.com/zodiacmedia/drupal-libraries-installer#alternate-method you describe an alternative way to include a library if it has no tags.

To mitigate against this issue, you should always download a specific commit version rather than from a branch like master

Now, if you do this and insert a specific commit in drupal-libraries, i.e.

        "drupal-libraries": {
            "chosen": "https://github.com/harvesthq/chosen/archive/91041bc9dd6867f9a1668050a1b092d92027f13b.zip"
        }

and perform a composer install, actually the following is displayed:

  - Downloading drupal-library/chosen (91041)
  - Installing drupal-library/chosen (91041): Extracting archive

In this case I would expect that the short hash of this commit 91041bc is displayed.

Would it be possible to detect the sha1 i.e. with a regex and then display the short hash when performing a composer install?

codebymikey commented 2 years ago

It's certainly possible, the library picking up 91041 in the first place is unintended behaviour with the regex trying to automatically detect version numbers from the URL.

If a specific version is required, then the user may provide a detailed definition instead like this:

"drupal-libraries": {
  "chosen": {
    "url": "https://github.com/harvesthq/chosen/archive/91041bc9dd6867f9a1668050a1b092d92027f13b.zip"
    "version": "91041bc"
  }
}

That being said, I'm not sure what the side effect of putting a non-numeric value as a composer version could cause, happy to take in a PR with tests if there's no documented side effect of making the switch.

But since it's a superficial change, I'm leaning towards not implementing this as there's a known workaround for users who require the short hash behaviour.