Skip to content

Commit 9a424bc

Browse files
authored
feat!: make entry only filter Rolldown entries (#342)
1 parent f13b3ac commit 9a424bc

4 files changed

Lines changed: 36 additions & 22 deletions

File tree

‎README.md‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,27 @@ dts({
9696

9797
### General
9898

99-
| Option | Description | Default |
100-
| ----------------- | ----------------------------------------------------------------------------------------- | ----------------------- |
101-
| `generator` | Built-in generator name or a custom `Generator` implementation. | Inferred |
102-
| `tsc` | Options for the built-in `tsc` generator. | `{}` |
103-
| `entry` | Glob or globs selecting files to emit. Supports `!` negation and paths relative to `cwd`. | Rolldown entries |
104-
| `cwd` | Base directory for config discovery, globs, and relative paths. | `process.cwd()` |
105-
| `dtsOnly` | Build declarations only. See [Declaration-only builds](#declaration-only-builds). | `false` |
106-
| `tsconfig` | Config path; `true` discovers one and `false` disables loading. | Nearest `tsconfig.json` |
107-
| `tsconfigRaw` | Raw config values merged over the loaded config. | `{}` |
108-
| `compilerOptions` | Compiler options merged over the loaded config. | `{}` |
109-
| `sourcemap` | Emit `.d.ts.map` files. | `declarationMap` |
110-
| `resolver` | Resolve declaration imports with `oxc` or `tsc`. | `oxc` |
111-
| `cjsDefault` | Convert a single default export to `export =`. | `false` |
112-
| `sideEffects` | Mark declaration modules as having side effects. | `false` |
113-
| `logger` | Logger implementing `info`, `warn`, and `error`. | `console` |
99+
| Option | Description | Default |
100+
| ----------------- | -------------------------------------------------------------------------------------------------------------------- | ----------------------- |
101+
| `generator` | Built-in generator name or a custom `Generator` implementation. | Inferred |
102+
| `tsc` | Options for the built-in `tsc` generator. | `{}` |
103+
| `entry` | Glob or globs filtering which Rolldown entries emit declarations. Supports `!` negation and paths relative to `cwd`. | All Rolldown entries |
104+
| `cwd` | Base directory for config discovery, globs, and relative paths. | `process.cwd()` |
105+
| `dtsOnly` | Build declarations only. See [Declaration-only builds](#declaration-only-builds). | `false` |
106+
| `tsconfig` | Config path; `true` discovers one and `false` disables loading. | Nearest `tsconfig.json` |
107+
| `tsconfigRaw` | Raw config values merged over the loaded config. | `{}` |
108+
| `compilerOptions` | Compiler options merged over the loaded config. | `{}` |
109+
| `sourcemap` | Emit `.d.ts.map` files. | `declarationMap` |
110+
| `resolver` | Resolve declaration imports with `oxc` or `tsc`. | `oxc` |
111+
| `cjsDefault` | Convert a single default export to `export =`. | `false` |
112+
| `sideEffects` | Mark declaration modules as having side effects. | `false` |
113+
| `logger` | Logger implementing `info`, `warn`, and `error`. | `console` |
114114

115115
`tsc.*`, `oxc.*`, `tsgo.*`, and `tsrs.*` apply only to their respective
116116
generators.
117117

118-
`entry` may include files that are not Rolldown entry points:
118+
`entry` filters Rolldown entries. It never adds declarations for files that
119+
are not entries. For example, to skip declarations for icon entries:
119120

120121
```ts
121122
dts({

‎src/generate.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ export function createGeneratePlugin(
218218
const mod = this.getModuleInfo(id)
219219
const dtsId = filename_to_dts(id, languageContext)
220220
const isDtsOnlyEntry = dtsOnlyEntries.get(dtsId)?.id === id
221+
// `entry` only filters Rolldown entries; it never adds files.
221222
const isEntry =
222223
isDtsOnlyEntry ||
223-
(entryMatcher
224-
? entryMatcher(path.relative(cwd, id))
225-
: !!mod?.isEntry)
224+
(!!mod?.isEntry &&
225+
(!entryMatcher || entryMatcher(path.relative(cwd, id))))
226226
dtsMap.set(dtsId, { code, id, isEntry, jsFile })
227227
declarationGenerator.addFile?.(code, id)
228228
debug('register dts source: %s', id)

‎src/options.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ export interface Options extends DeprecatedOptions {
5757
generator?: 'tsc' | 'oxc' | 'tsgo' | 'tsrs' | Generator
5858

5959
/**
60-
* Glob pattern(s) that select source files for declaration generation.
60+
* Glob pattern(s) that filter which Rolldown entries emit declarations.
6161
*
62-
* Patterns are relative to {@link cwd} and may be negated with `!`. Matching
63-
* files are emitted even when they are not Rolldown entry points.
62+
* Patterns are relative to {@link cwd} and may be negated with `!`. Only
63+
* Rolldown entries are matched; other files never emit declarations.
6464
*
6565
* Cannot be combined with {@link dtsOnly}; set Rolldown's `input` instead.
6666
*

‎tests/index.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ test('entry option - negation glob', async () => {
159159
expect(fileNames).not.toContain('output2/index.d.ts')
160160
})
161161

162+
test('entry option - does not add non-entry files', async () => {
163+
const root = path.resolve(dirname, 'fixtures/alias')
164+
const { chunks } = await rolldownBuild(
165+
{ output1: 'input1.ts' },
166+
[dts({ entry: '**/*.ts', cwd: root })],
167+
{ cwd: root },
168+
)
169+
const fileNames = chunks.map((chunk) => chunk.fileName).toSorted()
170+
171+
// `input2.ts` and `shared.ts` match, but are only imported by the entry.
172+
expect(fileNames).toEqual(['output1.d.ts', 'output1.js'])
173+
})
174+
162175
test('isolated declaration error', async () => {
163176
const error = await rolldownBuild(
164177
path.resolve(dirname, 'fixtures/isolated-decl-error.ts'),

0 commit comments

Comments
 (0)