From 43f1a1dd1b44065663a797603012394c52a9baea Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 13 May 2023 13:31:58 -0300 Subject: use ESM module syntax & update tui-lib Exciting update! This doesn't make any substantial changes exactly but does update the most quickly-archaic parts of older Node code. --- socat.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'socat.js') diff --git a/socat.js b/socat.js index 8871c7e..a465a73 100644 --- a/socat.js +++ b/socat.js @@ -2,16 +2,14 @@ // Assumes access to the `socat` command as a child process; if it's not // present, it will fall back to just writing to the specified file. -const EventEmitter = require('events') -const { spawn } = require('child_process') -const { killProcess, commandExists } = require('./general-util') -const { promisify } = require('util') -const fs = require('fs') -const path = require('path') +import {spawn} from 'node:child_process' +import {writeFile} from 'node:fs/promises' +import EventEmitter from 'node:events' +import path from 'node:path' -const writeFile = promisify(fs.writeFile) +import {killProcess, commandExists} from './general-util.js' -module.exports = class Socat extends EventEmitter { +export default class Socat extends EventEmitter { constructor(path) { super() this.setPath(path) @@ -30,7 +28,7 @@ module.exports = class Socat extends EventEmitter { this.subprocess.on('close', () => { this.subprocess = null }) - this.subprocess.stdin.on('error', err => { + this.subprocess.stdin.on('error', () => { this.stop() }) } @@ -69,7 +67,7 @@ module.exports = class Socat extends EventEmitter { } } else { try { - await writeFile(path.resolve(__dirname, this.path), message + '\r\n') + await writeFile(path.resolve(process.cwd(), this.path), message + '\r\n') } catch (error) { // :shrug: We tried! // -- It's possible to get here if the specified path isn't an actual -- cgit 1.3.0-6-gf8a5