egoist / tsup

The simplest and fastest way to bundle your TypeScript libraries.
https://tsup.egoist.dev
MIT License
9.18k stars 220 forks source link

Option to specify `outExtension` for generated dts files? #939

Open errmayank opened 1 year ago

errmayank commented 1 year ago

Like we can modify output extension of JavaScript files is there also a way to do the same for type definition files?

I tried returning this because dts was showing up in the autocomplete return options but it doesn't work.

format: ['cjs', 'esm'],
outExtension({ format }) {
  switch (format) {
    case 'cjs': {
      return { js: '.cjs', dts: '.d.cts' };
    }
    case 'esm': {
      return { js: '.mjs', dts: '.d.mts' };
    }
    default: {
      return { js: '.js', dts: '.d.ts' };
    }
  }
}

Output type definition files generated after building have extensions .d.ts and .d.cts which is the default since my package is of type module. Is there a way to do this?

Upvote & Fund

Fund with Polar

rodrigoehlers commented 1 year ago

Facing the exact same problem.

egorderg commented 1 year ago

It looks like 'outExtension' is overridden to 'undefined' when it's passed to rollup. In the rollup dts handling is even a check if there is a custom 'outExtension'.

Lonli-Lokli commented 1 month ago

is there any workaround? I would like to use 'file.d.mts' for esm typings.

There is no merged PR but seems like nobody want to merge it

Lonli-Lokli commented 1 month ago

@zvictor Seems like dts factory has been disabled explicitly? https://github.com/egoist/tsup/pull/668

Is there any way to specify it, eg use https://github.com/vkiryukhin/jsonfn?

Or merge https://github.com/egoist/tsup/pull/1053/files ?