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 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.15.3")
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 "1mcijznh481s44i59p571a38bfvcxm9f8x2l0l1005aly0kdj8jf"))
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 ;; TODO: Purge the bundled copies from the source.
78 '(#:configure-flags '("--shared-cares"
79 "--shared-http-parser"
80 "--shared-libuv"
81 "--shared-nghttp2"
82 "--shared-openssl"
83 "--shared-zlib"
84 "--without-snapshot"
85 "--with-intl=system-icu")
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"
89 #:phases
90 (modify-phases %standard-phases
91 (add-before 'configure 'patch-files
92 (lambda* (#:key inputs #:allow-other-keys)
93
94 ;; Fix hardcoded /bin/sh references.
95 (substitute* '("lib/child_process.js"
96 "lib/internal/v8_prof_polyfill.js"
97 "test/parallel/test-child-process-spawnsync-shell.js"
98 "test/parallel/test-stdio-closed.js")
99 (("'/bin/sh'")
100 (string-append "'" (which "sh") "'")))
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
109 ;; FIXME: These tests fail in the build container, but they don't
110 ;; seem to be indicative of real problems in practice.
111 (for-each delete-file
112 '("test/async-hooks/test-ttywrap.readstream.js"
113 "test/parallel/test-util-inspect.js"
114 "test/parallel/test-v8-serdes.js"
115 "test/parallel/test-dgram-membership.js"
116 "test/parallel/test-dns-cancel-reverse-lookup.js"
117 "test/parallel/test-dns-resolveany.js"
118 "test/parallel/test-cluster-master-error.js"
119 "test/parallel/test-cluster-master-kill.js"
120 "test/parallel/test-net-listen-after-destroying-stdin.js"
121 "test/parallel/test-npm-install.js"
122 "test/sequential/test-child-process-emfile.js"
123 "test/sequential/test-http-regr-gh-2928.js"))
124
125 ;; These tests have an expiry date: they depend on the validity of
126 ;; TLS certificates that are bundled with the source. We want this
127 ;; package to be reproducible forever, so remove those.
128 ;; TODO: Regenerate certs instead.
129 (for-each delete-file
130 '("test/parallel/test-tls-passphrase.js"
131 "test/parallel/test-tls-server-verify.js"))
132 #t))
133 (replace 'configure
134 ;; Node's configure script is actually a python script, so we can't
135 ;; run it with bash.
136 (lambda* (#:key outputs (configure-flags '()) inputs
137 #:allow-other-keys)
138 (let* ((prefix (assoc-ref outputs "out"))
139 (flags (cons (string-append "--prefix=" prefix)
140 configure-flags)))
141 (format #t "build directory: ~s~%" (getcwd))
142 (format #t "configure flags: ~s~%" flags)
143 ;; Node's configure script expects the CC environment variable to
144 ;; be set.
145 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
146 (apply invoke
147 (string-append (assoc-ref inputs "python")
148 "/bin/python")
149 "configure" flags))))
150 (add-after 'patch-shebangs 'patch-npm-shebang
151 (lambda* (#:key outputs #:allow-other-keys)
152 (let* ((bindir (string-append (assoc-ref outputs "out")
153 "/bin"))
154 (npm (string-append bindir "/npm"))
155 (target (readlink npm)))
156 (with-directory-excursion bindir
157 (patch-shebang target (list bindir))
158 #t)))))))
159 (native-inputs
160 `(("python" ,python-2)
161 ("perl" ,perl)
162 ("pkg-config" ,pkg-config)
163 ("procps" ,procps)
164 ("util-linux" ,util-linux)
165 ("which" ,which)))
166 (native-search-paths
167 (list (search-path-specification
168 (variable "NODE_PATH")
169 (files '("lib/node_modules")))))
170 (inputs
171 `(("c-ares" ,c-ares)
172 ("http-parser" ,http-parser)
173 ("icu4c" ,icu4c)
174 ("libuv" ,libuv)
175 ("nghttp2" ,nghttp2 "lib")
176 ("openssl" ,openssl)
177 ("zlib" ,zlib)))
178 (synopsis "Evented I/O for V8 JavaScript")
179 (description "Node.js is a platform built on Chrome's JavaScript runtime
180 for easily building fast, scalable network applications. Node.js uses an
181 event-driven, non-blocking I/O model that makes it lightweight and efficient,
182 perfect for data-intensive real-time applications that run across distributed
183 devices.")
184 (home-page "https://nodejs.org/")
185 (license expat)
186 (properties '((timeout . 3600))))) ; 1 h