[PATCH 00/16] gnu: Add KaTeX, lessc, and flow-remove-types.

  • Open
  • quality assurance status badge
Details
2 participants
  • Liliana Marie Prikler
  • Philip McGrath
Owner
unassigned
Submitted by
Philip McGrath
Severity
normal
P
P
Philip McGrath wrote on 9 Nov 2023 17:06
(address . guix-patches@gnu.org)
cover.1699540553.git.philip@philipmcgrath.com
Hi,

This patch series adds KaTeX, which renders TeX math notation to HTML and/or
MathML. (It's somewhat similar to MathJax, but with different emphases: in
particular, the rendered output from KaTeX doesn't require JavaScript.)

Along the way, this series adds two dependencies of KaTeX that are especially
notable in their own right:

1. Patches 01/16 to 03/16 add lessc, the compiler for the Less CSS extension
language (not to be confused with the pager less).

2. Patches 04/16 to 11/16 add flow-remove-types, which erases Flow type
annotations from JavaScript source code. This enables Guix to build
software written using Flow somewhat analagously to how esbuild does with
TypeScript.

Philip

Philip McGrath (16):
gnu: Add node-is-what.
gnu: Add node-copy-anything.
gnu: Add lessc.
gnu: Add ocaml-wtf8.
gnu: Add ocaml-visitors.
gnu: Add ocaml-ppx-gen-rec.
gnu: Add ocaml-dtoa.
gnu: Add node-vlq.
gnu: Add ocaml-flow-parser.
gnu: Add node-flow-parser.
gnu: Add flow-remove-types.
gnu: js-commander: Update to 11.1.0.
gnu: js-commander: Install as a node module.
gnu: Add mftrace.
gnu: Add font-katex.
gnu: Add katex.

gnu/packages/fontutils.scm | 45 +++++
gnu/packages/javascript.scm | 381 +++++++++++++++++++++++++++++++++--
gnu/packages/node-xyz.scm | 220 +++++++++++++++++++++
gnu/packages/ocaml.scm | 99 ++++++++++
gnu/packages/web.scm | 385 ++++++++++++++++++++++++++++++++++++
5 files changed, 1113 insertions(+), 17 deletions(-)


base-commit: 19fe24c5b978a16cbca3cddbfa3ab9d1ee2c68f2
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:12
[PATCH 01/16] gnu: Add node-is-what.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
2ac6934211cc66575c8c0c53461effc3bcf8fbdf.1699540553.git.philip@philipmcgrath.com
* gnu/packages/node-xyz.scm (node-is-what): New variable.
---
gnu/packages/node-xyz.scm | 81 +++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)

Toggle diff (91 lines)
diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm
index 6c16417309..49760ded2b 100644
--- a/gnu/packages/node-xyz.scm
+++ b/gnu/packages/node-xyz.scm
@@ -1631,3 +1631,84 @@ (define-public node-yazl
@item Prefer to open input files one at a time than all at once.
@end enumerate")
(license license:expat)))
+
+(define-public node-is-what
+ (package
+ (name "node-is-what")
+ (version "4.1.16")
+ (source
+ (origin (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/mesqueeb/is-what")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "02h76klvjxgk0cl8a7sq4wbi7l4pvdimbams08l34k5carg03bdx"))
+ (snippet
+ #~(for-each delete-file
+ '("dist/cjs/index.cjs"
+ "dist/index.js")))
+ (file-name (git-file-name name version))))
+ (build-system node-build-system)
+ (native-inputs (list esbuild))
+ (arguments
+ (list
+ #:tests? #f ; needs more dependencies
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '(;; devDependencies
+ "@typescript-eslint/eslint-plugin"
+ "@typescript-eslint/parser"
+ "del-cli"
+ "eslint"
+ "eslint-config-prettier"
+ "eslint-plugin-tree-shaking"
+ "np"
+ "prettier"
+ "prettier-plugin-jsdoc"
+ "rollup"
+ "rollup-plugin-dts"
+ "rollup-plugin-esbuild"
+ "rollup-plugin-typescript2"
+ "typedoc"
+ "typescript"
+ "vitest"))))
+ (add-after 'delete-dependencies 'patch-build-script
+ (lambda args
+ (define esbuild
+ "esbuild --bundle --platform=node")
+ (define new-build-script
+ (string-append
+ esbuild
+ " --format=cjs --outfile=dist/cjs/index.cjs src/index.ts"
+ " && "
+ esbuild
+ " --format=esm --outfile=dist/index.js src/index.ts"))
+ (with-atomic-json-file-replacement "package.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("scripts" @ . alist)
+ `("scripts" @ ,@(map (match-lambda
+ (("build" . _)
+ (cons "build"
+ new-build-script))
+ (other
+ other))
+ alist)))
+ (other
+ other))
+ alist))))))))))
+ (home-page "https://npmjs.com/is-what")
+ (synopsis "Type predicate functions for JavaScript")
+ (description "This package provides simple and small type predicate
+functions for JavaScript, such as @code{isString}, @code{isDate}, and
+@code{isPlainObject}.")
+ (license license:expat)))
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 02/16] gnu: Add node-copy-anything.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
0e821283aa47a488700cd018e7487ed5498a01ba.1699540553.git.philip@philipmcgrath.com
* gnu/packages/node-xyz.scm (node-copy-anything): New variable.
---
gnu/packages/node-xyz.scm | 81 +++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)

Toggle diff (91 lines)
diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm
index 49760ded2b..ee96dee767 100644
--- a/gnu/packages/node-xyz.scm
+++ b/gnu/packages/node-xyz.scm
@@ -1712,3 +1712,84 @@ (define-public node-is-what
functions for JavaScript, such as @code{isString}, @code{isDate}, and
@code{isPlainObject}.")
(license license:expat)))
+
+(define-public node-copy-anything
+ (package
+ (name "node-copy-anything")
+ (version "3.0.5")
+ (source
+ (origin (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/mesqueeb/copy-anything")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "1lpjqanjl04k088banpns4yvp6hgf97snaj7gfbfancjpd3i8gk6"))
+ (snippet
+ #~(for-each delete-file
+ '("dist/cjs/index.cjs"
+ "dist/index.js")))
+ (file-name (git-file-name name version))))
+ (build-system node-build-system)
+ (native-inputs (list esbuild))
+ (inputs (list node-is-what))
+ (arguments
+ (list
+ #:tests? #f ; needs more dependencies
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '(;; devDependencies
+ "@typescript-eslint/eslint-plugin"
+ "@typescript-eslint/parser"
+ "del-cli"
+ "eslint"
+ "eslint-config-prettier"
+ "eslint-plugin-tree-shaking"
+ "np"
+ "prettier"
+ "rollup"
+ "rollup-plugin-dts"
+ "rollup-plugin-esbuild"
+ "rollup-plugin-typescript2"
+ "typescript"
+ "vitest"))))
+ (add-after 'delete-dependencies 'patch-build-script
+ (lambda args
+ (define esbuild
+ "esbuild --bundle --platform=node --external:is-what")
+ (define new-build-script
+ (string-append
+ esbuild
+ " --format=cjs --outfile=dist/cjs/index.cjs src/index.ts"
+ " && "
+ esbuild
+ " --format=esm --outfile=dist/index.js src/index.ts"))
+ (with-atomic-json-file-replacement "package.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("scripts" @ . alist)
+ `("scripts" @ ,@(map (match-lambda
+ (("build" . _)
+ (cons "build"
+ new-build-script))
+ (other
+ other))
+ alist)))
+ (other
+ other))
+ alist))))))))))
+ (home-page "https://npmjs.com/copy-anything")
+ (synopsis "JavaScript library for copying objects and arrays")
+ (description "This library provides deep copying for JavaScript objects
+and arrays. Its design emphasizes speed, simplicity, and correctness in the
+face of complications like special objects, symbols, and non-enumerable
+properties.")
+ (license license:expat)))
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 03/16] gnu: Add lessc.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
ab477ad53c7277a9363eb5090493dd2bc81174c8.1699540553.git.philip@philipmcgrath.com
* gnu/packages/web.scm (lessc): New variable.
---
gnu/packages/web.scm | 187 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 187 insertions(+)

