From patchwork Mon Feb 17 23:43:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 38799 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 472CD27BBE2; Mon, 17 Feb 2025 23:49:29 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id C2D8E27BBE9 for ; Mon, 17 Feb 2025 23:49:24 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkArJ-0004mP-Dc; Mon, 17 Feb 2025 18:49:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tkArG-0004lk-GV for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:02 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkArG-0005Dx-7m for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=lwgmqWlMsIyr7GCOXS70gge+bIh2Df5gA7T+XHAbYiI=; b=uL2ninF8Ox0Oe/hkqNJHXirVFL3FCHr0xPMZLRrgCe7Gs4WFg9RO/aMJ60LsXmb5j6iMjmLA42BLlAxsVIY7Efj4zUbk6VPPEMSWK5Xwt9BEXpbLydLogrrG1IujjTs04e0im3CTTrpPvH/fJdemO4bNd2TDnjg78bwmG7bZX+SZsSisRIEQF+Va2bq7Vsr1xmKpm9EIbNU4uwOUpxdTFryJqPuc8aR1kywhlfEdZoXbtO6024ASbl6gF0TSLMOymdiQJ6ybg71hyVLteGB39miY7Ztv4NRPI3qCqWBrRFspj3zj856SLdiLY+2kq47ntfo5puTyABblpBvSAFHAhA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tkArG-0007Oy-1t for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74900] [PATCH v2 1/6] build-system/node: Switch to (json). Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 17 Feb 2025 23:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74900 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74900@debbugs.gnu.org Cc: jlicht@fsfe.org, d.khodabakhsh@gmail.com Received: via spool by 74900-submit@debbugs.gnu.org id=B74900.173983611828303 (code B ref 74900); Mon, 17 Feb 2025 23:49:02 +0000 Received: (at 74900) by debbugs.gnu.org; 17 Feb 2025 23:48:38 +0000 Received: from localhost ([127.0.0.1]:51163 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tkAqp-0007M3-JP for submit@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:38 -0500 Received: from 5.mo560.mail-out.ovh.net ([87.98.181.248]:35473) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tkAqj-0007LB-JK for 74900@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:33 -0500 Received: from director3.ghost.mail-out.ovh.net (unknown [10.109.176.96]) by mo560.mail-out.ovh.net (Postfix) with ESMTP id 4YxfVg4hy1z1fbY for <74900@debbugs.gnu.org>; Mon, 17 Feb 2025 23:48:27 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-cdqmd (unknown [10.110.168.82]) by director3.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 362711FD86; Mon, 17 Feb 2025 23:48:27 +0000 (UTC) Received: from ngraves.fr ([37.59.142.108]) by ghost-submission-5b5ff79f4f-cdqmd with ESMTPSA id Mc3aN8rKs2cX6AIA6KgjNw (envelope-from ); Mon, 17 Feb 2025 23:48:27 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-108S002f23f5fba-8074-470a-a5d1-bcb9b4536151, C3652AECFC9F6A3CBC46B0867312B59102225E78) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.92.117.144 Date: Tue, 18 Feb 2025 00:43:52 +0100 Message-ID: <20250217234823.10533-2-ngraves@ngraves.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250217234823.10533-1-ngraves@ngraves.fr> References: <20250217234823.10533-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 14612773415954866930 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdehleejjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepteeghefhfeetvdevueevhfefjeegfefgleeuvdeutdduudeljeduveehkefgvdfgnecuffhomhgrihhnpehgnhhurdhorhhgpdhgihhthhhusgdrtghomhenucfkphepuddvjedrtddrtddruddpledtrdelvddruddujedrudeggedpfeejrdehledrudegvddruddtkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjeegledttdesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheeitdgmpdhmohguvgepshhmthhpohhuth DKIM-Signature: a=rsa-sha256; bh=lwgmqWlMsIyr7GCOXS70gge+bIh2Df5gA7T+XHAbYiI=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1739836107; v=1; b=SJcd5TKswbDVxVYoeQXjxL4u+7fUvmSwq2lb9YyrntbtEmajf4ErrbMgqoS+nQmhyrtNh1e+ WHdlBfCVECsRTPrtIitBrvVYnbF0YDCNuimCuJ4SXW44oyfzYPrqTTtzvDX2Y/F3+dOFDe6GFSY OLY3ZYb/vUEj1kUuaBNb3r7Ar1wVzPpFlin32nl0N6kM74TPhD3jpEvvBqYRhlnSfiyO6iOkuu3 vSnshiyvlZ3khnErSBGdOUol/Btsh8pOqdtQdhoC/efmx5xBdQxe1PlIs3exwoDz0zapR+83NHh UgH4qMR10Tx2I1c9dwS7LyBOa9Fw6BuEuMm9jvcIFn63A== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From: Daniel Khodabakhsh Replace (guix build json) with (json) in node-build-system * guix/build/node-build-system.scm (jsobject-ref, jsobject-update, jsobject-union, newest, unkeyed->keyed): Remove unused functions. (with-atomic-json-file-replacement): Switch to (json) module. Move file argument as a second optional argument. (alist-update): Switch to (json) module. Remove optional default argument. (patch-dependencies, delete-dependencies, build): Switch to (json) module. Arguments are unchanged. * guix/build-system/node.scm (%node-build-system-modules): Switch to (json) module. * gnu/packages/node-xyz.scm (node-acorn, node-addon-api, node-serialport-bindings, node-sqlite3): Adapt package custom <#:phases> to the replacement. Signed-off-by: Daniel Khodabakhsh Change-Id: I9fd5152a98b6a241d414e9a94ab179c9cabcfb85 --- gnu/packages/node-xyz.scm | 148 ++++++++++++------------- guix/build-system/node.scm | 6 +- guix/build/node-build-system.scm | 180 ++++++++++++------------------- 3 files changed, 139 insertions(+), 195 deletions(-) diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm index bbdcbb2b78..84adde9e50 100644 --- a/gnu/packages/node-xyz.scm +++ b/gnu/packages/node-xyz.scm @@ -7,6 +7,7 @@ ;;; Copyright © 2021 Dhruvin Gandhi ;;; Copyright © 2022 Nicolas Graves ;;; Copyright © 2023 Jelle Licht +;;; Copyright © 2024 Daniel Khodabakhsh ;;; ;;; This file is part of GNU Guix. ;;; @@ -24,14 +25,14 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu packages node-xyz) - #:use-module ((guix licenses) #:prefix license:) #:use-module (gnu packages sqlite) #:use-module (gnu packages python) #:use-module (gnu packages web) + #:use-module (guix build-system node) #:use-module (guix gexp) - #:use-module (guix packages) #:use-module (guix git-download) - #:use-module (guix build-system node)) + #:use-module ((guix licenses) #:prefix license:) + #:use-module (guix packages)) ;;; ;;; Please: Try to add new module packages in alphabetic order. @@ -69,19 +70,17 @@ (define-public node-acorn ;; it would try to use the build environment and would block the ;; automatic building by other packages making use of node-acorn. ;; TODO: Add utility function - (with-atomic-json-file-replacement "package.json" - (match-lambda - (('@ . pkg-meta-alist) - (cons '@ (map (match-lambda - (("scripts" @ . scripts-alist) - `("scripts" @ ,@(filter (match-lambda - (("prepare" . _) - #f) - (_ - #t)) - scripts-alist))) - (other other)) - pkg-meta-alist))))))) + (with-atomic-json-file-replacement (lambda (pkg-meta-alist) + (map + (match-lambda + (("scripts" . scripts-alist) + (cons "scripts" (filter + (match-lambda + (("prepare" . _) #f) + (_ #t)) + scripts-alist))) + (other other)) + pkg-meta-alist))))) (replace 'build (lambda* (#:key inputs native-inputs #:allow-other-keys) (let ((esbuild (search-input-file (or native-inputs inputs) @@ -158,23 +157,17 @@ (define-public node-addon-api (lambda args (define new-test-script "echo stopping after pretest on Guix") - (with-atomic-json-file-replacement "package.json" - (match-lambda - (('@ . pkg-meta-alist) - (cons - '@ - (map (match-lambda - (("scripts" '@ . scripts-alist) - `("scripts" @ ,@(map (match-lambda - (("test" . _) - (cons "test" - new-test-script)) - (other - other)) - scripts-alist))) - (other - other)) - pkg-meta-alist)))))))))) + (with-atomic-json-file-replacement (lambda (pkg-meta-alist) + (map + (match-lambda + (("scripts" . scripts-alist) + (cons "scripts" (map + (match-lambda + (("test" . _) (cons "test" new-test-script)) + (other other)) + scripts-alist))) + (other other)) + pkg-meta-alist)))))))) (home-page "https://github.com/nodejs/node-addon-api") (synopsis "Node.js API (Node-API) header-only C++ wrappers") (description "This module contains header-only C++ wrapper classes which @@ -1223,22 +1216,19 @@ (define-public node-serialport-bindings "node-abi")))) (add-after 'chdir 'avoid-prebuild-install (lambda args - (with-atomic-json-file-replacement "package.json" - (match-lambda - (('@ . pkg-meta-alist) - (cons '@ (map (match-lambda - (("scripts" @ . scripts-alist) - `("scripts" @ ,@(filter (match-lambda - (("install" . _) - #f) - (_ - #t)) - scripts-alist))) - (("gypfile" . _) - '("gypfile" . #f)) - (other - other)) - pkg-meta-alist)))))))) + (with-atomic-json-file-replacement (lambda (pkg-meta-alist) + (map + (match-lambda + (("scripts" . scripts-alist) + (cons "scripts" (filter + (match-lambda + (("install" . _) #f) + (_ #t)) + scripts-alist))) + (("gypfile" . _) + (cons "gypfile" #f)) + (other other)) + pkg-meta-alist)))))) #:tests? #f)) (synopsis "Abstract base class for Node SerialPort bindings") (description "Node SerialPort is a modular suite of Node.js packages for @@ -1524,39 +1514,33 @@ (define-public node-sqlite3 (substitute* ".npmignore" (("lib/binding") "#lib/binding # <- patched for Guix")) - (with-atomic-json-file-replacement "package.json" - (match-lambda - (('@ . pkg-meta-alist) - (match (assoc-ref pkg-meta-alist "binary") - (('@ . binary-alist) - ;; When it builds from source, node-pre-gyp supplies - ;; module_name and module_path based on the entries under - ;; "binary" from "package.json", so this package's - ;; "binding.gyp" doesn't define them. Thus, we also need - ;; to supply them. The GYP_DEFINES environment variable - ;; turns out to be the easiest way to make sure they are - ;; propagated from npm to node-gyp to gyp. - (setenv "GYP_DEFINES" - (string-append - "module_name=" - (assoc-ref binary-alist "module_name") - " " - "module_path=" - (assoc-ref binary-alist "module_path"))))) - ;; We need to remove the install script from "package.json", - ;; as it would try to use node-pre-gyp and would block the - ;; automatic building performed by `npm install`. - (cons '@ (map (match-lambda - (("scripts" @ . scripts-alist) - `("scripts" @ ,@(filter (match-lambda - (("install" . _) - #f) - (_ - #t)) - scripts-alist))) - (other - other)) - pkg-meta-alist)))))))))) + (with-atomic-json-file-replacement (lambda (pkg-meta-alist) + (let ((binary-alist (assoc-ref pkg-meta-alist "binary"))) + ;; When it builds from source, node-pre-gyp supplies + ;; module_name and module_path based on the entries under + ;; "binary" from "package.json", so this package's + ;; "binding.gyp" doesn't define them. Thus, we also need + ;; to supply them. The GYP_DEFINES environment variable + ;; turns out to be the easiest way to make sure they are + ;; propagated from npm to node-gyp to gyp. + (setenv "GYP_DEFINES" (string-append + "module_name=" + (assoc-ref binary-alist "module_name") + " module_path=" + (assoc-ref binary-alist "module_path")))) + ;; We need to remove the install script from "package.json", + ;; as it would try to use node-pre-gyp and would block the + ;; automatic building performed by `npm install`. + (map + (match-lambda + (("scripts" . scripts-alist) + (cons "scripts" (filter + (match-lambda + (("install" . _) #f) + (_ #t)) + scripts-alist))) + (other other)) + pkg-meta-alist)))))))) (home-page "https://github.com/mapbox/node-sqlite3") (synopsis "Node.js bindings for SQLite3") (description diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm index 57fe5f6030..425b8cd9b3 100644 --- a/guix/build-system/node.scm +++ b/guix/build-system/node.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2021 Ludovic Courtès ;;; Copyright © 2021 Pierre Langlois ;;; Copyright © 2021 Philip McGrath +;;; Copyright © 2024 Daniel Khodabakhsh ;;; ;;; This file is part of GNU Guix. ;;; @@ -36,7 +37,10 @@ (define-module (guix build-system node) (define %node-build-system-modules ;; Build-side modules imported by default. `((guix build node-build-system) - (guix build json) + (json) + (json builder) + (json parser) + (json record) ,@%default-gnu-imported-modules)) (define (default-node) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index fb23894bc1..df7ea7774c 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2019, 2021 Timothy Sample ;;; Copyright © 2021, 2022 Philip McGrath ;;; Copyright © 2022 Liliana Marie Prikler +;;; Copyright © 2024 Daniel Khodabakhsh ;;; ;;; This file is part of GNU Guix. ;;; @@ -23,10 +24,10 @@ (define-module (guix build node-build-system) #:use-module ((guix build gnu-build-system) #:prefix gnu:) #: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 (json) #:use-module (srfi srfi-1) #:use-module (srfi srfi-71) #:export (%standard-phases @@ -34,13 +35,14 @@ (define-module (guix build node-build-system) delete-dependencies node-build)) -(define (with-atomic-json-file-replacement file proc) +(define* (with-atomic-json-file-replacement proc + #:optional (file "package.json")) "Like 'with-atomic-file-replacement', but PROC is called with a single argument---the result of parsing FILE's contents as json---and should a value to be written as json to the replacement FILE." (with-atomic-file-replacement file (lambda (in out) - (write-json (proc (read-json in)) out)))) + (scm->json (proc (json->scm in)) out)))) (define* (assoc-ref* alist key #:optional default) "Like assoc-ref, but return DEFAULT instead of #f if no value exists." @@ -48,10 +50,6 @@ (define* (assoc-ref* alist key #:optional default) (#f default) ((_ . value) value))) -(define* (jsobject-ref obj key #:optional default) - (match obj - (('@ . alist) (assoc-ref* alist key default)))) - (define* (alist-pop alist key #:optional (= equal?)) "Return two values, the first pair in ALIST with key KEY, and the other elements. Equality calls are made as (= KEY ALISTCAR)." @@ -63,67 +61,17 @@ (define (found? pair) (values (car after) (append before (cdr after))) (values #f before)))) -(define* (alist-update alist key proc #:optional default (= equal?)) +(define* (alist-update alist key proc #:optional (= equal?)) "Return an association list like ALIST, but with KEY mapped to the result of PROC applied to the first value found under the comparison (= KEY ALISTCAR). -If no such value exists, use DEFAULT instead. +If no such value exists, return the list unchanged. Unlike acons, this removes the previous association of KEY (assuming it is unique), but the result may still share storage with ALIST." (let ((pair rest (alist-pop alist key =))) - (acons key - (proc (if (pair? pair) - (cdr pair) - default)) - rest))) + (if (pair? pair) + (acons key (proc (cdr pair)) rest) + alist))) -(define (jsobject-update* js . updates) - "Return a json object like JS, but with all UPDATES applied. Each update is -a list (KEY PROC [DEFAULT]), so that KEY is mapped to the result of PROC -applied to the value to which KEY is mapped in JS. If no such mapping exists, -PROC is instead applied to DEFAULT, or to '#f' is no DEFAULT is specified. -The update takes place from left to right, so later UPDATERs will receive the -values returned by earlier UPDATERs for the same KEY." - (match js - (('@ . alist) - (let loop ((alist alist) - (updates updates)) - (match updates - (() (cons '@ alist)) - (((key proc) . updates) - (loop (alist-update alist key proc #f equal?) updates)) - (((key proc default) . updates) - (loop (alist-update alist key proc default equal?) updates))))))) - -(define (jsobject-union combine seed . objects) - "Merge OBJECTS into SEED by applying (COMBINE KEY VAL0 VAL), where VAL0 -is the value found in the (possibly updated) SEED and VAL is the new value -found in one of the OBJECTS." - (match seed - (('@ . aseed) - (match objects - (() seed) - ((('@ . alists) ...) - (cons - '@ - (fold (lambda (alist aseed) - (if (null? aseed) alist - (fold - (match-lambda* - (((k . v) aseed) - (let ((pair tail (alist-pop alist k))) - (match pair - (#f (acons k v aseed)) - ((_ . v0) (acons k (combine k v0 v) aseed)))))) - aseed - alist))) - aseed - alists))))))) - -;; Possibly useful helper functions: -;; (define (newest key val0 val) val) -;; (define (unkeyed->keyed proc) (lambda (_key val0 val) (proc val0 val))) - - ;;; ;;; Phases. ;;; @@ -142,8 +90,8 @@ (define (set-home . _) (define (module-name module) (let* ((package.json (string-append module "/package.json")) - (package-meta (call-with-input-file package.json read-json))) - (jsobject-ref package-meta "name"))) + (package-meta (call-with-input-file package.json json->scm))) + (assoc-ref package-meta "name"))) (define (index-modules input-paths) (define (list-modules directory) @@ -167,49 +115,59 @@ (define* (patch-dependencies #:key inputs #:allow-other-keys) (define index (index-modules (map cdr inputs))) - (define resolve-dependencies - (match-lambda - (('@ . alist) - (cons '@ (map (match-lambda - ((key . value) - (cons key (hash-ref index key value)))) - alist))))) + (define (resolve-dependencies dependencies) + (map + (match-lambda + ((dependency . version) + (cons dependency (hash-ref index dependency version)))) + dependencies)) - (with-atomic-json-file-replacement "package.json" + (with-atomic-json-file-replacement (lambda (pkg-meta) - (jsobject-update* - pkg-meta - `("devDependencies" ,resolve-dependencies (@)) - `("dependencies" ,(lambda (deps) - (resolve-dependencies - (jsobject-union - (lambda (k a b) b) - (jsobject-ref pkg-meta "peerDependencies" '(@)) - deps))) - (@))))) + (fold + (lambda (proc pkg-meta) (proc pkg-meta)) + pkg-meta + (list + (lambda (pkg-meta) + (alist-update pkg-meta "devDependencies" resolve-dependencies)) + (lambda (pkg-meta) + (assoc-set! + pkg-meta + "dependencies" + (resolve-dependencies + ; Combined "peerDependencies" and "dependencies" dependencies + ; with "dependencies" taking precedent. + (fold + (lambda (dependency dependencies) + (assoc-set! dependencies (car dependency) (cdr dependency))) + (assoc-ref* pkg-meta "peerDependencies" '()) + (assoc-ref* pkg-meta "dependencies" '()))))))))) #t) -(define (delete-dependencies absent) +(define (delete-dependencies dependencies-to-remove) "Rewrite 'package.json' to allow the build to proceed without packages -listed in ABSENT, a list of strings naming npm packages. +listed in 'dependencies-to-remove', a list of strings naming npm packages. To prevent the deleted dependencies from being reintroduced, use this function only after the 'patch-dependencies' phase." - (define delete-from-jsobject - (match-lambda - (('@ . alist) - (cons '@ (filter (match-lambda - ((k . _) - (not (member k absent)))) - alist))))) - - (with-atomic-json-file-replacement "package.json" + (with-atomic-json-file-replacement (lambda (pkg-meta) - (jsobject-update* - pkg-meta - `("devDependencies" ,delete-from-jsobject (@)) - `("dependencies" ,delete-from-jsobject (@)) - `("peerDependencies" ,delete-from-jsobject (@)))))) + (fold + (lambda (dependency-key pkg-meta) + (alist-update + pkg-meta + dependency-key + (lambda (dependencies) + (remove + (lambda (dependency) + (member (car dependency) dependencies-to-remove)) + dependencies)))) + pkg-meta + (list + "devDependencies" + "dependencies" + "peerDependencies" + "optionalDependencies"))))) (define* (delete-lockfiles #:key inputs #:allow-other-keys) "Delete 'package-lock.json', 'yarn.lock', and 'npm-shrinkwrap.json', if they @@ -228,8 +186,8 @@ (define* (configure #:key outputs inputs #:allow-other-keys) #t)) (define* (build #:key inputs #:allow-other-keys) - (let ((package-meta (call-with-input-file "package.json" read-json))) - (if (jsobject-ref (jsobject-ref package-meta "scripts" '(@)) "build" #f) + (let ((package-meta (call-with-input-file "package.json" json->scm))) + (if (assoc-ref* (assoc-ref* package-meta "scripts" '()) "build" #f) (let ((npm (string-append (assoc-ref inputs "node") "/bin/npm"))) (invoke npm "run" "build")) (format #t "there is no build script to run~%")) @@ -301,22 +259,20 @@ (define installed-package.json ;; even need to overwrite this file. Therefore, let's use some helpers ;; that we'd otherwise not need. (define pkg-meta - (call-with-input-file installed-package.json read-json)) + (call-with-input-file installed-package.json json->scm)) (define scripts - (jsobject-ref pkg-meta "scripts" '(@))) - (define (jsobject-set js key val) - (jsobject-update* js (list key (const val)))) + (assoc-ref* pkg-meta "scripts" '())) - (when (equal? "node-gyp rebuild" (jsobject-ref scripts "install" #f)) + (when (equal? "node-gyp rebuild" (assoc-ref* scripts "install" #f)) (call-with-output-file installed-package.json (lambda (out) - (write-json - (jsobject-set pkg-meta - "scripts" - (jsobject-set scripts - "install" - "echo Guix: avoiding node-gyp rebuild")) - out))))) + (scm->json + (assoc-set! pkg-meta + "scripts" + (assoc-set! scripts + "install" + "echo Guix: avoiding node-gyp rebuild")) + out))))) (define %standard-phases (modify-phases gnu:%standard-phases From patchwork Mon Feb 17 23:43:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 38800 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id F2D4927BBEA; Mon, 17 Feb 2025 23:49:33 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 58D4627BBE2 for ; Mon, 17 Feb 2025 23:49:30 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkArJ-0004mQ-Ie; Mon, 17 Feb 2025 18:49:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tkArG-0004m1-TM for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:03 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkArG-0005E2-KB for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=g7IuBJxKyT5+GnE8lpgTGQvO0Q3eLBN3GBwas3Et/Hs=; b=l6AYTzJNx81bwUqyoJP1fouPe82z0lI0BVrncsdQPmZgJTiSOAizQV2/GybjDcx3edHTAEPC+VttyFOunXdi6b8A7SRDraHkyShYFQeFwOLAaaFaR2FSQNNaBxDfYvnLO/p9KX+AuiRujLNf8njVVC3dv8Y4yllygkrN75kixBj+gECw+fvIRmgFVnbeHxf9sAYpcREU6GGmGP+qmzfxcqpx615i9QKgZs0p6sbqUKI26H2RATOveEi1cbl082vZu2bRjn+sTFa4Sa7c3qvrrc8pO4aiQVJXLyJ5LCRC8/m+xLM/yPk00rPuVqa8qwFxistuvIOMg/44XhMjvy4Paw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tkArG-0007P6-FK for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74900] [PATCH v2 2/6] build-system/node: New API for modifying json. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 17 Feb 2025 23:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74900 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74900@debbugs.gnu.org Cc: jlicht@fsfe.org, d.khodabakhsh@gmail.com Received: via spool by 74900-submit@debbugs.gnu.org id=B74900.173983612428348 (code B ref 74900); Mon, 17 Feb 2025 23:49:02 +0000 Received: (at 74900) by debbugs.gnu.org; 17 Feb 2025 23:48:44 +0000 Received: from localhost ([127.0.0.1]:51168 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tkAqw-0007N1-CR for submit@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:44 -0500 Received: from 9.mo581.mail-out.ovh.net ([46.105.60.248]:35939) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tkAqk-0007LI-RZ for 74900@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:34 -0500 Received: from director10.ghost.mail-out.ovh.net (unknown [10.109.176.96]) by mo581.mail-out.ovh.net (Postfix) with ESMTP id 4YxfVj1jLzz1Q9X for <74900@debbugs.gnu.org>; Mon, 17 Feb 2025 23:48:29 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-xm5dm (unknown [10.111.174.233]) by director10.ghost.mail-out.ovh.net (Postfix) with ESMTPS id A34CD1FD3D; Mon, 17 Feb 2025 23:48:28 +0000 (UTC) Received: from ngraves.fr ([37.59.142.100]) by ghost-submission-5b5ff79f4f-xm5dm with ESMTPSA id 1P4jOsvKs2feQQAA4Ix7sg (envelope-from ); Mon, 17 Feb 2025 23:48:28 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-100R003b120dbd2-b577-477a-8c5a-cec05924fa9b, C3652AECFC9F6A3CBC46B0867312B59102225E78) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.92.117.144 Date: Tue, 18 Feb 2025 00:43:53 +0100 Message-ID: <20250217234823.10533-3-ngraves@ngraves.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250217234823.10533-1-ngraves@ngraves.fr> References: <20250217234823.10533-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 14613336369233126130 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdehleejjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhggtgfgsehtkeertdertdejnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepvdffheegkefhkefggfelheffteeigfegiedtudetkeffhfekheevjeefjeeltdeinecuffhomhgrihhnpehgihhthhhusgdrtghomhenucfkphepuddvjedrtddrtddruddpledtrdelvddruddujedrudeggedpfeejrdehledrudegvddruddttdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjeegledttdesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheekudgmpdhmohguvgepshhmthhpohhuth DKIM-Signature: a=rsa-sha256; bh=g7IuBJxKyT5+GnE8lpgTGQvO0Q3eLBN3GBwas3Et/Hs=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1739836109; v=1; b=Nt+Et+H6pARcK4HJ2qlOMlyFglQ95xoDpuB0oEv4y6nl4hm7MYmq2ltJyQoPDAv/r5BSEINF dwb0v3YPS7bYmbccc8kZmLC5/o/wP7ZaRUFq+olEVW1lULz8KxEk62p3LJ6y9V80SZO7Vw1W2I8 m4PQCMrsj6ILzGdD+0PdCmx3C4wUvk8662Qu5102c/dLo5JXcWCVtPljddnqj/yeVwkK/lpcV/3 Y75cMpkKoHZ016j91gV3CbRZdWHBu5Gfe55/EcgjyTHSmdz/1jkSmDtPdTXOEkj2f1RUYpWwMBY qPcd4Q6B7BY/hH1t7+BP0b9qFtlpqe4HxiIQ1K+I29O+g== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From: Daniel Khodabakhsh Introduce (modify-json), (delete-fields), and (replace-fields) to node-build-system This change introduces helper procedures (modify-json) which takes in lambdas which modify the target json #:file which defaults to package.json This change also includes (delete-fields) and (replace-fields) to help deleting and replacing the value of fields in a package.json file. * guix/build/node-build-system.scm (modify-json, modify-json-fields, delete-fields, replace-fields, delete-dev-dependencies): New API exported procedures. (with-atomic-json-file-replacement, delete-dependencies): Change procedures to adapt to the new API. * gnu/packages/node.scm (node-ms-bootstrap, node-binary-search-bootstrap, node-debug-boostrap, node-llparse-builder-bootstrap, node-llparse-frontend-boostrap, node-llparse-bootstrap): Use new API procedures. * gnu/packages/node-xyz.scm (node-acorn, node-addon-api, node-buffer-crc32, node-crx3, node-debug, node-file-uri-to-path, node-ieee754, node-inherits, node-irc, node-irc-colors, node-minimist, node-ms, node-nan, node-normalize-path, node-once, node-path-key, node-pbf, node-protocol-buffers-schema, node-readable-stream, node-resolve-protobuf-schema, node-safe-buffer, node-safe-stable-stringify, node-semver, node-serialport, node-serialport-bindings, node-serialport-stream, node-sqlite3, node-string-decoder, node-tiddlywiki, node-wrappy, node-yazl): Use new API procedures. Signed-off-by: Daniel Khodabakhsh Change-Id: I957f7ca814078d2136d5261985174820235f1369 --- gnu/packages/node-xyz.scm | 395 ++++++++++++++----------------- gnu/packages/node.scm | 86 +++---- guix/build/node-build-system.scm | 198 +++++++++++++--- 3 files changed, 392 insertions(+), 287 deletions(-) diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm index 84adde9e50..54e3376e4e 100644 --- a/gnu/packages/node-xyz.scm +++ b/gnu/packages/node-xyz.scm @@ -69,18 +69,7 @@ (define-public node-acorn ;; We need to remove the prepare script from "package.json", as ;; it would try to use the build environment and would block the ;; automatic building by other packages making use of node-acorn. - ;; TODO: Add utility function - (with-atomic-json-file-replacement (lambda (pkg-meta-alist) - (map - (match-lambda - (("scripts" . scripts-alist) - (cons "scripts" (filter - (match-lambda - (("prepare" . _) #f) - (_ #t)) - scripts-alist))) - (other other)) - pkg-meta-alist))))) + (modify-json (delete-fields '(("scripts" "prepare")))))) (replace 'build (lambda* (#:key inputs native-inputs #:allow-other-keys) (let ((esbuild (search-input-file (or native-inputs inputs) @@ -136,38 +125,25 @@ (define-public node-addon-api (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies - `("benchmark" - "bindings" - "clang-format" - "eslint" - "eslint-config-semistandard" - "eslint-config-standard" - "eslint-plugin-import" - "eslint-plugin-node" - "eslint-plugin-promise" - "fs-extra" - "neostandard" - "path" - "pre-commit" - "semver")))) - (add-after 'unpack 'skip-js-tests - ;; We can't run the js-based tests, - ;; but we can still do the C++ parts - (lambda args - (define new-test-script - "echo stopping after pretest on Guix") - (with-atomic-json-file-replacement (lambda (pkg-meta-alist) - (map - (match-lambda - (("scripts" . scripts-alist) - (cons "scripts" (map - (match-lambda - (("test" . _) (cons "test" new-test-script)) - (other other)) - scripts-alist))) - (other other)) - pkg-meta-alist)))))))) + (modify-json (delete-dependencies + `("benchmark" + "bindings" + "clang-format" + "eslint" + "eslint-config-semistandard" + "eslint-config-standard" + "eslint-plugin-import" + "eslint-plugin-node" + "eslint-plugin-promise" + "fs-extra" + "neostandard" + "path" + "pre-commit" + "semver")) + ;; We can't run the js-based tests, + ;; but we can still do the C++ parts + (replace-fields (list (cons + "scripts.test" "echo stopping after pretest on Guix"))))))))) (home-page "https://github.com/nodejs/node-addon-api") (synopsis "Node.js API (Node-API) header-only C++ wrappers") (description "This module contains header-only C++ wrapper classes which @@ -232,7 +208,7 @@ (define-public node-buffer-crc32 #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("tap"))))))) + (modify-json (delete-dependencies '("tap")))))))) (home-page "https://github.com/brianloveswords/buffer-crc32") (synopsis "CRC32 implementation in Javascript") (description @@ -288,14 +264,15 @@ (define-public node-crx3 "minimist")))) (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("c8" - "docdash" - "eslint" - "eslint-plugin-jsdoc" - "jsdoc" - "tap-diff" - "tape" - "tape-catch"))))))) + (modify-json (delete-dependencies + '("c8" + "docdash" + "eslint" + "eslint-plugin-jsdoc" + "jsdoc" + "tap-diff" + "tape" + "tape-catch")))))))) (inputs (list node-minimist node-pbf node-yazl)) (home-page "https://github.com/ahwayakchih/crx3") (synopsis "Create CRXv3 browser extensions with Javascript") @@ -325,18 +302,19 @@ (define-public node-debug (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("brfs" - "browserify" - "coveralls" - "istanbul" - "karma" - "karma-browserify" - "karma-chrome-launcher" - "karma-mocha" - "mocha" - "mocha-lcov-reporter" - "xo" - "supports-color"))))) + (modify-json (delete-dependencies + `("brfs" + "browserify" + "coveralls" + "istanbul" + "karma" + "karma-browserify" + "karma-chrome-launcher" + "karma-mocha" + "mocha" + "mocha-lcov-reporter" + "xo" + "supports-color")))))) #:tests? #f)) (home-page "https://github.com/debug-js/debug") (synopsis "Debugging utility for Node.js") @@ -421,21 +399,22 @@ (define-public node-file-uri-to-path (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("@types/mocha" - "@types/node" - "@typescript-eslint/eslint-plugin" - "@typescript-eslint/parser" - "cpy-cli" - "eslint" - "eslint-config-airbnb" - "eslint-config-prettier" - "eslint-import-resolver-typescript" - "eslint-plugin-import" - "eslint-plugin-jsx-a11y" - "eslint-plugin-react" - "mocha" - "rimraf" - "typescript")))) + (modify-json (delete-dependencies + `("@types/mocha" + "@types/node" + "@typescript-eslint/eslint-plugin" + "@typescript-eslint/parser" + "cpy-cli" + "eslint" + "eslint-config-airbnb" + "eslint-config-prettier" + "eslint-import-resolver-typescript" + "eslint-plugin-import" + "eslint-plugin-jsx-a11y" + "eslint-plugin-react" + "mocha" + "rimraf" + "typescript"))))) (replace 'build (lambda* (#:key inputs native-inputs #:allow-other-keys) (copy-recursively "src" "dist") @@ -497,7 +476,9 @@ (define-public node-ieee754 #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("airtap" "standard" "tape"))))))) + (modify-json + (delete-dependencies + '("airtap" "standard" "tape")))))))) (home-page "https://github.com/feross/ieee754") (synopsis "Read/write IEEE754 floating point numbers in Javascript") (description "This package can read and write IEEE754 floating point @@ -524,7 +505,7 @@ (define-public node-inherits (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies '("tap"))))) + (modify-json (delete-dependencies '("tap")))))) ;; FIXME: Tests depend on node-tap #:tests? #f)) (home-page "https://github.com/isaacs/inherits") @@ -553,8 +534,9 @@ (define-public node-irc (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies - `("ansi-color" "faucet" "jscs" "tape"))))) + (modify-json + (delete-dependencies + `("ansi-color" "faucet" "jscs" "tape")))))) #:tests? #f)) (inputs (list node-irc-colors)) @@ -583,7 +565,7 @@ (define-public node-irc-colors (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("istanbul" "vows"))))) + (modify-json (delete-dependencies `("istanbul" "vows")))))) #:tests? #f)) (home-page "https://github.com/fent/irc-colors.js") (synopsis "Node.js module providing color and formatting for IRC") @@ -657,7 +639,8 @@ (define-public node-minimist #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("covert" "tap" "tape"))))))) + (modify-json (delete-dependencies + '("covert" "tap" "tape")))))))) (home-page "https://github.com/substack/minimist") (synopsis "Parse CLI arguments in Javascript") (description "This package can scan for CLI flags and arguments in @@ -683,12 +666,13 @@ (define-public node-ms (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("eslint" - "expect.js" - "husky" - "lint-staged" - "mocha" - "prettier"))))) + (modify-json (delete-dependencies + `("eslint" + "expect.js" + "husky" + "lint-staged" + "mocha" + "prettier")))))) #:tests? #f)) (home-page "https://github.com/vercel/ms") (synopsis "Convert time to milliseconds") @@ -716,14 +700,14 @@ (define-public node-nan (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies - '("bindings" - "commander" - "glob" - "request" - "node-gyp" ;; would be needed for tests - "tap" - "xtend"))))) + (modify-json (delete-dependencies + '("bindings" + "commander" + "glob" + "request" + "node-gyp" ;; would be needed for tests + "tap" + "xtend")))))) ;; tests need tap and other dependencies #:tests? #f)) (inputs @@ -755,7 +739,8 @@ (define-public node-normalize-path #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("gulp-format-md" "mocha"))))))) + (modify-json (delete-dependencies + '("gulp-format-md" "mocha")))))))) (native-inputs (list node-minimist)) (home-page "https://github.com/jonschlinkert/normalize-path") (synopsis "Normalize slashes in a file path") @@ -784,7 +769,7 @@ (define-public node-once (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies '("tap"))))) + (modify-json (delete-dependencies '("tap")))))) ;; FIXME: Tests depend on node-tap #:tests? #f)) (inputs @@ -841,7 +826,9 @@ (define-public node-path-key #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("@types/node" "ava" "tsd" "xo"))))))) + (modify-json + (delete-dependencies + '("@types/node" "ava" "tsd" "xo")))))))) (home-page "https://github.com/sindresorhus/path-key") (synopsis "Cross-platform utility to compute the PATH environment variable key") (description "@code{path-key} provides an implementation to compute the @@ -867,17 +854,17 @@ (define-public node-pbf #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies - '("benchmark" - "browserify" - "eslint" - "eslint-config-mourner" - "mkdirp" - "protobufjs" - "protocol-buffers" - "tap" - "tile-stats-runner" - "uglify-js"))))))) + (modify-json (delete-dependencies + '("benchmark" + "browserify" + "eslint" + "eslint-config-mourner" + "mkdirp" + "protobufjs" + "protocol-buffers" + "tap" + "tile-stats-runner" + "uglify-js")))))))) (inputs (list node-ieee754 node-resolve-protobuf-schema)) (home-page "https://github.com/mapbox/pbf") (synopsis "Decode and encode protocol buffers in Javascript") @@ -908,7 +895,8 @@ (define-public node-protocol-buffers-schema #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("standard" "tape"))))))) + (modify-json (delete-dependencies + '("standard" "tape")))))))) (home-page "https://github.com/mafintosh/protocol-buffers-schema") (synopsis "Protocol buffers schema parser written in Javascript") (description "This package provides a protocol buffers schema parser @@ -935,26 +923,27 @@ (define-public node-readable-stream (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("@babel/cli" - "@babel/core" - "@babel/polyfill" - "@babel/preset-env" - "airtap" - "assert" - "bl" - "deep-strict-equal" - "events.once" - "glob" - "gunzip-maybe" - "hyperquest" - "lolex" - "nyc" - "pump" - "rimraf" - "tap" - "tape" - "tar-fs" - "util-promisify"))))) + (modify-json (delete-dependencies + `("@babel/cli" + "@babel/core" + "@babel/polyfill" + "@babel/preset-env" + "airtap" + "assert" + "bl" + "deep-strict-equal" + "events.once" + "glob" + "gunzip-maybe" + "hyperquest" + "lolex" + "nyc" + "pump" + "rimraf" + "tap" + "tape" + "tar-fs" + "util-promisify")))))) #:tests? #f)) (inputs (list node-util-deprecate node-string-decoder node-inherits)) (home-page "https://github.com/nodejs/readable-stream") @@ -983,7 +972,8 @@ (define-public node-resolve-protobuf-schema #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("standard" "tape"))))))) + (modify-json (delete-dependencies + '("standard" "tape")))))))) (inputs (list node-protocol-buffers-schema)) (home-page "https://github.com/mafintosh/resolve-protobuf-schema") (synopsis "Resolve protobuf imports") @@ -1012,7 +1002,7 @@ (define-public node-safe-buffer (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies '("tape" "standard"))))) + (modify-json (delete-dependencies '("tape" "standard")))))) #:tests? #f)) (home-page "https://github.com/feross/safe-buffer") (synopsis "Buffer creation with explicit semantics") @@ -1040,20 +1030,22 @@ (define-public node-safe-stable-stringify #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("benchmark" "clone" - "fast-json-stable-stringify" - "fast-safe-stringify" - "fast-stable-stringify" - "faster-stable-stringify" - "fastest-stable-stringify" - "json-stable-stringify" - "json-stringify-deterministic" - "json-stringify-safe" - "standard" - "tap" - "typescript" - "@types/node" - "@types/json-stable-stringify"))))))) + (modify-json (delete-dependencies + '("benchmark" + "clone" + "fast-json-stable-stringify" + "fast-safe-stringify" + "fast-stable-stringify" + "faster-stable-stringify" + "fastest-stable-stringify" + "json-stable-stringify" + "json-stringify-deterministic" + "json-stringify-safe" + "standard" + "tap" + "typescript" + "@types/node" + "@types/json-stable-stringify")))))))) (home-page "https://github.com/BridgeAR/safe-stable-stringify") (synopsis "Serialization of javascript objects") (description @@ -1111,7 +1103,7 @@ (define-public node-semver (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies '("tap"))))) + (modify-json (delete-dependencies '("tap")))))) ;; FIXME: Tests depend on node-tap #:tests? #f)) (home-page "https://github.com/npm/node-semver") @@ -1151,7 +1143,8 @@ (define-public node-serialport (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("@serialport/binding-mock")))) + (modify-json (delete-dependencies + `("@serialport/binding-mock"))))) (add-after 'unpack 'chdir (lambda args (chdir "packages/serialport")))) @@ -1210,25 +1203,7 @@ (define-public node-serialport-bindings (chdir "packages/bindings"))) (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("prebuild-install" - ;; devDependencies - "@serialport/binding-mock" - "node-abi")))) - (add-after 'chdir 'avoid-prebuild-install - (lambda args - (with-atomic-json-file-replacement (lambda (pkg-meta-alist) - (map - (match-lambda - (("scripts" . scripts-alist) - (cons "scripts" (filter - (match-lambda - (("install" . _) #f) - (_ #t)) - scripts-alist))) - (("gypfile" . _) - (cons "gypfile" #f)) - (other other)) - pkg-meta-alist)))))) + (modify-json (delete-dependencies `("node-abi")))))) #:tests? #f)) (synopsis "Abstract base class for Node SerialPort bindings") (description "Node SerialPort is a modular suite of Node.js packages for @@ -1409,8 +1384,8 @@ (define-public node-serialport-stream (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `(;; devDependencies - "@serialport/binding-mock")))) + (modify-json + (delete-dependencies `("@serialport/binding-mock"))))) (add-after 'unpack 'chdir (lambda args (chdir "packages/stream")))) @@ -1461,26 +1436,27 @@ (define-public node-sqlite3 (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies - `(;; Normally, this is "built" using @mapbox/node-pre-gyp, - ;; which publishes or downloads pre-built binaries or - ;; falls back to building from source. Here, we patch out - ;; all of that and just build directly. It might be - ;; better to patch a version of @mapbox/node-pre-gyp that - ;; always builds from source, as Debian does, but there - ;; are a number of dependencies that need to be packaged - ;; or removed. - "@mapbox/node-pre-gyp" - "node-pre-gyp" ;; deprecated name still used in some places - "aws-sdk" - "@mapbox/cloudfriend" - ;; Confusingly, this is only a dependency because of - ;; @mapbox/node-pre-gyp: with that removed, - ;; npm will use its own copy: - "node-gyp" - ;; These we'd like, we just don't have them yet: - "eslint" - "mocha")))) + (modify-json + (delete-dependencies + `(;; Normally, this is "built" using @mapbox/node-pre-gyp, + ;; which publishes or downloads pre-built binaries or + ;; falls back to building from source. Here, we patch out + ;; all of that and just build directly. It might be + ;; better to patch a version of @mapbox/node-pre-gyp that + ;; always builds from source, as Debian does, but there + ;; are a number of dependencies that need to be packaged + ;; or removed. + "@mapbox/node-pre-gyp" + "node-pre-gyp" ;; deprecated name still used in some places + "aws-sdk" + "@mapbox/cloudfriend" + ;; Confusingly, this is only a dependency because of + ;; @mapbox/node-pre-gyp: with that removed, + ;; npm will use its own copy: + "node-gyp" + ;; These we'd like, we just don't have them yet: + "eslint" + "mocha"))))) (add-before 'configure 'npm-config-sqlite ;; We need this step even if we do replace @mapbox/node-pre-gyp ;; because the package expects to build its bundled sqlite @@ -1514,8 +1490,9 @@ (define-public node-sqlite3 (substitute* ".npmignore" (("lib/binding") "#lib/binding # <- patched for Guix")) - (with-atomic-json-file-replacement (lambda (pkg-meta-alist) - (let ((binary-alist (assoc-ref pkg-meta-alist "binary"))) + (modify-json + (lambda (pkg-meta-alist) + (let ((binary-alist (assoc-ref pkg-meta-alist "binary"))) ;; When it builds from source, node-pre-gyp supplies ;; module_name and module_path based on the entries under ;; "binary" from "package.json", so this package's @@ -1528,19 +1505,11 @@ (define-public node-sqlite3 (assoc-ref binary-alist "module_name") " module_path=" (assoc-ref binary-alist "module_path")))) + pkg-meta-alist) ;; We need to remove the install script from "package.json", ;; as it would try to use node-pre-gyp and would block the ;; automatic building performed by `npm install`. - (map - (match-lambda - (("scripts" . scripts-alist) - (cons "scripts" (filter - (match-lambda - (("install" . _) #f) - (_ #t)) - scripts-alist))) - (other other)) - pkg-meta-alist)))))))) + (delete-fields `(("scripts" "install"))))))))) (home-page "https://github.com/mapbox/node-sqlite3") (synopsis "Node.js bindings for SQLite3") (description @@ -1623,8 +1592,9 @@ (define-public node-string-decoder (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies - '("tap" "core-util-is" "babel-polyfill"))))) + (modify-json + (delete-dependencies + '("tap" "core-util-is" "babel-polyfill")))))) ;; FIXME: Tests depend on node-tap #:tests? #f)) (inputs (list node-safe-buffer node-inherits)) @@ -1656,7 +1626,8 @@ (define-public node-tiddlywiki (delete 'build) (add-after 'patch-dependencies 'delete-dev-dependencies (lambda _ - (delete-dependencies '("eslint" "@eslint/js"))))))) + (modify-json + (delete-dependencies '("eslint" "@eslint/js")))))))) (home-page "https://github.com/TiddlyWiki/TiddlyWiki5#readme") (synopsis "Non-linear personal web notebook") (description "TiddlyWiki is a unique non-linear notebook for capturing, @@ -1714,7 +1685,7 @@ (define-public node-wrappy (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies '("tap"))))))) + (modify-json (delete-dependencies '("tap")))))))) (home-page "https://github.com/npm/wrappy") (synopsis "Callback wrapping utility") (description "@code{wrappy} is a utility for Node.js to wrap callbacks.") @@ -1739,7 +1710,9 @@ (define-public node-yazl #:phases (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies '("airtap" "bl" "istanbul" "yauzl"))))))) + (modify-json + (delete-dependencies + '("airtap" "bl" "istanbul" "yauzl")))))))) (inputs (list node-buffer-crc32)) (home-page "https://github.com/thejoshwolfe/yazl") (synopsis "Yet another zip library for node") diff --git a/gnu/packages/node.scm b/gnu/packages/node.scm index 75a1a12c53..6d6768e590 100644 --- a/gnu/packages/node.scm +++ b/gnu/packages/node.scm @@ -13,6 +13,7 @@ ;;; Copyright © 2021, 2022 Philip McGrath ;;; Copyright © 2022 Hilton Chain ;;; Copyright © 2024 Efraim Flashner +;;; Copyright © 2024 Daniel Khodabakhsh ;;; ;;; This file is part of GNU Guix. ;;; @@ -366,7 +367,7 @@ (define-public node-semver-bootstrap (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies '("tap"))))))) + (modify-json (delete-dependencies '("tap")))))))) (home-page "https://github.com/npm/node-semver") (properties '((hidden? . #t))) (synopsis "Parses semantic versions strings") @@ -397,11 +398,12 @@ (define-public node-ms-bootstrap (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies '("eslint" - "expect.js" - "husky" - "lint-staged" - "mocha"))))))) + (modify-json (delete-dependencies + '("eslint" + "expect.js" + "husky" + "lint-staged" + "mocha")))))))) (home-page "https://github.com/zeit/ms#readme") (properties '((hidden? . #t))) (synopsis "Tiny millisecond conversion utility") @@ -431,7 +433,7 @@ (define-public node-binary-search-bootstrap (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("chai" "mocha"))))))) + (modify-json (delete-dependencies `("chai" "mocha")))))))) (home-page "https://github.com/darkskyapp/binary-search#readme") (properties '((hidden? . #t))) (synopsis "Tiny binary search function with comparators") @@ -460,17 +462,18 @@ (define-public node-debug-bootstrap (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("brfs" - "browserify" - "coveralls" - "istanbul" - "karma" - "karma-browserify" - "karma-chrome-launcher" - "karma-mocha" - "mocha" - "mocha-lcov-reporter" - "xo"))))))) + (modify-json (delete-dependencies + `("brfs" + "browserify" + "coveralls" + "istanbul" + "karma" + "karma-browserify" + "karma-chrome-launcher" + "karma-mocha" + "mocha" + "mocha-lcov-reporter" + "xo")))))))) (inputs (list node-ms-bootstrap)) (home-page "https://github.com/visionmedia/debug#readme") (properties '((hidden? . #t))) @@ -526,12 +529,13 @@ (define-public node-llparse-builder-bootstrap (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda _ - (delete-dependencies `("@types/mocha" - "@types/node" - "mocha" - "ts-node" - "tslint" - "typescript")))) + (modify-json (delete-dependencies + `("@types/mocha" + "@types/node" + "mocha" + "ts-node" + "tslint" + "typescript"))))) (replace 'build (lambda* (#:key inputs #:allow-other-keys) (let ((esbuild (search-input-file inputs "/bin/esbuild"))) @@ -587,13 +591,14 @@ (define-public node-llparse-frontend-bootstrap (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("@types/debug" - "@types/mocha" - "@types/node" - "mocha" - "ts-node" - "tslint" - "typescript")))) + (modify-json (delete-dependencies + `("@types/debug" + "@types/mocha" + "@types/node" + "mocha" + "ts-node" + "tslint" + "typescript"))))) (replace 'build (lambda* (#:key inputs #:allow-other-keys) (let ((esbuild (search-input-file inputs "/bin/esbuild"))) @@ -648,15 +653,16 @@ (define-public node-llparse-bootstrap (modify-phases %standard-phases (add-after 'patch-dependencies 'delete-dependencies (lambda args - (delete-dependencies `("@types/debug" - "@types/mocha" - "@types/node" - "esm" - "llparse-test-fixture" - "mocha" - "ts-node" - "tslint" - "typescript")))) + (modify-json (delete-dependencies + `("@types/debug" + "@types/mocha" + "@types/node" + "esm" + "llparse-test-fixture" + "mocha" + "ts-node" + "tslint" + "typescript"))))) (replace 'build (lambda* (#:key inputs #:allow-other-keys) (let ((esbuild (search-input-file inputs "/bin/esbuild"))) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index df7ea7774c..ea23d92a05 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -31,18 +31,14 @@ (define-module (guix build node-build-system) #: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 proc - #:optional (file "package.json")) - "Like 'with-atomic-file-replacement', but PROC is called with a single -argument---the result of parsing FILE's contents as json---and should a value -to be written as json to the replacement FILE." - (with-atomic-file-replacement file - (lambda (in out) - (scm->json (proc (json->scm in)) out)))) + delete-dev-dependencies + delete-fields + modify-json + modify-json-fields + node-build + replace-fields + with-atomic-json-file-replacement)) (define* (assoc-ref* alist key #:optional default) "Like assoc-ref, but return DEFAULT instead of #f if no value exists." @@ -72,6 +68,161 @@ (define* (alist-update alist key proc #:optional (= equal?)) (acons key (proc (cdr pair)) rest) alist))) +;;; +;;; package.json modification procedures +;;; + +(define* (with-atomic-json-file-replacement proc + #:optional (file "package.json")) + "Like 'with-atomic-file-replacement', but PROC is called with a single +argument---the result of parsing FILE's contents as json---and should a value +to be written as json to the replacement FILE." + (with-atomic-file-replacement file + (lambda (in out) + (scm->json (proc (json->scm in)) out)))) + +(define* (modify-json #:key (file "package.json") #:rest all-arguments) + "Provide package.json modifying callbacks such as (delete-dependencies ...)" + (let + ( + (modifications + (let loop ((arguments all-arguments)) + (cond + ((null? arguments) '()) + ((keyword? (car arguments)) (loop (cddr arguments))) + (else (cons (car arguments) (loop (cdr arguments)))))))) + (with-atomic-json-file-replacement + (lambda (package) + (fold + (lambda (modification package) + (modification package)) + package + modifications)) + file))) + +(define (delete-dependencies dependencies-to-remove) + "Rewrite 'package.json' to allow the build to proceed without packages +listed in 'dependencies-to-remove', a list of strings naming npm packages. + +To prevent the deleted dependencies from being reintroduced, use this function +only after the 'patch-dependencies' phase." + (lambda (pkg-meta) + (fold + (lambda (dependency-key pkg-meta) + (alist-update + pkg-meta + dependency-key + (lambda (dependencies) + (remove + (lambda (dependency) + (member (car dependency) dependencies-to-remove)) + dependencies)))) + pkg-meta + (list + "devDependencies" + "dependencies" + "peerDependencies" + "optionalDependencies")))) + +(define* (modify-json-fields + fields + field-modifier + #:key + (field-path-mapper (lambda (field) field)) + (insert? #f) + (strict? #t)) + "Provides a lambda to supply to modify-json which modifies the specified + json file. +- `fields` is a list procedure-specific data structures which should include + the definition of a `field-path` in one of two syntaxes: dot-syntax string + such as `\"devDependencies.esbuild\"`, or a list of strings such as + `(list \"devDependencies\" \"esbuild\")`. +- `field-modifier` is a lambda which is invoked at the position of the field. + It is supplied with the current field definition, the association list (alist) + at the field location in the json file, and the field name, also called `key`. +- `field-path-mapper` is a lambda which instructs where the field-path is + located within the field structure. +- `insert?` allows the creation of the field and any missing intermediate + fields. +- `strict?` causes an error to be thrown if the exact field-path is not found + in the data" + (lambda (package) + (fold + (lambda (field package) + (let* + ( + (field-path (field-path-mapper field)) + ( + field-path + (cond + ((string? field-path) + (string-split field-path #\.)) + ((and (list? field-path) (every string? field-path)) + field-path) + (else + (error + (string-append + "Invalid field value provided, expecting a string or a " + "list of string but instead got: " + (with-output-to-string (lambda _ (display field-path)))))) + ))) + (let loop + ( + (data package) + (field-path field-path)) + (let* + ( + (key (car field-path)) + (data + (if (and (not (assoc key data)) insert?) + (acons key '() data) + data))) + (if (not (assoc key data)) + (if strict? + (error (string-append + "Key '" key "' was not found in data: " + (with-output-to-string (lambda _ (display data))))) + data) + (if (= (length field-path) 1) + (field-modifier field data key) + (assoc-set! + data + key + (loop (assoc-ref data key) (cdr field-path))))))))) + package + fields))) + +(define* (delete-fields fields #:key (strict? #t)) + "Provides a lambda to supply to modify-json which deletes the specified + `fields` which is a list of field-paths as mentioned in `modify-json-fields`. + Examples: + (delete-fields '( + (\"path\" \"to\" \"field\") + \"path.to.other.field\"))" + (modify-json-fields + fields + (lambda (_ data key) + (assoc-remove! data key)) + #:strict? strict?)) + +(define* (replace-fields fields #:key (strict? #t)) + "Provides a lambda to supply to modify-json which replaces the value of the + supplied field. `fields` is a list of pairs, where the first element is the + field-path and the second element is the value to replace the target with. + Examples: + (replace-fields '( + ((\"path\" \"to\" \"field\") \"new field value\") + (\"path.to.other.field\" \"new field value\")))" + (modify-json-fields + fields + (lambda (field data key) + (assoc-set! data key (cdr field))) + #:field-path-mapper (lambda (field) (car field)) + #:strict? strict?)) + +(define (delete-dev-dependencies) + (delete-fields (list "devDependencies") #:strict #f)) + ;;; ;;; Phases. ;;; @@ -144,31 +295,6 @@ (define (resolve-dependencies dependencies) (assoc-ref* pkg-meta "dependencies" '()))))))))) #t) -(define (delete-dependencies dependencies-to-remove) - "Rewrite 'package.json' to allow the build to proceed without packages -listed in 'dependencies-to-remove', a list of strings naming npm packages. - -To prevent the deleted dependencies from being reintroduced, use this function -only after the 'patch-dependencies' phase." - (with-atomic-json-file-replacement - (lambda (pkg-meta) - (fold - (lambda (dependency-key pkg-meta) - (alist-update - pkg-meta - dependency-key - (lambda (dependencies) - (remove - (lambda (dependency) - (member (car dependency) dependencies-to-remove)) - dependencies)))) - pkg-meta - (list - "devDependencies" - "dependencies" - "peerDependencies" - "optionalDependencies"))))) - (define* (delete-lockfiles #:key inputs #:allow-other-keys) "Delete 'package-lock.json', 'yarn.lock', and 'npm-shrinkwrap.json', if they exist." From patchwork Mon Feb 17 23:43:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 38803 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3A06E27BBEA; Mon, 17 Feb 2025 23:50:01 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id B9F1827BBE9 for ; Mon, 17 Feb 2025 23:50:00 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkArK-0004ml-Bl; Mon, 17 Feb 2025 18:49:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tkArH-0004mE-Pi for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:03 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkArH-0005EF-H1 for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=NtuTg8z9zba1Fd3x0v+TaQpa8SkpppNgaX0wQ4/eBLo=; b=HoPA4maYcz29Ze9JXx4EHGF3xi0nuPcCvUZIbD405CqKm/yoYit3N+2Cs/CXVHJBtR1klqbGwOVJeuBTOI7y8I2D83iBqwE4oyNM42JI58SsLIM5sdj7dtHQCFV2a3Zm2n0HcFRRd/WIXJ0j22p+Aga9HkHVqgffTVgE5xlfa29DHUMTJarOKqbw5EjahO3mbDBsRAdBRCmj7D33Pw66BqUtBURWCEUz3UrHI85LRKV3bZifXndspBneNBUtrRwKuOGKo+bCyHO4bgd+3GjlVlUuidHAZoRf/lhhTL8wMug9OOr2f8fpi831rIHrI8t1fw0DYsFq7aR0c4k80LSX2Q==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tkArH-0007PJ-Ax for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74900] [PATCH v2 3/6] build-system/node: Add guile-json extension. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 17 Feb 2025 23:49:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74900 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74900@debbugs.gnu.org Cc: Nicolas Graves , jlicht@fsfe.org, d.khodabakhsh@gmail.com Received: via spool by 74900-submit@debbugs.gnu.org id=B74900.173983612528355 (code B ref 74900); Mon, 17 Feb 2025 23:49:03 +0000 Received: (at 74900) by debbugs.gnu.org; 17 Feb 2025 23:48:45 +0000 Received: from localhost ([127.0.0.1]:51170 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tkAqy-0007NB-PB for submit@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:45 -0500 Received: from 20.mo584.mail-out.ovh.net ([46.105.33.73]:58667) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tkAqm-0007LR-CA for 74900@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:34 -0500 Received: from director3.ghost.mail-out.ovh.net (unknown [10.108.9.204]) by mo584.mail-out.ovh.net (Postfix) with ESMTP id 4YxfVk2vm2z1T7y for <74900@debbugs.gnu.org>; Mon, 17 Feb 2025 23:48:30 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-xm5dm (unknown [10.108.54.144]) by director3.ghost.mail-out.ovh.net (Postfix) with ESMTPS id CDAAF1FD86; Mon, 17 Feb 2025 23:48:29 +0000 (UTC) Received: from ngraves.fr ([37.59.142.113]) by ghost-submission-5b5ff79f4f-xm5dm with ESMTPSA id e9u0Ic3Ks2fpQQAA4Ix7sg (envelope-from ); Mon, 17 Feb 2025 23:48:29 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-113S00773bd109f-12d9-4f01-8be9-130c038e1307, C3652AECFC9F6A3CBC46B0867312B59102225E78) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.92.117.144 Date: Tue, 18 Feb 2025 00:43:54 +0100 Message-ID: <20250217234823.10533-4-ngraves@ngraves.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250217234823.10533-1-ngraves@ngraves.fr> References: <20250217234823.10533-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 14613617842806317794 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdehleejjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeelffejteeutefhfeekfffffedvudekjeekgfeludeitdfhkeevhfeivdfhffeggeenucfkphepuddvjedrtddrtddruddpledtrdelvddruddujedrudeggedpfeejrdehledrudegvddruddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjeegledttdesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheekgegmpdhmohguvgepshhmthhpohhuth DKIM-Signature: a=rsa-sha256; bh=NtuTg8z9zba1Fd3x0v+TaQpa8SkpppNgaX0wQ4/eBLo=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1739836110; v=1; b=usQvUBOpuEqvCFXlpjqOP3C7VXZXJkVVAsnv6DUG9MXxT9jEuQDyFWpf0cVbCY6fGH2rdsaI ujQS9XACj8GDK39WezzxiEuFGpcmWrdLhMe6Tjet5hImFSQ4iWq9JC+jgSNlPQYz4rebYo7vvFv 9VQOwI77H/KKUCMzdfiSJCGXTZFx0sess6xFrvDOIa7oAk6NhP2qPc2kc6l/0x82Y4b21+RZbT7 pjOeJXkTMl4VPYfj3qHLk0vDE9x9Jrg96/fsKyCnRCuz1MLwM2EetBpBy2yF8iupeNEjDRa7ghO zUo+4wtIC0ADcweTchGUcficHj/w/HN4d5D1gDYIsb/1Q== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/build-system/node.scm (default-guile-json): New variable. (node-build): Use guile-json extension. --- guix/build-system/node.scm | 39 ++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm index 425b8cd9b3..240336ea35 100644 --- a/guix/build-system/node.scm +++ b/guix/build-system/node.scm @@ -80,6 +80,12 @@ (define private-keywords (build node-build) (arguments (strip-keyword-arguments private-keywords arguments))))) +(define (default-guile-json) + "Return the default guile-json package." + ;; Lazily resolve the binding to avoid a circular dependency. + (let ((mod (resolve-interface '(gnu packages guile)))) + (module-ref mod 'guile-json-4))) + (define* (node-build name inputs #:key source @@ -90,27 +96,28 @@ (define* (node-build name inputs (outputs '("out")) (search-paths '()) (system (%current-system)) - (guile #f) + (guile-json (default-guile-json)) (imported-modules %node-build-system-modules) (modules '((guix build node-build-system) (guix build utils)))) "Build SOURCE using NODE and INPUTS." (define builder - (with-imported-modules imported-modules - #~(begin - (use-modules #$@(sexp->gexp modules)) - (node-build #:name #$name - #:source #+source - #:system #$system - #:npm-flags #$npm-flags - #:test-target #$test-target - #:tests? #$tests? - #:phases #$phases - #:outputs #$(outputs->gexp outputs) - #:search-paths '#$(sexp->gexp - (map search-path-specification->sexp - search-paths)) - #:inputs #$(input-tuples->gexp inputs))))) + (with-extensions (list guile-json) + (with-imported-modules imported-modules + #~(begin + (use-modules #$@(sexp->gexp modules)) + (node-build #:name #$name + #:source #+source + #:system #$system + #:npm-flags #$npm-flags + #:test-target #$test-target + #:tests? #$tests? + #:phases #$phases + #:outputs #$(outputs->gexp outputs) + #:search-paths '#$(sexp->gexp + (map search-path-specification->sexp + search-paths)) + #:inputs #$(input-tuples->gexp inputs)))))) (mlet %store-monad ((guile (package->derivation (or guile (default-guile)) system #:graft? #f))) From patchwork Mon Feb 17 23:43:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 38798 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 83EF527BBEC; Mon, 17 Feb 2025 23:49:26 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id C0B9227BBE2 for ; Mon, 17 Feb 2025 23:49:24 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkArL-0004ng-P4; Mon, 17 Feb 2025 18:49:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tkArJ-0004mc-NI for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:06 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkArI-0005EL-4U for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=N8AvePCbuOFkojv9aw/pzfAUBuaAowRq0NEjTPXSVrg=; b=fBTlDLUVkrnjfSWdB5ZFrJQqNC6GgznuU1irLnmdp22mCM2zLR45oxaX7iaEL6OBUSZH8DM+LK0zKk89rAKv5W396Zw13QbW6NBu0My/jLQpMf/Cl79Bp3kS8sO93+rrTVD7HQTvBhBRrCsNBAtt5a8Oh7LTMV1ky6Tiq3FmjYC5njcnRGCa0RR+CW8VWbeUkx9ZgYBdsIwKpnZuVtMyTYmT8TfzsAsGKSPaLvUpyIluQpZrQVVD3R/N6IJK2lYBJ/24HuoC20g4xtTX7sB97fPw9kyXnt1/AdTT1zEG4RcvyY12uK1R965if9cW+wqDACKv2OQVVSWn+sumEtuFuA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tkArH-0007PT-Vr for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:04 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74900] [PATCH v2 4/6] build-system/node: Use test-target argument. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 17 Feb 2025 23:49:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74900 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74900@debbugs.gnu.org Cc: Nicolas Graves , jlicht@fsfe.org, d.khodabakhsh@gmail.com Received: via spool by 74900-submit@debbugs.gnu.org id=B74900.173983612528361 (code B ref 74900); Mon, 17 Feb 2025 23:49:03 +0000 Received: (at 74900) by debbugs.gnu.org; 17 Feb 2025 23:48:45 +0000 Received: from localhost ([127.0.0.1]:51172 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tkAqz-0007NI-6L for submit@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:45 -0500 Received: from 3.mo576.mail-out.ovh.net ([188.165.52.203]:46045) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tkAqn-0007LW-Qu for 74900@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:35 -0500 Received: from director6.ghost.mail-out.ovh.net (unknown [10.109.176.110]) by mo576.mail-out.ovh.net (Postfix) with ESMTP id 4YxfVm0ccJz1wKg for <74900@debbugs.gnu.org>; Mon, 17 Feb 2025 23:48:32 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-89r4f (unknown [10.110.168.204]) by director6.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 38CA81FDE9; Mon, 17 Feb 2025 23:48:30 +0000 (UTC) Received: from ngraves.fr ([37.59.142.113]) by ghost-submission-5b5ff79f4f-89r4f with ESMTPSA id Q+giJ87Ks2eVGyYAyjHCiA (envelope-from ); Mon, 17 Feb 2025 23:48:30 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-113S0070a72963e-8c81-4bdf-b639-d38630f67a1f, C3652AECFC9F6A3CBC46B0867312B59102225E78) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.92.117.144 Date: Tue, 18 Feb 2025 00:43:55 +0100 Message-ID: <20250217234823.10533-5-ngraves@ngraves.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250217234823.10533-1-ngraves@ngraves.fr> References: <20250217234823.10533-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 14614180794634592994 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdehleejjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeelffejteeutefhfeekfffffedvudekjeekgfeludeitdfhkeevhfeivdfhffeggeenucfkphepuddvjedrtddrtddruddpledtrdelvddruddujedrudeggedpfeejrdehledrudegvddruddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjeegledttdesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheejiegmpdhmohguvgepshhmthhpohhuth DKIM-Signature: a=rsa-sha256; bh=N8AvePCbuOFkojv9aw/pzfAUBuaAowRq0NEjTPXSVrg=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1739836112; v=1; b=iHlfBS7Y92/fTruW9b3M2xuCrzDM0yJQpLp+dy+h58a3JGjqWut94VTo65F/+hb0oG0oSlb/ uU28capmUcaSuRbzqZjBlSK5kmy6WFiK0MPRMVnkUJKxO2m3eVllCcGF+CUVNALfKlNxjRp9cmL 1+Sc22wu8icGNAGnLBw+ieS2LYQN2/jP7JUvQQT7sy+oR2wwgWrujt5U40Bj5FDtASkWdjfUm5c xtPPi6r5RUmLaTye8LcDtTvQBWrrG0ItwNSrLWSnEU/zyZW284Z0PgZeoKVaBdBkhRmWrp93/eI 9pgeAYgIEvH75TVj0v5yPsdZSt7LGyDaouW95FX4h3Xcw== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/build/node-build-system.scm (check): Use test-target argument. --- guix/build/node-build-system.scm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index ea23d92a05..9967069458 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -319,13 +319,12 @@ (define* (build #:key inputs #:allow-other-keys) (format #t "there is no build script to run~%")) #t)) -(define* (check #:key tests? inputs #:allow-other-keys) - "Run 'npm test' if TESTS?" +(define* (check #:key tests? inputs test-target #:allow-other-keys) + "Run 'npm run TEST-TARGET' if TESTS?" (if tests? (let ((npm (string-append (assoc-ref inputs "node") "/bin/npm"))) - (invoke npm "test")) - (format #t "test suite not run~%")) - #t) + (invoke npm "run" test-target)) + (format #t "test suite not run~%"))) (define* (repack #:key inputs #:allow-other-keys) (invoke "tar" From patchwork Mon Feb 17 23:43:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 38802 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5361727BBEA; Mon, 17 Feb 2025 23:49:59 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id CAF9827BBE2 for ; Mon, 17 Feb 2025 23:49:58 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkArM-0004o9-IH; Mon, 17 Feb 2025 18:49:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tkArJ-0004me-O3 for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:06 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkArJ-0005EN-EE for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=gkTexoAelNKp2uQ9cGmW5wSEeFpaj1pbgaaqcbZZLkE=; b=XqTobgD8Y0OcIyAa+MlmaNR5llEhbceRMOdWQls3g+i4f4oX2s2dcViAzPYgk+/m/YW1/DSDo0JjR0fA+Keg2gDdDT/pOEfJmCeUNXbNnkBIHgI9GUa31Vun+guBKTwFhcN8FygH8ClIpQGGBoohn7v0BQkfLD5rSV7qGniD/2bHh0yNgg08/TE4EGwb3ncwbScK7WjK1oWaoHnxLZQAyM1SBV0TfDIwnuAAb7y+C7Zs1SLw1lx/a+E+i45pa7MHMYZ4JF4eTET+tldacT1qUhJyTpARy6bMQbKAt5ack50vJGD4yn/3cQPsLr34NMPgUBqSVTYNSRkB/pkhNnaIhQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tkArJ-0007Pn-7n for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74900] [PATCH v2 5/6] build-system/tree-sitter: Switch to (json). Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 17 Feb 2025 23:49:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74900 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74900@debbugs.gnu.org Cc: Nicolas Graves , jlicht@fsfe.org, d.khodabakhsh@gmail.com Received: via spool by 74900-submit@debbugs.gnu.org id=B74900.173983613628417 (code B ref 74900); Mon, 17 Feb 2025 23:49:05 +0000 Received: (at 74900) by debbugs.gnu.org; 17 Feb 2025 23:48:56 +0000 Received: from localhost ([127.0.0.1]:51177 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tkAr9-0007O7-Di for submit@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:56 -0500 Received: from 8.mo576.mail-out.ovh.net ([46.105.56.233]:34287) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tkAqo-0007Lg-OS for 74900@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:36 -0500 Received: from director1.ghost.mail-out.ovh.net (unknown [10.109.148.6]) by mo576.mail-out.ovh.net (Postfix) with ESMTP id 4YxfVn1FQ5z1wMX for <74900@debbugs.gnu.org>; Mon, 17 Feb 2025 23:48:33 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-k5f24 (unknown [10.110.164.228]) by director1.ghost.mail-out.ovh.net (Postfix) with ESMTPS id BB80A1FD7F; Mon, 17 Feb 2025 23:48:32 +0000 (UTC) Received: from ngraves.fr ([37.59.142.107]) by ghost-submission-5b5ff79f4f-k5f24 with ESMTPSA id g4HbJdDKs2cshh8AqZ2JJA (envelope-from ); Mon, 17 Feb 2025 23:48:32 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-107S001153f58b5-a54d-4e93-90e4-4bb217cbff00, C3652AECFC9F6A3CBC46B0867312B59102225E78) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.92.117.144 Date: Tue, 18 Feb 2025 00:43:56 +0100 Message-ID: <20250217234823.10533-6-ngraves@ngraves.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250217234823.10533-1-ngraves@ngraves.fr> References: <20250217234823.10533-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 14614462266034807522 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdehleejjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeelffejteeutefhfeekfffffedvudekjeekgfeludeitdfhkeevhfeivdfhffeggeenucfkphepuddvjedrtddrtddruddpledtrdelvddruddujedrudeggedpfeejrdehledrudegvddruddtjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjeegledttdesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheejiegmpdhmohguvgepshhmthhpohhuth DKIM-Signature: a=rsa-sha256; bh=gkTexoAelNKp2uQ9cGmW5wSEeFpaj1pbgaaqcbZZLkE=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1739836113; v=1; b=2ezXZOYVWxAIPbf8TG1IBiel3X5RcFNswIK1ymVrpAmZnJD/P7sjg6EX7Hfzyt7V372N0jxO GEDeIuGoiUJwM1Qnbde0VmHwCD7eoXIARKxsLPAAdedKLrHSSM0SIFdmoNSPwh/Ik9TKKVNBBgr GV5UZ+DAK4bp9Fuxh0zXtgHcJBEGIVSsf6YgicQ/7PFZpmtnmA/4z25r52YFBH+nv/8sUOPqtFY ANeyOptI3CMe1P3tOGuGyOKC3Ltt9Qp42cRdwSbJzXeFfB67Gi+TNSaA7hjt9ixYVwB7uFdOmZl vSCsSLqWFZ2HwxXHMKHxJpFWHbp1wjmIN3ZuOCaQqlpBw== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/build/tree-sitter-build-system.scm (patch-dependencies, install): Switch from (guix build json) to (json). --- guix/build/tree-sitter-build-system.scm | 44 +++++++++++-------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/guix/build/tree-sitter-build-system.scm b/guix/build/tree-sitter-build-system.scm index 4106728bdf..1fe2601dd7 100644 --- a/guix/build/tree-sitter-build-system.scm +++ b/guix/build/tree-sitter-build-system.scm @@ -18,10 +18,10 @@ (define-module (guix build tree-sitter-build-system) #:use-module ((guix build node-build-system) #:prefix node:) - #:use-module (guix build json) #:use-module (guix build utils) #:use-module (ice-9 match) #:use-module (ice-9 regex) + #:use-module (json) #:use-module (srfi srfi-1) #:export (%standard-phases tree-sitter-build)) @@ -47,28 +47,24 @@ (define* (patch-dependencies #:key inputs #:allow-other-keys) "Rewrite dependencies in 'package.json'. We remove all runtime dependencies and replace development dependencies with tree-sitter grammar node modules." - (define (rewrite package.json) - (map (match-lambda - (("dependencies" @ . _) - '("dependencies" @)) - (("devDependencies" @ . _) - `("devDependencies" @ - ,@(filter-map (match-lambda - ((key . directory) - (let ((node-module - (string-append directory - "/lib/node_modules/" - key))) - (and (directory-exists? node-module) - `(,key . ,node-module))))) - (alist-delete "node" inputs)))) - (other other)) - package.json)) - - (node:with-atomic-json-file-replacement "package.json" - (match-lambda - (('@ . package.json) - (cons '@ (rewrite package.json)))))) + (node:with-atomic-json-file-replacement + (lambda (pkg-meta-alist) + (map (match-lambda + (("dependencies" dependencies ...) + '("dependencies")) + (("devDependencies" dev-dependencies ...) + `("devDependencies" + ,@(filter-map (match-lambda + ((key . directory) + (let ((node-module + (string-append directory + "/lib/node_modules/" + key))) + (and (directory-exists? node-module) + `(,key . ,node-module))))) + (alist-delete "node" inputs)))) + (other other)) + pkg-meta-alist)))) ;; FIXME: The node build-system's configure phase does not support ;; cross-compiling so we re-define it. @@ -99,7 +95,7 @@ (define* (install #:key target grammar-directories outputs #:allow-other-keys) (define (compile-language dir) (with-directory-excursion dir (let ((lang (assoc-ref (call-with-input-file "src/grammar.json" - read-json) + json->scm) "name")) (source-file (lambda (path) (if (file-exists? path) From patchwork Mon Feb 17 23:43:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 38801 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 1A6F627BBEA; Mon, 17 Feb 2025 23:49:40 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8549A27BBE2 for ; Mon, 17 Feb 2025 23:49:39 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tkArN-0004oU-Sm; Mon, 17 Feb 2025 18:49:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tkArK-0004nH-GI for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:06 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tkArK-0005Eb-6l for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=Vra8WAq1j6qzaPMCDbbdU2NdjSAblGFPm6cIzgyzoZU=; b=uPZAD4vmCUIwSLfCVqos2YozZV261+lic7euovcnbc4F1QYTVFswkoVOv/5ivJr+pP207YA96C06JFSDdDghfYwfFELbZ/4CpK6h2Q+Dc8vaj+6qeJ2uNgtd176mWYmBJZpP8KtKabYvzIk4KX/Gw3kvmXKbx+QYFIxPbHO0pyqKAqyH7E85wdvJwdjx44xXXSu0Vt28sulu8e+O24nPbgNyFismLUyG9eLxFM/6QzI/ye4ij34XF7d1Cu0PJVFVmjAO1+1O7Ejs1Trllt5t46slmqX8Ww6hFTIZ1LIF95r9c7k3U5K5Ex7/YERg+imP6irb48XOjTFxH/pPUNUlHw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tkArJ-0007Q0-Vr for guix-patches@gnu.org; Mon, 17 Feb 2025 18:49:06 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74900] [PATCH v2 6/6] build-system/tree-sitter: Add guile-json extension. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 17 Feb 2025 23:49:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74900 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74900@debbugs.gnu.org Cc: Nicolas Graves , jlicht@fsfe.org, d.khodabakhsh@gmail.com Received: via spool by 74900-submit@debbugs.gnu.org id=B74900.173983613728426 (code B ref 74900); Mon, 17 Feb 2025 23:49:05 +0000 Received: (at 74900) by debbugs.gnu.org; 17 Feb 2025 23:48:57 +0000 Received: from localhost ([127.0.0.1]:51179 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tkArA-0007OI-CH for submit@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:57 -0500 Received: from 15.mo584.mail-out.ovh.net ([91.121.62.11]:41615) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tkAqp-0007Lk-Nk for 74900@debbugs.gnu.org; Mon, 17 Feb 2025 18:48:37 -0500 Received: from director3.ghost.mail-out.ovh.net (unknown [10.109.176.110]) by mo584.mail-out.ovh.net (Postfix) with ESMTP id 4YxfVp0Sfdz1T8H for <74900@debbugs.gnu.org>; Mon, 17 Feb 2025 23:48:34 +0000 (UTC) Received: from ghost-submission-5b5ff79f4f-6drgp (unknown [10.110.168.167]) by director3.ghost.mail-out.ovh.net (Postfix) with ESMTPS id BA2391FE07; Mon, 17 Feb 2025 23:48:33 +0000 (UTC) Received: from ngraves.fr ([37.59.142.114]) by ghost-submission-5b5ff79f4f-6drgp with ESMTPSA id oyuPJdHKs2dLKwUA2IquHA (envelope-from ); Mon, 17 Feb 2025 23:48:33 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-114S008c8064da6-5d25-4593-afdc-bd86a47d139d, C3652AECFC9F6A3CBC46B0867312B59102225E78) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.92.117.144 Date: Tue, 18 Feb 2025 00:43:57 +0100 Message-ID: <20250217234823.10533-7-ngraves@ngraves.fr> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250217234823.10533-1-ngraves@ngraves.fr> References: <20250217234823.10533-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 14614743743081079522 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdehleejjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecunecujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeelffejteeutefhfeekfffffedvudekjeekgfeludeitdfhkeevhfeivdfhffeggeenucfkphepuddvjedrtddrtddruddpledtrdelvddruddujedrudeggedpfeejrdehledrudegvddruddugeenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepnhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrpdhnsggprhgtphhtthhopedupdhrtghpthhtohepjeegledttdesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheekgegmpdhmohguvgepshhmthhpohhuth DKIM-Signature: a=rsa-sha256; bh=Vra8WAq1j6qzaPMCDbbdU2NdjSAblGFPm6cIzgyzoZU=; c=relaxed/relaxed; d=ngraves.fr; h=From; s=ovhmo4487190-selector1; t=1739836114; v=1; b=U+mzLTnOxb7mKVGNy+box/KhYELm/cL5qb2uRnLSpajniOKkm1HwubkSHkTTlqI6WbDxE5SK QGhteFSw/ZphXAnk7izCbjqF3vOkNB3wWnsKTHmYm/Je/nCSQArluy/l8I1O/5xpzbnbK3GoBAz VS2iyemFllO/kJjdjz94YnSHKb+dle1ZFC19OIQvYlaUiz3x29hvzLr6Ml1ASrz9osTCfog/Ol7 7f+5RUW4dJ8iPnycVi8zrEocCohvvT70cxFB1HRCfdOCtogO+lEHNhfKokMcP8x0etFV+yzxN0V /Ur1MuF4QBIxL1qEhIAAYhsk9WweAr5IlQgIuni39E2IQ== X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/build-system/tree-sitter.scm (default-guile-json): New variable. (tree-sitter-cross-build, tree-sitter-build): Use guile-json extension. --- guix/build-system/tree-sitter.scm | 101 ++++++++++++++++-------------- 1 file changed, 55 insertions(+), 46 deletions(-) diff --git a/guix/build-system/tree-sitter.scm b/guix/build-system/tree-sitter.scm index 21c4eb35b2..f59a255307 100644 --- a/guix/build-system/tree-sitter.scm +++ b/guix/build-system/tree-sitter.scm @@ -36,6 +36,12 @@ (define %tree-sitter-build-system-modules `((guix build tree-sitter-build-system) ,@%node-build-system-modules)) +(define (default-guile-json) + "Return the default guile-json package." + ;; Lazily resolve the binding to avoid a circular dependency. + (let ((mod (resolve-interface '(gnu packages guile)))) + (module-ref mod 'guile-json-4))) + (define* (lower name #:key source inputs native-inputs outputs system target #:allow-other-keys @@ -98,26 +104,27 @@ (define* (tree-sitter-build name inputs (outputs '("out" "js")) (search-paths '()) (system (%current-system)) - (guile #f) + (guile-json (default-guile-json)) (imported-modules %tree-sitter-build-system-modules) (modules '((guix build utils) (guix build tree-sitter-build-system)))) (define builder - (with-imported-modules imported-modules - #~(begin - (use-modules #$@(sexp->gexp modules)) - (tree-sitter-build #:name #$name - #:source #+source - #:system #$system - #:phases #$phases - #:tests? #$tests? - #:grammar-directories '#$grammar-directories - #:outputs #$(outputs->gexp outputs) - #:search-paths - '#$(sexp->gexp - (map search-path-specification->sexp - search-paths)) - #:inputs #$(input-tuples->gexp inputs))))) + (with-extensions (list guile-json) + (with-imported-modules imported-modules + #~(begin + (use-modules #$@(sexp->gexp modules)) + (tree-sitter-build #:name #$name + #:source #+source + #:system #$system + #:phases #$phases + #:tests? #$tests? + #:grammar-directories '#$grammar-directories + #:outputs #$(outputs->gexp outputs) + #:search-paths + '#$(sexp->gexp + (map search-path-specification->sexp + search-paths)) + #:inputs #$(input-tuples->gexp inputs)))))) (mlet %store-monad ((guile (package->derivation (or guile (default-guile)) system #:graft? #f))) @@ -137,6 +144,7 @@ (define* (tree-sitter-cross-build name (search-paths '()) (native-search-paths '()) (system (%current-system)) + (guile-json (default-guile-json)) (build (nix-system->gnu-triplet system)) (imported-modules %tree-sitter-build-system-modules) @@ -144,40 +152,41 @@ (define* (tree-sitter-cross-build name '((guix build utils) (guix build tree-sitter-build-system)))) (define builder - (with-imported-modules imported-modules - #~(begin - (use-modules #$@(sexp->gexp modules)) + (with-extensions (list guile-json) + (with-imported-modules imported-modules + #~(begin + (use-modules #$@(sexp->gexp modules)) - (define %build-host-inputs - #+(input-tuples->gexp build-inputs)) + (define %build-host-inputs + #+(input-tuples->gexp build-inputs)) - (define %build-target-inputs - (append #$(input-tuples->gexp host-inputs) - #+(input-tuples->gexp target-inputs))) + (define %build-target-inputs + (append #$(input-tuples->gexp host-inputs) + #+(input-tuples->gexp target-inputs))) - (define %build-inputs - (append %build-host-inputs %build-target-inputs)) + (define %build-inputs + (append %build-host-inputs %build-target-inputs)) - (tree-sitter-build #:name #$name - #:source #+source - #:system #$system - #:build #$build - #:target #$target - #:phases #$phases - #:tests? #$tests? - #:grammar-directories '#$grammar-directories - #:outputs #$(outputs->gexp outputs) - #:inputs %build-target-inputs - #:native-inputs %build-host-inputs - #:search-paths ' - #$(sexp->gexp - (map search-path-specification->sexp - search-paths)) - #:native-search-paths - '#$(sexp->gexp - (map - search-path-specification->sexp - native-search-paths)))))) + (tree-sitter-build #:name #$name + #:source #+source + #:system #$system + #:build #$build + #:target #$target + #:phases #$phases + #:tests? #$tests? + #:grammar-directories '#$grammar-directories + #:outputs #$(outputs->gexp outputs) + #:inputs %build-target-inputs + #:native-inputs %build-host-inputs + #:search-paths ' + #$(sexp->gexp + (map search-path-specification->sexp + search-paths)) + #:native-search-paths + '#$(sexp->gexp + (map + search-path-specification->sexp + native-search-paths))))))) (mlet %store-monad ((guile (package->derivation (or guile (default-guile)) system #:graft? #f)))