Change require custom libraries to suggestions as a better method with more options

Created on 12 August 2024, 3 months ago
Updated 18 September 2024, 2 months ago

Problem/Motivation

After πŸ“Œ Install jquery.fancytree via Composer instead of CDN Fixed

The current method, is forcing all projects to add the following to "repositories" to the composer.json file

    "jquery.fancytree": {
      "type": "package",
      "package": {
        "name": "jquery/fancytree",
        "version": "2.38.3",
        "type": "drupal-library",
        "extra": {
          "installer-name": "jquery.fancytree"
        },
        "dist": {
          "url": "https://github.com/mar10/fancytree/archive/refs/tags/v2.38.3.zip",
          "type": "zip"
        },
        "license": "MIT"
      }
    }

Steps to reproduce

Adding "drupal/taxonomy_manager": "2.0.13" in the composer.json file
and composer update
will bring the following error

Dependency resolution completed in 0.026 seconds
Downloading https://packagist.org/providers/jquery/fancytree.json
[200] https://packagist.org/providers/jquery/fancytree.json
Downloading https://packagist.org/providers/jquery/fancytree.json
[200] https://packagist.org/providers/jquery/fancytree.json
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires drupal/taxonomy_manager 2.0.13 -> satisfiable by drupal/taxonomy_manager[2.0.13].
    - drupal/taxonomy_manager 2.0.13 requires jquery/fancytree ^2.38 -> could not be found in any version, there may be a typo in the package name.
  Problem 2
    - drupal/taxonomy_manager 2.0.13 requires jquery/fancytree ^2.38 -> could not be found in any version, there may be a typo in the package name.

Proposed resolution

Suggesting to switch to a better options
Add the library as a suggestion in the composer.json file.

Option #3

The Node packaging method

The module could only have suggestions (hints) in composer, and hook requirements in code to ask for adding the library before enabling.

Remaining tasks

  • File an issue
  • MR
  • Test
  • Review

User interface changes

API changes

Data model changes

✨ Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Rajab Natshah
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    OPTION #2 is my preferred method

    The jquery.fancytree library is in https://www.npmjs.com
    Which allows us to get npm-asset/jquery.fancytree using the composer

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    OPTION #2:

    Define npm-asset repository in the composer.json file, to allow downloading the CKEditor Anchor Link JavaScript library to the correct folder:

    1. Configure with composer commands by following steps.

    composer config repositories.assets composer https://asset-packagist.org
    composer config --unset repositories.0
    composer config repositories.drupal composer https://packages.drupal.org/8
    composer config --json extra.installer-types '["npm-asset", "bower-asset"]'
    composer config --json extra.installer-paths.web\/libraries\/fancytree '["npm-asset/jquery.fancytree"]'
    composer config --unset extra.installer-paths.web\/libraries\/\{\$name\}
    composer config --json extra.installer-paths.web\/libraries\/\{\$name\} '["type:drupal-library", "type:bower-asset", "type:npm-asset"]'
    

    2. Require the composer installer extender

    composer require oomphinc/composer-installers-extender
    

    3. Require the JQuery Fancytree library

    composer require npm-asset/jquery.fancytree:~2
    

    Check that you have the library in the libraries folder.

    4. Require Taxonomy Manager module

    composer require drupal/taxonomy_manager:~2
    

    5. Enable the Taxonomy Manager module with Drush

    drush en taxonomy_manager
    
  • Status changed to Needs review 3 months ago
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • πŸ‡¨πŸ‡¦Canada joelpittet Vancouver

    Thank you so much for all the work you’ve put into helping out with this project @rajab natshah β€” it’s greatly appreciated! I understand this might be a preference issue, but I would love to keep my node packages managed by NPM and my PHP packages by composer.

    Would it be possible to avoid making this a composer dependency or to make it optional? So a #3 option to the proposal?

    For context, I manage my NPM packages in my project root and then copy the necessary files from node_modules to WEB_ROOT/libraries.

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    I see this nice option JoΓ«l . I agree to move our methods to your logic.

    Option #3

    The Node packaging method

    It could be called the NPM/Yarn method (the name of the method could be changed). The module could only have suggestions (hints) in composer, and hook requirements in code to ask for adding the library before enabling.

    I see this Option #3 added to modules like CKEditor Anchor Link β†’ or Ace Code Editor β†’

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    The method is doable.

    I use the following in a theme

      "scripts": {
        "theme:init": "webpack --progress --config  webpack.config.init.js",
    

    Which webpack.config.init.js copy only what we need to the target location

    Something like Copy Drupal Libraries may work as a default in projects.

      "scripts": {
        "copy-drupal-libraries": "webpack --progress --config  webpack.config.copy-drupal-libraries.js",
    
    const { merge } = require('webpack-merge');
    const path = require("path");
    const webpackConfig = require('./webpack.config');
    const CopyPlugin = require("copy-webpack-plugin");
    
    module.exports = merge(webpackConfig, {
      mode: 'development',
      devtool: false,
      plugins: [
        new CopyPlugin({
          patterns: [
            {
              from: path.resolve(__dirname, "node_modules/jquery.fancytree/*"),
              to: path.resolve(__dirname, "web/libraries/fancytree"),
              context: "node_modules/jquery.fancytree",
            }
          ],
        }),
      ],
    });
    
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • Status changed to Needs work 2 months ago
  • πŸ‡¦πŸ‡ΊAustralia VladimirAus Brisbane, Australia

    Thanks @rajab natshah, I'm updating module to use both library and CDN as there were a lot of confusion.

    Another method would be including the library with the module.
    I also added successor library issue: ✨ Adding library with module, possible successor library Active

  • πŸ‡¦πŸ‡ΊAustralia VladimirAus Brisbane, Australia

    Seems like some updates broke the widget functionality.
    Not working on both 10.3 and 11.0 😞
    Investigating

  • πŸ‡¨πŸ‡¦Canada bsuttis

    @vladimiraus I found the patch at https://www.drupal.org/project/taxonomy_manager/issues/3474919 πŸ› Form element taxonomy_manager_tree broken RTBC fixed the broken functionality.

    The MR patch here (#3467549) combined with the MR patch there (#3474919) has it working via CDN in my tests.

    To use the fancytree library locally, I find I still have to edit my project's main composer.json like so:

    ...
            "merge-plugin": {
                "include": [
                    "docroot/modules/custom/*/composer.json",
                    "docroot/modules/contrib/taxonomy_manager/composer.libraries.json"
                ],
            },
    ...
    

    (note: I have wikimedia/composer-merge-plugin installed)

    and then run composer require fancytree/fancytree -W to install it locally to /docroot/libraries. Is this the correct process?

  • Hello,

    I was able to overcome all errors by using:

    Method #2 define in post #6 ✨ Change require custom libraries to suggestions as a better method with more options Needs work
    combined with this patch https://www.drupal.org/files/issues/2024-09-17/taxonomy_manager-3474919-... β†’
    from: https://www.drupal.org/project/taxonomy_manager/issues/3474919 πŸ› Form element taxonomy_manager_tree broken RTBC

    Thanks!

Production build 0.71.5 2024