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 πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

@wasmer/wasm-terminal

v0.12.0

Published

A terminal-like component for the browser, that fetches and runs Wasm modules in the context of a shell. 🐚

Downloads

53

Readme

@wasmer/wasm-terminal

A terminal-like component for the browser, that fetches and runs Wasm modules in the context of a shell. 🐚

Documentation for Wasmer-JS Stack can be found on the Wasmer Docs.

Wasm Terminal Demo Gif

Table of Contents

Features

This project is built using Xterm.js, and Comlink πŸ™

  • Runs WASI Wasm modules using @wasmer/wasi and @wasmer/wasmfs. πŸƒ

  • Provides a terminal-like experience, with stuff like autocomplete, hotkeys, pipes, and more! πŸ‘©β€πŸ’»

  • Allows passing in your own custom Wasm binaries, or callback commands to provide commands in the shell! βš™οΈ

  • Runs processes in seperate web workers using Comlink! πŸ”—

  • Exports a command fetcher for fetching packages from WAPM! πŸ“¦

Installation

For installing @wasmer/wasm-terminal, just run this command in your shell:

npm install --save @wasmer/wasm-terminal

Quick Start

First, We must also include the [xterm](https://github.com/xtermjs/xterm.js/).css. For example:

<!-- This includes the external stylesheet. NOTE: The path should point to wherever you are hosting the wasm-terminal output. -->
<link
  rel="stylesheet"
  type="text/css"
  href="./node_modules/@wasmer/wasm-terminal/lib/xterm/xterm.css"
/>
import WasmTerminal, { fetchCommandFromWAPM } from "@wasmer/wasm-terminal";
import { lowerI64Imports } from "@wasmer/wasm-transformer";

// Let's write handler for the fetchCommand property of the WasmTerminal Config.
const fetchCommandHandler = async ({args}) => {
  let commandName = args[0];
  // Let's return a "CallbackCommand" if our command matches a special name
  if (commandName === "callback-command") {
    const callbackCommand = async (options, wasmFs) => {
      return `Callback Command Working! Options: ${options}, fs: ${wasmFs}`;
    };
    return callbackCommand;
  }

  // Let's fetch a wasm Binary from WAPM for the command name.
  const wasmBinary = await fetchCommandFromWAPM({args});

  // lower i64 imports from Wasi Modules, so that most Wasi modules
  // Can run in a Javascript context.
  return await lowerI64Imports(wasmBinary);
};

// Let's create our Wasm Terminal
const wasmTerminal = new WasmTerminal({
  // Function that is run whenever a command is fetched
  fetchCommand: fetchCommandHandler
});

// Let's print out our initial message
wasmTerminal.print("Hello World!");

// Let's bind our Wasm terminal to it's container
const containerElement = document.querySelector("#root");
wasmTerminal.open(containerElement);
wasmTerminal.fit();
wasmTerminal.focus();

// Later, when we are done with the terminal, let's destroy it
// wasmTerminal.destroy();

NOTE: Remember to include the CSS file mentioned at the beginning of the "Quick Start" section.

Reference API

The Reference API Documentation can be found on the @wasmer/wasm-terminal Reference API Wasmer Docs.

Browser Compatibility

For more simple Wasm modules, E.g cowsay, the Wasm terminal will work on the latest version of all major browsers. However, more complex Wasm modules may only work on browsers that support SharedArrayBuffer. Which was previously implemented in all major browsers, but was removed due to the Meltdown and Spectre attacks. Though, some major browsers have already started to re-enable this feature. The following cases that may be problemsome are:

  • Wasm modules that infinitely loop like wasm-matrix. They will block the main thread and freeze the browser.

  • Wasm modules that take in input from /dev/stdin such as lolcat. They will not take input from the shell. but instead, use window.prompt to get input. Since window.prompt can pause the execution of javascript on the main thread for synchronous reads.

Contributing

The project is split up around the relationship between a terminal, tty, and shell.

This project follows the all-contributors specification.

Contributions of any kind are welcome! πŸ‘