Open springmeyer opened 7 years ago
The drawbacks of publishing C++ header-only libs in npm are:
node_modules
even when deployment is done with binaries (and they are essentially unused in that case)These are downsides enough that npm publishing of C++ headers is not the ideal method / best practice at Mapbox.
Instead we'll need to come up with some other method to recommend and consistently use via node c++ modules, like using a shell script + mason like carmen-cache does to install rocksdb (https://github.com/mapbox/carmen-cache/blob/1aaf88413be2243e3e3c772b1a9c777ea527578c/binding.gyp#L3-L16 + https://github.com/mapbox/carmen-cache/blob/4182501f748e2ca2635485cbd51e17b6c49329f1/install_mason.sh. This would have the added benefit that it would work for both header only libs and dependencies that are precompiled libs.
Nice @springmeyer! You may have a look over at hpp-skel as well, which implements some of the features you mention above. The README has a brief description of publishing as well.
Instead we'll need to come up with some other method to recommend and consistently use via node c++ modules, like using a shell script + mason like carmen-cache does
This is now implemented in node-cpp-skel. To recap the idea is:
Now that the best practice is in place the remaining actions are:
rational
We are increasingly working on small node C++ modules that depend on header-only C++ libs. Node.js's
Nan
module has pioneered a best practice for how to include header only C++ libs in node C++ addons by simply adding apackage.json
andinclude_dirs.js
file to the root of the project. I think we should follow the lead of howNan
does this and package all our C++ header only libs in npm as well as mason. I think publishing in two places is worth it because it makes including the libraries from node modules very easy and consistent with how JS modules work.method
Add:
files
parameter topackage.json
so that only theinclude/
directory is includedExample:
Then test that only the right files are going to be packaged:
^^ that should list just the headers and the default files npm includes like
README.md
andpackage.json
etcExamples:
Example use case: