Skip to content

Commit 1046dab

Browse files
Rich-HarrisRich Harrisgtm-nayan
authored
Generate type declarations with dts-buddy (#8702)
* use dts-buddy * remove debug output * remove existing type generation script * fix package.json * update gitignore * bump dts-buddy * remove unused action entry point * add svelte/compiler and svelte/types/compiler/preprocess modules * bump dts-buddy * annoying * changeset * bump dts-buddy * get rid of .d.ts files * another one * Update packages/svelte/package.json Co-authored-by: gtmnayan <[email protected]> --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: gtmnayan <[email protected]>
1 parent 15bdadb commit 1046dab

File tree

15 files changed

+84
-207
lines changed

15 files changed

+84
-207
lines changed

.changeset/green-sheep-learn.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
Generate type declarations with dts-buddy

packages/svelte/.gitignore

-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
*.map
22
/src/compiler/compile/internal_exports.js
3-
/compiler.d.ts
43
/compiler.cjs
5-
/index.d.ts
6-
/action.d.ts
7-
/internal.d.ts
8-
/store.d.ts
9-
/easing.d.ts
10-
/motion.d.ts
11-
/transition.d.ts
12-
/animate.d.ts
134
/scratch/
145
/test/*/samples/_
156
/test/runtime/shards

packages/svelte/generate-types.js

-162
This file was deleted.

packages/svelte/package.json

+13-12
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,42 @@
2424
"exports": {
2525
"./package.json": "./package.json",
2626
".": {
27-
"types": "./types/runtime/index.d.ts",
27+
"types": "./types/index.d.ts",
2828
"browser": {
2929
"import": "./src/runtime/index.js"
3030
},
3131
"import": "./src/runtime/ssr.js"
3232
},
3333
"./compiler": {
34-
"types": "./types/compiler/index.d.ts",
34+
"types": "./types/index.d.ts",
3535
"import": "./src/compiler/index.js",
3636
"require": "./compiler.cjs"
3737
},
3838
"./action": {
39-
"types": "./types/runtime/action/index.d.ts"
39+
"types": "./types/index.d.ts"
4040
},
4141
"./animate": {
42-
"types": "./types/runtime/animate/index.d.ts",
42+
"types": "./types/index.d.ts",
4343
"import": "./src/runtime/animate/index.js"
4444
},
4545
"./easing": {
46-
"types": "./types/runtime/easing/index.d.ts",
46+
"types": "./types/index.d.ts",
4747
"import": "./src/runtime/easing/index.js"
4848
},
4949
"./internal": {
50-
"types": "./types/runtime/internal/index.d.ts",
50+
"types": "./types/index.d.ts",
5151
"import": "./src/runtime/internal/index.js"
5252
},
5353
"./motion": {
54-
"types": "./types/runtime/motion/index.d.ts",
54+
"types": "./types/index.d.ts",
5555
"import": "./src/runtime/motion/index.js"
5656
},
5757
"./store": {
58-
"types": "./types/runtime/store/index.d.ts",
58+
"types": "./types/index.d.ts",
5959
"import": "./src/runtime/store/index.js"
6060
},
6161
"./transition": {
62-
"types": "./types/runtime/transition/index.d.ts",
62+
"types": "./types/index.d.ts",
6363
"import": "./src/runtime/transition/index.js"
6464
},
6565
"./elements": {
@@ -69,18 +69,18 @@
6969
"engines": {
7070
"node": ">=16"
7171
},
72-
"types": "types/runtime/index.d.ts",
72+
"types": "types/index.d.ts",
7373
"scripts": {
7474
"format": "prettier . --cache --plugin-search-dir=. --write",
7575
"check": "prettier . --cache --plugin-search-dir=. --check",
7676
"test": "vitest run && echo \"manually check that there are no type errors in test/types by opening the files in there\"",
77-
"build": "rollup -c && pnpm tsd",
77+
"build": "rollup -c && pnpm types",
7878
"prepare": "pnpm build",
7979
"generate:version": "node ./scripts/generate-version.js",
8080
"dev": "rollup -cw",
8181
"posttest": "agadoo src/internal/index.js",
8282
"prepublishOnly": "pnpm lint && pnpm build && pnpm test",
83-
"tsd": "node ./generate-types.js",
83+
"types": "node ./scripts/generate-dts.js",
8484
"lint": "eslint \"{src,test}/**/*.{ts,js}\" --cache"
8585
},
8686
"repository": {
@@ -126,6 +126,7 @@
126126
"@types/node": "^14.14.31",
127127
"@typescript-eslint/eslint-plugin": "^5.58.0",
128128
"agadoo": "^3.0.0",
129+
"dts-buddy": "^0.1.2",
129130
"esbuild": "^0.17.19",
130131
"happy-dom": "^9.18.3",
131132
"jsdom": "^21.1.1",

packages/svelte/rollup.config.js

-17
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@ fs.writeFileSync(
1717
`export default new Set(${JSON.stringify(Object.keys(internal))});`
1818
);
1919

20-
// Generate d.ts files for runtime entrypoints so that TS can find it also without `"moduleResolution": "bundler"`
21-
fs.readdirSync('src/runtime', { withFileTypes: true })
22-
.filter((dirent) => dirent.isDirectory())
23-
.forEach((dirent) =>
24-
fs.writeFileSync(
25-
`${dirent.name}.d.ts`,
26-
`export * from './types/runtime/${dirent.name}/index.js';`
27-
)
28-
);
29-
30-
fs.writeFileSync('./index.d.ts', `export * from './types/runtime/index.js';`);
31-
32-
fs.writeFileSync(
33-
'./compiler.d.ts',
34-
`export { compile, parse, preprocess, walk, VERSION } from './types/compiler/index.js';`
35-
);
36-
3720
/**
3821
* @type {import("rollup").RollupOptions[]}
3922
*/
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createBundle } from 'dts-buddy';
2+
3+
await createBundle({
4+
output: 'types/index.d.ts',
5+
modules: {
6+
svelte: 'src/runtime/public.d.ts',
7+
'svelte/compiler': 'src/compiler/public.d.ts',
8+
'svelte/types/compiler/preprocess': 'src/compiler/preprocess/public.d.ts',
9+
'svelte/action': 'src/runtime/action/public.d.ts',
10+
'svelte/animate': 'src/runtime/animate/public.d.ts',
11+
'svelte/easing': 'src/runtime/easing/index.js',
12+
'svelte/motion': 'src/runtime/motion/public.d.ts',
13+
'svelte/store': 'src/runtime/store/public.d.ts',
14+
'svelte/transition': 'src/runtime/transition/public.d.ts'
15+
}
16+
});
+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { CompileOptions, EnableSourcemap, CssHashGetter } from './interfaces';
22
export * from './preprocess/public.js';
3+
export * from './index.js';

