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

@context-fs/cli

v0.1.4

Published

Generic CLI runner for @context-fs virtual filesystems

Downloads

32

Readme

@context-fs/cli

Generic CLI runner framework for creating command-line tools that serve @context-fs/core virtual filesystems.

Installation

npm install @context-fs/cli

Quick Start

#!/usr/bin/env node
import { run } from "@context-fs/cli";
import { createFileSystem, read } from "@context-fs/core";

await run({
  name: "My VFS",

  async createVfs({ values, positionals }) {
    return createFileSystem({
      "hello.txt": {
        [read]: () => "Hello, world!",
      },
    });
  },

  examples: ({ mountPoint }) => [`cat "${mountPoint}/hello.txt"`],
});

API

run(options)

Main entry point for CLI tools. Handles argument parsing, server setup, mounting, and graceful shutdown.

interface RunOptions<TExtraValues> {
  // Display name for help and status messages
  name: string;

  // Factory function to create the VFS
  createVfs: (
    args: RunArgs<TExtraValues>,
  ) => Promise<VirtualFileSystem> | VirtualFileSystem;

  // Additional parseArgs options for custom flags
  options?: ParseArgsConfig["options"];

  // Default values for host, port, exportName
  defaults?: {
    host?: string;
    port?: number;
    exportName?: string;
  };

  // Example commands to show after mounting
  examples?: (ctx: { mountPoint: string }) => string[];
}

Built-in Flags

| Flag | Description | Default | | --------------------- | --------------------- | ------------- | | --mount <path> | Mount point directory | (server only) | | --host <host> | Server bind address | 127.0.0.1 | | --port <port> | Server port | 2049 | | --exportName <name> | NFS export name | / | | -h, --help | Show help message | |

Custom Flags

Add custom flags via the options parameter:

await run<{ apiKey?: string; verbose?: boolean }>({
  name: "My API VFS",

  options: {
    apiKey: { type: "string", short: "k" },
    verbose: { type: "boolean", short: "v" },
  },

  async createVfs({ values }) {
    const apiKey = values.apiKey ?? process.env.API_KEY;
    if (!apiKey) throw new Error("API key required");

    if (values.verbose) {
      console.log("Verbose mode enabled");
    }

    return createFileSystem({
      /* ... */
    });
  },
});

Positional Arguments

Access positional arguments via positionals:

await run({
  name: "File Browser",

  async createVfs({ positionals }) {
    const [rootPath] = positionals;
    if (!rootPath) throw new Error("Root path required");

    return createFileSystem({
      /* ... */
    });
  },

  examples: ({ mountPoint }) => [`ls "${mountPoint}"`],
});

// Usage: my-cli /path/to/root --mount /tmp/browser

Behavior

Server Mode (no --mount)

When --mount is not provided, the CLI starts an NFS server without mounting:

$ my-cli --port 2049
My VFS running on 127.0.0.1:2049

Mount with:
  sudo mount -t nfs -o port=2049,mountport=2049,vers=3,tcp,nolocks 127.0.0.1:/ /mnt/point

Press Ctrl+C to stop

Mount Mode (with --mount)

When --mount is provided, the CLI mounts the filesystem and shows example commands:

$ my-cli --mount /tmp/my-vfs
My VFS mounted at /tmp/my-vfs

Try:
  cat "/tmp/my-vfs/hello.txt"

Press Ctrl+C to unmount

Graceful Shutdown

The CLI handles SIGINT (Ctrl+C) and SIGTERM for clean shutdown, automatically unmounting if needed.

Complete Example

#!/usr/bin/env node
import { run } from "@context-fs/cli";
import { createFileSystem, read, list } from "@context-fs/core";

interface CliValues {
  token?: string;
  refresh?: boolean;
}

await run<CliValues>({
  name: "GitHub VFS",

  defaults: {
    port: 2049,
  },

  options: {
    token: {
      type: "string",
      short: "t",
      description: "GitHub API token",
    },
    refresh: {
      type: "boolean",
      short: "r",
      description: "Refresh cache on start",
    },
  },

  async createVfs({ values }) {
    const token = values.token ?? process.env.GITHUB_TOKEN;
    if (!token) {
      throw new Error("GitHub token required (--token or GITHUB_TOKEN)");
    }

    if (values.refresh) {
      console.log("Refreshing cache...");
    }

    return createFileSystem({
      repos: {
        ":owner": {
          ":repo": {
            [list]: async () => {
              // Fetch repos...
              return [{ owner: "octocat", repo: "Hello-World" }];
            },
            "README.md": {
              [read]: async (c) => {
                // Fetch README...
                return `# ${c.params.repo}`;
              },
            },
          },
        },
      },
    });
  },

  examples: ({ mountPoint }) => [
    `ls "${mountPoint}/repos/octocat"`,
    `cat "${mountPoint}/repos/octocat/Hello-World/README.md"`,
  ],
});

Related Packages

License

MIT