From d6559fbc614cc23ec11c5398017d2c1fe8fc6ac6 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Fri, 8 Sep 2023 16:11:27 +0200 Subject: [PATCH] breaking: Remove unreferenced utils from cli-tools --- packages/cli-tools/src/getPidFromPort.ts | 22 ---------------------- packages/cli-tools/src/hookStdout.ts | 18 ------------------ packages/cli-tools/src/index.ts | 2 -- 3 files changed, 42 deletions(-) delete mode 100644 packages/cli-tools/src/getPidFromPort.ts delete mode 100644 packages/cli-tools/src/hookStdout.ts diff --git a/packages/cli-tools/src/getPidFromPort.ts b/packages/cli-tools/src/getPidFromPort.ts deleted file mode 100644 index 98774d17d..000000000 --- a/packages/cli-tools/src/getPidFromPort.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {execFileSync} from 'child_process'; -import logger from './logger'; - -const getPID = (port: number): number | null => { - try { - const results = execFileSync( - 'lsof', - [`-i:${port}`, '-P', '-t', '-sTCP:LISTEN'], - {encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore']}, - ) - .split('\n')[0] - .trim(); - const pid = Number(results); - logger.debug(`Pid: ${pid} for port: ${port}`); - return pid; - } catch (error) { - logger.debug(`No pid found for port: ${port}. Error: ${error}`); - return null; - } -}; - -export default getPID; diff --git a/packages/cli-tools/src/hookStdout.ts b/packages/cli-tools/src/hookStdout.ts deleted file mode 100644 index dc1a14532..000000000 --- a/packages/cli-tools/src/hookStdout.ts +++ /dev/null @@ -1,18 +0,0 @@ -// https://gist.github.com/pguillory/729616 - -function hookStdout(callback: Function) { - let old_write = process.stdout.write; - - // @ts-ignore - process.stdout.write = ((write: any) => - function (str: string) { - write.apply(process.stdout, arguments); - callback(str); - })(process.stdout.write); - - return () => { - process.stdout.write = old_write; - }; -} - -export default hookStdout; diff --git a/packages/cli-tools/src/index.ts b/packages/cli-tools/src/index.ts index b23b5e8e9..ec17a7b41 100644 --- a/packages/cli-tools/src/index.ts +++ b/packages/cli-tools/src/index.ts @@ -7,11 +7,9 @@ export {default as launchDebugger} from './launchDebugger'; export {default as launchEditor} from './launchEditor'; export * as version from './releaseChecker'; export {default as resolveNodeModuleDir} from './resolveNodeModuleDir'; -export {default as hookStdout} from './hookStdout'; export {getLoader, NoopLoader, Loader} from './loader'; export {default as findProjectRoot} from './findProjectRoot'; export {default as printRunDoctorTip} from './printRunDoctorTip'; -export {default as getPidFromPort} from './getPidFromPort'; export * from './prompt'; export * as link from './doclink'; export {default as startServerInNewWindow} from './startServerInNewWindow';