From 75cc9916c70e5d41917e4002ce866c5f6a3282e8 Mon Sep 17 00:00:00 2001 From: Carson Full Date: Fri, 25 Aug 2023 14:20:53 -0500 Subject: [PATCH] Use require.resolve to lookup library path on disk Fixes PnP usage and simplifies code --- index.js | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 0755d54..4466965 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ const os = require('node:os'); -const path = require('node:path'); const process = require('node:process'); const verifyFile = require('./lib/verify-file.js'); @@ -16,28 +15,12 @@ if (!require('./package.json').optionalDependencies[packageName]) { const binary = platform === 'win32' ? 'ffprobe.exe' : 'ffprobe'; -const npm3Path = path.resolve(__dirname, '..', target); -const npm2Path = path.resolve(__dirname, 'node_modules', '@ffprobe-installer', target); - -const npm3Binary = path.join(npm3Path, binary); -const npm2Binary = path.join(npm2Path, binary); - -const npm3Package = path.join(npm3Path, 'package.json'); -const npm2Package = path.join(npm2Path, 'package.json'); - -let ffprobePath; -let packageJson; - -if (verifyFile(npm3Binary)) { - ffprobePath = npm3Binary; - packageJson = require(npm3Package); -} else if (verifyFile(npm2Binary)) { - ffprobePath = npm2Binary; - packageJson = require(npm2Package); -} else { - throw new Error('Could not find ffprobe executable, tried "' + npm3Binary + '" and "' + npm2Binary + '"'); +const ffprobePath = require.resolve(`${packageName}/${binary}`); +if (!verifyFile(ffprobePath)) { + throw new Error(`Could not find ffprobe executable, tried "${ffprobePath}"`); } +const packageJson = require(`${packageName}/package.json`); const version = packageJson.ffprobe || packageJson.version; const url = packageJson.homepage;