Add shell scripts to run without just, fix the issue with bun and tsx failing to exit
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2024-07-12 15:33:03 -04:00
parent 1951425508
commit 8c54ceb104
13 changed files with 64 additions and 34 deletions

View File

@ -12,7 +12,10 @@ To simplify running, I'm using [Just](https://github.com/casey/just).
- Bun: `just bun-run [filename]` - Bun: `just bun-run [filename]`
- Deno: `just deno-run [filename]` - Deno: `just deno-run [filename]`
- TSX: `just tsx-run [filename` - TSX: `just tsx-run [filename]`
Alternatively, there are shell scripts for each runtime in the `bin` folder.
So you can run the editor by calling `./bin/deno.sh [filename]` without installing Just.
Deno is generally used for dev tools, but each runtime should be functionally Deno is generally used for dev tools, but each runtime should be functionally
equivalent running the text editor. equivalent running the text editor.

5
bin/bun.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
PARENT_DIR="$(dirname "$(realpath "$0")")"
SCROLL="$(realpath "${PARENT_DIR}/../src/scroll.ts")"
bun run "${SCROLL}" "$@"

5
bin/deno.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
PARENT_DIR="$(dirname "$(realpath "$0")")"
SCROLL="$(realpath "${PARENT_DIR}/../src/scroll.ts")"
deno run --allow-all --deny-hrtime "${SCROLL}" "$@"

6
bin/tsx.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
PARENT_DIR="$(dirname "$(realpath "$0")")"
TSX="$(realpath "${PARENT_DIR}/../node_modules/.bin/tsx")"
SCROLL="$(realpath "${PARENT_DIR}/../src/scroll.ts")"
"${TSX}" "${SCROLL}" "$@";

View File

@ -1,8 +1,10 @@
{ {
"dependencies": {}, "dependencies": {},
"devDependencies": { "devDependencies": {
"bun-types": "^1.0.11", "@types/node": "*",
"typescript": "^5.5" "bun-types": "*",
"typescript": "^5.5",
"tsx": "*"
}, },
"scripts": { "scripts": {
"bun-check": "bunx tsc", "bun-check": "bunx tsc",
@ -15,8 +17,8 @@
"deno-run": "deno run --allow-all --deny-hrtime ./src/scroll.ts", "deno-run": "deno run --allow-all --deny-hrtime ./src/scroll.ts",
"deno-test": "deno test --allow-all", "deno-test": "deno test --allow-all",
"tsx-check": "npx tsc", "tsx-check": "npx tsc",
"tsx-run": "npx tsx ./src/scroll.ts", "tsx-run": "tsx ./src/scroll.ts",
"tsx-test": "npx tsx --test './src/common/all_test.ts'" "tsx-test": "tsx --test './src/common/all_test.ts'"
}, },
"type": "module" "type": "module"
} }

View File

