Skip to content

Commit baba23f

Browse files
chore: reduce sv API surface (#1046)
Co-authored-by: Scott Wu <sw@scottwu.ca>
1 parent 277f94b commit baba23f

32 files changed

Lines changed: 1585 additions & 189 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'sv': minor
3+
'@sveltejs/sv-utils': minor
4+
---
5+
6+
feat: decouple sv / sv-utils, explicit public API, deprecation pass
7+
8+
**`@sveltejs/sv-utils`**
9+
10+
- Rename file helpers: `readFile` -> `loadFile`, `writeFile` -> `saveFile`, `getPackageJson` -> `loadPackageJson`
11+
- Add `pnpm.onlyBuiltDependencies()` transform for `pnpm-workspace.yaml`
12+
- Export `YamlDocument` type from parsers
13+
- Remove `commonFilePaths`, `installPackages` (moved internal to `sv`)
14+
15+
**`sv`**
16+
17+
- `create()` signature changed to `create({ cwd, ...options })`. The old `create(cwd, options)` is deprecated and will be removed in the next major release.
18+
- `sv.pnpmBuildDependency()` is deprecated and will be removed in the next major release. Use `sv.file()` with `pnpm.onlyBuiltDependencies()` from `@sveltejs/sv-utils` instead.
19+
- `workspace.file.prettierignore`, `.prettierrc`, `.eslintConfig`, `.vscodeSettings`, `.vscodeExtensions` are deprecated and will be removed in the next major release. Use the raw strings directly (e.g. `'.prettierignore'`).
20+
- Add `workspace.file.findUp()` to locate files by walking up the directory tree.
21+
- Add `api-surface.md` snapshots (auto-generated on build) to track the public API of `sv` and `@sveltejs/sv-utils`.
22+
- Remove `setup`, `createProject`, `startPreview`, `addPnpmBuildDependencies` from `sv/testing` exports.
23+
- Make type exports explicit (no more `export type *`). Removed types that were never part of the intended public API: `PackageDefinition`, `Scripts`, `TestDefinition`.

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,30 @@ To run svelte-migrate locally:
153153
node ./packages/migrate/bin.js
154154
```
155155

156+
## Deprecation
157+
158+
Public APIs cannot be changed in a minor release since it is a breaking change. Instead, the old behaviour is marked as deprecated until the next major version, at which point they can be removed.
159+
160+
### How to deprecate
161+
162+
1. **Add `@deprecated` JSDoc** on the type/function - IDEs will show strikethrough:
163+
164+
```ts
165+
/** @deprecated use `newThing()` instead. */
166+
```
167+
168+
2. **Emit a runtime warning** (for functions/methods) using `svDeprecated()` from `core/deprecated.ts`. Warns once per message:
169+
170+
```ts
171+
svDeprecated('use `newThing()` instead of `oldThing()`');
172+
```
173+
174+
3. **Keep the old behavior working** - the deprecated API should still function correctly, just with a warning.
175+
176+
### Before a major release
177+
178+
Search for `svDeprecated` and `@deprecated` to find and remove all deprecated APIs.
179+
156180
## Generating changelogs
157181

158182
Here is the command to generate a change set:

documentation/docs/50-api/20-sv-utils.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Return `false` from any transform callback to abort - the original content is re
137137
import { transforms } from '@sveltejs/sv-utils';
138138

139139
sv.file(
140-
file.eslintConfig,
140+
'eslint.config.js',
141141
transforms.script(({ ast, js }) => {
142142
const { value: existing } = js.exports.createDefault(ast, { fallback: myConfig });
143143
if (existing !== myConfig) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"scripts": {
1111
"build": "tsdown",
12+
"postbuild": "node scripts/generate-api-surface.js",
1213
"changeset:publish": "changeset publish",
1314
"check": "pnpm --parallel check",
1415
"dev": "tsdown -w & pnpm --parallel check -w & wait",

0 commit comments

Comments
 (0)