fix: removed readline dependency

it was honestly never supposed to be written that way
but i very rarely used it so i never noticed

the actual readline module that we use is a node core module
https://nodejs.org/docs/latest-v12.x/api/readline.html#readline_readline_createinterface_options

additionally improved its formatting and whatnot
This commit is contained in:
Bobby 2022-05-07 01:35:07 +07:00
parent 52c121721b
commit b4e32a6001
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
3 changed files with 10 additions and 17 deletions

View File

@ -18,7 +18,6 @@ const NodeClam = require('clamscan')
const nunjucks = require('nunjucks')
const path = require('path')
const rateLimit = require('express-rate-limit')
const readline = require('readline')
const serveStatic = require('@bobbywibowo/serve-static')
const { accessSync, constants } = require('fs')
@ -407,27 +406,27 @@ safe.use('/api', api)
// NODE_ENV=development yarn start
if (isDevMode) {
const { inspect } = require('util')
// Add readline interface to allow evaluating arbitrary JavaScript from console
readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: ''
require('readline').createInterface({
input: process.stdin
}).on('line', line => {
try {
if (line === 'rs') return
if (line === '.exit') return process.exit(0)
// eslint-disable-next-line no-eval
logger.log(eval(line))
const evaled = eval(line)
process.stdout.write(`${typeof evaled === 'string' ? evaled : inspect(evaled)}\n`)
} catch (error) {
logger.error(error.toString())
process.stderr.write(`${error.stack}\n`)
}
}).on('SIGINT', () => {
process.exit(0)
})
logger.log('!!! DEVELOPMENT MODE !!!')
logger.log('- Nunjucks will auto rebuild (not live reload)')
logger.log('- Rate limits disabled')
logger.log('- Readline interface enabled')
logger.log(utils.stripIndents(`!!! DEVELOPMENT MODE !!!
[=] Nunjucks will auto rebuild (not live reload)
[=] HTTP rate limits disabled
[=] Readline interface enabled (eval arbitrary JS input)`))
}
} catch (error) {
logger.error(error)

View File

@ -51,7 +51,6 @@
"node-fetch": "~2.6.7",
"nunjucks": "~3.2.3",
"randomstring": "~1.2.2",
"readline": "~1.3.0",
"search-query-parser": "~1.6.0",
"sharp": "~0.30.4",
"sqlite3": "~5.0.8",

View File

@ -5762,11 +5762,6 @@ readdirp@~3.6.0:
dependencies:
picomatch "^2.2.1"
readline@~1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/readline/-/readline-1.3.0.tgz#c580d77ef2cfc8752b132498060dc9793a7ac01c"
integrity sha1-xYDXfvLPyHUrEySYBg3JeTp6wBw=
rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"