Thank you for your interest in contributing to the VersaTiles Node.js bindings!
- Node.js >= 16
- Rust toolchain (stable)
- Cargo
# Clone the repository
git clone https://github.com/versatiles-org/versatiles-rs.git
cd versatiles-rs/versatiles_node
# Install dependencies
npm install
# Build the native bindings
npm run build:debug # For development
# or
npm run build # For releaseversatiles_node/
├── src/ # Rust source code
│ ├── lib.rs # Main module
│ ├── container.rs # ContainerReader implementation
│ ├── server.rs # TileServer implementation
│ ├── types.rs # Type definitions
│ └── utils.rs # Utilities
├── examples/ # JavaScript examples (not published to NPM)
├── __test__/ # Tests (not published to NPM)
├── Cargo.toml # Rust dependencies
├── package.json # NPM package configuration
├── build.rs # napi-rs build script
├── .npmignore # Files to exclude from NPM package
└── README.md # User documentation
The build process uses napi-rs to create Node.js bindings from Rust code:
- Rust Compilation: Cargo compiles Rust code to native libraries
- Binding Generation: napi-rs generates Node.js bindings
- TypeScript Definitions: Automatically generated from Rust code
- Platform Binaries: Separate packages for each platform
npm run build:debugThis creates a debug build with:
- No optimizations (faster compilation)
- Debug symbols included
- Better error messages
npm run buildThis creates an optimized release build with:
- Full optimizations (LTO enabled)
- Stripped symbols
- Smaller binary size
When published, the NPM package includes only:
✅ Included:
index.js- Generated JavaScript bindingsindex.d.ts- TypeScript type definitions*.node- Native binary for the platformpackage.json- Package metadataREADME.md- User documentation
❌ Excluded (via .npmignore):
src/- Rust source codeexamples/- Example files__test__/- TestsCargo.toml,build.rs- Build configurationtarget/- Build artifacts- Development files
Users download pre-built binaries for their platform via optionalDependencies.
# Make sure you've built first
npm run build:debug
# Run individual examples
node examples/probe.js
node examples/convert.js
node examples/serve.js
node examples/read-tiles.jsTests are written in TypeScript and located in the src/ directory:
// src/example.test.ts
import { describe, test } from 'node:test';
import assert from 'node:assert';
import { ContainerReader } from '../index.js';
describe('Example', () => {
test('should work', async () => {
const reader = await ContainerReader.open('../testdata/berlin.mbtiles');
// ... assertions
});
});Run tests with:
npm test-
Update Rust code in
src/:#[napi] pub async fn new_method(&self) -> Result<String> { Ok("result".to_string()) }
-
Rebuild:
npm run build:debug
-
TypeScript definitions are automatically generated
-
Update documentation in README.md
-
Add example in
examples/if appropriate
- Update type definitions in
src/types.rs - Ensure
#[napi(object)]or#[napi]attributes are correct - Rebuild to generate new TypeScript definitions
- Update documentation
Before submitting a pull request, run:
npm run checkThis runs:
npm run typecheck- TypeScript type checkingnpm run lint- ESLintnpm run format:check- Prettier format validationnpm test- All tests
To automatically fix linting and formatting issues:
npm run fixThis runs:
npm run lint:fix- Auto-fix ESLint issuesnpm run format- Format all files with Prettier
Run checks individually:
npm run typecheck # TypeScript only
npm run lint # ESLint only
npm run format:check # Prettier check only
npm test # Tests only- Strict mode: All TypeScript code must pass strict type checking
- Naming: Use camelCase for variables and functions, PascalCase for classes
- Async: Prefer
async/awaitover raw promises - Error handling: Always handle promise rejections
- Tool: Prettier (automatic formatting)
- Line length: 120 characters (matches Rust)
- Indentation: Tabs (matches Rust)
- Quotes: Single quotes for strings
- Trailing commas: Required
Run npm run format to format all files automatically.
- Tool: ESLint with TypeScript support
- Config: See
eslint.config.mjs - Auto-fix: Run
npm run lint:fix
- Format: Use
cargo fmtto format code - Lint: Use
cargo clippyto check for issues - Style: Follow standard Rust conventions
From the repository root, run all checks (Rust + Node.js):
./scripts/check.shWe recommend Lefthook for automatic quality checks.
Setup:
brew install lefthook # Install
lefthook install # Enable hooksWhat happens:
- Pre-commit: Fast checks (formatting, linting, type-checking)
- Pre-push: Full checks (including tests)
See Pre-commit Hooks section for details.
We recommend using Lefthook to automatically run checks before commits and pushes.
macOS:
brew install lefthookLinux:
# Debian/Ubuntu
curl -1sLf 'https://dl.cloudsmith.io/public/evilmartians/lefthook/setup.deb.sh' | sudo -E bash
sudo apt install lefthook
# Or download binary from GitHub releasesWindows:
scoop install lefthookAfter installing Lefthook, activate the hooks:
cd /path/to/versatiles-rs
lefthook install- Pre-commit: Fast checks (formatting, linting, type-checking)
- Pre-push: Full checks (all of the above + tests)
If you need to skip hooks temporarily:
# Skip pre-commit hooks
LEFTHOOK=0 git commit -m "message"
# Skip specific hook
lefthook run pre-commit --exclude rust-fmtlefthook uninstallAll checks run automatically in GitHub Actions CI:
- Rust formatting, linting, tests
- Node.js type-checking, linting, formatting, tests
- Code coverage reporting
Pull requests must pass all CI checks before merging.
Before publishing a new version:
- Update version in
package.json - Update
CHANGELOG.md(if exists) - Run
cargo build --releaseto verify Rust compilation - Run
npm run buildto verify Node.js build - Test on multiple platforms if possible
- Update documentation if API changed
- Tag release in git
- GitHub Actions will build platform binaries
- Publish to NPM:
npm publish --access public
The package supports multiple platforms through separate packages:
@versatiles/versatiles-rs-darwin-x64(macOS Intel)@versatiles/versatiles-rs-darwin-arm64(macOS Apple Silicon)@versatiles/versatiles-rs-linux-x64-gnu(Linux x64)@versatiles/versatiles-rs-linux-arm64-gnu(Linux ARM64)@versatiles/versatiles-rs-linux-x64-musl(Alpine Linux x64)@versatiles/versatiles-rs-linux-arm64-musl(Alpine Linux ARM64)@versatiles/versatiles-rs-win32-x64-msvc(Windows x64)
GitHub Actions builds these automatically on release.
You need to build the project first:
npm run build:debugMake sure you have the latest stable Rust:
rustup update stableCheck the napi-rs documentation or GitHub issues.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: VersaTiles Docs
By contributing, you agree that your contributions will be licensed under the MIT License.