diff --git a/packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts b/packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts index c9b9d95f..b98df44b 100644 --- a/packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts +++ b/packages/@aws-cdk/service-spec-importers/src/diff-fmt.ts @@ -52,7 +52,9 @@ export class DiffFormatter { ), listWithCaption( 'resources', - this.dbs[db].follow('hasResource', s).map((e) => this.renderResource(e.entity, db).prefix([' '])), + [...this.dbs[db].follow('hasResource', s)] + .sort(sortByKey((e) => e.entity.name)) + .map((e) => this.renderResource(e.entity, db).prefix([' '])), ), ]); } @@ -95,7 +97,9 @@ export class DiffFormatter { listWithCaption('attributes', this.renderProperties(r.attributes, db)), listWithCaption( 'types', - this.dbs[db].follow('usesType', r).map((e) => this.renderTypeDefinition(e.entity, db).prefix([' '])), + [...this.dbs[db].follow('usesType', r)] + .sort(sortByKey((e) => e.entity.name)) + .map((e) => this.renderTypeDefinition(e.entity, db).prefix([' '])), ), ]); } @@ -291,3 +295,7 @@ function listWithCaption(caption: string, trees: PrintableTree[]) { ret.addBullets(trees); return ret.prefix([' '], [' ']); } + +function sortByKey(keyFn: (x: T) => string): (a: T, b: T) => number { + return (a, b) => keyFn(a).localeCompare(keyFn(b)); +}