@rsvelte/vite-plugin-svelte-native 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +75 -14
  2. package/package.json +6 -6
package/README.md CHANGED
@@ -1,23 +1,84 @@
1
- # @rsvelte/vite-plugin-svelte
1
+ # @rsvelte/vite-plugin-svelte-native
2
2
 
3
- Workspace package and changesets version anchor for the Vite plugin that delegates to the rsvelte compiler.
3
+ Native (N-API) bindings to the [rsvelte](https://github.com/baseballyama/rsvelte) Svelte 5 compiler, packaged for Node.js. Exposes the same `compile` / `compileModule` / `preprocess` / `hmrDiff` / `resolveId` surface as the official [`svelte/compiler`](https://svelte.dev/docs/svelte-compiler), plus a few low-overhead extras for tooling authors.
4
4
 
5
- ## Status
5
+ > **⚠️ Most users should not depend on this directly.** It's the engine that powers [`@rsvelte/vite-plugin-svelte`](https://github.com/baseballyama/vite-plugin-svelte/tree/rsvelte) — if you want to build a SvelteKit / Vite app with the Rust compiler, use that fork instead. Depend on this package if you're writing a build tool, language server, batch compiler, or any other Node.js program that needs to compile `.svelte` files at maximum speed.
6
6
 
7
- `private: true` until distribution is decided. The Rust side already exposes the napi bindings the plugin will use (`compile`, `preprocess`, `hmrDiff`, `resolveId` in `src/napi.rs`; helpers in `src/vps/`).
7
+ ## Install
8
8
 
9
- The plan in `docs/ecosystem-implementation-plan.md` (Wave 3) splits this into two npm packages:
9
+ ```bash
10
+ npm install @rsvelte/vite-plugin-svelte-native
11
+ # pnpm add @rsvelte/vite-plugin-svelte-native
12
+ # yarn add @rsvelte/vite-plugin-svelte-native
13
+ ```
10
14
 
11
- - `@rsvelte/vite-plugin-svelte` (this directory) — the JS-side Vite plugin façade. Maintains the same public API as `@sveltejs/vite-plugin-svelte`, loads the native module, and translates Vite hooks into NAPI calls.
12
- - `@rsvelte/vite-plugin-svelte-native` — the napi-rs prebuilt-binary package set (one per platform triple), produced by a matrix build.
15
+ The package ships a loader that resolves the right prebuilt `.node` binary for your platform via `optionalDependencies`. Supported targets:
13
16
 
14
- To go live:
17
+ | OS | Architecture |
18
+ |---|---|
19
+ | macOS | arm64, x64 |
20
+ | Linux | x64 (glibc), arm64 (glibc) |
21
+ | Windows | x64 (MSVC) |
15
22
 
16
- 1. Add the napi-rs platform matrix build to CI (target the rsvelte crate with `--features napi`).
17
- 2. Create the `@rsvelte/vite-plugin-svelte-native` workspace package and its per-triple siblings.
18
- 3. Add the JS entrypoint here that imports from `@rsvelte/vite-plugin-svelte-native`.
19
- 4. Flip `private` to `false` on both packages.
23
+ If your platform isn't listed, please [open an issue](https://github.com/baseballyama/rsvelte/issues).
20
24
 
21
- ## Release flow
25
+ ## Quick start
22
26
 
23
- Versioning is handled by the same changesets pipeline as `@rsvelte/compiler`. See `.github/workflows/release.yml`. While this package is `private`, `changeset version` still updates its `version` and `CHANGELOG.md`, but `changeset publish` skips it.
27
+ ```js
28
+ const { compile, compileModule, preprocess, VERSION } = require('@rsvelte/vite-plugin-svelte-native');
29
+
30
+ // Component
31
+ const result = compile('<h1>Hello {name}!</h1>', {
32
+ filename: 'App.svelte',
33
+ generate: 'client', // 'client' | 'server' | false
34
+ });
35
+ console.log(result.js.code);
36
+ console.log(result.css?.code);
37
+
38
+ // Module (.svelte.js / .svelte.ts)
39
+ const mod = compileModule('export const count = $state(0);', {
40
+ filename: 'counter.svelte.js',
41
+ });
42
+
43
+ // Pre-process pipeline (markup / script / style)
44
+ const pre = await preprocess(source, [/* PreprocessorGroup[] */], {
45
+ filename: 'App.svelte',
46
+ });
47
+
48
+ console.log(VERSION); // upstream Svelte version this binding targets
49
+ ```
50
+
51
+ The shape of `CompileOptions`, `CompileResult`, `Warning`, `PreprocessorGroup`, etc. matches the upstream `svelte/compiler` types. See [`index.d.ts`](./index.d.ts) for the complete surface.
52
+
53
+ ## Why use this over `svelte/compiler`?
54
+
55
+ - **Faster.** ~2× single-threaded vs the JS compiler on real corpora; ~15× with `compileBatch` across rayon worker threads.
56
+ - **Drop-in.** Same options, same output shape — wire it into an existing build tool with minimal changes.
57
+ - **Zero-overhead batching.** `compileBatch([...inputs])` compiles N files in parallel across rayon workers and crosses the N-API boundary exactly once.
58
+ - **Async-friendly.** `compileAsync` / `compileBatchAsync` run on libuv worker threads — the JS event loop stays free.
59
+
60
+ ## Performance tips for tool authors
61
+
62
+ This package exposes several levels of compile entry points; pick based on how your tool consumes the result:
63
+
64
+ | Entry point | When to use |
65
+ |---|---|
66
+ | `compile(source, options)` | Default. Returns the upstream `CompileResult` shape; lazy-decodes the underlying envelope so heavy strings (generated code, source map JSON) are read only when accessed. |
67
+ | `compileAsync(source, options)` | Same shape, runs on a libuv worker thread. Use inside Vite middleware, SSR pre-render, or anywhere you don't want to block the event loop. |
68
+ | `compileBatch([{source, options}, …])` | Compile many files in one N-API call. Per-file failures surface as `Error` instances at the corresponding slot — they don't abort the batch. |
69
+ | `compileBatchAsync([...])` | Same, async / off-thread. |
70
+ | `compileEnvelope(source, options)` | Returns a single `Buffer` containing the raw envelope. Useful for `postMessage` across worker threads with `transfer:` — no copy. Pair with `decodeEnvelope(buf)` on the receiving side. |
71
+ | `compileEnvelopeZeroCopy(...)` | Same as `compileEnvelope` but the returned `Buffer` is a view into `bumpalo` arena memory — skips Rust's `Vec` allocation. Faster, but with subtle GC / detach semantics. |
72
+ | `compileBuffers(...)` | Returns `js.code` / `js.map` / `css.code` / `css.map` as raw `Buffer`s. Skip when you can use `compile()` — kept as an escape hatch. |
73
+ | `compileLegacy(...)` | The old JSON-on-the-boundary path. Kept for parity tests; production callers should not use it. |
74
+
75
+ For Svelte source-to-TSX conversion use the bundled `svelte2tsx(source, options)`; for HMR-update diffs use `hmrDiff(prev, curr)`. See [`index.d.ts`](./index.d.ts) for full type signatures.
76
+
77
+ ## Compatibility
78
+
79
+ - **3,341 / 3,341** in-scope tests from the official Svelte 5 compiler test suite pass.
80
+ - `VERSION` tracks the upstream Svelte version (currently `5.51.3`) — it's the *Svelte* compatibility line, not the rsvelte release version.
81
+
82
+ ## License
83
+
84
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsvelte/vite-plugin-svelte-native",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "NAPI bindings to the rsvelte compiler — used by the @rsvelte vite-plugin-svelte shim",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,11 +27,11 @@
27
27
  "index.d.ts"
28
28
  ],
29
29
  "optionalDependencies": {
30
- "@rsvelte/vite-plugin-svelte-native-darwin-arm64": "^0.1.0",
31
- "@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.1.0",
32
- "@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.1.0",
33
- "@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.1.0",
34
- "@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.1.0"
30
+ "@rsvelte/vite-plugin-svelte-native-darwin-arm64": "^0.1.1",
31
+ "@rsvelte/vite-plugin-svelte-native-darwin-x64": "^0.1.1",
32
+ "@rsvelte/vite-plugin-svelte-native-linux-arm64-gnu": "^0.1.1",
33
+ "@rsvelte/vite-plugin-svelte-native-linux-x64-gnu": "^0.1.1",
34
+ "@rsvelte/vite-plugin-svelte-native-win32-x64-msvc": "^0.1.1"
35
35
  },
36
36
  "publishConfig": {
37
37
  "access": "public"