Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross-platform install of npm package sqlite3

Question

Is there a way to install node-sqlite3 for multiple platforms I am targeting in my app without running standalone build for just every target platform combination?

Context

In my Node.js app I have a npm dependency node-sqlite3 (GitHub, npm), which contains different binaries (bindings) for different platforms.

My app is targeting different platforms, including Windows, Linux and macOS (both ia32 and x64) and modern Node versions: v6, v7 and v8. The app doesn't have any platform-specific behavior.

If I install the project's dependencies using npm install, node-sqlite3 downloads binaries just for the current platform (let's say win32, x64, Node v7.10).

I also have a Travis CI build configuration, which I use for Continuous Deployment as well as Continuous Integration. I chose Ubuntu Trusty as a host for executing builds.

As a part of a build process the app's dependencies are being installed by npm install. Within deployment process, the built app with it's dependencies is being packaged (archived) and uploaded to a file hosting for further distribution.

Issue

node-sqlite3 is not installed for all target platforms I need, but just for a platform currently being used (for development or executing a build).

Possible solution

I could execute builds and deploy:

  • with Travis - for Linux and macOS
  • with AppVeyor - for Windows

But that's looks like a big overhead. As I've already said, the app doesn't have any platform-specific behavior. And I trust node-sqlite3's vendor tested it at all major platforms I am targeting.

like image 466
Deilan Avatar asked Jul 19 '17 13:07

Deilan


People also ask

What is sqlite3 in Nodejs?

The sqlite3 module is actively maintained and provides a rich set of features: Simple API for query execution. Parameters binding support. Control the query execution flow, supporting both serialized and parallel modes. Comprehensive debugging support.

How do I add packages to devDependencies?

To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.

Can I install npm packages offline?

Yes, but simply copying the content of node_modules should be enought, unless you install globally. Another way that may be simpler is to run npm install angular-cli on a connected system, and copy the content of node_modules to the offline computer.


1 Answers

Yes, in case with node-sqlite3 you do have such a capability.

It is possible because it's owner mapbox uses node-pre-gyp (GitHub, npm) for distribution of node-sqlite3.

After installing your app's dependencies with npm install execute the following command at the root of your Node project for every target platform combination:

./node_modules/.bin/node-pre-gyp install
--directory=./node_modules/sqlite3
--target_platform={OS}
--target_arch={OS architecture}
--target={Node version}

(please note that line breaks here are just for clarity, you have to remove or escape them prior to execution)

As a result you would have required bindings in ./node_modules/sqlite3/lib/binding/ directory.

Options

Here's the options' descriptions from the node-pre-gyp docs.

--directory: run the command in this directory

--target_platform=win32: Pass the target platform and override the host platform. Valid values are linux, darwin, win32, sunos, freebsd, openbsd, and aix.

--target_arch=ia32: Pass the target arch and override the host arch. Valid values are 'ia32','x64', or arm.

--target=0.10.25: Pass the target node or node-webkit version to compile against

If they exist, prebuilt binaries for chosen platform will be downloaded from a file storage (Amazon S3). Otherwise you have to build binaries by yourself.

A list of available binaries of node-sqlite3 is here.

Examples

A couple of examples for certain target platforms:

• Windows x86 and Node 6.10.0:

./node_modules/.bin/node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=win32 --target_arch=ia32 --target=6.10.0

• macOS x64 and Node 7.10.0:

./node_modules/.bin/node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=darwin--target_arch=x64 --target=7.10.0

• Linux x64 and Node 8.0.0:

./node_modules/.bin/node-pre-gyp install --directory=./node_modules/sqlite3 --target_platform=linux--target_arch=x64 --target=8.0.0
like image 185
Deilan Avatar answered Oct 18 '22 13:10

Deilan