diff options
| author | Lars-Dominik Braun <lars@6xq.net> | 2021-12-02 11:32:54 +0100 |
|---|---|---|
| committer | Lars-Dominik Braun <lars@6xq.net> | 2021-12-16 08:58:07 +0100 |
| commit | 44e1300994b783a758de7b3cf84287811ece5e80 (patch) | |
| tree | de899342896049513fecf24f46df6110dac1baca /gnu/packages/javascript.scm | |
| parent | 13c6ed07eaf38f51dc1c9c3329df713786cb8185 (diff) | |
gnu: Add js-mathjax-3.
* gnu/packages/javascript.scm (js-mathjax-3): New variable.
* gnu/packages/patches/mathjax-disable-webpack.patch,
gnu/packages/patches/mathjax-no-a11y.patch: New patches.
* gnu/local.mk (dist_patch_DATA): Register them.
Diffstat (limited to 'gnu/packages/javascript.scm')
| -rw-r--r-- | gnu/packages/javascript.scm | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm index 74a1e6b9bee..bc735d1c456 100644 --- a/gnu/packages/javascript.scm +++ b/gnu/packages/javascript.scm | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #:use-module (gnu packages) | 27 | #:use-module (gnu packages) |
| 28 | #:use-module (gnu packages base) | 28 | #:use-module (gnu packages base) |
| 29 | #:use-module (gnu packages compression) | 29 | #:use-module (gnu packages compression) |
| 30 | #:use-module (gnu packages node) | ||
| 30 | #:use-module (gnu packages readline) | 31 | #:use-module (gnu packages readline) |
| 31 | #:use-module (gnu packages uglifyjs) | 32 | #:use-module (gnu packages uglifyjs) |
| 32 | #:use-module (gnu packages web) | 33 | #:use-module (gnu packages web) |
| @@ -188,6 +189,125 @@ plugins or software to be installed on the browser. So the page author can | |||
| 188 | write web documents that include mathematics and be confident that readers will | 189 | write web documents that include mathematics and be confident that readers will |
| 189 | be able to view it naturally and easily."))) | 190 | be able to view it naturally and easily."))) |
| 190 | 191 | ||
| 192 | (define-public js-mathjax-3 | ||
| 193 | (package | ||
| 194 | (name "js-mathjax") | ||
| 195 | (version "3.2.0") | ||
| 196 | (source | ||
| 197 | (origin | ||
| 198 | (method git-fetch) | ||
| 199 | (uri (git-reference | ||
| 200 | (url "https://github.com/mathjax/MathJax-src") | ||
| 201 | (commit version))) | ||
| 202 | (file-name (git-file-name name version)) | ||
| 203 | (sha256 | ||
| 204 | (base32 | ||
| 205 | "05lm6nw7rzpcc5yz7xsjxi4id9369vvnrksx82nglxrqrpws97wx")) | ||
| 206 | (patches (search-patches "mathjax-disable-webpack.patch" | ||
| 207 | "mathjax-no-a11y.patch")))) | ||
| 208 | (build-system gnu-build-system) | ||
| 209 | (arguments | ||
| 210 | `(#:phases | ||
| 211 | (modify-phases %standard-phases | ||
| 212 | (add-after 'unpack 'prepare-sources | ||
| 213 | (lambda* (#:key inputs #:allow-other-keys) | ||
| 214 | ;; All a11y components depend on speech-rule-engine, which cannot be | ||
| 215 | ;; built from source. Since this only affects accessibility, remove them. | ||
| 216 | (delete-file-recursively "ts/a11y") | ||
| 217 | (delete-file-recursively "components/src/a11y") | ||
| 218 | (delete-file-recursively "components/src/sre") | ||
| 219 | (delete-file-recursively "components/src/node-main") | ||
| 220 | |||
| 221 | ;; Copy sources of dependencies, so we can create symlinks. | ||
| 222 | (mkdir-p "node_modules") | ||
| 223 | (with-directory-excursion "node_modules" | ||
| 224 | (for-each | ||
| 225 | (lambda (p) | ||
| 226 | (copy-recursively (assoc-ref inputs (string-append "node-" p)) p)) | ||
| 227 | '("mj-context-menu" "mhchemparser"))) | ||
| 228 | |||
| 229 | ;; Make sure esbuild can find imports. This way we don’t have to rewrite files. | ||
| 230 | (symlink "ts" "js") | ||
| 231 | (symlink "ts" "node_modules/mj-context-menu/js"))) | ||
| 232 | (delete 'configure) | ||
| 233 | (replace 'build | ||
| 234 | (lambda* (#:key inputs outputs #:allow-other-keys) | ||
| 235 | (let ((esbuild (string-append (assoc-ref inputs "esbuild") | ||
| 236 | "/bin/esbuild")) | ||
| 237 | (node (string-append (assoc-ref inputs "node") | ||
| 238 | "/bin/node")) | ||
| 239 | (target (string-append (assoc-ref outputs "out") | ||
| 240 | "/share/javascript/mathjax/es5"))) | ||
| 241 | ;; Preprocess files and generate lib/ subdirs. | ||
| 242 | (invoke node "components/bin/makeAll") | ||
| 243 | ;; Build components. | ||
| 244 | (apply | ||
| 245 | invoke | ||
| 246 | esbuild | ||
| 247 | "--bundle" | ||
| 248 | "--minify" | ||
| 249 | ;; esbuild cannot transpile some features to ES5, so use ES6 instead. | ||
| 250 | "--target=es6" | ||
| 251 | (string-append "--outdir=" target) | ||
| 252 | "--sourcemap" | ||
| 253 | "--outbase=components/src" | ||
| 254 | "--define:__dirname=\"/\"" | ||
| 255 | ;; In the browser the global object is window, see | ||
| 256 | ;; https://developer.mozilla.org/en-US/docs/Glossary/Global_object | ||
| 257 | "--define:global=window" | ||
| 258 | ;; Find all component entry points, which have the same name as their | ||
| 259 | ;; parent directory. | ||
| 260 | (filter | ||
| 261 | (lambda (f) | ||
| 262 | (string=? | ||
| 263 | (basename (dirname f)) | ||
| 264 | (string-drop-right (basename f) 3))) | ||
| 265 | (find-files "components/src" "\\.js$"))) | ||
| 266 | ;; Move all .js files into their parent directory, where MathJax | ||
| 267 | ;; expects them. | ||
| 268 | (for-each | ||
| 269 | (lambda (f) | ||
| 270 | (rename-file f (string-append (dirname (dirname f)) "/" (basename f)))) | ||
| 271 | (find-files target "\\.js(\\.map)?$")) | ||
| 272 | ;; Copy font files. | ||
| 273 | (copy-recursively | ||
| 274 | "ts/output/chtml/fonts/tex-woff-v2" | ||
| 275 | (string-append target "/output/chtml/fonts/woff-v2"))))) | ||
| 276 | (delete 'check) | ||
| 277 | (delete 'install)))) | ||
| 278 | (native-inputs | ||
| 279 | `(("esbuild" ,esbuild) | ||
| 280 | ("node" ,node-lts) | ||
| 281 | ("node-mj-context-menu" | ||
| 282 | ,(let ((name "context-menu") | ||
| 283 | (version "0.6.1")) | ||
| 284 | (origin | ||
| 285 | (method git-fetch) | ||
| 286 | (uri (git-reference | ||
| 287 | (url "https://github.com/zorkow/context-menu.git") | ||
| 288 | (commit (string-append "v" version)))) | ||
| 289 | (file-name (git-file-name name version)) | ||
| 290 | (sha256 | ||
| 291 | (base32 | ||
| 292 | "1q063l6477z285j6h5wvccp6iswvlp0jmb96sgk32sh0lf7nhknh"))))) | ||
| 293 | ("node-mhchemparser" | ||
| 294 | ,(let ((name "mhchemparser") | ||
| 295 | ;; Version 4.1.1. There are no tags. | ||
| 296 | (version "b1bd0670df7e9bbd5a724ac642aa2664d6e500b3")) | ||
| 297 | (origin | ||
| 298 | (method git-fetch) | ||
| 299 | (uri (git-reference | ||
| 300 | (url "https://github.com/mhchem/mhchemParser.git") | ||
| 301 | (commit version))) | ||
| 302 | (file-name (git-file-name name version)) | ||
| 303 | (sha256 | ||
| 304 | (base32 | ||
| 305 | "1g72kbxzf9f2igidpma3jwk28ln4bp3qhwspmhnm79baf3701dgv"))))))) | ||
| 306 | (home-page "https://www.mathjax.org/") | ||
| 307 | (synopsis (package-synopsis js-mathjax)) | ||
| 308 | (description (package-description js-mathjax)) | ||
| 309 | (license license:asl2.0))) | ||
| 310 | |||
| 191 | (define-public js-commander | 311 | (define-public js-commander |
| 192 | (package | 312 | (package |
| 193 | (name "js-commander") | 313 | (name "js-commander") |
