gnu: node: Patch shebangs in node_modules.

* gnu/packages/node.scm (node)[arguments]: Replace 'patch-npm-shebang
and 'patch-node-shebang with a new 'patch-nested-shebangs that also
handles node-gyp and other shebangs under "/lib/node_modules".
[inputs]: Add Python for node-gyp as "python-for-target".
(node-lts)[inputs]: Likewise.
(libnode)[arguments]: Adjust to delete 'patch-nested-shebangs rather
than 'patch-npm-shebang and 'patch-node-shebang.

Signed-off-by: Liliana Marie Prikler <liliana.prikler@gmail.com>
This commit is contained in:
Philip McGrath 2021-12-16 21:02:43 -05:00 committed by Liliana Marie Prikler
parent 3179e32eb9
commit bcaf6f14a1
No known key found for this signature in database
GPG key ID: 442A84B8C70E2F87

View file

@ -105,6 +105,11 @@
;; Run only the CI tests. The default test target requires additional ;; Run only the CI tests. The default test target requires additional
;; add-ons from NPM that are not distributed with the source. ;; add-ons from NPM that are not distributed with the source.
#:test-target "test-ci-js" #:test-target "test-ci-js"
#:modules
((guix build gnu-build-system)
(guix build utils)
(srfi srfi-1)
(ice-9 match))
#:phases #:phases
(modify-phases %standard-phases (modify-phases %standard-phases
(add-before 'configure 'patch-hardcoded-program-references (add-before 'configure 'patch-hardcoded-program-references
@ -240,21 +245,23 @@
(search-input-file inpts "/bin/python")))) (search-input-file inpts "/bin/python"))))
"configure" "configure"
flags)))) flags))))
(add-after 'patch-shebangs 'patch-npm-shebang (add-after 'patch-shebangs 'patch-nested-shebangs
(lambda* (#:key outputs #:allow-other-keys) (lambda* (#:key inputs outputs #:allow-other-keys)
(let* ((bindir (string-append (assoc-ref outputs "out") ;; Based on the implementation of patch-shebangs
"/bin")) ;; from (guix build gnu-build-system).
(npm (string-append bindir "/npm")) (let ((path (append-map (match-lambda
(target (readlink npm))) ((_ . dir)
(with-directory-excursion bindir (list (string-append dir "/bin")
(patch-shebang target (list bindir)))))) (string-append dir "/sbin")
(add-after 'install 'patch-node-shebang (string-append dir "/libexec"))))
(lambda* (#:key outputs #:allow-other-keys) (append outputs inputs))))
(let* ((bindir (string-append (assoc-ref outputs "out") (for-each
"/bin")) (lambda (file)
(npx (readlink (string-append bindir "/npx")))) (patch-shebang file path))
(with-directory-excursion bindir (find-files (search-input-directory outputs "lib/node_modules")
(patch-shebang npx (list bindir))))))))) (lambda (file stat)
(executable-file? file))
#:stat lstat))))))))
(native-inputs (native-inputs
`(;; Runtime dependencies for binaries used as a bootstrap. `(;; Runtime dependencies for binaries used as a bootstrap.
("c-ares" ,c-ares) ("c-ares" ,c-ares)
@ -283,6 +290,7 @@
libuv libuv
`(,nghttp2 "lib") `(,nghttp2 "lib")
openssl openssl
python-wrapper ;; for node-gyp (supports python3)
zlib)) zlib))
(synopsis "Evented I/O for V8 JavaScript") (synopsis "Evented I/O for V8 JavaScript")
(description "Node.js is a platform built on Chrome's JavaScript runtime (description "Node.js is a platform built on Chrome's JavaScript runtime
@ -802,6 +810,7 @@ source files.")
brotli brotli
`(,nghttp2 "lib") `(,nghttp2 "lib")
openssl openssl
python-wrapper ;; for node-gyp (supports python3)
zlib)))) zlib))))
(define-public libnode (define-public libnode
@ -813,5 +822,4 @@ source files.")
`(cons* "--shared" "--without-npm" ,flags)) `(cons* "--shared" "--without-npm" ,flags))
((#:phases phases '%standard-phases) ((#:phases phases '%standard-phases)
`(modify-phases ,phases `(modify-phases ,phases
(delete 'patch-npm-shebang) (delete 'patch-nested-shebangs)))))))
(delete 'patch-node-shebang)))))))