Skip to content

Commit a92bba6

Browse files
committed
Using bun for building native executables
As part of this move, knocking some stuff out, like: - Moving to ESM - Adding file extensions to all local imports - Emitting TypeScript types - Dropping some dependencies - Upgrading all dependencies to latest - Better build step that tests node, os, and arch matrix - Upgrading minimum supported node version - Running typescript, ts, esm, and es6 blocks with bun - Adding more tests - Running tests on both node and bun runtimes - Checking if CLI runs across node, tsx, bun, and native - Adding standardized output for file and command names - Pass-through exit code for a failed command - Fixing bug with repeated arg names - Adding support for passing the FORCE_INTERACTIVE env var - Using single log file with timestamps instead of timestamped file name - Using inspect instead of JSON stringify when logging - Logging trimmed command script content when running - Using minimist directly instead of yargs - Suggesting commands that have any word that matches user input - Allowing run logs to be silenced - Adding proper file extensions for all supported languages - Removing the need for chmod - Adding a custom-built inquirer plugin for searchable lists - Changes to log output, including suggestions
1 parent e503935 commit a92bba6

37 files changed

+3331
-4785
lines changed

.github/workflows/build.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
node:
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
matrix:
15+
node-version: [20.x, 22.x, 24.x]
16+
os: [ubuntu-latest, macos-latest, windows-latest]
17+
arch: [x64, arm64]
18+
exclude:
19+
- os: windows-latest
20+
arch: arm64
21+
- os: ubuntu-latest
22+
arch: arm64
23+
- os: macos-latest
24+
arch: x64
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-node@v4
28+
name: Use Node.js ${{ matrix.node-version }}
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
- run: npm ci
32+
- if: matrix.node-version == '20.x'
33+
run: node --test
34+
- if: matrix.node-version != '20.x'
35+
run: npm run test
36+
- run: node dist/cli.js ls
37+
- run: node bin/cli.cjs ls
38+
- run: node --import tsx/esm src/cli.ts ls
39+
- run: npx tsx src/cli.ts ls
40+
- run: npm link && runbook ls && r ls
41+
- run: npm install -g bun
42+
- run: bun test
43+
- run: bun run src/cli.ts -- ls
44+
- shell: bash
45+
run: |
46+
set -eoux pipefail
47+
platform="$(echo "${{ matrix.os }}" | sed -E 's/^ubuntu(-.*)?$/linux/; s/^macos(-.*)?$/darwin/; s/^windows(-.*)?$/windows/;')-${{ matrix.arch }}"
48+
binary="./exec/runbook-$platform"
49+
bun run "build:native:binaries:$platform"
50+
chmod +x "$binary"
51+
"$binary" ls

.github/workflows/test.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/node_modules/
22
/dist/
3-
/exec/
3+
/exec/

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"editor.insertSpaces": true,
33
"editor.tabSize": 2,
4+
"files.autoSave": "off",
45
"files.insertFinalNewline": true,
56
"git.inputValidation": true,
67
"git.inputValidationLength": 72,

DEVELOPERS.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,32 @@ This document is for developers working on the runbook application *itself*. If
88
>
99
> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/khalidx/runbook?quickstart=1)
1010
11-
To run without building first, use:
11+
First, install dependencies:
1212

13-
```bash "runbook ls"
14-
npx ts-node src/cli.ts ls # or any other runbook command
13+
```bash "install dependencies"
14+
npm install
15+
```
16+
17+
To run without building first, you can use `bun`:
18+
19+
```bash "install bun globally"
20+
npm install -g bun
21+
```
22+
23+
```bash "runbook ls with bun"
24+
bun run src/cli.ts -- ls # or any other runbook command
25+
```
26+
27+
Or, you can use `tsx`:
28+
29+
```bash "runbook ls with tsx"
30+
npx tsx src/cli.ts ls # or any other runbook command
1531
```
1632

1733
To quickly test while developing this package, run:
1834

1935
```bash "runbook run hello"
20-
npx ts-node src/cli.ts run hello --greeting Hey --name Batman
36+
bun run src/cli.ts -- run hello --greeting Hey --name Batman
2137
```
2238

2339
Alternatively, the package can be linked and run with the `DEV=true` environment variable to pick up the latest TypeScript source changes without the need to re-link the package.
@@ -27,6 +43,14 @@ npm link
2743
DEV=true runbook run hello --greeting Hey --name Batman
2844
```
2945

46+
When linked, you can use `runbook` and the shorter `r` commands right in the CLI, just like if you had installed the command globally via `npm`.
47+
48+
To build:
49+
50+
```bash "build"
51+
npm run build
52+
```
53+
3054
Here's some fun - using runbook to run runbook to run the raw TypeScript version of runbook to run the "hello" command.
3155

3256
```bash "runbook inception"
@@ -42,5 +66,9 @@ npm run test
4266
Here is a command that always fails (useful for seeing how runbook handles errors):
4367

4468
```bash "this will fail"
45-
exit 1
69+
runbook run this will fail --exitCode 1
70+
```
71+
72+
```bash hbs "this will fail"
73+
echo 'Failing with {{exitCode}}' && exit {{exitCode}}
4674
```

LIBRARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ runbook run generate password --length 20
3535
```
3636

3737
```javascript hbs "generate password"
38-
const { randomFillSync } = require('crypto')
38+
import { randomFillSync } from 'node:crypto'
3939

4040
const generatePassword = (
4141
length = {{ length }},

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Executable markdown documents that you can run, template, and share!
1010

1111
## quickstart
1212

13-
```bash "install"
13+
```bash "install from npm"
1414
npm install -g @khalidx/runbook
1515
```
1616

USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Currently, `runbook run` supports the execution of `bash`, `powershell`, `javasc
6666
- `bash` blocks are executed with `bash`
6767
- `powershell` and `ps1` blocks are executed with `pwsh` or `powershell.exe`
6868
- `javascript` and `js` blocks are executed with `node`
69-
- `typescript` and `ts` blocks are executed with `npx ts-node`
70-
- `esm` and `es6` blocks are executed with `node --loader ts-node/esm`
69+
- `typescript` and `ts` blocks are executed with `bun`
70+
- `esm` and `es6` blocks are executed with `bun`
7171
- `python` blocks are executed with `python`
7272
- `go` blocks are executed with `go`
7373

bin/cli.cjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
3+
if (process.env.DEV !== undefined) {
4+
const { resolve } = require('node:path')
5+
const { execFileSync } = require('node:child_process')
6+
const entrypoint = resolve(__dirname, '../src/cli.ts')
7+
try {
8+
execFileSync('bun', [ 'run', entrypoint, '--', ...process.argv.slice(2) ], { stdio: 'inherit' })
9+
} catch (error) {
10+
process.exitCode = error.status || 1
11+
}
12+
} else {
13+
require('../dist/cli.js')
14+
}

bin/cli.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)