From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id SJbvJypkzWEJzAAAgWs5BA (envelope-from ) for ; Thu, 30 Dec 2021 08:47:54 +0100 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 4AZ8JCpkzWEytQAAauVa8A (envelope-from ) for ; Thu, 30 Dec 2021 08:47:54 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx2.migadu.com (Postfix) with ESMTPS id 243C41E97C for ; Thu, 30 Dec 2021 08:47:54 +0100 (CET) Received: from localhost ([::1]:33058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2qAD-0004xB-88 for larch@yhetil.org; Thu, 30 Dec 2021 02:47:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2q9S-0004BF-AA for guix-patches@gnu.org; Thu, 30 Dec 2021 02:47:10 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:39606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n2q9R-0005sY-KZ for guix-patches@gnu.org; Thu, 30 Dec 2021 02:47:06 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n2q9R-0006ur-K5 for guix-patches@gnu.org; Thu, 30 Dec 2021 02:47:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51838] [PATCH v7 05/41] guix: node-build-system: Add #:absent-dependencies argument. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 30 Dec 2021 07:47:05 +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: Timothy Sample , Pierre Langlois , Jelle Licht , Philip McGrath , Liliana Marie Prikler Received: via spool by 51838-submit@debbugs.gnu.org id=B51838.164085041926495 (code B ref 51838); Thu, 30 Dec 2021 07:47:05 +0000 Received: (at 51838) by debbugs.gnu.org; 30 Dec 2021 07:46:59 +0000 Received: from localhost ([127.0.0.1]:51139 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n2q9K-0006sy-80 for submit@debbugs.gnu.org; Thu, 30 Dec 2021 02:46:59 -0500 Received: from mail-qv1-f52.google.com ([209.85.219.52]:36656) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n2q8N-0006oo-8S for 51838@debbugs.gnu.org; Thu, 30 Dec 2021 02:45:59 -0500 Received: by mail-qv1-f52.google.com with SMTP id kc16so21435138qvb.3 for <51838@debbugs.gnu.org>; Wed, 29 Dec 2021 23:45:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philipmcgrath.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YpY7I9/3vwIWnWFMsbMmcXC+bzQZOgggVRQdn95z9Rc=; b=R8JBsdflN8ugHukF4Bq53vGLEFUeE4Y7kZFrMsp+ekqXj6C7XCTaOqlVUtncTn9Sm6 v7iVF/03Ssm6hDRip8aZlufa6zH4fPXdIpbMuj9Wi+eoxS1hW2NdGA5m7oi0SJRX5Wn0 z67OVCvvlLGwzhsh0uN3i/4MzvX39yUqjvdxZDz1Z07N7KiFyODsUQMI1Ihe396QIm7l 5tjObqs5jjAwzn79FMPtJkd4dp8rS0O9hbPTdJWdIpcEDEmo3pcpal0SwfmYnqirraLm 6BOkA1y3Fl2QRUwVorZtv4wDbQFLaiLO7pJMhEt3FMUS5zF5bQQt4Prr+2eZEsHew7bX 5hfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YpY7I9/3vwIWnWFMsbMmcXC+bzQZOgggVRQdn95z9Rc=; b=bf+aVQT0k1QNvVX5d6SmgR8MZ+iWkkDyGMICcJyOoOOdhOst3gilQ+u8GCS8od+A5q CRlBHM5JQdeVc71CCYP+jcCPQuKNVkHwMwKP86qtlYf0HQ8MEzqZiBSJjNqxAOoLL1Du mjWHX6PhYW/SrzZMg9A5SzuE+xspRlwI6+sp26gHKKa7dV/8vvEVjCsmknEOdJSsaxE+ hnZ+r1H9SCupgdkAUQkRyAX5go1YNnnf5JJuZVPxBdgusFw4veUjO3sHT35R7iF6c+wI scGE4dKNT1ERxPn1hgoklyEF1Q6FhSligsCVpO8BeRJER0+HUxirj56PsPHjoEelnzj7 Ge0Q== X-Gm-Message-State: AOAM533Ab8vzsQGBB5fcFeX7SEO1170A8e+iMoj2XdrFXOkKJImbZ5yz JREd4SdpdNYQuvopubvL0H94ACgO67vyBIjd X-Google-Smtp-Source: ABdhPJzPX8MXqtA0FcoghUfmG8euapQCB+Ufg3K1D2NXFohoWG/eWTgE2UjT+fvGTE2zmu2po/ntvg== X-Received: by 2002:a05:6214:2483:: with SMTP id gi3mr23121825qvb.60.1640850353743; Wed, 29 Dec 2021 23:45:53 -0800 (PST) Received: from localhost (c-73-125-89-242.hsd1.fl.comcast.net. [73.125.89.242]) by smtp.gmail.com with UTF8SMTPSA id 22sm19525345qtw.12.2021.12.29.23.45.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Dec 2021 23:45:53 -0800 (PST) From: Philip McGrath Date: Thu, 30 Dec 2021 02:44:20 -0500 Message-Id: <20211230074456.33433-6-philip@philipmcgrath.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211230074456.33433-1-philip@philipmcgrath.com> References: <20211230073919.30327-1-philip@philipmcgrath.com> <20211230074456.33433-1-philip@philipmcgrath.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1640850474; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=YpY7I9/3vwIWnWFMsbMmcXC+bzQZOgggVRQdn95z9Rc=; b=oGVDZYIeDA+SJHNwfbFtFv+dyCkNs7nyOH5igGZWMgEzk9+er+Q7sEKT3OmYndLkQlsvnd 7y68fFZe528dY8YP5+gI6YQ/Uw9V+PrOHYU1Ui9jC39E0zL51nqzVpUT3GSd5XvOm4/Abj 3tqyjlah815KdJgAqffnT3YCw2TUWqmi7NlnyhfDjQ6yG6KOMQ6vY+HGkt7AyPFfoHIYzT whAm7hJKRjuNHzoK0BwX6cmZYZqUx2FqNJKYK4vfAQy+rfGljuwN+rDNZIrtQsyl52UTQ8 rNXzXLrjhh2uuLF6m8NbinqU3SQ8nlOfagBtwMlZ62ayuTZOWjrMkq1psCU2iA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1640850474; a=rsa-sha256; cv=none; b=gjIVruA7npNM/0QV09JlSdzLUe4tPOgMmne/KOHDrnWKHhm6CpspvLXs96j2wpZw/rWgqZ sNjgbvpsqIHRpEIRSLEno3AM6zOtPZzOvBUHWucyi4w6SR8kSOnzRc7DPpEjnYcbYRqrsY yoEJVmbtYAiFw3icrS9+CKVWkrkgQWpbseUj49cLgg6CIgwEdSXOWBWiZYiNBTSpZk0Zvd ETHKPJSHvaPlk2/wqLJXGd2iCos1U1t15dnmYkYSq1N8fWRcPIboYrQdMssfQw4NlMpWvi o0oJ7uLSGuzI4SpFwtdjQ7xfmMdLTkD7kzjnSXGMUIWCf9LzriBrMO8F3vvmEg== ARC-Authentication-Results: i=1; aspmx2.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=R8JBsdfl; dmarc=none; spf=pass (aspmx2.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 0.93 Authentication-Results: aspmx2.migadu.com; dkim=fail ("headers rsa verify failed") header.d=philipmcgrath.com header.s=google header.b=R8JBsdfl; dmarc=none; spf=pass (aspmx2.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 243C41E97C X-Spam-Score: 0.93 X-Migadu-Scanner: scn1.migadu.com X-TUID: UckTbVn8VrVi * 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 (delete-dependencies): New procedure. Respect the #:absent-dependencies argument, removing specified npm packages from the "dependencies" or "devDependencies" tables in "package.json". (%standard-phases): Add 'delete-dependencies after 'patch-dependencies. --- guix/build-system/node.scm | 19 ++++++++++++++++++- guix/build/node-build-system.scm | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/guix/build-system/node.scm b/guix/build-system/node.scm index 24bd677bfc..47af4bb9e2 100644 --- a/guix/build-system/node.scm +++ b/guix/build-system/node.scm @@ -49,6 +49,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." @@ -84,6 +85,7 @@ (define* (node-build name inputs (test-target "test") (tests? #t) (phases '%standard-phases) + (absent-dependencies ''()) (outputs '("out")) (search-paths '()) (system (%current-system)) @@ -91,7 +93,21 @@ (define* (node-build name inputs (imported-modules %node-build-system-modules) (modules '((guix build node-build-system) (guix build utils)))) - "Build SOURCE using NODE and INPUTS." + "Build SOURCE using NODE and INPUTS. + +The builder will remove Node.js packages listed in ABSENT-DEPENCENCIES from +the 'package.json' file's 'dependencies' and 'devDependencies' tables. This +mechanism can be used both avoid dependencies we don't want (e.g. optional +features that would increase closure size) and to work around dependencies +that haven't been packaged for Guix yet (e.g. test utilities)." + ;; Before #:absent-dependencies existed, this scenario was often handled by + ;; deleting the 'configure phase. Using #:absent-dependencies, instead, + ;; retains the check that no dependencies are silently missing and other + ;; actions performed by 'npm install', such as building native + ;; addons. Having an explicit list of absent dependencies in the package + ;; definition should also facilitate future maintenence: for example, if we + ;; add a package for a test framework, it should be easy to find all the + ;; other packages that use it and enable their tests. (define builder (with-imported-modules imported-modules #~(begin @@ -103,6 +119,7 @@ (define builder #:test-target #$test-target #:tests? #$tests? #:phases #$phases + #:absent-dependencies #$absent-dependencies #:outputs #$(outputs->gexp outputs) #:search-paths '#$(sexp->gexp (map search-path-specification->sexp diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm index dc8b6a41c2..e6b0811ca1 100644 --- a/guix/build/node-build-system.scm +++ b/guix/build/node-build-system.scm @@ -325,6 +325,22 @@ (define resolve-dependencies deps)))))) #t) +(define* (delete-dependencies #:key absent-dependencies #:allow-other-keys) + "Modify 'package.json' to allow building without the ABSENT-DEPENDENCIES." + (define delete-fom-jsobject + (match-lambda + (('@ . alist) + (cons '@ (filter (match-lambda + ((k . v) + (not (member k absent-dependencies)))) + alist))))) + (with-atomic-json-file-replacement "package.json" + (lambda (pkg-meta) + (jsobject-update* + pkg-meta + "devDependencies" '(@) delete-fom-jsobject + "dependencies" '(@) delete-fom-jsobject)))) + (define* (delete-lockfiles #:key inputs #:allow-other-keys) "Delete 'package-lock.json', 'yarn.lock', and 'npm-shrinkwrap.json', if they exist." @@ -431,7 +447,8 @@ (define %standard-phases (modify-phases gnu:%standard-phases (add-after 'unpack 'set-home set-home) (add-before 'configure 'patch-dependencies patch-dependencies) - (add-after 'patch-dependencies 'delete-lockfiles delete-lockfiles) + (add-after 'patch-dependencies 'delete-dependencies delete-dependencies) + (add-after 'delete-dependencies 'delete-lockfiles delete-lockfiles) (replace 'configure configure) (replace 'build build) (replace 'check check) -- 2.32.0