File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
tools/@aws-cdk/construct-metadata-updater/lib Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -160,12 +160,22 @@ export class ConstructsUpdater extends MetadataUpdater {
160160 return ;
161161 }
162162
163- // Create the new import statement
164- sourceFile . addImportDeclaration ( {
163+ // Find the correct insertion point (after the last import before the new one)
164+ const importDeclarations = sourceFile . getImportDeclarations ( ) ;
165+ let insertIndex = importDeclarations . length ;
166+ for ( let i = 0 ; i < importDeclarations . length ; i ++ ) {
167+ const existingImport = importDeclarations [ i ] . getModuleSpecifier ( ) . getText ( ) ;
168+ if ( existingImport . localeCompare ( relativePath ) > 0 ) {
169+ insertIndex = i ;
170+ break ;
171+ }
172+ }
173+
174+ // Insert the new import at the appropriate position
175+ sourceFile . insertImportDeclaration ( insertIndex , {
165176 moduleSpecifier : relativePath ,
166177 namedImports : [ { name : "addConstructMetadata" } ] ,
167178 } ) ;
168-
169179 console . log ( `Added import for MetadataType in file: ${ filePath } with relative path: ${ relativePath } ` ) ;
170180
171181 // Write the updated file back to disk
You can’t perform that action at this time.
0 commit comments