Skip to content

Commit

Permalink
Include-path-juggle node_api.h instead of napi.h (#41) (#42)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Gabriel "_|Nix|_" Schulhof authored and jasongin committed May 23, 2017
1 parent 16fc9a5 commit f797d14
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ To use N-API in a native module:

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

Expand Down
7 changes: 7 additions & 0 deletions external-napi/node_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef EXTERNAL_NODE_API_H_
#define EXTERNAL_NODE_API_H_

#define EXTERNAL_NAPI
#include "../src/node_api.h"

#endif
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ var path = require('path');
// or detect presence of built-in N-API by some other mechanism TBD.
var isNodeApiBuiltin = process.versions.modules >= 52; // Node 8.x

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

if (isNodeApiBuiltin) {
gyp += ':nothing';
} else {
gyp += ':node-api';
include = path.join(__dirname, 'src');
include = path.join(__dirname, 'external-napi');
}

module.exports = {
include: include,
include: [ '"' + include + '"', '"' + __dirname + '"' ].join(' '),
gyp: gyp,
isNodeApiBuiltin: isNodeApiBuiltin,
};
2 changes: 0 additions & 2 deletions src/napi.h

This file was deleted.

0 comments on commit f797d14

Please sign in to comment.