This commit is contained in:
Raven Scott
2026-02-19 18:08:31 -05:00
parent c5ed79276c
commit 44fd48c9cc
31 changed files with 2307 additions and 341 deletions
+66 -7
View File
@@ -1,19 +1,78 @@
# bare-boot - Boot Drive Loader
# bare-boot
Boot and execute a Bare module from a drive.
## Install
```sh
npm i bare-boot
```
## Overview
**bare-boot** boots drives in the Bare runtime. It provides the mechanism for loading and initializing Bare applications from various drive sources.
`bare-boot` bundles an entry file from a drive and loads it using `bare-module`. It is a minimal bootstrap helper for drive-based apps.
## Usage
## Architecture
```mermaid
flowchart TD
A[Drive] --> B[bare-pack-drive]
B --> C[Bundle]
C --> D[bare-module]
D --> E[module.exports]
```
## API
### `boot(drive, entry = '/index.js', opts = {})`
- **drive** Drive-like object (supports pack resolution)
- **entry** entry file path
- **opts.host** custom host for bundling
- **returns** `module.exports` from the entry bundle
## Examples
### Boot default entry
```js
const boot = require('bare-boot')
const app = await boot(drive)
```
### Boot custom entry
```js
const app = await boot(drive, '/main.js')
```
### Boot with host override
```js
await boot(drive, '/index.js', { host: 'pear' })
```
## Best Practices
- Keep entrypoints small and defer heavy imports.
## Performance
- Bundling adds startup cost; cache bundles if reused.
## Security
- Only boot trusted drives.
## Error Handling
- Catch errors from bundling or module loading.
## Integration
- Used in Bare runtime bootstraps and pack flows.
## License
Apache-2.0
---
**Module Type**: Core Runtime | **Ecosystem Role**: Application Bootstrapping | **Used With**: Bare
+70 -7
View File
@@ -1,19 +1,82 @@
# bare-dev - Development Tooling for Bare
# bare-dev
Development tooling modules for the Bare runtime.
## Install
```sh
npm i bare-dev
```
## Overview
**bare-dev** provides development tooling for the Bare JavaScript runtime. It includes utilities for debugging, testing, and developing Bare applications.
`bare-dev` is a collection of build, bundle, test, and platform helper modules used for developing Bare apps. It exposes submodules for Android/iOS, dependencies, and drive workflows.
## Usage
## API
### Exports
- `android`
- `build`
- `bundle`
- `clean`
- `configure`
- `dependencies`
- `drive`
- `init`
- `install`
- `ios`
- `paths`
- `test`
- `vendor`
## Examples
### Access build helpers
```js
const dev = require('bare-dev')
await dev.build.run({ release: true })
```
### Bundle an app
```js
const dev = require('bare-dev')
await dev.bundle.create({ entry: 'index.js' })
```
### Configure platform
```js
const dev = require('bare-dev')
await dev.configure.apply({ platform: 'ios' })
```
## Best Practices
- Use platform helpers (`android`, `ios`) to ensure correct build steps.
- Cache dependencies to speed up builds.
## Performance
- Build steps are CPU and I/O heavy; use incremental builds where possible.
## Security
- Avoid embedding secrets in build artifacts.
## Error Handling
- Each submodule may throw on misconfiguration; surface errors clearly.
## Integration
- Used by Bare CLI and runtime tooling.
## License
Apache-2.0
---
**Module Type**: Dev Tool | **Ecosystem Role**: Development Utilities | **Part Of**: Bare Ecosystem
+91 -11
View File
@@ -1,26 +1,106 @@
# bare-http1 - HTTP/1.x Parser/Server
# bare-http1
HTTP/1 client and server implementation for Bare.
## Install
```sh
npm i bare-http1
```
## Overview
**Stable** Low-level HTTP/1 server/request. Streams req/res headers/body.
`bare-http1` provides a Node-like `http` API built on Bare primitives. It includes request/response classes, agents, and server/client helpers.
## Usage
## Architecture
```mermaid
flowchart TD
A[ClientRequest] --> B[ClientConnection]
C[Server] --> D[ServerConnection]
B & D --> E[bare-tcp]
```
## API
### Classes
- `IncomingMessage`
- `OutgoingMessage`
- `Agent` (`globalAgent`)
- `Server`, `ServerResponse`, `ServerConnection`
- `ClientRequest`, `ClientConnection`
### Functions
- `createServer(opts?, onrequest?)`
- `request(url|options, opts?, onresponse?)`
- `get(url|options, opts?, onresponse?)`
### Constants
- `constants` and `errors`
- `METHODS` and `STATUS_CODES` (Node compatibility)
## Examples
### Basic server
```js
const http = require('bare-http1')
http.createServer((req, res) => {
const server = http.createServer((req, res) => {
res.statusCode = 200
res.end('Hi!')
}).listen(3000)
res.setHeader('Content-Length', 5)
res.end('hello')
})
server.listen(0)
```
Client: http.request({port}, res => res.on('data', ...))
### Client request
**Parser**: Strict RFC, chunked TE.
```js
const http = require('bare-http1')
**Deps**: bare-tcp/stream.
const req = http.request({ host: '127.0.0.1', port: 8080, path: '/' }, (res) => {
res.on('data', (buf) => console.log(buf.toString()))
})
req.end()
```
**P2P**: Proxy via hyperswarm? Pear web bridge.
### GET helper
**Source**: github/holepunchto/bare-http1
```js
http.get('http://localhost:8080', (res) => {
res.on('data', (buf) => console.log(buf.toString()))
})
```
## Best Practices
- Use `Agent` for connection reuse when issuing many requests.
- Set `Content-Length` or use chunked transfer as needed.
## Performance
- Reusing connections via `Agent` reduces latency.
- Throughput depends on `bare-tcp` buffer sizes.
## Security
- Validate request inputs; HTTP/1 is plaintext.
- Use `bare-https` for encrypted traffic.
## Error Handling
- Handle `error` events on requests and responses.
- Invalid URLs throw synchronously in `request`.
## Integration
- Built on `bare-tcp` and used by `bare-https`.
## License
Apache-2.0
+90 -7
View File
@@ -1,18 +1,101 @@
# bare-https - TLS Streams
# bare-https
HTTPS client and server for Bare, layered over TLS.
## Install
```sh
npm i bare-https
```
## Overview
**Stable** bare-tls wrapper for HTTPS. Server/client w/ certs.
`bare-https` provides a Node-like HTTPS API (server + request) for Bare runtimes. It wraps TLS and HTTP/1 primitives to support secure connections.
**Ex**:
## Architecture
```mermaid
flowchart TD
A[HTTPS Request] --> B[ClientRequest]
B --> C[TLS]
C --> D[bare-tcp]
```
## API
### Classes
- `Agent` (`globalAgent`)
- `Server`
- `ClientRequest`
### Functions
- `createServer(opts?, onrequest?)`
- `request(url|options, opts?, onresponse?)`
### Options
- TLS options like `key`, `cert`, `ca`, and related fields (passed to TLS layer).
## Examples
### HTTPS server
```js
const fs = require('fs')
const https = require('bare-https')
const server = https.createServer({
key: fs.readFileSync('server.key'),
cert: fs.readFileSync('server.crt')
}, (req, res) => {
res.statusCode = 200
res.end('secure')
})
server.listen(0)
```
### HTTPS client
```js
const https = require('bare-https')
https.createServer({ key, cert }, (req, res) => res.end('Secure!')).listen(443)
const req = https.request({ host: '127.0.0.1', port: 8443, path: '/' }, (res) => {
res.on('data', (buf) => console.log(buf.toString()))
})
req.end()
```
**Integr**: bare-tcp + bare-tls + bare-http1.
### Custom agent
**Pear**: Local HTTPS bridge for electron.
```js
const https = require('bare-https')
const agent = new https.Agent({ keepAlive: true })
```
**Source**: github/holepunchto/bare-https
## Best Practices
- Provide valid `key`/`cert` pairs and rotate periodically.
- Use `Agent` for connection reuse in clients.
## Performance
- TLS handshake adds overhead; reuse connections when possible.
## Security
- Validate certificates and avoid disabling verification in production.
## Error Handling
- Handle `error` events on `ClientRequest` and `Server`.
## Integration
- Built on `bare-http1` + TLS + `bare-tcp`.
## License
Apache-2.0
+103 -19
View File
@@ -1,28 +1,112 @@
# bare-os v3.6.2 - OS Utilities
# bare-os
Operating system utilities for Bare.
## Install
```sh
npm i bare-os
```
## Overview
**Stable** Platform info/constants/errors. Native bindings.
```js
const os = require('bare-os')
console.log(os.platform()) // 'linux'/'darwin'/'win32'/'android'/'ios'
console.log(os.arch()) // 'arm64' etc.
console.log(os.homedir())
console.log(os.tmpdir())
```
`bare-os` exposes OS metadata, process info, resource usage, and environment access through native bindings, mirroring parts of Node's `os` and `process` APIs.
## API
- `platform()`, `arch()`, `release()`
- `homedir()`, `tmpdir()`, `userInfo()`
- `cpus()`, `freemem()`, `totalmem()`
- `networkInterfaces()`
- `constants`: signals, errno
- `errors`: errno → Error
### Platform info
**Addon** w/ CMake prebuilds.
- `platform()`
- `arch()`
- `type`, `version`, `release`, `machine`
- `endianness()`
- `availableParallelism`
**Use**: Path selection, resource limits, in Pear appdirs.
### Process info
**Source**: [github/holepunchto/bare-os](https://github.com/holepunchto/bare-os)
- `execPath`, `pid`, `ppid`
- `cwd()`, `chdir(path)`
- `getProcessTitle()`, `setProcessTitle(title)`
### User and host
- `homedir()`, `tmpdir()`, `hostname()`, `userInfo()`
### Resource usage
- `cpuUsage([previous])`
- `threadCpuUsage([previous])`
- `resourceUsage()`
- `memoryUsage()`
- `freemem()`, `totalmem()`, `loadavg()`, `uptime()`
- `cpus()`
### Environment
- `getEnvKeys()`
- `getEnv(key)`
- `hasEnv(key)`
- `setEnv(key, value)`
- `unsetEnv(key)`
### Signals
- `kill(pid, signal)`
### Constants and errors
- `constants` (signals, errno, etc.)
- `errors`
## Examples
### Platform summary
```js
const os = require('bare-os')
console.log(os.platform(), os.arch(), os.release)
```
### CPU usage delta
```js
const os = require('bare-os')
const start = os.cpuUsage()
setTimeout(() => {
console.log(os.cpuUsage(start))
}, 1000)
```
### Update process title
```js
os.setProcessTitle('pear-worker')
```
## Best Practices
- Clamp process titles to <256 chars to avoid errors.
- Use `cpuUsage(previous)` for deltas instead of manual tracking.
## Performance
- Most calls are native and fast; avoid high-frequency polling if not needed.
## Security
- Limit exposure of environment variables.
## Error Handling
- `kill` throws for unknown signals.
- `setProcessTitle` throws if title is too long.
## Integration
- Used by Bare platform tooling and runtime diagnostics.
## License
Apache-2.0
+67 -21
View File
@@ -1,34 +1,80 @@
# bare-path v3.0.0 - Path Utils
# bare-path
Path utilities for Bare with POSIX/Win32 implementations.
## Install
```sh
npm i bare-path
```
## Overview
**Stable** Pure-JS path normalization/join/resolve. POSIX/Win32 backends.
`bare-path` mirrors Node's `path` API. It selects POSIX or Win32 behavior based on the runtime platform.
## API
Common functions:
- `join(...parts)`
- `resolve(...parts)`
- `normalize(path)`
- `isAbsolute(path)`
- `relative(from, to)`
- `dirname(path)`
- `basename(path, ext?)`
- `extname(path)`
- `parse(path)`
- `format(obj)`
Constants:
- `sep`, `delimiter`
## Examples
### Join and resolve
```js
const path = require('bare-path') // auto-selects posix/win32
const path = require('bare-path')
const file = path.join('/app', 'data', 'db')
const abs = path.resolve('..', 'app')
```
## API Table
| Method | Example |
|--------|---------|
| `join(...parts)` | `path.join('/foo','bar') → '/foo/bar'` |
| `resolve(...parts)` | Abs path |
| `dirname(p)` | Parent dir |
| `basename(p,ext?)` | Filename |
| `extname(p)` | '.ext' |
| `normalize(p)` | Clean ../.. |
| `sep` | '/' or '\\' |
**Usage**:
### Parse and format
```js
const basedir = '/app/data'
const file = path.join(basedir, 'hypercore.db')
const info = path.parse('/tmp/file.txt')
const out = path.format(info)
```
**Deps**: bare-os (platform detect)
### Relative paths
**Interconnect**: Essential for bare-fs, bare-url, app bundling.
```js
path.relative('/a/b', '/a/b/c') // 'c'
```
**Source**: [github/holepunchto/bare-path](https://github.com/holepunchto/bare-path)
## Best Practices
- Use `path.posix` or `path.win32` for deterministic behavior.
## Performance
- String operations are fast; avoid excessive path manipulation in hot loops.
## Security
- Normalize and validate user-supplied paths to prevent traversal.
## Error Handling
- Functions are pure and do not throw for typical inputs.
## Integration
- Used by Bare filesystem and module loaders.
## License
Apache-2.0
+139 -1
View File
@@ -1 +1,139 @@
# Bare TCP\n\nNative TCP sockets for JavaScript in Bare runtime.\n\nUpdated Feb 19, 2026.\n\nRepo: [github.com/holepunchto/bare-tcp](https://github.com/holepunchto/bare-tcp)
# bare-tcp
Native TCP sockets for the Bare runtime with a Node-like API.
## Install
```sh
npm i bare-tcp
```
## Overview
`bare-tcp` exposes `Socket` and `Server` classes plus convenience helpers (`createConnection`, `createServer`). It mirrors the Node `net` module API where possible while being implemented on top of Bare native bindings.
## Architecture
```mermaid
flowchart TD
A[User Code] --> B[Socket/Server]
B --> C[bare-tcp binding]
C --> D[OS TCP stack]
```
## API
### `new Socket(options)`
- `options.readBufferSize` (default `65536`)
- `options.allowHalfOpen` (default `true`)
- `options.eagerOpen` (default `true`)
### `socket.connect(port, host?, opts?, onconnect?)`
- `opts.lookup` (default `bare-dns.lookup`)
- `opts.family`, `opts.hints`
- `opts.keepAlive`, `opts.keepAliveInitialDelay`
- `opts.noDelay`
- `opts.timeout`
### Socket methods
- `setKeepAlive(enable, delay)`
- `setNoDelay(enable)`
- `setTimeout(ms, ontimeout?)`
- `ref()` / `unref()`
### Socket properties
- `connecting`, `pending`, `readyState`, `timeout`
- `localAddress`, `localPort`, `localFamily`
- `remoteAddress`, `remotePort`, `remoteFamily`
### `new Server(options, onconnection?)`
- `options.readBufferSize`
- `options.allowHalfOpen`
- `options.keepAlive`, `options.keepAliveInitialDelay`
- `options.noDelay`
- `options.pauseOnConnect`
### Server methods
- `listen(port?, host?, backlog?, opts?, onlistening?)`
- `close(onclose?)`
- `ref()` / `unref()`
- `address()`
### Server properties
- `listening`, `closing`, `connections`
### Helpers
- `createConnection(port, host?, opts?, onconnect?)`
- `createServer(opts?, onconnection?)`
- `connect` (alias of `createConnection`)
- `isIP`, `isIPv4`, `isIPv6`
## Examples
### Create a TCP server
```js
const tcp = require('bare-tcp')
const server = tcp.createServer((socket) => {
socket.on('data', (buf) => socket.write(buf))
})
server.listen(0, () => {
const { port } = server.address()
console.log('listening', port)
})
```
### Connect a client
```js
const tcp = require('bare-tcp')
const socket = tcp.createConnection(1234, '127.0.0.1')
socket.on('connect', () => socket.write('ping'))
```
### Enable keep-alive and timeout
```js
socket.setKeepAlive(true, 10_000)
socket.setTimeout(5_000, () => socket.destroy())
```
## Best Practices
- Use `setNoDelay(true)` for latency-sensitive traffic.
- Use `pauseOnConnect` when you need to attach handlers before reading.
- Always handle `error` and `close` to avoid leaks.
## Performance
- Read buffer size affects throughput and memory use.
- Aggregated DNS lookup results are tried in order for robust connect behavior.
## Security
- Validate remote input; TCP is unframed and untrusted.
- Use TLS (`bare-https`/`bare-tls`) for encrypted traffic.
## Error Handling
- `createServer.listen` throws if already listening or closed.
- DNS lookup errors are emitted as `lookup` and can fail connection.
## Integration
- Used by `bare-http1`, `bare-https`, and other network stacks.
## License
Apache-2.0