Skip to content
arraynotherePublic

About

Zero-config TypeScript library & toolchain for any Environment

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

SudoType logo

SudoType

Zero-config TypeScript toolchain for any environment.
Run, build, scaffold and type-check TypeScript with a single command, or call the same features from your own code through a fully typed API.

version node platform runtime bundler license

Visit Repository View on npm Report an Issue

Installation · Quick Start · Commands · API · Templates · Structure · Troubleshooting · Windows · FAQ

Programs used by SudoType: tsx, esbuild, Node.js, TypeScript

Overview

Setting up TypeScript on a phone usually means writing a tsconfig.json by hand, installing a compiler, and fixing native binaries that do not match the device. SudoType wraps that into one CLI. It uses tsx to run files and esbuild to compile them. esbuild ships native android-arm64 binaries that work in Termux, and tsx runs on top of it.

Run without a build step
Execute .ts files directly, with watch mode.
Project scaffolding
Start from Express, Discord bot, CLI or basic templates.
Fast compile
Bundle to a single JavaScript file with esbuild.
Environment check
sudotype doctor reports what is missing.
Typed programmatic API
Import build, init, check and more from TypeScript.
Works anywhere
Termux, Linux, macOS and Windows on Node.js 20.12+.

Requirements

  • Node.js 20.12 or newer (the discord template uses process.loadEnvFile())
  • Termux (Android, ARM64), or any Linux / macOS / Windows machine with Node.js
  • git (optional, used by sudotype init)

Supported platforms

SudoType is plain JavaScript on top of esbuild and tsx, so it runs anywhere Node.js 20.12+ and esbuild run.

PlatformStatus
Termux (Android, ARM64)Primary target
Linux (x64, ARM64), WSL, Docker, Raspberry Pi, CodespacesSupported
Linux on Android (proot-distro, UserLAnd, Andronix)Supported
macOS (Intel, Apple Silicon)Supported
Windows (x64, ARM64)Supported (see Windows notes)
FreeBSD, OpenBSD, ChromeOS (Crostini)Should work, not tested
iOS (iSH, a-Shell)Not supported

CI runs the test suite on Ubuntu, macOS and Windows with Node.js 20, 22 and 24.

Installation

Termux (Android)

pkg update && pkg install nodejs git
npm install -g @arraynothere/sudotype

Linux / macOS / Windows

npm install -g @arraynothere/sudotype

The npm package is @arraynothere/sudotype, and the command it installs is sudotype.

Or run it without installing:

npx @arraynothere/sudotype doctor

As a library (to use the API in your own project)

npm install @arraynothere/sudotype

Update or remove it:

npm update -g @arraynothere/sudotype
npm uninstall -g @arraynothere/sudotype

Verify the setup:

sudotype --version
sudotype doctor

Why SudoType?

You can call tsx and esbuild directly, but you still have to wire up the tsconfig.json, the build flags, the project layout and the environment checks yourself. SudoType puts those behind one command and ships ready-made templates, so a fresh phone goes from zero to a running TypeScript project in a few commands.

Quick Start

1. Run a file

echo 'console.log("Hello from SudoType");' > hello.ts
sudotype run hello.ts

2. Create a project

sudotype init my-api --template express --install
cd my-api

3. Develop, check and build

sudotype watch src/index.ts     # restart on change
sudotype check                  # type-check
sudotype build src/index.ts     # output: dist/index.js

Commands

CommandDescription
sudotype run <file.ts> [args]Run a TypeScript file
sudotype watch <file.ts>Run and restart on file changes
sudotype build [entry]Bundle to JavaScript with esbuild
sudotype init [name]Scaffold a new project
sudotype checkType-check with tsc --noEmit
sudotype tsconfigWrite a ready-to-use tsconfig.json
sudotype doctorDiagnose the environment

run / watch

Arguments after the file name are passed to your program.

sudotype run src/index.ts --port 8080
sudotype watch src/index.ts

build

The entry file defaults to src/index.ts. Dependencies stay external unless --bundle-deps is set.

sudotype build                              # src/index.ts -> dist/index.js
sudotype build src/cli.ts --minify
sudotype build src/index.ts -f cjs -o out/app.cjs --sourcemap
sudotype build src/index.ts --bundle-deps   # single self-contained file
OptionDefaultDescription
-o, --out <file>dist/<name>.js (.cjs / .mjs when the format differs from "type")Output file
-f, --format <esm|cjs>from package.json "type"Output module format
--target <target>node20esbuild target
--minifyoffMinify the output
--sourcemapoffEmit a source map
--bundle-depsoffBundle node_modules into the output

init

Run it without arguments for an interactive prompt, or pass everything as flags.

sudotype init                                   # interactive
sudotype init my-bot -t discord --install       # flags only
sudotype init my-cli -t cli --no-git
OptionDescription
-t, --template <name>basic, express, discord or cli
-i, --installRun npm install after scaffolding
--no-gitSkip git init

check / tsconfig / doctor

sudotype check                  # requires typescript in the project
sudotype tsconfig               # fails if tsconfig.json exists
sudotype tsconfig --force       # overwrite
sudotype doctor                 # exit code 1 if a problem is found

