MCPcopy Index your code
hub / github.com/Minigugus/bazx

github.com/Minigugus/bazx @0.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.1.0 ↗ · + Follow
485 symbols 593 edges 10 files 26 documented · 5%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

BAZX

🐚️ zx on 💊️ steroids

asciicast

Main differences with ZX

  • Written from scratch
  • 0 dependencies by default
  • Plateform-agnostic (not limited to Deno or NodeJS)
  • Extensible (enables remote command execution and thus browser support)
  • Streams at the core for better performances (no streaming support with zx)
  • Tree-shakable (usefull for bundling)
  • Modern (TypeScript, Deno, ES2020)
  • MIT vs Apache license
  • Library only

Streams

Unlike zx, bazx doesn't gather outputs into possibly big strings by default. The main reason for that is to avoid out of memory, especially on embedded devices and with "loud" commands (for instance, await $`yes`; with zx will crash the process, but not with bazx).

Support

  • Deno: 🐥️ (working)
  • NodeJS: 🥚️ (not started yet)
  • QuickJS: 🥚️ (not started yet)
  • Browser: 🥚️ (not started yet)

Setup

Deno

import { $ } from 'https://deno.land/x/bazx/mod.ts';

As of now, only the --allow-run command is required at runtime.

(Bring Your Own Runtime)

import { create } from 'https://deno.land/x/bazx/index.ts'; // `index.ts` is isomorphic, `mod.ts` is Deno only

const $ = create({
  exec(
    cmd: [string, ...string[]],
    streams: {
      stdin: ReadableStream<Uint8Array>,
      stdout: WritableStream<Uint8Array>,
      stderr: WritableStream<Uint8Array>
    }
  ): PromiseLike<{ success: boolean, code: number }> {
    // Insert runtime-dependant code here
  }
}, { /* Default options */ });

Usage

See the test folder

The $ tagged template function

Prepare a command. The process will spawn only when the returned object will be awaited (then called). The returned object as stdin, stdout and stderr properties, that are streams the user can use to communicated with the process. Also, it is possible to call the pipe(cmdOrTransfertStream: NativeCommand | PipeCommand | TransformStream) function to pipe the this command into the provided cmdOrTransfertStream stream, or to stdin stream of the provided command.

$`echo Never called`; // (never executed - missing `await`)

await $`echo Hi!`; // $ echo Hi!

const cmd = $`echo Only invoked once`;
(await cmd) === (await cmd); // => true

await $`env`.pipe($`grep PATH`); // $ env | grep PATH

The $ function can be obtained using the create function, or from a third party module that wrap this function. For instance, the deno.ts module expose a createDeno function, which is a wrapper function around create.

See test/debug.js for a pratical overview.

stdout, stderr and collect exports

Utilities to read respectively stdout, stderr and both from the command passed as argument:

console.log(await stdout($`echo Hello world!`));

// => { success: true, code: 0, stdout: "Hello world!" }

WIP

This project is work in progress for now; bugs and API change are expected.

Please fill an issue for any bug you encounter and open a discussion for any question or enhancement. :wink:

TODO

  • [ ] Rollup for NodeJS and browser builds
  • [ ] Improve docs
  • [ ] Add more runtime support (NodeJS at least)
  • [ ] Fix bugs (some complex use case doesn't work yet)

FAQ

Why is it called bazx?

Just like bash built from sh, there should be a bazx built from zx 😁️

How do you prononce bazx?

Just like basic but with a x instead of a c at the end: basix

License

Inspired by zx

MIT License

Copyright 2021 Minigugus

Extension points exported contracts — how you extend this code

GPUObjectBase (Interface)
(no doc) [19 implementers]
deno.d.ts
Bazx (Interface)
(no doc)
src/mod.ts
ExecutionResult (Interface)
(no doc)
src/bazx.ts
GPUProgrammablePassEncoder (Interface)
(no doc) [3 implementers]
deno.d.ts
BazxConfig (Interface)
(no doc)
src/mod.ts
BazxContext (Interface)
(no doc)
src/bazx.ts
Reader (Interface)
(no doc) [2 implementers]
deno.d.ts
BazxOptions (Interface)
(no doc)
src/mod.ts

Core symbols most depended-on inside this repo

$
called by 17
src/mod.ts
close
called by 10
deno.d.ts
pipeTo
called by 7
deno.d.ts
write
called by 5
deno.d.ts
enqueue
called by 4
deno.d.ts
collectAsString
called by 4
src/utils.ts
log
called by 3
deno.d.ts
read
called by 2
deno.d.ts

Shape

Interface 168
Class 153
Method 125
Function 38
Enum 1

Languages

TypeScript100%

Modules by API surface

deno.d.ts412 symbols
src/bazx.ts40 symbols
src/mod.ts13 symbols
deno.ts11 symbols
src/utils.ts4 symbols
test/showcase.js3 symbols
test/debug.js2 symbols

For agents

$ claude mcp add bazx \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact