Skip to content

AssetResolver

Defined in: packages/core/src/runtime/pkg/types.ts:133

Resolve per-package assets (WASM binaries, ESM glue) for a bundle factory.

Implement this to resolve a package’s sidecar assets by relative name.

Passed into package factories ((resolver?: AssetResolver) => Extension) so the same factory works in two locations:

  • Host-side (monorepo / dev): the factory constructs its own resolver from import.meta.url via createWasmBin(import.meta.url, ...).
  • Guest-side (pkg install from a registry): the pkg bin builds a resolver rooted at the installed package’s bundle directory (see fsResolver, cachedResolver, nullResolver in runtime/pkg/evaluator.ts) and threads it into the factory.

Asset names are relative paths declared by the package’s assets field in the registry index (e.g., "vim.wasm", "vim.glue.mjs"). The resolver joins the name to its base path; callers never pass absolute paths.

import type { AssetResolver, Extension } from '@fishnet/core'
import { createWasmBin } from '@fishnet/runtime'
export default function myWasmTool(resolver?: AssetResolver): Extension {
const bin = createWasmBin(resolver ?? import.meta.url, 'tool.wasm', 'tool.glue.mjs')
return { bins: { tool: bin } }
}

Extension

loadModule(name): Promise<unknown>

Defined in: packages/core/src/runtime/pkg/types.ts:155

Load a sidecar ESM/CJS module by relative name and return its namespace.

string

Promise<unknown>

The returned value is the module’s namespace-or-default. The default export is unwrapped for ESM; CJS modules return their module.exports.

Error when the module is not found or fails to evaluate.


resolve(name): Promise<Uint8Array<ArrayBufferLike>>

Defined in: packages/core/src/runtime/pkg/types.ts:145

Read a sidecar asset’s bytes by relative name.

string

Promise<Uint8Array<ArrayBufferLike>>

name is a package-relative path segment (no leading slash, no .. traversal). The implementation joins it to the package’s base.

The returned Uint8Array owns its buffer — callers may transfer or hand it to WebAssembly.compile without copying.

Error when the asset is not found (e.g., missing file or cache miss in a preloaded resolver).