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.
Remarks
Section titled “Remarks”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.urlviacreateWasmBin(import.meta.url, ...). - Guest-side (
pkg installfrom a registry): the pkg bin builds a resolver rooted at the installed package’s bundle directory (see fsResolver, cachedResolver, nullResolver inruntime/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.
Example
Section titled “Example”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 } }}Methods
Section titled “Methods”loadModule()
Section titled “loadModule()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<unknown>
Invariant
Section titled “Invariant”The returned value is the module’s namespace-or-default. The
default export is unwrapped for ESM; CJS modules return their
module.exports.
Throws
Section titled “Throws”Error when the module is not found or fails to evaluate.
resolve()
Section titled “resolve()”resolve(
name):Promise<Uint8Array<ArrayBufferLike>>
Defined in: packages/core/src/runtime/pkg/types.ts:145
Read a sidecar asset’s bytes by relative name.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<Uint8Array<ArrayBufferLike>>
Invariant
Section titled “Invariant”name is a package-relative path segment (no leading slash,
no .. traversal). The implementation joins it to the package’s base.
Invariant
Section titled “Invariant”The returned Uint8Array owns its buffer — callers may transfer
or hand it to WebAssembly.compile without copying.
Throws
Section titled “Throws”Error when the asset is not found (e.g., missing file or
cache miss in a preloaded resolver).