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 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages node)
24 #:use-module ((guix licenses) #:select (expat))
25 #:use-module (guix packages)
26 #:use-module (guix derivations)
27 #:use-module (guix download)
28 #:use-module (guix build-system gnu)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages adns)
31 #:use-module (gnu packages base)
32 #:use-module (gnu packages compression)
33 #:use-module (gnu packages gcc)
34 #:use-module (gnu packages icu4c)
35 #:use-module (gnu packages libevent)
36 #:use-module (gnu packages linux)
37 #:use-module (gnu packages perl)
38 #:use-module (gnu packages pkg-config)
39 #:use-module (gnu packages python)
40 #:use-module (gnu packages tls)
41 #:use-module (gnu packages web))
42
43 (define-public node
44 (package
45 (name "node")
46 (version "9.11.1")
47 (source (origin
48 (method url-fetch)
49 (uri (string-append "http://nodejs.org/dist/v" version
50 "/node-v" version ".tar.gz"))
51 (sha256
52 (base32
53 "1vjh9zvw7wkdz6b0l99ya7mqjk0l8lbg9isr1q8rxwp400dhkk32"))
54 (modules '((guix build utils)))
55 (snippet
56 `(begin
57 ;; Remove bundled software.
58 (for-each delete-file-recursively
59 '("deps/cares"
60 "deps/http_parser"
61 "deps/icu-small"
62 "deps/nghttp2"
63 "deps/openssl"
64 "deps/uv"
65 "deps/zlib"))
66 (substitute* "Makefile"
67 ;; Remove references to bundled software
68 (("deps/http_parser/http_parser.gyp") "")
69 (("deps/uv/include/\\*.h") "")
70 (("deps/uv/uv.gyp") "")
71 (("deps/zlib/zlib.gyp") ""))
72 #t))))
73 (build-system gnu-build-system)
74 (arguments
75 ;; TODO: Purge the bundled copies from the source.
76 '(#:configure-flags '("--shared-cares"
77 "--shared-http-parser"
78 "--shared-libuv"
79 "--shared-nghttp2"
80 "--shared-openssl"
81 "--shared-zlib"
82 "--without-snapshot"
83 "--with-intl=system-icu")
84 #:phases
85 (modify-phases %standard-phases
86 (add-before 'configure 'patch-files
87 (lambda* (#:key inputs #:allow-other-keys)
88 ;; Fix hardcoded /bin/sh references.
89 (substitute* '("lib/child_process.js"
90 "lib/internal/v8_prof_polyfill.js"
91 "test/parallel/test-child-process-spawnsync-shell.js"
92 "test/parallel/test-stdio-closed.js")
93 (("'/bin/sh'")
94 (string-append "'" (which "sh") "'")))
95
96 ;; Fix hardcoded /usr/bin/env references.
97 (substitute* '("test/parallel/test-child-process-default-options.js"
98 "test/parallel/test-child-process-env.js"
99 "test/parallel/test-child-process-exec-env.js")
100 (("'/usr/bin/env'")
101 (string-append "'" (which "env") "'")))
102
103 ;; FIXME: These tests depend on being able to install eslint.
104 ;; See https://github.com/nodejs/node/issues/17098.
105 (for-each delete-file
106 '("test/parallel/test-eslint-alphabetize-errors.js"
107 "test/parallel/test-eslint-buffer-constructor.js"
108 "test/parallel/test-eslint-documented-errors.js"
109 "test/parallel/test-eslint-inspector-check.js"))
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/async-hooks/test-ttywrap.readstream.js"
115 "test/parallel/test-util-inspect.js"
116 "test/parallel/test-v8-serdes.js"
117 "test/parallel/test-dgram-membership.js"
118 "test/parallel/test-dns-cancel-reverse-lookup.js"
119 "test/parallel/test-dns-resolveany.js"
120 "test/parallel/test-cluster-master-error.js"
121 "test/parallel/test-cluster-master-kill.js"
122 "test/parallel/test-net-listen-after-destroying-stdin.js"
123 "test/parallel/test-npm-install.js"
124 "test/sequential/test-child-process-emfile.js"
125 "test/sequential/test-benchmark-child-process.js"
126 "test/sequential/test-http-regr-gh-2928.js"))
127 #t))
128 (replace 'configure
129 ;; Node's configure script is actually a python script, so we can't
130 ;; run it with bash.
131 (lambda* (#:key outputs (configure-flags '()) inputs
132 #:allow-other-keys)
133 (let* ((prefix (assoc-ref outputs "out"))
134 (flags (cons (string-append "--prefix=" prefix)
135 configure-flags)))
136 (format #t "build directory: ~s~%" (getcwd))
137 (format #t "configure flags: ~s~%" flags)
138 ;; Node's configure script expects the CC environment variable to
139 ;; be set.
140 (setenv "CC" (string-append (assoc-ref inputs "gcc") "/bin/gcc"))
141 (zero? (apply system*
142 (string-append (assoc-ref inputs "python")
143 "/bin/python")
144 "configure" flags)))))
145 (add-after 'patch-shebangs 'patch-npm-shebang
146 (lambda* (#:key outputs #:allow-other-keys)
147 (let* ((bindir (string-append (assoc-ref outputs "out")
148 "/bin"))
149 (npm (string-append bindir "/npm"))
150 (target (readlink npm)))
151 (with-directory-excursion bindir
152 (patch-shebang target (list bindir))
153 #t)))))))
154 (native-inputs
155 `(("python" ,python-2)
156 ("perl" ,perl)
157 ("pkg-config" ,pkg-config)
158 ("procps" ,procps)
159 ("util-linux" ,util-linux)
160 ("which" ,which)))
161 (native-search-paths
162 (list (search-path-specification
163 (variable "NODE_PATH")
164 (files '("lib/node_modules")))))
165 (inputs
166 `(("c-ares" ,c-ares)
167 ("http-parser" ,http-parser)
168 ("icu4c" ,icu4c)
169 ("libuv" ,libuv)
170 ("nghttp2" ,nghttp2 "lib")
171 ("openssl" ,openssl)
172 ("zlib" ,zlib)))
173 (synopsis "Evented I/O for V8 JavaScript")
174 (description "Node.js is a platform built on Chrome's JavaScript runtime
175 for easily building fast, scalable network applications. Node.js uses an
176 event-driven, non-blocking I/O model that makes it lightweight and efficient,
177 perfect for data-intensive real-time applications that run across distributed
178 devices.")
179 (home-page "http://nodejs.org/")
180 (license expat)
181 (properties '((timeout . 3600))))) ; 1 h