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.
pull/4077/head
Bertrand Juglas 5 months ago committed by GitHub
parent 1687fca93c
commit 46652c62a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      .changeset/five-timers-reflect.md
  2. 7
      typescript/cli/src/config/chain.ts
  3. 5
      typescript/cli/src/utils/files.ts

@ -0,0 +1,5 @@
---
'@hyperlane-xyz/cli': patch
---
Fix the missing sorting in the YAML file generated

@ -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 {

@ -90,7 +90,10 @@ export function tryReadYamlAtPath<T>(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<T extends Record<string, any>>(

Loading…
Cancel
Save