Feature NPM Resource Changed PR-5.0-dev Pending

User tests: Successful: Unsuccessful:

avatar dgrammatiko
dgrammatiko
24 Jun 2023

Pull Request for Issue # .

Summary of Changes

  • Expose/localise the ESM module of the Cropper
  • Deprecate the Global Cropper script
  • Add the cropper.esm.js (the module) to the Joomla.assets.json (WAM) as importmap
  • Use the natural way to import the module import Cropper from 'cropper-module'; in the crop script

Testing Instructions

  • Check out this PR
  • run rpm ci
  • Open the media manager, select an image and edit it. Check that the CROP is working as expected

Actual result BEFORE applying this Pull Request

Cropper is a Global Object

Expected result AFTER applying this Pull Request

Cropper is ONLY available in the scope of the crop.js!

How importmap works:

There 2 parts: the import statement in the file that wants to import another script (ESM module) and the exposure of the module to the WAM (check the files in this PR). In the client side what happens is:

  • A polyfill is loaded so browsers that don't support importmap won't crash:
Screenshot 2023-06-24 at 11 54 33
  • The polyfill does a simple check by trying to import a blob and either patch or not the browser:
Screenshot 2023-06-24 at 11 54 45
  • The file that wants to import the module then is parsed/executed:
Screenshot 2023-06-24 at 11 55 00
  • The resolution of the module is taken from the importmap:
Screenshot 2023-06-24 at 12 12 50
  • Finally the module is fetched/parsed/executed and the importer script continues:
Screenshot 2023-06-24 at 11 55 13

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar joomla-cms-bot joomla-cms-bot - change - 24 Jun 2023
Category Repository JavaScript NPM Change Front End Plugins
avatar dgrammatiko dgrammatiko - open - 24 Jun 2023
avatar dgrammatiko dgrammatiko - change - 24 Jun 2023
Status New Pending
avatar dgrammatiko dgrammatiko - change - 24 Jun 2023
The description was changed
avatar dgrammatiko dgrammatiko - edited - 24 Jun 2023
c78926a 24 Jun 2023 avatar dgrammatiko CS
avatar dgrammatiko dgrammatiko - change - 24 Jun 2023
Labels Added: NPM Resource Changed PR-5.0-dev
avatar HLeithner
HLeithner - comment - 24 Jun 2023

is it good to name it -module instead of -esm ?

avatar dgrammatiko
dgrammatiko - comment - 24 Jun 2023

is it good to name it -module instead of -esm ?

this was my take, it was picked randomly, could change to whatever you decide. That said there is an interesting change that could be done in the source files: instead of the suffix .es6 you could use directly the extension mjs (the official extension for the esm modules). I’m not proposing to have those extensions for the transpiled modules because if the server doesn’t have the infra in place (mime.types) it he file could be send as text and everything will be broken. Fwiw I already did that on the Joomla-tools (they are essentially the tools on this repo written on pure esm)

avatar Fedik
Fedik - comment - 24 Jun 2023

I think use of .esm.js is fine.

It often can find recomendations to use .jsm instead of .js for ES modules.
But it a bit cryptic to me and require more changes in core.

avatar dgrammatiko
dgrammatiko - comment - 24 Jun 2023

@Fedik im talking about the SOURCE files not the transpiled, so instead of having some random suffix .es6.js just have the .mjs (which is standardized from ecmascript)

avatar dgrammatiko
dgrammatiko - comment - 24 Jun 2023

Anyways I’ve changed the name of the asset to cropper.esm

avatar Fedik
Fedik - comment - 24 Jun 2023

Well, I think "cropper-module" was also fine :)
"cropper-module" => cropper.esm.js

im talking about the SOURCE files not the transpiled

I am about file in general ;)
About a source file I not care very much how it will be called, I am fine with any.

avatar HLeithner HLeithner - close - 26 Jun 2023
avatar HLeithner HLeithner - merge - 26 Jun 2023
avatar HLeithner HLeithner - change - 26 Jun 2023
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2023-06-26 07:49:55
Closed_By HLeithner
Labels Added: Feature
avatar HLeithner
HLeithner - comment - 26 Jun 2023

Thanks, I'm merging this for now to have a reference using esm in core

Add a Comment

Login with GitHub to post a comment