@@ -488,3 +488,90 @@ (define-public tree-sitter-rust
(description
"This package provides a Rust grammar for the Tree-sitter library.")
(license license:expat)))
+
+(define-public tree-sitter-typescript
+ (let ((commit "111b07762e86efab9a918b7c721f720c37e76b0a")
+ (revision "1"))
+ (package (inherit tree-sitter-c)
+ (name "tree-sitter-typescript")
+ (version (git-version "0.20.0" revision commit))
+ (source (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/tree-sitter/tree-sitter-typescript")
+ (commit commit)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "1364bm3wbqqzvp03cvpx1w89bbqynb1v62i46gy7f6rhib9bf63a"))
+ (modules '((guix build utils)))
+ (snippet
+ '(begin
+ (for-each
+ (lambda (lang)
+ (with-directory-excursion lang
+ (delete-file "src/grammar.json")
+ (delete-file "src/node-types.json")
+ (delete-file "src/parser.c")
+ (delete-file-recursively "src/tree_sitter")))
+ '("typescript" "tsx"))
+ #t))))
+ (inputs
+ (list node-nan
+ `(,tree-sitter-javascript "js")))
+ (arguments
+ (substitute-keyword-arguments (package-arguments tree-sitter-c)
+ ((#:phases phases)
+ #~(modify-phases #$phases
+ ;; The parse-example script tries to clone git repositories.
+ (add-after 'unpack 'remove-parse-example
+ (lambda _
+ (substitute* "package.json"
+ ((" && script\\/parse-examples") ""))))
+ (add-after 'build 'build-gyp
+ (lambda* (#:key inputs #:allow-other-keys)
+ (invoke
+ (search-input-file
+ inputs
+ "/lib/node_modules/npm/bin/node-gyp-bin/node-gyp")
+ "build")))
+ (replace 'tree-sitter-generate
+ (lambda _
+ (for-each (lambda (dir)
+ (with-directory-excursion dir
+ (invoke "tree-sitter" "generate")))
+ '("typescript" "tsx"))))
+ (replace 'build-and-install-lib
+ (lambda* (#:key outputs #:allow-other-keys)
+ (use-modules (guix build json))
+ (let ((name (assoc-ref
+ (call-with-input-file "package.json" read-json)
+ "name"))
+ (lib (string-append #$output "/lib/tree-sitter/")))
+ (mkdir-p lib)
+ (define (source-file? basename)
+ "document me"
+ (let ((path (string-append src "/" basename)))
+ (if (file-exists? path)
+ path
+ #f)))
+ (for-each
+ (lambda (lang)
+ (let ((src (string-append #$output:js
+ "/lib/node_modules/"
+ name "/" lang "/src")))
+ (invoke #$(cc-for-target)
+ "-shared"
+ "-fPIC"
+ "-fno-exceptions"
+ "-O2"
+ "-g"
+ "-o" (string-append lib "/" lang ".so")
+ (string-append src "/scanner.c")
+ (string-append src "/parser.c"))))
+ '("typescript" "tsx")))))))))
+ (home-page "https://github.com/tree-sitter/tree-sitter-typescript")
+ (synopsis "Tree-sitter Typescript grammar")
+ (description
+ "This package provides Typescript and TSX grammars for the Tree-sitter
+library.")
+ (license license:expat))))