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