0

Is it possible to include a binary executable in NPM package? I am struggling to do so on macOS.

I am working on an electron application which uses SVN. Using svn-spawn package I am able to communicate with the svn if it's installed on the machine. However, I would like to not to install SVN and my application separately.

Since SVN works as a single executable - either svn.exe on Windows or svn on macOS, I can edit the following block in node_modules/svn-spawn/lib/svn.js

var Client = function(options) {
    this.option({
        program: '<path_to_svn>/svn.exe'
    }).option(options);
};

After I package it:

  • works on Windows (even after uninstalling svn - meaning svn became a part of the application)
  • works on macOS when svn is still in the directory
  • doesn't work on macOS when svn is deleted

What is the right way of including executables like that in npm installation?

Money_Badger
  • 537
  • 1
  • 5
  • 24
  • A lot of the gulp packages are shipped with binaries. You can check out [jpegtran-bin](https://github.com/imagemin/jpegtran-bin) for example. If you look at the profiles of the maintainers you'll find more packages that are also shipped with binaries. – Mika Sundland Jan 20 '18 at 17:08
  • Is this basically storing binaries on gitHub instead of local file system? – Money_Badger Jan 20 '18 at 17:43

1 Answers1

2

For anyone with the same problem - this tread helps: bundling precompiled binary into electron app

You can copy over a file by updating package.json

  "build": {
    "extraFiles": [
      {
        "from": "resources/${os}",
        "to": "Resources/bin",
        "filter": ["**/*"]
      }
    ],

Then referencing this file from your script.

Money_Badger
  • 537
  • 1
  • 5
  • 24