@@ -169,16 +169,29 @@ function scanComponents(dir, basePath = "") {
169169 * Generate TypeScript definition file for IDE autocomplete
170170 */
171171function generateTypeDefinitions ( root , componentsDir , components ) {
172- const dtsPath = path . resolve ( root , "src/openscript-components.d.ts" ) ;
172+ // Place d.ts in the parent directory of componentsDir
173+ const componentsAbsDir = path . resolve ( root , componentsDir ) ;
174+ const dtsDir = path . dirname ( componentsAbsDir ) ;
175+ const dtsPath = path . resolve ( dtsDir , "openscript-components.d.ts" ) ;
173176
174177 const imports = components
175- . map (
176- ( c ) =>
177- `import type ${ c . name } from './${ componentsDir } /${ c . path . replace (
178- ".js" ,
179- ""
180- ) } ';`
181- )
178+ . map ( ( c ) => {
179+ const componentAbsPath = path . resolve ( componentsAbsDir , c . path ) ;
180+ let relativePath = path . relative ( dtsDir , componentAbsPath ) ;
181+
182+ // Normalize to forward slashes
183+ relativePath = normalizePath ( relativePath ) ;
184+
185+ // Remove extension
186+ relativePath = relativePath . replace ( / \. \w + $ / , "" ) ;
187+
188+ // Ensure it starts with ./ or ../
189+ if ( ! relativePath . startsWith ( "." ) && ! relativePath . startsWith ( "/" ) ) {
190+ relativePath = "./" + relativePath ;
191+ }
192+
193+ return `import type ${ c . name } from '${ relativePath } ';` ;
194+ } )
182195 . join ( "\n" ) ;
183196
184197 const properties = components
0 commit comments