Code Monkey home page Code Monkey logo

bun-repl's Introduction

Bun REPL GitHub version GitHub code size in bytes license

Experimental REPL for Bun

NOTICE: This package is planned to be embedded directly into Bun sometime soon, this must be taken into consideration if making contributions to the package.

Install

You can use it directly via Bun with:

bun repl

No installation required!

Versioning

npm and GitHub releases will always be guaranteed to not rely on current Bun canary versions, but support for any version other than the latest non-canary will not be guaranteed.

The source code repository latest commit may contain code not yet in any release which depends on currently Bun canary-only features and has no guarantees.

Features

  • Seamless JavaScript & TypeScript execution
  • Single run CLI flags --eval and --print
  • Multi-line input (.multiline)
  • Top level import syntax supported (import fs from 'fs')
  • Top level await (experimental)
  • Lazy-loaded builtin modules as preloaded global variables. (including Bun modules! Try ffi or sqlite)
  • Import either CommonJS or ESM local files and packages into the REPL
  • Node.js REPL special underscore variables provided (_ and _error)
  • Resistent to global object modification (output quality may decrease but never crash)
  • Persistent execution history ( )
  • REPL Commands (.command)

Usage

bun repl [options]

Pass the -h or --help CLI option for a list of all options.

Type .help within the REPL for a list of commands.

Press and to travel up or down the execution history.

bun repl exposes the special variable repl which provides access to a REPL interface like the Node.js REPL (also accessible through import/require of repl or node:repl).

You can use repl.writer.options like you would in Node.js REPL to customize the live output of the running REPL.

bun-repl's People

Contributors

jhmaster2000 avatar meetmangukiya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

bun-repl's Issues

Question: How does the installation works?

A quick question that I couldn't find the answer by myself: How exactly does the installation work with bun repl? I would have expected to have to install a global package first.

Thanks for the great work!

Publish new version to NPM to fix linux arm64 support

Currently bun-repl is the suggested subcommand for bun x, however it's broken on linux arm64.

Problem

❯ docker run --rm -it --platform linux/arm64 oven/bun:latest -- x bun-repl
Unable to find image 'oven/bun:latest' locally
latest: Pulling from oven/bun
Digest: sha256:e8e19914f5aaf31e580245e569ebf0b1455fcbb991ee1a0986135ff0a063f16a
Status: Downloaded newer image for oven/bun:latest
59 |   }
60 |   return wrap.native = functionToCall, wrap.ptr = functionToCall.ptr, wrap;
61 | };
62 | function dlopen(path, options) {
63 |
64 |   const result = nativeDLOpen(path, options);
                    ^
ERR_DLOPEN_FAILED: Failed to open library. This is usually caused by a missing library or an invalid library path.
 syscall: "dlopen"

      at dlopen (bun:ffi:64:17)
      at /tmp/bun-repl@latest--bunx/node_modules/rustybun/dist/index.mjs:41:4
error: "bun-repl" exited with code 1 (SIGHUP)

Solution

[email protected] now supports linux arm64, which bun-repl@master uses, however the latest NPM version is out of date.

Simply pushing a new version to NPM should resolve this issue.

POC

❯ docker run --rm -it --platform linux/arm64 oven/bun:latest -- x bun-repl@git+https://github.com/jhmaster2000/bun-repl
Welcome to Bun.js v0.6.14
Type ".help" for more information.
>

Import not working

If I try to import a package installed with npm I get the following error:

ResolveError: Cannot find package "package-name" from /Users/mike/Projects/the-project/$bun$repl.ts

Any idea why? the package definitely exists and imports just fine with the node console.

`setTimeout` does not execute

$ bun-repl
Welcome to Bun.js v0.7.3
Type ".help" for more information.
> setTimeout(() => console.log('hello'), 1000)
Object [Timeout] {}
> 

I expect to see a "hello" printed, like in node:

$ node
Welcome to Node.js v18.12.1.
Type ".help" for more information.
> setTimeout(() => console.log('hello'), 1000)
Timeout {
[...]
}
> hello

.bun_repl_history does not exist on first run

Error on first run:

(env) bwasti@bwasti-mbp shumai % bun-repl
 7 |     constructor(prompt: string = '> ', historyPath?: string) {
 8 |         super();
 9 |         this.prompt = process.env.BUN_REPL_PROMPT ?? prompt;
10 |         historyPath ||= `${process.env.BUN_INSTALL ?? os.homedir()}/.bun_repl_history`;
11 |
12 |         const historyLines = fs.readFileSync(historyPath, 'utf8').split('\n');
                                 ^
ENOENT: No such file or directory
   path: "/Users/bwasti/.bun/.bun_repl_history"
syscall: "open"
  errno: -2

      at new REPLManager (/Users/bwasti/.bun/install/global/node_modules/bun-repl/src/replmanager.ts:12:29)
      at /Users/bwasti/.bun/install/global/node_modules/bun-repl/src/repl.ts:70:13

Workaround is to add that file: touch $HOME/.bun/.bun_repl_history, but I think the repl should do that for us :)

Error when `fetch` is called with inline config object

Keep getting the following error when running an await fetch command with a config object.

Basic example:

await fetch('https://api.github.com/orgs/nodejs', { method: 'GET' }).then(v => v.json())
SyntaxError: Unexpected keyword 'return'. Expected '}' to end an object literal.

When calling without config object, command runs just fine.

await fetch('https://api.github.com/orgs/nodejs').then(response => response.json())
{                                                                                                                                                                
  login: 'nodejs',                                                                                                                                               
  id: 9950313,                                                                                                                                                   
  node_id: 'MDEyOk9yZ2FuaXphdGlvbjk5NTAzMTM=',                                                                                                                   
  url: 'https://api.github.com/orgs/nodejs',                                                                                                                     
  repos_url: 'https://api.github.com/orgs/nodejs/repos',     
  // ...
}

If the config object is declared prior, instead of declared inline - works fine too.

const config: FetchRequestInit = { method: 'GET'}
await fetch('https://api.github.com/orgs/nodejs', config).then(v => v.json())
{                                                                                                                                                                
  login: 'nodejs',                                                                                                                                               
  id: 9950313,                                                                                                                                                   
  node_id: 'MDEyOk9yZ2FuaXphdGlvbjk5NTAzMTM=',                                                                                                                   
  url: 'https://api.github.com/orgs/nodejs',                                                                                                                     
  repos_url: 'https://api.github.com/orgs/nodejs/repos',     
  // ...
}

Something about inline config definition is causing SyntaxError: Unexpected keyword 'return'. Expected '}' to end an object literal.

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.