electron / get

Download Electron release artifacts
https://npm.im/@electron/get
MIT License
338 stars 106 forks source link

Providing electron binaries as NPM package #194

Closed Eli-Black-Work closed 3 years ago

Eli-Black-Work commented 3 years ago

Hello 🙂

My understanding is that when the electron NPM package is installed, it runs a script that downloads the electron binary from github.

This approach runs into issues when using Yarn 2 (Yarn Berry), because Yarn 2 by default doesn't run installation scripts. Once we enabled installation scripts, we still ran into the issue of configuring electron to use our company's proxy when downloading the binaries.

What I'd like to propose is a different approach that I think might be able to nicely sidestep these issues:

I think this approach would let people use the standard NPM packaging mechanism to retrieve the electron binaries, which would simplify life for those who are behind a proxy or are using Yarn 2 🙂

Does this seem like a reasonable approach?

malept commented 3 years ago

I'm pretty sure this won't work because you'd need to bundle every single prebuilt binary for all of the platform/arch combinations in a given Electron version. This is because you can't, as far as I know, depend on a package on a platform/arch specific basis. For Electron 15.0.0-alpha.1, that's 896.3MB. That is much too large to expect someone to download, especially every time Electron is updated.

Additionally, there may also be a limit to how large an npm package can be, which I imagine Electron would exceed.

You can use this module (@electron/get) to prefetch the Electron binary, it will download it to a predetermined cache folder.

Eli-Black-Work commented 3 years ago

Thanks for the reply, @malept.

I'm thinking that since the binary would be an optional peer dependency, not a direct dependency or a dev dependency, the platform/arch combinations could be in separate packages, and then the user would take a dependency on only the ones that they need.

For example,

{
  "name": "example-app",
  "scripts": {
    "run": "electron-forge start",
    "package": "electron-forge package --platform win32 --arch ia32"
  },
  "main": ".webpack/main",
  "config": ...,
  "dependencies": {
    "electron-squirrel-startup": "..."
  },
  "devDependencies": {
    "@electron-forge/cli": "...",
    "@electron-forge/maker-squirrel": "...",
    "@electron-forge/plugin-webpack": "...",
    "electron": "..."
  },
  "optionalDependencies": {
    "@electron-binaries/win-x86",
    "@electron-binaryes/win-64"
  }
}