From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 8KduHLiyMWQOWgAASxT56A (envelope-from ) for ; Sat, 08 Apr 2023 20:30:16 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id CCudG7iyMWSLzwAAG6o9tA (envelope-from ) for ; Sat, 08 Apr 2023 20:30:16 +0200 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 aspmx1.migadu.com (Postfix) with ESMTPS id BD58A2D943 for ; Sat, 8 Apr 2023 20:30:14 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1plDKE-0002bJ-62; Sat, 08 Apr 2023 14:30:10 -0400 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 1plDK6-0002ay-Oa for guix-patches@gnu.org; Sat, 08 Apr 2023 14:30:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1plDK6-0002ac-GU for guix-patches@gnu.org; Sat, 08 Apr 2023 14:30:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1plDK5-0006E6-Tf for guix-patches@gnu.org; Sat, 08 Apr 2023 14:30:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62375] [PATCH] import: Add binary npm importer. Resent-From: Jelle Licht Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 08 Apr 2023 18:30:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62375 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch moreinfo To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: Timothy Sample , Josselin Poiret , Tobias Geerinckx-Rice , Simon Tournier , Mathieu Othacehe , Christopher Baines , Lars-Dominik Braun , 62375@debbugs.gnu.org, Ricardo Wurmus Received: via spool by 62375-submit@debbugs.gnu.org id=B62375.168097856723863 (code B ref 62375); Sat, 08 Apr 2023 18:30:01 +0000 Received: (at 62375) by debbugs.gnu.org; 8 Apr 2023 18:29:27 +0000 Received: from localhost ([127.0.0.1]:59503 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1plDJW-0006Cp-N7 for submit@debbugs.gnu.org; Sat, 08 Apr 2023 14:29:27 -0400 Received: from mail1.fsfe.org ([217.69.89.151]:51332) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1plDJV-0006Cg-5Z for 62375@debbugs.gnu.org; Sat, 08 Apr 2023 14:29:26 -0400 From: Jelle Licht DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fsfe.org; s=2021100501; t=1680978563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TCVCfpFki70rsR5o/v6/FB9+JLzLyFnbaWiw754CNKc=; b=dAN0LsUiF/bu5xmO6SR/VIInhnckndz5rQJ5dqMF8doFsGxoxqLMKnLd3kHrHaIPNoqslA SXwiq9vNXTkmunhvU7/Dn4Yqofy7ikiUcCd97UkeXzMx063GESOq4uMcgKQwF7hpuGGgJB Q8+ikX67sUelnFC5SLZfk6PYmzclM+k= In-Reply-To: <87tty4g9kj.fsf@gnu.org> References: <87tty4g9kj.fsf@gnu.org> Date: Sat, 08 Apr 2023 20:29:18 +0200 Message-ID: <871qkurzwh.fsf@fsfe.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1680978616; a=rsa-sha256; cv=none; b=P4245vwvr3zcqd6WLTfyAWlDSg0AMa74hzLlZHbgrWCEzbSfoQVdl7EROKkPcThWxuqa9N bL9yje4W2XKyjySFq8nR9pjXbuvGlHTLBglyhaBhKnxuekEhZLmzD1WilHZwQxKznywRNB vvzinGu0ilolzNXoISFpsoHz9obmKjfZVzWo+Y96n7Tcec+Sq3LnWJkM28JL4aES7DBxay kwiZ6qcmkoKbLhe0x5DQMAz4PTA3iV6Szleh+882bNUar83fg4lfjg8GNgqI7qmsHgO4Sw bxy2dfYnW8pJfSanQrixzSMh2ZdlEkUQeNRyJQkFMPyk5OMJUjozytNfJHEGNw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=fsfe.org header.s=2021100501 header.b=dAN0LsUi; dmarc=fail reason="SPF not aligned (relaxed)" header.from=fsfe.org (policy=none); spf=pass (aspmx1.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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1680978616; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: 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=TCVCfpFki70rsR5o/v6/FB9+JLzLyFnbaWiw754CNKc=; b=aKNoHCAtS53L8UeXXSabvKF/6JWMjM5zsG7mQmlupIUzrzLRXn+zPYgoEfE3Kh0s4naT66 K4foyGv6BjfDu3k5v4GVgJRblV9+CI3cUH4tuC26qeBaT82Q+5JkjDtcbJxXcKNrVzz4uR IKcWb4fm+iFhKBLUvKpBI6W/Ta+RrP4ygZz++8xVmdM6aZmw9+/gfn8IoxTxHiC6bzpQaj 91P3AU6YCt3qkeSuVq4QvRe7OaCN589zTNbVCK/W1NiefeUoqkpJ5/+tUn1X0kWfyhZszQ eum5HAxgYsDWFPwuFEG8ejpOeaXKIM73sdbso0aYTZHGmI3RV4P/DJiBBtMg0Q== Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=fsfe.org header.s=2021100501 header.b=dAN0LsUi; dmarc=fail reason="SPF not aligned (relaxed)" header.from=fsfe.org (policy=none); spf=pass (aspmx1.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-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -1.12 X-Spam-Score: -1.12 X-Migadu-Queue-Id: BD58A2D943 X-TUID: g68dTQ/tr/tt Ludovic Court=C3=A8s writes: > Hello Jelle! > > jlicht@fsfe.org skribis: > >> From: Jelle Licht >> >> * guix/scripts/import.scm: (importers): Add "npm-binary". >> * guix/import/npm-binary.scm: New file. >> * guix/scripts/import/npm-binary.scm: New file. >> * Makefile.am: Add them. >> >> Co-authored-by: Timothy Sample >> Co-authored-by: Lars-Dominik Braun > > Woohoo! I think it=E2=80=99ll be useful to many, even if we know it=E2= =80=99s far from > =E2=80=9Cideal=E2=80=9D by our standards. > > We=E2=80=99ll need doc under =E2=80=9CInvoking guix import=E2=80=9D and t= ests in > =E2=80=98tests/npm-binary.scm=E2=80=99, similar to what=E2=80=99s done fo= r the other importers. > The doc should clarify why it=E2=80=99s called that way and what the limi= tations > are. > > For tests, I=E2=80=99d recommend mocking the npmjs.org HTTP servers using > =E2=80=98with-http-server=E2=80=99 as in =E2=80=98tests/cpan.scm=E2=80=99. > > Also, please add docstrings to top-level procedures. > >> +;; TODO: Support other registries >> +(define *registry* "https://registry.npmjs.org") >> +(define *default-page* "https://www.npmjs.com/package") > > The convention currently is more like =E2=80=98%registry=E2=80=99. > >> +(define (http-error-code arglist) >> + (match arglist >> + (('http-error _ _ _ (code)) code) >> + (_ #f))) > > Unused. :-) > >> +(define (hash-url url) >> + "Downloads the resource at URL and computes the base32 hash for it." >> + (call-with-temporary-output-file >> + (lambda (temp port) >> + (begin ((@ (guix import utils) url-fetch) url temp) >> + (guix-hash-url temp))))) > > Maybe something more like: (port-sha256 (http-fetch =E2=80=A6)) ? > >> +(define (npm-package->package-sexp npm-package) >> + "Return the `package' s-expression for an NPM-PACKAGE." >> + (define (new-or-existing-inputs resolved-deps) >> + (map package-revision->input resolved-deps)) >> + >> + (match npm-package >> + (($ name version home-page dependencies dev-depe= ndencies peer-dependencies license description dist) > > Please use =E2=80=98match-record=E2=80=99 instead and keep lines below 80= chars. :-) The records generated by `define-json-mapping' through `define-record-type' seem to not work with `match-record'. I could define our very own `define-json-mapping*' that works /w `define-record-type*' instead (and through that, `match-record'), but I thought I'd ask if you had something else in mind first :). >> + (let* ((name (npm-name->name name)) >> + (url (dist-tarball dist)) >> + (home-page (if (string? home-page) >> + home-page >> + (string-append *default-page* "/" (uri-encod= e name)))) >> + (synopsis description) >> + (resolved-deps (map (match-lambda (($ n= ame version) >> + (resolve-package name (s= tring->semver-range version)))) (append dependencies peer-dependencies))) > > Likewise. > > That=E2=80=99s it! Could you send an updated patch? Will do, once I got some proper test cases set up. Thanks again for the review!=20 - Jelle