@@ -57,14 +57,38 @@ export interface ExportsOptions {
5757 */
5858 legacy ?: boolean
5959
60- customExports ?: (
61- exports : Record < string , any > ,
62- context : {
63- pkg : PackageJson
64- chunks : ChunksByFormat
65- isPublish : boolean
66- } ,
67- ) => Awaitable < Record < string , any > >
60+ /**
61+ * Specifies custom exports to add to the package exports in addition to the ones generated by tsdown.
62+ * Use this to add additional exports in the exported package, such as workers or assets.
63+ *
64+ * @example
65+ * customExports(exports) {
66+ * exports['./worker.js'] = './dist/worker.js';
67+ * return exports;
68+ * }
69+ *
70+ * @example
71+ * ```jsonc
72+ * {
73+ * "customExports": {
74+ * "./worker.js": {
75+ * "types": "./dist/worker.d.ts",
76+ * "default": "./dist/worker.js"
77+ * }
78+ * }
79+ * }
80+ * ```
81+ */
82+ customExports ?:
83+ | Record < string , any >
84+ | ( (
85+ exports : Record < string , any > ,
86+ context : {
87+ pkg : PackageJson
88+ chunks : ChunksByFormat
89+ isPublish : boolean
90+ } ,
91+ ) => Awaitable < Record < string , any > > )
6892}
6993
7094export async function writeExports (
@@ -228,7 +252,9 @@ export async function generateExports(
228252 )
229253 exportMeta ( exports , all , packageJson )
230254 exportCss ( exports , chunks , css , pkgRoot )
231- if ( customExports ) {
255+ if ( typeof customExports === 'object' ) {
256+ exports = { ...exports , ...customExports }
257+ } else if ( typeof customExports === 'function' ) {
232258 exports = await customExports ( exports , {
233259 pkg,
234260 chunks,
@@ -246,7 +272,9 @@ export async function generateExports(
246272 )
247273 exportMeta ( publishExports , all , packageJson )
248274 exportCss ( publishExports , chunks , css , pkgRoot )
249- if ( customExports ) {
275+ if ( typeof customExports === 'object' ) {
276+ publishExports = { ...publishExports , ...customExports }
277+ } else if ( typeof customExports === 'function' ) {
250278 publishExports = await customExports ( publishExports , {
251279 pkg,
252280 chunks,
0 commit comments