import "../_dnt.polyfills.js"; import * as dntShim from "../_dnt.shims.js"; import * as $ from "../deps/scale.js" import { register } from "../deps/shims/register-ts-node.node.js" import * as path from "../deps/std/path.js" import { NetSpec } from "../nets/mod.js" const $nets = $.record($.instance(NetSpec as new() => NetSpec, $.tuple(), (_: NetSpec) => [])) export async function resolveNets(maybeNetsPath?: string): Promise> { const resolvedNetsPath = await resolveNetsPath(maybeNetsPath) if (resolvedNetsPath.endsWith(".ts")) { await register() } // shimmed by dnt let nets = await _import(resolvedNetsPath) if ("default" in nets) nets = nets.default $.assert($nets, nets) for (const key in nets) nets[key]!.name = key return nets } async function resolveNetsPath(maybeNetsPath?: string): Promise { if (maybeNetsPath) return path.resolve(maybeNetsPath) for (const p of ["nets.ts", "nets.js"]) { try { const resolved = path.resolve(p) await dntShim.Deno.stat(resolved) return resolved } catch (_e) {} } throw new Error( "Could not resolve nets path. Create a `nets.ts` or `nets.js` file and export your net specs.", ) } function _import(file: string) { return import(path.toFileUrl(file).toString()) }