|
| 1 | +# Publishing your grammar |
| 2 | + |
| 3 | +Once you feel that your parser is in a stable working state for consumers to use, you can publish it to various registries. |
| 4 | +It's strongly recommended to publish grammars to GitHub, [crates.io][crates.io] (Rust), [npm][npm] (JavaScript), and [PyPI][pypi] |
| 5 | +(Python) to make it easier for others to find and use your grammar. |
| 6 | + |
| 7 | +If your grammar is hosted on GitHub, you can make use of our [reusable workflows][workflows] to handle the publishing process |
| 8 | +for you. This action will automatically handle regenerating and publishing your grammar in CI, so long as you have the required |
| 9 | +tokens setup for the various registries. For an example of this workflow in action, see the [Python grammar's GitHub][python-gh] |
| 10 | + |
| 11 | +## From start to finish |
| 12 | + |
| 13 | +To release a new grammar (or publish your first version), these are the steps you should follow: |
| 14 | + |
| 15 | +1. Bump your version to the desired version with `tree-sitter version`. For example, if you're releasing version `1.0.0` |
| 16 | +of your grammar, you'd run `tree-sitter version 1.0.0`. |
| 17 | +2. Commit the changes with `git commit -am "Release 1.0.0" (or however you like)` (ensure that your working directory is |
| 18 | +clean). |
| 19 | +3. Tag the commit with `git tag -- v1.0.0`. |
| 20 | +4. Push the commit and tag with `git push --tags origin main` (assuming you're on the `main` branch, and `origin` is your |
| 21 | +remote). |
| 22 | +5. (optional) If you've set up the GitHub workflows for your grammar, the release will be automatically published to GitHub, |
| 23 | +crates.io, npm, and PyPI. |
| 24 | + |
| 25 | +### Adhering to Semantic Versioning |
| 26 | + |
| 27 | +When releasing new versions of your grammar, it's important to adhere to [Semantic Versioning][semver]. This ensures that |
| 28 | +consumers can predictably update their dependencies and that their existing tree-sitter integrations (queries, tree traversal |
| 29 | +code, node type checks) will continue to work as expected when upgrading. |
| 30 | + |
| 31 | +1. Increment the major version when you make incompatible changes to the grammar's node types or structure |
| 32 | +2. Increment the minor version when you add new node types or patterns while maintaining backward compatibility |
| 33 | +3. Increment the patch version when you fix bugs without changing the grammar's structure |
| 34 | + |
| 35 | +For grammars in version 0.y.z (zero version), the usual semantic versioning rules are technically relaxed. However, if your |
| 36 | +grammar already has users, it's recommended to treat version changes more conservatively: |
| 37 | + |
| 38 | +- Treat patch version (`z`) changes as if they were minor version changes |
| 39 | +- Treat minor version (`y`) changes as if they were major version changes |
| 40 | + |
| 41 | +This helps maintain stability for existing users during the pre-1.0 phase. By following these versioning guidelines, you |
| 42 | +ensure that downstream users can safely upgrade without their existing queries breaking. |
| 43 | + |
| 44 | +[crates.io]: https://crates.io |
| 45 | +[npm]: https://www.npmjs.com |
| 46 | +[pypi]: https://pypi.org |
| 47 | +[python-gh]: https://github.com/tree-sitter/tree-sitter-python/blob/master/.github/workflows/publish.yml |
| 48 | +[semver]: https://semver.org/ |
| 49 | +[workflows]: https://github.com/tree-sitter/workflows |
0 commit comments