new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Svelte · CLI and AI tooling · all subjects

sv-utils

18 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

transforms.text callback parameters

transforms.text callback receives { content, text }. No parser is used - string in, string out.

Aborting a transform

Return false from any transform callback to abort. The original content is returned unchanged.

sv-utils is experimental

@sveltejs/sv-utils is currently experimental. The API may change.

sv-utils installation

Install @sveltejs/sv-utils with: npm install -D @sveltejs/sv-utils

transforms.script callback parameters

transforms.script callback receives { ast, comments, content, js }.

transforms.svelte callback parameters

transforms.svelte callback receives { ast, content, svelte, js }.

transforms.svelteScript callback parameters

transforms.svelteScript callback receives { ast, content, svelte, js } where ast.instance is guaranteed to be non-null. Pass { language } as the first argument.

transforms.css callback parameters

transforms.css callback receives { ast, content, css }.

transforms.json callback parameters

transforms.json callback receives { data, content, json }. Mutate the data object directly.

transforms.yaml and transforms.toml callback parameters

transforms.yaml and transforms.toml callbacks receive { data, content }.

transforms are curried functions

Transforms are curried functions. Call them with the callback, then apply to content: const transform = transforms.script(callback); const result = transform(content);

parse API low-level usage

Low-level parse API returns { ast, generateCode } for script, svelte, css, and html. Returns { data, generateCode } for json, yaml, and toml. Usage: import { parse } from '@sveltejs/sv-utils'; const { ast, generateCode } = parse.script(content);

Language tooling namespaces

sv-utils provides namespaced helpers for AST manipulation: js.* for imports/exports/objects/arrays/variables/functions/vite/SvelteKit; css.* for rules/declarations/at-rules/imports; svelte.* for ensureScript/addSlot/addFragment; json.* for arrayUpsert/packageScriptsUpsert; html.* for attribute manipulation; text.* for upsert lines in flat files.

Svelte config location

The svelte/kit config can live in two places: passed to the sveltekit() plugin in vite.config.{js,ts}, or as a default export in svelte.config.{js,ts}. Projects created by sv keep config inside vite.config.js and ship no svelte.config.js.

svelteConfig option nesting rules

Svelte-level options (compilerOptions, preprocess, extensions, vitePlugin) sit on the config object. Kit options (adapter, alias, files, typescript, etc.) are flattened onto the sveltekit() argument in a vite config, or nested under kit in a svelte.config.

svelteConfig.edit method

svelteConfig.edit({ sv, cwd }, callback) allows add-ons to read and edit svelte config. The callback receives { ast, property, override, js }. Use property(name, { fallback }) to get-or-create an option's value, and override(props, { dropLeadingComments }) to set/replace options.

svelteConfig.find and svelteConfig.read methods

svelteConfig.find(read) returns { path, kind } or null (kind is 'vite' or 'svelte'; svelte.config wins when both present). svelteConfig.read(read) locates and parses in one pass, returning { location, config, kit } (the object expressions) or null.

pnpm.allowBuilds helper

pnpm.allowBuilds(packageName) returns a transform for pnpm-workspace.yaml. For pnpm >= 11: writes to unified allowBuilds map ({ pkg: true }), migrating legacy onlyBuiltDependencies list. For pnpm < 11: writes to legacy onlyBuiltDependencies list.

Give your agent this brain