Set up basic functionality for bun

This commit is contained in:
Timothy Warren 2023-10-31 14:47:59 -04:00
parent fba91bde10
commit 103cd1ecf6
3 changed files with 22 additions and 2 deletions

View File

@ -9,6 +9,10 @@ deno-lint:
# Code linting with bun # Code linting with bun
bun-lint: bun-lint:
# Run with bun
bun-run:
bun run ./src/scroll.ts
# Run with deno # Run with deno
deno-run: deno-run:
deno run --allow-all --allow-ffi --deny-net --deny-hrtime --unstable ./src/scroll.ts deno run --allow-all --allow-ffi --deny-net --deny-hrtime --unstable ./src/scroll.ts

15
src/bun/index.ts Normal file
View File

@ -0,0 +1,15 @@
/**
* The main entrypoint when using Deno as the runtime
*/
export async function main(): Promise<number> {
const decoder = new TextDecoder();
for await (const chunk of Bun.stdin.stream()) {
const char = String(decoder.decode(chunk)).trim();
if (char === 'q') {
return 0;
}
}
return -1;
}

View File

@ -15,10 +15,11 @@ export enum RunTime {
let RUNTIME = RunTime.Unknown; let RUNTIME = RunTime.Unknown;
if ('Deno' in globalThis) { if ('Deno' in globalThis) {
RUNTIME = RunTime.Deno; RUNTIME = RunTime.Deno;
const { main } = await import('./deno/index.ts');
await main();
} }
if ('Bun' in globalThis) { if ('Bun' in globalThis) {
RUNTIME = RunTime.Bun; RUNTIME = RunTime.Bun;
} }
const { main } = await import(`./${RUNTIME}/index.ts`);
await main();
})(); })();