2626 console . warn ( `⚠️ Could not read enums directory at ${ enumsDir } . Skipping enum detection.` , e ) ;
2727}
2828
29+ const hooksDir = path . join (
30+ path . dirname ( require . resolve ( '@ui5/webcomponents-react-base/package.json' ) ) ,
31+ 'dist' ,
32+ 'hooks' ,
33+ ) ;
34+ let hookNames : string [ ] = [ ] ;
35+ try {
36+ hookNames = fs
37+ . readdirSync ( hooksDir )
38+ . filter (
39+ ( file ) => ( file . endsWith ( '.js' ) || file . endsWith ( '.ts' ) ) && ! file . endsWith ( '.d.ts' ) && ! file . startsWith ( 'index' ) ,
40+ )
41+ . map ( ( file ) => path . basename ( file , path . extname ( file ) ) ) ;
42+ } catch ( e ) {
43+ console . warn ( `⚠️ Could not read hooks directory at ${ hooksDir } .` , e ) ;
44+ }
45+
46+ const utilsDir = path . join (
47+ path . dirname ( require . resolve ( '@ui5/webcomponents-react-base/package.json' ) ) ,
48+ 'dist' ,
49+ 'utils' ,
50+ ) ;
51+ let utilNames : string [ ] = [ ] ;
52+ try {
53+ utilNames = fs
54+ . readdirSync ( utilsDir )
55+ . filter (
56+ ( file ) => ( file . endsWith ( '.js' ) || file . endsWith ( '.ts' ) ) && ! file . endsWith ( '.d.ts' ) && ! file . startsWith ( 'index' ) ,
57+ )
58+ . map ( ( file ) => path . basename ( file , path . extname ( file ) ) ) ;
59+ } catch ( e ) {
60+ console . warn ( `⚠️ Could not read utils directory at ${ utilsDir } .` , e ) ;
61+ }
62+
63+ const utilsIndexPath = path . join ( utilsDir , 'index.js' ) ;
64+
65+ try {
66+ const indexSource = fs . readFileSync ( utilsIndexPath , 'utf-8' ) ;
67+ const exportRegex = / e x p o r t \s + (?: c o n s t | f u n c t i o n | c l a s s | t y p e | i n t e r f a c e | { [ ^ } ] + } ) \s + ( [ a - z A - Z 0 - 9 _ ] + ) / g;
68+ let match ;
69+ while ( ( match = exportRegex . exec ( indexSource ) ) !== null ) {
70+ utilNames . push ( match [ 1 ] ) ;
71+ }
72+ utilNames = Array . from ( new Set ( utilNames ) ) ; // Remove duplicates
73+ } catch ( e ) {
74+ console . warn ( `⚠️ Could not read utils index at ${ utilsIndexPath } .` , e ) ;
75+ }
76+
2977// Mapping functions
3078function resolveBaseExport ( importedName : string ) : string | undefined {
3179 const directMap : Record < string , string > = {
@@ -40,8 +88,19 @@ function resolveBaseExport(importedName: string): string | undefined {
4088 utils : `${ basePackageName } /utils` ,
4189 addCustomCSSWithScoping : `${ basePackageName } /internal/addCustomCSSWithScoping.js` ,
4290 } ;
43- if ( directMap [ importedName ] ) return directMap [ importedName ] ;
44- if ( importedName === 'default' || importedName === 'index' ) return basePackageName ;
91+
92+ if ( directMap [ importedName ] ) {
93+ return directMap [ importedName ] ;
94+ }
95+ if ( hookNames . includes ( importedName ) ) {
96+ return `${ basePackageName } /hooks` ;
97+ }
98+ if ( utilNames . includes ( importedName ) ) {
99+ return `${ basePackageName } /utils` ;
100+ }
101+ if ( importedName === 'default' || importedName === 'index' ) {
102+ return basePackageName ;
103+ }
45104 return undefined ;
46105}
47106
@@ -58,8 +117,12 @@ function resolveChartsExport(importedName: string): string | undefined {
58117 ScatterChartPlaceholder : `${ chartsPackageName } /ScatterChartPlaceholder` ,
59118 TimelineChartPlaceholder : `${ chartsPackageName } /TimelineChartPlaceholder` ,
60119 } ;
61- if ( directMap [ importedName ] ) return directMap [ importedName ] ;
62- if ( importedName === 'default' || importedName === 'index' ) return chartsPackageName ;
120+ if ( directMap [ importedName ] ) {
121+ return directMap [ importedName ] ;
122+ }
123+ if ( importedName === 'default' || importedName === 'index' ) {
124+ return chartsPackageName ;
125+ }
63126 return undefined ;
64127}
65128
0 commit comments