guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#51838] [PATCH v3 29/43] gnu: Add node-sqlite3.


From: Philip McGrath
Subject: [bug#51838] [PATCH v3 29/43] gnu: Add node-sqlite3.
Date: Wed, 8 Dec 2021 15:28:24 -0500

* gnu/packages/node-xyz.scm (node-sqlite3): New variable.
---
 gnu/packages/node-xyz.scm | 118 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 115 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/node-xyz.scm b/gnu/packages/node-xyz.scm
index 60dbfc163c..b979d0cd53 100644
--- a/gnu/packages/node-xyz.scm
+++ b/gnu/packages/node-xyz.scm
@@ -615,7 +615,8 @@ (define-public node-addon-api
        (sha256
         (base32 "1bhvfi2m9nxfz418s619914vmidcnrzbjv6l9nid476c3zlpazch"))))
     (inputs
-     `(("python" ,python)))
+     `(("python" ,python)
+       ("node-safe-buffer" ,node-safe-buffer)))
     (build-system node-build-system)
     (arguments
      `(#:absent-dependencies
@@ -630,8 +631,7 @@ (define-public node-addon-api
          "eslint-plugin-promise"
          "fs-extra"
          "path"
-         "pre-commit"
-         "safe-buffer")
+         "pre-commit")
        #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'skip-js-tests
@@ -660,3 +660,115 @@ (define-public node-addon-api
 @code{libuv} (included in a project via @code{#include <uv.h>}) are not
 ABI-stable across Node.js major versions.")
     (license license:expat)))
+
+(define-public node-sqlite3
+  (package
+    (name "node-sqlite3")
+    (version "5.0.2")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/mapbox/node-sqlite3";)
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "0sbbzzli282nxyfha10zx0k5m8hdp0sf3ipl59khjb7wm449j86h"))
+       (snippet
+        (with-imported-modules '((guix build utils))
+          #~(begin
+              (use-modules (guix build utils))
+              ;; unbundle sqlite
+              (for-each delete-file-recursively
+                        (find-files "deps"
+                                    (lambda (pth stat)
+                                      (gzip-file? pth)))))))))
+    (inputs
+     `(("node-addon-api" ,node-addon-api)
+       ("python" ,python)
+       ("sqlite" ,sqlite)))
+    (build-system node-build-system)
+    (arguments
+     `(#:tests?
+       #f ; FIXME: tests depend on node-mocha
+       #:modules
+       ((guix build node-build-system)
+        (guix build json)
+        (srfi srfi-1)
+        (ice-9 match)
+        (guix build utils))
+       #:absent-dependencies
+       `(;; Normally, this is "built" using @mapbox/node-pre-gyp,
+         ;; which publishes or downloads pre-built binaries
+         ;; or falls back to building from source.
+         ;; Here, we patch out all of that and just build directly.
+         ;; It would be better to patch a version of @mapbox/node-pre-gyp
+         ;; that always builds from source, as Debian does,
+         ;; but there are a number of dependencies that need
+         ;; to be packaged or removed.
+         "@mapbox/node-pre-gyp"
+         "node-pre-gyp" ;; deprecated name still used in some places
+         "aws-sdk"
+         "@mapbox/cloudfriend"
+         ;; Confusingly, this is only a dependency beceuse of
+         ;; @mapbox/node-pre-gyp: with that removed,
+         ;; npm will use its own copy:
+         "node-gyp"
+         ;; These we'd like, we just don't have them yet:
+         "eslint"
+         "mocha")
+       #:phases
+       (modify-phases %standard-phases
+         (add-before 'configure 'npm-config-sqlite
+           ;; We need this step even if we do replace @mapbox/node-pre-gyp
+           ;; because the package expects to build its bundled sqlite
+           (lambda* (#:key inputs #:allow-other-keys)
+             (setenv "npm_config_sqlite" (assoc-ref inputs "sqlite"))))
+         (add-after 'install 'patch-binding-path
+           (lambda* (#:key outputs #:allow-other-keys)
+             (with-directory-excursion
+                 (string-append (assoc-ref outputs "out")
+                                "/lib/node_modules/sqlite3/lib")
+               (match (find-files "binding" "\\.node$")
+                 ((rel-path)
+                  (with-atomic-file-replacement "sqlite3-binding.js"
+                    (lambda (in out)
+                      (format out "var binding = require('./~a');\n" rel-path)
+                      (display "module.exports = exports = binding;\n" 
out))))))))
+         (add-after 'patch-dependencies 'avoid-node-pre-gyp
+           (lambda args
+             (substitute* ".npmignore"
+               (("lib/binding")
+                "#lib/binding # <- patched for Guix"))
+             (with-atomic-file-replacement "package.json"
+               (lambda (in out)
+                 (let* ((js (read-json in))
+                        (alist (match js
+                                 (('@ . alist) alist)))
+                        (scripts-alist (match (assoc-ref alist "scripts")
+                                         (('@ . alist) alist)))
+                        (scripts-alist
+                         ;; install script would use node-pre-gyp
+                         (assoc-remove! scripts-alist "install"))
+                        (alist
+                         (assoc-set! alist "scripts" (cons '@ scripts-alist)))
+                        (binary-alist (match (assoc-ref alist "binary")
+                                        (('@ . alist) alist)))
+                        (js (cons '@ alist)))
+                   ;; compensate for lack of @mapbox/node-pre-gyp
+                   (setenv "GYP_DEFINES"
+                           (string-append
+                            "module_name="
+                            (assoc-ref binary-alist "module_name")
+                            " "
+                            "module_path="
+                            (assoc-ref binary-alist "module_path")))
+                   (write-json js
+                               out)))))))))
+    (home-page "https://github.com/mapbox/node-sqlite3";)
+    (synopsis "Asynchronous, non-blocking SQLite3 bindings for Node.js")
+    (description
+     "The Node.js add-on @code{node-sqlite3} provides a set of a asynchronous,
+non-blocking bindings for SQLite3, written in modern C++ and tested for memory
+leaks.")
+     (license license:bsd-3)))
-- 
2.32.0






reply via email to

[Prev in Thread] Current Thread [Next in Thread]