UNPKG

2.12 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fs = require("fs");
4const path = require("path");
5const builder_util_1 = require("builder-util");
6const binDownload_1 = require("../binDownload");
7// NOTE: Adapted from https://github.com/MarshallOfSound/electron-packager-plugin-non-proprietary-codecs-ffmpeg to resolve dependency vulnerabilities
8const downloadFFMPEG = async (electronVersion, platform, arch) => {
9 const ffmpegFileName = `ffmpeg-v${electronVersion}-${platform}-${arch}.zip`;
10 const url = `https://github.com/electron/electron/releases/download/v${electronVersion}/${ffmpegFileName}`;
11 builder_util_1.log.info({ file: ffmpegFileName }, "downloading non-proprietary FFMPEG");
12 return (0, binDownload_1.getBin)(ffmpegFileName, url);
13};
14const copyFFMPEG = (targetPath, platform) => (sourcePath) => {
15 let fileName = "ffmpeg.dll";
16 if (["darwin", "mas"].includes(platform)) {
17 fileName = "libffmpeg.dylib";
18 }
19 else if (platform === "linux") {
20 fileName = "libffmpeg.so";
21 }
22 const libPath = path.resolve(sourcePath, fileName);
23 const libTargetPath = path.resolve(targetPath, fileName);
24 builder_util_1.log.info({ lib: libPath, target: libTargetPath }, "copying non-proprietary FFMPEG");
25 // If the source doesn't exist we have a problem
26 if (!fs.existsSync(libPath)) {
27 throw new Error(`Failed to find FFMPEG library file at path: ${libPath}`);
28 }
29 // If we are copying to the source we can stop immediately
30 if (libPath !== libTargetPath) {
31 fs.copyFileSync(libPath, libTargetPath);
32 }
33 return libTargetPath;
34};
35function injectFFMPEG(options, electrionVersion) {
36 let libPath = options.appOutDir;
37 if (options.platformName === "darwin") {
38 libPath = path.resolve(options.appOutDir, "Electron.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries");
39 }
40 return downloadFFMPEG(electrionVersion, options.platformName, options.arch).then(copyFFMPEG(libPath, options.platformName));
41}
42exports.default = injectFFMPEG;
43//# sourceMappingURL=injectFFMPEG.js.map
\No newline at end of file