Skip to content

Commit 1f918d0

Browse files
refactor(sdk): add reader subpath exports and narrow utils logging deps (#8616)
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent ee48c20 commit 1f918d0

6 files changed

Lines changed: 73 additions & 35 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@hyperlane-xyz/sdk': patch
3+
'@hyperlane-xyz/utils': patch
4+
---
5+
6+
Added `@hyperlane-xyz/sdk` subpath exports for `core`, `hook`, and `ism` modules. Hardened `@hyperlane-xyz/utils` pretty-mode logging with a graceful fallback when `pino-pretty` is not installed.

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typescript/fee-quoting/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"format": "oxfmt --write ./src"
2525
},
2626
"dependencies": {
27+
"@google-cloud/pino-logging-gcp-config": "catalog:",
2728
"@hyperlane-xyz/registry": "catalog:",
2829
"@hyperlane-xyz/sdk": "workspace:*",
2930
"@hyperlane-xyz/utils": "workspace:*",

typescript/http-registry-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"test:unit": "mocha --config .mocharc.json './test/**/*.ts' --exit"
2626
},
2727
"dependencies": {
28+
"@google-cloud/pino-logging-gcp-config": "catalog:",
2829
"@hyperlane-xyz/registry": "catalog:",
2930
"@hyperlane-xyz/sdk": "workspace:*",
3031
"@hyperlane-xyz/utils": "workspace:*",

typescript/sdk/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@
2121
"types": "./dist/index.d.ts",
2222
"default": "./dist/index.js"
2323
},
24+
"./core/*": {
25+
"types": "./dist/core/*.d.ts",
26+
"default": "./dist/core/*.js"
27+
},
28+
"./hook/*": {
29+
"types": "./dist/hook/*.d.ts",
30+
"default": "./dist/hook/*.js"
31+
},
32+
"./ism/*": {
33+
"types": "./dist/ism/*.d.ts",
34+
"default": "./dist/ism/*.js"
35+
},
2436
"./metadata/*": {
2537
"types": "./dist/metadata/*.d.ts",
2638
"default": "./dist/metadata/*.js"

typescript/utils/src/logging.ts

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,52 +75,64 @@ export function createHyperlanePinoLogger(
7575
logLevel: LevelWithSilent,
7676
logFormat: LogFormat,
7777
) {
78+
const createFallbackLogger = () =>
79+
pino({
80+
level: logLevel,
81+
name: 'hyperlane',
82+
formatters: {
83+
// Remove pino's default bindings of hostname but keep pid
84+
bindings: (defaultBindings) => ({ pid: defaultBindings.pid }),
85+
},
86+
hooks: {
87+
logMethod(inputArgs, method, level) {
88+
// Pino has no simple way of setting custom log shapes and they
89+
// recommend against using pino-pretty in production so when
90+
// pretty is enabled we circumvent pino and log directly to console
91+
if (
92+
logFormat === LogFormat.Pretty &&
93+
level >= pino.levels.values[logLevel]
94+
) {
95+
// eslint-disable-next-line no-console
96+
console.log(...inputArgs);
97+
// Then return null to prevent pino from logging
98+
return null;
99+
}
100+
return method.apply(this, inputArgs);
101+
},
102+
},
103+
});
104+
78105
// In development, pino-pretty is used for a better dev experience,
79106
// but only if the log format is 'pretty'. This allows for JSON logs
80107
// in development as well if explicitly configured.
81108
if (
82109
process.env.NODE_ENV === 'development' &&
83110
logFormat === LogFormat.Pretty
84111
) {
85-
return pino({
86-
level: logLevel,
87-
transport: {
88-
target: 'pino-pretty',
89-
options: {
90-
colorize: true,
91-
translateTime: 'SYS:standard',
92-
ignore: 'pid,hostname',
112+
try {
113+
return pino({
114+
level: logLevel,
115+
transport: {
116+
target: 'pino-pretty',
117+
options: {
118+
colorize: true,
119+
translateTime: 'SYS:standard',
120+
ignore: 'pid,hostname',
121+
},
93122
},
94-
},
95-
});
123+
});
124+
} catch (err) {
125+
const fallbackLogger = createFallbackLogger();
126+
fallbackLogger.warn(
127+
err,
128+
'Could not initialize pino-pretty, falling back to built-in pretty logger',
129+
);
130+
return fallbackLogger;
131+
}
96132
}
97133

98134
// In production (or other envs), use the original hook-based logger
99-
return pino({
100-
level: logLevel,
101-
name: 'hyperlane',
102-
formatters: {
103-
// Remove pino's default bindings of hostname but keep pid
104-
bindings: (defaultBindings) => ({ pid: defaultBindings.pid }),
105-
},
106-
hooks: {
107-
logMethod(inputArgs, method, level) {
108-
// Pino has no simple way of setting custom log shapes and they
109-
// recommend against using pino-pretty in production so when
110-
// pretty is enabled we circumvent pino and log directly to console
111-
if (
112-
logFormat === LogFormat.Pretty &&
113-
level >= pino.levels.values[logLevel]
114-
) {
115-
// eslint-disable-next-line no-console
116-
console.log(...inputArgs);
117-
// Then return null to prevent pino from logging
118-
return null;
119-
}
120-
return method.apply(this, inputArgs);
121-
},
122-
},
123-
});
135+
return createFallbackLogger();
124136
}
125137

126138
export function ethersBigNumberSerializer(key: string, value: any): any {

0 commit comments

Comments
 (0)