Skip to content

Commit da272c6

Browse files
committed
src: include node_api_types.h instead of node_api.h in node.h
Including `node.h` should not result in all of Node-API also being available to callers. Users who want `node_api.h` contents should explicitly include that header. We currently include it specifically for `napi_addon_register_func`; by moving that into `node_api_types.h` and including that instead, we can reduce unintentionally included API surface a lot. Refs: #60345 (comment)
1 parent bdf03bf commit da272c6

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
#include "v8-platform.h" // NOLINT(build/include_order)
7777
#include "node_version.h" // NODE_MODULE_VERSION
7878

79-
#include "node_api.h"
79+
#include "node_api_types.h" // napi_addon_register_func
8080

8181
#include <functional>
8282
#include <memory>

src/node_api.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ struct uv_loop_s; // Forward declaration.
3333
#define NAPI_NO_RETURN
3434
#endif
3535

36-
typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
37-
napi_value exports);
38-
typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
39-
4036
// Used by deprecated registration method napi_module_register.
4137
typedef struct napi_module {
4238
int nm_version;

src/node_api_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#include "js_native_api_types.h"
55

6+
typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env,
7+
napi_value exports);
8+
typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void);
9+
610
typedef struct napi_callback_scope__* napi_callback_scope;
711
typedef struct napi_async_context__* napi_async_context;
812
typedef struct napi_async_work__* napi_async_work;

0 commit comments

Comments
 (0)