npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

astrobit

v0.1.5

Published

A thin framework for running MoonBit components as Astro islands

Readme

astrobit

A thin framework for running MoonBit components as Astro islands.

Write your UI logic in MoonBit, use it directly in .astro files — SSR and client-side hydration included.

Requirements

Installation

npm install astrobit

Add the integration to your astro.config.mjs:

import { defineConfig } from 'astro/config'
import astrobit from 'astrobit'

export default defineConfig({
  integrations: [astrobit()],
})

Project Setup

Place a moon.mod.json at the root of your Astro project:

{
  "name": "yourname/your-project",
  "deps": {
    "SouichiroTsujimoto/astrobit": "0.1.1",
    "mizchi/signals": "0.6.4"
  },
  "preferred-target": "js"
}

Then install the MoonBit dependencies:

moon install

Writing a Component

Each component lives in its own directory with a moon.pkg file.

src/components/counter/moon.pkg

{
  "import": [
    "SouichiroTsujimoto/astrobit" @a,
    "SouichiroTsujimoto/astrobit/dom",
    "mizchi/signals"
  ],
  "options": {
    "link": { "js": { "exports": ["mount", "render", "hydrate"], "format": "esm" } }
  }
}

src/components/counter/counter.mbt

fn counter(props : @dom.Props) -> @a.Node {
  let initial = props.get_int("initial")
  let count = @signals.signal(initial)
  @a.div([
    @a.p(@a.dyn_text(fn() { "Count: " + count.get().to_string() })),
    @a.button("-") |> @a.on_click(fn(_) { count.update(fn(n) { n - 1 }) }),
    @a.button("+") |> @a.on_click(fn(_) { count.update(fn(n) { n + 1 }) }),
  ])
}

pub fn mount(element : @dom.Element, props : @dom.Props) -> Unit {
  @a.mount_dom(element, counter(props))
}

pub fn render(props : @dom.Props) -> String {
  @a.render_to_html(counter(props))
}

pub fn hydrate(element : @dom.Element, props : @dom.Props) -> Unit {
  @a.hydrate_dom(element, counter(props))
}

Props are received as @dom.Props and extracted with typed accessors:

props.get_int("key")               // Int (default: 0)
props.get_string("key")            // String (default: "")
props.get_bool("key")              // Bool (default: false)

props.get_int("key", default=10)   // with explicit default

Using in Astro

Import the .mbt file directly. The Vite plugin handles the rest.

---
import Counter from '../components/counter/counter.mbt'
---

<!-- client:only — mount on the client, no SSR -->
<Counter client:only="astrobit" initial={0} />

<!-- client:load — SSR + hydration -->
<Counter client:load initial={0} />

TypeScript types for *.mbt imports are injected automatically — no manual env.d.ts setup required.

Build

Before running the dev server, build the MoonBit sources:

moon build

Then start Astro:

npm run dev

HMR is supported — saving a .mbt file triggers an automatic rebuild and page reload.

How It Works

  • SSR: render(props) returns an HTML string, rendered server-side by Astro.
  • Hydration (client:load): hydrate(element, props) attaches signals and event listeners to the existing DOM without re-rendering.
  • Mount (client:only): mount(element, props) builds the DOM from scratch on the client.
  • Reactivity: Powered by mizchi/signals.

License

MIT