diff --git a/.changeset/beige-foxes-compare.md b/.changeset/beige-foxes-compare.md new file mode 100644 index 00000000000..ffae682bb1d --- /dev/null +++ b/.changeset/beige-foxes-compare.md @@ -0,0 +1,5 @@ +--- +"@hyperlane-xyz/utils": patch +--- + +Use stringifyObject in writeJson and writeYaml for proper ethers BigNumber serialization. Rename removeEndingSlash to removeTrailingSlash. diff --git a/typescript/cli/src/commands/warp.ts b/typescript/cli/src/commands/warp.ts index 58226613caa..6d2a3ff20c4 100644 --- a/typescript/cli/src/commands/warp.ts +++ b/typescript/cli/src/commands/warp.ts @@ -41,7 +41,7 @@ import { ExtendedChainSubmissionStrategySchema } from '../submitters/types.js'; import { indentYamlOrJson, readYamlOrJson, - removeEndingSlash, + removeTrailingSlash, writeYamlOrJson, } from '../utils/files.js'; import { @@ -123,7 +123,7 @@ export const apply: CommandModuleWithWarpApplyContext< type: 'string', description: 'The directory to output transaction receipts.', default: './generated/transactions', - coerce: (dir) => removeEndingSlash(dir), + coerce: (dir) => removeTrailingSlash(dir), }, relay: { type: 'boolean', diff --git a/typescript/cli/src/utils/files.ts b/typescript/cli/src/utils/files.ts index 35aa3ab8b12..951ae37118f 100644 --- a/typescript/cli/src/utils/files.ts +++ b/typescript/cli/src/utils/files.ts @@ -15,7 +15,7 @@ import { readJson, readYaml, readYamlOrJson, - removeEndingSlash, + removeTrailingSlash, resolveFileFormat, resolvePath, tryReadJson, @@ -36,7 +36,7 @@ export { isFile, readFileAtPath, writeFileAtPath, - removeEndingSlash, + removeTrailingSlash, resolvePath, readJson, tryReadJson, diff --git a/typescript/utils/src/fs/index.ts b/typescript/utils/src/fs/index.ts index ca01d12f9af..3f0b82b94c9 100644 --- a/typescript/utils/src/fs/index.ts +++ b/typescript/utils/src/fs/index.ts @@ -8,7 +8,7 @@ export { isFile, pathExists, readFileAtPath, - removeEndingSlash, + removeTrailingSlash, resolvePath, writeFileAtPath, writeToFile, diff --git a/typescript/utils/src/fs/json.ts b/typescript/utils/src/fs/json.ts index d4c48a34902..652fcadcdcd 100644 --- a/typescript/utils/src/fs/json.ts +++ b/typescript/utils/src/fs/json.ts @@ -1,6 +1,6 @@ import path from 'path'; -import { objMerge } from '../objects.js'; +import { objMerge, stringifyObject } from '../objects.js'; import { isFile, pathExists, readFileAtPath, writeToFile } from './utils.js'; @@ -24,9 +24,10 @@ export function tryReadJson(filepath: string): T | null { /** * Writes an object as JSON to a file with a trailing newline. + * Uses stringifyObject to properly handle ethers BigNumber serialization. */ export function writeJson(filepath: string, obj: unknown): void { - writeToFile(filepath, JSON.stringify(obj, null, 2)); + writeToFile(filepath, stringifyObject(obj, 'json', 2)); } /** diff --git a/typescript/utils/src/fs/utils.test.ts b/typescript/utils/src/fs/utils.test.ts index fcd3fa225f0..4d0427fe176 100644 --- a/typescript/utils/src/fs/utils.test.ts +++ b/typescript/utils/src/fs/utils.test.ts @@ -8,7 +8,7 @@ import { isFile, pathExists, readFileAtPath, - removeEndingSlash, + removeTrailingSlash, resolvePath, writeFileAtPath, writeToFile, @@ -32,17 +32,17 @@ describe('fs utilities', () => { } }); - describe('removeEndingSlash', () => { + describe('removeTrailingSlash', () => { it('removes trailing slash', () => { - expect(removeEndingSlash('/path/to/dir/')).to.equal('/path/to/dir'); + expect(removeTrailingSlash('/path/to/dir/')).to.equal('/path/to/dir'); }); it('leaves path without trailing slash unchanged', () => { - expect(removeEndingSlash('/path/to/dir')).to.equal('/path/to/dir'); + expect(removeTrailingSlash('/path/to/dir')).to.equal('/path/to/dir'); }); it('handles empty string', () => { - expect(removeEndingSlash('')).to.equal(''); + expect(removeTrailingSlash('')).to.equal(''); }); }); diff --git a/typescript/utils/src/fs/utils.ts b/typescript/utils/src/fs/utils.ts index 789373c330a..c8f6f463805 100644 --- a/typescript/utils/src/fs/utils.ts +++ b/typescript/utils/src/fs/utils.ts @@ -5,7 +5,7 @@ import path from 'path'; /** * Removes trailing slash from a directory path. */ -export function removeEndingSlash(dirPath: string): string { +export function removeTrailingSlash(dirPath: string): string { if (dirPath.endsWith('/')) { return dirPath.slice(0, -1); } diff --git a/typescript/utils/src/fs/yaml.ts b/typescript/utils/src/fs/yaml.ts index e90b5efafb9..35a6da464b3 100644 --- a/typescript/utils/src/fs/yaml.ts +++ b/typescript/utils/src/fs/yaml.ts @@ -5,10 +5,9 @@ import { SchemaOptions, ToJSOptions, parse, - stringify as yamlStringify, } from 'yaml'; -import { objMerge } from '../objects.js'; +import { objMerge, stringifyObject } from '../objects.js'; import { isFile, readFileAtPath, writeToFile } from './utils.js'; @@ -45,12 +44,10 @@ export function tryReadYaml(filepath: string): T | null { /** * Writes an object as YAML to a file with a trailing newline. + * Uses stringifyObject to properly handle ethers BigNumber serialization. */ export function writeYaml(filepath: string, obj: unknown): void { - writeToFile( - filepath, - yamlStringify(obj, { indent: 2, sortMapEntries: true }).trimEnd(), - ); + writeToFile(filepath, stringifyObject(obj, 'yaml', 2).trimEnd()); } /**