Skip to content

Commit 9a1e9c0

Browse files
committed
Clean up include path and flag-check
node_api.h must be included from the normal node include path when we can use the built-in API. The variable needsFlag must be true from version 8.0.0 inclusive until version 8.6.0 non-inclusive. PR-URL: nodejs/node-addon-api#152 Fixes: nodejs/node-addon-api#139 Reviewed-By: Michael Dawson <[email protected]>
1 parent 9709cef commit 9a1e9c0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,26 @@ var versionArray = process.version
1717
var isNodeApiBuiltin =
1818
(versionArray[0] > 8 || (versionArray[0] == 8 && versionArray[1] > 5));
1919

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);
20+
// The flag is not needed when the Node version is not 8, nor if the API is
21+
// built-in, because we removed the flag at the same time as creating the final
22+
// incarnation of the built-in API.
23+
var needsFlag = (!isNodeApiBuiltin && versionArray[0] == 8);
2324

24-
var include = path.join(__dirname, 'src');
25+
var include = [__dirname];
2526
var gyp = path.join(__dirname, 'src', 'node_api.gyp');
2627

2728
if (isNodeApiBuiltin) {
28-
gyp += ':nothing';
29+
gyp += ':nothing';
2930
} else {
30-
gyp += ':node-api';
31-
include = path.join(__dirname, 'external-napi');
31+
gyp += ':node-api';
32+
include.unshift(path.join(__dirname, 'external-napi'));
3233
}
3334

3435
module.exports = {
35-
include: [ '"' + include + '"', '"' + __dirname + '"' ].join(' '),
36-
gyp: gyp,
37-
isNodeApiBuiltin: isNodeApiBuiltin,
38-
needsFlag: needsFlag
36+
include: include.map(function(item) {
37+
return '"' + item + '"';
38+
}).join(' '),
39+
gyp: gyp,
40+
isNodeApiBuiltin: isNodeApiBuiltin,
41+
needsFlag: needsFlag
3942
};

0 commit comments

Comments
 (0)