Skip to content

Commit 2858dbe

Browse files
authored
feat!: merge emitDtsOnly and dtsInput into dtsOnly (#340)
1 parent 84ddfb2 commit 2858dbe

25 files changed

Lines changed: 620 additions & 263 deletions

‎README.md‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ export default defineConfig({
4444

4545
See [rolldown.config.ts](./rolldown.config.ts) for the project's own setup.
4646

47+
### Declaration-only builds
48+
49+
With `dtsOnly: true`, each entry resolves to its declaration and the build emits
50+
no JavaScript. Entries may be source files, existing `.d.ts` files, or both:
51+
52+
```ts
53+
export default defineConfig({
54+
input: ['src/index.ts', 'types/globals.d.ts'],
55+
plugins: [dts({ dtsOnly: true })],
56+
output: { dir: 'dist' },
57+
})
58+
```
59+
4760
## Generators
4861

4962
| Generator | Use it for | Requirement |
@@ -89,8 +102,7 @@ dts({
89102
| `tsc` | Options for the built-in `tsc` generator. | `{}` |
90103
| `entry` | Glob or globs selecting files to emit. Supports `!` negation and paths relative to `cwd`. | Rolldown entries |
91104
| `cwd` | Base directory for config discovery, globs, and relative paths. | `process.cwd()` |
92-
| `dtsInput` | Treat entry files as existing declarations. | `false` |
93-
| `emitDtsOnly` | Remove non-declaration chunks from the output. | `false` |
105+
| `dtsOnly` | Build declarations only. See [Declaration-only builds](#declaration-only-builds). | `false` |
94106
| `tsconfig` | Config path; `true` discovers one and `false` disables loading. | Nearest `tsconfig.json` |
95107
| `tsconfigRaw` | Raw config values merged over the loaded config. | `{}` |
96108
| `compilerOptions` | Compiler options merged over the loaded config. | `{}` |
@@ -111,6 +123,9 @@ dts({
111123
})
112124
```
113125

126+
`entry` cannot be combined with `dtsOnly`. In a declaration-only build, list the
127+
files in Rolldown `input` instead.
128+
114129
`cjsDefault` only changes the emitted export syntax. It does not enable
115130
CommonJS-style declaration input.
116131

@@ -260,7 +275,7 @@ export default {
260275

261276
Declaration bundling requires an ESM Rolldown output. The `cjs` output format is
262277
not supported. For CommonJS packages, build the JavaScript output separately
263-
and use `emitDtsOnly` for a second declaration-only build.
278+
and use `dtsOnly` for a second declaration-only build.
264279

265280
The following declaration input cannot be bundled:
266281

‎__snapshots__/tsnapi/index.snapshot.d.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ export interface Options extends DeprecatedOptions {
3030
generator?: "tsc" | "oxc" | "tsgo" | "tsrs" | Generator;
3131
entry?: string | string[];
3232
cwd?: string;
33-
dtsInput?: boolean;
34-
emitDtsOnly?: boolean;
33+
dtsOnly?: boolean;
3534
tsconfig?: string | boolean;
3635
tsconfigRaw?: Omit<TsconfigJson, "compilerOptions">;
3736
compilerOptions?: TsconfigJson.CompilerOptions;
@@ -59,13 +58,15 @@ export interface TscOptions {
5958

6059
// #region Functions
6160
export declare function createFakeJsPlugin({ sourcemap, cjsDefault, sideEffects }: Pick<OptionsResolved, "sourcemap" | "cjsDefault" | "sideEffects">): Plugin;
62-
export declare function createGeneratePlugin(_: Pick<OptionsResolved, "generator" | "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "oxc" | "emitDtsOnly" | "languageContext" | "tsc" | "tsgo" | "tsrs" | "emitJs" | "sourcemap">): Plugin;
61+
export declare function createGeneratePlugin(_: Pick<OptionsResolved, "generator" | "entry" | "cwd" | "tsconfig" | "tsconfigRaw" | "oxc" | "dtsOnly" | "languageContext" | "tsc" | "tsgo" | "tsrs" | "emitJs" | "sourcemap">): Plugin;
6362
export declare function dts(_?: Options): Plugin[];
64-
export declare function resolveOptions({ generator, entry, cwd, dtsInput, emitDtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, logger, customLanguages, tsc, emitJs, oxc, tsgo, tsrs, ...deprecated }: Options): OptionsResolved;
63+
export declare function resolveOptions({ generator, entry, cwd, dtsOnly, tsconfig, tsconfigRaw: overriddenTsconfigRaw, compilerOptions, sourcemap, resolver, cjsDefault, sideEffects, logger, customLanguages, tsc, emitJs, oxc, tsgo, tsrs, ...deprecated }: Options): OptionsResolved;
6564
// #endregion
6665

6766
// #region Referenced (internal)
6867
interface DeprecatedOptions {
68+
dtsInput?: boolean;
69+
emitDtsOnly?: boolean;
6970
build?: TscOptions["build"];
7071
incremental?: TscOptions["incremental"];
7172
parallel?: TscOptions["parallel"];

0 commit comments

Comments
 (0)