From b4e32a6001bf4dfaeec1d5bfafbf1bf70d423405 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 7 May 2022 01:35:07 +0700 Subject: [PATCH] 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 --- lolisafe.js | 21 ++++++++++----------- package.json | 1 - yarn.lock | 5 ----- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lolisafe.js b/lolisafe.js index 0fc2d00..e52ff64 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -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) diff --git a/package.json b/package.json index 9512d93..47dc4b2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 9ca897f..179ef5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"