Subject: [PATCH 10/16] gnu: Add node-flow-parser.

From: Philip McGrath <[email-masked]>
Date: Thu, 9 Nov 2023 11:26:32 -0500

* 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(-)

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