Subject: [bug#67019] [PATCH 01/16] gnu: Add node-is-what.

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

* gnu/packages/node-xyz.scm (node-is-what): New variable.
---
 gnu/packages/node-xyz.scm | 81 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)

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