Merge branch 'master' into core-updates
[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 ;;;
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)
26 #:use-module ((guix licenses) #:select (expat))
27 #:use-module (guix packages)
28 #:use-module (guix derivations)
29 #:use-module (guix download)
30 #:use-module (guix build-system gnu)
31 #:use-module (gnu packages)
32 #:use-module (gnu packages adns)
33 #:use-module (gnu packages base)
34 #:use-module (gnu packages compression)
35 #:use-module (gnu packages gcc)
36 #:use-module (gnu packages icu4c)
37 #:use-module (gnu packages libevent)
38 #:use-module (gnu packages linux)
39 #:use-module (gnu packages perl)
40 #:use-module (gnu packages pkg-config)
41 #:use-module (gnu packages python)
42 #:use-module (gnu packages tls)
43 #:use-module (gnu packages web))
44
45 (define-public node
46 (package
47 (name "node")
48 (version "10.19.0")
49 (source (origin
50 (method url-fetch)
51 (uri (string-append "https://nodejs.org/dist/v" version
52 "/node-v" version ".tar.xz"))
53 (sha256
54 (base32
55 "0sginvcsf7lrlzsnpahj4bj1f673wfvby8kaxgvzlrbb7sy229v2"))
56 (modules '((guix build utils)))
57 (snippet
58 `(begin
59 ;; Remove bundled software.
60 (for-each delete-file-recursively
61 '("deps/cares"
62 "deps/http_parser"
63 "deps/icu-small"
64 "deps/nghttp2"
65 "deps/openssl"
66 "deps/uv"
67 "deps/zlib"))
68 (substitute* "Makefile"
69 ;; Remove references to bundled software.
70 (("deps/http_parser/http_parser.gyp") "")
71 (("deps/uv/include/\\*.h") "")
72 (("deps/uv/uv.gyp") "")
73 (("deps/zlib/zlib.gyp") ""))
74 #t))))
75 (build-system gnu-build-system)
76 (arguments
77 `(#:configure-flags '("--shared-cares"
78 "--shared-http-parser"
79 "--shared-libuv"
80 "--shared-nghttp2"
81 "--shared-openssl"
82 "--shared-zlib"
83 "--without-snapshot"
84 "--with-intl=system-icu")
85 ;; Run only the CI tests. The default test target requires additional
86 ;; add-ons from NPM that are not distributed with the source.
87 #:test-target "test-ci-js"
88 #:phases
89 (modify-phases %standard-phases
90 (add-before 'configure 'patch-files
91 (lambda* (#:key inputs #:allow-other-keys)
92 ;; Fix hardcoded /bin/sh references.
93 (substitute* '("lib/child_process.js"
94 "lib/internal/v8_prof_polyfill.js"
95 "test/parallel/test-child-process-spawnsync-shell.js"
96 "test/parallel/test-stdio-closed.js"
97 "test/sequential/test-child-process-emfile.js")
98 (("'/bin/sh'")
99 (string-append "'" (which "sh") "'")))
100
101 ;; Fix hardcoded /usr/bin/env references.
102 (substitute* '("test/parallel/test-child-process-default-options.js"
103 "test/parallel/test-child-process-env.js"
104 "test/parallel/test-child-process-exec-env.js")
105 (("'/usr/bin/env'")
106 (string-append "'" (which "env") "'")))
107
108 ;; FIXME: These tests fail in the build container, but they don't
109 ;; seem to be indicative of real problems in practice.
110 (for-each delete-file
111 '("test/parallel/test-cluster-master-error.js"
112 "test/parallel/test-cluster-master-kill.js"
113 ;; See also <https://github.com/nodejs/node/issues/25903>.
114 "test/sequential/test-performance.js"))
115
116 ;; This requires a DNS resolver.
117 (delete-file "test/parallel/test-dns.js")
118
119 ;; FIXME: This test fails randomly:
120 ;; https://github.com/nodejs/node/issues/31213
121 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
122
123 ;; FIXME: These tests fail on armhf-linux:
124 ;; https://github.com/nodejs/node/issues/31970
125 ,@(if (string-prefix? "arm" (%current-system))
126 '((for-each delete-file
127 '("test/parallel/test-zlib.js"
128 "test/parallel/test-zlib-brotli.js"
129 "test/parallel/test-zlib-brotli-flush.js"
130 "test/parallel/test-zlib-brotli-from-brotli.js"
131 "test/parallel/test-zlib-brotli-from-string.js"
132 "test/parallel/test-zlib-convenience-methods.js"
133 "test/parallel/test-zlib-random-byte-pipes.js"
134 "test/parallel/test-zlib-write-after-flush.js")))
135 '())
136
137 ;; These tests have an expiry date: they depend on the validity of
138 ;; TLS certificates that are bundled with the source. We want this
139 ;; package to be reproducible forever, so remove those.
140 ;; TODO: Regenerate certs instead.
141 (for-each delete-file
142 '("test/parallel/test-tls-passphrase.js"
143 "test/parallel/test-tls-server-verify.js"))
144 #t))
145 (replace 'configure
146 ;; Node's configure script is actually a python script, so we can't
147 ;; run it with bash.
148 (lambda* (#:key outputs (configure-flags '()) inputs
149 #:allow-other-keys)
150 (let* ((prefix (assoc-ref outputs "out"))
151 (flags (cons (string-append "--prefix=" prefix)
152 configure-flags)))
153 (format #t "build directory: ~s~%" (getcwd))
154 (format #t "configure flags: ~s~%" flags)
155 ;; Node's configure script expects the CC environment variable to
156 ;; be set.
157 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
158 (apply invoke
159 (string-append (assoc-ref inputs "python")
160 "/bin/python")
161 "configure" flags))))
162 (add-after 'patch-shebangs 'patch-npm-shebang
163 (lambda* (#:key outputs #:allow-other-keys)
164 (let* ((bindir (string-append (assoc-ref outputs "out")
165 "/bin"))
166 (npm (string-append bindir "/npm"))
167 (target (readlink npm)))
168 (with-directory-excursion bindir
169 (patch-shebang target (list bindir))
170 #t)))))))
171 (native-inputs
172 `(("python" ,python-2)
173 ("perl" ,perl)
174 ("pkg-config" ,pkg-config)
175 ("procps" ,procps)
176 ("util-linux" ,util-linux)
177 ("which" ,which)))
178 (native-search-paths
179 (list (search-path-specification
180 (variable "NODE_PATH")
181 (files '("lib/node_modules")))))
182 (inputs
183 `(("c-ares" ,c-ares)
184 ("http-parser" ,http-parser)
185 ("icu4c" ,icu4c)
186 ("libuv" ,libuv)
187 ("nghttp2" ,nghttp2 "lib")
188 ("openssl" ,openssl)
189 ("zlib" ,zlib)))
190 (synopsis "Evented I/O for V8 JavaScript")
191 (description "Node.js is a platform built on Chrome's JavaScript runtime
192 for easily building fast, scalable network applications. Node.js uses an
193 event-driven, non-blocking I/O model that makes it lightweight and efficient,
194 perfect for data-intensive real-time applications that run across distributed
195 devices.")
196 (home-page "https://nodejs.org/")
197 (license expat)
198 (properties '((max-silent-time . 7200) ;2h, needed on ARM
199 (timeout . 21600))))) ;6h