Skip to content

Commit

Permalink
Remove hard dep on utils package
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Apr 16, 2024
1 parent 034a9c0 commit ee98300
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@hyperlane-xyz/registry",
"description": "A collection of configs, artifacts, and schemas for Hyperlane",
"version": "1.0.2",
"dependencies": {
"yaml": "^2"
},
"devDependencies": {
"@changesets/cli": "^2.26.2",
"@hyperlane-xyz/sdk": "3.10.0",
Expand All @@ -14,7 +17,6 @@
"prettier": "^2.8.8",
"tsx": "^4.7.1",
"typescript": "5.3.3",
"yaml": "^2.3.1",
"zod": "^3.21.2",
"zod-to-json-schema": "^3.22.5"
},
Expand Down
13 changes: 7 additions & 6 deletions src/registry/BaseRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { Logger } from 'pino';

import { rootLogger } from '@hyperlane-xyz/utils';

import { ChainMap, ChainMetadata, ChainName } from '@hyperlane-xyz/sdk';
import { ChainAddresses, IRegistry, RegistryContent } from './IRegistry.js';
import type { ChainMap, ChainMetadata, ChainName } from '@hyperlane-xyz/sdk';
import type { ChainAddresses, IRegistry, RegistryContent } from './IRegistry.js';

export abstract class BaseRegistry implements IRegistry {
protected readonly logger: Logger;
Expand All @@ -13,8 +11,11 @@ export abstract class BaseRegistry implements IRegistry {
protected metadataCache?: ChainMap<ChainMetadata>;
protected addressCache?: ChainMap<ChainAddresses>;

constructor({ logger = rootLogger.child({ module: 'Registry' }) }: { logger?: Logger }) {
this.logger = logger;
constructor({ logger }: { logger?: Logger }) {
// @ts-ignore forcing in to avoid a @hyperlane-xyz/utils
// dependency here, which could bloat consumer bundles
// unnecessarily (e.g. they just want metadata)
this.logger = logger || console;
}

protected getChainsPath(): string {
Expand Down
10 changes: 3 additions & 7 deletions src/registry/GithubRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import type { Logger } from 'pino';
import { parse } from 'yaml';

import { rootLogger } from '@hyperlane-xyz/utils';

import { ChainMap, ChainMetadata, ChainName } from '@hyperlane-xyz/sdk';
import type { ChainMap, ChainMetadata, ChainName } from '@hyperlane-xyz/sdk';

import { BaseRegistry } from './BaseRegistry.js';
import { ChainAddresses, ChainFiles, IRegistry, RegistryContent } from './IRegistry.js';
import type { ChainAddresses, ChainFiles, IRegistry, RegistryContent } from './IRegistry.js';

const DEFAULT_REGISTRY = 'https://github.com/hyperlane-xyz/hyperlane-registry';
const CHAIN_FILE_REGEX = /chains\/([a-z]+)\/([a-z]+)\.yaml/;
Expand All @@ -33,9 +31,7 @@ export class GithubRegistry extends BaseRegistry implements IRegistry {
public readonly repoName: string;

constructor(options: GithubRegistryOptions = {}) {
super({
logger: options.logger ?? rootLogger.child({ module: 'GithubRegistry' }),
});
super({ logger: options.logger });
this.url = new URL(options.url ?? DEFAULT_REGISTRY);
this.branch = options.branch ?? 'main';
const pathSegments = this.url.pathname.split('/');
Expand Down

0 comments on commit ee98300

Please sign in to comment.