Programmatic API

Everything the CLI does is also available as a typed API. The package ships its own type definitions, so no @types/* package is needed for SudoType itself (your project still needs @types/node, which TypeScript projects on Node.js normally have).

npm install @arraynothere/sudotype
import { build, check, doctor, init, listTemplates, SudoTypeError } from "@arraynothere/sudotype";

// Scaffold a project
const project = await init({ name: "my-api", template: "express", git: false });
console.log(project.directory);

// Bundle a file
const result = await build({ cwd: project.directory, entry: "src/index.ts", minify: true });
console.log(`${result.outfile} (${result.size} bytes in ${result.duration}ms)`);

// Type-check and capture the output
const { success, output } = await check({ cwd: project.directory, silent: true });
if (!success) console.error(output);

CommonJS works too:

const { build } = require("@arraynothere/sudotype");

Differences from the CLI:

  • API functions never call process.exit() and never print. They return a result or throw a SudoTypeError.
  • Paths are resolved against the cwd option (default process.cwd()).
  • build() is silent by default. Pass logLevel: "warning" to see esbuild warnings.
  • init() does not prompt. Interactive prompts exist only in the CLI.
  • Requires Node.js 20.12 or newer, like the CLI.

Functions

FunctionReturnsDescription
build(options?)Promise<BuildResult>Bundle a TypeScript entry file with esbuild
check(options?)Promise<CheckResult>Run tsc --noEmit with the project's TypeScript
doctor(options?)Promise<DoctorReport>Inspect the environment
init(options)Promise<InitResult>Scaffold a project from a template
listTemplates()TemplateInfo[]List the built-in templates
installDependencies(dir, options?)Promise<boolean>Run npm install in a directory
writeTsconfig(options?){ path: string }Write the recommended tsconfig.json
run(file, args?, options?)Promise<number>Run a file with tsx, resolves to the exit code
watch(file, args?, options?)Promise<number>Run a file and restart on changes
versionstringInstalled SudoType version
SudoTypeErrorclassError type thrown by every function

build(options?)

OptionTypeDefaultDescription
entrystring"src/index.ts"Entry file
outstringdist/<name>.jsOutput file
format"esm" | "cjs"from "type"Module format
targetstring"node20"esbuild target
minifybooleanfalseMinify the output
sourcemapbooleanfalseEmit a source map
bundleDepsbooleanfalseBundle node_modules
cwdstringprocess.cwd()Working directory
logLevel"silent" | "error" | "warning" | "info""silent"esbuild log level

Result: { entry, outfile, format, size, duration }. entry and outfile are absolute paths, size is in bytes and duration in milliseconds.

check(options?)

Option Type Default Description
cwd string process.cwd() Project directory
args string[] [] Extra arguments for tsc
silent boolean false Capture output in result.output instead of printing it

Result: { success, exitCode, output }. A project with type errors resolves with success: false. It only rejects when TypeScript is missing or cannot start.

doctor(options?)

const report = await doctor();
// {
//   platform: "linux", arch: "x64", termux: false,
//   ok: true, problems: 0,
//   checks: [{ id: "node", status: "ok", message: "Node.js v22.0.0" }, ...]
// }

Each check has an id (node, esbuild, tsx, typescript, git), a status (ok, warn or error), a message and an optional hint. Only error counts as a problem.

init(options)

Option Type Default Description
name string required Project and directory name
template "basic" | "express" | "discord" | "cli" "basic" Template to use
cwd string process.cwd() Parent directory
git boolean true Run git init
install boolean false Run npm install afterwards
silent boolean false Hide npm output

Result: { name, template, directory, installed }.

run / watch

import { run, watch } from "@arraynothere/sudotype";

const code = await run("src/index.ts", ["--port", "8080"]);

const controller = new AbortController();
const done = watch("src/index.ts", [], { signal: controller.signal });
controller.abort();          // stop watching
await done.catch(() => {});  // an aborted process rejects with code "ABORTED"
Option Type Default Description
cwd string process.cwd() Working directory
env NodeJS.ProcessEnv process.env Environment variables
stdio "inherit" | "pipe" | "ignore" "inherit" Child stdio
signal AbortSignal none Stops the process when aborted
onSpawn (child: ChildProcess) => void none Called with the child process after it starts

Error handling

Every function throws (or rejects with) a SudoTypeError. Branch on error.code, not on the message:

import { build, SudoTypeError } from "@arraynothere/sudotype";

try {
  await build({ entry: "src/missing.ts" });
} catch (err) {
  if (err instanceof SudoTypeError && err.code === "ENTRY_NOT_FOUND") {
    console.error(err.message);
  } else {
    throw err;
  }
}
CodeThrown byMeaning
ENTRY_NOT_FOUNDbuildThe entry file does not exist
ESBUILD_UNAVAILABLEbuildesbuild failed to load (run doctor)
INVALID_FORMATbuildformat is not "esm" or "cjs"
BUILD_FAILEDbuildesbuild reported errors (see error.cause)
TYPESCRIPT_NOT_INSTALLEDcheckThe project has no typescript package
INVALID_NAMEinitMissing or invalid project name
UNKNOWN_TEMPLATEinitThe template does not exist
DIRECTORY_NOT_EMPTYinitThe target directory already has files
TEMPLATE_MISSINGinitTemplate files are missing, reinstall SudoType
TSCONFIG_EXISTSwriteTsconfigtsconfig.json exists and force is not set
FILE_NOT_FOUNDrun, watchThe file does not exist
INVALID_ARGUMENTrun, watchNo file was given
TSX_NOT_FOUNDrun, watchtsx is missing, reinstall SudoType
SPAWN_FAILEDcheck, run, watchThe child process could not start
ABORTEDrun, watchThe signal option aborted the process

TypeScript configuration

SudoType's types use the exports field, so use a modern module resolution mode:

{
  "compilerOptions": {
    "module": "Node16",
    "moduleResolution": "Node16"
  }
}

"moduleResolution": "Bundler" works as well. The generated tsconfig.json from sudotype tsconfig already uses a compatible setup. All types (BuildOptions, BuildResult, CheckResult, DoctorReport, InitOptions, RunOptions, TemplateName, ...) are exported:

import type { BuildOptions, DoctorReport } from "@arraynothere/sudotype";

Templates

TemplateDescriptionExtra dependencies
basicMinimal TypeScript projectnone
expressREST API server listening on PORT (default 3000)express
discordDiscord bot with a /ping slash commanddiscord.js v14
cliCommand-line app using node:util parseArgsnone

Every generated project includes these scripts, so the global sudotype command must be installed:

npm start         # sudotype run src/index.ts
npm run dev       # sudotype watch src/index.ts
npm run build     # sudotype build src/index.ts --minify
npm run check     # sudotype check

The Discord template reads DISCORD_TOKEN and CLIENT_ID from .env:

cp .env.example .env            # fill in the values
sudotype run src/deploy-commands.ts
sudotype run src/index.ts

Project Structure

Generated project

my-api/
├── src/
│   └── index.ts
├── .env.example        (express, discord)
├── .gitignore
├── package.json
├── README.md
└── tsconfig.json

The discord template also contains src/deploy-commands.ts.

This repository

sudotype/
├── bin/
│   └── sudotype.js         CLI entry point
├── src/
│   ├── index.js            programmatic API entry (package "main")
│   ├── index.d.ts          type definitions for the API
│   ├── errors.js           SudoTypeError
│   ├── core/               API implementation (no printing, no process.exit)
│   ├── cli.js              command dispatcher
│   ├── utils.js            shared helpers
│   └── commands/           CLI adapters: run, build, init, check, tsconfig, doctor
├── templates/              basic, express, discord, cli
├── test/
│   ├── smoke.test.js       CLI tests
│   ├── api.test.js         programmatic API tests
│   └── types/              type-definition tests (tsc)
├── assets/                 README badges and graphics
├── CHANGELOG.md
├── CONTRIBUTING.md
├── icon/                   project icons
├── tsconfig.base.json
└── package.json

Troubleshooting

esbuild fails to start
pkg upgrade
npm install -g @arraynothere/sudotype --force
sudotype doctor
Node.js version is too old
pkg upgrade nodejs
node --version      # must be 20.12 or newer
sudotype check says TypeScript is not installed

check uses the TypeScript version of the current project:

npm install -D typescript @types/node
The Discord template says Missing DISCORD_TOKEN but my .env is filled in

process.loadEnvFile() needs Node.js 20.12 or newer. Check with node --version and upgrade if needed.

command not found: sudotype
npm config get prefix           # the bin folder must be in PATH
npm install -g @arraynothere/sudotype

Windows notes

  • Use PowerShell, Command Prompt or WSL. All commands work the same way.
  • sudotype init --install runs npm.cmd through the shell, so Node.js must be on your PATH.
  • Press Ctrl+C to stop run and watch.

FAQ

Why not Bun?
Bun does not run natively on Termux because it needs glibc. tsx and esbuild work on Android (Bionic) without extra layers.
Does it work outside Termux?
Yes. SudoType runs on any system with Node.js 20.12 or newer, including Linux, macOS and Windows. See Supported platforms.
Can I use SudoType from my own code?
Yes. npm install @arraynothere/sudotype and import the functions, see the Programmatic API. The CLI is a thin layer on top of the same functions.
Do I need to install tsx or esbuild myself?
No. Both are dependencies of SudoType. check is the exception: it uses the typescript package of your own project.

Contributing

git clone https://github.com/arraynothere/sudotype.git
cd sudotype
npm install
npm test              # CLI and API tests
npm run test:types    # type definitions
node bin/sudotype.js doctor

Pull requests and issues are welcome at github.com/arraynothere/sudotype. Maintainers: see CONTRIBUTING.md for the release process.

Changelog

See CHANGELOG.md for release notes.

License

Released under the MIT License.


Made by Array

About

Zero-config TypeScript library & toolchain for any Environment

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages