diff options
| author | Ricardo Wurmus <rekado@elephly.net> | 2026-01-28 09:08:33 +0100 |
|---|---|---|
| committer | Andreas Enge <andreas@enge.fr> | 2026-02-14 10:18:12 +0100 |
| commit | 6dd4497f6378fe4c2eaf7179c265be8ca0d7b8c6 (patch) | |
| tree | e74077f3d8a40f7e3a41534b32e943f433156f7f /gnu/packages/javascript.scm | |
| parent | 853b2585222023bde2aa4f9033cade97548b5735 (diff) | |
gnu: Add js-mathjax-4.
* gnu/packages/patches/mathjax-4.0.0-disable-webpack.patch,
gnu/packages/patches/mathjax-4.0.0-no-a11y.patch: New files.
* gnu/local.mk (dist_patch_DATA): Record them.
* gnu/packages/javascript.scm (js-mathjax-4): New variable.
(js-mathjax-for-r-mathjaxr): Define as alias for js-mathjax-4.
Change-Id: I156605a8d11d615489d8f0c0c267c96339afc3c7
Diffstat (limited to 'gnu/packages/javascript.scm')
| -rw-r--r-- | gnu/packages/javascript.scm | 176 |
1 files changed, 146 insertions, 30 deletions
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm index e89cdf855e3..bd6d2a0a62b 100644 --- a/gnu/packages/javascript.scm +++ b/gnu/packages/javascript.scm | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2017 Arun Isaac <arunisaac@systemreboot.net> | 2 | ;;; Copyright © 2017 Arun Isaac <arunisaac@systemreboot.net> |
| 3 | ;;; Copyright © 2017, 2019, 2020, 2022, 2023 Ricardo Wurmus <rekado@elephly.net> | 3 | ;;; Copyright © 2017, 2019, 2020, 2022, 2023, 2026 Ricardo Wurmus <rekado@elephly.net> |
| 4 | ;;; Copyright © 2017, 2018, 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr> | 4 | ;;; Copyright © 2017, 2018, 2020, 2021 Tobias Geerinckx-Rice <me@tobias.gr> |
| 5 | ;;; Copyright © 2017-2020, 2022-2024 Efraim Flashner <efraim@flashner.co.il> | 5 | ;;; Copyright © 2017-2020, 2022-2024 Efraim Flashner <efraim@flashner.co.il> |
| 6 | ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr> | 6 | ;;; Copyright © 2018 Nicolas Goaziou <mail@nicolasgoaziou.fr> |
| @@ -316,11 +316,10 @@ be able to view it naturally and easily."))) | |||
| 316 | (description (package-description js-mathjax)) | 316 | (description (package-description js-mathjax)) |
| 317 | (license license:asl2.0))) | 317 | (license license:asl2.0))) |
| 318 | 318 | ||
| 319 | (define-public js-mathjax-for-r-mathjaxr | 319 | (define-public js-mathjax-4 |
| 320 | (package | 320 | (package |
| 321 | (inherit js-mathjax-3) | ||
| 322 | (name "js-mathjax") | 321 | (name "js-mathjax") |
| 323 | (version "3.1.2") | 322 | (version "4.0.0") |
| 324 | (source | 323 | (source |
| 325 | (origin | 324 | (origin |
| 326 | (method git-fetch) | 325 | (method git-fetch) |
| @@ -330,39 +329,136 @@ be able to view it naturally and easily."))) | |||
| 330 | (file-name (git-file-name name version)) | 329 | (file-name (git-file-name name version)) |
| 331 | (sha256 | 330 | (sha256 |
| 332 | (base32 | 331 | (base32 |
| 333 | "0kqcb6pl0zfs4hf8zqb4l50kkfq7isv35vpy05m0lg0yr9w0w4ai")) | 332 | "1ak864p80bvsvmz5fb41snrb165zs5miy54h08lld005ph8pqgk0")) |
| 334 | (patches (search-patches "mathjax-disable-webpack.patch" | 333 | (patches (search-patches "mathjax-4.0.0-disable-webpack.patch" |
| 335 | "mathjax-3.1.2-no-a11y.patch")))) | 334 | "mathjax-4.0.0-no-a11y.patch")))) |
| 335 | (build-system gnu-build-system) | ||
| 336 | (arguments | 336 | (arguments |
| 337 | (substitute-keyword-arguments (package-arguments js-mathjax-3) | 337 | (list |
| 338 | ((#:phases phases '%standard-phases) | 338 | #:phases |
| 339 | `(modify-phases ,phases | 339 | #~(modify-phases %standard-phases |
| 340 | (replace 'prepare-sources | 340 | (add-after 'unpack 'prepare-sources |
| 341 | (lambda* (#:key inputs #:allow-other-keys) | 341 | (lambda* (#:key inputs #:allow-other-keys) |
| 342 | ;; All a11y components depend on speech-rule-engine, which cannot be | 342 | ;; All a11y components depend on speech-rule-engine, which cannot be |
| 343 | ;; built from source. Since this only affects accessibility, remove them. | 343 | ;; built from source. Since this only affects accessibility, remove them. |
| 344 | (delete-file-recursively "ts/a11y") | 344 | (delete-file-recursively "ts/a11y/") |
| 345 | (delete-file-recursively "components/src/a11y") | 345 | (delete-file-recursively "components/mjs/a11y") |
| 346 | (delete-file-recursively "components/src/sre") | 346 | (delete-file-recursively "components/mjs/sre") |
| 347 | (delete-file-recursively "components/src/node-main") | 347 | (delete-file-recursively "components/mjs/node-main") |
| 348 | 348 | ||
| 349 | ;; Copy sources of dependencies, so we can create symlinks. | 349 | ;; Copy sources of dependencies, so we can create symlinks. |
| 350 | (mkdir-p "node_modules") | 350 | (mkdir-p "node_modules") |
| 351 | (with-directory-excursion "node_modules" | 351 | (let ((components (string-append (getcwd) "/components")) |
| 352 | (for-each | 352 | (subdir "mathjax-newcm-font")) |
| 353 | (lambda (p) | 353 | (with-directory-excursion "node_modules" |
| 354 | (copy-recursively (assoc-ref inputs (string-append "node-" p)) p)) | 354 | (for-each |
| 355 | '("mj-context-menu"))) | 355 | (lambda (p) |
| 356 | (copy-recursively (assoc-ref inputs (string-append "node-" p)) p)) | ||
| 357 | '("mj-context-menu" "mhchemparser"))) | ||
| 356 | 358 | ||
| 357 | ;; Make sure esbuild can find imports. This way we don’t have to rewrite files. | 359 | ;; Unpack font files. |
| 358 | (symlink "ts" "js") | 360 | (mkdir-p subdir) |
| 359 | (symlink "ts" "node_modules/mj-context-menu/js"))))))) | 361 | (invoke "tar" "-xf" (assoc-ref inputs "node-mathjax-newcm-font") |
| 362 | "-C" subdir | ||
| 363 | "--strip-components=1") | ||
| 364 | (substitute* (find-files subdir "\\.js$") | ||
| 365 | (("@mathjax/src/mjs/output/chtml/") | ||
| 366 | (string-append components "/mjs/output/chtml/lib/output/chtml/")) | ||
| 367 | (("@mathjax/src/mjs/output/svg/") | ||
| 368 | (string-append components "/mjs/output/svg/lib/output/svg/")) | ||
| 369 | (("@mathjax/src/mjs/output/common/") | ||
| 370 | (string-append components "/mjs/output/chtml/lib/output/common/")) | ||
| 371 | (("@mathjax/src/components/") | ||
| 372 | (string-append components "/")) | ||
| 373 | (("@mathjax/src/mjs/util/Options.js") | ||
| 374 | (string-append components "/mjs/core/lib/util/Options.js"))) | ||
| 375 | (rename-file (string-append subdir "/mjs") "components/mjs/font")) | ||
| 376 | |||
| 377 | ;; Make sure esbuild can find imports. This way we don’t have to rewrite files. | ||
| 378 | (symlink "ts" "js") | ||
| 379 | (symlink "ts" "mjs") | ||
| 380 | (symlink "ts" "node_modules/mj-context-menu/js") | ||
| 381 | (substitute* "package.json" | ||
| 382 | (("@mathjax/src/") "./js/") | ||
| 383 | (("@mathjax/mathjax-newcm-font/mjs/") "./components/mjs/font/")))) | ||
| 384 | (delete 'configure) | ||
| 385 | (replace 'build | ||
| 386 | (lambda* (#:key inputs outputs #:allow-other-keys) | ||
| 387 | (let ((esbuild (string-append (assoc-ref inputs "esbuild") | ||
| 388 | "/bin/esbuild")) | ||
| 389 | (node (string-append (assoc-ref inputs "node") | ||
| 390 | "/bin/node")) | ||
| 391 | (npm (string-append (assoc-ref inputs "node") | ||
| 392 | "/bin/npm")) | ||
| 393 | (target (string-append #$output | ||
| 394 | "/share/javascript/mathjax"))) | ||
| 395 | ;; Prepare fonts. | ||
| 396 | (invoke node "components/bin/makeAll" "--mjs" "components/mjs/font") | ||
| 397 | ;; Preprocess files and generate lib/ subdirs. | ||
| 398 | (invoke node "components/bin/makeAll" "--mjs" "components/mjs") | ||
| 399 | ;; Build components. | ||
| 400 | (apply | ||
| 401 | invoke | ||
| 402 | esbuild | ||
| 403 | "--bundle" | ||
| 404 | "--minify" | ||
| 405 | ;; esbuild cannot transpile some features to ES5, so use ES6 instead. | ||
| 406 | "--target=es6" | ||
| 407 | (string-append "--outdir=" target) | ||
| 408 | "--sourcemap" | ||
| 409 | "--outbase=components/mjs" | ||
| 410 | "--define:__dirname=\"/\"" | ||
| 411 | ;; In the browser the global object is window, see | ||
| 412 | ;; https://developer.mozilla.org/en-US/docs/Glossary/Global_object | ||
| 413 | "--define:global=window" | ||
| 414 | ;; Find all component entry points, which have the same name as their | ||
| 415 | ;; parent directory. | ||
| 416 | (filter | ||
| 417 | (lambda (f) | ||
| 418 | (string=? | ||
| 419 | (basename (dirname f)) | ||
| 420 | (string-drop-right (basename f) 3))) | ||
| 421 | (find-files "components/mjs" "\\.js$"))) | ||
| 422 | ;; Move all .js files into their parent directory, where MathJax | ||
| 423 | ;; expects them. | ||
| 424 | (for-each | ||
| 425 | (lambda (f) | ||
| 426 | (rename-file f (string-append (dirname (dirname f)) "/" (basename f)))) | ||
| 427 | (find-files target "\\.js(\\.map)?$")) | ||
| 428 | |||
| 429 | ;; Copy font files. These files contain character tables, | ||
| 430 | ;; which is why they are so large. The tools to generate | ||
| 431 | ;; these tables has not been released yet, so we install them | ||
| 432 | ;; as opaque data instead of building them from font | ||
| 433 | ;; definition files. | ||
| 434 | (install-file | ||
| 435 | "mathjax-newcm-font/chtml.js" | ||
| 436 | (string-append target "/font/")) | ||
| 437 | (install-file | ||
| 438 | "mathjax-newcm-font/tex-mml-chtml-mathjax-newcm.js" | ||
| 439 | (string-append target "/font/")) | ||
| 440 | (copy-recursively | ||
| 441 | "mathjax-newcm-font/chtml/woff2" | ||
| 442 | (string-append target "/font/chtml/woff2"))))) | ||
| 443 | (delete 'check) | ||
| 444 | (delete 'install)))) | ||
| 360 | (native-inputs | 445 | (native-inputs |
| 361 | `(("esbuild" ,esbuild) | 446 | `(("esbuild" ,esbuild) |
| 362 | ("node" ,node-lts) | 447 | ("node" ,node-lts) |
| 448 | ;; There is no public source code repository for this component. See | ||
| 449 | ;; <https://github.com/mathjax/MathJax-src/issues/973>. | ||
| 450 | ("node-mathjax-newcm-font" | ||
| 451 | ,(origin | ||
| 452 | (method url-fetch) | ||
| 453 | (uri (string-append "https://registry.npmjs.org/@mathjax/" | ||
| 454 | "mathjax-newcm-font/-/mathjax-newcm-font-" | ||
| 455 | version ".tgz")) | ||
| 456 | (sha256 | ||
| 457 | (base32 | ||
| 458 | "0cklfhl2n5zy20cnik1ww068rk91bsvllx8bnrjhjbk1sz7yw63q")))) | ||
| 363 | ("node-mj-context-menu" | 459 | ("node-mj-context-menu" |
| 364 | ,(let ((name "context-menu") | 460 | ,(let ((name "context-menu") |
| 365 | (version "0.6.1")) | 461 | (version "0.9.1")) |
| 366 | (origin | 462 | (origin |
| 367 | (method git-fetch) | 463 | (method git-fetch) |
| 368 | (uri (git-reference | 464 | (uri (git-reference |
| @@ -371,7 +467,27 @@ be able to view it naturally and easily."))) | |||
| 371 | (file-name (git-file-name name version)) | 467 | (file-name (git-file-name name version)) |
| 372 | (sha256 | 468 | (sha256 |
| 373 | (base32 | 469 | (base32 |
| 374 | "1q063l6477z285j6h5wvccp6iswvlp0jmb96sgk32sh0lf7nhknh"))))))))) | 470 | "03wdf8v99sxr91h4b21gaggf32h5l0h2jk0yw3wm6f6r1ildxdap"))))) |
| 471 | ("node-mhchemparser" | ||
| 472 | ,(let ((name "mhchemparser") | ||
| 473 | ;; Version 4.2.1. There are no tags. | ||
| 474 | (commit "2159346e2bb45ec6beaf64b617e0e5a049b4d200") | ||
| 475 | (revision "0")) | ||
| 476 | (origin | ||
| 477 | (method git-fetch) | ||
| 478 | (uri (git-reference | ||
| 479 | (url "https://github.com/mhchem/mhchemParser.git") | ||
| 480 | (commit commit))) | ||
| 481 | (file-name (git-file-name name (git-version "4.2.1" revision commit))) | ||
| 482 | (sha256 | ||
| 483 | (base32 | ||
| 484 | "1xzzfrk5bl5cby77qm0bdsmzjmfxxzjrzdh0cw5f811r78js0cib"))))))) | ||
| 485 | (home-page "https://www.mathjax.org/") | ||
| 486 | (synopsis (package-synopsis js-mathjax)) | ||
| 487 | (description (package-description js-mathjax)) | ||
| 488 | (license license:asl2.0))) | ||
| 489 | |||
| 490 | (define-public js-mathjax-for-r-mathjaxr js-mathjax-4) | ||
| 375 | 491 | ||
| 376 | (define-public js-commander | 492 | (define-public js-commander |
| 377 | (package | 493 | (package |
