Skip to content

Commit eae1481

Browse files
committed
feat: dtsPath options
1 parent 03c4c4f commit eae1481

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

.changeset/fast-nights-sit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"elysia-remote-dts": patch
3+
---
4+
5+
add option to change path to get server types

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@ const app = new Elysia().use(dts('./src/index.ts')).listen(3000)
3636
export type App = typeof app;
3737
```
3838

39-
Types will then be available at `/server.d.ts`.
39+
Types will then be available at `/server.d.ts` by default, or at the path specified in the `dtsPath` option.
4040

4141
Due to limitations with [Triple-Slash Directives](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html), types cannot be directly consumed from a remote URL ([tracking issue](https://github.com/microsoft/TypeScript/issues/28985)). For frontend projects, you'll need to first download the type declaration file before using it with Eden:
4242

4343
```
4444
curl -o server.ts https://<remote-url>/server.d.ts
4545
```
4646

47+
If you've customized the path:
48+
49+
```
50+
curl -o server.ts https://<remote-url>/your-custom-path
51+
```
52+
4753
Then use it in your frontend code:
4854

4955
```ts
@@ -70,6 +76,7 @@ dts(entryPoint, options)
7076
| `compilerOptions` | `object` | `{}` | The `compilerOptions` for the TypeScript compiler. See [TypeScript compiler options](https://www.typescriptlang.org/docs/handbook/compiler-options.html). |
7177
| `resolve` | `boolean \| (string \| RegExp)[]` | `false` | Resolve external types used in `.d.ts` files from `node_modules`. Can be a boolean or an array of strings/RegExp patterns. |
7278
| `resolvePaths` | `boolean` | `false` | When `true`, the plugin will resolve `paths` in `tsconfig.json`. This option is enabled automatically when `paths` is set in `compilerOptions`. |
79+
| `dtsPath` | `string` | `"/server.d.ts"` | The path where the type definitions will be served. |
7380

7481
### Example with Options
7582

@@ -82,7 +89,8 @@ const app = new Elysia().use(
8289
tsconfig: './tsconfig.json',
8390
compilerOptions: {
8491
strict: true
85-
}
92+
},
93+
dtsPath: '/types.d.ts'
8694
})
8795
).listen(3000)
8896

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import type { Options } from './types'
44

55
export const dts = (filePath: string, options?: Options) => {
66
let dts = ''
7+
const dtsPath = options?.dtsPath || '/server.d.ts'
78

89
return new Elysia()
910
.onStart(async () => {
1011
dts = await generateDts(filePath, options)
1112
})
12-
.get('/server.d.ts', ({ set }) => {
13+
.get(dtsPath, ({ set }) => {
1314
// use same Content-Type as Deno
1415
// https://github.com/denoland/deno/blob/f42cb0816ef3be41213c0b2151b1d1c28495d4ce/cli/lsp/documents.rs#L1712
1516
set.headers['Content-Type'] = 'application/typescript'

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ export interface Options {
3939
* This option is enabled when `paths` is set in `compilerOptions`.
4040
*/
4141
resolvePaths?: boolean
42+
43+
/**
44+
* The path where the type definitions will be served.
45+
*
46+
* @default `/server.d.ts`
47+
*/
48+
dtsPath?: string
4249
}
4350

4451
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U

0 commit comments

Comments
 (0)