Review main Merged

72892[TASK] Separate JavaScriptHandler concerns

Benjamin Franzke CR +2 V +2 Hard +276 −316 updated 01/10/22, 15:32

Commit message

This change is preparatory refactoring in order to support
native JavaScript modules (ESM) where a module can't be used both
as classic script-src and as ES6 module providing exports at the same
time (this was/is possible for AMD as implemented in #95953):
`export` is an invalid keyword in non-module scripts and cannot be
specified conditionally, that is very different to AMD modules where
`define()` can be called conditionally.

JavaScriptHandler currently has three execution modes:

 * If used as script-scr: Call processItems from text content for:
   * RequireJS configuration
   * Generic JavaScriptItems processing
 * If used as AMD module:
   * Generic JavaScriptItems processing

JavaScriptHandler is now separated into the following three concerns:

JavaScriptItemProcessor
-----------------------
The previous processor "mode" is now available as
streamlined JavaScriptItemProcessor module, in order
to drop type invariance (it requires parsed objects
instead of allowing raw json data or objects)

JavaScriptItemHandler
---------------------
The previous JavaScriptHandler module that processes
text content and calls arbitrary hooks has been
simplified to the one usecase that was actually being used:
Handling JavaScriptItems by parsing the text content.
The extracted JavaScriptItemProcessor is used as backend
for the actual work.

RequireJSConfigHandler
----------------------
The RequireJS configurator is now available as
separate module, as this logic is only needed once and not by
other modules. There is no need to keep that functionality in
JavaScriptItemProcessor, especially as it has been hidden from
AMD modules, which complicated the JavaScriptHandler.
This extraction also actually allows to make use of modules
in JavaScriptHandler and therefore enables the possibility to
share code using JavaScriptItemProcessor.

Also the code has been migrated to TypeScript.
JavaScriptItemHandler and RequireJSConfigHandler do not export
or import code, therefore they are usable as plain targets
for script-tags.

In addition the JavaScriptItemHandler is now executed
asynchronously, which allows the browser to parse DOM
in parallel. (synchronous mode is required for RequireJS
config, but not for loading of requirejs-modules/instructions,
they are asynchronous anyway).

FileClipboardCest is adapted to wait more than 1 second, since the
rerendering of the clipboard (a new iframe request is made) takes
longer than 1 second in some test runs (not locally, but on CI)
(note: the default 1 second wait timeout is configured in
typo3/sysext/core/Tests/Acceptance/Application.suite.yml, but that's
too less in this case).

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Oliver Hader +1
    • Benni Mack +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Oliver Hader +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 3

Files 20

Review log 1420

  1. Benjamin Franzke uploaded patch set 1 01/06/22, 14:02

  2. core-ci voted on patch set 1 V -1 01/06/22, 14:21 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21702

  3. Benjamin Franzke uploaded patch set 2 01/06/22, 14:23

  4. core-ci voted on patch set 2 V -1 01/06/22, 14:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21704

  5. Benjamin Franzke uploaded patch set 3 01/06/22, 15:07

  6. core-ci voted on patch set 3 V -1 01/06/22, 15:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21710

  7. Benjamin Franzke uploaded patch set 4 01/06/22, 15:26

  8. core-ci voted on patch set 4 V -1 01/06/22, 15:38 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21714

  9. Benjamin Franzke uploaded patch set 5 01/06/22, 15:57

  10. core-ci voted on patch set 5 V +1 01/06/22, 16:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21715

  11. Benjamin Franzke uploaded patch set 6 01/06/22, 18:50

  12. core-ci voted on patch set 6 V +1 01/06/22, 19:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/21729

  13. Benjamin Franzke commented on patch set 6 01/06/22, 20:17

    Note, Please following WIP change for possible future ES6 module integration: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72637/19/Build/Sources/TypeScript/core/Resources/Public/TypeScript/JavaScriptItemProcessor.ts (Therefore module loading is moved into a separate function and already uses Promise, makes later patches easier to integrate)
  14. Benni Mack commented on patch set 6 01/06/22, 23:15

    Looks good on reading, but I guess we'd need Olly Haders' input on this as well.
  15. Benjamin Franzke commented on patch set 6 01/07/22, 06:01

    Reply

    yeah, would be great. thanks for cc'ing him, I was unsure because of possible holidays.
  16. Oliver Hader voted on patch set 6 CR +1 01/10/22, 13:49

  17. Oliver Hader voted on patch set 6 V +1 01/10/22, 14:03

  18. Benni Mack voted on patch set 6 V +1 CR +1 01/10/22, 15:06

  19. Benjamin Franzke voted on patch set 6 V +2 CR +2 01/10/22, 15:31

  20. Benjamin Franzke merged patch set 7 01/10/22, 15:32