Skip to content

Commit f797d14

Browse files
Gabriel "_|Nix|_" Schulhofjasongin
authored andcommitted
Include-path-juggle node_api.h instead of napi.h (#41) (#42)
Instead of making the path from which napi.h is included conditional upon the Node.js version, make the path of node_api.h thusly conditional. This way, no additional modification needs to be made to a dependent's binding.gyp in order to add the EXTERNAL_NAPI preprocessor directive when the C++ wrappers are not used. By this mechanism the C++ wrapper napi.h will also refer to the correct version of node_api.h. Fixes #41
1 parent 16fc9a5 commit f797d14

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ To use N-API in a native module:
2222

2323
2. Reference this package's include directory and gyp file in `binding.gyp`:
2424
```gyp
25-
'include_dirs': ["<!(node -p \"require('node-addon-api').include\")"],
25+
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
2626
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
2727
```
2828

external-napi/node_api.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef EXTERNAL_NODE_API_H_
2+
#define EXTERNAL_NODE_API_H_
3+
4+
#define EXTERNAL_NAPI
5+
#include "../src/node_api.h"
6+
7+
#endif

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ var path = require('path');
44
// or detect presence of built-in N-API by some other mechanism TBD.
55
var isNodeApiBuiltin = process.versions.modules >= 52; // Node 8.x
66

7-
var include = __dirname;
7+
var include = path.join(__dirname, 'src');
88
var gyp = path.join(__dirname, 'src', 'node_api.gyp');
99

1010
if (isNodeApiBuiltin) {
1111
gyp += ':nothing';
1212
} else {
1313
gyp += ':node-api';
14-
include = path.join(__dirname, 'src');
14+
include = path.join(__dirname, 'external-napi');
1515
}
1616

1717
module.exports = {
18-
include: include,
18+
include: [ '"' + include + '"', '"' + __dirname + '"' ].join(' '),
1919
gyp: gyp,
2020
isNodeApiBuiltin: isNodeApiBuiltin,
2121
};

src/napi.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)