Conversation
Typed, parser-aware `string -> string` functions that wrap parse -> callback(ast/data) -> generateCode(). Includes transforms for script, svelte, css, json, yaml, toml, html, and text. The engine detects transforms via `isTransform()` and injects workspace context (language) automatically.
Mechanical migration: every `sv.file()` callback that followed the parse -> mutate -> generateCode pattern now uses the typed transform. `parse` is retained only where transforms don't fit: - prettier.ts: try/catch around JSON parsing - sveltekit-adapter.ts: conditional parser (json vs toml) and standalone parse outside sv.file
|
commit: |
|
I thought I wrote that somewhere already, but I might be imagining. I would suggest something like this, because I do get what you want to abstract: transforms.script(sv, filePath, () => {
// some random code
}):This would fully replace the Alternatively you could also get me to vote for having What do you think? |
|
Thx for sharing, I'll play around with these apis 👍👍👍 |
Why I like D/ explicit content
Style convention
@manuel3108 WDYT ? :D |
|
Here are my off the wall ideas. curried functionAlternative to option D, reads like option A. If type transforms = {
// svelte: (content, ast) => ast
svelte: (ast) => (content) => ast
}you could do something like this. sv.file(path, transforms.svelte((ast) => {
svelte.addFragment(ast, `<p>Hello ${options.who}!</p>`);
}));but if you need sv.file(path, content => transforms.svelte((ast) => {
svelte.addFragment(ast, `<p>Hello ${options.who}!</p>`);
})(content);
);two APIsMore or less what @manuel3108 said but keeping them similar looking for conhesiveness. One for the common case, the other for a comprehensive case. sv.file.svelte(path, (ast) => {...})
sv.file(path, (content) => {
const step1 = transform.svelte(content, (ast) => {...})
const step2 = transform.text(content, (ast) => {...})
return step2
}transforms.svelte(sv, path, (ast) => {...})
transforms.custom(sv, path, ...)Might as well give me the utilI'm already calling // original
import { transforms, svelte } from '@sveltejs/sv-utils';
sv.file(path, (content) => {
return transforms.svelte(content, (ast) => {
svelte.addFragment(ast, `<p>Hello ${options.who}!</p>`);
});
});// proposal
-import { transforms, svelte } from '@sveltejs/sv-utils';
+import { transforms } from '@sveltejs/sv-utils';
sv.file(path, (content) => {
- return transforms.svelte(content, (ast) => {
+ return transforms.svelte(content, (ast, svelte) => {
svelte.addFragment(ast, `<p>Hello ${options.who}!</p>`);
});
});some kind of injectionrun: ({ isKit, cancel, sv, options, directory }) => {
if (!isKit) return cancel('SvelteKit is required');
const file = sv.load(transforms)
// Add "Hello [who]!" to the root page
file.svelte(path, (content) => {
return transforms.svelte(content, (ast) => {...});
}); |
|
@jycouet You wrote in the PR description
But is that actually true? Because each addon & community addon should receive If I would need to make the decision right now only based on my personal preferences and dx, I would combine my suggestion with one from @sacrosanctic sv.file.svelte(path, ({ ast, utils }) => {
utils.addFragment(ast, `<p>Hello ${options.who}!</p>`)
})this
potential cons:
But given my recent activity in this project im totally open if you guys decide on continue with another solution. Just adding my two cents here :D |
This is the most import IMO ^^. official add-ons are an "exception" of sv... (I don't know how to say it) I wanted to write this here quickly ^^, will now look closely all your option @sacrosanctic & @manuel3108 :D |
|
@manuel3108 @sacrosanctic , another round of comments with this style? let's call it option sv.file(path, transforms.svelte(({ast, content, svelte, js, ... }) => {
svelte.addFragment(ast, '<p>Hello!</p>');
})); |

transformsAPI — Options exploredProblem
Every addon repeats the same boilerplate:
parse → manipulate AST → return generateCode().Constraint
sv(engine) andsv-utilsmust stay independent; separate packages, separate versioning.Options
sv.file(path, transforms.script((ast) => {...}))contentisTransform()in engine, engine needs to know sv-utils typessv.filesv.file.script(path, (ast) => {...})sv, can't version independentlysvto transformstransforms.script(sv, path, (ast) => {...})sv.file()contractsv.file(path, (content) => { return transforms.script(content, (ast) => {...}); })Prep for community add-on improvements.