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.
---
Comments
Comment #2
pasqualleComment #3
pasqualleComment #4
pasqualleComment #5
pasquallemain 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
Comment #6
nod_We're standardized on yarn in core, also have a look at the related issues they are not all directly related but can be interesting for the background.
We would also need to automate the creation/population of libraries.yml to some extend
Comment #7
nod_Comment #8
droplet commentedwe 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.
Comment #9
nod_@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.
Comment #10
andypost@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
Comment #11
andypostNo 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
Comment #12
nod_if I follow you want npm but in PHP?
Comment #13
andypostI mean that this issue looks a duplicate of one of related #2873160: Implement core management of 3rd-party FE libraries
Comment #14
pasqualleYes, 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.
Comment #17
effulgentsia commentedWe 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.
Comment #18
anybodyI 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.
Comment #19
anybodySorry, 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.
Comment #23
catchClosing as duplicate of #2873160: Implement core management of 3rd-party FE libraries