All Projects → adonisjs → repl

adonisjs / repl

Licence: MIT license
Framework Agnostic REPL For Node.js. Used by AdonisJS

Programming Languages

typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to repl

Tinker
Powerful REPL for the Laravel framework.
Stars: ✭ 6,957 (+9053.95%)
Mutual labels:  repl, tinker
sliver
REPL for SilverStripe, powered by Psysh. Interactively debug and tinker with a sliver of your code.
Stars: ✭ 17 (-77.63%)
Mutual labels:  repl, tinker
tinker-zero
Bridge laravel/tinker for your laravel-zero applications
Stars: ✭ 39 (-48.68%)
Mutual labels:  repl, tinker
JShellStandalone
Provides a standalone version of the JShell REPL. Anything needed to run JShell independently is contained, so there is no need to install the full JDK. A minimal Java runtime is embedded and compressed using the jlink tool.
Stars: ✭ 36 (-52.63%)
Mutual labels:  repl
replbot
Slack/Discord bot for running interactive REPLs and shells from a chat.
Stars: ✭ 169 (+122.37%)
Mutual labels:  repl
vue-code-view
A Vue 2 component like Vue SFC REPL `@vue/repl` : u can edit, run and preview the code effect display in real time on the web page.
Stars: ✭ 67 (-11.84%)
Mutual labels:  repl
dirac-sample
An example integration of Dirac DevTools
Stars: ✭ 17 (-77.63%)
Mutual labels:  repl
scope-capture-nrepl
nREPL middleware for scope-capture
Stars: ✭ 27 (-64.47%)
Mutual labels:  repl
laravel-live-tinker
Laravel tinker in your browser with code highlight
Stars: ✭ 51 (-32.89%)
Mutual labels:  tinker
nim-noise
Nim implementation of linenoise command line editor
Stars: ✭ 45 (-40.79%)
Mutual labels:  repl
GameOfLife
A python implementation of 'game of life'
Stars: ✭ 17 (-77.63%)
Mutual labels:  tinker
lambda
lambda calculus interpreter
Stars: ✭ 23 (-69.74%)
Mutual labels:  repl
Replay.jl
Replay your REPL instructions
Stars: ✭ 24 (-68.42%)
Mutual labels:  repl
lucid-slugify
Generate unique slugs using your Lucid models
Stars: ✭ 87 (+14.47%)
Mutual labels:  first-party-package
graphyne
⚡ Lightning-fast JavaScript GraphQL Server ⚡
Stars: ✭ 18 (-76.32%)
Mutual labels:  framework-agnostic
NeoConsole
NeoConsole offers a command line (REPL) interface to a Pharo image, as well as other tools.
Stars: ✭ 22 (-71.05%)
Mutual labels:  repl
Clojure-Sublimed
Clojure support for Sublime Text 4
Stars: ✭ 268 (+252.63%)
Mutual labels:  repl
situp android proj
🚀一个基组件化、模块化、MVP + MVVM 计划 App,兼容安卓 10.0 9.0 8.0 等 🔥a app like keep, you can edit your plans here, and you can share your life to others by post, too.🔥
Stars: ✭ 15 (-80.26%)
Mutual labels:  tinker
nodeScratchpad
Evaluate Nodejs Code Snippets From Menubar! 💻
Stars: ✭ 102 (+34.21%)
Mutual labels:  repl
huginn
Programming language with no quirks, so simple every child can master it.
Stars: ✭ 41 (-46.05%)
Mutual labels:  repl

AdonisJS REPL

A slick framework agnostic REPL for Node.js with first class support for
top level await, typescript compilation, accurate stack traces and a lot more.


gh-workflow-image npm-image license-image synk-image

Built with ❤︎ by Harminder Virk


AdonisJS REPL is a standalone and framework agnostic package to create custom Node.js REPL with first class support for:

👉 Execute typescript code with in-memory compilation.
👉 Support for top level await keyword.
👉 Ability to define custom method with a help description.

Table of contents

Installation

Install the package from the npm registry as follows:

npm i @adonisjs/repl

# Yarn
yarn add @adonisjs/repl

Usage

Import the Repl class from the standalone module.

import { Repl } from '@adonisjs/repl/build/standalone'
const repl = new Repl()

repl.start()

Typescript support

You will have to make use of @adonisjs/require-ts in order for the REPL to compile and run the typescript code. For example:

import { loadCompiler } from '@adonisjs/require-ts'
import { Repl } from '@adonisjs/repl/build/standalone'

const compilerOptions = {
  target: 'es2019',
  module: 'commonjs',
  allowSyntheticDefaultImports: true,
  esModuleInterop: true,
}

const repl = new Repl(loadCompiler(compilerOptions))

If you are using @adonisjs/require-ts as a require hook, then there is no need to instantiate another instance of the compiler as you can reference the compiler instance from the global object.

const compiler = global[Symbol.for('REQUIRE_TS_COMPILER')]
const repl = new Repl(compiler)

And now run the file containing the above code as follows:

node -r @adonisjs/require-ts/build/register repl.ts

History file

AdonisJS REPL allows you store the commands history inside a file so that the subsequent sessions can reference the commands executed in an earlier session.

You need to just pass the path to the history file and rest is taken care for you.

import { join } from 'path'
import { homedir } from 'os'
import { Repl } from '@adonisjs/repl/build/standalone'

const repl = new Repl(compiler, join(homedir(), '.adonis_repl_history'))

repl.start()

Accurate Stack Trace

The stack trace for the Typescript files points back to the correct file, line and the column number.

The .ls command

The .ls command prints the REPL session context. The output is divided to two sections.

  • Global Methods are the methods in the repl context object, but has some description associated with them.
  • Context properties: are the properties/methods in the context object. Only the first level of properties are printed on the console (to avoid noisy output).

Adding custom properties

If you are aware about the Node.js repl context, then you would know that you can add properties to the context as follows:

// NODE.JS EXAMPLE
const { start } = require('repl')

const server = start({})
server.context.foo = 'bar'

Similarly, you can add properties to the AdonisJS repl context by referencing the underlying server property.

import { Repl } from '@adonisjs/repl/build/standalone'

const repl = new Repl().start()
repl.server.context.foo = 'bar'

Global methods

In addition to adding properties to the context directly. You can also define custom methods with a description and its usage text. For example:

import { Repl } from '@adonisjs/repl/build/standalone'
const repl = new Repl()

repl.addMethod(
  'getUsers',
  () => {
    return [
      { id: 1, name: 'virk' },
      { id: 2, name: 'romain' },
    ]
  },
  {
    description: 'Returns a list of users',
  }
)

repl.start()

There is no technical advantage for using addMethod over adding properties to the context directly. It's just that addMethod properties are given special treatment during the .ls command.

Checkout the following example

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].