svelte-check-native is designed for performance, offering a blazing fast type-checking experience for Svelte projects. Serving as a drop-in replacement for svelte-check, it retains all existing flags and output formats. Ideal for integrating into CI/CD pipelines or pre-commit hooks, it leverages Rust and tsgo for efficiency.
svelte-check-native
svelte-check-native is a high-performance command-line interface (CLI) type-checker specifically designed for Svelte projects. It serves as a drop-in replacement for svelte-check, maintaining compatibility with the same flags, output formats, and exit codes. This tool is built with Rust and leverages tsgo, making it ideal for:
- AI agents that require rapid feedback loops
- Efficient CI/CD pipelines
- Reliable Git pre-commit hooks
What it is and what it isn't
| It is | It isn't |
|---|---|
| A CLI type-checker for Svelte 4 and 5 | An LSP / editor integration |
A drop-in for svelte-check (flags + output) | A CSS linter |
| A single Rust binary, powered by tsgo | A formatter |
| Provides byte-identical diagnostics upstream | |
Supports incremental checking via tsgo's tsbuildinfo |
Performance
When tested on a SvelteKit + TypeScript monorepo containing 1,359 .svelte files, the performance metrics are as follows:
Command executed: svelte-check-native --tsconfig tsconfig.json --diagnostic-sources 'js,svelte'
| Tool | Cold | Warm | Dirty | Speedup | Errors | Warnings | Files w/ issues |
|---|---|---|---|---|---|---|---|
svelte-check-native | 6.0 s | 2.6 s | 2.6 s | 15.8× | 1 | 44 | 16 |
svelte-check 4.4.6 | 39.9 s | 41.0 s | 41.0 s | 1.0× | 1 | 44 | 16 |
svelte-check-rs 0.9.7 | 15.0 s | 5.5 s | 4.4 s | 6.9× | 732 | 44 | 261 |
Installation
To install svelte-check-native, execute the following command:
npm i -D svelte-check-native @typescript/native-preview
The package @typescript/native-preview denotes the tsgo binary, essential for the checking process.
Usage
To utilize svelte-check-native, run:
npx svelte-check-native --workspace .
Alternatively, script it into your package.json:
{
"scripts": {
"check": "svelte-check-native --workspace ."
}
}
This tool supports the same flags as svelte-check. For assistance, use:
npx svelte-check-native --help
How it Works
The type-checking process involves:
- Parsing each
.sveltefile into script and template sections. - Emitting a corresponding
.svelte.tsoverlay file. - Executing
tsgoagainst the overlay TypeScript configuration. - Running the
svelte/compilerfor warnings via parallel processing. - Mapping diagnostics back to the original
.sveltefile.
Flags and Environment Variables
Various flags are available for customized operation:
--workspace <path>
--tsconfig <path>
--output <fmt>
--threshold <level>
--fail-on-warnings
--diagnostic-sources <list>
--compiler-warnings <list>
--ignore <globs>
--color / --no-color
--timings
--debug-paths
--tsgo-version
--tsgo-diagnostics
--emit-ts
For detailed functionality, reviewing the output of svelte-check-native --help is recommended.
Additional environment variables may also influence the tool's behavior, such as TSGO_BIN for overriding tsgo discovery paths.
Troubleshooting
In case of stale errors after modifying tsconfig.json, the following command can be run to clear the cache:
rm -rf node_modules/.cache/svelte-check-native
Roadmap
Future features include CSS support for enhanced versatility.
For developers requiring speed and accuracy in type-checking their Svelte applications, svelte-check-native provides an efficient, Rust-optimized solution that seamlessly integrates into existing workflows.
No comments yet.
Sign in to be the first to comment.