Toggle diff (221 lines)
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 66d09700db..8e22997957 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -64,6 +64,7 @@
;;; Copyright © 2023 David Thompson <dthompson2@worcester.edu>
;;; Copyright © 2023 Christopher Howard <christopher@librehacker.com>
;;; Copyright © 2023 Felix Lechner <felix.lechner@lease-up.com>
+;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -98,6 +99,7 @@ (define-module (gnu packages web)
#:use-module (guix build-system gnu)
#:use-module (guix build-system go)
#:use-module (guix build-system meson)
+ #:use-module (guix build-system node)
#:use-module (guix build-system perl)
#:use-module (guix build-system pyproject)
#:use-module (guix build-system python)
@@ -168,6 +170,7 @@ (define-module (gnu packages web)
#:use-module (gnu packages ncurses)
#:use-module (gnu packages networking)
#:use-module (gnu packages node)
+ #:use-module (gnu packages node-xyz)
#:use-module (gnu packages nss)
#:use-module (gnu packages openldap)
#:use-module (gnu packages openstack)
@@ -2343,6 +2346,190 @@ (define-public sassc/libsass-3.5
"0830pjcvhzxh6yixj82x5k5r1xnadjqzi16kp53213icbly0r9ma")))))))
(properties '((hidden? . #t)))))
+(define-public lessc
+ (package
+ (name "lessc")
+ (version "4.2.0")
+ (source
+ (origin (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/less/less.js")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "1b6anlafk7lnayxy3vhsi474jcdah2ffaw2qyac5s2ibxb1wmr54"))
+ (snippet
+ #~(begin
+ (use-modules (guix build utils))
+ (delete-file-recursively "packages/less/dist")))
+ (file-name (git-file-name name version))))
+ (build-system node-build-system)
+ (native-inputs (list esbuild))
+ (inputs (list node-copy-anything))
+ (arguments
+ (list
+ #:tests? #f ; many more dependencies
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'chdir
+ (lambda args
+ (chdir "packages/less")))
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '(;; dependencies
+ "parse-node-version" ; patched out
+ "tslib" ; probably not needed w/ esbuild
+ ;; devDependencies
+ "@less/test-data"
+ "@less/test-import-module"
+ "@rollup/plugin-commonjs"
+ "@rollup/plugin-json"
+ "@rollup/plugin-node-resolve"
+ "@typescript-eslint/eslint-plugin"
+ "@typescript-eslint/parser"
+ "benny"
+ "bootstrap-less-port"
+ "chai"
+ "cross-env"
+ "diff"
+ "eslint"
+ "fs-extra"
+ "git-rev"
+ "globby"
+ "grunt"
+ "grunt-cli"
+ "grunt-contrib-clean"
+ "grunt-contrib-connect"
+ "grunt-eslint"
+ "grunt-saucelabs"
+ "grunt-shell"
+ "html-template-tag"
+ "jit-grunt"
+ "less-plugin-autoprefix"
+ "less-plugin-clean-css"
+ "minimist"
+ "mocha"
+ "mocha-headless-chrome"
+ "mocha-teamcity-reporter"
+ "nock"
+ "npm-run-all"
+ "performance-now"
+ "phin"
+ "promise"
+ "read-glob"
+ "resolve"
+ "rollup"
+ "rollup-plugin-terser"
+ "rollup-plugin-typescript2"
+ "semver"
+ "shx"
+ "time-grunt"
+ "ts-node"
+ "typescript"
+ "uikit"
+ ;; optionalDependencies
+ "errno"
+ "graceful-fs"
+ "image-size"
+ "make-dir"
+ "mime"
+ "needle"
+ "source-map"))))
+ (add-after 'delete-dependencies 'avoid-parse-node-version
+ (lambda args
+ (define version
+ #$(package-version this-package))
+ (substitute* "src/less/index.js"
+ (("import [{] version [}]" orig)
+ (string-append "// " orig))
+ (("import parseVersion from 'parse-node-version';" orig)
+ (string-append "// " orig))
+ (("const v = parseVersion[(]`v\\$[{]version[}]`[)];" orig)
+ (string-append "// " orig))
+ (("(version: )(\\[v\\.major, v\\.minor, v\\.patch],)" _ lhs rhs)
+ (string-append
+ lhs
+ "["
+ (string-join
+ (list-head (string-split
+ version (char-set-complement char-set:digit))
+ 3)
+ ", ")
+ "], // "
+ rhs)))))
+ (add-after 'avoid-parse-node-version 'do-not-target-es5
+ (lambda args
+ ;; esbuild can't compile all features to ES5
+ (with-atomic-json-file-replacement "tsconfig.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("compilerOptions" '@ . alist)
+ `("scripts" @ ,@(filter (match-lambda
+ (("target" "ES5")
+ #f)
+ (_
+ #t))
+ alist)))
+ (other
+ other))
+ alist)))))))
+ (add-after 'do-not-target-es5 'patch-build-script
+ (lambda args
+ (define new-build-script
+ (string-join
+ `("esbuild"
+ "--platform=node"
+ "--format=cjs"
+ "--outdir=lib"
+ ,@(find-files "src/less" "\\.js$")
+ ,@(find-files "src/less-node" "\\.js$"))))
+ (with-atomic-json-file-replacement "package.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("scripts" @ . alist)
+ `("scripts" @ ,@(map (match-lambda
+ (("build" . _)
+ (cons "build"
+ new-build-script))
+ (other
+ other))
+ alist)))
+ (other
+ other))
+ alist)))))))
+ (add-after 'build 'build-browser
+ (lambda args
+ (invoke "esbuild"
+ "--bundle"
+ "--platform=browser"
+ "--format=cjs"
+ "--outfile=dist/less.js"
+ "src/less-browser/bootstrap.js")
+ (invoke "esbuild"
+ "--bundle"
+ "--minify"
+ "--sourcemap"
+ "--platform=browser"
+ "--format=cjs"
+ "--outfile=dist/less.min.js"
+ "src/less-browser/bootstrap.js"))))))
+ (home-page "https://lesscss.org")
+ (synopsis "Compiler for @acronym{Less} @acronym{CSS} language extension")
+ ;; XXX: @abbr{} seems better for Less (which is always capitalized that
+ ;; way), but it is rejected as invalid Texinfo markup here.
+ (description "@acronym{Less, Leaner Style Sheets} is a
+backwards-compatible language extension for @acronym{CSS}. This package
+provides @command{lessc}, which compiles Less files to plain @acronym{CSS}.")
+ (license license:asl2.0)))
+
(define-public perl-apache-logformat-compiler
(package
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 05/16] gnu: Add ocaml-visitors.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
75521995e3f961afa09fe9f7b382b518cfd7283c.1699540553.git.philip@philipmcgrath.com
* gnu/packages/ocaml.scm (ocaml-visitors): New variable.
---
gnu/packages/ocaml.scm | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

Toggle diff (35 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index 50b0d1ddb7..f9a3932d18 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -5232,6 +5232,28 @@ (define-public ocaml-graph
(description "OCamlgraph is a generic graph library for OCaml.")
(license license:lgpl2.1)))
+(define-public ocaml-visitors
+ (package
+ (name "ocaml-visitors")
+ (version "20210608")
+ (source (origin
+ (method url-fetch)
+ (uri
+ (string-append "https://gitlab.inria.fr/fpottier/visitors/-/"
+ "archive/" version "/archive.tar.gz"))
+ (sha256
+ (base32
+ "1yx4bjw4yw3zi35yfp66x320xgb9f8jh7rqj1j7hrrvn0f60m2y2"))))
+ (build-system dune-build-system)
+ (propagated-inputs (list ocaml-ppxlib ocaml-ppx-deriving ocaml-result))
+ (home-page "https://gitlab.inria.fr/fpottier/visitors")
+ (synopsis "OCaml syntax extension for generating visitor classes")
+ (description
+ "This package provides an OCaml syntax extension that automatically
+generates object-oriented visitors for traversing and transforming data
+structures.")
+ (license license:lgpl2.1)))
+
(define-public ocaml-piqi
(package
(name "ocaml-piqi")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 06/16] gnu: Add ocaml-ppx-gen-rec.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
68e5bf3706131231c8c9bb8736eb944bda35cd12.1699540553.git.philip@philipmcgrath.com
* gnu/packages/ocaml.scm (ocaml-ppx-gen-rec): New variable.
---
gnu/packages/ocaml.scm | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

Toggle diff (41 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index f9a3932d18..b12c12fad5 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -6722,6 +6722,34 @@ (define-public ocaml-ppx-deriving
on type definitions, and a set of useful plugins for common tasks.")
(license license:expat)))
+(define-public ocaml-ppx-gen-rec
+ (package
+ (name "ocaml-ppx-gen-rec")
+ (version "2.0.0")
+ (source (origin
+ (method url-fetch)
+ (uri
+ (string-append "https://github.com/flow/ocaml-ppx_gen_rec/"
+ "releases/download/v"
+ version
+ "/ppx_gen_rec-v" version ".tbz"))
+ (sha256
+ (base32
+ "0ncy7ps0w3cnb3nk6y1j4v4g60rs500qwv1daw3a9n7n8kjj6qzy"))))
+ (build-system dune-build-system)
+ (propagated-inputs (list ocaml-ppxlib))
+ (native-inputs (list ocaml-ppx-deriving))
+ (properties `((upstream-name . "ppx_gen_rec")))
+ (home-page "https://github.com/flow/ocaml-ppx_gen_rec")
+ (synopsis "Ppx rewriter for recursive module expressions")
+ (description
+ "This package provides a ppx rewriter that transforms a recursive module
+expression into a struct. In a recursive module expression, the struct can be
+derived from the signature automatically by the compiler. This package does
+the same thing, but doing it this way allows @code{ppx_deriving} to transform
+the signature and the struct separately.")
+ (license license:expat)))
+
(define-public ocaml-ppx-derivers
(package
(name "ocaml-ppx-derivers")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 10/16] gnu: Add node-flow-parser.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
c54efbfecde79df8ccaafbc0edeb8e1ec2111ad4.1699540553.git.philip@philipmcgrath.com
* gnu/packages/web.scm (node-flow-parser): New variable.
(ocaml-flow-parser)[description]: Mention it.
---
gnu/packages/web.scm | 45 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)

Toggle diff (60 lines)
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 82923786f2..0ade9e46e3 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -2029,9 +2029,52 @@ (define-public ocaml-flow-parser
(synopsis "Parser for the Flow JavaScript type system")
(description "Flow is a gradual type system for JavaScript. This package
provides the Flow parser, which is an OCaml library that can also be compiled
-to JavaScript.")
+to JavaScript. To use the compiled parser with Node.js or NPM, see the Guix
+package @code{node-flow-parser}.")
(license license:expat)))
+(define-public node-flow-parser
+ (package
+ (inherit ocaml-flow-parser)
+ (name "node-flow-parser")
+ (properties '())
+ (outputs '("out"))
+ (propagated-inputs '())
+ (native-inputs '())
+ (inputs (list `(,ocaml-flow-parser "js")))
+ (build-system node-build-system)
+ (arguments
+ (list
+ #:tests? #f ; need unpackaged dependencies
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'delete-workspace-file
+ (lambda args
+ ;; this workspace file causes NPM to try to install dependencies
+ ;; of other packages developed in this source repository
+ (delete-file "package.json")))
+ (add-after 'delete-workspace-file 'chdir
+ (lambda args
+ (chdir "packages/flow-parser")))
+ (add-after 'chdir 'unpack-generated-js
+ (lambda* (#:key inputs #:allow-other-keys)
+ (install-file
+ (search-input-file inputs
+ "share/javascript/flow/flow_parser.js")
+ ".")
+ (delete-file "Makefile")))
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '("ast-types"
+ "colors"
+ "esprima-fb"
+ "minimist")))))))
+ (synopsis "Parser for the Flow JavaScript type system")
+ (description "Flow is a gradual type system for JavaScript. This package
+provides the Flow parser in its compiled-to-JavaScript form for use with
+Node.js and NPM.")))
+
(define-public tinyproxy
(package
(name "tinyproxy")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 11/16] gnu: Add flow-remove-types.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
00fd9449a17eb15c0816754c6e438fa399711573.1699540553.git.philip@philipmcgrath.com
* gnu/packages/web.scm (flow-remove-types): New variable.
---
gnu/packages/web.scm | 60 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)

Toggle diff (73 lines)
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 0ade9e46e3..8f0295998a 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -2075,6 +2075,66 @@ (define-public node-flow-parser
provides the Flow parser in its compiled-to-JavaScript form for use with
Node.js and NPM.")))
+(define-public flow-remove-types
+ (package
+ (inherit node-flow-parser)
+ (name "flow-remove-types")
+ (inputs (list node-flow-parser node-vlq))
+ (arguments
+ (list
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'delete-workspace-file
+ (lambda args
+ ;; this workspace file causes NPM to try to install dependencies
+ ;; of other packages developed in this source repository
+ (delete-file "package.json")))
+ (add-after 'delete-workspace-file 'chdir
+ (lambda args
+ (chdir "packages/flow-remove-types")))
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies '("pirates"))))
+ (add-after 'delete-dependencies 'remove-unsupported-features
+ (lambda args
+ (delete-file "register.js")
+ (with-output-to-file "register.js"
+ (lambda ()
+ (for-each
+ display
+ '("console.warn('flow-remove-types/register.js does not add"
+ " a require hook on Guix');\n"
+ "module.exports ="
+ " function setOptions(newOptions) {};\n"))))
+ (substitute* "flow-node"
+ (("var flowRemoveTypes")
+ (string-append
+ "process.stderr.write('flow-node: not yet supported"
+ " on Guix');\n"
+ "return process.exit(1);\n"
+ "var flowRemoveTypes")))
+ (substitute* "test.sh"
+ (("echo \"Test: node require hook\"")
+ "echo \"SKIPPING Test: node require hook\"")
+ (("RES=\\$[(]node -e 'require[(]\"\\./register\"[)];")
+ "RES=42 # ")
+ (("echo \"Test: flow-node\"")
+ "echo \"SKIPPING Test: flow-node\"")
+ (("FLOW_NODE=")
+ "FLOW_NODE=42 # ")
+ (("echo \"Test: flow-node with options\"")
+ "echo \"SKIPPING Test: flow-node with options\"")
+ (("FLOW_NODE_OPTS=")
+ "FLOW_NODE_OPTS=4 # ")))))))
+ (synopsis "Utility to erase Flow type annotations from JavaScript")
+ (description "Flow is a gradual type system for JavaScript. This package
+provides @command{flow-remove-types}, a command-line tool that erases Flow
+type annotations, producing standard JavaScript files. The functionality is
+also provided as a JavaScript library.
+
+Note that the Guix package does not yet support the @command{flow-node}
+command or the Node.js require hook for interactive development.")))
+
(define-public tinyproxy
(package
(name "tinyproxy")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 04/16] gnu: Add ocaml-wtf8.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
065050593a0d2dc5d2743ed0b8f1af728f9bc18f.1699540553.git.philip@philipmcgrath.com
* gnu/packages/ocaml.scm (ocaml-wtf8): New variable.
---
gnu/packages/ocaml.scm | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

Toggle diff (45 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index 7993dbaa73..50b0d1ddb7 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -29,6 +29,7 @@
;;; Copyright © 2022 Garek Dyszel <garekdyszel@disroot.org>
;;; Copyright © 2023 Csepp <raingloom@riseup.net>
;;; Copyright © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
+;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -3655,6 +3656,30 @@ (define-public ocaml-uutf
string values and to directly encode characters in OCaml Buffer.t values.")
(license license:isc)))
+(define-public ocaml-wtf8
+ (package
+ (name "ocaml-wtf8")
+ (version "1.0.2")
+ (source (origin
+ (method url-fetch)
+ (uri (string-append
+ "https://github.com/flow/ocaml-wtf8/releases/download/"
+ "v" version "/wtf8-v" version ".tbz"))
+ (sha256
+ (base32
+ "09ygcxxd5warkdzz17rgpidrd0pg14cy2svvnvy1hna080lzg7vp"))))
+ (build-system dune-build-system)
+ (home-page "https://github.com/flow/ocaml-wtf8")
+ (synopsis "OCaml encoder and decoder for @acronym{WTF-8}")
+ (description
+ "This library provides an OCaml encoder and decoder for @acronym{WTF-8,
+Wobbly Transformation Format---8 bit}, a superset of UTF-8 that allows
+unpaired surrogates while preserving the other well-formedness constraints of
+UTF-8. This format is useful for interoperating with systems that use
+potentially ill-formed UTF-16, notably including ECMAScript strings and
+Windows filesystems.")
+ (license license:expat)))
+
(define-public ocaml-uunf
(package
(name "ocaml-uunf")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 08/16] gnu: Add node-vlq.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
5114fc6c4d716300492b2e04d7af0389412bcf71.1699540553.git.philip@philipmcgrath.com
* gnu/packages/node-xyz.scm (node-vlq): New variable.
---
gnu/packages/node-xyz.scm | 58 +++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)

Toggle diff (68 lines)
diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm
index ee96dee767..adbac8a6cd 100644
--- a/gnu/packages/node-xyz.scm
+++ b/gnu/packages/node-xyz.scm
@@ -1793,3 +1793,61 @@ (define-public node-copy-anything
face of complications like special objects, symbols, and non-enumerable
properties.")
(license license:expat)))
+
+(define-public node-vlq
+ (package
+ (name "node-vlq")
+ (version "0.2.3") ; last version accepted by flow-remove-types ("^0.2.1")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/Rich-Harris/vlq")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "1vdrarssrwxpcngyfx050ba0gnfinzi5jn3xs4w9rnjvxngx6m8f"))
+ (snippet
+ #~(delete-file "dist/vlq.js"))
+ (file-name (git-file-name name version))))
+ (build-system node-build-system)
+ (native-inputs (list esbuild))
+ (arguments
+ (list
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '("eslint"
+ "rollup"))))
+ (add-after 'delete-dependencies 'patch-build-script
+ (lambda args
+ (define new-build-script
+ "esbuild --bundle --platform=node --outdir=dist src/vlq.js")
+ (with-atomic-json-file-replacement "package.json"
+ (lambda (js)
+ (match js
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("scripts" @ . alist)
+ `("scripts" @ ,@(map (match-lambda
+ (("build" . _)
+ (cons "build"
+ new-build-script))
+ (other
+ other))
+ alist)))
+ (other
+ other))
+ alist)))))))))))
+ (home-page "https://github.com/Rich-Harris/vlq")
+ (synopsis "JavaScript library for @acronym{VLQ} encoding and decoding")
+ (description "This package provides a JavaScript library for converting
+integers to and from Base64-encoded @acronym{VLQ, variable-length quantity}
+strings.")
+ (license license:expat)))
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 12/16] gnu: js-commander: Update to 11.1.0.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
5db0b1d07088f030bf963ff6507b840a2a632e9b.1699540553.git.philip@philipmcgrath.com
* gnu/packages/javascript.scm (js-commander): Update to 11.1.0.
---
gnu/packages/javascript.scm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Toggle diff (24 lines)
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index e70aa7d7e1..c62b23a4c4 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -373,7 +373,7 @@ (define-public js-mathjax-for-r-mathjaxr
(define-public js-commander
(package
(name "js-commander")
- (version "6.2.1")
+ (version "11.1.0")
(source
(origin
(method git-fetch)
@@ -383,7 +383,7 @@ (define-public js-commander
(file-name (git-file-name name version))
(sha256
(base32
- "126m25s6mxpxmdj4aw5awz06b47r8r798lcf1c5bnmmh39cik5i1"))))
+ "1xwh85kbxj76ni41r2h0apl8mjbfcnmxzzp3vlspq30w8kwfckni"))))
(build-system trivial-build-system)
(arguments
`(#:modules ((guix build utils))
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 09/16] gnu: Add ocaml-flow-parser.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
842136e70d3ef468a005ae7f26101523f74d9593.1699540553.git.philip@philipmcgrath.com
* gnu/packages/web.scm (ocaml-flow-parser): New variable.
---

Note: `guix lint` reports that a v0.220.1 has been tagged, but this is the
version that `guix import opam` finds, and I could not readily figure out how
to get this building with v0.220.1.

gnu/packages/web.scm | 95 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)

Toggle diff (122 lines)
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 8e22997957..82923786f2 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -95,6 +95,7 @@ (define-module (gnu packages web)
#:use-module (guix build-system cargo)
#:use-module (guix build-system cmake)
#:use-module (guix build-system copy)
+ #:use-module (guix build-system dune)
#:use-module (guix build-system glib-or-gtk)
#:use-module (guix build-system gnu)
#:use-module (guix build-system go)
@@ -172,6 +173,7 @@ (define-module (gnu packages web)
#:use-module (gnu packages node)
#:use-module (gnu packages node-xyz)
#:use-module (gnu packages nss)
+ #:use-module (gnu packages ocaml)
#:use-module (gnu packages openldap)
#:use-module (gnu packages openstack)
#:use-module (gnu packages package-management)
@@ -1937,6 +1939,99 @@ (define-public esbuild
and other data, for distribution on the web.")
(license license:expat)))
+(define-public ocaml-flow-parser
+ (package
+ (name "ocaml-flow-parser")
+ (version "0.159.0")
+ (outputs '("out" "js"))
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/facebook/flow")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "1i9svf641s24nj4w6y9vvglzg29h0lr4n9a6mvwrn9psy9x1lril"))
+ (file-name (git-file-name "flow" version))))
+ (build-system dune-build-system)
+ (propagated-inputs (list ocaml-base
+ ocaml-core-kernel
+ ocaml-dtoa
+ ocaml-sedlex
+ ocaml-wtf8))
+ (native-inputs (list js-of-ocaml
+ ocamlbuild
+ ocaml-findlib
+ ocaml-ounit2
+ ocaml-ppx-deriving
+ ocaml-ppx-gen-rec
+ ocaml-visitors))
+ (arguments
+ (list
+ #:tests? #f ; tests need lwt_ppx
+ #:package "flow_parser"
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-before 'build 'chdir
+ (lambda args
+ (chdir "src/parser")))
+ (add-before 'build 'patch-source
+ (lambda args
+ ;; Avoid errors with newer OCaml:
+ ;; "Error (warning 16 [unerasable-optional-argument]):"
+ ;; " this optional argument cannot be erased."
+ ;; "Error (warning 69 [unused-field]):"
+ ;; " mutable record field buf is never mutated."
+ ;; "Error (warning 70 [missing-mli]): Cannot find interface file."
+ (substitute* "_tags"
+ (("<\\*\\.ml\\*>: warn[(]-39[)]")
+ "<*.ml*>: warn(-16-39-70)"))
+ (substitute* "../../_tags"
+ (("<\\*\\*/\\*.ml\\*>: ")
+ "<**/*.ml*>: warn(-69), "))
+ ;; Deprecation of Js.Unsafe.variable, Js.Error, Js.raise_js_error
+ (substitute* "flow_parser_js.ml"
+ (("Js\\.Unsafe\\.variable")
+ "Js.Unsafe.pure_js_expr"))
+ (substitute* "flow_parser_dot_js.ml"
+ (("Js\\.Error")
+ "Js_of_ocaml.Js_error.Exn")
+ (("Js\\.raise_js_error")
+ "Js_of_ocaml.Js_error.raise_"))))
+ (replace 'build
+ (lambda args
+ (invoke "make"
+ (string-append "CC=" #$(cc-for-target))
+ "build-parser")))
+ (add-after 'build 'build-js
+ (lambda args
+ (invoke "make"
+ (string-append "CC=" #$(cc-for-target))
+ "js")))
+ (replace 'check
+ (lambda* (#:key tests? #:allow-other-keys)
+ (when tests?
+ (invoke "make"
+ (string-append "CC=" #$(cc-for-target))
+ "test-ocaml"))))
+ (replace 'install
+ (lambda args
+ (invoke "make"
+ (string-append "CC=" #$(cc-for-target))
+ "ocamlfind-install")))
+ (add-after 'install 'install-js
+ (lambda args
+ (install-file "flow_parser.js"
+ (string-append #$output:js
+ "/share/javascript/flow")))))))
+ (properties `((upstream-name . "flow_parser")))
+ (home-page "https://flow.org")
+ (synopsis "Parser for the Flow JavaScript type system")
+ (description "Flow is a gradual type system for JavaScript. This package
+provides the Flow parser, which is an OCaml library that can also be compiled
+to JavaScript.")
+ (license license:expat)))
+
(define-public tinyproxy
(package
(name "tinyproxy")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 07/16] gnu: Add ocaml-dtoa.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
b0471470d0682452467cbe502a87a8d9880a905f.1699540553.git.philip@philipmcgrath.com
* gnu/packages/ocaml.scm (ocaml-dtoa): New variable.
---
gnu/packages/ocaml.scm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

Toggle diff (37 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index b12c12fad5..36f349df73 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -2513,6 +2513,30 @@ (define-public ocaml4.07-fmt
"0gkkkj4x678vxdda4xaw2dd44qjacavsvn5nx8gydfwah6pjbkxk"))))
(properties '()))))
+(define-public ocaml-dtoa
+ (package
+ (name "ocaml-dtoa")
+ (version "0.3.3")
+ (source (origin
+ (method url-fetch)
+ (uri
+ (string-append "https://github.com/flow/ocaml-dtoa/releases/"
+ "download/v" version "/dtoa-" version ".tbz"))
+ (sha256
+ (base32
+ "0gpfr6iyiihmkpas542916cnhfdbrigvzwrix8jrxcljks661x6q"))))
+ (build-system dune-build-system)
+ (native-inputs (list ocaml-ounit2))
+ (home-page "https://github.com/flow/ocaml-dtoa")
+ (synopsis
+ "Efficent float to string conversion for OCaml")
+ (description
+ "This package provides functions that convert OCaml floats into strings
+quickly, accurately, and (almost always) optimally using the Grisu3 algorithm.
+The implementation was adapted from a C++ library originally developed as part
+of the V8 JavaScript engine.")
+ (license license:expat)))
+
(define-public ocaml-astring
(package
(name "ocaml-astring")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 13/16] gnu: js-commander: Install as a node module.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
b74ead23489211670495ff15023fae887cfad038.1699540553.git.philip@philipmcgrath.com
Previously, NPM would not find 'commander' when resolving dependencies.

In case anyone is using it, keep building the bundled version at
'share/javascript/commander/index.min.js', too.

* gnu/packages/javascript.scm (js-commander)[build-system]: Use
'node-build-system'.
[arguments]: Delete unpackaged 'devDependencies'. Build bundle for
compatibility.
---
gnu/packages/javascript.scm | 52 ++++++++++++++++++++++++++-----------
1 file changed, 37 insertions(+), 15 deletions(-)

Toggle diff (80 lines)
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index c62b23a4c4..97cb3b6270 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -7,6 +7,7 @@
;;; Copyright © 2021 Pierre Neidhardt <mail@ambrevar.xyz>
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2022 Frank Pursel <frank.pursel@gmail.com>
+;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -42,6 +43,7 @@ (define-module (gnu packages javascript)
#:use-module (guix build-system cmake)
#:use-module (guix build-system gnu)
#:use-module (guix build-system minify)
+ #:use-module (guix build-system node)
#:use-module (guix build-system trivial)
#:use-module (guix utils))
@@ -384,22 +386,42 @@ (define-public js-commander
(sha256
(base32
"1xwh85kbxj76ni41r2h0apl8mjbfcnmxzzp3vlspq30w8kwfckni"))))
- (build-system trivial-build-system)
+ (build-system node-build-system)
(arguments
- `(#:modules ((guix build utils))
- #:builder
- (begin
- (use-modules (guix build utils))
- (chdir (assoc-ref %build-inputs "source"))
- (let ((esbuild (search-input-file %build-inputs "/bin/esbuild"))
- (target (string-append %output "/share/javascript/commander")))
- (invoke esbuild
- "--bundle"
- "--minify"
- "--tsconfig=tsconfig.json"
- "--platform=node"
- (string-append "--outfile=" target "/index.min.js")
- "index.js")))))
+ (list
+ #:tests? #f ; many more dependencies
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies `(;; devDependencies
+ "@types/jest"
+ "@types/node"
+ "@typescript-eslint/eslint-plugin"
+ "@typescript-eslint/parser"
+ "eslint"
+ "eslint-config-standard"
+ "eslint-config-standard-with-typescript"
+ "eslint-plugin-import"
+ "eslint-plugin-jest"
+ "eslint-plugin-n"
+ "eslint-plugin-promise"
+ "jest"
+ "ts-jest"
+ "tsd"
+ "typescript"))))
+ (add-after 'install 'install-compat
+ (lambda args
+ ;; This is what this package built before adopting
+ ;; node-build-system. Does anything use it?
+ (invoke "esbuild"
+ "--bundle"
+ "--minify"
+ "--platform=node"
+ (string-append "--outfile="
+ #$output
+ "/share/javascript/commander/index.min.js")
+ "index.js"))))))
(native-inputs
(list esbuild))
(home-page "https://github.com/tj/commander.js")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 14/16] gnu: Add mftrace.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
19765a75ed634d3c1749e9a81c25a31be27a8c75.1699540553.git.philip@philipmcgrath.com
* gnu/packages/fontutils.scm (mftrace): New variable.
---
gnu/packages/fontutils.scm | 45 ++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)

