@@ -11,7 +11,8 @@ export const AdminExtension = defineExtension({
1111 multiple : true ,
1212 paramsSchema : ( { project } ) => {
1313 return z . object ( {
14- src : zodSrcPath ( { project } )
14+ src : zodSrcPath ( { project } ) ,
15+ exportName : z . string ( ) . optional ( )
1516 } ) ;
1617 } ,
1718 async build ( params , ctx ) {
@@ -33,6 +34,11 @@ export const AdminExtension = defineExtension({
3334 absoluteExtensionFilePath = extensionFilePath ;
3435 }
3536
37+ const extensionFileName = path . basename ( absoluteExtensionFilePath ) ;
38+
39+ // Export name can be customized or defaults to the file name without extension.
40+ const exportName = params . exportName ?? path . parse ( extensionFileName ) . name ;
41+
3642 // Generate a constant hash-based component name to avoid using timestamps.
3743 const hash = crypto . createHash ( "sha256" ) . update ( extensionFilePath ) . digest ( "hex" ) ;
3844 const componentName = `AdminExtension_${ hash . slice ( - 10 ) } ` ;
@@ -41,7 +47,7 @@ export const AdminExtension = defineExtension({
4147
4248 const importPath = path
4349 . relative ( path . dirname ( extensionsTsxFilePath ) , absoluteExtensionFilePath )
44- . replace ( " .tsx" , ".js" ) ;
50+ . replace ( / \ .t s x ? $ / , ".js" ) ;
4551
4652 project . addSourceFileAtPath ( extensionsTsxFilePath ) ;
4753
@@ -66,15 +72,15 @@ export const AdminExtension = defineExtension({
6672 index = last . getChildIndex ( ) + 1 ;
6773 }
6874
69- // Import as default export if available, otherwise import named "Extension" export
75+ // Import as default export if available, otherwise import named export
7076 if ( hasDefaultExport ) {
7177 source . insertImportDeclaration ( index , {
7278 defaultImport : componentName ,
7379 moduleSpecifier : importPath
7480 } ) ;
7581 } else {
7682 source . insertImportDeclaration ( index , {
77- namedImports : [ { name : "Extension" , alias : componentName } ] ,
83+ namedImports : [ { name : exportName , alias : componentName } ] ,
7884 moduleSpecifier : importPath
7985 } ) ;
8086 }
0 commit comments