New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bun-repl

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bun-repl - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

bun-repl-cli2.sh

5

package.json
{
"type": "module",
"name": "bun-repl",
"version": "1.0.1",
"version": "1.0.2",
"description": "Experimental unofficial REPL for Bun",

@@ -36,4 +36,5 @@ "main": "src/repl.ts",

"bin": {
"repl": "./bun-repl-cli.sh"
"repl": "./bun-repl-cli.sh",
"bun-repl": "./bun-repl-cli2.sh"
}
}

32

README.md
# bun-repl [![GitHub version][github-image]][github-url] [![GitHub code size in bytes][size-image]][github-url] [![license][license-image]][license-url]
Experimental unofficial REPL for [Bun](https://github.com/oven-sh/bun)
Experimental unofficial REPL for Bun
Powered by Bun itself with the help of `swc` and JSC's `ShadowRealm` API

@@ -13,9 +11,18 @@

```
> ⚠️ Due to workarounds for Bun-specific issues, installation on other package managers like `npm` or `yarn` will not work.
## Usage
```sh
bun run repl -- [options]
# or
bun-repl [options]
```
bun run repl
```
Pass the `-h` or `--help` CLI option for a list of all options.
Type `.help` within the REPL for a list of commands.
Press `↑`+`Enter` to travel up the execution history.
Press `↓`+`Enter` to travel back down.
## Features

@@ -25,12 +32,19 @@

* Top level import syntax supported (`import fs from 'fs'`)
* Import either CommonJS or ESM into the REPL
* Import either CommonJS or ESM local files and packages into the REPL
* Node.js REPL special underscore variables provided (`_` and `_error`)
* Execution history (Arrow up/down)
* Execution history (`↑` `↓`)
* REPL Commands (`.command`)
## Known issues/limitations
## Known issues & limitations
Please keep in mind this is unofficial and experimental software built on top of experimental software, there **ARE** bugs. Additionally, Bun will obviously be getting an official native REPL in the future which certainly will be much better, this module is merely serving as a temporary alternative until then.
PRs are welcome to help fix any of the items below or anything else.
* Top level await is not supported.
* Reason: Usage of `eval()`
* The execution history (Arrow up/down) is buggy to navigate and doesn't support backspacing past the history entry.
* Multi-line inputs are not supported.
* Reason: Same as below.
* Pressing `←` and `→` to traverse the input with the cursor is not supported.
* Reason: Same as below.
* The execution history is buggy to navigate and doesn't support backspacing past the history entry.
* Reason: Bun's current lack of support for event-based streams limits us to `prompt()`, which provides little to no control over the input as its being written. This also makes it impossible to intercept keypresses/combinations.

@@ -37,0 +51,0 @@ * There is a space between the execution history entry and your appended code.

@@ -12,2 +12,16 @@ #!/usr/bin/env bun

const pkgjson = await Bun.file(path.join(import.meta.dir, '..', 'package.json')).json() as PackageJson;
const helpFlag = process.argv.includes('-h') || process.argv.includes('--help');
if (helpFlag) {
printCLIHelp();
process.exit(0);
}
const versionFlag = process.argv.includes('-v') || process.argv.includes('--version');
if (versionFlag) {
console.log(`bun-repl ${pkgjson.version}`);
process.exit(0);
}
const IS_DEBUG = process.argv.includes('--debug');

@@ -24,4 +38,2 @@ const debuglog = IS_DEBUG ? console.debug : () => void 0;

const pkgjson = await Bun.file(path.join(import.meta.dir, '..', 'package.json')).json() as PackageJson;
console.log(`Welcome to Bun.js ${process.version} (${process.revision ? 'canary-'+process.revision : 'release'})

@@ -71,10 +83,10 @@ Type ".help" for more information.`);

realm.evaluate(`
let $__SHADOWREALM_EVAL_RETURN_VALUE__;
try {
$__SHADOWREALM_EVAL_RETURN_VALUE__ = eval(${evalIn});
} catch (error) {
$__SHADOWREALM_EVAL_RETURN_VALUE__ = _error = error;
}
if ($__SHADOWREALM_EVAL_RETURN_VALUE__ !== _error) _ = $__SHADOWREALM_EVAL_RETURN_VALUE__;
globalThis['@@replFmt']($__SHADOWREALM_EVAL_RETURN_VALUE__);`);
let $__SHADOWREALM_EVAL_RETURN_VALUE__;
try {
$__SHADOWREALM_EVAL_RETURN_VALUE__ = eval(${evalIn});
} catch (error) {
$__SHADOWREALM_EVAL_RETURN_VALUE__ = _error = error;
}
if ($__SHADOWREALM_EVAL_RETURN_VALUE__ !== _error) _ = $__SHADOWREALM_EVAL_RETURN_VALUE__;
globalThis['@@replFmt']($__SHADOWREALM_EVAL_RETURN_VALUE__);`);
}

@@ -84,10 +96,22 @@

console.log(`Commands:
.help = Print this message.
.info = Print REPL information.
.clear = Clear the screen.
.exit = Exit the REPL.
.help = Print this message.
.info = Print REPL information.
.clear = Clear the screen.
.exit = Exit the REPL.
Press Ctrl+C to forcefully terminate the REPL.`);
Press Ctrl+C or Ctrl+Z to forcefully terminate the REPL.`);
}
function printCLIHelp(): void {
console.log(`Usage: bun-repl [options]
Options:
-h, --help = Display this message.
-v, --version = Show installed bun-repl version.
--debug = Print debug information while running.
Environment variables:
None`);
}
function printInfo(): void {

@@ -100,3 +124,2 @@ console.log(`bun-repl v${pkgjson.version}

Current session uptime: ${prettyms(performance.now())}`);
}

@@ -28,3 +28,3 @@ import swc from '@swc/core';

treatConstEnumAsEnum: false,
optimizer: {
optimizer: {
simplify: false,

@@ -31,0 +31,0 @@ globals: { vars: {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc