Everything from #3185289: Use package.json and rollup to manage third party JS libraries, but using a very simple script.

yarn outdated
yarn upgrade X Y Z
yarn vendor-update

The script will copy all relevant files in all the relevant places and update the versions in core.libraries.yml.

Issue fork drupal-3219088

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

nod_ created an issue. See original summary.

nod_’s picture

Title: Use package.json and webpack to manage third party JS libraries » Use package.json to manage third party JS libraries

don't need webpack

nod_’s picture

Status: Active » Needs review

This will definitely not work with yarn2 but it's a problem for when we talk about yarn2 in core.

nod_’s picture

Issue summary: View changes
nod_’s picture

Issue summary: View changes
nod_’s picture

Added js-cookie, css.escape and some comments to explain how things work.

Modernizr, CKEditor, and jQuery.ui are not in the scope since they require a custom compile step (we could just add them to the package.json file to know when there are updates).

justafish’s picture

Status: Needs review » Reviewed & tested by the community

Looks good!

drupal/core on  3219088-use-package.json-and [!] via ⬢ v15.11.0 via 🐘 v7.4.3 took 32s 
❯ yarn vendor-update
yarn run v1.22.10
$ node ./scripts/js/assets.js
Copy backbone/backbone.js to backbone/backbone.js
Copy backbone/backbone-min.js to backbone/backbone-min.js
Process map file backbone-min.map
Copy css.escape/css.escape.js to css-escape/css.escape.js
Copy es6-promise/dist/es6-promise.auto.min.js to es6-promise/es6-promise.auto.min.js
Process map file dist/es6-promise.auto.min.map
Copy farbtastic/marker.png to farbtastic/marker.png
Copy farbtastic/mask.png to farbtastic/mask.png
Copy farbtastic/wheel.png to farbtastic/wheel.png
Copy farbtastic/farbtastic.css to farbtastic/farbtastic.css
Copy farbtastic/farbtastic.min.js to farbtastic/farbtastic.js
Copy jquery/dist/jquery.js to jquery/jquery.js
Copy jquery/dist/jquery.min.js to jquery/jquery.min.js
Process map file dist/jquery.min.map
Copy jquery-form/dist/jquery.form.min.js to jquery-form/jquery.form.min.js
Process map file dist/jquery.form.min.js.map
Copy jquery-form/src/jquery.form.js to jquery-form/src/jquery.form.js
Copy joyride/jquery.joyride-2.1.js to jquery-joyride/jquery.joyride-2.1.js
Copy jquery-once/jquery.once.js to jquery-once/jquery.once.js
Copy jquery-once/jquery.once.min.js to jquery-once/jquery.once.min.js
Process map file jquery.once.min.js.map
Copy js-cookie/dist/js.cookie.min.js to js-cookie/js.cookie.min.js
Copy normalize.css/normalize.css to normalize-css/normalize.css
Copy @drupal/once/dist/once.js to once/once.js
Copy @drupal/once/dist/once.min.js to once/once.min.js
Process map file dist/once.min.js.map
Copy picturefill/dist/picturefill.min.js to picturefill/picturefill.min.js
Copy @popperjs/core/dist/umd/popper.min.js to popperjs/popper.min.js
Process map file dist/umd/popper.min.js.map
Copy shepherd.js/dist/js/shepherd.min.js to shepherd/shepherd.min.js
Process map file dist/js/shepherd.min.js.map
Copy sortablejs/Sortable.min.js to sortable/Sortable.min.js
Copy tabbable/dist/index.umd.min.js to tabbable/index.umd.min.js
Process map file dist/index.umd.min.js.map
Copy underscore/underscore-min.js to underscore/underscore-min.js
Process map file underscore-min.js.map
Done in 0.14s.
longwave’s picture

Should our runtime dependencies be listed as true dependencies rather than dev dependencies? That would also help keep them separated from our build dependencies.

nod_’s picture

Added the automatic update of the version in core.libraries.yml. Had to use regex because the various yaml js libraries didn't support everything we use in this file and it was messing up the format when saving.

@#9 I think we had the discussion, let me try to find it.

nod_’s picture

nod_’s picture

Priority: Normal » Major

As per the previous issue.

nod_’s picture

Issue summary: View changes
longwave’s picture

I don't think the linked discussion quite answers my question - if these are dev dependencies, what would be a production dependency in the case of core? package.json is in the core directory so I assumed it was only intended for core developers; if you are using JavaScript elsewhere in a Drupal site you would have a separate package.json in your theme or wherever.

nod_’s picture

