Skip to content

Commit 3444254

Browse files
committed
Support pointing npm at a pre-built capnp.node
...via an environment variable. I'm using this in: sandstorm-io/sandstorm#3413 to avoid building the module twice.
1 parent 544bf09 commit 3444254

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

build.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1111
// sell copies of the Software, and to permit persons to whom the Software is
1212
// furnished to do so, subject to the following conditions:
13-
//
13+
//
1414
// The above copyright notice and this permission notice shall be included in
1515
// all copies or substantial portions of the Software.
16-
//
16+
//
1717
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1818
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1919
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -50,7 +50,13 @@ if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(arch)) {
5050

5151
// Test for pre-built library
5252
var modPath = platform+ '-'+ arch+ '-v8-'+ v8;
53-
if (!force) {
53+
var installDir = path.join(__dirname, 'bin', modPath);
54+
var installPath = path.join(installDir, 'capnp.node');
55+
56+
if('PREBUILT_NODE_CAPNP_BINARY' in process.env) {
57+
fs.mkdirSync(installDir, {recursive: true});
58+
fs.copyFileSync(process.env.PREBUILT_NODE_CAPNP_BINARY, installPath);
59+
} else if (!force) {
5460
try {
5561
fs.statSync(path.join(__dirname, 'bin', modPath, 'capnp.node'));
5662
console.log('`'+ modPath+ '` exists; testing');
@@ -99,7 +105,6 @@ function build() {
99105
// Move it to expected location
100106
function afterBuild() {
101107
var targetPath = path.join(__dirname, 'build', debug ? 'Debug' : 'Release', 'capnp.node');
102-
var installPath = path.join(__dirname, 'bin', modPath, 'capnp.node');
103108

104109
try {
105110
fs.mkdirSync(path.join(__dirname, 'bin', modPath));

0 commit comments

Comments
 (0)