on master help sign in
Run prettier on nodejs
commitad98944402dc99c5aa43f9a29edcf7a6c70a0ed9 authormasfrost <farismasad@gmail.com> dateTue 26 Oct 2021, 16:57 (5 years ago) parent4a42408
1 file changed+23−28
languages/nodejs/repl.js+23−28
languages/nodejs/repl.js+23−28
@@ -1,17 +1,16 @@
1−const util = require("util");
2−const repl = require("repl");
3−const path = require("path");
4−const fs = require("fs");
5−const vm = require("vm");
6−const { isatty } = require("tty");
7−const assets_dir =
8− process.env.PRYBAR_ASSETS_DIR || path.join(process.cwd(), "prybar_assets");
9−const rl = require(path.join(assets_dir, "nodejs", "input-sync.js"));
10−const Module = require("module");
1+const util = require('util');
2+const repl = require('repl');
3+const path = require('path');
4+const fs = require('fs');
5+const vm = require('vm');
6+const { isatty } = require('tty');
7+const assets_dir = process.env.PRYBAR_ASSETS_DIR || path.join(process.cwd(), 'prybar_assets');
8+const rl = require(path.join(assets_dir, 'nodejs', 'input-sync.js'));
9+const Module = require('module');
1110
1211let r;
1312if (!process.env.PRYBAR_QUIET) {
14− console.log("Node " + process.version + " on " + process.platform);
13+ console.log('Node ' + process.version + ' on ' + process.platform);
1514}
1615
1716const isTTY = isatty(process.stdin.fd);
@@ -51,17 +50,15 @@ function handleError(e) {
5150 r.lastError = e;
5251 }
5352
54− if (e && typeof e === "object" && e.stack && e.name) {
55− if (e.name === "SyntaxError") {
56− e.stack = e.stack
57− .replace(/^repl:\d+\r?\n/, "")
58− .replace(/^\s+at\s.*\n?/gm, "");
53+ if (e && typeof e === 'object' && e.stack && e.name) {
54+ if (e.name === 'SyntaxError') {
55+ e.stack = e.stack.replace(/^repl:\d+\r?\n/, '').replace(/^\s+at\s.*\n?/gm, '');
5956 }
6057
6158 logError(e.stack);
6259 } else {
6360 // For some reason needs a newline to flush.
64− logError("Thrown: " + r.writer(e) + "\n");
61+ logError('Thrown: ' + r.writer(e) + '\n');
6562 }
6663
6764 if (r) {
@@ -78,9 +75,9 @@ function start(context) {
7875 });
7976
8077 // remove the internal error and ours for red etc.
81− r._domain.removeListener("error", r._domain.listeners("error")[0]);
82− r._domain.on("error", handleError);
83− process.on("uncaughtException", handleError);
78+ r._domain.removeListener('error', r._domain.listeners('error')[0]);
79+ r._domain.on('error', handleError);
80+ process.on('uncaughtException', handleError);
8481}
8582
8683global.alert = console.log;
@@ -123,10 +120,10 @@ if (process.env.PRYBAR_CODE) {
123120 }
124121} else if (process.env.PRYBAR_FILE) {
125122 const mainPath = path.resolve(process.env.PRYBAR_FILE);
126− const main = fs.readFileSync(mainPath, "utf-8");
123+ const main = fs.readFileSync(mainPath, 'utf-8');
127124 const module = new Module(mainPath, null);
128125
129− module.id = ".";
126+ module.id = '.';
130127 module.filename = mainPath;
131128 module.paths = Module._nodeModulePaths(path.dirname(mainPath));
132129
@@ -138,9 +135,7 @@ if (process.env.PRYBAR_CODE) {
138135 global.__filename = mainPath;
139136
140137 if (isTTY) {
141− console.log(
142− "\u001b[0m\u001b[90mHint: hit control+c anytime to enter REPL.\u001b[0m"
143− );
138+ console.log('\u001b[0m\u001b[90mHint: hit control+c anytime to enter REPL.\u001b[0m');
144139 }
145140
146141 let script;
@@ -165,14 +160,14 @@ if (process.env.PRYBAR_CODE) {
165160
166161 module.loaded = true;
167162
168− if (typeof res !== "undefined") {
163+ if (typeof res !== 'undefined') {
169164 console.log(util.inspect(res, { colors: true }));
170165 }
171166 }
172167
173168 if (process.env.PRYBAR_INTERACTIVE) {
174− process.once("SIGINT", () => start());
175− process.once("beforeExit", () => start());
169+ process.once('SIGINT', () => start());
170+ process.once('beforeExit', () => start());
176171 }
177172} else if (process.env.PRYBAR_INTERACTIVE) {
178173 start();