-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description This PR re-adds getRegistry, but with it exported from index-fs.ts and removed from index.ts. The reason is that we cannot export functions that use `fs` considering that the frontend cannot access this package. Instead we must rely on tree-shaking via index-fs.ts ### Backward compatibility Yes ### Testing Tested with `yarn link` --------- Co-authored-by: Morteza Shojaei <[email protected]>
- Loading branch information
1 parent
dedd673
commit 6031ff9
Showing
5 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@hyperlane-xyz/registry': minor | ||
--- | ||
|
||
Add getRegistry function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Exports for utilities that require fs access and are not suitable for browser use | ||
export { FileSystemRegistry } from './registry/FileSystemRegistry.js'; | ||
export { getRegistry } from './registry/registry-utils.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { Logger } from 'pino'; | ||
import { GithubRegistry } from './GithubRegistry.js'; | ||
import { FileSystemRegistry } from './FileSystemRegistry.js'; | ||
import { IRegistry } from './IRegistry.js'; | ||
import { DEFAULT_GITHUB_REGISTRY, PROXY_DEPLOYED_URL } from '../consts.js'; | ||
import { MergedRegistry } from './MergedRegistry.js'; | ||
|
||
const isHttpsUrl = (value: string): boolean => { | ||
try { | ||
if (!value) return false; | ||
const url = new URL(value); | ||
return url.protocol === 'https:'; | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
|
||
const isCanonicalRepoUrl = (url: string): boolean => { | ||
return url === DEFAULT_GITHUB_REGISTRY; | ||
}; | ||
|
||
export function getRegistry( | ||
registryUris: string[], | ||
enableProxy: boolean, | ||
logger?: Logger, | ||
): IRegistry { | ||
const registryLogger = logger?.child({ module: 'MergedRegistry' }); | ||
const registries = registryUris | ||
.map((uri) => uri.trim()) | ||
.filter((uri) => !!uri) | ||
.map((uri, index) => { | ||
const childLogger = registryLogger?.child({ uri, index }); | ||
if (isHttpsUrl(uri)) { | ||
return new GithubRegistry({ | ||
uri, | ||
logger: childLogger, | ||
proxyUrl: enableProxy && isCanonicalRepoUrl(uri) ? PROXY_DEPLOYED_URL : undefined, | ||
}); | ||
} else { | ||
return new FileSystemRegistry({ | ||
uri, | ||
logger: childLogger, | ||
}); | ||
} | ||
}); | ||
return new MergedRegistry({ | ||
registries, | ||
logger, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters