Skip to content

Commit

Permalink
fix path resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed Feb 22, 2024
1 parent df70771 commit 78cb9c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/throttle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async function applyRules(
}

async function start(config: ThrottleConfig): Promise<void> {
// 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; \
Expand Down
28 changes: 13 additions & 15 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}

/**
Expand Down

0 comments on commit 78cb9c6

Please sign in to comment.