Say you want to write a program that consumes a tree-sitter grammar you've written, using the node-tree-sitter package. How do you package the grammar you've written for consumption? What is the minimal set of files that must be included in the node module? In the package.json file of the javascript module there's a section specific to tree-sitter, is it important to fill that out?
Asked
Active
Viewed 478 times
1 Answers
2
No, that section of the package.json
is only used by the tree-sitter
CLI tool, when running tree-sitter parse
or tree-sitter highlight
. It is described here.
To use a Tree-sitter grammar with node-tree-sitter
, you just need to ensure that the nan
module is included in the dependencies
of your package.json. The tree-sitter generate
command will generate the other files that are needed for exposing the code to Node.js: binding.gyp
and src/binding.cc
. If you want to publish your module to npmjs.com, you can do that with the usual commands (e.g. npm publish
).

maxbrunsfeld
- 341
- 2
- 2
-
1I will also add here that if you just want to import your grammar module locally without publishing it, you have to re-run `npm install` in your grammar directory after every change to the grammar. – ahelwer Jul 25 '20 at 23:25