guix_mirror_bot pushed a commit to branch master
in repository guix.
commit 860cee0575041b88581188f1e449f412d2cf8bd8
Author: Jelle Licht <[email protected]>
AuthorDate: Thu Oct 15 13:07:38 2026 +0200
build/node: Do not copy and hoist dependencies on install.
Due to store items being read-only, have npm skip bin links and generate
links
to package executables in a separate phase.
* guix/build/node-build-system.scm (set-home): Set npm_config_bin_links.
(configure, install): Remove '--install-links'.
(link-bins): New procedure.
(%standard-phases): Add 'link-bins after 'build-addon, and run
'avoid-node-gyp-rebuild after it.
* gnu/packages/node-xyz.scm (node-typescript)[native-inputs]: Add
node-chalk.
[arguments]<#:phases>: Do not delete "chalk" dependency.
---
gnu/packages/node-xyz.scm | 2 +-
guix/build/node-build-system.scm | 27 ++++++++++++++++++++++++---
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm
index c81a97d8c0d..9f703605d22 100644
--- a/gnu/packages/node-xyz.scm
+++ b/gnu/packages/node-xyz.scm
@@ -4494,6 +4494,7 @@ tablets.
(base32 "05w6rmlc0d2xicmp7dkjvbgz95cjkp0525qq8dfqpq5xcdy3xws6"))))
(build-system node-build-system)
(native-inputs (list
+ node-chalk
node-dprint-formatter ; 0.x
node-esbuild ; 0.x
node-fast-xml-parser ; 4.x
@@ -4532,7 +4533,6 @@ tablets.
"c8"
"chai"
"chokidar"
- "chalk"
"diff"
"dprint"
"eslint"
diff --git a/guix/build/node-build-system.scm b/guix/build/node-build-system.scm
index 0e641a59432..fbe30615ecc 100644
--- a/guix/build/node-build-system.scm
+++ b/guix/build/node-build-system.scm
@@ -143,6 +143,7 @@ dependencies."
(setenv "npm_config_fetch_retries" "0")
(setenv "npm_config_audit" "false")
(setenv "npm_config_ignore_scripts" "true")
+ (setenv "npm_config_bin_links" "false")
(setenv "npm_config_offline" "true")
(format #t "set HOME to ~s~%" (getenv "HOME"))))))))
@@ -210,7 +211,7 @@ dependencies."
(define* (configure #:key inputs #:allow-other-keys)
(let ((npm (string-append (assoc-ref inputs "node") "/bin/npm")))
- (invoke npm "--install-links" "install")))
+ (invoke npm "install")))
(define* (build #:key inputs #:allow-other-keys)
(let* ((package-meta (call-with-input-file "package.json" json->scm))
@@ -264,9 +265,28 @@ dependencies."
"--global"
"--loglevel" "info"
"--production"
- "--install-links"
"install" "../package.tgz")))
+(define* (link-bins #:key outputs #:allow-other-keys)
+ "Create symlinks in OUTPUT/bin as declared in package.json's bin field."
+ (let* ((out (assoc-ref outputs "out"))
+ (pkg (call-with-input-file "package.json" json->scm))
+ (pkg-name (assoc-ref pkg "name"))
+ (pkg-dir (string-append out "/lib/node_modules/" pkg-name)))
+ (define (link-bin name file)
+ (let ((file (if (string-prefix? "./" file)
+ (string-drop file 2)
+ file)))
+ (mkdir-p (string-append out "/bin"))
+ (symlink (string-append pkg-dir "/" file)
+ (string-append out "/bin/" (basename name)))))
+ (match (assoc-ref pkg "bin")
+ ((? string? file)
+ (link-bin pkg-name file))
+ (((names . files) ...)
+ (for-each link-bin names files))
+ (#f #t))))
+
(define* (build-addon #:key inputs outputs #:allow-other-keys)
"Build the native addon of the installed package, as 'npm install' would
when running scripts."
@@ -351,7 +371,8 @@ would try to run 'node-gyp rebuild'."
(add-before 'install 'repack repack)
(replace 'install install)
(add-after 'install 'build-addon build-addon)
- (add-after 'build-addon 'avoid-node-gyp-rebuild avoid-node-gyp-rebuild)))
+ (add-after 'build-addon 'link-bins link-bins)
+ (add-after 'link-bins 'avoid-node-gyp-rebuild avoid-node-gyp-rebuild)))
(define* (node-build #:key inputs (phases %standard-phases)
#:allow-other-keys #:rest args)