Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate type declarations with dts-buddy #8702

Merged
merged 16 commits into from
Jun 8, 2023
5 changes: 5 additions & 0 deletions .changeset/green-sheep-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

Generate type declarations with dts-buddy
9 changes: 0 additions & 9 deletions packages/svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
*.map
/src/compiler/compile/internal_exports.js
/compiler.d.ts
/compiler.cjs
/index.d.ts
/action.d.ts
/internal.d.ts
/store.d.ts
/easing.d.ts
/motion.d.ts
/transition.d.ts
/animate.d.ts
/scratch/
/test/*/samples/_
/test/runtime/shards
Expand Down
162 changes: 0 additions & 162 deletions packages/svelte/generate-types.js

This file was deleted.

25 changes: 13 additions & 12 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,42 @@
"exports": {
"./package.json": "./package.json",
".": {
"types": "./types/runtime/index.d.ts",
"types": "./types/index.d.ts",
"browser": {
"import": "./src/runtime/index.js"
},
"import": "./src/runtime/ssr.js"
},
"./compiler": {
"types": "./types/compiler/index.d.ts",
"types": "./types/index.d.ts",
"import": "./src/compiler/index.js",
"require": "./compiler.cjs"
},
"./action": {
"types": "./types/runtime/action/index.d.ts"
"types": "./types/index.d.ts"
},
"./animate": {
"types": "./types/runtime/animate/index.d.ts",
"types": "./types/index.d.ts",
"import": "./src/runtime/animate/index.js"
},
"./easing": {
"types": "./types/runtime/easing/index.d.ts",
"types": "./types/index.d.ts",
"import": "./src/runtime/easing/index.js"
},
"./internal": {
"types": "./types/runtime/internal/index.d.ts",
"types": "./types/index.d.ts",
"import": "./src/runtime/internal/index.js"
},
"./motion": {
"types": "./types/runtime/motion/index.d.ts",
"types": "./types/index.d.ts",
"import": "./src/runtime/motion/index.js"
},
"./store": {
"types": "./types/runtime/store/index.d.ts",
"types": "./types/index.d.ts",
"import": "./src/runtime/store/index.js"
},
"./transition": {
"types": "./types/runtime/transition/index.d.ts",
"types": "./types/index.d.ts",
"import": "./src/runtime/transition/index.js"
},
"./elements": {
Expand All @@ -69,18 +69,18 @@
"engines": {
"node": ">=16"
},
"types": "types/runtime/index.d.ts",
"types": "types/index.d.ts",
"scripts": {
"format": "prettier . --cache --plugin-search-dir=. --write",
"check": "prettier . --cache --plugin-search-dir=. --check",
"test": "vitest run && echo \"manually check that there are no type errors in test/types by opening the files in there\"",
"build": "rollup -c && pnpm tsd",
"build": "rollup -c && pnpm types",
"prepare": "pnpm build",
"generate:version": "node ./scripts/generate-version.js",
"dev": "rollup -cw",
"posttest": "agadoo src/internal/index.js",
"prepublishOnly": "pnpm lint && pnpm build && pnpm test",
"tsd": "node ./generate-types.js",
"types": "node ./scripts/generate-dts.js",
"lint": "eslint \"{src,test}/**/*.{ts,js}\" --cache"
},
"repository": {
Expand Down Expand Up @@ -126,6 +126,7 @@
"@types/node": "^14.14.31",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"agadoo": "^3.0.0",
"dts-buddy": "^0.1.2",
"esbuild": "^0.17.19",
"happy-dom": "^9.18.3",
"jsdom": "^21.1.1",
Expand Down
17 changes: 0 additions & 17 deletions packages/svelte/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@ fs.writeFileSync(
`export default new Set(${JSON.stringify(Object.keys(internal))});`
);

// Generate d.ts files for runtime entrypoints so that TS can find it also without `"moduleResolution": "bundler"`
fs.readdirSync('src/runtime', { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.forEach((dirent) =>
fs.writeFileSync(
`${dirent.name}.d.ts`,
`export * from './types/runtime/${dirent.name}/index.js';`
)
);

fs.writeFileSync('./index.d.ts', `export * from './types/runtime/index.js';`);

fs.writeFileSync(
'./compiler.d.ts',
`export { compile, parse, preprocess, walk, VERSION } from './types/compiler/index.js';`
);

/**
* @type {import("rollup").RollupOptions[]}
*/
Expand Down
16 changes: 16 additions & 0 deletions packages/svelte/scripts/generate-dts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createBundle } from 'dts-buddy';

await createBundle({
output: 'types/index.d.ts',
modules: {
svelte: 'src/runtime/public.d.ts',
'svelte/compiler': 'src/compiler/public.d.ts',
'svelte/types/compiler/preprocess': 'src/compiler/preprocess/public.d.ts',
'svelte/action': 'src/runtime/action/public.d.ts',
'svelte/animate': 'src/runtime/animate/public.d.ts',
'svelte/easing': 'src/runtime/easing/index.js',
'svelte/motion': 'src/runtime/motion/public.d.ts',
'svelte/store': 'src/runtime/store/public.d.ts',
'svelte/transition': 'src/runtime/transition/public.d.ts'
}
});
1 change: 1 addition & 0 deletions packages/svelte/src/compiler/public.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { CompileOptions, EnableSourcemap, CssHashGetter } from './interfaces';
export * from './preprocess/public.js';
export * from './index.js';
1 change: 0 additions & 1 deletion packages/svelte/src/runtime/action/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/svelte/src/runtime/animate/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export interface FlipParams {
duration?: number | ((len: number) => number);
easing?: (t: number) => number;
}

export * from './index.js';
2 changes: 2 additions & 0 deletions packages/svelte/src/runtime/internal/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ export interface EventDispatcher<EventMap extends Record<string, any>> {
: [type: Type, parameter: EventMap[Type], options?: DispatchOptions]
): boolean;
}

export * from './index.js';
2 changes: 2 additions & 0 deletions packages/svelte/src/runtime/motion/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export interface Tweened<T> extends Readable<T> {
set(value: T, opts?: TweenedOptions<T>): Promise<void>;
update(updater: Updater<T>, opts?: TweenedOptions<T>): Promise<void>;
}

export * from './index.js';
2 changes: 2 additions & 0 deletions packages/svelte/src/runtime/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export type {
ComponentProps,
ComponentEvents
} from './internal/public.js';

export * from './index.js';
2 changes: 2 additions & 0 deletions packages/svelte/src/runtime/store/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ export interface Writable<T> extends Readable<T> {
*/
update(this: void, updater: Updater<T>): void;
}

export * from './index.js';
2 changes: 2 additions & 0 deletions packages/svelte/src/runtime/transition/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ export interface CrossfadeParams {
duration?: number | ((len: number) => number);
easing?: EasingFunction;
}

export * from './index.js';
Loading