Skip to content

Commit 575603a

Browse files
committed
update import insert order
1 parent 2a9e84e commit 575603a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tools/@aws-cdk/construct-metadata-updater/lib/metadata-updater.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)