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

@d8d-webcontainer/server

v1.0.12

Published

Server implementation for D8D WebContainer

Downloads

672

Readme

@d8d-webcontainer/server

D8D WebContainer 的服务器端实现。

安装

# 全局安装
npm install -g @d8d-webcontainer/server
# 或者作为项目依赖安装
npm install @d8d-webcontainer/server

快速开始

使用 npx 运行

最简单的方式是使用 npx 直接运行:

npx @d8d-webcontainer/server

全局安装后运行

如果已全局安装,可以直接运行:

d8d-webcontainer-server

配置选项

服务器可以通过环境变量进行配置:

  • PORT: 服务器端口号 (默认: 3000)
  • HOST: 服务器主机地址 (默认: localhost)
  • WORKSPACE_ROOT: 工作区根目录 (默认: ./workspaces)

示例:

# 自定义端口和主机
PORT=8080 HOST=0.0.0.0 npx @d8d-webcontainer-server
# 自定义工作区目录
WORKSPACE_ROOT=/path/to/workspaces npx @d8d-webcontainer-server

作为依赖使用

也可以在代码中引入使用:

import { WebContainerServer } from "@d8d-webcontainer/server";
const server = new WebContainerServer({
  port: 3000,
  host: "localhost",
  workspaceRoot: "./workspaces",
});
server.start();

API 参考

WebContainerServer

构造函数

new WebContainerServer(config: WebContainerServerConfig)

配置选项:

  • port: 服务器端口号 (可选,默认: 3000)
  • host: 服务器主机地址 (可选,默认: 'localhost')
  • workspaceRoot: 工作区根目录 (可选,默认: './workspaces')

方法

start()

启动服务器。

返回值: void

事件

服务器会通过 Socket.IO 发送以下事件:

server-ready

当开发服务器就绪时触发,包含以下信息:

interface ServerReadyEvent {
  port: number; // 服务器端口
  url: string; // 可访问的 URL(通过隧道)
  localUrl?: string; // 本地 URL
}

process:output

当进程有输出时触发,包含以下信息:

interface ProcessOutput {
  type: "stdout" | "stderr" | "exit"; // 输出类型
  data: string; // 输出内容
}

文件系统 API

服务器提供以下文件系统操作:

  • fs:list: 列出目录内容
  • fs:read: 读取文件内容
  • fs:write: 写入文件内容
  • fs:delete: 删除文件或目录
  • fs:mkdir: 创建目录
  • fs:watch: 监听文件变化

许可证

MIT