Skip to content

Commit a870338

Browse files
Gabriel Schulhofmhdawson
authored andcommitted
Introduce flag check
The version starting with which N-API is considered built-in is not the same as the version starting with which the --napi-modules flag is consisdered dropped. The latter needs a separate check. PR-URL: #121 Fixes: #119 Reviewed-By: Michael Dawson <[email protected]>
1 parent 67c12f6 commit a870338

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
var path = require('path');
22

3+
var versionArray = process.version
4+
.substr(1)
5+
.replace(/-.*$/, '')
6+
.split('.')
7+
.map(function(item) {
8+
return +item;
9+
});
10+
11+
// TODO: Check if the main node semantic version is within multiple ranges,
12+
// or detect presence of built-in N-API by some other mechanism TBD.
13+
314
// We know which version of Node.js first shipped the incarnation of the API
415
// available in *this* package. So, if we find that the Node.js version is below
516
// 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-
}
17+
var isNodeApiBuiltin =
18+
(versionArray[0] >= 8 && versionArray[1] >= 4 && versionArray[2] >= 0);
1519

16-
// TODO: Check if the main node semantic version is within multiple ranges,
17-
// or detect presence of built-in N-API by some other mechanism TBD.
18-
var isNodeApiBuiltin = getNodeApiBuiltin();
20+
// So far it looks like even version 9 will need the flag. We need to adjust
21+
// this for the version where the flag is dropped whenever that version lands.
22+
var needsFlag = (versionArray[0] >= 8);
1923

2024
var include = path.join(__dirname, 'src');
2125
var gyp = path.join(__dirname, 'src', 'node_api.gyp');
@@ -31,4 +35,5 @@ module.exports = {
3135
include: [ '"' + include + '"', '"' + __dirname + '"' ].join(' '),
3236
gyp: gyp,
3337
isNodeApiBuiltin: isNodeApiBuiltin,
38+
needsFlag: needsFlag
3439
};

test/napi_child.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Makes sure that child processes are spawned appropriately.
22
exports.spawnSync = function(command, args, options) {
3-
if (require('../index').isNodeApiBuiltin) {
3+
if (require('../index').needsFlag) {
44
args.splice(0, 0, '--napi-modules');
55
}
66
return require('child_process').spawnSync(command, args, options);

0 commit comments

Comments
 (0)