packages/svelte/src/runtime/action/index.js

-1
This file was deleted.

packages/svelte/src/runtime/animate/public.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ export interface FlipParams {
1212
duration?: number | ((len: number) => number);
1313
easing?: (t: number) => number;
1414
}
15+
16+
export * from './index.js';

packages/svelte/src/runtime/internal/public.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,5 @@ export interface EventDispatcher<EventMap extends Record<string, any>> {
9191
: [type: Type, parameter: EventMap[Type], options?: DispatchOptions]
9292
): boolean;
9393
}
94+
95+
export * from './index.js';

packages/svelte/src/runtime/motion/public.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export interface Tweened<T> extends Readable<T> {
1313
set(value: T, opts?: TweenedOptions<T>): Promise<void>;
1414
update(updater: Updater<T>, opts?: TweenedOptions<T>): Promise<void>;
1515
}
16+
17+
export * from './index.js';

packages/svelte/src/runtime/public.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ export type {
55
ComponentProps,
66
ComponentEvents
77
} from './internal/public.js';
8+
9+
export * from './index.js';

packages/svelte/src/runtime/store/public.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ export interface Writable<T> extends Readable<T> {
4747
*/
4848
update(this: void, updater: Updater<T>): void;
4949
}
50+
51+
export * from './index.js';

packages/svelte/src/runtime/transition/public.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,5 @@ export interface CrossfadeParams {
5858
duration?: number | ((len: number) => number);
5959
easing?: EasingFunction;
6060
}
61+
62+
export * from './index.js';

0 commit comments

Comments
 (0)