diff mbox series

[bug#67019,02/16] gnu: Add node-copy-anything.

Message ID 0e821283aa47a488700cd018e7487ed5498a01ba.1699540553.git.philip@philipmcgrath.com
State New
Headers show
Series gnu: Add KaTeX, lessc, and flow-remove-types. | expand

Commit Message

Philip McGrath Nov. 9, 2023, 4:26 p.m. UTC
* gnu/packages/node-xyz.scm (node-copy-anything): New variable.
---
 gnu/packages/node-xyz.scm | 81 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 81 insertions(+)
diff mbox series

Patch

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