From patchwork Sat Nov 20 04:33:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 34675 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 40A9C27BBE5; Sat, 20 Nov 2021 04:35:23 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8E86B27BBE3 for ; Sat, 20 Nov 2021 04:35:22 +0000 (GMT) Received: from localhost ([::1]:34520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1moI5x-0002Kj-Lx for patchwork@mira.cbaines.net; Fri, 19 Nov 2021 23:35:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1moI5g-0002J2-UL for guix-patches@gnu.org; Fri, 19 Nov 2021 23:35:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:57919) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1moI5f-0007OZ-H0 for guix-patches@gnu.org; Fri, 19 Nov 2021 23:35:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1moI5f-0007xE-E7; Fri, 19 Nov 2021 23:35:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v2 05/26] guix: node-build-system: Add #:absent-dependencies argument. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: liliana.prikler@gmail.com, guix-patches@gnu.org Resent-Date: Sat, 20 Nov 2021 04:35:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51838 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 51838@debbugs.gnu.org Cc: Liliana Marie Prikler X-Debbugs-Original-Xcc: Liliana Marie Prikler Received: via spool by 51838-submit@debbugs.gnu.org id=B51838.163738286130265 (code B ref 51838); Sat, 20 Nov 2021 04:35:03 +0000 Received: (at 51838) by debbugs.gnu.org; 20 Nov 2021 04:34:21 +0000 Received: from localhost ([127.0.0.1]:41174 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1moI4z-0007rt-67 for submit@debbugs.gnu.org; Fri, 19 Nov 2021 23:34:21 -0500 Received: from mail-qt1-f181.google.com ([209.85.160.181]:35708) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1moI4v-0007qb-AU for 51838@debbugs.gnu.org; Fri, 19 Nov 2021 23:34:17 -0500 Received: by mail-qt1-f181.google.com with SMTP id j17so11453011qtx.2 for <51838@debbugs.gnu.org>; Fri, 19 Nov 2021 20:34:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philipmcgrath.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=rFhMeClAh1FA9n4bk9oFR9mta1Ty4XRgs6HxE0DL8BU=; b=XtSL6lqyu4d5CYAsRg62nSMO6LPG8C2L8D0cAItuEaGZ2x9LaM0m4Mib1KvW3L8GKV w4Y6s9lW6MRAF1vtl1ZzpllcYbHKLGO5pCV+7GwJdi9d6EJ70dGxbOb/UGTGmcjd5myE NDmgbT6rYCjL8oBrx3ExMcAy9/0ORy9b59fwdtNN/sk4c//JLKD8Ya4jEB2fpW/+LFjy NI7JKJN1awBv09PLZTmUHL5aaTAnnm0/NlqwoI7N141gj0r6jzROVXGbZ5POQlTl5zE5 K+IWaADTdqh1Ggb2NKC+RXhy+Ba7mKqiV6vA0bWGMf+lh74Yv+6MLWSYk4b0Wu1mUsdN CZtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rFhMeClAh1FA9n4bk9oFR9mta1Ty4XRgs6HxE0DL8BU=; b=u5UhZ7EZoozhb/X4wGz6Hk8rD3a+AtA5ugwoqFryXNXTr2a+ugWJdTTrVAXkn/o9qF lgyATkc2XLEbvy+BevE7YJGsHwaQ0mBHV6xzZNvZmebUKPfa5K1bHy/Qqa/4T1lgXM71 EjffeC+0i/AsB+bRSRFejuFXC1HfO4zlrOeFs5e8hb2dqPcjDLcu2Gc3AdWN7bDax4aQ vHdpoi0HUkf18R82NTqCqxM/9XNr8SMydIF/tF/4HF+eUfST0RPqca8hA2pccAg31D1k VSKiXZkfdhmjPuIA3kV0nfCs8FdV+bknrOepwaDTfGBDt2lNP7qwng+CdJNIutwJoyku oDQg== X-Gm-Message-State: AOAM531AVXerKPs5cbeCBlMAn0+czE4V0rzx3YzvKL/P7haVhOlPobXc Jhaz/qvHWPfDP2mcT8F85UiVwiwXZtpf7dy7 X-Google-Smtp-Source: ABdhPJw/hOZ8j2dV2l9gXXQjHfNeD1FMQKwMs6Jp4T218VixB47vBD860W1r6wAu1j3QVR+N6MjmdA== X-Received: by 2002:ac8:7f09:: with SMTP id f9mr1696728qtk.163.1637382851670; Fri, 19 Nov 2021 20:34:11 -0800 (PST) Received: from localhost (c-73-125-89-242.hsd1.fl.comcast.net. [73.125.89.242]) by smtp.gmail.com with ESMTPSA id u10sm996300qtx.3.2021.11.19.20.34.11 for <51838@debbugs.gnu.org> (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Nov 2021 20:34:11 -0800 (PST) From: Philip McGrath Date: Fri, 19 Nov 2021 23:33:45 -0500 Message-Id: <20211120043406.952350-5-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211120043406.952350-1-philip@philipmcgrath.com> References: <5a04aa92-e80d-e11b-235c-b7f5e3a92d00@philipmcgrath.com> <20211120043406.952350-1-philip@philipmcgrath.com> MIME-Version: 1.0 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: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Many of Guix's Node.js packages are built without some of the dependencies they specify in their "package-lock.json" files, either because we don't have them packaged yet (e.g. test utilities) or because we don't want them (e.g. to reduce the closure size). Previously, Guix package definitions would work around this situation by deleting the `'configure` phase (i.e. the initial `npm install`). This commit adds an optional #:absent-dependencies argument to `node-build-system` to list Node.js packages that should be removed from the "package.json" file.Retaining the `'configure` phase avoids skipping checks for the dependencies that are intended to be present and other actions performed by `npm install`, such as automatically building native add-ons with `node-gyp` when the "gypfile" key is present. * guix/build-system/node.scm (lower, node-build): Add optional argument #:absent-dependencies with default of ''(). Pass it on to the build-side code. * guix/build/node-build-system.scm (patch-dependencies): Respect the #:absent-dependencies argument, removing specified npm packages from the "dependencies" or "devDependencies" tables in "package.json". Also, strictly follow the linearity rules for `assoc-set!` and friends. --- guix/build-system/node.scm | 3 ++ guix/build/node-build-system.scm | 55 ++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm index 98f63f87ef..75ae34508f 100644 --- a/guix/build-system/node.scm +++ b/guix/build-system/node.scm @@ -44,6 +44,7 @@ (define (default-node) (define* (lower name #:key source inputs native-inputs outputs system target (node (default-node)) + (absent-dependencies ''()) #:allow-other-keys #:rest arguments) "Return a bag for NAME." @@ -73,6 +74,7 @@ (define* (node-build store name inputs (tests? #t) (phases '(@ (guix build node-build-system) %standard-phases)) + (absent-dependencies ''()) (outputs '("out")) (search-paths '()) (system (%current-system)) @@ -94,6 +96,7 @@ (define builder #:test-target ,test-target #:tests? ,tests? #:phases ,phases + #:absent-dependencies ,absent-dependencies #:outputs %outputs #:search-paths ',(map search-path-specification->sexp search-paths) diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index 70a367618e..32d6807e3e 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -69,30 +69,51 @@ (define (list-modules directory) input-paths) index)) -(define* (patch-dependencies #:key inputs #:allow-other-keys) +(define* (patch-dependencies #:key inputs absent-dependencies + #:allow-other-keys) (define index (index-modules (map cdr inputs))) - (define (resolve-dependencies package-meta meta-key) - (fold (lambda (key+value acc) - (match key+value - ('@ acc) - ((key . value) (acons key (hash-ref index key value) acc)))) + (define (resolve-dependencies meta-alist meta-key) + (match (assoc-ref meta-alist meta-key) + (#f + '()) + (('@ . orig-deps) + (fold (match-lambda* + (('@ acc) + acc) + (((key . value) acc) + (if (member key absent-dependencies) + acc + (acons key (hash-ref index key value) acc)))) '() - (or (assoc-ref package-meta meta-key) '()))) + orig-deps)))) (with-atomic-file-replacement "package.json" (lambda (in out) - (let ((package-meta (read-json in))) - (assoc-set! package-meta "dependencies" - (append - '(@) - (resolve-dependencies package-meta "dependencies") - (resolve-dependencies package-meta "peerDependencies"))) - (assoc-set! package-meta "devDependencies" - (append - '(@) - (resolve-dependencies package-meta "devDependencies"))) + ;; It is unsafe to rely on 'assoc-set!' to update an + ;; existing assosciation list variable: + ;; see 'info "(guile)Adding or Setting Alist Entries"'. + (let* ((package-meta (read-json in)) + (alist (match package-meta + ((@ . alist) alist))) + ;; Other relevant keys may include peerDependenciesMeta + ;; and optionalDependencies, but it seems to work out fine + ;; just to leave those alone. + (alist + (assoc-set! + alist "dependencies" + (append + '(@) + (resolve-dependencies alist "dependencies") + (resolve-dependencies alist "peerDependencies")))) + (alist + (assoc-set! + alist "devDependencies" + (append + '(@) + (resolve-dependencies alist "devDependencies")))) + (package-meta (cons '@ alist))) (write-json package-meta out)))) #t)