Skip to content

Commit 2b4e2d9

Browse files
Gabriel Schulhofmhdawson
authored andcommitted
Use a version check to determine if N-API is internal
PR-URL: #114 Reviewed-By: Michael Dawson <[email protected]>
1 parent e46d590 commit 2b4e2d9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
var path = require('path');
22

3+
// We know which version of Node.js first shipped the incarnation of the API
4+
// available in *this* package. So, if we find that the Node.js version is below
5+
// that, we indicate that the API is missing from Node.js.
6+
function getNodeApiBuiltin() {
7+
var versionArray = process.version
8+
.substr(1)
9+
.split('.')
10+
.map(function(item) {
11+
return +item;
12+
});
13+
return versionArray[0] >= 8 && versionArray[1] >= 4 && versionArray[2] >= 0;
14+
}
15+
316
// TODO: Check if the main node semantic version is within multiple ranges,
417
// or detect presence of built-in N-API by some other mechanism TBD.
5-
var isNodeApiBuiltin = process.versions.modules >= 52; // Node 8.x
18+
var isNodeApiBuiltin = getNodeApiBuiltin();
619

720
var include = path.join(__dirname, 'src');
821
var gyp = path.join(__dirname, 'src', 'node_api.gyp');

0 commit comments

Comments
 (0)