node.jselectronnode-pre-gyp

Prebuilt electron module distribution


I'd like to distribute prebuilt binaries for a native Node.js add-on for Electron.

Presumably Node ABI changes between major bumps so I wonder if running node-pre-gyp with the right version of Node.js is gonna cut it or do I have to run electron-rebuild and publish rebuilt binaries?

A little experiment showed that node-pre-gyp couldn't find the compiled binary when running in electron environment. So it seems that electron-rebuild does something to patch that.


Solution

  • I looked through the sources of electron-builder and found that it simply runs install on the package.

    So having the following install hook is sufficient enough:

    node-pre-gyp install --fallback-to-build
    

    I don't use electron-rebuild directly anymore since I produce the right binaries in the first place, but I run electron-builder install-app-deps which probably does similar.

    I don't see any reason to bother with prebuild and prebuild-install at this point. It's two more dependencies that shield what node-pre-gyp and node-gyp both already implement.

    I modified my script for travis to run builds for node and electron side by side:

    # build for nodejs
    - npm install --build-from-source
    
    # build for electron
    - npm install --build-from-source --runtime=electron --target=$ELECTRON_VERSION --dist-url=https://atom.io/download/atom-shell
    

    Packaging step has to run twice with the same flags, i.e:

    - if [[ "${TRAVIS_TAG}" != "" ]]; then npm run package --verbose; fi
    - if [[ "${TRAVIS_TAG}" != "" ]]; then npm run package --runtime=electron --target=$ELECTRON_VERSION --verbose; fi
    

    Both Travis and Appveyor support uploads to Github Releases or S3 so again no gain from using prebuild or node-pre-gyp-github, example for Travis:

    deploy:
      provider: releases
      api_key:
        secure: ENCRYPTED_KEY
      file_glob: true
      file: build/stage/$PACKAGE_VERSION/*.tar.gz
      skip_cleanup: true
      on:
        tags: true