diff mbox series

[bug#36599] gnu: Add node-semver.

Message ID 20190711121221.16123-1-goodoldpaul@autistici.org
State Accepted
Headers show
Series [bug#36599] gnu: Add node-semver. | expand

Commit Message

Giacomo Leidi July 11, 2019, 12:12 p.m. UTC
* gnu/packages/node.scm (node-semver): New variable.
---
 gnu/packages/node.scm | 48 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

Comments

Ludovic Courtès Sept. 2, 2019, 12:49 p.m. UTC | #1
Hi Giacomo,

This patch seems to have been forgotten…

Giacomo Leidi <goodoldpaul@autistici.org> skribis:

> * gnu/packages/node.scm (node-semver): New variable.

[...]

> +(define-public node-semver
> +  (package
> +    (name "node-semver")
> +    (version "6.2.0")
> +    (source (origin
> +              (method git-fetch)
> +              (uri (git-reference
> +                    (url "https://github.com/npm/node-semver.git")
> +                    (commit (string-append "v" version))))
> +              (file-name (git-file-name name version))
> +              (sha256
> +               (base32
> +                "0lqb0v7frrdr7yvxy8b2yg6rp1jilninzk76qnx5qnswxnr4gj5m"))))

The nice thing is that the source doesn’t contain any binaries (or
“minified” code),.

> +    (build-system trivial-build-system)
> +    (propagated-inputs
> +     `(("node" ,node)))
> +    (arguments
> +     '(#:modules ((guix build utils))
> +       #:builder
> +       (begin
> +         (use-modules (guix build utils))
> +         (let* ((source (assoc-ref %build-inputs "source"))
> +                (out (assoc-ref %outputs "out"))
> +                (semver-js "semver.js")
> +                (entry-point (string-append "bin/" semver-js)))
> +           (mkdir-p (string-append out "/bin"))
> +           (setenv "PATH" (string-append (assoc-ref %build-inputs
> +                                                    "node")
> +                                         "/bin:" (getenv "PATH")))
> +           (map (lambda (file)
> +                  (install-file (string-append source "/" file) out))
> +                (list semver-js "LICENSE" "package.json" "package-lock.json" "range.bnf"))
> +           (install-file (string-append source "/" entry-point)
> +                         (string-append out "/bin"))
> +           (patch-shebang (string-append out "/" entry-point))
> +           #t))))

This installs files in non-standard locations:

--8<---------------cut here---------------start------------->8---
$ find $(./pre-inst-env guix build node-semver)
/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0
/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/package-lock.json
/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/bin
/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/bin/semver.js
/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/package.json
/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/semver.js
/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/range.bnf
/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/LICENSE
--8<---------------cut here---------------end--------------->8---

bin/ is fine, though should the binary be called ‘semver’ instead of
‘semver.js’?

Could you arrange so that ‘LICENSE’ goes to ‘share/doc/node-semver’?

As for the other files, I don’t know.   Are they needed?  Should they go
to share/node-semver?

Thanks in advance, and apologies for the loooong delay!

Ludo’.
Julien Lepiller Sept. 2, 2019, 2:50 p.m. UTC | #2
Le 2 septembre 2019 14:49:08 GMT+02:00, "Ludovic Courtès" <ludo@gnu.org> a écrit :
>Hi Giacomo,
>
>This patch seems to have been forgotten…
>
>Giacomo Leidi <goodoldpaul@autistici.org> skribis:
>
>> * gnu/packages/node.scm (node-semver): New variable.
>
>[...]
>
>> +(define-public node-semver
>> +  (package
>> +    (name "node-semver")
>> +    (version "6.2.0")
>> +    (source (origin
>> +              (method git-fetch)
>> +              (uri (git-reference
>> +                    (url "https://github.com/npm/node-semver.git")
>> +                    (commit (string-append "v" version))))
>> +              (file-name (git-file-name name version))
>> +              (sha256
>> +               (base32
>> +               
>"0lqb0v7frrdr7yvxy8b2yg6rp1jilninzk76qnx5qnswxnr4gj5m"))))
>
>The nice thing is that the source doesn’t contain any binaries (or
>“minified” code),.
>
>> +    (build-system trivial-build-system)
>> +    (propagated-inputs
>> +     `(("node" ,node)))
>> +    (arguments
>> +     '(#:modules ((guix build utils))
>> +       #:builder
>> +       (begin
>> +         (use-modules (guix build utils))
>> +         (let* ((source (assoc-ref %build-inputs "source"))
>> +                (out (assoc-ref %outputs "out"))
>> +                (semver-js "semver.js")
>> +                (entry-point (string-append "bin/" semver-js)))
>> +           (mkdir-p (string-append out "/bin"))
>> +           (setenv "PATH" (string-append (assoc-ref %build-inputs
>> +                                                    "node")
>> +                                         "/bin:" (getenv "PATH")))
>> +           (map (lambda (file)
>> +                  (install-file (string-append source "/" file)
>out))
>> +                (list semver-js "LICENSE" "package.json"
>"package-lock.json" "range.bnf"))
>> +           (install-file (string-append source "/" entry-point)
>> +                         (string-append out "/bin"))
>> +           (patch-shebang (string-append out "/" entry-point))
>> +           #t))))
>
>This installs files in non-standard locations:
>
>--8<---------------cut here---------------start------------->8---
>$ find $(./pre-inst-env guix build node-semver)
>/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0
>/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/package-lock.json
>/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/bin
>/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/bin/semver.js
>/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/package.json
>/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/semver.js
>/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/range.bnf
>/gnu/store/dmclr4h1jwqp02j9bpp9xsr5pzacdmnl-node-semver-6.2.0/LICENSE
>--8<---------------cut here---------------end--------------->8---
>
>bin/ is fine, though should the binary be called ‘semver’ instead of
>‘semver.js’?
>
>Could you arrange so that ‘LICENSE’ goes to ‘share/doc/node-semver’?
>
>As for the other files, I don’t know.   Are they needed?  Should they
>go
>to share/node-semver?
>
>Thanks in advance, and apologies for the loooong delay!
>
>Ludo’.

Actually we have a node-build-system now which woull work much better than the trivial-build-system.
Giacomo Leidi April 17, 2020, 2:54 p.m. UTC | #3
Hi Julien,

> Does npm install the test.js files when run by ittself (in which case 
> we replicate its behavior), or does it have a mechanism to know what 
> files to install? If so we thould replicate that mecanism.

On my system I get

giacomo@frarch /tmp$ npm i semver
npm WARN saveError ENOENT: no such file or directory, open 
'/tmp/package.json'
npm WARN enoent ENOENT: no such file or directory, open 
'/tmp/package.json'
npm WARN tmp No description
npm WARN tmp No repository field.
npm WARN tmp No README data
npm WARN tmp No license field.

+ semver@7.3.2
added 1 package and audited 1 package in 0.626s
found 0 vulnerabilities

giacomo@frarch /tmp$ ls -l node_modules/semver/
total 48
drwxr-xr-x 2 giacomo giacomo    60 Apr 17 16:43 bin/
-rw-r--r-- 1 giacomo giacomo  2257 Oct 26  1985 CHANGELOG.md
drwxr-xr-x 2 giacomo giacomo   120 Apr 17 16:43 classes/
drwxr-xr-x 2 giacomo giacomo   520 Apr 17 16:43 functions/
-rw-r--r-- 1 giacomo giacomo  1982 Oct 26  1985 index.js
drwxr-xr-x 2 giacomo giacomo   120 Apr 17 16:43 internal/
-rw-r--r-- 1 giacomo giacomo   765 Oct 26  1985 LICENSE
-rw-r--r-- 1 giacomo giacomo  1645 Apr 17 16:43 package.json
-rw-r--r-- 1 giacomo giacomo    69 Oct 26  1985 preload.js
-rw-r--r-- 1 giacomo giacomo   619 Oct 26  1985 range.bnf
drwxr-xr-x 2 giacomo giacomo   260 Apr 17 16:43 ranges/
-rw-r--r-- 1 giacomo giacomo 22109 Oct 26  1985 README.md

so I believe that npm uses the "files" key [0] in package.json to decide 
what to install.

I'm definitely available to implement that but it could take a week or 
two, if we feel it should be changed right away I'm probably not the 
best person to do that.

What do you think? Should I open another issue about this?

Giacomo

[0]: https://github.com/npm/node-semver/blob/master/package.json#L21
Efraim Flashner April 17, 2020, 3:03 p.m. UTC | #4
On Fri, Apr 17, 2020 at 02:54:43PM +0000, goodoldpaul@autistici.org wrote:
> Hi Julien,
> 
> > Does npm install the test.js files when run by ittself (in which case we
> > replicate its behavior), or does it have a mechanism to know what files
> > to install? If so we thould replicate that mecanism.
> 
> On my system I get
> 
> giacomo@frarch /tmp$ npm i semver
> npm WARN saveError ENOENT: no such file or directory, open
> '/tmp/package.json'
> npm WARN enoent ENOENT: no such file or directory, open '/tmp/package.json'
> npm WARN tmp No description
> npm WARN tmp No repository field.
> npm WARN tmp No README data
> npm WARN tmp No license field.
> 
> + semver@7.3.2
> added 1 package and audited 1 package in 0.626s
> found 0 vulnerabilities
> 
> giacomo@frarch /tmp$ ls -l node_modules/semver/
> total 48
> drwxr-xr-x 2 giacomo giacomo    60 Apr 17 16:43 bin/
> -rw-r--r-- 1 giacomo giacomo  2257 Oct 26  1985 CHANGELOG.md
> drwxr-xr-x 2 giacomo giacomo   120 Apr 17 16:43 classes/
> drwxr-xr-x 2 giacomo giacomo   520 Apr 17 16:43 functions/
> -rw-r--r-- 1 giacomo giacomo  1982 Oct 26  1985 index.js
> drwxr-xr-x 2 giacomo giacomo   120 Apr 17 16:43 internal/
> -rw-r--r-- 1 giacomo giacomo   765 Oct 26  1985 LICENSE
> -rw-r--r-- 1 giacomo giacomo  1645 Apr 17 16:43 package.json
> -rw-r--r-- 1 giacomo giacomo    69 Oct 26  1985 preload.js
> -rw-r--r-- 1 giacomo giacomo   619 Oct 26  1985 range.bnf
> drwxr-xr-x 2 giacomo giacomo   260 Apr 17 16:43 ranges/
> -rw-r--r-- 1 giacomo giacomo 22109 Oct 26  1985 README.md
> 
> so I believe that npm uses the "files" key [0] in package.json to decide
> what to install.
> 

Thanks for looking into it.

> I'm definitely available to implement that but it could take a week or two,
> if we feel it should be changed right away I'm probably not the best person
> to do that.
> 
> What do you think? Should I open another issue about this?

I think we should fix it, but it shouldn't block getting your package
into Guix. Go ahead and open a new issue for it.

> 
> Giacomo
> 
> [0]: https://github.com/npm/node-semver/blob/master/package.json#L21
> 
> 
>
Julien Lepiller April 17, 2020, 4:09 p.m. UTC | #5
Le 17 avril 2020 10:54:43 GMT-04:00, goodoldpaul@autistici.org a écrit :
>Hi Julien,
>
>> Does npm install the test.js files when run by ittself (in which case
>
>> we replicate its behavior), or does it have a mechanism to know what 
>> files to install? If so we thould replicate that mecanism.
>
>On my system I get
>
>giacomo@frarch /tmp$ npm i semver
>npm WARN saveError ENOENT: no such file or directory, open 
>'/tmp/package.json'
>npm WARN enoent ENOENT: no such file or directory, open 
>'/tmp/package.json'
>npm WARN tmp No description
>npm WARN tmp No repository field.
>npm WARN tmp No README data
>npm WARN tmp No license field.
>
>+ semver@7.3.2
>added 1 package and audited 1 package in 0.626s
>found 0 vulnerabilities
>
>giacomo@frarch /tmp$ ls -l node_modules/semver/
>total 48
>drwxr-xr-x 2 giacomo giacomo    60 Apr 17 16:43 bin/
>-rw-r--r-- 1 giacomo giacomo  2257 Oct 26  1985 CHANGELOG.md
>drwxr-xr-x 2 giacomo giacomo   120 Apr 17 16:43 classes/
>drwxr-xr-x 2 giacomo giacomo   520 Apr 17 16:43 functions/
>-rw-r--r-- 1 giacomo giacomo  1982 Oct 26  1985 index.js
>drwxr-xr-x 2 giacomo giacomo   120 Apr 17 16:43 internal/
>-rw-r--r-- 1 giacomo giacomo   765 Oct 26  1985 LICENSE
>-rw-r--r-- 1 giacomo giacomo  1645 Apr 17 16:43 package.json
>-rw-r--r-- 1 giacomo giacomo    69 Oct 26  1985 preload.js
>-rw-r--r-- 1 giacomo giacomo   619 Oct 26  1985 range.bnf
>drwxr-xr-x 2 giacomo giacomo   260 Apr 17 16:43 ranges/
>-rw-r--r-- 1 giacomo giacomo 22109 Oct 26  1985 README.md
>
>so I believe that npm uses the "files" key [0] in package.json to
>decide 
>what to install.
>
>I'm definitely available to implement that but it could take a week or 
>two, if we feel it should be changed right away I'm probably not the 
>best person to do that.
>
>What do you think? Should I open another issue about this?
>
>Giacomo
>
>[0]: https://github.com/npm/node-semver/blob/master/package.json#L21

We don't have to rush, and I won't implement that faster than you, so if you can and want to do it, please go ahead :). Opening a new bug to track that is a good idea. Can you do that?

Thank you!
diff mbox series

Patch

diff --git a/gnu/packages/node.scm b/gnu/packages/node.scm
index fc43fcb04c..2f3fe17334 100644
--- a/gnu/packages/node.scm
+++ b/gnu/packages/node.scm
@@ -6,6 +6,7 @@ 
 ;;; Copyright © 2017 Mike Gerwitz <mtg@gnu.org>
 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
 ;;; Copyright © 2018, 2019 Marius Bakke <mbakke@fastmail.com>
+;;; Copyright © 2019 Giacomo Leidi <goodoldpaul@autistici.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -23,10 +24,12 @@ 
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (gnu packages node)
-  #:use-module ((guix licenses) #:select (expat))
+  #:use-module ((guix licenses) #:select (expat isc))
   #:use-module (guix packages)
   #:use-module (guix derivations)
   #:use-module (guix download)
+  #:use-module (guix git-download)
+  #:use-module (guix build-system trivial)
   #:use-module (guix build-system gnu)
   #:use-module (gnu packages)
   #:use-module (gnu packages adns)
@@ -184,3 +187,46 @@  devices.")
     (home-page "https://nodejs.org/")
     (license expat)
     (properties '((timeout . 3600))))) ; 1 h
+
+(define-public node-semver
+  (package
+    (name "node-semver")
+    (version "6.2.0")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/npm/node-semver.git")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0lqb0v7frrdr7yvxy8b2yg6rp1jilninzk76qnx5qnswxnr4gj5m"))))
+    (build-system trivial-build-system)
+    (propagated-inputs
+     `(("node" ,node)))
+    (arguments
+     '(#:modules ((guix build utils))
+       #:builder
+       (begin
+         (use-modules (guix build utils))
+         (let* ((source (assoc-ref %build-inputs "source"))
+                (out (assoc-ref %outputs "out"))
+                (semver-js "semver.js")
+                (entry-point (string-append "bin/" semver-js)))
+           (mkdir-p (string-append out "/bin"))
+           (setenv "PATH" (string-append (assoc-ref %build-inputs
+                                                    "node")
+                                         "/bin:" (getenv "PATH")))
+           (map (lambda (file)
+                  (install-file (string-append source "/" file) out))
+                (list semver-js "LICENSE" "package.json" "package-lock.json" "range.bnf"))
+           (install-file (string-append source "/" entry-point)
+                         (string-append out "/bin"))
+           (patch-shebang (string-append out "/" entry-point))
+           #t))))
+    (home-page "https://github.com/npm/node-semver")
+    (synopsis "Parses semantic versions strings")
+    (description
+     "node-semver is a JavaScript implementation of the
+@uref{https://semver.org/, SemVer.org} specification.")
+    (license isc)))