projects/guix·blob version-1.4.0 · refs

901 lines · 38.0 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014 Cyrill Schenkel <[email protected]>
3;;; Copyright © 2015 Andreas Enge <[email protected]>
4;;; Copyright © 2015, 2016 David Thompson <[email protected]>
5;;; Copyright © 2016, 2021 Ludovic Courtès <[email protected]>
6;;; Copyright © 2017 Mike Gerwitz <[email protected]>
7;;; Copyright © 2018 Tobias Geerinckx-Rice <[email protected]>
8;;; Copyright © 2018-2022 Marius Bakke <[email protected]>
9;;; Copyright © 2020, 2021 Pierre Langlois <[email protected]>
10;;; Copyright © 2020 Ricardo Wurmus <[email protected]>
11;;; Copyright © 2021 Simon Tournier <[email protected]>
12;;; Copyright © 2021 Guillaume Le Vaillant <[email protected]>
13;;; Copyright © 2021, 2022 Philip McGrath <[email protected]>
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 "'" (search-input-file inputs "/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 #:unwind? #t))
250 "configure"
251 flags))))
252 (add-after 'patch-shebangs 'patch-nested-shebangs
253 (lambda* (#:key inputs outputs #:allow-other-keys)
254 ;; Based on the implementation of patch-shebangs
255 ;; from (guix build gnu-build-system).
256 (let ((path (append-map (match-lambda
257 ((_ . dir)
258 (list (string-append dir "/bin")
259 (string-append dir "/sbin")
260 (string-append dir "/libexec"))))
261 (append outputs inputs))))
262 (for-each
263 (lambda (file)
264 (patch-shebang file path))
265 (find-files (search-input-directory outputs "lib/node_modules")
266 (lambda (file stat)
267 (executable-file? file))
268 #:stat lstat)))))
269 (add-after 'install 'install-npmrc
270 ;; Note: programs like node-gyp only receive these values if
271 ;; they are started via `npm` or `npx`.
272 ;; See: https://github.com/nodejs/node-gyp#npm-configuration
273 (lambda* (#:key outputs #:allow-other-keys)
274 (let* ((out (assoc-ref outputs "out")))
275 (with-output-to-file
276 ;; Use the config file "primarily for distribution
277 ;; maintainers" rather than "{prefix}/etc/npmrc",
278 ;; especially because node-build-system uses --prefix
279 ;; to install things to their store paths:
280 (string-append out "/lib/node_modules/npm/npmrc")
281 (lambda ()
282 ;; Tell npm (mostly node-gyp) where to find our
283 ;; installed headers so it doesn't try to
284 ;; download them from the internet:
285 (format #t "nodedir=~a\n" out)))))))))
286 (native-inputs
287 ;; Runtime dependencies for binaries used as a bootstrap.
288 (list c-ares
289 http-parser
290 icu4c
291 libuv
292 `(,nghttp2 "lib")
293 openssl-1.1
294 zlib
295 ;; Regular build-time dependencies.
296 perl
297 pkg-config
298 procps
299 python-2
300 util-linux))
301 (native-search-paths
302 (list (search-path-specification
303 (variable "NODE_PATH")
304 (files '("lib/node_modules")))))
305 (inputs
306 (list bash-minimal
307 coreutils
308 c-ares
309 http-parser
310 icu4c
311 libuv
312 `(,nghttp2 "lib")
313 openssl
314 python-wrapper ;for node-gyp (supports python3)
315 zlib))
316 (synopsis "Evented I/O for V8 JavaScript")
317 (description
318 "Node.js is a platform built on Chrome's JavaScript runtime
319for easily building fast, scalable network applications. Node.js uses an
320event-driven, non-blocking I/O model that makes it lightweight and efficient,
321perfect for data-intensive real-time applications that run across distributed
322devices.")
323 (home-page "https://nodejs.org/")
324 (license license:expat)
325 (properties '((max-silent-time . 7200) ;2h, needed on ARM
326 (timeout . 21600) ;6h
327 (cpe-name . "node.js")))))
328
329;; This should be the latest version of node that still builds without
330;; depending on llhttp.
331(define-public node-bootstrap
332 (hidden-package node))
333
334;; Duplicate of node-semver
335(define-public node-semver-bootstrap
336 (package
337 (name "node-semver")
338 (version "7.2.1")
339 (source (origin
340 (method git-fetch)
341 (uri (git-reference
342 (url "https://github.com/npm/node-semver")
343 (commit (string-append "v" version))))
344 (file-name (git-file-name name version))
345 (sha256
346 (base32
347 "06biknqb05r9xsmcflm3ygh50pjvdk84x6r79w43kmck4fn3qn5p"))))
348 (build-system node-build-system)
349 (arguments
350 `(#:node ,node-bootstrap
351 #:tests? #f
352 #:phases
353 (modify-phases %standard-phases
354 (add-after 'patch-dependencies 'delete-dependencies
355 (lambda args
356 (delete-dependencies '("tap")))))))
357 (home-page "https://github.com/npm/node-semver")
358 (properties '((hidden? . #t)))
359 (synopsis "Parses semantic versions strings")
360 (description
361 "@code{node-semver} is a JavaScript implementation of the
362@uref{https://semver.org/, SemVer.org} specification.")
363 (license license:isc)))
364
365(define-public node-ms-bootstrap
366 (package
367 (name "node-ms")
368 (version "2.1.2")
369 (source
370 (origin
371 (method git-fetch)
372 (uri (git-reference
373 (url "https://github.com/vercel/ms.git")
374 (commit version)))
375 (file-name (git-file-name name version))
376 (sha256
377 (base32
378 "1pjxzbi4j8pinlsc7yxvfrh0b47kb2dc4lfc2rjq4wx5bdwl33fj"))))
379 (build-system node-build-system)
380 (arguments
381 `(#:node ,node-bootstrap
382 #:tests? #f
383 #:phases
384 (modify-phases %standard-phases
385 (add-after 'patch-dependencies 'delete-dependencies
386 (lambda args
387 (delete-dependencies '("eslint"
388 "expect.js"
389 "husky"
390 "lint-staged"
391 "mocha")))))))
392 (home-page "https://github.com/zeit/ms#readme")
393 (properties '((hidden? . #t)))
394 (synopsis "Tiny millisecond conversion utility")
395 (description "Use this package to easily convert various time
396formats to milliseconds.")
397 (license license:expat)))
398
399(define-public node-binary-search-bootstrap
400 (package
401 (name "node-binary-search")
402 (version "1.3.6")
403 (source
404 (origin
405 (method git-fetch)
406 (uri (git-reference
407 (url "https://github.com/darkskyapp/binary-search.git")
408 (commit (string-append "v" version))))
409 (file-name (git-file-name name version))
410 (sha256
411 (base32
412 "1xr2msdc143cd3xwgq7n3rhzy7j8wrnaidxl0r6l6b6g3mpbpjig"))))
413 (build-system node-build-system)
414 (arguments
415 `(#:node ,node-bootstrap
416 #:tests? #f
417 #:phases
418 (modify-phases %standard-phases
419 (add-after 'patch-dependencies 'delete-dependencies
420 (lambda args
421 (delete-dependencies `("chai" "mocha")))))))
422 (home-page "https://github.com/darkskyapp/binary-search#readme")
423 (properties '((hidden? . #t)))
424 (synopsis "Tiny binary search function with comparators")
425 (description "This package is a binary search function for Node.js.")
426 (license license:cc0)))
427
428(define-public node-debug-bootstrap
429 (package
430 (name "node-debug")
431 (version "4.3.0")
432 (source
433 (origin
434 (method git-fetch)
435 (uri (git-reference
436 (url "https://github.com/visionmedia/debug.git")
437 (commit version)))
438 (file-name (git-file-name name version))
439 (sha256
440 (base32
441 "08g52r1d4yqcsfdfb7n5if33d4cghaq75gx5n9hj6m6fd8jfp2pi"))))
442 (build-system node-build-system)
443 (arguments
444 `(#:node ,node-bootstrap
445 #:tests? #f
446 #:phases
447 (modify-phases %standard-phases
448 (add-after 'patch-dependencies 'delete-dependencies
449 (lambda args
450 (delete-dependencies `("brfs"
451 "browserify"
452 "coveralls"
453 "istanbul"
454 "karma"
455 "karma-browserify"
456 "karma-chrome-launcher"
457 "karma-mocha"
458 "mocha"
459 "mocha-lcov-reporter"
460 "xo")))))))
461 (inputs (list node-ms-bootstrap))
462 (home-page "https://github.com/visionmedia/debug#readme")
463 (properties '((hidden? . #t)))
464 (synopsis "Small debugging utility")
465 (description "This package contains a tiny JavaScript debugging
466utility modelled after Node.js core's debugging technique. It works in
467Node.js and web browsers.")
468 (license license:expat)))
469
470(define-public node-llparse-builder-bootstrap
471 (package
472 (name "node-llparse-builder")
473 (version "1.5.2")
474 (source
475 (origin
476 (method git-fetch)
477 (uri (git-reference
478 (url "https://github.com/indutny/llparse-builder.git")
479 (commit (string-append "v" version))))
480 (file-name (git-file-name name version))
481 (sha256
482 (base32
483 "0r82iiwqsb73k2fxw7842rjjiixllxpyc6yl9cq4ma6ybkf6xmzm"))
484 (modules '((guix build utils)))
485 (snippet
486 '(begin
487 ;; FIXME: Unneeded runtime dependency.
488 ;; https://github.com/indutny/llparse-builder/pull/2
489 (substitute* "package.json"
490 (("\"@types/debug.*,") ""))
491 ;; Fix imports for esbuild.
492 ;; https://github.com/evanw/esbuild/issues/477
493 (substitute* '("src/node/invoke.ts"
494 "src/node/base.ts"
495 "src/node/consume.ts"
496 "src/node/match.ts"
497 "src/node/error.ts"
498 "src/node/pause.ts"
499 "src/edge.ts"
500 "src/utils.ts"
501 "src/loop-checker/index.ts"
502 "src/loop-checker/lattice.ts"
503 "src/code/field.ts"
504 "src/span-allocator.ts")
505 (("\\* as assert") "assert")
506 (("\\* as debugAPI") "debugAPI"))
507 #t))))
508 (build-system node-build-system)
509 (arguments
510 `(#:node ,node-bootstrap
511 #:tests? #f
512 #:phases
513 (modify-phases %standard-phases
514 (add-after 'patch-dependencies 'delete-dependencies
515 (lambda _
516 (delete-dependencies `("@types/mocha"
517 "@types/node"
518 "mocha"
519 "ts-node"
520 "tslint"
521 "typescript"))))
522 (replace 'build
523 (lambda* (#:key inputs #:allow-other-keys)
524 (let ((esbuild (search-input-file inputs "/bin/esbuild")))
525 (invoke esbuild
526 "--platform=node"
527 "--outfile=lib/builder.js"
528 "--bundle"
529 "src/builder.ts")))))))
530 (inputs
531 (list node-binary-search-bootstrap node-debug-bootstrap))
532 (native-inputs
533 (list esbuild))
534 (home-page "https://github.com/indutny/llparse-builder#readme")
535 (properties '((hidden? . #t)))
536 (synopsis "Graph builder for consumption by llparse")
537 (description "This package builds graphs for consumption by llparse.")
538 (license license:expat)))
539
540(define-public node-llparse-frontend-bootstrap
541 (package
542 (name "node-llparse-frontend")
543 (version "3.0.0")
544 (source
545 (origin
546 (method git-fetch)
547 (uri (git-reference
548 (url "https://github.com/indutny/llparse-frontend.git")
549 (commit (string-append "v" version))))
550 (file-name (git-file-name name version))
551 (sha256
552 (base32 "1rm9g4ifyip30svm5cgnf0gx7d45jgh4mpf2hkd092xhngmfvicc"))
553 (modules '((guix build utils)))
554 (snippet
555 '(begin
556 ;; Fix imports for esbuild.
557 ;; https://github.com/evanw/esbuild/issues/477
558 (substitute* '("src/frontend.ts"
559 "src/code/field-value.ts"
560 "src/container/index.ts"
561 "src/container/wrap.ts"
562 "src/node/sequence.ts"
563 "src/node/single.ts"
564 "src/node/table-lookup.ts"
565 "src/trie/index.ts")
566 (("\\* as assert") "assert")
567 (("\\* as debugAPI") "debugAPI"))
568 #t))))
569 (build-system node-build-system)
570 (arguments
571 `(#:node ,node-bootstrap
572 #:tests? #f
573 #:phases
574 (modify-phases %standard-phases
575 (add-after 'patch-dependencies 'delete-dependencies
576 (lambda args
577 (delete-dependencies `("@types/debug"
578 "@types/mocha"
579 "@types/node"
580 "mocha"
581 "ts-node"
582 "tslint"
583 "typescript"))))
584 (replace 'build
585 (lambda* (#:key inputs #:allow-other-keys)
586 (let ((esbuild (search-input-file inputs "/bin/esbuild")))
587 (invoke esbuild
588 "--platform=node"
589 "--outfile=lib/frontend.js"
590 "--bundle"
591 "src/frontend.ts")))))))
592 (inputs
593 (list node-debug-bootstrap node-llparse-builder-bootstrap))
594 (native-inputs
595 (list esbuild))
596 (home-page "https://github.com/indutny/llparse-frontend#readme")
597 (properties '((hidden? . #t)))
598 (synopsis "Frontend for the llparse compiler")
599 (description "This package is a frontend for the llparse compiler.")
600 (license license:expat)))
601
602(define-public node-llparse-bootstrap
603 (package
604 (name "node-llparse")
605 (version "7.1.0")
606 (source
607 (origin
608 (method git-fetch)
609 (uri (git-reference
610 (url "https://github.com/indutny/llparse.git")
611 (commit (string-append "v" version))))
612 (file-name (git-file-name name version))
613 (sha256
614 (base32
615 "10da273iy2if88hp79cwms6c8qpsl1fkgzll6gmqyx5yxv5mkyp6"))
616 (modules '((guix build utils)))
617 (snippet
618 '(begin
619 ;; Fix imports for esbuild.
620 ;; https://github.com/evanw/esbuild/issues/477
621 (substitute* '("src/compiler/index.ts"
622 "src/implementation/c/node/base.ts"
623 "src/implementation/c/node/table-lookup.ts"
624 "src/implementation/c/compilation.ts"
625 "src/implementation/c/helpers/match-sequence.ts"
626 "src/implementation/c/code/mul-add.ts")
627 (("\\* as assert") "assert")
628 (("\\* as debugAPI") "debugAPI"))
629 #t))))
630 (build-system node-build-system)
631 (arguments
632 `(#:node ,node-bootstrap
633 #:tests? #f
634 #:phases
635 (modify-phases %standard-phases
636 (add-after 'patch-dependencies 'delete-dependencies
637 (lambda args
638 (delete-dependencies `("@types/debug"
639 "@types/mocha"
640 "@types/node"
641 "esm"
642 "llparse-test-fixture"
643 "mocha"
644 "ts-node"
645 "tslint"
646 "typescript"))))
647 (replace 'build
648 (lambda* (#:key inputs #:allow-other-keys)
649 (let ((esbuild (search-input-file inputs "/bin/esbuild")))
650 (invoke esbuild
651 "--platform=node"
652 "--outfile=lib/api.js"
653 "--bundle"
654 "src/api.ts")))))))
655 (inputs
656 (list node-debug-bootstrap node-llparse-frontend-bootstrap))
657 (native-inputs
658 (list esbuild))
659 (home-page "https://github.com/nodejs/llparse#readme")
660 (properties '((hidden? . #t)))
661 (synopsis "Compile incremental parsers to C code")
662 (description "This package offers an API for compiling an incremental
663parser definition into a C output.")
664 (license license:expat)))
665
666(define-public llhttp-bootstrap
667 (package
668 (name "llhttp")
669 (version "2.1.4")
670 (source (origin
671 (method git-fetch)
672 (uri (git-reference
673 (url "https://github.com/nodejs/llhttp.git")
674 (commit (string-append "v" version))))
675 (file-name (git-file-name name version))
676 (sha256
677 (base32
678 "115mwyds9655p76lhglxg2blc1ksgrix6zhigaxnc2q6syy3pa6x"))
679 (patches (search-patches "llhttp-bootstrap-CVE-2020-8287.patch"))
680 (modules '((guix build utils)))
681 (snippet
682 '(begin
683 ;; Fix imports for esbuild.
684 ;; https://github.com/evanw/esbuild/issues/477
685 (substitute* "src/llhttp/http.ts"
686 (("\\* as assert") "assert"))
687 (substitute* "Makefile"
688 (("npx ts-node bin/generate.ts")
689 "node bin/generate.js"))
690 #t))))
691 (build-system gnu-build-system)
692 (arguments
693 `(#:tests? #f ; no tests
694 #:make-flags (list (string-append "CLANG=" ,(cc-for-target))
695 (string-append "DESTDIR=" (assoc-ref %outputs "out"))
696 "PREFIX=")
697 #:phases
698 (modify-phases %standard-phases
699 (replace 'configure
700 (lambda* (#:key inputs native-inputs #:allow-other-keys)
701 (let ((esbuild (search-input-file (or native-inputs inputs)
702 "/bin/esbuild")))
703 (invoke esbuild
704 "--platform=node"
705 "--outfile=bin/generate.js"
706 "--bundle" "bin/generate.ts"))))
707 (add-before 'install 'create-install-directories
708 (lambda* (#:key outputs #:allow-other-keys)
709 (let ((out (assoc-ref outputs "out")))
710 (for-each (lambda (dir)
711 (mkdir-p (string-append out dir)))
712 (list "/lib" "/include" "/src"))
713 #t)))
714 (add-after 'install 'install-src
715 (lambda* (#:key outputs #:allow-other-keys)
716 (let* ((out (assoc-ref outputs "out"))
717 (src-dir (string-append out "/src")))
718 (install-file "build/c/llhttp.c" src-dir)
719 (install-file "src/native/api.c" src-dir)
720 (install-file "src/native/http.c" src-dir)
721 #t))))))
722 (native-inputs
723 `(("esbuild" ,esbuild)
724 ("node" ,node-bootstrap)
725 ("node-semver" ,node-semver-bootstrap)
726 ("node-llparse-bootstrap" ,node-llparse-bootstrap)))
727 (home-page "https://github.com/nodejs/llhttp")
728 (properties '((hidden? . #t)))
729 (synopsis "Parser for HTTP messages")
730 (description "This is a rewrite of
731@url{https://github.com/nodejs/http-parser, http-parser} using
732@url{https://github.com/nodejs/llparse, llparse} to generate the C
733source files.")
734 (license license:expat)))
735
736(define-public node-lts
737 (package
738 (inherit node)
739 (version "14.19.3")
740 (source (origin
741 (method url-fetch)
742 (uri (string-append "https://nodejs.org/dist/v" version
743 "/node-v" version ".tar.xz"))
744 (sha256
745 (base32
746 "15691j5zhiikyamiwwd7f282g6d9acfhq91nrwx54xya38gmpx2w"))
747 (modules '((guix build utils)))
748 (snippet
749 `(begin
750 ;; Remove bundled software, where possible
751 (for-each delete-file-recursively
752 '("deps/cares"
753 "deps/icu-small"
754 "deps/nghttp2"
755 "deps/openssl"
756 "deps/zlib"))
757 (substitute* "Makefile"
758 ;; Remove references to bundled software.
759 (("deps/uv/uv.gyp") "")
760 (("deps/zlib/zlib.gyp") ""))
761 #t))))
762 (arguments
763 (substitute-keyword-arguments (package-arguments node)
764 ((#:configure-flags configure-flags)
765 ''("--shared-cares"
766 "--shared-libuv"
767 "--shared-nghttp2"
768 "--shared-openssl"
769 "--shared-zlib"
770 "--shared-brotli"
771 "--with-intl=system-icu"))
772 ((#:phases phases)
773 `(modify-phases ,phases
774 (replace 'set-bootstrap-host-rpath
775 (lambda* (#:key native-inputs inputs #:allow-other-keys)
776 (let* ((inputs (or native-inputs inputs))
777 (c-ares (assoc-ref inputs "c-ares"))
778 (brotli (assoc-ref inputs "brotli"))
779 (icu4c (assoc-ref inputs "icu4c"))
780 (nghttp2 (assoc-ref inputs "nghttp2"))
781 (openssl (assoc-ref inputs "openssl"))
782 (libuv (assoc-ref inputs "libuv"))
783 (zlib (assoc-ref inputs "zlib"))
784 (host-binaries '("torque"
785 "bytecode_builtins_list_generator"
786 "gen-regexp-special-case"
787 "node_mksnapshot"
788 "mksnapshot")))
789 (substitute* '("node.gyp" "tools/v8_gypfiles/v8.gyp")
790 (((string-append "'target_name': '("
791 (string-join host-binaries "|")
792 ")',")
793 target)
794 (string-append target
795 "'ldflags': ['-Wl,-rpath="
796 c-ares "/lib:"
797 brotli "/lib:"
798 icu4c "/lib:"
799 nghttp2 "/lib:"
800 openssl "/lib:"
801 libuv "/lib:"
802 zlib "/lib"
803 "'],"))))))
804 (replace 'delete-problematic-tests
805 (lambda* (#:key inputs #:allow-other-keys)
806 ;; FIXME: These tests fail in the build container, but they don't
807 ;; seem to be indicative of real problems in practice.
808 (for-each delete-file
809 '("test/parallel/test-cluster-master-error.js"
810 "test/parallel/test-cluster-master-kill.js"))
811
812 ;; These require a DNS resolver.
813 (for-each delete-file
814 '("test/parallel/test-dns.js"
815 "test/parallel/test-dns-lookupService-promises.js"))
816
817 ;; These tests require networking.
818 (for-each delete-file
819 '("test/parallel/test-https-agent-unref-socket.js"
820 "test/parallel/test-corepack-yarn-install.js"))
821
822 ;; This test is timing-sensitive, and fails sporadically on
823 ;; slow, busy, or even very fast machines.
824 (delete-file "test/parallel/test-fs-utimes.js")
825
826 ;; FIXME: This test fails randomly:
827 ;; https://github.com/nodejs/node/issues/31213
828 (delete-file "test/parallel/test-net-listen-after-destroying-stdin.js")
829
830 ;; FIXME: These tests fail on armhf-linux:
831 ;; https://github.com/nodejs/node/issues/31970
832 ,@(if (target-arm32?)
833 '((for-each delete-file
834 '("test/parallel/test-zlib.js"
835 "test/parallel/test-zlib-brotli.js"
836 "test/parallel/test-zlib-brotli-flush.js"
837 "test/parallel/test-zlib-brotli-from-brotli.js"
838 "test/parallel/test-zlib-brotli-from-string.js"
839 "test/parallel/test-zlib-convenience-methods.js"
840 "test/parallel/test-zlib-random-byte-pipes.js"
841 "test/parallel/test-zlib-write-after-flush.js")))
842 '())
843
844 ;; These tests have an expiry date: they depend on the validity of
845 ;; TLS certificates that are bundled with the source. We want this
846 ;; package to be reproducible forever, so remove those.
847 ;; TODO: Regenerate certs instead.
848 (for-each delete-file
849 '("test/parallel/test-tls-passphrase.js"
850 "test/parallel/test-tls-server-verify.js"))))
851 (add-after 'delete-problematic-tests 'replace-llhttp-sources
852 (lambda* (#:key inputs #:allow-other-keys)
853 ;; Replace pre-generated llhttp sources
854 (let ((llhttp (assoc-ref inputs "llhttp")))
855 (copy-file (string-append llhttp "/src/llhttp.c")
856 "deps/llhttp/src/llhttp.c")
857 (copy-file (string-append llhttp "/src/api.c")
858 "deps/llhttp/src/api.c")
859 (copy-file (string-append llhttp "/src/http.c")
860 "deps/llhttp/src/http.c")
861 (copy-file (string-append llhttp "/include/llhttp.h")
862 "deps/llhttp/include/llhttp.h"))))))))
863 (native-inputs
864 (list ;; Runtime dependencies for binaries used as a bootstrap.
865 c-ares-for-node
866 brotli
867 icu4c-71
868 libuv-for-node
869 `(,nghttp2 "lib")
870 openssl-1.1
871 zlib
872 ;; Regular build-time dependencies.
873 perl
874 pkg-config
875 procps
876 python
877 util-linux))
878 (inputs
879 (list bash-minimal
880 coreutils
881 c-ares-for-node
882 icu4c-71
883 libuv-for-node
884 llhttp-bootstrap
885 brotli
886 `(,nghttp2 "lib")
887 openssl-1.1
888 python-wrapper ;; for node-gyp (supports python3)
889 zlib))))
890
891(define-public libnode
892 (package/inherit node
893 (name "libnode")
894 (arguments
895 (substitute-keyword-arguments (package-arguments node)
896 ((#:configure-flags flags ''())
897 `(cons* "--shared" "--without-npm" ,flags))
898 ((#:phases phases '%standard-phases)
899 `(modify-phases ,phases
900 (delete 'install-npmrc)
901 (delete 'patch-nested-shebangs)))))))