From 0b02d6685df0bf3997994a3fee55c24abdeba4d0 Mon Sep 17 00:00:00 2001 From: Mary Gao Date: Wed, 16 Jul 2025 20:57:59 +0800 Subject: [PATCH] Fix the import ordering issues --- packages/typespec-ts/src/framework/hooks/binder.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/typespec-ts/src/framework/hooks/binder.ts b/packages/typespec-ts/src/framework/hooks/binder.ts index 2e7f542573..140e2ddfbf 100644 --- a/packages/typespec-ts/src/framework/hooks/binder.ts +++ b/packages/typespec-ts/src/framework/hooks/binder.ts @@ -232,6 +232,10 @@ class BinderImp implements Binder { this.resolveDependencyReferences(file); const importStructures = this.imports.get(file); if (importStructures) { + // Sort imports in place by module specifier to ensure consistent ordering + importStructures.sort((a, b) => + a.moduleSpecifier < b.moduleSpecifier ? -1 : 1 + ); for (const importStructure of importStructures) { file.addImportDeclaration(importStructure); }