Skip to content

Commit 0fa6905

Browse files
committed
feat!: remove resolve option, respect rolldown config
closes #106
1 parent 03998d4 commit 0fa6905

File tree

5 files changed

+28
-63
lines changed

5 files changed

+28
-63
lines changed

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,6 @@ See: [TypeScript compilerOptions documentation](https://www.typescriptlang.org/t
8181

8282
If `true`, the plugin will generate declaration maps (`.d.ts.map`) for `.d.ts` files.
8383

84-
#### `resolve`
85-
86-
Controls whether type definitions from `node_modules` are bundled into your final `.d.ts` file or kept as external `import` statements.
87-
88-
By default, dependencies are external, resulting in `import { Type } from 'some-package'`. When bundled, this `import` is removed, and the type definitions from `some-package` are copied directly into your file.
89-
90-
- `true`: Bundles all dependencies.
91-
- `false`: (Default) Keeps all dependencies external.
92-
- `(string | RegExp)[]`: Bundles only dependencies matching the provided strings or regular expressions (e.g. `['pkg-a', /^@scope\//]`).
93-
9484
#### `resolver`
9585

9686
Specifies a resolver to resolve type definitions, especially for `node_modules`.

src/options.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ export interface GeneralOptions {
5858
*/
5959
sourcemap?: boolean
6060

61-
/**
62-
* Controls whether type definitions from `node_modules` are bundled into your final `.d.ts` file or kept as external `import` statements.
63-
*
64-
* By default, dependencies are external, resulting in `import { Type } from 'some-package'`. When bundled, this `import` is removed, and the type definitions from `some-package` are copied directly into your file.
65-
66-
* - `true`: Bundles all dependencies.
67-
* - `false`: (Default) Keeps all dependencies external.
68-
* - `(string | RegExp)[]`: Bundles only dependencies matching the provided strings or regular expressions (e.g. `['pkg-a', /^@scope\//]`).
69-
*/
70-
resolve?: boolean | (string | RegExp)[]
71-
7261
/**
7362
* Specifies a resolver to resolve type definitions, especially for `node_modules`.
7463
*
@@ -231,7 +220,6 @@ export function resolveOptions({
231220
tsconfigRaw: overriddenTsconfigRaw = {},
232221
compilerOptions = {},
233222
sourcemap,
234-
resolve = false,
235223
resolver = 'oxc',
236224
cjsDefault = false,
237225
sideEffects = false,
@@ -331,7 +319,6 @@ export function resolveOptions({
331319
tsconfig,
332320
tsconfigRaw,
333321
sourcemap,
334-
resolve,
335322
resolver,
336323
cjsDefault,
337324
sideEffects,

src/resolver.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
RE_CSS,
99
RE_DTS,
1010
RE_JSON,
11-
RE_NODE_MODULES,
1211
RE_TS,
1312
RE_VUE,
1413
} from './filename.ts'
@@ -25,16 +24,15 @@ export function createDtsResolvePlugin({
2524
cwd,
2625
tsconfig,
2726
tsconfigRaw,
28-
resolve,
2927
resolver,
3028
sideEffects,
3129
}: Pick<
3230
OptionsResolved,
33-
'cwd' | 'tsconfig' | 'tsconfigRaw' | 'resolve' | 'resolver' | 'sideEffects'
31+
'cwd' | 'tsconfig' | 'tsconfigRaw' | 'resolver' | 'sideEffects'
3432
>): Plugin {
3533
const baseDtsResolver = createResolver({
3634
tsconfig,
37-
resolveNodeModules: !!resolve,
35+
resolveNodeModules: true,
3836
ResolverFactory,
3937
})
4038
const moduleSideEffects = sideEffects ? true : null
@@ -95,19 +93,6 @@ export function createDtsResolvePlugin({
9593
return isFileImport ? null : external
9694
}
9795

98-
// Externalize non-bundled node_modules dependencies
99-
if (
100-
// request resolved to inside node_modules
101-
RE_NODE_MODULES.test(dtsResolution) &&
102-
// User doesn't want to bundle this module
103-
!shouldBundleNodeModule(id) &&
104-
// The importer is not in node_modules, or if it is, the module is marked as external by Rolldown
105-
!RE_NODE_MODULES.test(importer)
106-
) {
107-
debug('Externalizing node_modules dts import:', id)
108-
return external
109-
}
110-
11196
// The path is either a declaration file or a source file that needs redirection.
11297
if (RE_DTS.test(dtsResolution)) {
11398
debug('Resolving dts import to declaration file:', id)
@@ -132,13 +117,6 @@ export function createDtsResolvePlugin({
132117
},
133118
}
134119

135-
function shouldBundleNodeModule(id: string) {
136-
if (typeof resolve === 'boolean') return resolve
137-
return resolve.some((pattern) =>
138-
typeof pattern === 'string' ? id === pattern : pattern.test(id),
139-
)
140-
}
141-
142120
async function resolveDtsPath(
143121
id: string,
144122
importer: string,

tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ test('resolve dependencies', async () => {
2727
path.resolve(dirname, 'fixtures/resolve-dep.ts'),
2828
[
2929
dts({
30-
resolve: ['get-tsconfig'],
3130
oxc: true,
3231
emitDtsOnly: true,
3332
}),
3433
],
34+
{ external: ['rolldown'] },
3535
)
3636
expect(snapshot).contain('type TsConfigResult')
3737
expect(snapshot).not.contain('node_modules/rolldown')

tests/tsc.test.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,20 +215,25 @@ describe('tsc', () => {
215215

216216
test('vue-sfc w/ ts-compiler w/ vueCompilerOptions in tsconfig', async () => {
217217
const root = path.resolve(dirname, 'fixtures/vue-sfc-fallthrough')
218-
const { snapshot } = await rolldownBuild(path.resolve(root, 'main.ts'), [
219-
dts({
220-
tsconfig: path.resolve(root, 'tsconfig.json'),
221-
emitDtsOnly: true,
222-
vue: true,
223-
}),
224-
])
218+
const { snapshot } = await rolldownBuild(
219+
path.resolve(root, 'main.ts'),
220+
[
221+
dts({
222+
tsconfig: path.resolve(root, 'tsconfig.json'),
223+
emitDtsOnly: true,
224+
vue: true,
225+
}),
226+
],
227+
{ external: ['vue'] },
228+
)
225229
expect(snapshot).toMatchSnapshot()
226230
})
227231

228232
test('jsdoc', async () => {
229233
const { snapshot } = await rolldownBuild(
230234
path.resolve(dirname, 'fixtures/jsdoc.ts'),
231235
[dts({ oxc: false })],
236+
{ external: ['rolldown'] },
232237
)
233238
expect(snapshot).toMatchSnapshot()
234239
})
@@ -258,14 +263,18 @@ describe('tsc', () => {
258263

259264
test('vue-sfc w/ ts-macro w/ ts-compiler', async () => {
260265
const root = path.resolve(dirname, 'fixtures/vue-sfc-with-ts-macro')
261-
const { snapshot } = await rolldownBuild(path.resolve(root, 'main.ts'), [
262-
dts({
263-
emitDtsOnly: true,
264-
tsconfig: path.resolve(root, 'tsconfig.json'),
265-
vue: true,
266-
tsMacro: true,
267-
}),
268-
])
266+
const { snapshot } = await rolldownBuild(
267+
path.resolve(root, 'main.ts'),
268+
[
269+
dts({
270+
emitDtsOnly: true,
271+
tsconfig: path.resolve(root, 'tsconfig.json'),
272+
vue: true,
273+
tsMacro: true,
274+
}),
275+
],
276+
{ external: ['vue'] },
277+
)
269278
expect(snapshot).toMatchSnapshot()
270279
})
271280

@@ -280,6 +289,7 @@ describe('tsc', () => {
280289
emitDtsOnly: true,
281290
}),
282291
],
292+
{ external: [/^arktype/] },
283293
)
284294
expect(snapshot).toMatchSnapshot()
285295
})

0 commit comments

Comments
 (0)