Problem/Motivation
The current drupal-libraries-sync.js implementation in Varbase works, but has two areas that can be improved to make the workflow more intuitive, reduce errors, and better align the sync step with how dependencies are actually installed.
1. Missing fallback behavior when adding new NPM dependencies
Developers often install a new NPM package, expecting it to appear under docroot/libraries.
However, the script only syncs libraries explicitly listed under the drupal-libraries.libraries section in package.json.
If a developer installs a new NPM dependency but forgets to add a mapping entry, the script silently ignores it, leading to missing front-end libraries inside Drupal with no clear feedback.
2. Redundant script execution in Composer hooks
The sync script currently runs during post-create-project, and also during NPM/Yarn postinstall.
Since library syncing depends only on what exists in node_modules, running the sync script during Composer operations is unnecessary overhead.
Running the sync solely via the Node postinstall step is sufficient. We can just run npm/yarn install in post-create-project.
Steps to reproduce
- Install a new NPM dependency (e.g.,
npm install @ckeditor/ckeditor5-utils). - Run
yarn installornpm install. - The package appears in
node_modules/but is not copied todocroot/librariesunless manually added todrupal-libraries.libraries. - Drupal attempts to load the library from
docroot/librariesand fails.
Proposed resolution
A. Add fallback behavior for unmapped NPM dependencies
- If a package exists in
dependenciesbut does not have a mapping entry, the script should automatically copy it intodocroot/libraries/<package-name>. - Emit a warning, e.g.:
⚠️ No explicit mapping found for '@ckeditor/ckeditor5-utils'. Synced using default path.
- Allow developers to override behavior by adding an explicit mapping in
package.json.
B. Clean up script execution logic
- Only run
drupal-libraries-sync.jsduring NPM/Yarnpostinstall. - In Composer, run only
yarn install(ornpm install) duringpost-create-project-cmd. - The
postinstallhook will then automatically execute the sync script.
Remaining tasks
- ✅ File an issue about this project
- ❌ Addition/Change/Update/Fix to this project
- ❌ Testing to ensure no regression
- ➖ Automated unit/functional testing coverage
- ➖ Developer Documentation support on feature change/addition
- ➖ User Guide Documentation support on feature change/addition
- ➖ UX/UI designer responsibilities
- ➖ Accessibility and Readability
- ❌ Code review from 1 Varbase core team member
- ❌ Full testing and approval
- ❌ Credit contributors
- ❌ Review with the product owner
- ❌ Update Release Notes and Update Helper on new feature change/addition
- ❌ Release
Varbase update type
- ✅ No Update
- ➖ Optional Update
- ➖ Forced Update
- ➖ Forced Update if Unchanged
User interface changes
- N/A
API changes
- N/A
Data model changes
- N/A
Release notes snippet
- N/A
Comments
Comment #2
rajab natshahThanks, Redwan, for suggesting and filing the issue.
Comment #3
rajab natshahI like to have a Varbase Scaffold logic much like the Drupal Scaffolding process.
Then let Varbase do it's scaffolding in the
"post-drupal-scaffold-cmd"event.