Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sxzz/tsdown
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.6.6
Choose a base ref
...
head repository: sxzz/tsdown
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.6.7
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Mar 11, 2025

  1. feat: support resolving specific id for bundle dts

    sxzz committed Mar 11, 2025

    Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    16b9be3 View commit details
  2. chore: release v0.6.7

    sxzz committed Mar 11, 2025
    Copy the full SHA
    deb0729 View commit details
Showing with 35 additions and 11 deletions.
  1. +1 −1 jsr.json
  2. +1 −1 package.json
  3. +22 −6 src/features/dts.ts
  4. +2 −1 src/options.ts
  5. +2 −0 tests/__snapshots__/resolve-dependency-for-dts.snap.md
  6. +7 −2 tests/index.test.ts
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sxzz/tsdown",
"version": "0.6.6",
"version": "0.6.7",
"exports": "./src/index.ts",
"publish": {
"include": [
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsdown",
"version": "0.6.6",
"version": "0.6.7",
"packageManager": "pnpm@10.6.2",
"description": "An even faster bundler powered by Rolldown.",
"type": "module",
28 changes: 22 additions & 6 deletions src/features/dts.ts
Original file line number Diff line number Diff line change
@@ -30,8 +30,9 @@ export async function bundleDts(
format: NormalizedFormat,
pkg?: PackageJson,
): Promise<void> {
typeAsserts<IsolatedDeclOptions>(options.dts)
typeAsserts<BundleDtsOptions>(options.bundleDts)
const { dts, bundleDts } = options
typeAsserts<IsolatedDeclOptions>(dts)
typeAsserts<BundleDtsOptions>(bundleDts)

const ext = jsExtension.replace('j', 't')
const dtsOutDir = path.resolve(options.outDir, getTempDtsDir(format))
@@ -41,6 +42,7 @@ export async function bundleDts(
path.resolve(dtsOutDir, `${key}.d.${ext}`),
]),
)

const build = await rollup({
input: dtsEntry,
external: options.external,
@@ -51,10 +53,13 @@ export async function bundleDts(
},
plugins: [
ExternalPlugin(options, pkg) as any,
options.bundleDts.resolve && ResolveDtsPlugin(),
bundleDts.resolve &&
ResolveDtsPlugin(
bundleDts.resolve !== true ? bundleDts.resolve : undefined,
),
DtsPlugin({
compilerOptions: {
...options.bundleDts.compilerOptions,
...bundleDts.compilerOptions,
declaration: true,
noEmit: false,
emitDeclarationOnly: true,
@@ -70,7 +75,7 @@ export async function bundleDts(
})

let outDir = options.outDir
const extraOutdir = options.dts.extraOutdir
const extraOutdir = dts.extraOutdir
if (extraOutdir) {
outDir = path.resolve(outDir, extraOutdir)
}
@@ -84,7 +89,7 @@ export async function bundleDts(
}

let resolver: ResolverFactory | undefined
export function ResolveDtsPlugin(): Plugin {
export function ResolveDtsPlugin(resolveOnly?: Array<string | RegExp>): Plugin {
return {
name: 'resolve-dts',
buildStart() {
@@ -99,6 +104,17 @@ export function ResolveDtsPlugin(): Plugin {
if (id[0] === '.' || path.isAbsolute(id)) return
if (/\0/.test(id)) return

if (resolveOnly) {
const shouldResolve = resolveOnly.some((value) => {
if (typeof value === 'string') return value === id
return value.test(id)
})
if (!shouldResolve) {
debug('skipped by matching resolveOnly: %s', id)
return
}
}

const directory = importer ? path.dirname(importer) : process.cwd()
debug('Resolving:', id, 'from:', directory)
const { path: resolved } = await resolver!.async(directory, id)
3 changes: 2 additions & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
@@ -29,7 +29,8 @@ import type { ConfigEnv, UserConfigExport as ViteUserConfigExport } from 'vite'
export type Sourcemap = boolean | 'inline' | 'hidden'

export interface BundleDtsOptions {
resolve?: boolean
/** Resolve external types used in dts files from node_modules */
resolve?: boolean | (string | RegExp)[]
compilerOptions?: CompilerOptions
}

2 changes: 2 additions & 0 deletions tests/__snapshots__/resolve-dependency-for-dts.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## index.d.mts

```mts
export * from 'consola';

interface GlobOptions {
absolute?: boolean;
cwd?: string;
9 changes: 7 additions & 2 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -176,7 +176,12 @@ test('fromVite', async (context) => {

test('resolve dependency for dts', async (context) => {
const files = {
'index.ts': `export type { GlobOptions } from 'tinyglobby'`,
'index.ts': `export type { GlobOptions } from 'tinyglobby'
export type * from 'consola'`,
}
await testBuild(context, files, { dts: true, bundleDts: { resolve: true } })
const { snapshot } = await testBuild(context, files, {
dts: true,
bundleDts: { resolve: ['tinyglobby'] },
})
expect(snapshot).contain(`export * from 'consola'`)
})