diff mbox series

[bug#51838,v8,05/41] guix: node-build-system: Add 'delete-dependencies' helper function.

Message ID 9ae866e3078c04f1716b665b7e2de114fe666514.camel@gmail.com
State Accepted
Headers show
Series guix: node-build-system: Support compiling add-ons with node-gyp. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Liliana Marie Prikler Dec. 30, 2021, 7:38 a.m. UTC
Many node packages currently skip the configure phase, because they lack
both dependencies and a convenient way to build without all of them, e.g.
for the purposes of bootstrapping.  This patch adds a big hammer to flatten
these nails.

* guix/build/node-build-system.scm (delete-dependencies): New variable.

Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
---
 guix/build/node-build-system.scm | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff mbox series

Patch

diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm
index 49b3db34ad..75bded73af 100644
--- a/guix/build/node-build-system.scm
+++ b/guix/build/node-build-system.scm
@@ -25,11 +25,13 @@  (define-module (guix build node-build-system)
   #:use-module (guix build utils)
   #:use-module (guix build json)
   #:use-module (ice-9 ftw)
+  #:use-module (ice-9 regex)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-71)
   #:export (%standard-phases
             with-atomic-json-file-replacement
+            delete-dependencies
             node-build))
 
 (define (with-atomic-json-file-replacement file proc)
@@ -184,6 +186,30 @@  (define resolve-dependencies
          (@)))))
   #t)
 
+(define (delete-dependencies unwanted)
+  "Rewrite package.json to remove UNWANTED dependencies.  Unwanted dependencies
+can be specified as regular expressions to exclude a range of related
+dependencies, e.g. \"tap\" excludes all dependencies including \"tap\" in their
+name, but \"^tap$\" explicitly excludes \"tap\"."
+  (define delete-from-jsobject
+    (match-lambda
+      (('@ . alist)
+       (cons '@ (filter (match-lambda
+                          ((k . v)
+                           (not (any
+                                 (lambda (pattern)
+                                   (string-match pattern k))
+                                 unwanted))))
+                        alist)))))
+
+  (with-atomic-json-file-replacement "package.json"
+    (lambda (pkg-meta)
+      (jsobject-update*
+       pkg-meta
+       `("peerDependencies" ,delete-from-jsobject (@))
+       `("devDependencies" ,delete-from-jsobject (@))
+       `("dependencies" ,delete-from-jsobject (@))))))
+
 (define* (delete-lockfiles #:key inputs #:allow-other-keys)
   "Delete 'package-lock.json', 'yarn.lock', and 'npm-shrinkwrap.json', if they
 exist."