Problem/Motivation

More and more modules have npm dependencies. Installing such dependencies require manual changes (in composer.json) or using unsupported solutions (like asset-packagist).
These solutions are wrong for various reasons
- hard to define
- hard to install
- hard to update
- and might be insecure

Steps to reproduce

asset-packagist:
Many distributions use asset-packagist: Lightning, Varbase
Steps to configure asset-packagist
Problems:
- asset-packagist seems unmaintained
- npm packages should not be managed with composer #3198245: Composer script: enable-asset-packagist

example solutions requiring manual changes:
project dependency visualizer complicated install, currently using unmaintained library
project chosen complicated install, currently using unofficial, deprecated library
copy-files-from-to manually defined assets, no relation to Drupal projects
Problems:
- need to inform and educate the user about the installation
- the configuration is not user friendly, and can lead to issues
- manual changes required to update the package, which might result using insecure release

Proposed resolution

Develop an official npm package management solution for Drupal, which is as good and easy to use as composer.

Remaining tasks

Discuss the solution, create child issues.

---

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Pasqualle created an issue. See original summary.

pasqualle’s picture

Issue summary: View changes
pasqualle’s picture

Issue summary: View changes
pasqualle’s picture

Issue summary: View changes
pasqualle’s picture

main goal:
- Create package.json file inside the Drupal module
- Running npm install (from Drupal project root) would install defined npm package(s) (with all dependencies)
- Drupal modules can see and use all installed npm packages

nod_’s picture

nod_’s picture

droplet’s picture

we should create a `npm install --global drupal-cli` tool and search `target config` smartly. The start point from `/core` is bad, very bad!

Olivero is the first priority in Core I believe and using many new tools (, also skipped many evaluation processes I thought). If you find a way to hook it, you will get rocket speed to push it forward.

nod_’s picture

@droplet I want to do something similar to wordpress, https://www.npmjs.com/package/@wordpress/scripts so that we can take most of the config/compile scripts out of core PHP project and put them into npm packages. That way core and contrib can use the exact same scripts and we make it available to projects easily too.

andypost’s picture

@nod_ the issue is not about npm/yarn - this issue looks duplicate of existing - painful downloading of js-dependencies for contrib and custom code.

I'd say inability to provide dependencies for contrib modules and themes, for example ckeditor colorbutton plugin/module https://www.drupal.org/project/colorbutton/issues/2897776

andypost’s picture

No libs/scripts scripts will help when someone will try install contrib theme which requires nodejs stack installed to make it work(

It's a challenge to install composer/php for newcomers still but you propose to add one more layer/language to help someone to start with D?

Basically all Google full of asset-packagist recipes, it works but has lots of downsides

nod_’s picture

if I follow you want npm but in PHP?

andypost’s picture

pasqualle’s picture

Yes, it seems like a duplicate issue, at least it matches some of the lasts comments from there..
It seems blazey figured out this already, I need to test his Webpack bundler module.
And yes, Drupal core should officially support such solution, not what we have today.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

effulgentsia’s picture

We should keep in mind Project Browser. The idea there is that (once that is built) someone running a site on shared hosting can install a module on production through the Drupal UI. This will entail the UI running Composer commands in production, which we've made a lot of progress on in the 2.x branch of Automatic Updates, which we'll add to core once it's ready.

If npm or yarn becomes a requirement to install or update a module, that will mean that it will become a requirement for Automatic Updates and Project Browser, but I don't think that Node.js is commonly available on PHP-based shared hosting accounts.

However, if npm or yarn provides optional convenience features, but the essential tasks are still achievable without it, that would probably be ok.

anybody’s picture

I think this is still an issue for modules with external (npm) javascript / library dependencies. Furthermore as written in #17 this should be considered for the project browser.

What about https://github.com/fxpio/foxy ? I don't have experience with it yet.

anybody’s picture

Sorry, I didn't see the comment about this being a potential duplicate of #2873160: Implement core management of 3rd-party FE libraries. For the reasons given and the discussion over there, I'd agree to close this as duplicate. Foxy is also discussed over there.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Component: asset library system » javascript
Status: Active » Closed (duplicate)
Issue tags: -JavaScript +JavaScript