injectFFMPEG.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const fs = require("fs");
  4. const path = require("path");
  5. const builder_util_1 = require("builder-util");
  6. const binDownload_1 = require("../binDownload");
  7. // NOTE: Adapted from https://github.com/MarshallOfSound/electron-packager-plugin-non-proprietary-codecs-ffmpeg to resolve dependency vulnerabilities
  8. const 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. };
  14. const 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. };
  35. function 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. }
  42. exports.default = injectFFMPEG;
  43. //# sourceMappingURL=injectFFMPEG.js.map