From 46652c62a8909bb2cb02eaa5e3ee3f8eb82142e7 Mon Sep 17 00:00:00 2001 From: Bertrand Juglas Date: Wed, 3 Jul 2024 17:08:33 +0200 Subject: [PATCH] fix: use sortMapEntries in writeYaml (#4091) ### Description It includes usage of sortMapEntries option in yamlStringify function called in writeYaml function. ### Drive-by changes None ### Related issues - Fixes #4057 ### Backward compatibility Yes Because I've converted the argument 2 into the indent option as documented in yaml library. ### Testing Manual by trying to reproduce the issue in the same way. --- .changeset/five-timers-reflect.md | 5 +++++ typescript/cli/src/config/chain.ts | 7 +++++-- typescript/cli/src/utils/files.ts | 5 ++++- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .changeset/five-timers-reflect.md diff --git a/.changeset/five-timers-reflect.md b/.changeset/five-timers-reflect.md new file mode 100644 index 000000000..c476ee66a --- /dev/null +++ b/.changeset/five-timers-reflect.md @@ -0,0 +1,5 @@ +--- +'@hyperlane-xyz/cli': patch +--- + +Fix the missing sorting in the YAML file generated diff --git a/typescript/cli/src/config/chain.ts b/typescript/cli/src/config/chain.ts index 924bbd325..548c2474b 100644 --- a/typescript/cli/src/config/chain.ts +++ b/typescript/cli/src/config/chain.ts @@ -95,8 +95,11 @@ export async function createChainConfig({ const parseResult = ChainMetadataSchema.safeParse(metadata); if (parseResult.success) { - logGreen(`Chain config is valid, writing to registry:`); - const metadataYaml = yamlStringify(metadata, null, 2); + logGreen(`Chain config is valid, writing unsorted to registry:`); + const metadataYaml = yamlStringify(metadata, { + indent: 2, + sortMapEntries: true, + }); log(indentYamlOrJson(metadataYaml, 4)); await context.registry.updateChain({ chainName: metadata.name, metadata }); } else { diff --git a/typescript/cli/src/utils/files.ts b/typescript/cli/src/utils/files.ts index 277850af6..c09e7cabc 100644 --- a/typescript/cli/src/utils/files.ts +++ b/typescript/cli/src/utils/files.ts @@ -90,7 +90,10 @@ export function tryReadYamlAtPath(filepath: string): T | null { } export function writeYaml(filepath: string, obj: any) { - writeFileAtPath(filepath, yamlStringify(obj, null, 2) + '\n'); + writeFileAtPath( + filepath, + yamlStringify(obj, { indent: 2, sortMapEntries: true }) + '\n', + ); } export function mergeYaml>(