Toggle diff (58 lines)
diff --git a/gnu/packages/fontutils.scm b/gnu/packages/fontutils.scm
index 5bfdea1b27..6bab6ab7df 100644
--- a/gnu/packages/fontutils.scm
+++ b/gnu/packages/fontutils.scm
@@ -1182,6 +1182,51 @@ (define-public ttf2pt1
(home-page "https://ttf2pt1.sourceforge.net/")
(license license:bsd-3)))
+(define-public mftrace
+ (let ((commit "3b4bc2e5b8a4ae6f9c776593961b38389e62a484")
+ ;; see https://github.com/hanwen/mftrace/pull/12
+ (revision "0"))
+ (package
+ (name "mftrace")
+ (version (git-version "1.2.20" revision commit))
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/hanwen/mftrace")
+ (commit commit)))
+ (sha256
+ (base32 "01cg6z1z69za07wrvx1y5dnfagx4di2a9qnx25f97l6843x03s36"))
+ (file-name (git-file-name name version))))
+ (build-system gnu-build-system)
+ (native-inputs (list autoconf
+ ;; for tests:
+ (texlive-updmap.cfg
+ (list texlive-cm))))
+ (propagated-inputs (list potrace lcdf-typetools))
+ (arguments
+ (list
+ ;; setting CC is needed for implicit rule
+ #:make-flags #~(list (string-append "CC=" #$(cc-for-target)))
+ #:test-target "test"
+ #:phases
+ #~(modify-phases %standard-phases
+ (replace 'bootstrap
+ (lambda args
+ (invoke "autoconf"))))))
+ (home-page "https://lilypond.org/mftrace/")
+ (synopsis "Scalable PostScript fonts for MetaFont")
+ (description "This package provides @command{mftrace}, a small Python
+program that lets you trace a TeX bitmap font into a PFA or PFB font (a
+PostScript Type 1 Scalable Font) or a @acronym{TTF,TrueType Font}.
+
+Scalable fonts offer many advantages over bitmaps, as they allow documents to
+render correctly at many printer resolutions. Moreover, Ghostscript can
+generate much better PDFs if given scalable PostScript fonts.
+
+Versions of this program prior to 1.0.5 were called @command{pktrace}.")
+ (license license:gpl2+))))
+
(define-public woff2
(package
(name "woff2")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 15/16] gnu: Add font-katex.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
2dde955ad085ec06cf5734171cefc26c36465c5a.1699540553.git.philip@philipmcgrath.com
* gnu/packages/javascript.scm (font-katex): New variable.
---
gnu/packages/javascript.scm | 74 +++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)

