@@ -177,7 +177,7 @@ async function generateBarrelFiles(
177177 packagePath : string ,
178178 barrelFiles : Record < string , string >
179179) : Promise < void > {
180- for ( const [ barrelPath ] of Object . entries ( barrelFiles ) ) {
180+ for ( const [ barrelPath , typesPath ] of Object . entries ( barrelFiles ) ) {
181181 const barrelFilePath = resolve ( packagePath , `${ barrelPath } .d.ts` ) ;
182182
183183 // Ensure parent directory exists
@@ -186,8 +186,8 @@ async function generateBarrelFiles(
186186 fs . mkdirSync ( parentDir , { recursive : true } ) ;
187187 }
188188
189- // Calculate relative path from barrel file to the dist path
190- const relativePath = calculateRelativePath ( barrelPath ) ;
189+ // Calculate relative path from barrel file to the dist types file (without extension)
190+ const relativePath = calculateRelativePath ( barrelPath , typesPath ) ;
191191
192192 // Generate the barrel file content
193193 const content = `export * from "${ relativePath } ";` ;
@@ -198,16 +198,25 @@ async function generateBarrelFiles(
198198}
199199
200200/**
201- * Calculate the relative path from barrel file location to the dist path
201+ * Calculate the relative path from barrel file location to the dist types file
202202 * Returns path without file extension for proper TypeScript module resolution
203203 */
204- function calculateRelativePath ( barrelPath : string ) : string {
204+ function calculateRelativePath ( barrelPath : string , typesPath : string ) : string {
205205 const barrelDepth = barrelPath . split ( "/" ) . length - 1 ;
206206
207207 // Build the relative path with appropriate ../
208208 const upLevels = barrelDepth > 0 ? "../" . repeat ( barrelDepth ) : "./" ;
209209
210- return `${ upLevels } dist/${ barrelPath } ` ;
210+ // Remove the leading ./ and file extension from typesPath
211+ const cleanPath = typesPath
212+ . replace ( / ^ \. \/ / , "" )
213+ . replace ( / \. d \. c t s $ / , "" )
214+ . replace ( / \. d \. t s $ / , "" )
215+ . replace ( / \. c t s $ / , "" )
216+ . replace ( / \. t s $ / , "" )
217+ . replace ( / \. j s $ / , "" ) ;
218+
219+ return `${ upLevels } ${ cleanPath } ` ;
211220}
212221
213222/**
0 commit comments