Review 13.4 Merged

88765[TASK] Modernize JavaScript and CSS buildchain

Benjamin Franzke CR +2 V +2 Impossible +8133 −20616 updated 03/26/25, 07:37

Commit message

Use ECMAScript 2023 as target for TypeScript, rollup and esbuild,
which is understood by all supported browsers. Plus: We already
use ES2023 features anyway, so it's fine to let tools optimize for
this target.

Replace clean-css with cssnano
------------------------------

Replace clean-css with cssnano, which is a native postcss plugin
that can operate on the postcss CSS AST directly, without the need
for an own CSS parser implementation.
This means that this plugin is less likely to miss support for new
CSS functionality like container queries (which clean-css – in the
version pulled in by postcss-clean – does not yet support).

Replace html-minifier with htmlnano
-----------------------------------

Replace the ancient library minify-html-literals with litnano (htmlnano
for lit template literals), as minify-html-literals pulls in insecure
dependencies and does not allow for asynchronous css processing
(needed for cssnano usage).

Replace terser with esbuild
---------------------------

Esbuild can be used to bundle and terse dependencies in one step
and is much faster than terser. It can also replace our existing
UMD wrappers and therefore is now used as third-party bundler
for all the "simple" cases (excluding ckeditor and lit).

Also our own TypeScript buildchain now uses esbuild minification
as final minification sink.

Allow generation of (temporary) JavaScript and CSS sourcemaps
-------------------------------------------------------------

The TypeScript, SASS and thirdparty package buildchain is adapted to
support temporary generation of sourcemaps, which may become helpful for
debugging and development, now that more variables are being mangled due
to the usage of esbuild minification.

A sourcemap can be built via:

  npm run build -- --sourcemaps

  npm run build-js -- --sourcemaps
  npm run build-css -- --sourcemaps

  # Or only build sourcemaps for changed files
  npm run build -- watch --sourcemaps

Please note that the sourcemap are inlined into the generated files
and needs to be removed by rebuiling without `--sourcemaps` enabled
in order to be mergable. (CI will verify)

Asynchronous execution task
---------------------------

The TypeScript post-processing-copy task and the minification task
(previously terser, now esbuild) are merged into a new combined
asynchronous grunt task, allowing to minify lit html
literals first and apply JavaScript minification afterwards.
(Previously terser was executed first and minify-html-literals
afterwards, which worked because terser did not mangle `html`
literals without `module` mode being enabled, now that we use
esbuild, top level variable names will be mangled into shorter
variants)

The combined – and most importantly asynchronous – grunt task allows
to perform the switch to cssnano instead of clean-css,
which also requires asynchronous execution.

Miscellaneous build optimizations
---------------------------------

 * Fully parallelize CPU-bound tasks, `npm run build` is now 4x faster
   (parallelization improved `npm run build` runtime from ~40sec to
   ~18sec and the switch to esbuild caused another 9sec decrease,
   so we're at ~9sec build time)
 * Remove concurrent wrappers for io-bound copy operations.
   Thread creation creates unneeded overhead, resulting in 200-400ms
   slowdowns instead of performance gains.
 * Drop tsconfig.json processing, instead adapt the paths of dashed
   extensions to match the bare JavaScript module prefix
 * Avoid intermediate files where possible (simplifies sourcemap
   generation and avoids dozen "changed" tracked files while rebuilding)
 * Move Build/util to Build/lib and use ES6 modules (can be loaded via
   require in nodejs 22 LTS)
 * Avoid fake thirdparty module paths (mark.js, chart.js, flatpickr)
   where possible and provide custom TypeScript mappings where missing
 * Merge sass processing into the postcss grunt task to ease sourcemap
   generation and to reduce configuration boilerplate

Commands executed:
  npm remove \
    es-module-lexer \
    terser \
    grunt-npmcopy \
    grunt-sass \
    grunt-terser \
    @rollup/plugin-terser \
    rollup-plugin-postcss \
    postcss-clean \
    minify-html-literals
  npm install --save-dev \
    esbuild@^0.25 \
    rollup@^4.37 \
    rollup-plugin-esbuild@^6.2 \
    @rollup/plugin-commonjs@^28 \
    @rollup/plugin-node-resolve@^16 \
    postcss@^8.5 \
    cssnano@^7 \
    litnano@^1 \
    autoprefixer@^10.4.21 \
    @csstools/postcss-sass@^5.1
  # Update to depend on cssnano v7 instead of v6
  npm install --save-dev @ckeditor/ckeditor5-dev-utils@^46
  git mv Build/Sources/TypeScript/indexed_search \
    Build/Sources/TypeScript/indexed-search
  git mv Build/Sources/TypeScript/rte_ckeditor \
    Build/Sources/TypeScript/rte-ckeditor
  git mv Build/Sources/TypeScript/sys_note \
    Build/Sources/TypeScript/sys-note
  grep -rl clean-css Build/Sources | xargs sed -i '/clean-css/d'
  npm audit fix
  npm run build

Review

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

Issues 2

Files 532

Show 512 more files

Review log 23

  1. Benjamin Franzke uploaded patch set 1 03/26/25, 07:28

  2. core-ci voted on patch set 1 V +1 03/26/25, 07:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76349

  3. Benjamin Franzke merged patch set 2 03/26/25, 07:37