Skip to content

Instantly share code, notes, and snippets.

@zamfofex
Last active December 8, 2022 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zamfofex/eac93bc0e00477a8b79f5ca4dc1a34ff to your computer and use it in GitHub Desktop.
Save zamfofex/eac93bc0e00477a8b79f5ca4dc1a34ff to your computer and use it in GitHub Desktop.
npm importer for Guix
(use-modules
(guix packages)
(guix git-download)
(guix build-system node)
((guix licenses) #:prefix license:)
(gnu packages web))
(define-public jquery
(package
(name "jquery")
(version "4.0.0-pre")
(source
(origin
(method git-fetch)
(uri
(git-reference
(url "https://github.com/jquery/jquery")
(commit "f62d8e2159baf1eabf3b760b85b2dda56d569a09")))
(sha256 (base32 "06fm6x9iczzvskhd534db7fymds2w8wwa0cvahr35h9w9ryda7qb"))
(file-name (git-file-name name version))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(add-before 'configure 'remove-binaries
(lambda _
(delete-file-recursively "dist")))
(delete 'configure)
(replace 'build
(lambda _
(invoke "esbuild" "src/jquery.js" "--bundle" "--minify" "--outfile=dist/jquery.js"))))))
(native-inputs (list esbuild))
(synopsis "JavaScript library for DOM operations")
(description "JavaScript library for DOM operations")
(home-page "https://jquery.com")
(license license:expat)))
jquery
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org>
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
;;; Copyright © 2022 zamfofex <zamfofex@twdb.moe>
;;;
;;; This file is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; This file is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
(use-modules
(json)
((guix licenses) #:select (expat))
(guix utils)
(web uri)
(guix build git)
(guix base32)
(guix hash)
((guix download) #:prefix download:)
(guix serialization)
(guix import json)
(srfi srfi-1)
(srfi srfi-11)
(srfi srfi-9 gnu)
(srfi srfi-9)
(srfi srfi-26)
(ice-9 regex)
(ice-9 rdelim)
(ice-9 control)
(ice-9 vlist)
(rnrs bytevectors)
(ice-9 binary-ports)
(rnrs io ports)
(ice-9 match)
(ice-9 regex)
(ice-9 receive)
(guix import utils)
(guix packages)
(gnu packages)
(guix build-system node)
(guix build node-build-system)
(guix http-client))
(define* (assoc-ref* alist keys) (fold (lambda (key alist) (assoc-ref alist key)) alist keys))
(define scheme-pat
"[a-zA-Z][-a-zA-Z0-9+.-]*")
(define host-pat
"[a-zA-Z0-9.-]+")
(define authority-pat
(make-regexp "[^/?#]*"))
(define path-pat
(make-regexp "[^?#]*"))
(define user-project-pat
"([a-zA-Z][-a-zA-Z0-9+.]*)/([a-zA-Z][-a-zA-Z0-9+.]*)")
(define gh-shorthand-regexp
(make-regexp (format #f "^~a$" user-project-pat)))
(define alternative-gh-shorthand-regexp
(make-regexp (format #f "^github:~a$" user-project-pat)))
(define bitbucket-shorthand-regexp
(make-regexp (format #f "^bitbucket:~a$" user-project-pat)))
(define gitlab-shorthand-regexp
(make-regexp (format #f "^gitlab:~a$" user-project-pat)))
(define pseudo-url-regexp
(make-regexp (format #f "^(~a)@(~a):(~a)\\.git$"
scheme-pat
host-pat
user-project-pat)))
(define (pseudo-to-real-url pseudo-url-match)
(let* ((m pseudo-url-match)
(protocol (match:substring m 1))
(hostname (match:substring m 2))
(user-project (match:substring m 3)))
(format #f "~a://~a/~a.git"
protocol
hostname
user-project)))
(define (make-gh-url user project)
(format #f "https://github.com/~a/~a.git" user project))
(define (make-bb-url user project)
(format #f "https://bitbucket.org/~a/~a.git" user project))
(define (make-gl-url user project)
(format #f "https://gitlab.com/~a/~a.git" user project))
(define (normalise-url url)
(cond ((regexp-exec pseudo-url-regexp url)
;; git@host:user/project.git
=>
(lambda (match)
(pseudo-to-real-url match)))
((or (regexp-exec gh-shorthand-regexp url)
(regexp-exec alternative-gh-shorthand-regexp url))
;; user/project or github:user/project
=> (lambda (match)
(let ((user (match:substring match 1))
(project (match:substring match 2)))
(make-gh-url user project))))
((regexp-exec bitbucket-shorthand-regexp url)
;; bitbucket:user/project
=>
(lambda (match)
(let ((user (match:substring match 1))
(project (match:substring match 2)))
(make-bb-url user project))))
((regexp-exec gitlab-shorthand-regexp url)
;; gitlab:user/project
=>
(lambda (match)
(let ((user (match:substring match 1))
(project (match:substring match 2)))
(make-gl-url user project))))
((not (string-suffix? ".git" url)) ;XXX: forgetful npm people
(normalise-url (string-append url ".git")))
((string->uri url)
=>
(lambda (uri)
;; XXX: Use actual schemes supported by git
(case (uri-scheme uri)
((git+ssh)
(uri->string (set-fields uri ((uri-scheme) 'git))))
((git+http)
(uri->string (set-fields uri ((uri-scheme) 'http))))
((git+https)
(uri->string (set-fields uri ((uri-scheme) 'https))))
(else
url))))
(else
url)))
(define (json-fetch* url)
(with-exception-handler
(lambda _ #f)
(lambda ()
(json->scm
(http-fetch/cached url
#:headers
`((User-Agent . "Guix")
(Authorization . ,(string-append "token " (getenv "GUIX_GITHUB_TOKEN")))))))
#:unwind? #t))
(define (heuristic-tags name version)
(let*
((names (list name (string-replace-substring name "-" "_") (string-replace-substring name "-" "")))
(versions (list version (string-append "v" version)))
(versions (append-map (lambda (version) (cons version (append-map (lambda (name) (list (string-append name "-" version) (string-append name "_" version))) names))) versions)))
versions))
(define (generic-fuzzy-tag-match repo-url name version)
"Return a likely match for the git tag VERSION for the repository at REPO-URL"
version)
; XXX: Where does 'git-fetch-tags' come from?
; ---------------
; (let* ((fuzzy-tags (heuristic-tags name version))
; (repo-tags (git-fetch-tags repo-url))
; (proper-release (filter
; (lambda (tags)
; (member tags fuzzy-tags))
; repo-tags)))
; (match proper-release
; (()
; #f)
; ((release . rest)
; ;;XXX: Just pick the first release
; release))))
(define (gh-fuzzy-tag-match github-repo name version)
"Return a likely match for the git tag VERSION for the repository at
GITHUB-REPO"
(let* ((fuzzy-tags (heuristic-tags name version))
(api-url (string-append "https://api.github.com/repos/" (github-user-slash-repository github-repo) "/tags"))
(json (json-fetch* api-url)))
(if (not json)
(error "Error downloading release information through the GitHub
API. This may be fixed by using an access token and setting the environment
variable GUIX_GITHUB_TOKEN, for instance one procured from
https://github.com/settings/tokens. E: " github-repo "@" version " via "
api-url)
(let ((proper-release
(filter
(lambda (x)
(let ((name (assoc-ref x "name")))
(member name fuzzy-tags)))
(vector->list json))))
(match proper-release
(() ;fuzzy version mismatch
(if (pair? json)
(begin
;;XXX: Just pick first release
;; e.g.: xmldom 0.1.16 vs 0.1.22
(assoc-ref json "name"))
;;XXX: No tags: Just pick latest commit from master
;; e.g.: cjson
;; TODO: iso master, snarf default_branch from /
(let* ((branches-url (string-append "https://api.github.com/repos/" (github-user-slash-repository github-repo) "/branches"))
(branches (json-fetch* branches-url))
(first-or-master
(or
(find (lambda (x) (or (equal? (assoc-ref x "name") "main") (equal? (assoc-ref x "name") "master")))
(vector->list branches))
(vector->list branches)))
(commit (assoc-ref first-or-master "commit"))
(sha (assoc-ref commit "sha")))
sha)))
((release . rest) ;one or more releases
;;XXX: Just pick the first release
(let ((tag (assoc-ref release "name")))
tag)))))))
(define (strip-.git-if-needed project)
;; for babel, e.g. string does not end in `.git'
(if (string-suffix? ".git" project)
(string-drop-right project 4)
project))
(define (github-user-slash-repository github-url)
"Return a string e.g. arq5x/bedtools2 of the owner and the name of the
repository separated by a forward slash, from a string URL of the form
'https://github.com/arq5x/bedtools2.git'"
(match (string-split (uri-path (string->uri github-url)) #\/)
((_ owner project . rest)
(string-append owner "/" (strip-.git-if-needed project)))))
(define (github-repository github-url)
"Return a string e.g. bedtools2 of the name of the repository, from a string
URL of the form 'https://github.com/arq5x/bedtools2.git'"
(match (string-split (uri-path (string->uri github-url)) #\/)
((_ owner project . rest)
(strip-.git-if-needed project))))
(define (github-tag-url github-url tag)
(if tag
(if (equal? (uri-host (string->uri github-url)) "github.com")
(string-append "https://github.com/" (github-user-slash-repository github-url) "/archive/refs/tags/" tag ".tar.gz"))))
(define (github-branch-url github-url branch)
(if branch
(if (equal? (uri-host (string->uri github-url)) "github.com")
(string-append "https://github.com/" (github-user-slash-repository github-url) "/archive/heads/tags/" branch ".tar.gz"))))
(define (github-commit-url github-url commit)
(if commit
(if (equal? (uri-host (string->uri github-url)) "github.com")
(string-append "https://github.com/" (github-user-slash-repository github-url) "/archive/" commit ".tar.gz"))))
;; npm specific code
(define *REGISTRY* "https://registry.npmjs.org/")
;; First try with released tarball, (github only?)
;; then heuristics for git repo
(define (npm-fetch name)
"Return metadata from the npm registry for package NAME."
(json-fetch (string-append *REGISTRY* name)))
(define (latest-source-release npm-meta)
"Return the latest source release for NPM-META."
(assoc-ref* npm-meta '("dist-tags" "latest")))
(define (node-package? package)
"Return true if PACKAGE is a node package."
(string-prefix? "node-" (package-name package)))
(define (source-uri npm-meta version)
"Return the repository url for version VERSION of NPM-META"
(let* ((v (assoc-ref* npm-meta `("versions" ,version)))
(repo (assoc-ref v "repository"))
(page (assoc-ref v "homepage"))
(dist (assoc-ref v "dist")))
(or
(and repo (and=> (assoc-ref repo "url") normalise-url))
(and page (and=> (assoc-ref page "url") normalise-url))
(and dist (assoc-ref dist "tarball")))))
(define (node-package-name name0)
"Given the NAME of a package on npmjs, return a Guix-compliant name for the package."
(define name1 (string-replace-substring name0 "@" ""))
(define name2 (string-replace-substring name1 "/" "-"))
(define name3 (snake-case name2))
(if (string-prefix? "node-" name3) name3 (string-append "node-" name3)))
(define (node-git-fetch url commit directory)
"Fetch the git repo located at URL, clone into DIRECTORY and check out
revision COMMIT. URL can be any url supported by the 'git clone' command.
COMMIT can be identifier of a commit that works with the 'git checkout'
command."
;;XXX: Assumes 'commit' is actually a tag
(let ((url (normalise-url url))
(v (string-append "v" commit)))
(git-fetch url v directory)))
(define (pipe-port in out)
(do
((bv #vu8() (get-bytevector-some in)))
((eof-object? bv))
(put-bytevector out bv))
(force-output out)
(close-port in))
(define (package-origin repo-url name version)
"Return a complete package origin for version VERSION of the software
located at REPO-URL. Tries to locate a released tarball before falling back to
a git checkout."
(let* ((uri (string->uri repo-url))
(host (and=> uri uri-host)))
(cond
((not host)
`(origin
(method url-fetch)
(uri ,repo-url)
(file-name (string-append name "-" version ".tar.gz"))
(sha256 (base32 "0000000000000000000000000000000000000000000000000000"))))
((equal? host "registry.npmjs.org")
(call-with-temporary-output-file
(lambda (temp port)
(let* ((_ (pipe-port (http-fetch/cached repo-url) port))
(hash (bytevector->nix-base32-string (file-hash* temp))))
`(origin
(method url-fetch)
(uri ,repo-url)
(file-name (string-append name "-" version ".tar.gz"))
(sha256 (base32 ,hash)))))))
((equal? host "github.com")
(call-with-temporary-output-file
(lambda (temp port)
(let* ((gh-version (or (gh-fuzzy-tag-match repo-url name version) version))
(tb
(or
(with-exception-handler
(lambda _ #f)
(lambda () (define url (github-tag-url repo-url gh-version)) `(,url . ,(http-fetch/cached url)))
#:unwind? #t)
(with-exception-handler
(lambda _ #f)
(lambda () (define url (github-branch-url repo-url gh-version)) `(,url . ,(http-fetch/cached url)))
#:unwind? #t)
(with-exception-handler
(lambda _ #f)
(lambda () (define url (github-commit-url repo-url gh-version)) `(,url . ,(http-fetch/cached url)))
#:unwind? #t))))
(if tb (pipe-port (cdr tb) port) (close port))
`(origin
(method url-fetch)
(uri ,(and=> tb car)) ; XXX: use the 'version' field
(file-name (string-append name "-" version ".tar.gz"))
(sha256 (base32 ,(if tb (bytevector->nix-base32-string (file-hash* temp)) "0000000000000000000000000000000000000000000000000000"))))))))
(else
(call-with-temporary-directory
(lambda (temp-dir)
(let* ((fuzzy-version (generic-fuzzy-tag-match repo-url name version))
(hash "0000000000000000000000000000000000000000000000000000"))
`(origin
(method git-fetch)
(uri (git-reference (url ,repo-url) (commit ,fuzzy-version)))
(file-name (string-append name "-" version ".tar.gz"))
(sha256 (base32 ,hash))))))))))
(define (make-npm-sexp name version home-page description dependencies dev-dependencies license source-url)
(let ((origin (package-origin source-url name version)))
`(package
(name ,(node-package-name name))
(version ,version)
(source ,origin)
(build-system node-build-system)
,@(if (or (not dependencies) (null? dependencies))
'()
`((propagated-inputs
(list
,@(map (lambda (name) (string->symbol name))
dependencies)))))
,@(if (or (not dev-dependencies) (null? dev-dependencies))
'()
`((native-inputs
(list
,@(map (lambda (name) (string->symbol name))
dev-dependencies)))))
(synopsis ,description) ; no synopsis field in package.json files
(description ,description)
(home-page ,home-page)
(license ,license))))
(define (extract-guix-dependencies dependencies)
"Returns a list of dependencies according to the guix naming scheme, from
the npm list of dependencies DEPENDENCIES."
(if (not dependencies) '() (map (compose node-package-name car) dependencies)))
(define (extract-npm-dependencies dependencies)
"Returns a list of dependencies according to the npm naming scheme, from the
npm list of dependencies DEPENDENCIES."
(if (not dependencies) '() (map car dependencies)))
(define (extract-license package-json)
(let ((license-entry (assoc-ref package-json "license"))
(license-legacy (assoc-ref package-json "licenses")))
(cond
((string? license-entry)
(spdx-string->license license-entry))
((list? license-entry)
(spdx-string->license (assoc-ref license-entry "type")))
((string? license-legacy)
(spdx-string->license license-legacy))
(else
(format (current-error-port) "extract-license: no license found: ~a\n" package-json) #f))))
(define* (npm->guix-package package-name)
"Fetch the metadata for PACKAGE-NAME from registry.npmjs.com and return the
`package' s-expression corresponding to that package, or #f on failure."
(let* ((package (npm-fetch package-name))
(version (latest-source-release package))
(curr (assoc-ref* package `("versions" ,version))))
(if (and package curr)
(let* ((name (assoc-ref package "name"))
(raw-dependencies (assoc-ref curr "dependencies"))
(raw-dev-dependencies '())
(dependencies (extract-guix-dependencies raw-dependencies))
(dev-dependencies (extract-guix-dependencies raw-dev-dependencies))
(npm-dependencies
(append
(extract-npm-dependencies raw-dependencies)
(extract-npm-dependencies raw-dev-dependencies)))
(description (assoc-ref package "description"))
(home-page (or (assoc-ref package "homepage") "https://www.npmjs.com"))
(license (or (extract-license curr) 'npm-license-unknown))
(source-url (source-uri package version)))
(values
(make-npm-sexp name version home-page description
dependencies dev-dependencies license source-url)
npm-dependencies))
(values #f '()))))
(define* (recursive-import package-name)
"Recursively fetch the metadata for PACKAGE-NAME and its dependencies from
registry.npmjs.com and return a list of 'package name, package s-expression'
tuples."
(define (seen? item seen)
(or (vhash-assoc item seen)
(not (null? (find-packages-by-name (node-package-name item))))))
(let loop ((todo (list package-name))
(seen vlist-null)
(result '()))
(match todo
(() result)
((package-name rest ...)
(if (seen? package-name seen)
(loop rest seen result)
(let ((seen (vhash-cons package-name #t seen)))
(format (current-error-port) "importing ~a...\n" package-name)
(receive (package dependencies) (npm->guix-package package-name)
(if package
(loop (append rest dependencies) seen (cons (list package-name package) result))
(begin
(format (current-error-port) "error: failed to import package ~a from archive npm.\n" package-name)
(loop rest seen result))))))))))
; Printing packages
(use-modules (ice-9 pretty-print))
(define* (to-define pair)
(define name (car pair))
(define pkg (cadr pair))
`(define-public ,(string->symbol (node-package-name name)) ,pkg))
(define* (defines name)
(cons
'(use-modules
(guix packages)
(guix download)
(guix build-system node)
((guix licenses) #:prefix license:)
(gnu packages node-xyz))
(map to-define (recursive-import name))))
(define* (pretty-print-spaced expression)
(pretty-print expression)
(newline))
; (define exprs (defines "jquery"))
; (define exprs (defines "underscore"))
; (define exprs (defines "jsdom"))
; (define exprs (defines "lodash"))
; (define exprs (defines "nodelint"))
; (define exprs (defines "chessground"))
(define exprs (defines "sucrase"))
(for-each pretty-print-spaced exprs)
(use-modules
(guix packages)
(guix download)
(guix build-system node)
((guix licenses) #:prefix license:)
(gnu packages bash)
(gnu packages node-xyz)
(gnu packages web))
(define-public node-balanced-match
(package
(name "node-balanced-match")
(version "2.0.0")
(source
(origin
(method url-fetch)
(uri "https://github.com/juliangruber/balanced-match/archive/refs/tags/v2.0.0.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"12xqfcss567fqzz906hbysm63cs0whjdxdpbq3bwvrziqsxznkww"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(synopsis
"Match balanced character pairs, like \"{\" and \"}\"")
(description
"Match balanced character pairs, like \"{\" and \"}\"")
(home-page
"https://github.com/juliangruber/balanced-match")
(license license:expat)))
(define-public node-brace-expansion
(package
(name "node-brace-expansion")
(version "2.0.1")
(source
(origin
(method url-fetch)
(uri "https://github.com/juliangruber/brace-expansion/archive/refs/tags/v2.0.1.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"061gc7g8j8n63vangs9lks9cvh9y1pkwvh6a414lvhazayrz8pbq"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(propagated-inputs (list node-balanced-match))
(synopsis
"Brace expansion as known from sh/bash")
(description
"Brace expansion as known from sh/bash")
(home-page
"https://github.com/juliangruber/brace-expansion")
(license license:expat)))
(define-public node-thenify
(package
(name "node-thenify")
(version "3.3.1")
(source
(origin
(method url-fetch)
(uri "https://github.com/thenables/thenify/archive/refs/tags/3.3.1.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"16rcqbwxhhvjpvzaz8ih21mjrvjlbfv8n9306djq2zaaqvxdbq3f"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(propagated-inputs (list node-any-promise))
(synopsis "Promisify a callback-based function")
(description
"Promisify a callback-based function")
(home-page
"https://github.com/thenables/thenify#readme")
(license license:expat)))
(define-public node-fs-realpath
(package
(name "node-fs-realpath")
(version "1.0.0")
(source
(origin
(method url-fetch)
(uri "https://github.com/isaacs/fs.realpath/archive/refs/tags/v1.0.0.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"16ybsq9mxm1cwwpx2j3k2pffznsqil13ifkwf6q8q2dpavmsy5k2"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(synopsis
"Use node's fs.realpath, but fall back to the JS implementation if the native one fails")
(description
"Use node's fs.realpath, but fall back to the JS implementation if the native one fails")
(home-page
"https://github.com/isaacs/fs.realpath#readme")
(license license:isc)))
(define-public node-inflight
(package
(name "node-inflight")
(version "1.0.6")
(source
(origin
(method url-fetch)
(uri "https://github.com/npm/inflight/archive/refs/tags/v1.0.6.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"04viwwgwkgmg01n29hz15qf16gdxjvyjaz61ncn7a81pz9laq7bd"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(propagated-inputs (list node-wrappy node-once))
(synopsis
"Add callbacks to requests in flight to avoid async duplication")
(description
"Add callbacks to requests in flight to avoid async duplication")
(home-page "https://github.com/isaacs/inflight")
(license license:isc)))
(define-public node-minimatch
(package
(name "node-minimatch")
(version "5.1.0")
(source
(origin
(method url-fetch)
(uri "https://github.com/isaacs/minimatch/archive/refs/tags/v5.1.0.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"1yvfjf0mr06d5wq8b6s8hy9y24n8z279xp4f7s64dxmnya2861fx"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(propagated-inputs (list node-brace-expansion))
(synopsis "a glob matcher in javascript")
(description "a glob matcher in javascript")
(home-page
"https://github.com/isaacs/minimatch#readme")
(license license:isc)))
(define-public node-any-promise
(package
(name "node-any-promise")
(version "1.3.0")
(source
(origin
(method url-fetch)
(uri "https://github.com/kevinbeaty/any-promise/archive/refs/tags/1.3.0.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"07g2gkz7fyj7m7zpkp9i3hbfqqz7gf6i2nkckl9sqrnqc1g76qkj"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(synopsis
"Resolve any installed ES6 compatible promise")
(description
"Resolve any installed ES6 compatible promise")
(home-page
"http://github.com/kevinbeaty/any-promise")
(license license:expat)))
(define-public node-object-assign
(package
(name "node-object-assign")
(version "4.1.1")
(source
(origin
(method url-fetch)
(uri "https://github.com/sindresorhus/object-assign/archive/refs/tags/v4.1.1.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"1dgfb9sc9zkm8axrj9014207z84j701szcmnbd4bsrzvk6xh9z8n"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(synopsis "ES2015 `Object.assign()` ponyfill")
(description "ES2015 `Object.assign()` ponyfill")
(home-page
"https://github.com/sindresorhus/object-assign#readme")
(license license:expat)))
(define-public node-thenify-all
(package
(name "node-thenify-all")
(version "1.6.0")
(source
(origin
(method url-fetch)
(uri "https://github.com/thenables/thenify-all/archive/refs/tags/1.6.0.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"18bdbzn9cfq4d22l4547jbncfvdisnq42jska7w067ickqrzkwks"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(propagated-inputs (list node-thenify))
(synopsis
"Promisifies all the selected functions in an object")
(description
"Promisifies all the selected functions in an object")
(home-page
"https://github.com/thenables/thenify-all")
(license license:expat)))
(define-public node-commander
(package
(name "node-commander")
(version "4.1.0")
(source
(origin
(method url-fetch)
(uri "https://github.com/tj/commander.js/archive/refs/tags/v4.1.0.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"09lbmca5hpqrxd9xsm4868r8x50n20l59lzp62dhqcn97zccdbip"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(synopsis
"the complete solution for node.js command-line programs")
(description
"the complete solution for node.js command-line programs")
(home-page
"https://github.com/tj/commander.js#readme")
(license license:expat)))
(define-public node-glob
(package
(name "node-glob")
(version "8.0.3")
(source
(origin
(method url-fetch)
(uri "https://github.com/isaacs/node-glob/archive/refs/tags/v8.0.3.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"125768jrdvwlxbgcr2jq0cy7i4h6gw169lidfnwbl8zl3y9f30cz"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(propagated-inputs
(list node-once
node-minimatch
node-inherits
node-inflight
node-fs-realpath))
(synopsis "a little globber")
(description "a little globber")
(home-page
"https://github.com/isaacs/node-glob#readme")
(license license:isc)))
(define-public node-lines-and-columns
(package
(name "node-lines-and-columns")
(version "2.0.3")
(source
(origin
(method url-fetch)
(uri "https://github.com/eventualbuddha/lines-and-columns/archive/refs/tags/v2.0.3.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"1l52g7n17m7ajgx158x3bcfylxkxgci8mml3v5aydcwbgwpl4a5h"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure)
(replace 'build
(lambda _
(invoke "esbuild" "src/index.ts" "--outdir=build" "--tsconfig=tsconfig.build.json")
(rename-file "build/index.js" "build/index.mjs")
(invoke "esbuild" "src/index.ts" "--outdir=build" "--format=cjs" "--tsconfig=tsconfig.build.json")
(rename-file "build/index.js" "build/index.cjs"))))))
(native-inputs (list esbuild))
(synopsis
"Maps lines and columns to character offsets and back.")
(description
"Maps lines and columns to character offsets and back.")
(home-page
"https://github.com/eventualbuddha/lines-and-columns#readme")
(license license:expat)))
(define-public node-mz
(package
(name "node-mz")
(version "2.7.0")
(source
(origin
(method url-fetch)
(uri "https://github.com/normalize/mz/archive/refs/tags/2.7.0.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"193j7rjskplz4kkd5xzqvrlxj1rhs1r3mh7xw9a0fjirlclaa2hf"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure))))
(propagated-inputs
(list node-thenify-all
node-object-assign
node-any-promise))
(synopsis
"modernize node.js to current ECMAScript standards")
(description
"modernize node.js to current ECMAScript standards")
(home-page
"https://github.com/normalize/mz#readme")
(license license:expat)))
(define-public node-pirates
(package
(name "node-pirates")
(version "4.0.5")
(source
(origin
(method url-fetch)
(uri "https://github.com/danez/pirates/archive/refs/tags/v4.0.5.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"02r9df3rzadqhw10hycdw7i0i7l5i11w1arvvq9n8ck3bl8bjcgq"))))
(build-system node-build-system)
(arguments
`(#:tests? #f
#:phases
(modify-phases %standard-phases
(add-before 'repack 'patch-version
(lambda _
(substitute* "package.json"
(("\"name\": *\"pirates\"," all) (string-append all ,(string-append "\n\"version\": \"" version "\","))))))
(delete 'configure)
(replace 'build
(lambda _
(use-modules (ice-9 ftw))
(define src "src")
(ftw src
(lambda (name info flag)
(if (string-suffix? ".js" name)
(invoke "esbuild" name "--format=cjs" (string-append "--outfile=lib" (string-drop name (string-length src)))))
#t)))))))
(native-inputs (list esbuild))
(synopsis "Properly hijack require")
(description "Properly hijack require")
(home-page
"https://github.com/danez/pirates#readme")
(license license:expat)))
(define-public node-ts-interface-checker
(package
(name "node-ts-interface-checker")
(version "1.0.2")
(source
(origin
(method url-fetch)
(uri "https://github.com/gristlabs/ts-interface-checker/archive/refs/tags/v1.0.2.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"10avan0qvw16qc1g2miic9kysn51h4d01f55bx1p6pbhdn5gggm1"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure)
(replace 'build
(lambda _
(use-modules (ice-9 ftw))
(define src "lib")
(define suffix ".ts")
(ftw src
(lambda (name info flag)
(if (string-suffix? suffix name)
(invoke "esbuild" name "--target=esnext" "--format=cjs" (string-append "--outfile=dist" (string-drop (string-drop-right name (string-length suffix)) (string-length src)) ".js")))
#t)))))))
(native-inputs (list esbuild))
(synopsis
"Runtime library to validate data against TypeScript interfaces")
(description
"Runtime library to validate data against TypeScript interfaces")
(home-page
"https://github.com/gristlabs/ts-interface-checker#readme")
(license license:asl2.0)))
(define-public node-sucrase0
(package
(name "node-sucrase0")
(version "3.29.0")
(source
(origin
(method url-fetch)
(uri "https://github.com/alangpierce/sucrase/archive/78a4c9a800ed046ac4731d003ae2f276df974738.tar.gz")
(file-name
(string-append name "-" version ".tar.gz"))
(sha256
(base32
"166yda7w9mydwn9vdmg5j7anwgrv8nkac7nbf4vnbr5bn3478m12"))))
(build-system node-build-system)
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure)
(replace 'build
(lambda _
(use-modules (ice-9 ftw))
(define src "src")
(define suffix ".ts")
(ftw src
(lambda (name info flag)
(if (string-suffix? suffix name)
(invoke "esbuild" name "--format=cjs" (string-append "--outfile=dist" (string-drop (string-drop-right name (string-length suffix)) (string-length src)) ".js")))
#t)))))))
(propagated-inputs
(list node-ts-interface-checker
node-pirates
node-mz
node-lines-and-columns
node-glob
node-commander))
(native-inputs (list esbuild))
(synopsis
"Super-fast alternative to Babel for when you can target modern JS runtimes")
(description
"Super-fast alternative to Babel for when you can target modern JS runtimes")
(home-page
"https://github.com/alangpierce/sucrase#readme")
(license license:expat)))
(define-public node-sucrase
(package (inherit node-sucrase0)
(name "node-sucrase")
(arguments
'(#:tests? #f
#:phases
(modify-phases %standard-phases
(delete 'configure)
(add-before 'build 'patch-build
(lambda* (#:key inputs #:allow-other-keys)
(substitute* "script/run.ts"
(("\"/bin/bash\"") (string-append "\"" (search-input-file inputs "/bin/bash") "\"")))
(substitute* "script/build.ts"
(("\"./node_modules/.bin/sucrase\"") (string-append "\"" (search-input-file inputs "/bin/sucrase") "\""))
(("run\\(\"yarn\\b") "run(\"true")
(("\"\\./node_modules/\\.bin/tsc\"") "\"true\"")
(("await mergeDirectoryContents\\(\"\\./dist-types/src\", \"\\./dist/types\"\\);" all) (string-append "// " all))))))))
(native-inputs (list bash node-sucrase0))))
node-sucrase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment