Skip to content

Commit

Permalink
Merge pull request #269 from CarsonF/patch-1
Browse files Browse the repository at this point in the history
Use require.resolve to lookup library path on disk
  • Loading branch information
SavageCore committed Aug 25, 2023
2 parents c99f939 + 75cc991 commit 4a6aa44
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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;

Expand Down

0 comments on commit 4a6aa44

Please sign in to comment.