Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
@adonisjs/repl
Advanced tools
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.
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.
Install the package from the npm registry as follows:
npm i @adonisjs/repl
# Yarn
yarn add @adonisjs/repl
Import the Repl
class from the standalone module.
import { Repl } from '@adonisjs/repl/build/standalone'
const repl = new Repl()
repl.start()
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
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()
The stack trace for the Typescript files points back to the correct file, line and the column number.
.ls
commandThe .ls
command prints the REPL session context. The output is divided to two sections.
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'
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
FAQs
REPL for AdonisJS
The npm package @adonisjs/repl receives a total of 18,874 weekly downloads. As such, @adonisjs/repl popularity was classified as popular.
We found that @adonisjs/repl demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.