gnu: node-lts: Update to 14.18.1 [security fixes].
[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, 2021 Marius Bakke <marius@gnu.org>
9 ;;; Copyright © 2020, 2021 Pierre Langlois <pierre.langlois@gmx.com>
10 ;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
11 ;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
12 ;;;
13 ;;; This file is part of GNU Guix.
14 ;;;
15 ;;; GNU Guix is free software; you can redistribute it and/or modify it
16 ;;; under the terms of the GNU General Public License as published by
17 ;;; the Free Software Foundation; either version 3 of the License, or (at
18 ;;; your option) any later version.
19 ;;;
20 ;;; GNU Guix is distributed in the hope that it will be useful, but
21 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;;; GNU General Public License for more details.
24 ;;;
25 ;;; You should have received a copy of the GNU General Public License
26 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
27
28 (define-module (gnu packages node)
29 #:use-module ((guix licenses) #:prefix license:)
30 #:use-module ((guix build utils) #:select (alist-replace))
31 #:use-module (guix packages)
32 #:use-module (guix derivations)
33 #:use-module (guix download)
34 #:use-module (guix git-download)
35 #:use-module (guix utils)
36 #:use-module (guix build-system gnu)
37 #:use-module (guix build-system node)
38 #:use-module (gnu packages)
39 #:use-module (gnu packages adns)
40 #:use-module (gnu packages base)
41 #:use-module (gnu packages bash)
42 #:use-module (gnu packages compression)
43 #:use-module (gnu packages gcc)
44 #:use-module (gnu packages icu4c)
45 #:use-module (gnu packages libevent)
46 #:use-module (gnu packages linux)
47 #:use-module (gnu packages node-xyz)
48 #:use-module (gnu packages perl)
49 #:use-module (gnu packages pkg-config)
50 #:use-module (gnu packages python)
51 #:use-module (gnu packages tls)
52 #:use-module (gnu packages web)
53 #:use-module (ice-9 match)
54 #:use-module (srfi srfi-26))
55
56 (define-public node
57 (package
58 (name "node")
59 (version "10.24.0")
60 (source (origin
61 (method url-fetch)
62 (uri (string-append "https://nodejs.org/dist/v" version
63 "/node-v" version ".tar.xz"))
64 (sha256
65 (base32
66 "1k1srdis23782hnd1ymgczs78x9gqhv77v0am7yb54gqcspp70hm"))
67 (modules '((guix build utils)))
68 (snippet
69 `(begin
70 ;; Patch for compatibility with ICU 68 and newer, which
71 ;; removed the public TRUE and FALSE macros.
72 (substitute* '("deps/v8/src/objects/intl-objects.cc"
73 "deps/v8/src/runtime/runtime-intl.cc")
74 (("TRUE") "true")
75 (("FALSE") "false"))
76
77 ;; Remove bundled software.
78 (for-each delete-file-recursively
79 '("deps/cares"
80 "deps/http_parser"
81 "deps/icu-small"
82 "deps/nghttp2"
83 "deps/openssl"
84 "deps/uv"
85 "deps/zlib"))
86 (substitute* "Makefile"
87 ;; Remove references to bundled software.
88 (("deps/http_parser/http_parser.gyp") "")
89 (("deps/uv/include/\\*.h") "")
90 (("deps/uv/uv.gyp") "")
91 (("deps/zlib/zlib.gyp") ""))
92 #t))))
93 (build-system gnu-build-system)
94 (arguments
95 `(#:configure-flags '("--shared-cares"
96 "--shared-http-parser"
97 "--shared-libuv"
98 "--shared-nghttp2"
99 "--shared-openssl"
100 "--shared-zlib"
101 "--without-snapshot"
102 "--with-intl=system-icu")
103 ;; Run only the CI tests. The default test target requires additional
104 ;; add-ons from NPM that are not distributed with the source.
105 #:test-target "test-ci-js"
106 #:phases
107 (modify-phases %standard-phases
108 (add-before 'configure 'patch-files
109 (lambda* (#:key inputs #:allow-other-keys)
110 ;; Fix hardcoded /bin/sh references.
111 (substitute* '("lib/child_process.js"
112 "lib/internal/v8_prof_polyfill.js"
113 "test/parallel/test-child-process-spawnsync-shell.js"
114 "test/parallel/test-stdio-closed.js"
115 "test/sequential/test-child-process-emfile.js")
116 (("'/bin/sh'")
117 (string-append "'" (assoc-ref inputs "bash") "/bin/sh'")))
118
119 ;; Fix hardcoded /usr/bin/env references.
120 (substitute* '("test/parallel/test-child-process-default-options.js"
121 "test/parallel/test-child-process-env.js"
122 "test/parallel/test-child-process-exec-env.js")
123 (("'/usr/bin/env'")
124 (string-append "'" (assoc-ref inputs "coreutils")
125 "/bin/env'")))
126
127 ;; FIXME: These tests fail in the build container, but they don't
128 ;; seem to be indicative of real problems in practice.
129 (for-each delete-file
130 '("test/parallel/test-cluster-master-error.js"
131 "test/parallel/test-cluster-master-kill.js"
132 ;; See also <https://github.com/nodejs/node/issues/25903>.
133 "test/sequential/test-performance.js"))
134
135 ;; This requires a DNS resolver.
136 (delete-file "test/parallel/test-dns.js")
137
138 ;; FIXME: This test fails randomly:
139 ;; https://github.com/nodejs/node/issues/31213
140 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
141
142 ;; FIXME: These tests fail on armhf-linux:
143 ;; https://github.com/nodejs/node/issues/31970
144 ,@(if (string-prefix? "arm" (%current-system))
145 '((for-each delete-file
146 '("test/parallel/test-zlib.js"
147 "test/parallel/test-zlib-brotli.js"
148 "test/parallel/test-zlib-brotli-flush.js"
149 "test/parallel/test-zlib-brotli-from-brotli.js"
150 "test/parallel/test-zlib-brotli-from-string.js"
151 "test/parallel/test-zlib-convenience-methods.js"
152 "test/parallel/test-zlib-random-byte-pipes.js"
153 "test/parallel/test-zlib-write-after-flush.js")))
154 '())
155
156 ;; These tests have an expiry date: they depend on the validity of
157 ;; TLS certificates that are bundled with the source. We want this
158 ;; package to be reproducible forever, so remove those.
159 ;; TODO: Regenerate certs instead.
160 (for-each delete-file
161 '("test/parallel/test-tls-passphrase.js"
162 "test/parallel/test-tls-server-verify.js"))))
163 (add-before 'configure 'set-bootstrap-host-rpath
164 (lambda* (#:key native-inputs inputs #:allow-other-keys)
165 (let* ((inputs (or native-inputs inputs))
166 (c-ares (assoc-ref inputs "c-ares"))
167 (http-parser (assoc-ref inputs "http-parser"))
168 (icu4c (assoc-ref inputs "icu4c"))
169 (nghttp2 (assoc-ref inputs "nghttp2"))
170 (openssl (assoc-ref inputs "openssl"))
171 (libuv (assoc-ref inputs "libuv"))
172 (zlib (assoc-ref inputs "zlib")))
173 (substitute* "deps/v8/gypfiles/v8.gyp"
174 (("'target_name': 'torque'," target)
175 (string-append target
176 "'ldflags': ['-Wl,-rpath="
177 c-ares "/lib:"
178 http-parser "/lib:"
179 icu4c "/lib:"
180 nghttp2 "/lib:"
181 openssl "/lib:"
182 libuv "/lib:"
183 zlib "/lib"
184 "'],"))))))
185 (replace 'configure
186 ;; Node's configure script is actually a python script, so we can't
187 ;; run it with bash.
188 (lambda* (#:key outputs (configure-flags '()) native-inputs inputs
189 #:allow-other-keys)
190 (let* ((prefix (assoc-ref outputs "out"))
191 (xflags ,(if (%current-target-system)
192 `'("--cross-compiling"
193 ,(string-append
194 "--dest-cpu="
195 (match (%current-target-system)
196 ((? (cut string-prefix? "arm" <>))
197 "arm")
198 ((? (cut string-prefix? "aarch64" <>))
199 "arm64")
200 ((? (cut string-prefix? "i686" <>))
201 "ia32")
202 ((? (cut string-prefix? "x86_64" <>))
203 "x64")
204 ((? (cut string-prefix? "powerpc64" <>))
205 "ppc64")
206 (_ "unsupported"))))
207 ''()))
208 (flags (cons (string-append "--prefix=" prefix)
209 (append xflags configure-flags))))
210 (format #t "build directory: ~s~%" (getcwd))
211 (format #t "configure flags: ~s~%" flags)
212 ;; Node's configure script expects the CC environment variable to
213 ;; be set.
214 (setenv "CC_host" "gcc")
215 (setenv "CXX_host" "g++")
216 (setenv "CC" ,(cc-for-target))
217 (setenv "CXX" ,(cxx-for-target))
218 (setenv "PKG_CONFIG" ,(pkg-config-for-target))
219 (apply invoke
220 (string-append (assoc-ref (or native-inputs inputs)
221 "python")
222 "/bin/python")
223 "configure" flags))))
224 (add-after 'patch-shebangs 'patch-npm-shebang
225 (lambda* (#:key outputs #:allow-other-keys)
226 (let* ((bindir (string-append (assoc-ref outputs "out")
227 "/bin"))
228 (npm (string-append bindir "/npm"))
229 (target (readlink npm)))
230 (with-directory-excursion bindir
231 (patch-shebang target (list bindir))))))
232 (add-after 'install 'patch-node-shebang
233 (lambda* (#:key outputs #:allow-other-keys)
234 (let* ((bindir (string-append (assoc-ref outputs "out")
235 "/bin"))
236 (npx (readlink (string-append bindir "/npx"))))
237 (with-directory-excursion bindir
238 (patch-shebang npx (list bindir)))))))))
239 (native-inputs
240 `(;; Runtime dependencies for binaries used as a bootstrap.
241 ("c-ares" ,c-ares)
242 ("http-parser" ,http-parser)
243 ("icu4c" ,icu4c)
244 ("libuv" ,libuv)
245 ("nghttp2" ,nghttp2 "lib")
246 ("openssl" ,openssl)
247 ("zlib" ,zlib)
248 ;; Regular build-time dependencies.
249 ("perl" ,perl)
250 ("pkg-config" ,pkg-config)
251 ("procps" ,procps)
252 ("python" ,python-2)
253 ("util-linux" ,util-linux)))
254 (native-search-paths
255 (list (search-path-specification
256 (variable "NODE_PATH")
257 (files '("lib/node_modules")))))
258 (inputs
259 `(("bash" ,bash)
260 ("coreutils" ,coreutils)
261 ("c-ares" ,c-ares)
262 ("http-parser" ,http-parser)
263 ("icu4c" ,icu4c)
264 ("libuv" ,libuv)
265 ("nghttp2" ,nghttp2 "lib")
266 ("openssl" ,openssl)
267 ("zlib" ,zlib)))
268 (synopsis "Evented I/O for V8 JavaScript")
269 (description "Node.js is a platform built on Chrome's JavaScript runtime
270 for easily building fast, scalable network applications. Node.js uses an
271 event-driven, non-blocking I/O model that makes it lightweight and efficient,
272 perfect for data-intensive real-time applications that run across distributed
273 devices.")
274 (home-page "https://nodejs.org/")
275 (license license:expat)
276 (properties '((max-silent-time . 7200) ;2h, needed on ARM
277 (timeout . 21600) ;6h
278 (cpe-name . "node.js")))))
279
280 ;; This should be the latest version of node that still builds without
281 ;; depending on llhttp.
282 (define-public node-bootstrap
283 (hidden-package node))
284
285 ;; Duplicate of node-semver
286 (define-public node-semver-bootstrap
287 (package
288 (name "node-semver")
289 (version "7.2.1")
290 (source (origin
291 (method git-fetch)
292 (uri (git-reference
293 (url "https://github.com/npm/node-semver")
294 (commit (string-append "v" version))))
295 (file-name (git-file-name name version))
296 (sha256
297 (base32
298 "06biknqb05r9xsmcflm3ygh50pjvdk84x6r79w43kmck4fn3qn5p"))))
299 (build-system node-build-system)
300 (arguments
301 `(#:node ,node-bootstrap
302 #:tests? #f
303 #:phases
304 (modify-phases %standard-phases
305 (delete 'configure))))
306 (home-page "https://github.com/npm/node-semver")
307 (properties '((hidden? . #t)))
308 (synopsis "Parses semantic versions strings")
309 (description
310 "@code{node-semver} is a JavaScript implementation of the
311 @uref{https://semver.org/, SemVer.org} specification.")
312 (license license:isc)))
313
314 (define-public node-ms-bootstrap
315 (package
316 (name "node-ms")
317 (version "2.1.2")
318 (source
319 (origin
320 (method git-fetch)
321 (uri (git-reference
322 (url "https://github.com/vercel/ms.git")
323 (commit version)))
324 (file-name (git-file-name name version))
325 (sha256
326 (base32
327 "1pjxzbi4j8pinlsc7yxvfrh0b47kb2dc4lfc2rjq4wx5bdwl33fj"))))
328 (build-system node-build-system)
329 (arguments
330 `(#:node ,node-bootstrap
331 #:tests? #f
332 #:phases
333 (modify-phases %standard-phases
334 (delete 'configure))))
335 (home-page "https://github.com/zeit/ms#readme")
336 (properties '((hidden? . #t)))
337 (synopsis "Tiny millisecond conversion utility")
338 (description "Use this package to easily convert various time
339 formats to milliseconds.")
340 (license license:expat)))
341
342 (define-public node-binary-search-bootstrap
343 (package
344 (name "node-binary-search")
345 (version "1.3.6")
346 (source
347 (origin
348 (method git-fetch)
349 (uri (git-reference
350 (url "https://github.com/darkskyapp/binary-search.git")
351 (commit (string-append "v" version))))
352 (file-name (git-file-name name version))
353 (sha256
354 (base32
355 "1xr2msdc143cd3xwgq7n3rhzy7j8wrnaidxl0r6l6b6g3mpbpjig"))))
356 (build-system node-build-system)
357 (arguments
358 `(#:node ,node-bootstrap
359 #:tests? #f
360 #:phases
361 (modify-phases %standard-phases
362 (delete 'configure))))
363 (home-page "https://github.com/darkskyapp/binary-search#readme")
364 (properties '((hidden? . #t)))
365 (synopsis "Tiny binary search function with comparators")
366 (description "This package is a binary search function for Node.js.")
367 (license license:cc0)))
368
369 (define-public node-debug-bootstrap
370 (package
371 (name "node-debug")
372 (version "4.3.0")
373 (source
374 (origin
375 (method git-fetch)
376 (uri (git-reference
377 (url "https://github.com/visionmedia/debug.git")
378 (commit version)))
379 (file-name (git-file-name name version))
380 (sha256
381 (base32
382 "08g52r1d4yqcsfdfb7n5if33d4cghaq75gx5n9hj6m6fd8jfp2pi"))))
383 (build-system node-build-system)
384 (arguments
385 `(#:node ,node-bootstrap
386 #:tests? #f
387 #:phases
388 (modify-phases %standard-phases
389 (delete 'configure))))
390 (inputs `(("node-ms" ,node-ms-bootstrap)))
391 (home-page "https://github.com/visionmedia/debug#readme")
392 (properties '((hidden? . #t)))
393 (synopsis "Small debugging utility")
394 (description "This package contains a tiny JavaScript debugging
395 utility modelled after Node.js core's debugging technique. It works in
396 Node.js and web browsers.")
397 (license license:expat)))
398
399 (define-public node-llparse-builder-bootstrap
400 (package
401 (name "node-llparse-builder")
402 (version "1.5.2")
403 (source
404 (origin
405 (method git-fetch)
406 (uri (git-reference
407 (url "https://github.com/indutny/llparse-builder.git")
408 (commit (string-append "v" version))))
409 (file-name (git-file-name name version))
410 (sha256
411 (base32
412 "0r82iiwqsb73k2fxw7842rjjiixllxpyc6yl9cq4ma6ybkf6xmzm"))
413 (modules '((guix build utils)))
414 (snippet
415 '(begin
416 ;; FIXME: Unneeded runtime dependency.
417 ;; https://github.com/indutny/llparse-builder/pull/2
418 (substitute* "package.json"
419 (("\"@types/debug.*,") ""))
420 ;; Fix imports for esbuild.
421 ;; https://github.com/evanw/esbuild/issues/477
422 (substitute* '("src/node/invoke.ts"
423 "src/node/base.ts"
424 "src/node/consume.ts"
425 "src/node/match.ts"
426 "src/node/error.ts"
427 "src/node/pause.ts"
428 "src/edge.ts"
429 "src/utils.ts"
430 "src/loop-checker/index.ts"
431 "src/loop-checker/lattice.ts"
432 "src/code/field.ts"
433 "src/span-allocator.ts")
434 (("\\* as assert") "assert")
435 (("\\* as debugAPI") "debugAPI"))
436 #t))))
437 (build-system node-build-system)
438 (arguments
439 `(#:node ,node-bootstrap
440 #:tests? #f
441 #:phases
442 (modify-phases %standard-phases
443 (delete 'configure)
444 (replace 'build
445 (lambda* (#:key inputs #:allow-other-keys)
446 (let ((esbuild (string-append (assoc-ref inputs "esbuild")
447 "/bin/esbuild")))
448 (invoke esbuild
449 "--platform=node"
450 "--outfile=lib/builder.js"
451 "--bundle"
452 "src/builder.ts")))))))
453 (inputs
454 `(("node-binary-search" ,node-binary-search-bootstrap)
455 ("node-debug" ,node-debug-bootstrap)))
456 (native-inputs
457 `(("esbuild" ,esbuild)))
458 (home-page "https://github.com/indutny/llparse-builder#readme")
459 (properties '((hidden? . #t)))
460 (synopsis "Graph builder for consumption by llparse")
461 (description "This package builds graphs for consumption by llparse.")
462 (license license:expat)))
463
464 (define-public node-llparse-frontend-bootstrap
465 (package
466 (name "node-llparse-frontend")
467 (version "3.0.0")
468 (source
469 (origin
470 (method git-fetch)
471 (uri (git-reference
472 (url "https://github.com/indutny/llparse-frontend.git")
473 (commit (string-append "v" version))))
474 (file-name (git-file-name name version))
475 (sha256
476 (base32 "1rm9g4ifyip30svm5cgnf0gx7d45jgh4mpf2hkd092xhngmfvicc"))
477 (modules '((guix build utils)))
478 (snippet
479 '(begin
480 ;; Fix imports for esbuild.
481 ;; https://github.com/evanw/esbuild/issues/477
482 (substitute* '("src/frontend.ts"
483 "src/code/field-value.ts"
484 "src/container/index.ts"
485 "src/container/wrap.ts"
486 "src/node/sequence.ts"
487 "src/node/single.ts"
488 "src/node/table-lookup.ts"
489 "src/trie/index.ts")
490 (("\\* as assert") "assert")
491 (("\\* as debugAPI") "debugAPI"))
492 #t))))
493 (build-system node-build-system)
494 (arguments
495 `(#:node ,node-bootstrap
496 #:tests? #f
497 #:phases
498 (modify-phases %standard-phases
499 (delete 'configure)
500 (replace 'build
501 (lambda* (#:key inputs #:allow-other-keys)
502 (let ((esbuild (string-append (assoc-ref inputs "esbuild")
503 "/bin/esbuild")))
504 (invoke esbuild
505 "--platform=node"
506 "--outfile=lib/frontend.js"
507 "--bundle"
508 "src/frontend.ts")))))))
509 (inputs
510 `(("node-debug" ,node-debug-bootstrap)
511 ("node-llparse-builder" ,node-llparse-builder-bootstrap)))
512 (native-inputs
513 `(("esbuild" ,esbuild)))
514 (home-page "https://github.com/indutny/llparse-frontend#readme")
515 (properties '((hidden? . #t)))
516 (synopsis "Frontend for the llparse compiler")
517 (description "This package is a frontend for the llparse compiler.")
518 (license license:expat)))
519
520 (define-public node-llparse-bootstrap
521 (package
522 (name "node-llparse")
523 (version "7.1.0")
524 (source
525 (origin
526 (method git-fetch)
527 (uri (git-reference
528 (url "https://github.com/indutny/llparse.git")
529 (commit (string-append "v" version))))
530 (file-name (git-file-name name version))
531 (sha256
532 (base32
533 "10da273iy2if88hp79cwms6c8qpsl1fkgzll6gmqyx5yxv5mkyp6"))
534 (modules '((guix build utils)))
535 (snippet
536 '(begin
537 ;; Fix imports for esbuild.
538 ;; https://github.com/evanw/esbuild/issues/477
539 (substitute* '("src/compiler/index.ts"
540 "src/implementation/c/node/base.ts"
541 "src/implementation/c/node/table-lookup.ts"
542 "src/implementation/c/compilation.ts"
543 "src/implementation/c/helpers/match-sequence.ts"
544 "src/implementation/c/code/mul-add.ts")
545 (("\\* as assert") "assert")
546 (("\\* as debugAPI") "debugAPI"))
547 #t))))
548 (build-system node-build-system)
549 (arguments
550 `(#:node ,node-bootstrap
551 #:tests? #f
552 #:phases
553 (modify-phases %standard-phases
554 (delete 'configure)
555 (replace 'build
556 (lambda* (#:key inputs #:allow-other-keys)
557 (let ((esbuild (string-append (assoc-ref inputs "esbuild")
558 "/bin/esbuild")))
559 (invoke esbuild
560 "--platform=node"
561 "--outfile=lib/api.js"
562 "--bundle"
563 "src/api.ts")))))))
564 (inputs
565 `(("node-debug" ,node-debug-bootstrap)
566 ("node-llparse-frontend" ,node-llparse-frontend-bootstrap)))
567 (native-inputs
568 `(("esbuild" ,esbuild)))
569 (home-page "https://github.com/nodejs/llparse#readme")
570 (properties '((hidden? . #t)))
571 (synopsis "Compile incremental parsers to C code")
572 (description "This package offers an API for compiling an incremental
573 parser definition into a C output.")
574 (license license:expat)))
575
576 (define-public llhttp-bootstrap
577 (package
578 (name "llhttp")
579 (version "2.1.4")
580 (source (origin
581 (method git-fetch)
582 (uri (git-reference
583 (url "https://github.com/nodejs/llhttp.git")
584 (commit (string-append "v" version))))
585 (file-name (git-file-name name version))
586 (sha256
587 (base32
588 "115mwyds9655p76lhglxg2blc1ksgrix6zhigaxnc2q6syy3pa6x"))
589 (patches (search-patches "llhttp-bootstrap-CVE-2020-8287.patch"))
590 (modules '((guix build utils)))
591 (snippet
592 '(begin
593 ;; Fix imports for esbuild.
594 ;; https://github.com/evanw/esbuild/issues/477
595 (substitute* "src/llhttp/http.ts"
596 (("\\* as assert") "assert"))
597 (substitute* "Makefile"
598 (("npx ts-node bin/generate.ts")
599 "node bin/generate.js"))
600 #t))))
601 (build-system gnu-build-system)
602 (arguments
603 `(#:tests? #f ; no tests
604 #:make-flags (list (string-append "CLANG=" ,(cc-for-target))
605 (string-append "DESTDIR=" (assoc-ref %outputs "out"))
606 "PREFIX=")
607 #:phases
608 (modify-phases %standard-phases
609 (replace 'configure
610 (lambda* (#:key native-inputs inputs #:allow-other-keys)
611 (let ((esbuild (string-append
612 (assoc-ref (or native-inputs inputs) "esbuild")
613 "/bin/esbuild")))
614 (invoke esbuild
615 "--platform=node"
616 "--outfile=bin/generate.js"
617 "--bundle" "bin/generate.ts"))))
618 (add-before 'install 'create-install-directories
619 (lambda* (#:key outputs #:allow-other-keys)
620 (let ((out (assoc-ref outputs "out")))
621 (for-each (lambda (dir)
622 (mkdir-p (string-append out dir)))
623 (list "/lib" "/include" "/src"))
624 #t)))
625 (add-after 'install 'install-src
626 (lambda* (#:key outputs #:allow-other-keys)
627 (let* ((out (assoc-ref outputs "out"))
628 (src-dir (string-append out "/src")))
629 (install-file "build/c/llhttp.c" src-dir)
630 (install-file "src/native/api.c" src-dir)
631 (install-file "src/native/http.c" src-dir)
632 #t))))))
633 (native-inputs
634 `(("esbuild" ,esbuild)
635 ("node" ,node-bootstrap)
636 ("node-semver" ,node-semver-bootstrap)
637 ("node-llparse-bootstrap" ,node-llparse-bootstrap)))
638 (home-page "https://github.com/nodejs/llhttp")
639 (properties '((hidden? . #t)))
640 (synopsis "Parser for HTTP messages")
641 (description "This is a rewrite of
642 @url{https://github.com/nodejs/http-parser, http-parser} using
643 @url{https://github.com/nodejs/llparse, llparse} to generate the C
644 source files.")
645 (license license:expat)))
646
647 (define-public node-lts
648 (package
649 (inherit node)
650 (version "14.18.1")
651 (source (origin
652 (method url-fetch)
653 (uri (string-append "https://nodejs.org/dist/v" version
654 "/node-v" version ".tar.xz"))
655 (sha256
656 (base32
657 "1vc9rypkgr5i5y946jnyr9jjpydxvm74p1s17rg2zayzvlddg89z"))
658 (modules '((guix build utils)))
659 (snippet
660 `(begin
661 ;; Remove bundled software, where possible
662 (for-each delete-file-recursively
663 '("deps/cares"
664 "deps/icu-small"
665 "deps/nghttp2"
666 "deps/openssl"
667 "deps/zlib"))
668 (substitute* "Makefile"
669 ;; Remove references to bundled software.
670 (("deps/uv/uv.gyp") "")
671 (("deps/zlib/zlib.gyp") ""))
672 #t))))
673 (arguments
674 (substitute-keyword-arguments (package-arguments node)
675 ((#:configure-flags configure-flags)
676 ''("--shared-cares"
677 "--shared-libuv"
678 "--shared-nghttp2"
679 "--shared-openssl"
680 "--shared-zlib"
681 "--shared-brotli"
682 "--with-intl=system-icu"))
683 ((#:phases phases)
684 `(modify-phases ,phases
685 (replace 'set-bootstrap-host-rpath
686 (lambda* (#:key native-inputs inputs #:allow-other-keys)
687 (let* ((inputs (or native-inputs inputs))
688 (c-ares (assoc-ref inputs "c-ares"))
689 (brotli (assoc-ref inputs "brotli"))
690 (icu4c (assoc-ref inputs "icu4c"))
691 (nghttp2 (assoc-ref inputs "nghttp2"))
692 (openssl (assoc-ref inputs "openssl"))
693 (libuv (assoc-ref inputs "libuv"))
694 (zlib (assoc-ref inputs "zlib"))
695 (host-binaries '("torque"
696 "bytecode_builtins_list_generator"
697 "gen-regexp-special-case"
698 "node_mksnapshot"
699 "mksnapshot")))
700 (substitute* '("node.gyp" "tools/v8_gypfiles/v8.gyp")
701 (((string-append "'target_name': '("
702 (string-join host-binaries "|")
703 ")',")
704 target)
705 (string-append target
706 "'ldflags': ['-Wl,-rpath="
707 c-ares "/lib:"
708 brotli "/lib:"
709 icu4c "/lib:"
710 nghttp2 "/lib:"
711 openssl "/lib:"
712 libuv "/lib:"
713 zlib "/lib"
714 "'],"))))))
715 (replace 'configure
716 ;; Node's configure script is actually a python script, so we can't
717 ;; run it with bash.
718 (lambda* (#:key outputs (configure-flags '()) native-inputs inputs
719 #:allow-other-keys)
720 (let* ((prefix (assoc-ref outputs "out"))
721 (xflags ,(if (%current-target-system)
722 `'("--cross-compiling"
723 ,(string-append
724 "--dest-cpu="
725 (match (%current-target-system)
726 ((? (cut string-prefix? "arm" <>))
727 "arm")
728 ((? (cut string-prefix? "aarch64" <>))
729 "arm64")
730 ((? (cut string-prefix? "i686" <>))
731 "ia32")
732 ((? (cut string-prefix? "x86_64" <>))
733 "x64")
734 ((? (cut string-prefix? "powerpc64" <>))
735 "ppc64")
736 (_ "unsupported"))))
737 ''()))
738 (flags (cons
739 (string-append "--prefix=" prefix)
740 (append xflags configure-flags))))
741 (format #t "build directory: ~s~%" (getcwd))
742 (format #t "configure flags: ~s~%" flags)
743 ;; Node's configure script expects the CC environment variable to
744 ;; be set.
745 (setenv "CC_host" "gcc")
746 (setenv "CXX_host" "g++")
747 (setenv "CC" ,(cc-for-target))
748 (setenv "CXX" ,(cxx-for-target))
749 (setenv "PKG_CONFIG" ,(pkg-config-for-target))
750 (apply invoke
751 (string-append (assoc-ref (or native-inputs inputs)
752 "python")
753 "/bin/python3")
754 "configure" flags))))
755 (replace 'patch-files
756 (lambda* (#:key inputs #:allow-other-keys)
757 ;; Fix hardcoded /bin/sh references.
758 (substitute* '("lib/child_process.js"
759 "lib/internal/v8_prof_polyfill.js"
760 "test/parallel/test-child-process-spawnsync-shell.js"
761 "test/parallel/test-fs-write-sigxfsz.js"
762 "test/parallel/test-stdio-closed.js"
763 "test/sequential/test-child-process-emfile.js")
764 (("'/bin/sh'")
765 (string-append "'" (assoc-ref inputs "bash") "/bin/sh'")))
766
767 ;; Fix hardcoded /usr/bin/env references.
768 (substitute* '("test/parallel/test-child-process-default-options.js"
769 "test/parallel/test-child-process-env.js"
770 "test/parallel/test-child-process-exec-env.js")
771 (("'/usr/bin/env'")
772 (string-append "'" (assoc-ref inputs "coreutils")
773 "/bin/env'")))
774
775 ;; FIXME: These tests fail in the build container, but they don't
776 ;; seem to be indicative of real problems in practice.
777 (for-each delete-file
778 '("test/parallel/test-cluster-master-error.js"
779 "test/parallel/test-cluster-master-kill.js"))
780
781 ;; These require a DNS resolver.
782 (for-each delete-file
783 '("test/parallel/test-dns.js"
784 "test/parallel/test-dns-lookupService-promises.js"))
785
786 ;; These tests require networking.
787 (delete-file "test/parallel/test-https-agent-unref-socket.js")
788
789 ;; FIXME: This test fails randomly:
790 ;; https://github.com/nodejs/node/issues/31213
791 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
792
793 ;; FIXME: These tests fail on armhf-linux:
794 ;; https://github.com/nodejs/node/issues/31970
795 ,@(if (target-arm32?)
796 '((for-each delete-file
797 '("test/parallel/test-zlib.js"
798 "test/parallel/test-zlib-brotli.js"
799 "test/parallel/test-zlib-brotli-flush.js"
800 "test/parallel/test-zlib-brotli-from-brotli.js"
801 "test/parallel/test-zlib-brotli-from-string.js"
802 "test/parallel/test-zlib-convenience-methods.js"
803 "test/parallel/test-zlib-random-byte-pipes.js"
804 "test/parallel/test-zlib-write-after-flush.js")))
805 '())
806
807 ;; These tests have an expiry date: they depend on the validity of
808 ;; TLS certificates that are bundled with the source. We want this
809 ;; package to be reproducible forever, so remove those.
810 ;; TODO: Regenerate certs instead.
811 (for-each delete-file
812 '("test/parallel/test-tls-passphrase.js"
813 "test/parallel/test-tls-server-verify.js"))
814
815 ;; Replace pre-generated llhttp sources
816 (let ((llhttp (assoc-ref inputs "llhttp")))
817 (copy-file (string-append llhttp "/src/llhttp.c")
818 "deps/llhttp/src/llhttp.c")
819 (copy-file (string-append llhttp "/src/api.c")
820 "deps/llhttp/src/api.c")
821 (copy-file (string-append llhttp "/src/http.c")
822 "deps/llhttp/src/http.c")
823 (copy-file (string-append llhttp "/include/llhttp.h")
824 "deps/llhttp/include/llhttp.h"))))))))
825 (native-inputs
826 `(;; Runtime dependencies for binaries used as a bootstrap.
827 ("c-ares" ,c-ares-for-node)
828 ("brotli" ,brotli)
829 ("icu4c" ,icu4c-67)
830 ("libuv" ,libuv-for-node)
831 ("nghttp2" ,nghttp2 "lib")
832 ("openssl" ,openssl)
833 ("zlib" ,zlib)
834 ;; Regular build-time dependencies.
835 ("perl" ,perl)
836 ("pkg-config" ,pkg-config)
837 ("procps" ,procps)
838 ("python" ,python)
839 ("util-linux" ,util-linux)))
840 (inputs
841 `(("bash" ,bash)
842 ("coreutils" ,coreutils)
843 ("c-ares" ,c-ares-for-node)
844 ("icu4c" ,icu4c-67)
845 ("libuv" ,libuv-for-node)
846 ("llhttp" ,llhttp-bootstrap)
847 ("brotli" ,brotli)
848 ("nghttp2" ,nghttp2 "lib")
849 ("openssl" ,openssl)
850 ("zlib" ,zlib)))))
851
852 (define-public libnode
853 (package/inherit node
854 (name "libnode")
855 (arguments
856 (substitute-keyword-arguments (package-arguments node)
857 ((#:configure-flags flags ''())
858 `(cons* "--shared" "--without-npm" ,flags))
859 ((#:phases phases '%standard-phases)
860 `(modify-phases ,phases
861 (delete 'patch-npm-shebang)
862 (delete 'patch-node-shebang)))))))