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