Skip to content

Commit 62afd80

Browse files
dominikgRich-Harrisbluwy
authored
refactor(types): use dts-buddy to generate types with map (#751)
* refactor(types): use dts-buddy to generate types with map, cleanup type definitions and tsconfig * chore: update generated types * fix: use .d.ts for type imports * fix: ignore .changesets/pre.json to prevent format check fails on main after release merge * fix: move types inside import condition to avoid masquerading as cjs warning * fix: types * bump dts-buddy * fix: regenerate types * fix: use correct type Options for plugin function arg * fix(types): reexport index.js from public.d.ts to ensure types and functions are properly exported through module declaration generated by dts-buddy; move dynamicCompileOptions to PluginOptions, rename SvelteOptions to SvelteConfig * fix: update lockfile * Update .changeset/metal-olives-wait.md Co-authored-by: Bjorn Lu <[email protected]> * fix: update types --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Bjorn Lu <[email protected]>
1 parent efd571f commit 62afd80

33 files changed

+475
-151
lines changed

.changeset/gorgeous-hats-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
fix(types): use correct type Options for svelte function arg

.changeset/many-cows-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': major
3+
---
4+
5+
breaking: remove package.json export

.changeset/metal-olives-wait.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte-inspector': major
3+
'@sveltejs/vite-plugin-svelte': major
4+
---
5+
6+
breaking(types): emit types with dts-buddy to include type map

.changeset/small-pears-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': major
3+
---
4+
5+
breaking(types): rename SvelteOptions to SvelteConfig

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ jobs:
6666
- name: publint
6767
if: (${{ success() }} || ${{ failure() }})
6868
run: pnpm check:publint
69+
- name: generated types are up to date
70+
if: (${{ success() }} || ${{ failure() }})
71+
run: pnpm generate:types && [ "`git status --porcelain=v1`" == "" ]
6972

7073
test:
7174
timeout-minutes: 10

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ jobs:
4343
cache-dependency-path: '**/pnpm-lock.yaml'
4444
- name: install
4545
run: pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
46-
46+
- name: generated types are up to date
47+
run: pnpm generate:types && [ "`git status --porcelain=v1`" == "" ]
48+
- name: publint
49+
run: pnpm check:publint
4750
- name: Creating .npmrc
4851
run: |
4952
cat << EOF > "$HOME/.npmrc"

.prettierrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ export default {
1616
},
1717
{
1818
files: [
19-
'**/vite.config.js.timestamp-*.mjs',
2019
'**/CHANGELOG.md',
2120
'.github/renovate.json5',
21+
'**/types/index.d.ts',
22+
'**/types/index.d.ts.map',
23+
'**/pnpm-lock.yaml',
24+
'.changeset/pre.json',
25+
'**/vite.config.js.timestamp-*.mjs',
2226
'packages/e2e-tests/dynamic-compile-options/src/components/A.svelte'
2327
],
2428
options: {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"fixup": "run-s lint format",
1919
"release": "pnpm changeset publish",
2020
"prepare": "husky install",
21-
"playwright": "playwright-core"
21+
"playwright": "playwright-core",
22+
"generate:types": "pnpm --filter \"./packages/*\" --parallel generate:types"
2223
},
2324
"devDependencies": {
2425
"@changesets/cli": "^2.26.2",
@@ -28,6 +29,7 @@
2829
"@typescript-eslint/eslint-plugin": "^6.8.0",
2930
"@typescript-eslint/parser": "^6.8.0",
3031
"cross-env": "^7.0.3",
32+
"dts-buddy": "^0.3.0",
3133
"eslint": "^8.51.0",
3234
"eslint-config-prettier": "^9.0.0",
3335
"eslint-plugin-html": "^7.1.0",

packages/vite-plugin-svelte-inspector/package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
"license": "MIT",
55
"author": "dominikg",
66
"files": [
7-
"src"
7+
"src",
8+
"types"
89
],
910
"type": "module",
10-
"types": "src/index.d.ts",
11+
"types": "types/index.d.ts",
1112
"exports": {
1213
".": {
13-
"types": "./src/index.d.ts",
14-
"import": "./src/index.js"
14+
"import": {
15+
"types": "./types/index.d.ts",
16+
"default": "./src/index.js"
17+
}
1518
}
1619
},
1720
"scripts": {
1821
"check:publint": "publint --strict",
19-
"check:types": "tsc --noEmit"
22+
"check:types": "tsc --noEmit",
23+
"generate:types": "dts-buddy -m \"@sveltejs/vite-plugin-svelte-inspector:src/public.d.ts\""
2024
},
2125
"engines": {
2226
"node": "^18.0.0 || >=20"

packages/vite-plugin-svelte-inspector/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ function getInspectorPath() {
1414
);
1515
}
1616

17-
/** @type {import('.').svelteInspector} */
17+
/**
18+
* @param {Partial<import('./public.d.ts').Options>} [options]
19+
* @returns {import('vite').Plugin}
20+
*/
1821
export function svelteInspector(options) {
1922
const inspectorPath = getInspectorPath();
2023
debug(`svelte inspector path: ${inspectorPath}`);
2124

2225
/** @type {import('vite').ResolvedConfig} */
2326
let viteConfig;
24-
/** @type {import('.').Options} */
27+
/** @type {import('./public.d.ts').Options} */
2528
let inspectorOptions;
2629
let disabled = false;
2730

0 commit comments

Comments
 (0)