summary refs log tree commit diff
path: root/gnu/packages/web.scm
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2024-05-22 16:32:20 +0200
committerRicardo Wurmus <rekado@elephly.net>2024-05-22 17:44:49 +0200
commit675d31a5dff6ca35a4a79cda95e7e850162e35f8 (patch)
tree34311af6311728312edcdaaa77b35641968183b0 /gnu/packages/web.scm
parent9f9127e80ac9338dc426921208e5b88fce6ff72e (diff)
downloadguix-675d31a5dff6ca35a4a79cda95e7e850162e35f8.tar.gz
gnu: Add esbuild-node.
* gnu/packages/web.scm (esbuild-node): New variable.

Change-Id: I5e1a353a13ef7b4018fcf4aef4832af25f3dabe2
Diffstat (limited to 'gnu/packages/web.scm')
-rw-r--r--gnu/packages/web.scm59
1 files changed, 59 insertions, 0 deletions
diff --git a/gnu/packages/web.scm b/gnu/packages/web.scm
index 162f4837be..cbf270ec6b 100644
--- a/gnu/packages/web.scm
+++ b/gnu/packages/web.scm
@@ -2054,6 +2054,65 @@ begins forwarding traffic between the client and the target in both
 directions.")
     (license license:lgpl3)))
 
+;; This is a variant of esbuild that builds and installs the nodejs API.
+;; Eventually, this should probably be merged with the esbuild package.
+(define-public esbuild-node
+  (package
+    (inherit esbuild)
+    (name "esbuild-node")
+    (version (package-version esbuild))
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/evanw/esbuild")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "09r1xy0kk6c9cpz6q0mxr4why373pwxbm439z2ihq3k1d5kk7x4w"))
+       (modules '((guix build utils)))
+       (snippet
+        ;; Remove prebuilt binaries
+        '(delete-file-recursively "lib/npm/exit0"))))
+    (arguments
+     (list
+      #:import-path "github.com/evanw/esbuild/cmd/esbuild"
+      #:unpack-path "github.com/evanw/esbuild"
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'build 'build-platform
+            (lambda* (#:key unpack-path #:allow-other-keys)
+              (with-directory-excursion (string-append "src/" unpack-path)
+                ;; We're using Node 10, which doesn't have this method.
+                (substitute* "scripts/esbuild.js"
+                  (("exports.buildNativeLib" m)
+                   (string-append
+                    "Object.fromEntries = entries => entries.reduce((result, entry) => (result[entry[0]] = entry[1], result), {});\n"
+                    m)))
+                ;; Must be writable.
+                (for-each make-file-writable (find-files "." "."))
+                (invoke "node" "scripts/esbuild.js"
+                        (string-append #$output "/bin/esbuild"))
+                (let ((modules (string-append #$output "/lib/node_modules/esbuild")))
+                  (mkdir-p modules)
+                  (copy-recursively "npm/esbuild" modules)))))
+          (replace 'check
+            (lambda* (#:key tests? unpack-path #:allow-other-keys)
+              (when tests?
+                ;; The "Go Race Detector" is only supported on 64-bit
+                ;; platforms, this variable disables it.
+                ;; TODO: Causes too many rebuilds, rewrite to limit to x86_64,
+                ;; aarch64 and ppc64le.
+                #$(if (target-riscv64?)
+                      `(setenv "ESBUILD_RACE" "")
+                      #~(unless #$(target-64bit?)
+                          (setenv "ESBUILD_RACE" "")))
+                (with-directory-excursion (string-append "src/" unpack-path)
+                  (invoke "make" "test-go"))))))))
+    (native-inputs
+     (modify-inputs (package-native-inputs esbuild)
+       (append node)))))
+
 (define-public wwwoffle
   (package
     (name "wwwoffle")