@ -419,12 +419,6 @@ export default class Editor {
? this.document.row(this.cursor.y).unwrap().cxToRx(this.cursor.x) ? this.document.row(this.cursor.y).unwrap().cxToRx(this.cursor.x)
: 0; : 0;
logDebug('Editor.scroll - start', {
cursor: this.cursor,
renderX: this.renderX,
offset: this.offset,
});
const { y } = this.cursor; const { y } = this.cursor;
const offset = this.offset; const offset = this.offset;
const width = this.screen.cols; const width = this.screen.cols;
@ -441,12 +435,6 @@ export default class Editor {
} else if (this.renderX >= offset.x + width) { } else if (this.renderX >= offset.x + width) {
offset.x = this.renderX - width + 1; offset.x = this.renderX - width + 1;
} }
logDebug('Editor.scroll - end', {
cursor: this.cursor,
renderX: this.renderX,
offset: this.offset,
});
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -1,5 +1,10 @@
import { readKey } from './fns.ts'; import { readKey } from './fns.ts';
import { getRuntime, logError, logWarning, process } from './runtime/mod.ts'; import {
getRuntime,
logError,
logWarning,
node_process as process,
} from './runtime/mod.ts';
import Editor from './editor.ts'; import Editor from './editor.ts';
export async function main() { export async function main() {

View File

@ -1,8 +1,8 @@
/** /**
* Functions/Methods that depend on the current runtime to function * Functions/Methods that depend on the current runtime to function
*/ */
import { logError } from './log.ts'; import { logError, logWarning } from './log.ts';
import { process } from './node.ts'; import { node_path as path, node_process as process } from './node.ts';
import { RunTimeType } from './runtime.ts'; import { RunTimeType } from './runtime.ts';
import { IRuntime, ITestBase } from '../types.ts'; import { IRuntime, ITestBase } from '../types.ts';
@ -23,15 +23,24 @@ export function die(s: string | Error): void {
* Determine which Typescript runtime we are operating under * Determine which Typescript runtime we are operating under
*/ */
export function runtimeType(): RunTimeType { export function runtimeType(): RunTimeType {
let runtime = RunTimeType.Tsx; const cmd = path.basename(process.argv[0]);
switch (cmd) {
case 'deno':
return RunTimeType.Deno;
if ('Deno' in globalThis) { case 'bun':
runtime = RunTimeType.Deno; return RunTimeType.Bun;
} else if ('Bun' in globalThis) {
runtime = RunTimeType.Bun; case 'node':
return RunTimeType.Tsx;
default:
logWarning('Fallback runtime detection', { cmd });
if ('bun' in globalThis) {
return RunTimeType.Bun;
}
return RunTimeType.Tsx;
} }
return runtime;
} }
/** /**

View File

@ -5,3 +5,6 @@ export * from './node.ts';
export * from './runtime.ts'; export * from './runtime.ts';
export * from './terminal_io.ts'; export * from './terminal_io.ts';
export * from './test_base.ts'; export * from './test_base.ts';
import { CommonRuntime } from './runtime.ts';
export default CommonRuntime;

View File

@ -1,7 +1,9 @@
/** /**
* Re-export of node apis shared by runtimes * Re-export of node apis shared by runtimes
*/ */
import * as assert from 'node:assert'; import node_assert from 'node:assert';
import * as process from 'node:process'; import node_path from 'node:path';
import node_process from 'node:process';
import node_tty from 'node:tty';
export { assert, process }; export { node_assert, node_path, node_process, node_tty };

View File

@ -1,4 +1,4 @@
import { process } from './node.ts'; import { node_process as process } from './node.ts';
import CommonFileIO from './file_io.ts'; import CommonFileIO from './file_io.ts';
import CommonTerminalIO from './terminal_io.ts'; import CommonTerminalIO from './terminal_io.ts';

View File

@ -1,4 +1,4 @@
import { process } from './node.ts'; import { node_process as process } from './node.ts';
import { readKey } from '../fns.ts'; import { readKey } from '../fns.ts';
import { ITerminal, ITerminalSize } from '../types.ts'; import { ITerminal, ITerminalSize } from '../types.ts';
@ -26,6 +26,7 @@ export const CommonTerminalIO: ITerminal = {
process.stdin.resume().once( process.stdin.resume().once(
'data', 'data',
(buffer: Uint8Array) => { (buffer: Uint8Array) => {
process.stdin.pause();
resolve(buffer); resolve(buffer);
}, },
); );

View File

@ -13,8 +13,9 @@
"skipLibCheck": true, "skipLibCheck": true,
"composite": true, "composite": true,
"downlevelIteration": true, "downlevelIteration": true,
"esModuleInterop": false, "esModuleInterop": true,
"allowSyntheticDefaultImports": false "allowSyntheticDefaultImports": true,
"isolatedModules": true
}, },
"exclude": ["src/deno"] "exclude": ["src/deno"]
} }