Skip to content

Commit

Permalink
Support pointing npm at a pre-built capnp.node
Browse files Browse the repository at this point in the history
...via an environment variable. I'm using this in:

    sandstorm-io/sandstorm#3413

to avoid building the module twice.
  • Loading branch information
zenhack committed Dec 7, 2020
1 parent 544bf09 commit 3444254
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -50,7 +50,13 @@ if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(arch)) {

// Test for pre-built library
var modPath = platform+ '-'+ arch+ '-v8-'+ v8;
if (!force) {
var installDir = path.join(__dirname, 'bin', modPath);
var installPath = path.join(installDir, 'capnp.node');

if('PREBUILT_NODE_CAPNP_BINARY' in process.env) {
fs.mkdirSync(installDir, {recursive: true});
fs.copyFileSync(process.env.PREBUILT_NODE_CAPNP_BINARY, installPath);
} else if (!force) {
try {
fs.statSync(path.join(__dirname, 'bin', modPath, 'capnp.node'));
console.log('`'+ modPath+ '` exists; testing');
Expand Down Expand Up @@ -99,7 +105,6 @@ function build() {
// Move it to expected location
function afterBuild() {
var targetPath = path.join(__dirname, 'build', debug ? 'Debug' : 'Release', 'capnp.node');
var installPath = path.join(__dirname, 'bin', modPath, 'capnp.node');

try {
fs.mkdirSync(path.join(__dirname, 'bin', modPath));
Expand Down

0 comments on commit 3444254

Please sign in to comment.