You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> `sv` owns the file system -`sv.file()` resolves the path, reads the file, applies the edit function, and writes the result.
63
-
> `@sveltejs/sv-utils` owns the content -`transforms.svelte()`returns a curried function that handles parsing, gives you the AST and utils, and serializes back. See [sv-utils](/docs/cli/sv-utils) for the full API.
65
+
> `sv` owns the file system —`sv.file()` resolves the path, reads the file, applies the transform, and writes the result.
66
+
> `@sveltejs/sv-utils` owns the content —`transforms.svelte()` handles parsing, gives you the AST, and serializes back. See [sv-utils](/docs/cli/sv-utils) for the full API.
64
67
65
68
## Development with `file:` protocol
66
69
@@ -176,7 +179,7 @@ npm publish
176
179
You can optionally display guidance after your add-on runs:
The Svelte CLI is split into two packages with a clear boundary:
17
17
18
18
-**`sv`** = **where and when** to do it. It owns paths, workspace detection, dependency tracking, and file I/O. The engine orchestrates add-on execution.
19
-
-**`@sveltejs/sv-utils`** = **what** to do to content. It provides parsers, language tooling, and typed transforms. Everything here is pure - no file system, no workspace awareness.
19
+
-**`@sveltejs/sv-utils`** = **what** to do to content. It provides parsers, language tooling, and typed transforms. Everything here is pure — no file system, no workspace awareness.
20
20
21
21
This separation means transforms are testable without a workspace and composable across add-ons.
22
22
23
23
## Transforms
24
24
25
-
Transforms are curried, parser-aware functions that turn `string -> string`. Call a transform with your callback to get a function that plugs directly into `sv.file()`. The parser choice is baked into the transform type - you can't accidentally parse a vite config as Svelte because you never call a parser yourself.
26
-
27
-
Each transform injects relevant utilities into the callback, so you only need one import:
25
+
Transforms are typed, parser-aware functions that turn `string -> string`. The parser choice is baked into the transform type — you can't accidentally parse a vite config as Svelte because you never call a parser yourself.
Transform a Svelte component with a `<script>` block guaranteed. Pass `{ language }` as the first argument. The callback receives `{ ast, content, svelte, js }` where `ast.instance` is always non-null.
0 commit comments