There wouldn't be a production dependency, because Drupal doesn't require you to have nodejs installed to work, so we can't (won't) require people to do yarn/npm install to make Drupal work.

tom konda’s picture

Priority: Major » Normal
Status: Reviewed & tested by the community » Needs review

When I using Node.js 14 LTS, file copying works successfully.
But, when I using Node.js 12 LTS, fails file copying because of undefined 'fs/promises' calling.
According to Node.js documentation, fs/promises is defined after Node.js 14.
I think below code will work on Node.js 12 and 14.

const { copyFile, writeFile, readFile, chmod } = require('fs').promises;
nod_’s picture

Priority: Normal » Major

yeah didn't pay attention to versions, feel free to update the MR :)

nod_’s picture

Status: Needs review » Reviewed & tested by the community

taken care of it, thanks for the review :)

nod_’s picture

Status: Reviewed & tested by the community » Needs review
nod_’s picture

haha crossed post. Thanks for the fix :)

nod_’s picture

nod_’s picture

script updates the licence URL as well as the library version in the core.libraries.yml file.

nod_’s picture

All good, put the same releases of js-cookie and joyride as in core. This copy/paste script is ready IMHO.

nod_’s picture

Issue summary: View changes
nod_’s picture

alexpott’s picture

This looks really really neat. So nice to not have to maintain these manually!

Here are some notes I made while reviewing the patch - all positives

  • Note: core/assets/vendor/jquery-form/src/jquery.form.js is added for the source map
  • Note: core/assets/vendor/farbtastic/ JS and CSS changes are whitespace and comments
  • This patch fixes the core/assets/vendor/jquery-form/jquery.form.min.js.map because the src is now pointed to a real source.
  • This patch fixes core/assets/vendor/jquery/jquery.min.map to point to a valid source.

Here are two questions I have from reviewing the patch:

  • Do we care that core/assets/vendor/farbtastic/marker.png is becoming less optimised - it's going from 437B to 652B? The other images are the same size at 11K and 2.0K - so maybe not?
  • core/assets/vendor/popperjs/popper.min.js.map is changes to pointing from ../../src/dom-utils/getBoundingClientRect.js to src/dom-utils/getBoundingClientRect.js etc... neither file exists so this is not a regression but I don't think it is going to work. Same with the map for Shepherd and Tabbable. Maybe we should file a follow issue? Or is this expected? Or given we're manipulating the map files should we only do this when we're also providing the source - as in jquery and jquery.form? Or should we also be copying in the sources for these too?
nod_’s picture

Thanks for having a look. to answer the two questions:

  1. Given that we're deprecating (#1651344: Use color input type in the color.module) it i wouldn't worry. It's not in any critical path related to performance.
  2. Map files can contain the original source, here essentially we have 2 arrays sources and sourcesContent, one with a list of file, and another one with the contents of each file (then all the map-stuff that makes everything works). We're changing the path of "virtual" files, so no problem either way. Only issue would be is someone was checking file hashes but then again i haven't heard of this for map files.
longwave’s picture

Status: Needs review » Reviewed & tested by the community

The questions were answered, no changes required that I can see. This looks like a neat solution to our JS dependency management, so let's get this RTBC.

catch’s picture

This looks really good to me, it's only a change for core developers, so if we run into problems later with it we can try to come up with a new system, but hopefully it'll be a good improvement with no drawbacks.

lauriii’s picture

I haven't reviewed this in detail yet but I like the overall approach. Do you think it would make sense to open a follow-up for adding a CI check that ensures that the vendor files are indeed generated by the tool? I think it's fine as is for the time being but it would help reduce some work since it's a step I always do when committing minified files.

larowlan made their first commit to this issue’s fork.

larowlan’s picture

Catch, Alex and I have reviewed this now - removing the tag

I've pushed some minor nit-picks to the branch.

This looks good to me, I think just a follow-up for #30 is all that remains.

nod_’s picture

Package is language keyword so while it works like this I wanted to avoid any potential confusion down the line (we can't use destructuring directly with package for example)

If that is clearer like this, all good.

larowlan’s picture

Ah, I didn't realise it was a future reserved word, reverted that change and expanded the comment to explain why we use pack

nod_’s picture

catch’s picture

Should have removed the RM review tag with #29.

larowlan’s picture

  • larowlan committed 3071938 on 9.3.x authored by nod_
    Issue #3219088 by nod_, Tom Konda, longwave, alexpott, justafish: Use...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 9.3.x, thanks all

Published change record

nod_’s picture

now those issues are easy to do: #3225811: Update to js-cookie 3.0.1

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.