gnu: Add ronn-ng
[jackhill/guix/guix.git] / gnu / packages / node.scm
CommitLineData
ed02caff
CS
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014 Cyrill Schenkel <cyrill.schenkel@gmail.com>
20fbd209 3;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
c5b5e275 4;;; Copyright © 2015, 2016 David Thompson <davet@gnu.org>
2de091f0 5;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
797d2387 6;;; Copyright © 2017 Mike Gerwitz <mtg@gnu.org>
5112238f 7;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
458c3ff5 8;;; Copyright © 2018, 2019, 2020 Marius Bakke <mbakke@fastmail.com>
ed02caff
CS
9;;;
10;;; This file is part of GNU Guix.
11;;;
12;;; GNU Guix is free software; you can redistribute it and/or modify it
13;;; under the terms of the GNU General Public License as published by
14;;; the Free Software Foundation; either version 3 of the License, or (at
15;;; your option) any later version.
16;;;
17;;; GNU Guix is distributed in the hope that it will be useful, but
18;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;;; GNU General Public License for more details.
21;;;
22;;; You should have received a copy of the GNU General Public License
23;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25(define-module (gnu packages node)
1eca745b 26 #:use-module ((guix licenses) #:select (expat))
ed02caff
CS
27 #:use-module (guix packages)
28 #:use-module (guix derivations)
29 #:use-module (guix download)
bb310a19 30 #:use-module (guix utils)
1eca745b 31 #:use-module (guix build-system gnu)
dd04f56a 32 #:use-module (gnu packages)
ea584538 33 #:use-module (gnu packages adns)
1eca745b
DT
34 #:use-module (gnu packages base)
35 #:use-module (gnu packages compression)
36 #:use-module (gnu packages gcc)
fe5d4f81 37 #:use-module (gnu packages icu4c)
1eca745b
DT
38 #:use-module (gnu packages libevent)
39 #:use-module (gnu packages linux)
40 #:use-module (gnu packages perl)
fe5d4f81 41 #:use-module (gnu packages pkg-config)
1eca745b 42 #:use-module (gnu packages python)
ea584538
JL
43 #:use-module (gnu packages tls)
44 #:use-module (gnu packages web))
ed02caff
CS
45
46(define-public node
47 (package
48 (name "node")
458c3ff5 49 (version "10.19.0")
ed02caff
CS
50 (source (origin
51 (method url-fetch)
e9027160 52 (uri (string-append "https://nodejs.org/dist/v" version
70248461 53 "/node-v" version ".tar.xz"))
ed02caff
CS
54 (sha256
55 (base32
458c3ff5 56 "0sginvcsf7lrlzsnpahj4bj1f673wfvby8kaxgvzlrbb7sy229v2"))
fe5d4f81
JL
57 (modules '((guix build utils)))
58 (snippet
59 `(begin
60 ;; Remove bundled software.
61 (for-each delete-file-recursively
62 '("deps/cares"
63 "deps/http_parser"
64 "deps/icu-small"
65 "deps/nghttp2"
66 "deps/openssl"
67 "deps/uv"
68 "deps/zlib"))
69 (substitute* "Makefile"
5112238f 70 ;; Remove references to bundled software.
fe5d4f81
JL
71 (("deps/http_parser/http_parser.gyp") "")
72 (("deps/uv/include/\\*.h") "")
73 (("deps/uv/uv.gyp") "")
6cbee49d
MW
74 (("deps/zlib/zlib.gyp") ""))
75 #t))))
ed02caff
CS
76 (build-system gnu-build-system)
77 (arguments
2f38e38f 78 `(#:configure-flags '("--shared-cares"
ea584538 79 "--shared-http-parser"
fe5d4f81
JL
80 "--shared-libuv"
81 "--shared-nghttp2"
82 "--shared-openssl"
83 "--shared-zlib"
84 "--without-snapshot"
85 "--with-intl=system-icu")
70248461
MB
86 ;; Run only the CI tests. The default test target requires additional
87 ;; add-ons from NPM that are not distributed with the source.
88 #:test-target "test-ci-js"
1eca745b
DT
89 #:phases
90 (modify-phases %standard-phases
c5b5e275
DT
91 (add-before 'configure 'patch-files
92 (lambda* (#:key inputs #:allow-other-keys)
93 ;; Fix hardcoded /bin/sh references.
94 (substitute* '("lib/child_process.js"
95 "lib/internal/v8_prof_polyfill.js"
3759deab 96 "test/parallel/test-child-process-spawnsync-shell.js"
4c482696
MB
97 "test/parallel/test-stdio-closed.js"
98 "test/sequential/test-child-process-emfile.js")
c5b5e275 99 (("'/bin/sh'")
f2ea722a 100 (string-append "'" (which "sh") "'")))
c5b5e275
DT
101
102 ;; Fix hardcoded /usr/bin/env references.
103 (substitute* '("test/parallel/test-child-process-default-options.js"
104 "test/parallel/test-child-process-env.js"
105 "test/parallel/test-child-process-exec-env.js")
106 (("'/usr/bin/env'")
107 (string-append "'" (which "env") "'")))
108
c5b5e275
DT
109 ;; FIXME: These tests fail in the build container, but they don't
110 ;; seem to be indicative of real problems in practice.
70248461 111 (for-each delete-file
4c482696 112 '("test/parallel/test-cluster-master-error.js"
c5b5e275 113 "test/parallel/test-cluster-master-kill.js"
4c482696
MB
114 ;; See also <https://github.com/nodejs/node/issues/25903>.
115 "test/sequential/test-performance.js"))
116
117 ;; This requires a DNS resolver.
118 (delete-file "test/parallel/test-dns.js")
020c4ef1 119
51583265
MB
120 ;; FIXME: This test fails randomly:
121 ;; https://github.com/nodejs/node/issues/31213
122 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
123
5cfc6a88
MB
124 ;; FIXME: These tests fail on armhf-linux:
125 ;; https://github.com/nodejs/node/issues/31970
126 ,@(if (string-prefix? "arm" (%current-system))
127 '((for-each delete-file
128 '("test/parallel/test-zlib.js"
129 "test/parallel/test-zlib-brotli.js"
130 "test/parallel/test-zlib-brotli-flush.js"
131 "test/parallel/test-zlib-brotli-from-brotli.js"
132 "test/parallel/test-zlib-brotli-from-string.js"
133 "test/parallel/test-zlib-convenience-methods.js"
134 "test/parallel/test-zlib-random-byte-pipes.js"
135 "test/parallel/test-zlib-write-after-flush.js")))
136 '())
137
020c4ef1
MB
138 ;; These tests have an expiry date: they depend on the validity of
139 ;; TLS certificates that are bundled with the source. We want this
140 ;; package to be reproducible forever, so remove those.
141 ;; TODO: Regenerate certs instead.
70248461 142 (for-each delete-file
020c4ef1
MB
143 '("test/parallel/test-tls-passphrase.js"
144 "test/parallel/test-tls-server-verify.js"))
c5b5e275
DT
145 #t))
146 (replace 'configure
147 ;; Node's configure script is actually a python script, so we can't
148 ;; run it with bash.
149 (lambda* (#:key outputs (configure-flags '()) inputs
150 #:allow-other-keys)
151 (let* ((prefix (assoc-ref outputs "out"))
152 (flags (cons (string-append "--prefix=" prefix)
153 configure-flags)))
154 (format #t "build directory: ~s~%" (getcwd))
155 (format #t "configure flags: ~s~%" flags)
156 ;; Node's configure script expects the CC environment variable to
157 ;; be set.
158 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
5112238f
TGR
159 (apply invoke
160 (string-append (assoc-ref inputs "python")
161 "/bin/python")
162 "configure" flags))))
dd04f56a
AM
163 (add-after 'patch-shebangs 'patch-npm-shebang
164 (lambda* (#:key outputs #:allow-other-keys)
165 (let* ((bindir (string-append (assoc-ref outputs "out")
166 "/bin"))
167 (npm (string-append bindir "/npm"))
2de091f0 168 (target (readlink npm)))
dd04f56a
AM
169 (with-directory-excursion bindir
170 (patch-shebang target (list bindir))
171 #t)))))))
1eca745b
DT
172 (native-inputs
173 `(("python" ,python-2)
174 ("perl" ,perl)
fe5d4f81 175 ("pkg-config" ,pkg-config)
c5b5e275 176 ("procps" ,procps)
1eca745b
DT
177 ("util-linux" ,util-linux)
178 ("which" ,which)))
45c18f85
JL
179 (native-search-paths
180 (list (search-path-specification
181 (variable "NODE_PATH")
182 (files '("lib/node_modules")))))
1eca745b 183 (inputs
ea584538
JL
184 `(("c-ares" ,c-ares)
185 ("http-parser" ,http-parser)
fe5d4f81 186 ("icu4c" ,icu4c)
70248461 187 ("libuv" ,libuv)
fe5d4f81 188 ("nghttp2" ,nghttp2 "lib")
d9bbfe04 189 ("openssl" ,openssl)
1eca745b 190 ("zlib" ,zlib)))
2d094239 191 (synopsis "Evented I/O for V8 JavaScript")
ed02caff
CS
192 (description "Node.js is a platform built on Chrome's JavaScript runtime
193for easily building fast, scalable network applications. Node.js uses an
194event-driven, non-blocking I/O model that makes it lightweight and efficient,
195perfect for data-intensive real-time applications that run across distributed
196devices.")
e9027160 197 (home-page "https://nodejs.org/")
3759deab 198 (license expat)
b4481f2d
MB
199 (properties '((max-silent-time . 7200) ;2h, needed on ARM
200 (timeout . 21600))))) ;6h
bb310a19
RW
201
202(define-public libnode
203 (package
204 (inherit node)
205 (name "libnode")
206 (arguments
207 (substitute-keyword-arguments (package-arguments node)
208 ((#:configure-flags flags ''())
e8521f0b
RW
209 `(cons* "--shared" "--without-npm" ,flags))
210 ((#:phases phases '%standard-phases)
211 `(modify-phases ,phases
212 (delete 'patch-npm-shebang)))))))