@@ -7,6 +7,46 @@ export default defineConfig({
77 target : "es2022" ,
88 platform : "neutral" ,
99 sourcemap : true ,
10- exports : true ,
1110 unbundle : true ,
11+ exports : {
12+ customExports ( pkg , context ) {
13+ // Create simplified export paths for API modules (e.g., "./accounting" instead of "./api/accounting/accounting")
14+ // Dynamically discovers modules from build output and includes proper type definitions for both ESM and CJS
15+
16+ // Extract module names from the build chunks
17+ const modules = new Set < string > ( ) ;
18+
19+ // Get chunks from all formats and extract module names
20+ for ( const format in context . chunks ) {
21+ const chunks = context . chunks [ format as keyof typeof context . chunks ] ;
22+ if ( chunks ) {
23+ for ( const chunk of chunks ) {
24+ if ( chunk . type === "chunk" && chunk . fileName ) {
25+ // Match pattern: api/{moduleName}/{moduleName}.js (or .cjs)
26+ const match = chunk . fileName . match ( / ^ a p i \/ ( [ ^ / ] + ) \/ \1\. ( j s | c j s ) $ / ) ;
27+ if ( match && match [ 1 ] ) {
28+ modules . add ( match [ 1 ] ) ;
29+ }
30+ }
31+ }
32+ }
33+ }
34+
35+ // For each module, create a simplified export path
36+ for ( const moduleName of modules ) {
37+ pkg [ `./${ moduleName } ` ] = {
38+ import : {
39+ types : `./dist/api/${ moduleName } /${ moduleName } .d.ts` ,
40+ default : `./dist/api/${ moduleName } /${ moduleName } .js` ,
41+ } ,
42+ require : {
43+ types : `./dist/api/${ moduleName } /${ moduleName } .d.cts` ,
44+ default : `./dist/api/${ moduleName } /${ moduleName } .cjs` ,
45+ } ,
46+ } ;
47+ }
48+
49+ return pkg ;
50+ } ,
51+ } ,
1252} ) ;
0 commit comments