From 78cb9c67485a6e3c205ab551ebaf4873dc725088 Mon Sep 17 00:00:00 2001 From: Vittorio Palmisano Date: Thu, 22 Feb 2024 13:31:50 +0100 Subject: [PATCH] fix path resolution --- src/throttle.ts | 2 +- src/utils.ts | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/throttle.ts b/src/throttle.ts index 31c096a..47b5bde 100644 --- a/src/throttle.ts +++ b/src/throttle.ts @@ -130,7 +130,7 @@ async function applyRules( } async function start(config: ThrottleConfig): Promise { - // https://rotadev.com/using-tc-to-delay-packets-to-only-a-single-ip-address-server-fault/ + // https://serverfault.com/questions/389290/using-tc-to-delay-packets-to-only-a-single-ip-address const device = await getDefaultInterface() await runShellCommand(`\ sudo modprobe ifb; \ diff --git a/src/utils.ts b/src/utils.ts index ab11e17..03be142 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -70,27 +70,25 @@ export class LoggerInterface { const log = logger('app:utils') -let tsNode = false -try { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - tsNode = !!(process as any)[Symbol.for('ts-node.register.instance')] -} catch (_err) { - // ignore -} - /** * Resolves the absolute path from the package installation directory. * @param relativePath The relative path. * @returns The absolute path. */ export function resolvePackagePath(relativePath: string): string { - return '__nexe' in process - ? relativePath - : process.env.WEBPACK - ? path.join(path.dirname(__filename), relativePath) - : tsNode - ? require.resolve(path.join(__dirname, '..', relativePath)) - : require.resolve(path.join(__dirname, '../..', relativePath)) + if ('__nexe' in process) { + return relativePath + } + if (process.env.WEBPACK) { + return path.join(path.dirname(__filename), relativePath) + } + for (const d of ['..', '../..']) { + const p = path.join(__dirname, d, relativePath) + if (fs.existsSync(p)) { + return require.resolve(p) + } + } + throw new Error(`resolvePackagePath: ${relativePath} not found`) } /**