User tests: Successful: Unsuccessful:
Pull Request for Issue # .
Use type=module
for ES2017 and nomodule
for ES5 scripts
Test every url Front End and Back End to confirm that there's no console errors and all the interactive elements continue to work as before
Especially check the Admin login by insering a username but ignoring the password should raise a message (formbvalidation)
Set the editor to Codemirror and create an article and also check that editing a template file is working as before
Just as a comment here: all .es6.js
and .w-c.es6.js
are handled by Rollup, meaning that any import
will be correctly bundled. Also the compiled -es5.js
is again created by Rollup using Babel. This adds a delay on the build command BUT now all the ES6 files are ES2017 (meaning there is translation to a minimum version) against the previous state (ES6 files
could have eg 2021 code that would be problematic for many browsers as the coverage is way bellow the 95% threshold, which is assumed the industry standard for the compatibility lower boundary. Worth watching https://www.youtube.com/watch?v=cLxNdLK--yI by @developit and @housseindjirdeh as this PR basically implements exactly that)
The impact could be from 1s to 20s depending on the actual hardware
Calling for testing @richard67 @Fedik @anibalsanchez @alikon @laoneo
how Joomla is doing the transition
what an extension developer should do to follow the steps
{
"name": "com_example.awesome-script",
"type": "script",
"uri": "com_example/awesome-script.min.js",
"dependencies": [
"core"
],
"attributes": {
"defer": true
}
Modern way assumes that the script has a source (modern JS) that transpiles to 2 files, one ES2017 and one ES5 (the one with -es5):
{
"name": "com_example.awesome-script.es5",
"type": "script",
"uri": "com_example/awesome-script-es5.min.js",
"dependencies": [
"core"
],
"attributes": {
"nomodule": true,
"defer": true
},
}
{
"name": "com_example.awesome-script",
"type": "script",
"uri": "com_example/awesome-script.min.js",
"dependencies": [
"com_example.awesome-script.es5"
],
"attributes": {
"type": "module"
}
}
HTMLHelper::_('script', 'com_example/awesome-script.min.js', ['version' => 'auto', 'relative' => true], ['defer' => true]);
Eg Modern:
HTMLHelper::_('script', 'com_example/awesome-script-es5.min.js', ['version' => 'auto', 'relative' => true], ['defer' => true, 'nomodule' => true]);
HTMLHelper::_('script', 'com_example/awesome-script.min.js', ['version' => 'auto', 'relative' => true], ['type' => 'module']);
Mind that the legacy script com_example/awesome-script.min.js
was theoretically rewritten as modern JS and was transpiled to ES2017 with the same name and then a transpiled ES5 was produced by a bundler and had a theoretical name com_example/awesome-script-es5.min.js
. But this is the convention Joomla is using, devs can use their own naming convention here, Joomla will not impose anything in this part.
What the CMS provides
Joomla has a set of tools for compiling a modern script to ES2017 and ES5 files. Devs can use Rollup, Webpack, Parcel, ESBuild, SnowPack, or any other bundler out there. The scripts for the bundling live at https://github.com/joomla/joomla-cms/tree/4.0-dev/build/build-modules-js/javascript and devs can even use them as-is if they develop on top of the Joomla repo (this is probably an antipattern, but...) or fork them for their own benefit.
Status | New | ⇒ | Pending |
Category | ⇒ | Repository NPM Change |
Labels |
Added:
NPM Resource Changed
?
|
I think we should note somewhere (at release page or system requirement), that nomodule will be dropped at some point of 4.x, maybe even in 4.1
Sure, but only if we ever come to an agreement on how we move forward with Js, transpiling, etc
Category | Repository NPM Change | ⇒ | Administration com_admin Repository NPM Change |
you know what I thinking,
we need es5 fallback only for a scripts that may be used on frontend,
because whole backend is unusable in old browsers anyway (I can actually login, but not much can do).
because whole backend is unusable in old browsers anyway
The backend is unusable with the default template. If I fork Atum and use bs4 css (patching the changed classes with some extends or whatever) the backend should be still fine on IE11
@wilsonge any input here?
If I fork Atum and use bs4 css
It not only the styling, but much of JS errors (I tried on current 4.0-dev branch, without this PR)
but much of JS errors
There are known errors right now as people removed some polyfills without our tools adding them back. Basically, the tools are not really transpiling properly the es6 files. Partially this is fixed with #32300 but I think there will be a bit more tweaking required
@Fedik can you post some of those errors?
Basically, the tools are not really transpiling properly the es6 files
yeah I suspect that also,
there was something about undefined require()
, and some others,
I can try to run again sometime later and copy some of them, if it makes sense
Thanks, so there are quite some problems here:
EDIT: it seems there's a tag missing: <meta http-equiv="X-UA-Compatible" content="IE=11" />
Category | Repository NPM Change Administration com_admin | ⇒ | Administration com_admin JavaScript Repository NPM Change |
Are the attributed nomodule: true and module: defer the opposites of each other - asking for a friend
Are the attributed nomodule: true and module: defer the opposites of each other - asking for a friend
They are exclusive, type=module means the script is loaded with defer and ONLY by 2017+ browesers also these browsers will ignore the nomodule scripts.
Browsers up to 2017 (eg without module support) will ignore the type=module (they don't know how to handle it) but we're setting also the defer so we have the same order of execution
ok - thanks. as long as it all gets documented
Looks like some leftover test code in code mirror logging mode
to console in https://github.com/joomla/joomla-cms/pull/32315/files#diff-1ae7d38a00585728880c44a33b57e666285099ba9879ffc55b91cdb7f43fadb1R53
I don't see any other issues thus far.
I have tested this item
I like, but would be nice to explain a bit more how extension devs can benefit from this.
@brianteeman @laoneo ok so then I'll write a doc about this and also cover all the JS parts (API, passing data from PHP to client-side, etc)
The video is clear about "the transitioning to modern JavaScript" and there is plenty of information about modern JavaScript around. So, you can include in the documentation a brief summary.
What I'm missing is a guide about how Joomla is doing the transition and what an extension developer should do to follow the steps. What the CMS provides and what the extension developer must do in terms of JavaScript code modernization for Joomla.
how Joomla is doing the transition
what an extension developer should do to follow the steps
{
"name": "com_example.awesome-script",
"type": "script",
"uri": "com_example/awesome-script.min.js",
"dependencies": [
"core"
],
"attributes": {
"defer": true
}
Modern way assumes that the script has a source (modern JS) that transpiles to 2 files, one ES2017 and one ES5 (the one with -es5):
{
"name": "com_example.awesome-script.es5",
"type": "script",
"uri": "com_example/awesome-script-es5.min.js",
"dependencies": [
"core"
],
"attributes": {
"nomodule": true,
"defer": true
},
}
{
"name": "com_example.awesome-script",
"type": "script",
"uri": "com_example/awesome-script.min.js",
"dependencies": [
"com_example.awesome-script.es5"
],
"attributes": {
"type": "module"
}
}
HTMLHelper::_('script', 'com_example/awesome-script.min.js', ['version' => 'auto', 'relative' => true], ['defer' => true]);
Eg Modern:
HTMLHelper::_('script', 'com_example/awesome-script-es5.min.js', ['version' => 'auto', 'relative' => true], ['defer' => true, 'nomodule' => true]);
HTMLHelper::_('script', 'com_example/awesome-script.min.js', ['version' => 'auto', 'relative' => true], ['type' => 'module']);
Mind that the legacy script com_example/awesome-script.min.js
was theoretically rewritten as modern JS and was transpiled to ES2017 with the same name and then a transpiled ES5 was produced by a bundler and had a theoretical name com_example/awesome-script-es5.min.js
. But this is the convention Joomla is using, devs can use their own naming convention here, Joomla will not impose anything in this part.
What the CMS provides
Joomla has a set of tools for compiling a modern script to ES2017 and ES5 files. Devs can use Rollup, Webpack, Parcel, ESBuild, SnowPack, or any other bundler out there. The scripts for the bundling live at https://github.com/joomla/joomla-cms/tree/4.0-dev/build/build-modules-js/javascript and devs can even use them as-is if they develop on top of the Joomla repo (this is probably an antipattern, but...) or fork them for their own benefit.
Great, thanks for the explanation.
HTMLHelper::_('script', ..
for note: this is now forbidden in Joomla 4
for note: this is now forbidden in Joomla 4
I'm with you here but then once this merged we need another PR to remove the few instances of HTMLHelper::_('script'
. I don't want to invalidate the one good test. Finding people willing to test such PRs is hard...
hmhm then I have missed it when replaces all to WebAsset,
yea, it need to be done separately
@dgrammatiko I have tested this, it's awesome, I mean it really works!
I've updated my commit #32510 to reflect these changes.
I noted that both my field.color-picker
es6 and es5 coming both use TinyColor es5 for some reason, perhaps that's what it was supposed to do, however I tried to use import TinyColor from '@ctrl/tinycolor/dist/public_api.js'
, same result? Perhaps that's a non-issue at this point.
I have tested, it works. IE11 explodes with errors, but nevermind
I have tested this item
I have tested this item
Status | Pending | ⇒ | Ready to Commit |
RTC
I have tested, it works. IE11 explodes with errors
I know, I commented out the required lines for IE https://github.com/joomla/joomla-cms/pull/32315/files#diff-7973fa8a952791298a25a8354216ed84a7476bf991fce4be84f05cb1d91f2bce because we might want to abstract (if possible) the Babel runtime (it's 6kb that will be included in each script) but besides that, we need a list of DOM polyfills that Babel is not injecting (eg htmlElement.colsest()
). Also, the webcomponents polyfill should include the file webcomponents-bundle.js
instead of bundles/webcomponents-sd-ce-pf.js
. In short, this is a bug we can fix, I just didn't want to blow this PR even further. I will do the patches in another PR or PRs
...because we might want to abstract (if possible) the Babel runtime (it's 6kb that will be included in each script) but besides that, we need a list of DOM polyfills that Babel is not injecting
you wanted to say that we need jQuery?
you wanted to say that we need jQuery?
I some cases also Mootools
@dgrammatiko I think with this PR, it's a good opportunity to change ESlint with @babel/eslint-parser, this one allows static properties to be parsed, something I need for the color-picker called static formAssociated = true;
.
Also onformdata
isn't good enough? Seems well supported.
Safari doesn’t support it so: no
ref https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onformdata
Btw I already gave you the solution
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2021-03-10 18:34:57 |
Closed_By | ⇒ | rdeutz | |
Labels |
Added:
?
|
@dgrammatiko Now I have a problem when using node version 12:
I.e. it breaks here:
With node version 14 I don't have that problem.
At least one other person could reproduce that, i.e. same problem on same OS (Linux) with node v12, and no problem anymore after removing node and installing v14.
Any idea?
@wilsonge What version of node do we require?
@richard67 Can you change it to: const { access } = require('fs').promises;
? Does that solve the problem?
Also according to https://nodejs.org/en/about/releases/ v10 goes EOL next month, so v12 should be set as the minimum at the end of April.
@richard67 Can you change it to:
const { access } = require('fs').promises;
?
Not sure if I can. Can you advise me? Does it need a text editor for that?
...
Joking ;-)
Does that solve the problem?
It solves the problem on node v12 on my Linux VM. Will see in a few minutes if it still works with node v14 on my Windows VM.
It solves the problem on node v12 on my Linux VM.
Well, the 'fs/promises'
is just a newer syntax of the same thing. Everything should be ok. Node is confusing with the rolling versions but I guess I should have tested this
Everything should be ok.
It means no need for a fix? Or it means your suggested fix is ok? If the latter: Could you make the necessary PR?
so the question arise what should be the node and npm versions ? for testing of course
so the question arise what should be the node and npm versions ? for testing of course
Till the end of April v10 should be ok but I guess the project should raise the minimum to v12 before v10 goes EOL. Also whatever you do MARK the date (end of April) as you have to do this every year since Javascript the language gets a new version every year (so nodejs just follows the ecmascript releases)
looks okau to me.
I think we should note somewhere (at release page or system requirement), that
nomodule
will be dropped at some point of 4.x, maybe even in 4.1