Skip to content

Commit 5f84095

Browse files
authored
adjustments (#1051)
1 parent 5c4683e commit 5f84095

File tree

10 files changed

+62
-48
lines changed

10 files changed

+62
-48
lines changed

.changeset/coupling-sv-and-sv-utils.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ feat: decouple sv / sv-utils, explicit public API, deprecation pass
1414

1515
**`sv`**
1616

17-
- `create()` signature changed to `create({ cwd, ...options })`. The old `create(cwd, options)` form still works but is deprecated and will be removed in the next major.
18-
- `sv.pnpmBuildDependency()` is deprecated. Use `sv.file()` with `pnpm.onlyBuiltDependencies()` from `@sveltejs/sv-utils` instead. Still works for now.
19-
- `workspace.file.prettierignore`, `.prettierrc`, `.eslintConfig`, `.vscodeSettings`, `.vscodeExtensions` are deprecated. Use the raw strings directly (e.g. `'.prettierignore'`). Still works for now.
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'`).
2020
- Add `workspace.file.findUp()` to locate files by walking up the directory tree.
21-
- Make type exports explicit (no more `export type *`). Removed types that were never part of the intended public API: `PackageDefinition`, `Scripts`, `TestDefinition`.
22-
- Remove `setup`, `createProject`, `startPreview`, `addPnpmBuildDependencies` from `sv/testing` exports.
2321
- 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,16 @@ To run svelte-migrate locally:
153153
node ./packages/migrate/bin.js
154154
```
155155

156-
## Deprecation pattern
156+
## Deprecation
157157

158-
When removing public API from `sv`, **do not hard-remove** it. Instead, deprecate it and keep it working until the next major version.
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.
159159

160160
### How to deprecate
161161

162162
1. **Add `@deprecated` JSDoc** on the type/function - IDEs will show strikethrough:
163163

164164
```ts
165-
/** @deprecated use `newThing()` instead */
165+
/** @deprecated use `newThing()` instead. */
166166
```
167167

168168
2. **Emit a runtime warning** (for functions/methods) using `svDeprecated()` from `core/deprecated.ts`. Warns once per message:
@@ -175,7 +175,7 @@ When removing public API from `sv`, **do not hard-remove** it. Instead, deprecat
175175

176176
### Before a major release
177177

178-
Search for `svDeprecated` and `@deprecated` to find and remove all deprecated APIs:
178+
Search for `svDeprecated` and `@deprecated` to find and remove all deprecated APIs.
179179

180180
## Generating changelogs
181181

packages/sv-utils/src/files.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ export type Package = {
1414
};
1515

1616
/** Check if a file exists at the given workspace-relative path. */
17+
/**
18+
* Checks the file.
19+
* @param filePath - Resolves paths relative to the workspace.
20+
*/
1721
export function fileExists(cwd: string, filePath: string): boolean {
1822
const fullFilePath = path.resolve(cwd, filePath);
1923
return fs.existsSync(fullFilePath);
2024
}
2125

22-
/** Synchronous load of a workspace-relative file; missing files yield `''`. */
26+
/**
27+
* Reads the file.
28+
* @param filePath - Resolves paths relative to the workspace.
29+
* @returns The raw UTF-8 text, or `''` if the file is not found.
30+
*/
2331
export function loadFile(cwd: string, filePath: string): string {
2432
const fullFilePath = path.resolve(cwd, filePath);
2533

@@ -32,7 +40,10 @@ export function loadFile(cwd: string, filePath: string): string {
3240
return text;
3341
}
3442

35-
/** Synchronous write of a workspace-relative file (creates parent dirs). */
43+
/**
44+
* Writes the file. Will make parent directories as needed.
45+
* @param filePath - Resolves paths relative to the workspace.
46+
*/
3647
export function saveFile(cwd: string, filePath: string, content: string): void {
3748
const fullFilePath = path.resolve(cwd, filePath);
3849
const fullDirectoryPath = path.dirname(fullFilePath);
@@ -47,6 +58,13 @@ export function saveFile(cwd: string, filePath: string, content: string): void {
4758
}
4859

4960
/** Load and parse a workspace-relative `package.json`. Throws if missing or invalid. */
61+
/**
62+
* Loads the workspace `package.json`.
63+
* @returns
64+
* - `source`: The raw UTF-8 text.
65+
* - `data`: The parsed JSON object.
66+
* - `generateCode`: A function to serialize the data back to a string.
67+
*/
5068
export function loadPackageJson(cwd: string): {
5169
source: string;
5270
data: Package;

packages/sv/src/cli/create.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,10 +480,8 @@ export async function createVirtualWorkspace({
480480
file: {
481481
...tentativeWorkspace.file,
482482
viteConfig:
483-
type === 'typescript'
484-
? common.commonFilePaths.viteConfigTS
485-
: common.commonFilePaths.viteConfig,
486-
svelteConfig: common.commonFilePaths.svelteConfig // currently we always use js files, never typescript files
483+
type === 'typescript' ? common.filePaths.viteConfigTS : common.filePaths.viteConfig,
484+
svelteConfig: common.filePaths.svelteConfig // currently we always use js files, never typescript files
487485
}
488486
};
489487

packages/sv/src/core/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export function updateAgent(
325325
}
326326
}
327327

328-
export const commonFilePaths = {
328+
export const filePaths = {
329329
packageJson: 'package.json',
330330
svelteConfig: 'svelte.config.js',
331331
svelteConfigTS: 'svelte.config.ts',

packages/sv/src/core/engine.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@sveltejs/sv-utils';
1111
import { NonZeroExitError, exec } from 'tinyexec';
1212
import { createLoadedAddon } from '../cli/add.ts';
13-
import { commonFilePaths } from './common.ts';
13+
import { filePaths } from './common.ts';
1414
import {
1515
getErrorHint,
1616
type Addon,
@@ -53,8 +53,8 @@ function updatePackages(
5353
if (data.devDependencies)
5454
data.devDependencies = alphabetizePackageJsonDependencies(data.devDependencies);
5555

56-
saveFile(cwd, commonFilePaths.packageJson, generateCode());
57-
return commonFilePaths.packageJson;
56+
saveFile(cwd, filePaths.packageJson, generateCode());
57+
return filePaths.packageJson;
5858
}
5959

6060
export type InstallOptions<Addons extends AddonMap> = {

packages/sv/src/core/workspace.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import * as find from 'empathic/find';
1010
import fs from 'node:fs';
1111
import path from 'node:path';
12-
import { commonFilePaths } from './common.ts';
12+
import { filePaths } from './common.ts';
1313
import { svDeprecated } from './deprecated.ts';
1414
import type { OptionDefinition, OptionValues } from './options.ts';
1515
import { detectPackageManager } from './package-manager.ts';
@@ -38,15 +38,15 @@ export type Workspace = {
3838
package: 'package.json';
3939
gitignore: '.gitignore';
4040

41-
/** @deprecated use the string `'.prettierignore'` directly */
41+
/** @deprecated use the string `.prettierignore` instead. */
4242
prettierignore: '.prettierignore';
43-
/** @deprecated use the string `'.prettierrc'` directly */
43+
/** @deprecated use the string `.prettierrc` instead. */
4444
prettierrc: '.prettierrc';
45-
/** @deprecated use the string `'eslint.config.js'` directly */
45+
/** @deprecated use the string `eslint.config.js` instead. */
4646
eslintConfig: 'eslint.config.js';
47-
/** @deprecated use the string `'.vscode/settings.json'` directly */
47+
/** @deprecated use the string `.vscode/settings.json` instead. */
4848
vscodeSettings: '.vscode/settings.json';
49-
/** @deprecated use the string `'.vscode/extensions.json'` directly */
49+
/** @deprecated use the string `.vscode/extensions.json` instead. */
5050
vscodeExtensions: '.vscode/extensions.json';
5151

5252
/** Get the relative path between two files */
@@ -87,18 +87,16 @@ export async function createWorkspace({
8787
const resolvedCwd = path.resolve(cwd);
8888

8989
// Will go up and prioritize jsconfig.json as it's first in the array
90-
const typeConfigOptions = [commonFilePaths.jsconfig, commonFilePaths.tsconfig];
90+
const typeConfigOptions = [filePaths.jsconfig, filePaths.tsconfig];
9191
const typeConfig = find.any(typeConfigOptions, { cwd }) as Workspace['file']['typeConfig'];
92-
const typescript = typeConfig?.endsWith(commonFilePaths.tsconfig) ?? false;
92+
const typescript = typeConfig?.endsWith(filePaths.tsconfig) ?? false;
9393
// This is not linked with typescript detection
94-
const viteConfigPath = path.join(resolvedCwd, commonFilePaths.viteConfigTS);
95-
const viteConfig = fs.existsSync(viteConfigPath)
96-
? commonFilePaths.viteConfigTS
97-
: commonFilePaths.viteConfig;
98-
const svelteConfigPath = path.join(resolvedCwd, commonFilePaths.svelteConfigTS);
94+
const viteConfigPath = path.join(resolvedCwd, filePaths.viteConfigTS);
95+
const viteConfig = fs.existsSync(viteConfigPath) ? filePaths.viteConfigTS : filePaths.viteConfig;
96+
const svelteConfigPath = path.join(resolvedCwd, filePaths.svelteConfigTS);
9997
const svelteConfig = fs.existsSync(svelteConfigPath)
100-
? commonFilePaths.svelteConfigTS
101-
: commonFilePaths.svelteConfig;
98+
? filePaths.svelteConfigTS
99+
: filePaths.svelteConfig;
102100

103101
let dependencies: Record<string, string> = {};
104102
if (override?.dependencies) {
@@ -113,7 +111,7 @@ export async function createWorkspace({
113111
// we are still in the workspace (including the workspace root)
114112
directory.length >= workspaceRoot.length
115113
) {
116-
if (fs.existsSync(path.join(directory, commonFilePaths.packageJson))) {
114+
if (fs.existsSync(path.join(directory, filePaths.packageJson))) {
117115
const { data: packageJson } = loadPackageJson(directory);
118116
dependencies = {
119117
...packageJson.devDependencies,
@@ -156,35 +154,35 @@ export async function createWorkspace({
156154
/** @deprecated */
157155
get prettierignore() {
158156
svDeprecated(
159-
'`workspace.file.prettierignore` is deprecated, use the string `".prettierignore"` directly'
157+
'`workspace.file.prettierignore` is deprecated, use the string `.prettierignore` isntead.'
160158
);
161159
return '.prettierignore' as const;
162160
},
163161
/** @deprecated */
164162
get prettierrc() {
165163
svDeprecated(
166-
'`workspace.file.prettierrc` is deprecated, use the string `".prettierrc"` directly'
164+
'`workspace.file.prettierrc` is deprecated, use the string `.prettierrc` isntead.'
167165
);
168166
return '.prettierrc' as const;
169167
},
170168
/** @deprecated */
171169
get eslintConfig() {
172170
svDeprecated(
173-
'`workspace.file.eslintConfig` is deprecated, use the string `"eslint.config.js"` directly'
171+
'`workspace.file.eslintConfig` is deprecated, use the string `eslint.config.js` isntead.'
174172
);
175173
return 'eslint.config.js' as const;
176174
},
177175
/** @deprecated */
178176
get vscodeSettings() {
179177
svDeprecated(
180-
'`workspace.file.vscodeSettings` is deprecated, use the string `".vscode/settings.json"` directly'
178+
'`workspace.file.vscodeSettings` is deprecated, use the string `.vscode/settings.json` isntead.'
181179
);
182180
return '.vscode/settings.json' as const;
183181
},
184182
/** @deprecated */
185183
get vscodeExtensions() {
186184
svDeprecated(
187-
'`workspace.file.vscodeExtensions` is deprecated, use the string `".vscode/extensions.json"` directly'
185+
'`workspace.file.vscodeExtensions` is deprecated, use the string `.vscode/extensions.json` isntead.'
188186
);
189187
return '.vscode/extensions.json' as const;
190188
},
@@ -217,7 +215,7 @@ function findWorkspaceRoot(cwd: string): string {
217215
const { root } = path.parse(cwd);
218216
let directory = cwd;
219217
while (directory && directory !== root) {
220-
if (fs.existsSync(path.join(directory, commonFilePaths.packageJson))) {
218+
if (fs.existsSync(path.join(directory, filePaths.packageJson))) {
221219
// in pnpm it can be a file
222220
if (fs.existsSync(path.join(directory, 'pnpm-workspace.yaml'))) {
223221
return directory;

packages/sv/src/create/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { sanitizeName } from '@sveltejs/sv-utils';
22
import fs from 'node:fs';
33
import path from 'node:path';
4-
import { commonFilePaths } from '../core/common.ts';
4+
import { filePaths } from '../core/common.ts';
55
import { mkdirp, copy, dist, getSharedFiles, replace, kv } from './utils.ts';
66

77
export type TemplateType = (typeof templateTypes)[number];
@@ -81,7 +81,7 @@ function write_template_files(template: string, types: LanguageType, name: strin
8181
function write_common_files(cwd: string, options: Omit<Options, 'cwd'>, name: string) {
8282
const files = getSharedFiles();
8383

84-
const pkg_file = path.join(cwd, commonFilePaths.packageJson);
84+
const pkg_file = path.join(cwd, filePaths.packageJson);
8585
const pkg = /** @type {any} */ JSON.parse(fs.readFileSync(pkg_file, 'utf-8'));
8686

8787
sort_files(files).forEach((file) => {
@@ -90,7 +90,7 @@ function write_common_files(cwd: string, options: Omit<Options, 'cwd'>, name: st
9090

9191
if (exclude || !include) return;
9292

93-
if (file.name === commonFilePaths.packageJson) {
93+
if (file.name === filePaths.packageJson) {
9494
const new_pkg = JSON.parse(file.contents);
9595
merge(pkg, new_pkg);
9696
} else {

packages/sv/src/create/playground.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@sveltejs/sv-utils';
1010
import fs from 'node:fs';
1111
import path from 'node:path';
12-
import { commonFilePaths } from '../core/common.ts';
12+
import { filePaths } from '../core/common.ts';
1313
import { getSharedFiles } from './utils.ts';
1414

1515
export function validatePlaygroundUrl(link: string): boolean {
@@ -241,7 +241,7 @@ export function setupPlaygroundProject(
241241
fs.writeFileSync(filePath, newContent, 'utf-8');
242242

243243
// add packages as dependencies to package.json if requested
244-
const pkgPath = path.join(cwd, commonFilePaths.packageJson);
244+
const pkgPath = path.join(cwd, filePaths.packageJson);
245245
const pkgSource = fs.readFileSync(pkgPath, 'utf-8');
246246
const pkgJson = parse.json(pkgSource);
247247
let updatePackageJson = false;
@@ -255,7 +255,7 @@ export function setupPlaygroundProject(
255255

256256
let experimentalAsyncNeeded = true;
257257
const addExperimentalAsync = () => {
258-
const svelteConfigPath = path.join(cwd, commonFilePaths.svelteConfig);
258+
const svelteConfigPath = path.join(cwd, filePaths.svelteConfig);
259259
const svelteConfig = fs.readFileSync(svelteConfigPath, 'utf-8');
260260
const { ast, generateCode } = parse.script(svelteConfig);
261261
const { value: config } = js.exports.createDefault(ast, { fallback: js.object.create({}) });

packages/sv/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { create as _create, type Options as CreateOptions } from './create/index
33

44
export type { TemplateType, LanguageType } from './create/index.ts';
55

6-
/** @deprecated use `create({ cwd, ...options })` instead */
6+
/** @deprecated use `create({ cwd, ...options })` instead. */
77
export function create(cwd: string, options: Omit<CreateOptions, 'cwd'>): void;
88
export function create(options: CreateOptions): void;
99
export function create(

0 commit comments

Comments
 (0)