Toggle diff (104 lines)
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index 97cb3b6270..ee7a48154c 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -30,9 +30,15 @@ (define-module (gnu packages javascript)
#:use-module (gnu packages base)
#:use-module (gnu packages bash)
#:use-module (gnu packages compression)
+ #:use-module (gnu packages fontutils)
#:use-module (gnu packages java)
#:use-module (gnu packages node)
+ #:use-module (gnu packages perl)
+ #:use-module (gnu packages python)
+ #:use-module (gnu packages python-compression)
+ #:use-module (gnu packages python-xyz)
#:use-module (gnu packages readline)
+ #:use-module (gnu packages tex)
#:use-module (gnu packages uglifyjs)
#:use-module (gnu packages web)
#:use-module (guix gexp)
@@ -41,6 +47,7 @@ (define-module (gnu packages javascript)
#:use-module (guix git-download)
#:use-module (guix build-system ant)
#:use-module (guix build-system cmake)
+ #:use-module (guix build-system copy)
#:use-module (guix build-system gnu)
#:use-module (guix build-system minify)
#:use-module (guix build-system node)
@@ -372,6 +379,73 @@ (define-public js-mathjax-for-r-mathjaxr
(base32
"1q063l6477z285j6h5wvccp6iswvlp0jmb96sgk32sh0lf7nhknh")))))))))
+(define-public font-katex
+ (package
+ (name "font-katex")
+ (version "0.16.4")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/KaTeX/KaTeX")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32
+ "0z6y2188lhfv0gk0hp4rm37g6fs99qb3ab2q3n9g76ga9dwxhw3s"))
+ (snippet
+ ;; unbundle generated files
+ #~(begin
+ (use-modules (guix build utils))
+ (delete-file "src/fontMetricsData.js")
+ (delete-file-recursively "fonts")))
+ (file-name (git-file-name "katex" version))))
+ (build-system copy-build-system)
+ (native-inputs (list (texlive-updmap.cfg
+ (list texlive-amsfonts
+ texlive-cm
+ texlive-fonts-rsfs))
+ fontforge
+ mftrace
+ ttfautohint
+ perl
+ perl-json
+ python
+ python-fonttools
+ python-brotli
+ python-zopfli
+ which))
+ (arguments
+ (list
+ #:install-plan
+ #~`(("fonts/" "share/fonts/truetype/katex/")
+ ("src/fontMetricsData.js" "share/katex/"))
+ #:imported-modules
+ `((guix build union)
+ ,@%copy-build-system-modules)
+ #:modules
+ '((guix build copy-build-system)
+ (guix build union)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-before 'install 'build
+ (lambda args
+ (invoke "make" "-C" "src/fonts" "all")
+ (union-build "fonts"
+ '("src/fonts/ttf"
+ "src/fonts/woff"
+ "src/fonts/woff2")
+ #:symlink copy-file)))
+ (add-after 'build 'build-metrics
+ (lambda args
+ (with-directory-excursion "dockers/fonts"
+ ;; script assumes it is run from this directory
+ (invoke "./buildMetrics.sh")))))))
+ (home-page "https://katex.org")
+ (synopsis "Fonts for KaTeX")
+ (description "This package contains the fonts required for KaTeX.")
+ (license license:expat)))
+
(define-public js-commander
(package
(name "js-commander")
--
2.41.0
P
P
Philip McGrath wrote on 9 Nov 2023 17:26
[PATCH 16/16] gnu: Add katex.
(address . 67019@debbugs.gnu.org)(name . Philip McGrath)(address . philip@philipmcgrath.com)
a79a3cc99c5cb36f3f3a8c51f417df313d4a0b2f.1699540553.git.philip@philipmcgrath.com
* gnu/packages/javascript.scm (katex): New variable.
---
gnu/packages/javascript.scm | 255 +++++++++++++++++++++++++++++++++++-
1 file changed, 253 insertions(+), 2 deletions(-)

Toggle diff (289 lines)
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index ee7a48154c..76a51c22ac 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -32,6 +32,7 @@ (define-module (gnu packages javascript)
#:use-module (gnu packages compression)
#:use-module (gnu packages fontutils)
#:use-module (gnu packages java)
+ #:use-module (gnu packages man)
#:use-module (gnu packages node)
#:use-module (gnu packages perl)
#:use-module (gnu packages python)
@@ -382,7 +383,7 @@ (define-public js-mathjax-for-r-mathjaxr
(define-public font-katex
(package
(name "font-katex")
- (version "0.16.4")
+ (version "0.16.9")
(source
(origin
(method git-fetch)
@@ -391,7 +392,7 @@ (define-public font-katex
(commit (string-append "v" version))))
(sha256
(base32
- "0z6y2188lhfv0gk0hp4rm37g6fs99qb3ab2q3n9g76ga9dwxhw3s"))
+ "1aq8n9s4r15m1fdi4h58qxal4brkafm4xsw6rpz40wqi9454kkgn"))
(snippet
;; unbundle generated files
#~(begin
@@ -446,6 +447,256 @@ (define-public font-katex
(description "This package contains the fonts required for KaTeX.")
(license license:expat)))
+(define-public katex
+ (package
+ (inherit font-katex)
+ (name "katex")
+ (outputs '("out" "dist"))
+ (build-system node-build-system)
+ (native-inputs
+ (list esbuild
+ flow-remove-types
+ help2man
+ lessc))
+ (inputs
+ (list font-katex
+ js-commander))
+ (arguments
+ (list
+ #:tests? #f ; many more dependencies
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (srfi srfi-1)
+ (srfi srfi-26)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-before 'patch-dependencies 'move-sources
+ (lambda* (#:key inputs #:allow-other-keys)
+ ;; Our node-build-system doesn't properly respect the "files"
+ ;; entry in "package.json" to determine which files to install.
+ ;; This case is particularly egregious because the source
+ ;; repository also contains the source for the whole katex.org
+ ;; website. For now, manually do what "files" ought to do.
+ (mkdir "../guix-source")
+ (copy-recursively "src" "../guix-source/src")
+ (copy-recursively "contrib" "../guix-source/contrib")
+ (for-each (cut install-file <> "../guix-source")
+ '("README.md"
+ "LICENSE"
+ "package.json"
+ "katex.js"
+ "cli.js"))
+ (install-file
+ (search-input-file inputs "share/katex/fontMetricsData.js")
+ "../guix-source/src")
+ (chdir "../guix-source")))
+ (add-after 'move-sources 'patch-package-json
+ (lambda args
+ (with-atomic-json-file-replacement "package.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (filter-map
+ (match-lambda
+ (((or "devDependencies" "scripts") . _)
+ #f)
+ ;; ESBuild can't generate Universal Module Definitions,
+ ;; so keep our CJS separate from our browser builds:
+ (("files" . lst)
+ `("files" "guix-node-cjs/" ,@lst))
+ (("main" . "dist/katex.js")
+ `("main" . "guix-node-cjs/katex.js"))
+ (("exports" '@ . alist)
+ `("exports" @
+ ,@(map (match-lambda
+ (("./*" . "./*")
+ `("./*" . "./*"))
+ ((lhs '@ . alist)
+ `(,lhs @
+ ,@(map (match-lambda
+ (("require" . ,str)
+ (cons
+ "require"
+ (string-append
+ "./guix-node-cjs/"
+ (substring str
+ (string-length
+ "./dist")))))
+ (other
+ other))
+ alist))))
+ alist)))
+ (other
+ other))
+ alist)))))))
+ (add-after 'patch-dependencies 'patch-sources
+ (lambda* (#:key inputs #:allow-other-keys)
+ (substitute* "src/SourceLocation.js"
+ ;; for some reason, the + prefix isn't handled
+ ;; by flow-remove-types
+ (("[+](lexer|start|end)" _ name)
+ name))
+ (substitute* "src/fonts.less"
+ ;; what webpack would do
+ (("@font-folder: \"\\.\\./fonts\";" orig)
+ (string-append "@font-folder: \"fonts\"; // " orig)))
+ (define version
+ #$(package-version this-package))
+ (substitute* "src/katex.less"
+ (("@version: \"\";" orig)
+ (string-append "@version: \"" version "\"; // " orig)))
+ (substitute* "katex.js"
+ (("version: __VERSION__," orig)
+ (string-append "version: \"" version "\", // " orig)))))
+ (add-after 'patch-sources 'erase-types
+ (lambda args
+ (invoke "flow-remove-types"
+ "--sourcemaps"
+ "--out-dir" "../erased/src/"
+ "src/")
+ (invoke "flow-remove-types"
+ "--sourcemaps"
+ "--out-dir" "../erased/"
+ "katex.js")
+ (invoke "flow-remove-types"
+ "--sourcemaps"
+ "--out-dir" "../erased/contrib/"
+ "contrib/")))
+ (add-after 'erase-types 'build-js
+ (lambda args
+ (with-directory-excursion "../erased"
+ ;; ^ avoid "../erased" in generated code
+ (define (esbuild . args)
+ (apply invoke `("esbuild"
+ "--bundle"
+ "--log-limit=0"
+ "--platform=neutral"
+ ,@args)))
+ (esbuild "--outfile=../guix-source/dist/katex.mjs"
+ "--format=esm"
+ "katex.js")
+ ;; Workaround for different handling of ES6 default export
+ ;; when generating CJS:
+ (esbuild "--outfile=katex-cjs.js"
+ "--format=cjs"
+ "katex.js")
+ (with-output-to-file "katex-wrapper.js"
+ (lambda ()
+ (display
+ "module.exports = require('./katex-cjs.js').default;\n")))
+ (esbuild "--outfile=../guix-source/guix-node-cjs/katex.js"
+ "--format=cjs"
+ "katex-wrapper.js")
+ (esbuild "--outfile=../guix-source/dist/katex.js"
+ "--format=iife"
+ "--global-name=katex"
+ "katex-wrapper.js")
+ (esbuild "--outfile=../guix-source/dist/katex.min.js"
+ "--minify"
+ "--format=iife"
+ "--global-name=katex"
+ "katex-wrapper.js")
+ ;; Build extensions:
+ (for-each
+ (match-lambda
+ ((name export)
+ ;; The copy-tex extension doesn't actually import katex,
+ ;; but it's harmless to handle it the same way.
+ (with-directory-excursion (string-append "contrib/" name)
+ (esbuild (string-append "--outfile=../../../guix-source"
+ "/guix-node-cjs/contrib/"
+ name ".js")
+ "--format=cjs"
+ "--external:katex"
+ (string-append name ".js"))
+ (substitute* (string-append name ".js")
+ (("import katex from \"katex\";")
+ "import katex from \"../katex.mjs\";"))
+ (esbuild (string-append "--outfile=" name ".mjs")
+ "--format=esm"
+ "--external:../katex.mjs"
+ (string-append name ".js"))
+ (install-file (string-append name ".mjs")
+ "../../../guix-source/dist/contrib")
+ (substitute* (string-append name ".js")
+ (("import katex")
+ "// import katex"))
+ (for-each
+ (lambda (minify?)
+ (apply
+ esbuild
+ `(,(string-append "--outfile=../../.."
+ "/guix-source/dist/contrib/"
+ name
+ (if minify? ".min" "")
+ ".js")
+ "--format=iife"
+ ,@(if minify?
+ '("--minify")
+ '())
+ ,@(if export
+ `("--global-name=guixTmp"
+ ,(string-append "--banner:js=const "
+ export
+ " = (() => {")
+ "--footer:js=return guixTmp.default;\n})();")
+ '())
+ ,(string-append name ".js"))))
+ '(#t #f)))))
+ '(("auto-render" "renderMathInElement")
+ ("copy-tex" #f)
+ ("mathtex-script-type" #f)
+ ("mhchem" #f)
+ ("render-a11y-string" "renderA11yString"))))))
+ (add-after 'build-js 'build-css
+ (lambda args
+ (invoke "lessc" "src/katex.less" "dist/katex.css")))
+ (add-after 'install 'generate-man-page
+ (lambda args
+ (invoke "help2man"
+ "-N"
+ "-n" "render TeX math to HTML and MathML"
+ "--output=katex.1"
+ (string-append #$output "/bin/katex"))
+ (install-file "katex.1"
+ (string-append #$output "/share/man/man1"))))
+ (add-after 'generate-man-page 'install-dist
+ (lambda* (#:key inputs #:allow-other-keys)
+ ;; The CSS, fonts, etc. needed for KaTeX, plus the optional
+ ;; bundled version of the JavaScript for dynamic use in the
+ ;; browser, are in the 'dist' directory of the Node module.
+ ;; Putting them in a separate output lets them be used without
+ ;; retaining a reference to Node and the cli utility.
+ ;; In Debian, 'dist' is a symlink to /usr/share/javascript/katex:
+ ;; do likewise to help tools that may need to find it.
+ (define up-dist-dir
+ (string-append #$output:dist "/share/javascript"))
+ (define dist-dir
+ (string-append up-dist-dir "/katex"))
+ (mkdir-p up-dist-dir)
+ (with-directory-excursion
+ (string-append #$output "/lib/node_modules/katex")
+ (rename-file "dist" dist-dir)
+ (symlink dist-dir "dist"))
+ (with-directory-excursion dist-dir
+ ;; Link the fonts to where the CSS expects them:
+ (symlink (search-input-directory inputs
+ "share/fonts/truetype/katex")
+ "fonts")
+ ;; We can't actually minify the CSS, but fake it for anything
+ ;; that may expect it. With Brotli compression, the difference
+ ;; is only about 300 bytes anyway.
+ (symlink "katex.css" "katex.min.css")))))))
+ (synopsis "Fast math typesetting for the web")
+ (description "KaTeX renders TeX math notation to HTML and/or MathML. The
+rendered output does not depend on JavaScript, so rendering can be done
+entirely ahead-of-time using the @command{katex} command-line tool. When
+desired, KaTeX can also be used as a JavaScript library in the browser to
+render math dynamically, and it is designed to be fast, even on pages with
+hundreds of mathematical expressions.")))
+
(define-public js-commander
(package
(name "js-commander")
--
2.41.0
L
L
Liliana Marie Prikler wrote on 11 Nov 2023 01:56
Re: [PATCH 03/16] gnu: Add lessc.
a4bff90da2e236a8d11d9e414400390eeb416077.camel@gmail.com
Am Donnerstag, dem 09.11.2023 um 11:26 -0500 schrieb Philip McGrath:
Toggle quote (206 lines)
> * gnu/packages/web.scm (lessc): New variable.
> ---
>  gnu/packages/web.scm | 187
> +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 187 insertions(+)
>
> diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
> index 66d09700db..8e22997957 100644
> --- a/gnu/packages/web.scm
> +++ b/gnu/packages/web.scm
> @@ -64,6 +64,7 @@
>  ;;; Copyright © 2023 David Thompson <dthompson2@worcester.edu>
>  ;;; Copyright © 2023 Christopher Howard
> <christopher@librehacker.com>
>  ;;; Copyright © 2023 Felix Lechner <felix.lechner@lease-up.com>
> +;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
>  ;;;
>  ;;; This file is part of GNU Guix.
>  ;;;
> @@ -98,6 +99,7 @@ (define-module (gnu packages web)
>    #:use-module (guix build-system gnu)
>    #:use-module (guix build-system go)
>    #:use-module (guix build-system meson)
> +  #:use-module (guix build-system node)
>    #:use-module (guix build-system perl)
>    #:use-module (guix build-system pyproject)
>    #:use-module (guix build-system python)
> @@ -168,6 +170,7 @@ (define-module (gnu packages web)
>    #:use-module (gnu packages ncurses)
>    #:use-module (gnu packages networking)
>    #:use-module (gnu packages node)
> +  #:use-module (gnu packages node-xyz)
>    #:use-module (gnu packages nss)
>    #:use-module (gnu packages openldap)
>    #:use-module (gnu packages openstack)
> @@ -2343,6 +2346,190 @@ (define-public sassc/libsass-3.5
>                                                     
> "0830pjcvhzxh6yixj82x5k5r1xnadjqzi16kp53213icbly0r9ma")))))))
>      (properties '((hidden? . #t)))))
>  
> +(define-public lessc
> +  (package
> +    (name "lessc")
> +    (version "4.2.0")
> +    (source
> +     (origin (method git-fetch)
> +             (uri (git-reference
> +                   (url "https://github.com/less/less.js")
> +                   (commit (string-append "v" version))))
> +             (sha256
> +              (base32
> "1b6anlafk7lnayxy3vhsi474jcdah2ffaw2qyac5s2ibxb1wmr54"))
> +             (snippet
> +              #~(begin
> +                  (use-modules (guix build utils))
> +                  (delete-file-recursively "packages/less/dist")))
> +             (file-name (git-file-name name version))))
> +    (build-system node-build-system)
> +    (native-inputs (list esbuild))
> +    (inputs (list node-copy-anything))
> +    (arguments
> +     (list
> +      #:tests? #f ; many more dependencies
> +      #:modules
> +      `((guix build node-build-system)
> +        (ice-9 match)
> +        (guix build utils))
> +      #:phases
> +      #~(modify-phases %standard-phases
> +          (add-after 'unpack 'chdir
> +            (lambda args
> +              (chdir "packages/less")))
> +          (add-after 'patch-dependencies 'delete-dependencies
> +            (lambda args
> +              (delete-dependencies
> +               '(;; dependencies
> +                 "parse-node-version" ; patched out
> +                 "tslib" ; probably not needed w/ esbuild
> +                 ;; devDependencies
> +                 "@less/test-data"
> +                 "@less/test-import-module"
> +                 "@rollup/plugin-commonjs"
> +                 "@rollup/plugin-json"
> +                 "@rollup/plugin-node-resolve"
> +                 "@typescript-eslint/eslint-plugin"
> +                 "@typescript-eslint/parser"
> +                 "benny"
> +                 "bootstrap-less-port"
> +                 "chai"
> +                 "cross-env"
> +                 "diff"
> +                 "eslint"
> +                 "fs-extra"
> +                 "git-rev"
> +                 "globby"
> +                 "grunt"
> +                 "grunt-cli"
> +                 "grunt-contrib-clean"
> +                 "grunt-contrib-connect"
> +                 "grunt-eslint"
> +                 "grunt-saucelabs"
> +                 "grunt-shell"
> +                 "html-template-tag"
> +                 "jit-grunt"
> +                 "less-plugin-autoprefix"
> +                 "less-plugin-clean-css"
> +                 "minimist"
> +                 "mocha"
> +                 "mocha-headless-chrome"
> +                 "mocha-teamcity-reporter"
> +                 "nock"
> +                 "npm-run-all"
> +                 "performance-now"
> +                 "phin"
> +                 "promise"
> +                 "read-glob"
> +                 "resolve"
> +                 "rollup"
> +                 "rollup-plugin-terser"
> +                 "rollup-plugin-typescript2"
> +                 "semver"
> +                 "shx"
> +                 "time-grunt"
> +                 "ts-node"
> +                 "typescript"
> +                 "uikit"
> +                 ;; optionalDependencies
> +                 "errno"
> +                 "graceful-fs"
> +                 "image-size"
> +                 "make-dir"
> +                 "mime"
> +                 "needle"
> +                 "source-map"))))
> +          (add-after 'delete-dependencies 'avoid-parse-node-version
> +            (lambda args
> +              (define version
> +                #$(package-version this-package))
> +              (substitute* "src/less/index.js"
> +                (("import [{] version [}]" orig)
> +                 (string-append "// " orig))
> +                (("import parseVersion from 'parse-node-version';"
> orig)
> +                 (string-append "// " orig))
> +                (("const v = parseVersion[(]`v\\$[{]version[}]`[)];"
> orig)
> +                 (string-append "// " orig))
> +                (("(version: )(\\[v\\.major, v\\.minor,
> v\\.patch],)" _ lhs rhs)
> +                 (string-append
> +                  lhs
> +                  "["
> +                  (string-join
> +                   (list-head (string-split
> +                               version (char-set-complement char-
> set:digit))
> +                              3)
> +                   ", ")
> +                  "], // "
> +                  rhs)))))
> +          (add-after 'avoid-parse-node-version 'do-not-target-es5
> +            (lambda args
> +              ;; esbuild can't compile all features to ES5
> +              (with-atomic-json-file-replacement "tsconfig.json"
> +                (match-lambda
> +                  (('@ . alist)
> +                   (cons '@
> +                    (map (match-lambda
> +                           (("compilerOptions" '@ . alist)
> +                            `("scripts" @ ,@(filter (match-lambda
> +                                                      (("target"
> "ES5")
> +                                                       #f)
> +                                                      (_
> +                                                       #t))
> +                                                    alist)))
> +                           (other
> +                            other))
> +                         alist)))))))
> +          (add-after 'do-not-target-es5 'patch-build-script
> +            (lambda args
> +              (define new-build-script
> +                (string-join
> +                 `("esbuild"
> +                   "--platform=node"
> +                   "--format=cjs"
> +                   "--outdir=lib"
> +                   ,@(find-files "src/less" "\\.js$")
> +                   ,@(find-files "src/less-node" "\\.js$"))))
> +              (with-atomic-json-file-replacement "package.json"
> +                (match-lambda
> +                  (('@ . alist)
> +                   (cons '@
> +                    (map (match-lambda
> +                           (("scripts" @ . alist)
> +                            `("scripts" @ ,@(map (match-lambda
> +                                                   (("build" . _)
> +                                                    (cons "build"
> +                                                          new-build-
> script))
> +                                                   (other
> +                                                    other))
> +                                                 alist)))
> +                           (other
> +                            other))
> +                         alist)))))))
Can we somehow save a bit of horizontal real-estate here? Same goes
for 1 and 2.
Toggle quote (29 lines)
> +          (add-after 'build 'build-browser
> +            (lambda args
> +              (invoke "esbuild"
> +                      "--bundle"
> +                      "--platform=browser"
> +                      "--format=cjs"
> +                      "--outfile=dist/less.js"
> +                      "src/less-browser/bootstrap.js")
> +              (invoke "esbuild"
> +                      "--bundle"
> +                      "--minify"
> +                      "--sourcemap"
> +                      "--platform=browser"
> +                      "--format=cjs"
> +                      "--outfile=dist/less.min.js"
> +                      "src/less-browser/bootstrap.js"))))))
> +    (home-page "https://lesscss.org")
> +    (synopsis "Compiler for @acronym{Less} @acronym{CSS} language
> extension")
> +    ;; XXX: @abbr{} seems better for Less (which is always
> capitalized that
> +    ;; way), but it is rejected as invalid Texinfo markup here.
> +    (description "@acronym{Less, Leaner Style Sheets} is a
> +backwards-compatible language extension for @acronym{CSS}.  This
> package
> +provides @command{lessc}, which compiles Less files to plain
> @acronym{CSS}.")
> +    (license license:asl2.0)))
> +
IMHO it doesn't make sense to type @acronym without the expansion.

Cheers
P
P
Philip McGrath wrote on 15 Nov 2023 20:35
a37b92c6-442b-4bdd-a0e7-d6fdcd36f7e2@philipmcgrath.com
Hi,

Thanks for taking a look at this!

On 11/10/23 19:56, Liliana Marie Prikler wrote:
Toggle quote (4 lines)
> Am Donnerstag, dem 09.11.2023 um 11:26 -0500 schrieb Philip McGrath:
>> * gnu/packages/web.scm (lessc): New variable.
>>
>> [...]
>>
Toggle quote (49 lines)
>> +          (add-after 'avoid-parse-node-version 'do-not-target-es5
>> +            (lambda args
>> +              ;; esbuild can't compile all features to ES5
>> +              (with-atomic-json-file-replacement "tsconfig.json"
>> +                (match-lambda
>> +                  (('@ . alist)
>> +                   (cons '@
>> +                    (map (match-lambda
>> +                           (("compilerOptions" '@ . alist)
>> +                            `("scripts" @ ,@(filter (match-lambda
>> +                                                      (("target"
>> "ES5")
>> +                                                       #f)
>> +                                                      (_
>> +                                                       #t))
>> +                                                    alist)))
>> +                           (other
>> +                            other))
>> +                         alist)))))))
>> +          (add-after 'do-not-target-es5 'patch-build-script
>> +            (lambda args
>> +              (define new-build-script
>> +                (string-join
>> +                 `("esbuild"
>> +                   "--platform=node"
>> +                   "--format=cjs"
>> +                   "--outdir=lib"
>> +                   ,@(find-files "src/less" "\\.js$")
>> +                   ,@(find-files "src/less-node" "\\.js$"))))
>> +              (with-atomic-json-file-replacement "package.json"
>> +                (match-lambda
>> +                  (('@ . alist)
>> +                   (cons '@
>> +                    (map (match-lambda
>> +                           (("scripts" @ . alist)
>> +                            `("scripts" @ ,@(map (match-lambda
>> +                                                   (("build" . _)
>> +                                                    (cons "build"
>> +                                                          new-build-
>> script))
>> +                                                   (other
>> +                                                    other))
>> +                                                 alist)))
>> +                           (other
>> +                            other))
>> +                         alist)))))))
> Can we somehow save a bit of horizontal real-estate here? Same goes
> for 1 and 2.

To clarify, do you mean vertical or horizontal?

The long list of dependencies to delete does take a *lot* of vertical
space, especially in this patch. The obvious alternative would be to put
more than one dependency on the same line. I'm not opposed to that, but
it would deviate from normal style and could make future diffs less clear.

For horizontal space, I don't really like any of the alternatives I've
thought of. The culprit in each case seems to be the three
`match-lambda`s under `with-atomic-json-file-replacement`. (Specifically
in do-not-target-es5, I guess the innermost one could be replaced with
just `remove`, which might help a little.)

In normal programming, I'd want to abstract the three patch-build-script
phases into a helper function that would take the new-build-script
string as an argument, but that's a bit awkward to do with build-side
code in Guix. Putting it in guix/build/node-build-system.scm (like
delete-dependencies) would trigger a lot of rebuilds that seem hard to
justify. It could be done as a gexp-producing function, but
node-is-what, node-copy-anything, and lessc aren't in the same file: I
guess the arguments field is delayed, so maybe it wouldn't create a
cyclic dependency issue, but that seemed to open a whole new can of worms.

(Making e.g. `jsobject-update*` from guix/build/node-build-system.scm
public would also help, but I have no desire to revisit that.)

Obviously it would be possible, within each G-expression, to lift one of
the `match-lambda`s (probably the innermost one) to a local definition,
but IMO that would make the structure of the code less obviously
correspond to the structure of the JSON being transformed.

I could also imagine breaking these lines:

>> + (("scripts" @ . alist)
>> + `("scripts" @ ,@(map (match-lambda

instead as:

>> + (("scripts"
>> + @ . alist)
>> + `("scripts"
>> + @ ,@(map (match-lambda

but that doesn't seem like much of an improvement to me.


Toggle quote (15 lines)
>> +    (synopsis "Compiler for @acronym{Less} @acronym{CSS} language
>> extension")
>> +    ;; XXX: @abbr{} seems better for Less (which is always
>> capitalized that
>> +    ;; way), but it is rejected as invalid Texinfo markup here.
>> +    (description "@acronym{Less, Leaner Style Sheets} is a
>> +backwards-compatible language extension for @acronym{CSS}.  This
>> package
>> +provides @command{lessc}, which compiles Less files to plain
>> @acronym{CSS}.")
>> +    (license license:asl2.0)))
>> +
> IMHO it doesn't make sense to type @acronym without the expansion.
>

I don't have a strong opinion on this, and I only know the tiny amount
of Texinfo I've picked up for Guix. I inferred from the fact that the
one-argument version of @acronym{} exists that it should be used when
applicable. I know that some typographical conventions handle capital
letters and punctuation in acronyms specially, which would be one reason
for @acronym{} to exist, but maybe that isn't relevant?

Philip
L
L
Liliana Marie Prikler wrote on 15 Nov 2023 21:23
522f4e2a30c81dc738096bac21f46be50ddd8563.camel@gmail.com
Am Mittwoch, dem 15.11.2023 um 14:35 -0500 schrieb Philip McGrath:
Toggle quote (67 lines)
> Hi,
>
> Thanks for taking a look at this!
>
> On 11/10/23 19:56, Liliana Marie Prikler wrote:
> > Am Donnerstag, dem 09.11.2023 um 11:26 -0500 schrieb Philip
> > McGrath:
> > > * gnu/packages/web.scm (lessc): New variable.
> > >
> > > [...]
>  >>
> > > +          (add-after 'avoid-parse-node-version 'do-not-target-
> > > es5
> > > +            (lambda args
> > > +              ;; esbuild can't compile all features to ES5
> > > +              (with-atomic-json-file-replacement "tsconfig.json"
> > > +                (match-lambda
> > > +                  (('@ . alist)
> > > +                   (cons '@
> > > +                    (map (match-lambda
> > > +                           (("compilerOptions" '@ . alist)
> > > +                            `("scripts" @ ,@(filter (match-
> > > lambda
> > > +                                                      (("target"
> > > "ES5")
> > > +                                                       #f)
> > > +                                                      (_
> > > +                                                       #t))
> > > +                                                    alist)))
> > > +                           (other
> > > +                            other))
> > > +                         alist)))))))
> > > +          (add-after 'do-not-target-es5 'patch-build-script
> > > +            (lambda args
> > > +              (define new-build-script
> > > +                (string-join
> > > +                 `("esbuild"
> > > +                   "--platform=node"
> > > +                   "--format=cjs"
> > > +                   "--outdir=lib"
> > > +                   ,@(find-files "src/less" "\\.js$")
> > > +                   ,@(find-files "src/less-node" "\\.js$"))))
> > > +              (with-atomic-json-file-replacement "package.json"
> > > +                (match-lambda
> > > +                  (('@ . alist)
> > > +                   (cons '@
> > > +                    (map (match-lambda
> > > +                           (("scripts" @ . alist)
> > > +                            `("scripts" @ ,@(map (match-lambda
> > > +                                                   (("build" .
> > > _)
> > > +                                                    (cons
> > > "build"
> > > +                                                          new-
> > > build-
> > > script))
> > > +                                                   (other
> > > +                                                    other))
> > > +                                                 alist)))
> > > +                           (other
> > > +                            other))
> > > +                         alist)))))))
> > Can we somehow save a bit of horizontal real-estate here?  Same
> > goes
> > for 1 and 2.
>
> To clarify, do you mean vertical or horizontal?
I do mean horizontal.

Toggle quote (5 lines)
> The long list of dependencies to delete does take a *lot* of vertical
> space, especially in this patch. The obvious alternative would be to
> put more than one dependency on the same line. I'm not opposed to
> that, but it would deviate from normal style and could make future
> diffs less clear.
Speaking of which, can we has regexps here?

Toggle quote (20 lines)
> For horizontal space, I don't really like any of the alternatives
> I've thought of. The culprit in each case seems to be the three
> `match-lambda`s under `with-atomic-json-file-replacement`.
> (Specifically in do-not-target-es5, I guess the innermost one could
> be replaced with just `remove`, which might help a little.)
>
> In normal programming, I'd want to abstract the three patch-build-
> script phases into a helper function that would take the new-build-
> script string as an argument, but that's a bit awkward to do with
> build-side code in Guix. Putting it in guix/build/node-build-
> system.scm (like
> delete-dependencies) would trigger a lot of rebuilds that seem hard
> to justify. It could be done as a gexp-producing function, but
> node-is-what, node-copy-anything, and lessc aren't in the same file:
> I guess the arguments field is delayed, so maybe it wouldn't create a
> cyclic dependency issue, but that seemed to open a whole new can of
> worms.
>
> (Making e.g. `jsobject-update*` from guix/build/node-build-system.scm
> public would also help, but I have no desire to revisit that.)
I think this is valid criticism of our node-build-system to perhaps
take to another thread.

Toggle quote (18 lines)
> Obviously it would be possible, within each G-expression, to lift one
> of the `match-lambda`s (probably the innermost one) to a local
> definition, but IMO that would make the structure of the code less
> obviously correspond to the structure of the JSON being transformed.
>
> I could also imagine breaking these lines:
>
>  >> +                           (("scripts" @ . alist)
>  >> +                            `("scripts" @ ,@(map (match-lambda
>
> instead as:
>
>  >> +                           (("scripts"
>  >> +                             @ . alist)
>  >> +                            `("scripts"
>  >> +                              @ ,@(map (match-lambda
>
> but that doesn't seem like much of an improvement to me.
But what about breaking lines before (match-lambda? That ought to at
least give us enough to get (_ #f) onto a single line, no?

Toggle quote (23 lines)
> > > +    (synopsis "Compiler for @acronym{Less} @acronym{CSS}
> > > language
> > > extension")
> > > +    ;; XXX: @abbr{} seems better for Less (which is always
> > > capitalized that
> > > +    ;; way), but it is rejected as invalid Texinfo markup here.
> > > +    (description "@acronym{Less, Leaner Style Sheets} is a
> > > +backwards-compatible language extension for @acronym{CSS}.  This
> > > package
> > > +provides @command{lessc}, which compiles Less files to plain
> > > @acronym{CSS}.")
> > > +    (license license:asl2.0)))
> > > +
> > IMHO it doesn't make sense to type @acronym without the expansion.
> >
>
> I don't have a strong opinion on this, and I only know the tiny
> amount of Texinfo I've picked up for Guix. I inferred from the fact
> that the one-argument version of @acronym{} exists that it should be
> used when applicable. I know that some typographical conventions
> handle capital letters and punctuation in acronyms specially, which
> would be one reason for @acronym{} to exist, but maybe that isn't
> relevant?
Yeah, CAPS aren't relevant here. The @acronym is typically for giving
meaning to an acronym, but if said meaning has already been given once,
repeating it would not make sense.

Some quotes from the manual:

Toggle quote (15 lines)
> - In Texinfo, an acronym (but not an abbreviation) should consist
> only of capital letters and periods, no lowercase.
> [...]
> - It usually turns out to be quite difficult and/or time-consuming
> to consistently use '@acronym' for all sequences of uppercase
> letters. Furthermore, it looks strange for some acronyms to be
> in the normal font size and others to be smaller. Thus, a
> simpler approach you may wish to consider is to avoid '@acronym'
> and just typeset everything as normal text in all capitals:
> 'GNU', producing the output 'GNU'.
>
> - In general, it's not essential to use either of these commands
> for all abbreviations; use your judgment. Text is perfectly
> readable without them.

Cheers
P
P
Philip McGrath wrote on 16 Nov 2023 01:03
13a1da53-4273-4ebf-aa58-4c23d1f5a641@philipmcgrath.com
Hi,

On 11/15/23 15:23, Liliana Marie Prikler wrote:
Toggle quote (67 lines)
> Am Mittwoch, dem 15.11.2023 um 14:35 -0500 schrieb Philip McGrath:
>> On 11/10/23 19:56, Liliana Marie Prikler wrote:
>>> Am Donnerstag, dem 09.11.2023 um 11:26 -0500 schrieb Philip
>>> McGrath:
>>>> * gnu/packages/web.scm (lessc): New variable.
>>>>
>>>> [...]
>>  >>
>>>> +          (add-after 'avoid-parse-node-version 'do-not-target-
>>>> es5
>>>> +            (lambda args
>>>> +              ;; esbuild can't compile all features to ES5
>>>> +              (with-atomic-json-file-replacement "tsconfig.json"
>>>> +                (match-lambda
>>>> +                  (('@ . alist)
>>>> +                   (cons '@
>>>> +                    (map (match-lambda
>>>> +                           (("compilerOptions" '@ . alist)
>>>> +                            `("scripts" @ ,@(filter (match-
>>>> lambda
>>>> +                                                      (("target"
>>>> "ES5")
>>>> +                                                       #f)
>>>> +                                                      (_
>>>> +                                                       #t))
>>>> +                                                    alist)))
>>>> +                           (other
>>>> +                            other))
>>>> +                         alist)))))))
>>>> +          (add-after 'do-not-target-es5 'patch-build-script
>>>> +            (lambda args
>>>> +              (define new-build-script
>>>> +                (string-join
>>>> +                 `("esbuild"
>>>> +                   "--platform=node"
>>>> +                   "--format=cjs"
>>>> +                   "--outdir=lib"
>>>> +                   ,@(find-files "src/less" "\\.js$")
>>>> +                   ,@(find-files "src/less-node" "\\.js$"))))
>>>> +              (with-atomic-json-file-replacement "package.json"
>>>> +                (match-lambda
>>>> +                  (('@ . alist)
>>>> +                   (cons '@
>>>> +                    (map (match-lambda
>>>> +                           (("scripts" @ . alist)
>>>> +                            `("scripts" @ ,@(map (match-lambda
>>>> +                                                   (("build" .
>>>> _)
>>>> +                                                    (cons
>>>> "build"
>>>> +                                                          new-
>>>> build-
>>>> script))
>>>> +                                                   (other
>>>> +                                                    other))
>>>> +                                                 alist)))
>>>> +                           (other
>>>> +                            other))
>>>> +                         alist)))))))
>>> Can we somehow save a bit of horizontal real-estate here?  Same
>>> goes
>>> for 1 and 2.
>>
>> To clarify, do you mean vertical or horizontal?
> I do mean horizontal.
>
> [...]
>
Toggle quote (18 lines)
>>
>> I could also imagine breaking these lines:
>>
>>  >> +                           (("scripts" @ . alist)
>>  >> +                            `("scripts" @ ,@(map (match-lambda
>>
>> instead as:
>>
>>  >> +                           (("scripts"
>>  >> +                             @ . alist)
>>  >> +                            `("scripts"
>>  >> +                              @ ,@(map (match-lambda
>>
>> but that doesn't seem like much of an improvement to me.
> But what about breaking lines before (match-lambda? That ought to at
> least give us enough to get (_ #f) onto a single line, no?
>

Maybe I'm confused: there isn't (_ #f) anywhere. There is currently
enough space to put (other other) on a single line, but I thought it was
better style to put a newline between the match pattern and the
expression, especially when the pattern is not _.

Breaking before match-lambda gets enough space to put (cons "build"
new-build-script) on a single line, but I don't think it looks better
overall:

Toggle quote (28 lines)
> (add-after 'do-not-target-es5 'patch-build-script
> (lambda args
> (define new-build-script
> (string-join
> `("esbuild"
> "--platform=node"
> "--format=cjs"
> "--outdir=lib"
> ,@(find-files "src/less" "\\.js$")
> ,@(find-files "src/less-node" "\\.js$"))))
> (with-atomic-json-file-replacement "package.json"
> (match-lambda
> (('@ . alist)
> (cons '@
> (map
> (match-lambda
> (("scripts" @ . alist)
> `("scripts" @ ,@(map
> (match-lambda
> (("build" . _)
> (cons "build" new-build-script))
> (other
> other))
> alist)))
> (other
> other))
> alist)))))))

Using delete in do-not-target-es5 does seem like a minor improvement:

Toggle quote (15 lines)
> (add-after 'avoid-parse-node-version 'do-not-target-es5
> (lambda args
> ;; esbuild can't compile all features to ES5
> (with-atomic-json-file-replacement "tsconfig.json"
> (match-lambda
> (('@ . alist)
> (cons '@
> (map (match-lambda
> (("compilerOptions" '@ . alist)
> `("scripts" @ ,@(delete '("target" "ES5")
> alist)))
> (other
> other))
> alist)))))))

Philip
L
L
Liliana Marie Prikler wrote on 16 Nov 2023 02:17
4d72986a039c897ba8a91c34fc1d9b7ef16d49dc.camel@gmail.com
Hi,

Am Mittwoch, dem 15.11.2023 um 19:03 -0500 schrieb Philip McGrath:
Toggle quote (31 lines)
> Hi,
>
> On 11/15/23 15:23, Liliana Marie Prikler wrote:
> > Am Mittwoch, dem 15.11.2023 um 14:35 -0500 schrieb Philip McGrath:
> > > [...]
> > >
> > > To clarify, do you mean vertical or horizontal?
> > I do mean horizontal.
> >
> > [...]
>  >
> > >
> > > I could also imagine breaking these lines:
> > >
> > >   >> +                           (("scripts" @ . alist)
> > >   >> +                            `("scripts" @ ,@(map (match-
> > > lambda
> > >
> > > instead as:
> > >
> > >   >> +                           (("scripts"
> > >   >> +                             @ . alist)
> > >   >> +                            `("scripts"
> > >   >> +                              @ ,@(map (match-lambda
> > >
> > > but that doesn't seem like much of an improvement to me.
> > But what about breaking lines before (match-lambda?  That ought to
> > at least give us enough to get (_ #f) onto a single line, no?
> >
>
> Maybe I'm confused: there isn't (_ #f) anywhere.
There was a (_ #t) in the filter, though :)
In any case, such trivial matches should fit onto one line imho.

Toggle quote (4 lines)
> There is currently enough space to put (other other) on a single
> line, but I thought it was better style to put a newline between the
> match pattern and the expression, especially when the pattern is not
> _.
IMHO, this only makes sense for non-trivial replacements. If you keep
some piece of data as-is, you more often than not don't want to draw
attention to this implementation detail by blowing up its size.

Toggle quote (50 lines)
> Breaking before match-lambda gets enough space to put (cons "build"
> new-build-script) on a single line, but I don't think it looks better
> overall:
>
> >           (add-after 'do-not-target-es5 'patch-build-script
> >             (lambda args
> >               (define new-build-script
> >                 (string-join
> >                  `("esbuild"
> >                    "--platform=node"
> >                    "--format=cjs"
> >                    "--outdir=lib"
> >                    ,@(find-files "src/less" "\\.js$")
> >                    ,@(find-files "src/less-node" "\\.js$"))))
> >               (with-atomic-json-file-replacement "package.json"
> >                 (match-lambda
> >                   (('@ . alist)
> >                    (cons '@
> >                     (map
> >                      (match-lambda
> >                        (("scripts" @ . alist)
> >                         `("scripts" @ ,@(map
> >                                          (match-lambda
> >                                            (("build" . _)
> >                                             (cons "build" new-
> > build-script))
> >                                            (other
> >                                             other))
> >                                          alist)))
> >                        (other
> >                         other))
> >                      alist)))))))
>
> Using delete in do-not-target-es5 does seem like a minor improvement:
>
> >           (add-after 'avoid-parse-node-version 'do-not-target-es5
> >             (lambda args
> >               ;; esbuild can't compile all features to ES5
> >               (with-atomic-json-file-replacement "tsconfig.json"
> >                 (match-lambda
> >                   (('@ . alist)
> >                    (cons '@
> >                     (map (match-lambda
> >                            (("compilerOptions" '@ . alist)
> >                             `("scripts" @ ,@(delete '("target"
> > "ES5")
> >                                                     alist)))
> >                            (other
> >                             other))
> >                          alist)))))))
Fun fact, you could inline this delete into the "compilerOptions" line
– or sexp at least, by using (= (cute delete '("target" "ES5") <>)
options). That being said, it's not necessary to do so; the delete you
currently have works fine.

Anyhow, since this isn't a clean alist, I'd use a different variable
name, perhaps "options"?

Cheers
P
P
Philip McGrath wrote on 16 Nov 2023 02:51
a953b344-0ac9-4e91-a0c0-ebc86f1daa81@philipmcgrath.com
Hi,

On 11/15/23 20:17, Liliana Marie Prikler wrote:
Toggle quote (46 lines)
> Hi,
>
> Am Mittwoch, dem 15.11.2023 um 19:03 -0500 schrieb Philip McGrath:
>> Hi,
>>
>> On 11/15/23 15:23, Liliana Marie Prikler wrote:
>>> Am Mittwoch, dem 15.11.2023 um 14:35 -0500 schrieb Philip McGrath:
>>>> [...]
>>>>
>>>> To clarify, do you mean vertical or horizontal?
>>> I do mean horizontal.
>>>
>>> [...]
>>  >
>>>>
>>>> I could also imagine breaking these lines:
>>>>
>>>>   >> +                           (("scripts" @ . alist)
>>>>   >> +                            `("scripts" @ ,@(map (match-
>>>> lambda
>>>>
>>>> instead as:
>>>>
>>>>   >> +                           (("scripts"
>>>>   >> +                             @ . alist)
>>>>   >> +                            `("scripts"
>>>>   >> +                              @ ,@(map (match-lambda
>>>>
>>>> but that doesn't seem like much of an improvement to me.
>>> But what about breaking lines before (match-lambda?  That ought to
>>> at least give us enough to get (_ #f) onto a single line, no?
>>>
>>
>> Maybe I'm confused: there isn't (_ #f) anywhere.
> There was a (_ #t) in the filter, though :)
> In any case, such trivial matches should fit onto one line imho.
>
>> There is currently enough space to put (other other) on a single
>> line, but I thought it was better style to put a newline between the
>> match pattern and the expression, especially when the pattern is not
>> _.
> IMHO, this only makes sense for non-trivial replacements. If you keep
> some piece of data as-is, you more often than not don't want to draw
> attention to this implementation detail by blowing up its size.
>

I don't think the content of the right-hand side is relevant: in my
view, the purpose of the newline is to make the shape of the clause
clear, especially given that the left-hand side is not an expression.
The fact that Guix's style forbids square brackets makes the newline
even more necessary, IMO.

In any case, what arrangement of whitespace in patch-build-script would
unblock this patch series for you?

Toggle quote (27 lines)
>>
>> Using delete in do-not-target-es5 does seem like a minor improvement:
>>
>>>           (add-after 'avoid-parse-node-version 'do-not-target-es5
>>>             (lambda args
>>>               ;; esbuild can't compile all features to ES5
>>>               (with-atomic-json-file-replacement "tsconfig.json"
>>>                 (match-lambda
>>>                   (('@ . alist)
>>>                    (cons '@
>>>                     (map (match-lambda
>>>                            (("compilerOptions" '@ . alist)
>>>                             `("scripts" @ ,@(delete '("target"
>>> "ES5")
>>>                                                     alist)))
>>>                            (other
>>>                             other))
>>>                          alist)))))))
> Fun fact, you could inline this delete into the "compilerOptions" line
> – or sexp at least, by using (= (cute delete '("target" "ES5") <>)
> options). That being said, it's not necessary to do so; the delete you
> currently have works fine.
>
> Anyhow, since this isn't a clean alist, I'd use a different variable
> name, perhaps "options"?
>

All of the variables named alist are, in fact, alists.

I noticed, though, that this was inadvertently renaming
"compilerOptions" to "scripts" and thus effectively patching out all the
other options, too: things seemed to work regardless, but here's a
correct version:

Toggle quote (15 lines)
> (add-after 'avoid-parse-node-version 'do-not-target-es5
> (lambda args
> ;; esbuild can't compile all features to ES5
> (with-atomic-json-file-replacement "tsconfig.json"
> (match-lambda
> (('@ . alist)
> (cons '@
> (map (match-lambda
> (("compilerOptions" '@ . alist)
> `("compilerOptions" @ ,@(delete '("target" . "ES5")
> alist)))
> (other
> other))
> alist)))))))

Philip
L
L
Liliana Marie Prikler wrote on 16 Nov 2023 08:18
bc695f24a0eb1e536fcebadae66212bab4515298.camel@gmail.com
Hi,

Am Mittwoch, dem 15.11.2023 um 20:51 -0500 schrieb Philip McGrath:
Toggle quote (64 lines)
> Hi,
>
> On 11/15/23 20:17, Liliana Marie Prikler wrote:
> > Hi,
> >
> > Am Mittwoch, dem 15.11.2023 um 19:03 -0500 schrieb Philip McGrath:
> > > Hi,
> > >
> > > On 11/15/23 15:23, Liliana Marie Prikler wrote:
> > > > Am Mittwoch, dem 15.11.2023 um 14:35 -0500 schrieb Philip
> > > > McGrath:
> > > > > [...]
> > > > >
> > > > > To clarify, do you mean vertical or horizontal?
> > > > I do mean horizontal.
> > > >
> > > > [...]
> > >   >
> > > > >
> > > > > I could also imagine breaking these lines:
> > > > >
> > > > >    >> +                           (("scripts" @ . alist)
> > > > >    >> +                            `("scripts" @ ,@(map
> > > > > (match-
> > > > > lambda
> > > > >
> > > > > instead as:
> > > > >
> > > > >    >> +                           (("scripts"
> > > > >    >> +                             @ . alist)
> > > > >    >> +                            `("scripts"
> > > > >    >> +                              @ ,@(map (match-lambda
> > > > >
> > > > > but that doesn't seem like much of an improvement to me.
> > > > But what about breaking lines before (match-lambda?  That ought
> > > > to
> > > > at least give us enough to get (_ #f) onto a single line, no?
> > > >
> > >
> > > Maybe I'm confused: there isn't (_ #f) anywhere.
> > There was a (_ #t) in the filter, though :)
> > In any case, such trivial matches should fit onto one line imho.
> >
> > > There is currently enough space to put (other other) on a single
> > > line, but I thought it was better style to put a newline between
> > > the
> > > match pattern and the expression, especially when the pattern is
> > > not
> > > _.
> > IMHO, this only makes sense for non-trivial replacements.  If you
> > keep
> > some piece of data as-is, you more often than not don't want to
> > draw
> > attention to this implementation detail by blowing up its size.
> >
>
> I don't think the content of the right-hand side is relevant: in my
> view, the purpose of the newline is to make the shape of the clause
> clear, especially given that the left-hand side is not an expression.
> The fact that Guix's style forbids square brackets makes the newline
> even more necessary, IMO.
>
> In any case, what arrangement of whitespace in patch-build-script
> would unblock this patch series for you?
If push comes to shove, I can rearrange the whitespace as I want, given
my committer privileges; it's just that you've complained about me
abusing them before, so I don't really want to.

Anyhow, stuff like (_ #t), (_ #f), (x x), … should all fit onto a
single line.

Toggle quote (30 lines)
> > >
> > > Using delete in do-not-target-es5 does seem like a minor
> > > improvement:
> > >
> > > >            (add-after 'avoid-parse-node-version 'do-not-target-
> > > > es5
> > > >              (lambda args
> > > >                ;; esbuild can't compile all features to ES5
> > > >                (with-atomic-json-file-replacement
> > > > "tsconfig.json"
> > > >                  (match-lambda
> > > >                    (('@ . alist)
> > > >                     (cons '@
> > > >                      (map (match-lambda
> > > >                             (("compilerOptions" '@ . alist)
> > > >                              `("scripts" @ ,@(delete '("target"
> > > > "ES5")
> > > >                                                      alist)))
> > > >                             (other
> > > >                              other))
> > > >                           alist)))))))
> > Fun fact, you could inline this delete into the "compilerOptions"
> > line or sexp at least, by using (= (cute delete '("target" "ES5")
> > <>) options).  That being said, it's not necessary to do so; the
> > delete you currently have works fine.
> >
> > Anyhow, since this isn't a clean alist, I'd use a different
> > variable name, perhaps "options"?
>
> All of the variables named alist are, in fact, alists.
TIL.

Toggle quote (21 lines)
> I noticed, though, that this was inadvertently renaming
> "compilerOptions" to "scripts" and thus effectively patching out all
> the other options, too: things seemed to work regardless, but here's
> a correct version:
>
> >           (add-after 'avoid-parse-node-version 'do-not-target-es5
> >             (lambda args
> >               ;; esbuild can't compile all features to ES5
> >               (with-atomic-json-file-replacement "tsconfig.json"
> >                 (match-lambda
> >                   (('@ . alist)
> >                    (cons '@
> >                     (map (match-lambda
> >                            (("compilerOptions" '@ . alist)
> >                             `("compilerOptions" @ ,@(delete
> > '("target" . "ES5")
> >                                                            
> > alist)))
> >                            (other
> >                             other))
> >                          alist)))))))
Now that looks like a proper alist to me :)
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 00/16] gnu: Add KaTeX, lessc, and flow-remove-types.
(address . 67019@debbugs.gnu.org)
cover.1700161584.git.philip@philipmcgrath.com
Hi,

Here is a v2.

Other than rebasing, the only change is in 03/16, in which I've fixed
do-not-target-es5 as I explained in https://issues.guix.gnu.org/67019#20.

I've not made other whitespace changes, as I still prefer this to the other
options we've discussed, but, Liliana, feel free to adjust it to your liking
if you feel this is otherwise ready to merge.

Philip

Philip McGrath (16):
gnu: Add node-is-what.
gnu: Add node-copy-anything.
gnu: Add lessc.
gnu: Add ocaml-wtf8.
gnu: Add ocaml-visitors.
gnu: Add ocaml-ppx-gen-rec.
gnu: Add ocaml-dtoa.
gnu: Add node-vlq.
gnu: Add ocaml-flow-parser.
gnu: Add node-flow-parser.
gnu: Add flow-remove-types.
gnu: js-commander: Update to 11.1.0.
gnu: js-commander: Install as a node module.
gnu: Add mftrace.
gnu: Add font-katex.
gnu: Add katex.

gnu/packages/fontutils.scm | 45 +++++
gnu/packages/javascript.scm | 381 ++++++++++++++++++++++++++++++++++--
gnu/packages/node-xyz.scm | 220 +++++++++++++++++++++
gnu/packages/ocaml.scm | 99 ++++++++++
gnu/packages/web.scm | 381 ++++++++++++++++++++++++++++++++++++
5 files changed, 1109 insertions(+), 17 deletions(-)


base-commit: fc6bdaad57bf91609849623c5f485403c030cb49
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 01/16] gnu: Add node-is-what.
(address . 67019@debbugs.gnu.org)
9daf928c3989a207159dd6f53b531be65e7bae64.1700161584.git.philip@philipmcgrath.com
* gnu/packages/node-xyz.scm (node-is-what): New variable.
---
gnu/packages/node-xyz.scm | 81 +++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)

Toggle diff (91 lines)
diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm
index 6c16417309..49760ded2b 100644
--- a/gnu/packages/node-xyz.scm
+++ b/gnu/packages/node-xyz.scm
@@ -1631,3 +1631,84 @@ (define-public node-yazl
@item Prefer to open input files one at a time than all at once.
@end enumerate")
(license license:expat)))
+
+(define-public node-is-what
+ (package
+ (name "node-is-what")
+ (version "4.1.16")
+ (source
+ (origin (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/mesqueeb/is-what")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "02h76klvjxgk0cl8a7sq4wbi7l4pvdimbams08l34k5carg03bdx"))
+ (snippet
+ #~(for-each delete-file
+ '("dist/cjs/index.cjs"
+ "dist/index.js")))
+ (file-name (git-file-name name version))))
+ (build-system node-build-system)
+ (native-inputs (list esbuild))
+ (arguments
+ (list
+ #:tests? #f ; needs more dependencies
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '(;; devDependencies
+ "@typescript-eslint/eslint-plugin"
+ "@typescript-eslint/parser"
+ "del-cli"
+ "eslint"
+ "eslint-config-prettier"
+ "eslint-plugin-tree-shaking"
+ "np"
+ "prettier"
+ "prettier-plugin-jsdoc"
+ "rollup"
+ "rollup-plugin-dts"
+ "rollup-plugin-esbuild"
+ "rollup-plugin-typescript2"
+ "typedoc"
+ "typescript"
+ "vitest"))))
+ (add-after 'delete-dependencies 'patch-build-script
+ (lambda args
+ (define esbuild
+ "esbuild --bundle --platform=node")
+ (define new-build-script
+ (string-append
+ esbuild
+ " --format=cjs --outfile=dist/cjs/index.cjs src/index.ts"
+ " && "
+ esbuild
+ " --format=esm --outfile=dist/index.js src/index.ts"))
+ (with-atomic-json-file-replacement "package.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("scripts" @ . alist)
+ `("scripts" @ ,@(map (match-lambda
+ (("build" . _)
+ (cons "build"
+ new-build-script))
+ (other
+ other))
+ alist)))
+ (other
+ other))
+ alist))))))))))
+ (home-page "https://npmjs.com/is-what")
+ (synopsis "Type predicate functions for JavaScript")
+ (description "This package provides simple and small type predicate
+functions for JavaScript, such as @code{isString}, @code{isDate}, and
+@code{isPlainObject}.")
+ (license license:expat)))
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 02/16] gnu: Add node-copy-anything.
(address . 67019@debbugs.gnu.org)
5bfba55639dc6d855faf260358c25c37aa34b3de.1700161584.git.philip@philipmcgrath.com
* gnu/packages/node-xyz.scm (node-copy-anything): New variable.
---
gnu/packages/node-xyz.scm | 81 +++++++++++++++++++++++++++++++++++++++
1 file changed, 81 insertions(+)

Toggle diff (91 lines)
diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm
index 49760ded2b..ee96dee767 100644
--- a/gnu/packages/node-xyz.scm
+++ b/gnu/packages/node-xyz.scm
@@ -1712,3 +1712,84 @@ (define-public node-is-what
functions for JavaScript, such as @code{isString}, @code{isDate}, and
@code{isPlainObject}.")
(license license:expat)))
+
+(define-public node-copy-anything
+ (package
+ (name "node-copy-anything")
+ (version "3.0.5")
+ (source
+ (origin (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/mesqueeb/copy-anything")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "1lpjqanjl04k088banpns4yvp6hgf97snaj7gfbfancjpd3i8gk6"))
+ (snippet
+ #~(for-each delete-file
+ '("dist/cjs/index.cjs"
+ "dist/index.js")))
+ (file-name (git-file-name name version))))
+ (build-system node-build-system)
+ (native-inputs (list esbuild))
+ (inputs (list node-is-what))
+ (arguments
+ (list
+ #:tests? #f ; needs more dependencies
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '(;; devDependencies
+ "@typescript-eslint/eslint-plugin"
+ "@typescript-eslint/parser"
+ "del-cli"
+ "eslint"
+ "eslint-config-prettier"
+ "eslint-plugin-tree-shaking"
+ "np"
+ "prettier"
+ "rollup"
+ "rollup-plugin-dts"
+ "rollup-plugin-esbuild"
+ "rollup-plugin-typescript2"
+ "typescript"
+ "vitest"))))
+ (add-after 'delete-dependencies 'patch-build-script
+ (lambda args
+ (define esbuild
+ "esbuild --bundle --platform=node --external:is-what")
+ (define new-build-script
+ (string-append
+ esbuild
+ " --format=cjs --outfile=dist/cjs/index.cjs src/index.ts"
+ " && "
+ esbuild
+ " --format=esm --outfile=dist/index.js src/index.ts"))
+ (with-atomic-json-file-replacement "package.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("scripts" @ . alist)
+ `("scripts" @ ,@(map (match-lambda
+ (("build" . _)
+ (cons "build"
+ new-build-script))
+ (other
+ other))
+ alist)))
+ (other
+ other))
+ alist))))))))))
+ (home-page "https://npmjs.com/copy-anything")
+ (synopsis "JavaScript library for copying objects and arrays")
+ (description "This library provides deep copying for JavaScript objects
+and arrays. Its design emphasizes speed, simplicity, and correctness in the
+face of complications like special objects, symbols, and non-enumerable
+properties.")
+ (license license:expat)))
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 03/16] gnu: Add lessc.
(address . 67019@debbugs.gnu.org)
83a3e16cf7d86bb07f6cf728acf3872dcae604dc.1700161584.git.philip@philipmcgrath.com
* gnu/packages/web.scm (lessc): New variable.
---
gnu/packages/web.scm | 183 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 183 insertions(+)

Toggle diff (217 lines)
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 389f7d1375..9efc6ebc9d 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -65,6 +65,7 @@
;;; Copyright © 2023 Christopher Howard <christopher@librehacker.com>
;;; Copyright © 2023 Felix Lechner <felix.lechner@lease-up.com>
;;; Copyright © 2023 Evgeny Pisemsky <evgeny@pisemsky.com>
+;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -99,6 +100,7 @@ (define-module (gnu packages web)
#:use-module (guix build-system gnu)
#:use-module (guix build-system go)
#:use-module (guix build-system meson)
+ #:use-module (guix build-system node)
#:use-module (guix build-system perl)
#:use-module (guix build-system pyproject)
#:use-module (guix build-system python)
@@ -169,6 +171,7 @@ (define-module (gnu packages web)
#:use-module (gnu packages ncurses)
#:use-module (gnu packages networking)
#:use-module (gnu packages node)
+ #:use-module (gnu packages node-xyz)
#:use-module (gnu packages nss)
#:use-module (gnu packages openldap)
#:use-module (gnu packages openstack)
@@ -2344,6 +2347,186 @@ (define-public sassc/libsass-3.5
"0830pjcvhzxh6yixj82x5k5r1xnadjqzi16kp53213icbly0r9ma")))))))
(properties '((hidden? . #t)))))
+(define-public lessc
+ (package
+ (name "lessc")
+ (version "4.2.0")
+ (source
+ (origin (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/less/less.js")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "1b6anlafk7lnayxy3vhsi474jcdah2ffaw2qyac5s2ibxb1wmr54"))
+ (snippet
+ #~(begin
+ (use-modules (guix build utils))
+ (delete-file-recursively "packages/less/dist")))
+ (file-name (git-file-name name version))))
+ (build-system node-build-system)
+ (native-inputs (list esbuild))
+ (inputs (list node-copy-anything))
+ (arguments
+ (list
+ #:tests? #f ; many more dependencies
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'chdir
+ (lambda args
+ (chdir "packages/less")))
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '(;; dependencies
+ "parse-node-version" ; patched out
+ "tslib" ; probably not needed w/ esbuild
+ ;; devDependencies
+ "@less/test-data"
+ "@less/test-import-module"
+ "@rollup/plugin-commonjs"
+ "@rollup/plugin-json"
+ "@rollup/plugin-node-resolve"
+ "@typescript-eslint/eslint-plugin"
+ "@typescript-eslint/parser"
+ "benny"
+ "bootstrap-less-port"
+ "chai"
+ "cross-env"
+ "diff"
+ "eslint"
+ "fs-extra"
+ "git-rev"
+ "globby"
+ "grunt"
+ "grunt-cli"
+ "grunt-contrib-clean"
+ "grunt-contrib-connect"
+ "grunt-eslint"
+ "grunt-saucelabs"
+ "grunt-shell"
+ "html-template-tag"
+ "jit-grunt"
+ "less-plugin-autoprefix"
+ "less-plugin-clean-css"
+ "minimist"
+ "mocha"
+ "mocha-headless-chrome"
+ "mocha-teamcity-reporter"
+ "nock"
+ "npm-run-all"
+ "performance-now"
+ "phin"
+ "promise"
+ "read-glob"
+ "resolve"
+ "rollup"
+ "rollup-plugin-terser"
+ "rollup-plugin-typescript2"
+ "semver"
+ "shx"
+ "time-grunt"
+ "ts-node"
+ "typescript"
+ "uikit"
+ ;; optionalDependencies
+ "errno"
+ "graceful-fs"
+ "image-size"
+ "make-dir"
+ "mime"
+ "needle"
+ "source-map"))))
+ (add-after 'delete-dependencies 'avoid-parse-node-version
+ (lambda args
+ (define version
+ #$(package-version this-package))
+ (substitute* "src/less/index.js"
+ (("import [{] version [}]" orig)
+ (string-append "// " orig))
+ (("import parseVersion from 'parse-node-version';" orig)
+ (string-append "// " orig))
+ (("const v = parseVersion[(]`v\\$[{]version[}]`[)];" orig)
+ (string-append "// " orig))
+ (("(version: )(\\[v\\.major, v\\.minor, v\\.patch],)" _ lhs rhs)
+ (string-append
+ lhs
+ "["
+ (string-join
+ (list-head (string-split
+ version (char-set-complement char-set:digit))
+ 3)
+ ", ")
+ "], // "
+ rhs)))))
+ (add-after 'avoid-parse-node-version 'do-not-target-es5
+ (lambda args
+ ;; esbuild can't compile all features to ES5
+ (with-atomic-json-file-replacement "tsconfig.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("compilerOptions" '@ . alist)
+ `("compilerOptions" @ ,@(delete '("target" . "ES5")
+ alist)))
+ (other
+ other))
+ alist)))))))
+ (add-after 'do-not-target-es5 'patch-build-script
+ (lambda args
+ (define new-build-script
+ (string-join
+ `("esbuild"
+ "--platform=node"
+ "--format=cjs"
+ "--outdir=lib"
+ ,@(find-files "src/less" "\\.js$")
+ ,@(find-files "src/less-node" "\\.js$"))))
+ (with-atomic-json-file-replacement "package.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("scripts" @ . alist)
+ `("scripts" @ ,@(map (match-lambda
+ (("build" . _)
+ (cons "build"
+ new-build-script))
+ (other
+ other))
+ alist)))
+ (other
+ other))
+ alist)))))))
+ (add-after 'build 'build-browser
+ (lambda args
+ (invoke "esbuild"
+ "--bundle"
+ "--platform=browser"
+ "--format=cjs"
+ "--outfile=dist/less.js"
+ "src/less-browser/bootstrap.js")
+ (invoke "esbuild"
+ "--bundle"
+ "--minify"
+ "--sourcemap"
+ "--platform=browser"
+ "--format=cjs"
+ "--outfile=dist/less.min.js"
+ "src/less-browser/bootstrap.js"))))))
+ (home-page "https://lesscss.org")
+ (synopsis "Compiler for @acronym{Less} @acronym{CSS} language extension")
+ ;; XXX: @abbr{} seems better for Less (which is always capitalized that
+ ;; way), but it is rejected as invalid Texinfo markup here.
+ (description "@acronym{Less, Leaner Style Sheets} is a
+backwards-compatible language extension for @acronym{CSS}. This package
+provides @command{lessc}, which compiles Less files to plain @acronym{CSS}.")
+ (license license:asl2.0)))
+
(define-public perl-apache-logformat-compiler
(package
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 04/16] gnu: Add ocaml-wtf8.
(address . 67019@debbugs.gnu.org)
db84f047bb784803acdef04dd72bc3131323e076.1700161584.git.philip@philipmcgrath.com
* gnu/packages/ocaml.scm (ocaml-wtf8): New variable.
---
gnu/packages/ocaml.scm | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

Toggle diff (45 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index 7993dbaa73..50b0d1ddb7 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -29,6 +29,7 @@
;;; Copyright © 2022 Garek Dyszel <garekdyszel@disroot.org>
;;; Copyright © 2023 Csepp <raingloom@riseup.net>
;;; Copyright © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
+;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -3655,6 +3656,30 @@ (define-public ocaml-uutf
string values and to directly encode characters in OCaml Buffer.t values.")
(license license:isc)))
+(define-public ocaml-wtf8
+ (package
+ (name "ocaml-wtf8")
+ (version "1.0.2")
+ (source (origin
+ (method url-fetch)
+ (uri (string-append
+ "https://github.com/flow/ocaml-wtf8/releases/download/"
+ "v" version "/wtf8-v" version ".tbz"))
+ (sha256
+ (base32
+ "09ygcxxd5warkdzz17rgpidrd0pg14cy2svvnvy1hna080lzg7vp"))))
+ (build-system dune-build-system)
+ (home-page "https://github.com/flow/ocaml-wtf8")
+ (synopsis "OCaml encoder and decoder for @acronym{WTF-8}")
+ (description
+ "This library provides an OCaml encoder and decoder for @acronym{WTF-8,
+Wobbly Transformation Format---8 bit}, a superset of UTF-8 that allows
+unpaired surrogates while preserving the other well-formedness constraints of
+UTF-8. This format is useful for interoperating with systems that use
+potentially ill-formed UTF-16, notably including ECMAScript strings and
+Windows filesystems.")
+ (license license:expat)))
+
(define-public ocaml-uunf
(package
(name "ocaml-uunf")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 05/16] gnu: Add ocaml-visitors.
(address . 67019@debbugs.gnu.org)
a7c0e24994d3a676648d634c837a75c2180de5bf.1700161584.git.philip@philipmcgrath.com
* gnu/packages/ocaml.scm (ocaml-visitors): New variable.
---
gnu/packages/ocaml.scm | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

Toggle diff (35 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index 50b0d1ddb7..f9a3932d18 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -5232,6 +5232,28 @@ (define-public ocaml-graph
(description "OCamlgraph is a generic graph library for OCaml.")
(license license:lgpl2.1)))
+(define-public ocaml-visitors
+ (package
+ (name "ocaml-visitors")
+ (version "20210608")
+ (source (origin
+ (method url-fetch)
+ (uri
+ (string-append "https://gitlab.inria.fr/fpottier/visitors/-/"
+ "archive/" version "/archive.tar.gz"))
+ (sha256
+ (base32
+ "1yx4bjw4yw3zi35yfp66x320xgb9f8jh7rqj1j7hrrvn0f60m2y2"))))
+ (build-system dune-build-system)
+ (propagated-inputs (list ocaml-ppxlib ocaml-ppx-deriving ocaml-result))
+ (home-page "https://gitlab.inria.fr/fpottier/visitors")
+ (synopsis "OCaml syntax extension for generating visitor classes")
+ (description
+ "This package provides an OCaml syntax extension that automatically
+generates object-oriented visitors for traversing and transforming data
+structures.")
+ (license license:lgpl2.1)))
+
(define-public ocaml-piqi
(package
(name "ocaml-piqi")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 11/16] gnu: Add flow-remove-types.
(address . 67019@debbugs.gnu.org)
875d54cc655b21a748fbf0e981642475ddd94bde.1700161584.git.philip@philipmcgrath.com
* gnu/packages/web.scm (flow-remove-types): New variable.
---
gnu/packages/web.scm | 60 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)

Toggle diff (73 lines)
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index b8646e9d0d..f5afb453f9 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -2076,6 +2076,66 @@ (define-public node-flow-parser
provides the Flow parser in its compiled-to-JavaScript form for use with
Node.js and NPM.")))
+(define-public flow-remove-types
+ (package
+ (inherit node-flow-parser)
+ (name "flow-remove-types")
+ (inputs (list node-flow-parser node-vlq))
+ (arguments
+ (list
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'delete-workspace-file
+ (lambda args
+ ;; this workspace file causes NPM to try to install dependencies
+ ;; of other packages developed in this source repository
+ (delete-file "package.json")))
+ (add-after 'delete-workspace-file 'chdir
+ (lambda args
+ (chdir "packages/flow-remove-types")))
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies '("pirates"))))
+ (add-after 'delete-dependencies 'remove-unsupported-features
+ (lambda args
+ (delete-file "register.js")
+ (with-output-to-file "register.js"
+ (lambda ()
+ (for-each
+ display
+ '("console.warn('flow-remove-types/register.js does not add"
+ " a require hook on Guix');\n"
+ "module.exports ="
+ " function setOptions(newOptions) {};\n"))))
+ (substitute* "flow-node"
+ (("var flowRemoveTypes")
+ (string-append
+ "process.stderr.write('flow-node: not yet supported"
+ " on Guix');\n"
+ "return process.exit(1);\n"
+ "var flowRemoveTypes")))
+ (substitute* "test.sh"
+ (("echo \"Test: node require hook\"")
+ "echo \"SKIPPING Test: node require hook\"")
+ (("RES=\\$[(]node -e 'require[(]\"\\./register\"[)];")
+ "RES=42 # ")
+ (("echo \"Test: flow-node\"")
+ "echo \"SKIPPING Test: flow-node\"")
+ (("FLOW_NODE=")
+ "FLOW_NODE=42 # ")
+ (("echo \"Test: flow-node with options\"")
+ "echo \"SKIPPING Test: flow-node with options\"")
+ (("FLOW_NODE_OPTS=")
+ "FLOW_NODE_OPTS=4 # ")))))))
+ (synopsis "Utility to erase Flow type annotations from JavaScript")
+ (description "Flow is a gradual type system for JavaScript. This package
+provides @command{flow-remove-types}, a command-line tool that erases Flow
+type annotations, producing standard JavaScript files. The functionality is
+also provided as a JavaScript library.
+
+Note that the Guix package does not yet support the @command{flow-node}
+command or the Node.js require hook for interactive development.")))
+
(define-public tinyproxy
(package
(name "tinyproxy")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 06/16] gnu: Add ocaml-ppx-gen-rec.
(address . 67019@debbugs.gnu.org)
c52577a55bb53bda385797dfe2faab477b94ffbc.1700161584.git.philip@philipmcgrath.com
* gnu/packages/ocaml.scm (ocaml-ppx-gen-rec): New variable.
---
gnu/packages/ocaml.scm | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

Toggle diff (41 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index f9a3932d18..b12c12fad5 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -6722,6 +6722,34 @@ (define-public ocaml-ppx-deriving
on type definitions, and a set of useful plugins for common tasks.")
(license license:expat)))
+(define-public ocaml-ppx-gen-rec
+ (package
+ (name "ocaml-ppx-gen-rec")
+ (version "2.0.0")
+ (source (origin
+ (method url-fetch)
+ (uri
+ (string-append "https://github.com/flow/ocaml-ppx_gen_rec/"
+ "releases/download/v"
+ version
+ "/ppx_gen_rec-v" version ".tbz"))
+ (sha256
+ (base32
+ "0ncy7ps0w3cnb3nk6y1j4v4g60rs500qwv1daw3a9n7n8kjj6qzy"))))
+ (build-system dune-build-system)
+ (propagated-inputs (list ocaml-ppxlib))
+ (native-inputs (list ocaml-ppx-deriving))
+ (properties `((upstream-name . "ppx_gen_rec")))
+ (home-page "https://github.com/flow/ocaml-ppx_gen_rec")
+ (synopsis "Ppx rewriter for recursive module expressions")
+ (description
+ "This package provides a ppx rewriter that transforms a recursive module
+expression into a struct. In a recursive module expression, the struct can be
+derived from the signature automatically by the compiler. This package does
+the same thing, but doing it this way allows @code{ppx_deriving} to transform
+the signature and the struct separately.")
+ (license license:expat)))
+
(define-public ocaml-ppx-derivers
(package
(name "ocaml-ppx-derivers")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 12/16] gnu: js-commander: Update to 11.1.0.
(address . 67019@debbugs.gnu.org)
e5db9646ee07cfd33da68b570ee57d5b657a5140.1700161584.git.philip@philipmcgrath.com
* gnu/packages/javascript.scm (js-commander): Update to 11.1.0.
---
gnu/packages/javascript.scm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

Toggle diff (24 lines)
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index e70aa7d7e1..c62b23a4c4 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -373,7 +373,7 @@ (define-public js-mathjax-for-r-mathjaxr
(define-public js-commander
(package
(name "js-commander")
- (version "6.2.1")
+ (version "11.1.0")
(source
(origin
(method git-fetch)
@@ -383,7 +383,7 @@ (define-public js-commander
(file-name (git-file-name name version))
(sha256
(base32
- "126m25s6mxpxmdj4aw5awz06b47r8r798lcf1c5bnmmh39cik5i1"))))
+ "1xwh85kbxj76ni41r2h0apl8mjbfcnmxzzp3vlspq30w8kwfckni"))))
(build-system trivial-build-system)
(arguments
`(#:modules ((guix build utils))
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 07/16] gnu: Add ocaml-dtoa.
(address . 67019@debbugs.gnu.org)
4ccdb4652b68ad0cb1ed898b8ab5ecfc34125cb7.1700161584.git.philip@philipmcgrath.com
* gnu/packages/ocaml.scm (ocaml-dtoa): New variable.
---
gnu/packages/ocaml.scm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

Toggle diff (37 lines)
diff --git a/gnu/packages/ocaml.scm b/gnu/packages/ocaml.scm
index b12c12fad5..36f349df73 100644
--- a/gnu/packages/ocaml.scm
+++ b/gnu/packages/ocaml.scm
@@ -2513,6 +2513,30 @@ (define-public ocaml4.07-fmt
"0gkkkj4x678vxdda4xaw2dd44qjacavsvn5nx8gydfwah6pjbkxk"))))
(properties '()))))
+(define-public ocaml-dtoa
+ (package
+ (name "ocaml-dtoa")
+ (version "0.3.3")
+ (source (origin
+ (method url-fetch)
+ (uri
+ (string-append "https://github.com/flow/ocaml-dtoa/releases/"
+ "download/v" version "/dtoa-" version ".tbz"))
+ (sha256
+ (base32
+ "0gpfr6iyiihmkpas542916cnhfdbrigvzwrix8jrxcljks661x6q"))))
+ (build-system dune-build-system)
+ (native-inputs (list ocaml-ounit2))
+ (home-page "https://github.com/flow/ocaml-dtoa")
+ (synopsis
+ "Efficent float to string conversion for OCaml")
+ (description
+ "This package provides functions that convert OCaml floats into strings
+quickly, accurately, and (almost always) optimally using the Grisu3 algorithm.
+The implementation was adapted from a C++ library originally developed as part
+of the V8 JavaScript engine.")
+ (license license:expat)))
+
(define-public ocaml-astring
(package
(name "ocaml-astring")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 13/16] gnu: js-commander: Install as a node module.
(address . 67019@debbugs.gnu.org)
2dbd50a275174556a071bc7047823c80fa20ee67.1700161584.git.philip@philipmcgrath.com
Previously, NPM would not find 'commander' when resolving dependencies.

In case anyone is using it, keep building the bundled version at
'share/javascript/commander/index.min.js', too.

* gnu/packages/javascript.scm (js-commander)[build-system]: Use
'node-build-system'.
[arguments]: Delete unpackaged 'devDependencies'. Build bundle for
compatibility.
---
gnu/packages/javascript.scm | 52 ++++++++++++++++++++++++++-----------
1 file changed, 37 insertions(+), 15 deletions(-)

Toggle diff (80 lines)
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index c62b23a4c4..97cb3b6270 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -7,6 +7,7 @@
;;; Copyright © 2021 Pierre Neidhardt <mail@ambrevar.xyz>
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
;;; Copyright © 2022 Frank Pursel <frank.pursel@gmail.com>
+;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -42,6 +43,7 @@ (define-module (gnu packages javascript)
#:use-module (guix build-system cmake)
#:use-module (guix build-system gnu)
#:use-module (guix build-system minify)
+ #:use-module (guix build-system node)
#:use-module (guix build-system trivial)
#:use-module (guix utils))
@@ -384,22 +386,42 @@ (define-public js-commander
(sha256
(base32
"1xwh85kbxj76ni41r2h0apl8mjbfcnmxzzp3vlspq30w8kwfckni"))))
- (build-system trivial-build-system)
+ (build-system node-build-system)
(arguments
- `(#:modules ((guix build utils))
- #:builder
- (begin
- (use-modules (guix build utils))
- (chdir (assoc-ref %build-inputs "source"))
- (let ((esbuild (search-input-file %build-inputs "/bin/esbuild"))
- (target (string-append %output "/share/javascript/commander")))
- (invoke esbuild
- "--bundle"
- "--minify"
- "--tsconfig=tsconfig.json"
- "--platform=node"
- (string-append "--outfile=" target "/index.min.js")
- "index.js")))))
+ (list
+ #:tests? #f ; many more dependencies
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies `(;; devDependencies
+ "@types/jest"
+ "@types/node"
+ "@typescript-eslint/eslint-plugin"
+ "@typescript-eslint/parser"
+ "eslint"
+ "eslint-config-standard"
+ "eslint-config-standard-with-typescript"
+ "eslint-plugin-import"
+ "eslint-plugin-jest"
+ "eslint-plugin-n"
+ "eslint-plugin-promise"
+ "jest"
+ "ts-jest"
+ "tsd"
+ "typescript"))))
+ (add-after 'install 'install-compat
+ (lambda args
+ ;; This is what this package built before adopting
+ ;; node-build-system. Does anything use it?
+ (invoke "esbuild"
+ "--bundle"
+ "--minify"
+ "--platform=node"
+ (string-append "--outfile="
+ #$output
+ "/share/javascript/commander/index.min.js")
+ "index.js"))))))
(native-inputs
(list esbuild))
(home-page "https://github.com/tj/commander.js")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 08/16] gnu: Add node-vlq.
(address . 67019@debbugs.gnu.org)
7f4e71aad9adc111dd5ff673d707ef9e3db0d7e0.1700161584.git.philip@philipmcgrath.com
* gnu/packages/node-xyz.scm (node-vlq): New variable.
---
gnu/packages/node-xyz.scm | 58 +++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)

Toggle diff (68 lines)
diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm
index ee96dee767..adbac8a6cd 100644
--- a/gnu/packages/node-xyz.scm
+++ b/gnu/packages/node-xyz.scm
@@ -1793,3 +1793,61 @@ (define-public node-copy-anything
face of complications like special objects, symbols, and non-enumerable
properties.")
(license license:expat)))
+
+(define-public node-vlq
+ (package
+ (name "node-vlq")
+ (version "0.2.3") ; last version accepted by flow-remove-types ("^0.2.1")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/Rich-Harris/vlq")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "1vdrarssrwxpcngyfx050ba0gnfinzi5jn3xs4w9rnjvxngx6m8f"))
+ (snippet
+ #~(delete-file "dist/vlq.js"))
+ (file-name (git-file-name name version))))
+ (build-system node-build-system)
+ (native-inputs (list esbuild))
+ (arguments
+ (list
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '("eslint"
+ "rollup"))))
+ (add-after 'delete-dependencies 'patch-build-script
+ (lambda args
+ (define new-build-script
+ "esbuild --bundle --platform=node --outdir=dist src/vlq.js")
+ (with-atomic-json-file-replacement "package.json"
+ (lambda (js)
+ (match js
+ (('@ . alist)
+ (cons '@
+ (map (match-lambda
+ (("scripts" @ . alist)
+ `("scripts" @ ,@(map (match-lambda
+ (("build" . _)
+ (cons "build"
+ new-build-script))
+ (other
+ other))
+ alist)))
+ (other
+ other))
+ alist)))))))))))
+ (home-page "https://github.com/Rich-Harris/vlq")
+ (synopsis "JavaScript library for @acronym{VLQ} encoding and decoding")
+ (description "This package provides a JavaScript library for converting
+integers to and from Base64-encoded @acronym{VLQ, variable-length quantity}
+strings.")
+ (license license:expat)))
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 14/16] gnu: Add mftrace.
(address . 67019@debbugs.gnu.org)
4b3be6a948d9e6da5dd729caaaeff9c5fef06783.1700161584.git.philip@philipmcgrath.com
* gnu/packages/fontutils.scm (mftrace): New variable.
---
gnu/packages/fontutils.scm | 45 ++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)

Toggle diff (58 lines)
diff --git a/gnu/packages/fontutils.scm b/gnu/packages/fontutils.scm
index 5bfdea1b27..6bab6ab7df 100644
--- a/gnu/packages/fontutils.scm
+++ b/gnu/packages/fontutils.scm
@@ -1182,6 +1182,51 @@ (define-public ttf2pt1
(home-page "https://ttf2pt1.sourceforge.net/")
(license license:bsd-3)))
+(define-public mftrace
+ (let ((commit "3b4bc2e5b8a4ae6f9c776593961b38389e62a484")
+ ;; see https://github.com/hanwen/mftrace/pull/12
+ (revision "0"))
+ (package
+ (name "mftrace")
+ (version (git-version "1.2.20" revision commit))
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/hanwen/mftrace")
+ (commit commit)))
+ (sha256
+ (base32 "01cg6z1z69za07wrvx1y5dnfagx4di2a9qnx25f97l6843x03s36"))
+ (file-name (git-file-name name version))))
+ (build-system gnu-build-system)
+ (native-inputs (list autoconf
+ ;; for tests:
+ (texlive-updmap.cfg
+ (list texlive-cm))))
+ (propagated-inputs (list potrace lcdf-typetools))
+ (arguments
+ (list
+ ;; setting CC is needed for implicit rule
+ #:make-flags #~(list (string-append "CC=" #$(cc-for-target)))
+ #:test-target "test"
+ #:phases
+ #~(modify-phases %standard-phases
+ (replace 'bootstrap
+ (lambda args
+ (invoke "autoconf"))))))
+ (home-page "https://lilypond.org/mftrace/")
+ (synopsis "Scalable PostScript fonts for MetaFont")
+ (description "This package provides @command{mftrace}, a small Python
+program that lets you trace a TeX bitmap font into a PFA or PFB font (a
+PostScript Type 1 Scalable Font) or a @acronym{TTF,TrueType Font}.
+
+Scalable fonts offer many advantages over bitmaps, as they allow documents to
+render correctly at many printer resolutions. Moreover, Ghostscript can
+generate much better PDFs if given scalable PostScript fonts.
+
+Versions of this program prior to 1.0.5 were called @command{pktrace}.")
+ (license license:gpl2+))))
+
(define-public woff2
(package
(name "woff2")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 09/16] gnu: Add ocaml-flow-parser.
(address . 67019@debbugs.gnu.org)
9e31af33a03e3581f3c124b6b53241a34c31e42e.1700161584.git.philip@philipmcgrath.com
* gnu/packages/web.scm (ocaml-flow-parser): New variable.
---
gnu/packages/web.scm | 95 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)

Toggle diff (122 lines)
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 9efc6ebc9d..b222c2ae40 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -96,6 +96,7 @@ (define-module (gnu packages web)
#:use-module (guix build-system cargo)
#:use-module (guix build-system cmake)
#:use-module (guix build-system copy)
+ #:use-module (guix build-system dune)
#:use-module (guix build-system glib-or-gtk)
#:use-module (guix build-system gnu)
#:use-module (guix build-system go)
@@ -173,6 +174,7 @@ (define-module (gnu packages web)
#:use-module (gnu packages node)
#:use-module (gnu packages node-xyz)
#:use-module (gnu packages nss)
+ #:use-module (gnu packages ocaml)
#:use-module (gnu packages openldap)
#:use-module (gnu packages openstack)
#:use-module (gnu packages package-management)
@@ -1938,6 +1940,99 @@ (define-public esbuild
and other data, for distribution on the web.")
(license license:expat)))
+(define-public ocaml-flow-parser
+ (package
+ (name "ocaml-flow-parser")
+ (version "0.159.0")
+ (outputs '("out" "js"))
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/facebook/flow")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32 "1i9svf641s24nj4w6y9vvglzg29h0lr4n9a6mvwrn9psy9x1lril"))
+ (file-name (git-file-name "flow" version))))
+ (build-system dune-build-system)
+ (propagated-inputs (list ocaml-base
+ ocaml-core-kernel
+ ocaml-dtoa
+ ocaml-sedlex
+ ocaml-wtf8))
+ (native-inputs (list js-of-ocaml
+ ocamlbuild
+ ocaml-findlib
+ ocaml-ounit2
+ ocaml-ppx-deriving
+ ocaml-ppx-gen-rec
+ ocaml-visitors))
+ (arguments
+ (list
+ #:tests? #f ; tests need lwt_ppx
+ #:package "flow_parser"
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-before 'build 'chdir
+ (lambda args
+ (chdir "src/parser")))
+ (add-before 'build 'patch-source
+ (lambda args
+ ;; Avoid errors with newer OCaml:
+ ;; "Error (warning 16 [unerasable-optional-argument]):"
+ ;; " this optional argument cannot be erased."
+ ;; "Error (warning 69 [unused-field]):"
+ ;; " mutable record field buf is never mutated."
+ ;; "Error (warning 70 [missing-mli]): Cannot find interface file."
+ (substitute* "_tags"
+ (("<\\*\\.ml\\*>: warn[(]-39[)]")
+ "<*.ml*>: warn(-16-39-70)"))
+ (substitute* "../../_tags"
+ (("<\\*\\*/\\*.ml\\*>: ")
+ "<**/*.ml*>: warn(-69), "))
+ ;; Deprecation of Js.Unsafe.variable, Js.Error, Js.raise_js_error
+ (substitute* "flow_parser_js.ml"
+ (("Js\\.Unsafe\\.variable")
+ "Js.Unsafe.pure_js_expr"))
+ (substitute* "flow_parser_dot_js.ml"
+ (("Js\\.Error")
+ "Js_of_ocaml.Js_error.Exn")
+ (("Js\\.raise_js_error")
+ "Js_of_ocaml.Js_error.raise_"))))
+ (replace 'build
+ (lambda args
+ (invoke "make"
+ (string-append "CC=" #$(cc-for-target))
+ "build-parser")))
+ (add-after 'build 'build-js
+ (lambda args
+ (invoke "make"
+ (string-append "CC=" #$(cc-for-target))
+ "js")))
+ (replace 'check
+ (lambda* (#:key tests? #:allow-other-keys)
+ (when tests?
+ (invoke "make"
+ (string-append "CC=" #$(cc-for-target))
+ "test-ocaml"))))
+ (replace 'install
+ (lambda args
+ (invoke "make"
+ (string-append "CC=" #$(cc-for-target))
+ "ocamlfind-install")))
+ (add-after 'install 'install-js
+ (lambda args
+ (install-file "flow_parser.js"
+ (string-append #$output:js
+ "/share/javascript/flow")))))))
+ (properties `((upstream-name . "flow_parser")))
+ (home-page "https://flow.org")
+ (synopsis "Parser for the Flow JavaScript type system")
+ (description "Flow is a gradual type system for JavaScript. This package
+provides the Flow parser, which is an OCaml library that can also be compiled
+to JavaScript.")
+ (license license:expat)))
+
(define-public tinyproxy
(package
(name "tinyproxy")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 10/16] gnu: Add node-flow-parser.
(address . 67019@debbugs.gnu.org)
a2d6ace236cc8cc5f90889801bee9b453700d59f.1700161584.git.philip@philipmcgrath.com
* gnu/packages/web.scm (node-flow-parser): New variable.
(ocaml-flow-parser)[description]: Mention it.
---
gnu/packages/web.scm | 45 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)

Toggle diff (60 lines)
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index b222c2ae40..b8646e9d0d 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -2030,9 +2030,52 @@ (define-public ocaml-flow-parser
(synopsis "Parser for the Flow JavaScript type system")
(description "Flow is a gradual type system for JavaScript. This package
provides the Flow parser, which is an OCaml library that can also be compiled
-to JavaScript.")
+to JavaScript. To use the compiled parser with Node.js or NPM, see the Guix
+package @code{node-flow-parser}.")
(license license:expat)))
+(define-public node-flow-parser
+ (package
+ (inherit ocaml-flow-parser)
+ (name "node-flow-parser")
+ (properties '())
+ (outputs '("out"))
+ (propagated-inputs '())
+ (native-inputs '())
+ (inputs (list `(,ocaml-flow-parser "js")))
+ (build-system node-build-system)
+ (arguments
+ (list
+ #:tests? #f ; need unpackaged dependencies
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'delete-workspace-file
+ (lambda args
+ ;; this workspace file causes NPM to try to install dependencies
+ ;; of other packages developed in this source repository
+ (delete-file "package.json")))
+ (add-after 'delete-workspace-file 'chdir
+ (lambda args
+ (chdir "packages/flow-parser")))
+ (add-after 'chdir 'unpack-generated-js
+ (lambda* (#:key inputs #:allow-other-keys)
+ (install-file
+ (search-input-file inputs
+ "share/javascript/flow/flow_parser.js")
+ ".")
+ (delete-file "Makefile")))
+ (add-after 'patch-dependencies 'delete-dependencies
+ (lambda args
+ (delete-dependencies
+ '("ast-types"
+ "colors"
+ "esprima-fb"
+ "minimist")))))))
+ (synopsis "Parser for the Flow JavaScript type system")
+ (description "Flow is a gradual type system for JavaScript. This package
+provides the Flow parser in its compiled-to-JavaScript form for use with
+Node.js and NPM.")))
+
(define-public tinyproxy
(package
(name "tinyproxy")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 15/16] gnu: Add font-katex.
(address . 67019@debbugs.gnu.org)
16f8bf6f752e012ec9a61c8cfc6029cb7c46e536.1700161584.git.philip@philipmcgrath.com
* gnu/packages/javascript.scm (font-katex): New variable.
---
gnu/packages/javascript.scm | 74 +++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)

Toggle diff (104 lines)
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index 97cb3b6270..ee7a48154c 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -30,9 +30,15 @@ (define-module (gnu packages javascript)
#:use-module (gnu packages base)
#:use-module (gnu packages bash)
#:use-module (gnu packages compression)
+ #:use-module (gnu packages fontutils)
#:use-module (gnu packages java)
#:use-module (gnu packages node)
+ #:use-module (gnu packages perl)
+ #:use-module (gnu packages python)
+ #:use-module (gnu packages python-compression)
+ #:use-module (gnu packages python-xyz)
#:use-module (gnu packages readline)
+ #:use-module (gnu packages tex)
#:use-module (gnu packages uglifyjs)
#:use-module (gnu packages web)
#:use-module (guix gexp)
@@ -41,6 +47,7 @@ (define-module (gnu packages javascript)
#:use-module (guix git-download)
#:use-module (guix build-system ant)
#:use-module (guix build-system cmake)
+ #:use-module (guix build-system copy)
#:use-module (guix build-system gnu)
#:use-module (guix build-system minify)
#:use-module (guix build-system node)
@@ -372,6 +379,73 @@ (define-public js-mathjax-for-r-mathjaxr
(base32
"1q063l6477z285j6h5wvccp6iswvlp0jmb96sgk32sh0lf7nhknh")))))))))
+(define-public font-katex
+ (package
+ (name "font-katex")
+ (version "0.16.4")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/KaTeX/KaTeX")
+ (commit (string-append "v" version))))
+ (sha256
+ (base32
+ "0z6y2188lhfv0gk0hp4rm37g6fs99qb3ab2q3n9g76ga9dwxhw3s"))
+ (snippet
+ ;; unbundle generated files
+ #~(begin
+ (use-modules (guix build utils))
+ (delete-file "src/fontMetricsData.js")
+ (delete-file-recursively "fonts")))
+ (file-name (git-file-name "katex" version))))
+ (build-system copy-build-system)
+ (native-inputs (list (texlive-updmap.cfg
+ (list texlive-amsfonts
+ texlive-cm
+ texlive-fonts-rsfs))
+ fontforge
+ mftrace
+ ttfautohint
+ perl
+ perl-json
+ python
+ python-fonttools
+ python-brotli
+ python-zopfli
+ which))
+ (arguments
+ (list
+ #:install-plan
+ #~`(("fonts/" "share/fonts/truetype/katex/")
+ ("src/fontMetricsData.js" "share/katex/"))
+ #:imported-modules
+ `((guix build union)
+ ,@%copy-build-system-modules)
+ #:modules
+ '((guix build copy-build-system)
+ (guix build union)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-before 'install 'build
+ (lambda args
+ (invoke "make" "-C" "src/fonts" "all")
+ (union-build "fonts"
+ '("src/fonts/ttf"
+ "src/fonts/woff"
+ "src/fonts/woff2")
+ #:symlink copy-file)))
+ (add-after 'build 'build-metrics
+ (lambda args
+ (with-directory-excursion "dockers/fonts"
+ ;; script assumes it is run from this directory
+ (invoke "./buildMetrics.sh")))))))
+ (home-page "https://katex.org")
+ (synopsis "Fonts for KaTeX")
+ (description "This package contains the fonts required for KaTeX.")
+ (license license:expat)))
+
(define-public js-commander
(package
(name "js-commander")
--
2.41.0
P
P
Philip McGrath wrote on 16 Nov 2023 20:15
[PATCH v2 16/16] gnu: Add katex.
(address . 67019@debbugs.gnu.org)
ef6269b7bc4d8454bf34b99335717c0e666b4b7f.1700161584.git.philip@philipmcgrath.com
* gnu/packages/javascript.scm (katex): New variable.
---
gnu/packages/javascript.scm | 255 +++++++++++++++++++++++++++++++++++-
1 file changed, 253 insertions(+), 2 deletions(-)

Toggle diff (289 lines)
diff --git a/gnu/packages/javascript.scm b/gnu/packages/javascript.scm
index ee7a48154c..76a51c22ac 100644
--- a/gnu/packages/javascript.scm
+++ b/gnu/packages/javascript.scm
@@ -32,6 +32,7 @@ (define-module (gnu packages javascript)
#:use-module (gnu packages compression)
#:use-module (gnu packages fontutils)
#:use-module (gnu packages java)
+ #:use-module (gnu packages man)
#:use-module (gnu packages node)
#:use-module (gnu packages perl)
#:use-module (gnu packages python)
@@ -382,7 +383,7 @@ (define-public js-mathjax-for-r-mathjaxr
(define-public font-katex
(package
(name "font-katex")
- (version "0.16.4")
+ (version "0.16.9")
(source
(origin
(method git-fetch)
@@ -391,7 +392,7 @@ (define-public font-katex
(commit (string-append "v" version))))
(sha256
(base32
- "0z6y2188lhfv0gk0hp4rm37g6fs99qb3ab2q3n9g76ga9dwxhw3s"))
+ "1aq8n9s4r15m1fdi4h58qxal4brkafm4xsw6rpz40wqi9454kkgn"))
(snippet
;; unbundle generated files
#~(begin
@@ -446,6 +447,256 @@ (define-public font-katex
(description "This package contains the fonts required for KaTeX.")
(license license:expat)))
+(define-public katex
+ (package
+ (inherit font-katex)
+ (name "katex")
+ (outputs '("out" "dist"))
+ (build-system node-build-system)
+ (native-inputs
+ (list esbuild
+ flow-remove-types
+ help2man
+ lessc))
+ (inputs
+ (list font-katex
+ js-commander))
+ (arguments
+ (list
+ #:tests? #f ; many more dependencies
+ #:modules
+ `((guix build node-build-system)
+ (ice-9 match)
+ (srfi srfi-1)
+ (srfi srfi-26)
+ (guix build utils))
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-before 'patch-dependencies 'move-sources
+ (lambda* (#:key inputs #:allow-other-keys)
+ ;; Our node-build-system doesn't properly respect the "files"
+ ;; entry in "package.json" to determine which files to install.
+ ;; This case is particularly egregious because the source
+ ;; repository also contains the source for the whole katex.org
+ ;; website. For now, manually do what "files" ought to do.
+ (mkdir "../guix-source")
+ (copy-recursively "src" "../guix-source/src")
+ (copy-recursively "contrib" "../guix-source/contrib")
+ (for-each (cut install-file <> "../guix-source")
+ '("README.md"
+ "LICENSE"
+ "package.json"
+ "katex.js"
+ "cli.js"))
+ (install-file
+ (search-input-file inputs "share/katex/fontMetricsData.js")
+ "../guix-source/src")
+ (chdir "../guix-source")))
+ (add-after 'move-sources 'patch-package-json
+ (lambda args
+ (with-atomic-json-file-replacement "package.json"
+ (match-lambda
+ (('@ . alist)
+ (cons '@
+ (filter-map
+ (match-lambda
+ (((or "devDependencies" "scripts") . _)
+ #f)
+ ;; ESBuild can't generate Universal Module Definitions,
+ ;; so keep our CJS separate from our browser builds:
+ (("files" . lst)
+ `("files" "guix-node-cjs/" ,@lst))
+ (("main" . "dist/katex.js")
+ `("main" . "guix-node-cjs/katex.js"))
+ (("exports" '@ . alist)
+ `("exports" @
+ ,@(map (match-lambda
+ (("./*" . "./*")
+ `("./*" . "./*"))
+ ((lhs '@ . alist)
+ `(,lhs @
+ ,@(map (match-lambda
+ (("require" . ,str)
+ (cons
+ "require"
+ (string-append
+ "./guix-node-cjs/"
+ (substring str
+ (string-length
+ "./dist")))))
+ (other
+ other))
+ alist))))
+ alist)))
+ (other
+ other))
+ alist)))))))
+ (add-after 'patch-dependencies 'patch-sources
+ (lambda* (#:key inputs #:allow-other-keys)
+ (substitute* "src/SourceLocation.js"
+ ;; for some reason, the + prefix isn't handled
+ ;; by flow-remove-types
+ (("[+](lexer|start|end)" _ name)
+ name))
+ (substitute* "src/fonts.less"
+ ;; what webpack would do
+ (("@font-folder: \"\\.\\./fonts\";" orig)
+ (string-append "@font-folder: \"fonts\"; // " orig)))
+ (define version
+ #$(package-version this-package))
+ (substitute* "src/katex.less"
+ (("@version: \"\";" orig)
+ (string-append "@version: \"" version "\"; // " orig)))
+ (substitute* "katex.js"
+ (("version: __VERSION__," orig)
+ (string-append "version: \"" version "\", // " orig)))))
+ (add-after 'patch-sources 'erase-types
+ (lambda args
+ (invoke "flow-remove-types"
+ "--sourcemaps"
+ "--out-dir" "../erased/src/"
+ "src/")
+ (invoke "flow-remove-types"
+ "--sourcemaps"
+ "--out-dir" "../erased/"
+ "katex.js")
+ (invoke "flow-remove-types"
+ "--sourcemaps"
+ "--out-dir" "../erased/contrib/"
+ "contrib/")))
+ (add-after 'erase-types 'build-js
+ (lambda args
+ (with-directory-excursion "../erased"
+ ;; ^ avoid "../erased" in generated code
+ (define (esbuild . args)
+ (apply invoke `("esbuild"
+ "--bundle"
+ "--log-limit=0"
+ "--platform=neutral"
+ ,@args)))
+ (esbuild "--outfile=../guix-source/dist/katex.mjs"
+ "--format=esm"
+ "katex.js")
+ ;; Workaround for different handling of ES6 default export
+ ;; when generating CJS:
+ (esbuild "--outfile=katex-cjs.js"
+ "--format=cjs"
+ "katex.js")
+ (with-output-to-file "katex-wrapper.js"
+ (lambda ()
+ (display
+ "module.exports = require('./katex-cjs.js').default;\n")))
+ (esbuild "--outfile=../guix-source/guix-node-cjs/katex.js"
+ "--format=cjs"
+ "katex-wrapper.js")
+ (esbuild "--outfile=../guix-source/dist/katex.js"
+ "--format=iife"
+ "--global-name=katex"
+ "katex-wrapper.js")
+ (esbuild "--outfile=../guix-source/dist/katex.min.js"
+ "--minify"
+ "--format=iife"
+ "--global-name=katex"
+ "katex-wrapper.js")
+ ;; Build extensions:
+ (for-each
+ (match-lambda
+ ((name export)
+ ;; The copy-tex extension doesn't actually import katex,
+ ;; but it's harmless to handle it the same way.
+ (with-directory-excursion (string-append "contrib/" name)
+ (esbuild (string-append "--outfile=../../../guix-source"
+ "/guix-node-cjs/contrib/"
+ name ".js")
+ "--format=cjs"
+ "--external:katex"
+ (string-append name ".js"))
+ (substitute* (string-append name ".js")
+ (("import katex from \"katex\";")
+ "import katex from \"../katex.mjs\";"))
+ (esbuild (string-append "--outfile=" name ".mjs")
+ "--format=esm"
+ "--external:../katex.mjs"
+ (string-append name ".js"))
+ (install-file (string-append name ".mjs")
+ "../../../guix-source/dist/contrib")
+ (substitute* (string-append name ".js")
+ (("import katex")
+ "// import katex"))
+ (for-each
+ (lambda (minify?)
+ (apply
+ esbuild
+ `(,(string-append "--outfile=../../.."
+ "/guix-source/dist/contrib/"
+ name
+ (if minify? ".min" "")
+ ".js")
+ "--format=iife"
+ ,@(if minify?
+ '("--minify")
+ '())
+ ,@(if export
+ `("--global-name=guixTmp"
+ ,(string-append "--banner:js=const "
+ export
+ " = (() => {")
+ "--footer:js=return guixTmp.default;\n})();")
+ '())
+ ,(string-append name ".js"))))
+ '(#t #f)))))
+ '(("auto-render" "renderMathInElement")
+ ("copy-tex" #f)
+ ("mathtex-script-type" #f)
+ ("mhchem" #f)
+ ("render-a11y-string" "renderA11yString"))))))
+ (add-after 'build-js 'build-css
+ (lambda args
+ (invoke "lessc" "src/katex.less" "dist/katex.css")))
+ (add-after 'install 'generate-man-page
+ (lambda args
+ (invoke "help2man"
+ "-N"
+ "-n" "render TeX math to HTML and MathML"
+ "--output=katex.1"
+ (string-append #$output "/bin/katex"))
+ (install-file "katex.1"
+ (string-append #$output "/share/man/man1"))))
+ (add-after 'generate-man-page 'install-dist
+ (lambda* (#:key inputs #:allow-other-keys)
+ ;; The CSS, fonts, etc. needed for KaTeX, plus the optional
+ ;; bundled version of the JavaScript for dynamic use in the
+ ;; browser, are in the 'dist' directory of the Node module.
+ ;; Putting them in a separate output lets them be used without
+ ;; retaining a reference to Node and the cli utility.
+ ;; In Debian, 'dist' is a symlink to /usr/share/javascript/katex:
+ ;; do likewise to help tools that may need to find it.
+ (define up-dist-dir
+ (string-append #$output:dist "/share/javascript"))
+ (define dist-dir
+ (string-append up-dist-dir "/katex"))
+ (mkdir-p up-dist-dir)
+ (with-directory-excursion
+ (string-append #$output "/lib/node_modules/katex")
+ (rename-file "dist" dist-dir)
+ (symlink dist-dir "dist"))
+ (with-directory-excursion dist-dir
+ ;; Link the fonts to where the CSS expects them:
+ (symlink (search-input-directory inputs
+ "share/fonts/truetype/katex")
+ "fonts")
+ ;; We can't actually minify the CSS, but fake it for anything
+ ;; that may expect it. With Brotli compression, the difference
+ ;; is only about 300 bytes anyway.
+ (symlink "katex.css" "katex.min.css")))))))
+ (synopsis "Fast math typesetting for the web")
+ (description "KaTeX renders TeX math notation to HTML and/or MathML. The
+rendered output does not depend on JavaScript, so rendering can be done
+entirely ahead-of-time using the @command{katex} command-line tool. When
+desired, KaTeX can also be used as a JavaScript library in the browser to
+render math dynamically, and it is designed to be fast, even on pages with
+hundreds of mathematical expressions.")))
+
(define-public js-commander
(package
(name "js-commander")
--
2.41.0
L
L
Liliana Marie Prikler wrote on 16 Nov 2023 21:29
Re: [PATCH v2 09/16] gnu: Add ocaml-flow-parser.
596d17b7a4895a8a4ae2045133ab694416b0583b.camel@gmail.com
Am Donnerstag, dem 16.11.2023 um 14:15 -0500 schrieb Philip McGrath:
Toggle quote (98 lines)
> * gnu/packages/web.scm (ocaml-flow-parser): New variable.
> ---
>  gnu/packages/web.scm | 95
> ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 95 insertions(+)
>
> diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
> index 9efc6ebc9d..b222c2ae40 100644
> --- a/gnu/packages/web.scm
> +++ b/gnu/packages/web.scm
> @@ -96,6 +96,7 @@ (define-module (gnu packages web)
>    #:use-module (guix build-system cargo)
>    #:use-module (guix build-system cmake)
>    #:use-module (guix build-system copy)
> +  #:use-module (guix build-system dune)
>    #:use-module (guix build-system glib-or-gtk)
>    #:use-module (guix build-system gnu)
>    #:use-module (guix build-system go)
> @@ -173,6 +174,7 @@ (define-module (gnu packages web)
>    #:use-module (gnu packages node)
>    #:use-module (gnu packages node-xyz)
>    #:use-module (gnu packages nss)
> +  #:use-module (gnu packages ocaml)
>    #:use-module (gnu packages openldap)
>    #:use-module (gnu packages openstack)
>    #:use-module (gnu packages package-management)
> @@ -1938,6 +1940,99 @@ (define-public esbuild
>  and other data, for distribution on the web.")
>      (license license:expat)))
>  
> +(define-public ocaml-flow-parser
> +  (package
> +    (name "ocaml-flow-parser")
> +    (version "0.159.0")
> +    (outputs '("out" "js"))
> +    (source
> +     (origin
> +       (method git-fetch)
> +       (uri (git-reference
> +             (url "https://github.com/facebook/flow")
> +             (commit (string-append "v" version))))
> +       (sha256
> +        (base32
> "1i9svf641s24nj4w6y9vvglzg29h0lr4n9a6mvwrn9psy9x1lril"))
> +       (file-name (git-file-name "flow" version))))
> +    (build-system dune-build-system)
> +    (propagated-inputs (list ocaml-base
> +                             ocaml-core-kernel
> +                             ocaml-dtoa
> +                             ocaml-sedlex
> +                             ocaml-wtf8))
> +    (native-inputs (list js-of-ocaml
> +                         ocamlbuild
> +                         ocaml-findlib
> +                         ocaml-ounit2
> +                         ocaml-ppx-deriving
> +                         ocaml-ppx-gen-rec
> +                         ocaml-visitors))
> +    (arguments
> +     (list
> +      #:tests? #f ; tests need lwt_ppx
> +      #:package "flow_parser"
> +      #:phases
> +      #~(modify-phases %standard-phases
> +          (add-before 'build 'chdir
> +            (lambda args
> +              (chdir "src/parser")))
> +          (add-before 'build 'patch-source
> +            (lambda args
> +              ;; Avoid errors with newer OCaml:
> +              ;; "Error (warning 16 [unerasable-optional-
> argument]):"
> +              ;;   " this optional argument cannot be erased."
> +              ;; "Error (warning 69 [unused-field]):"
> +              ;;   " mutable record field buf is never mutated."
> +              ;; "Error (warning 70 [missing-mli]): Cannot find
> interface file."
> +              (substitute* "_tags"
> +                (("<\\*\\.ml\\*>: warn[(]-39[)]")
> +                 "<*.ml*>: warn(-16-39-70)"))
> +              (substitute* "../../_tags"
> +                (("<\\*\\*/\\*.ml\\*>: ")
> +                 "<**/*.ml*>: warn(-69), "))
> +              ;; Deprecation of Js.Unsafe.variable, Js.Error,
> Js.raise_js_error
> +              (substitute* "flow_parser_js.ml"
> +                (("Js\\.Unsafe\\.variable")
> +                 "Js.Unsafe.pure_js_expr"))
> +              (substitute* "flow_parser_dot_js.ml"
> +                (("Js\\.Error")
> +                 "Js_of_ocaml.Js_error.Exn")
> +                (("Js\\.raise_js_error")
> +                 "Js_of_ocaml.Js_error.raise_"))))
> +          (replace 'build
> +            (lambda args
> +              (invoke "make"
> +                      (string-append "CC=" #$(cc-for-target))
> +                      "build-parser")))
You might want to let-bind (invoke "make" "CC=..." <>) so that you can
call it with a single argument in this and other phases.
Toggle quote (32 lines)
> +          (add-after 'build 'build-js
> +            (lambda args
> +              (invoke "make"
> +                      (string-append "CC=" #$(cc-for-target))
> +                      "js")))
> +          (replace 'check
> +            (lambda* (#:key tests? #:allow-other-keys)
> +              (when tests?
> +                (invoke "make"
> +                        (string-append "CC=" #$(cc-for-target))
> +                        "test-ocaml"))))
> +          (replace 'install
> +            (lambda args
> +              (invoke "make"
> +                      (string-append "CC=" #$(cc-for-target))
> +                      "ocamlfind-install")))
> +          (add-after 'install 'install-js
> +            (lambda args
> +              (install-file "flow_parser.js"
> +                            (string-append #$output:js
> +                                          
> "/share/javascript/flow")))))))
> +    (properties `((upstream-name . "flow_parser")))
> +    (home-page "https://flow.org")
> +    (synopsis "Parser for the Flow JavaScript type system")
> +    (description "Flow is a gradual type system for JavaScript. 
> This package
> +provides the Flow parser, which is an OCaml library that can also be
> compiled
> +to JavaScript.")
> +    (license license:expat)))
> +
Cheers
?