From 3b4c7bb736a924d13d1a541ee401f6ccc5ffda79 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 31 Oct 2025 14:57:27 +0100 Subject: [PATCH 1/2] src: move Node-API version detection to where it is used `src/js_native_api_types.h` and other files actually depend on the moved macros being evaluated, so before this change there was an implicit requirement that `src/js_native_api.h` would be included separately before any include of `src/js_native_api_types.h`, direct or transitive. --- src/js_native_api.h | 28 ---------------------------- src/js_native_api_types.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/js_native_api.h b/src/js_native_api.h index 4e211128d5ada6..f979720b0caeab 100644 --- a/src/js_native_api.h +++ b/src/js_native_api.h @@ -5,34 +5,6 @@ #include // NOLINT(modernize-deprecated-headers) #include // NOLINT(modernize-deprecated-headers) -// Use INT_MAX, this should only be consumed by the pre-processor anyway. -#define NAPI_VERSION_EXPERIMENTAL 2147483647 -#ifndef NAPI_VERSION -#ifdef NAPI_EXPERIMENTAL -#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL -#else -// The baseline version for N-API. -// The NAPI_VERSION controls which version will be used by default when -// compilling a native addon. If the addon developer specifically wants to use -// functions available in a new version of N-API that is not yet ported in all -// LTS versions, they can set NAPI_VERSION knowing that they have specifically -// depended on that version. -#define NAPI_VERSION 8 -#endif -#endif - -#if defined(NAPI_EXPERIMENTAL) && \ - !defined(NODE_API_EXPERIMENTAL_NO_WARNING) && \ - !defined(NODE_WANT_INTERNALS) -#ifdef _MSC_VER -#pragma message("NAPI_EXPERIMENTAL is enabled. " \ - "Experimental features may be unstable.") -#else -#warning "NAPI_EXPERIMENTAL is enabled. " \ - "Experimental features may be unstable." -#endif -#endif - #include "js_native_api_types.h" // If you need __declspec(dllimport), either include instead, or diff --git a/src/js_native_api_types.h b/src/js_native_api_types.h index 43e7bb77ff94e7..eaae231b4dd4db 100644 --- a/src/js_native_api_types.h +++ b/src/js_native_api_types.h @@ -1,6 +1,34 @@ #ifndef SRC_JS_NATIVE_API_TYPES_H_ #define SRC_JS_NATIVE_API_TYPES_H_ +// Use INT_MAX, this should only be consumed by the pre-processor anyway. +#define NAPI_VERSION_EXPERIMENTAL 2147483647 +#ifndef NAPI_VERSION +#ifdef NAPI_EXPERIMENTAL +#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL +#else +// The baseline version for N-API. +// The NAPI_VERSION controls which version will be used by default when +// compilling a native addon. If the addon developer specifically wants to use +// functions available in a new version of N-API that is not yet ported in all +// LTS versions, they can set NAPI_VERSION knowing that they have specifically +// depended on that version. +#define NAPI_VERSION 8 +#endif +#endif + +#if defined(NAPI_EXPERIMENTAL) && \ + !defined(NODE_API_EXPERIMENTAL_NO_WARNING) && \ + !defined(NODE_WANT_INTERNALS) +#ifdef _MSC_VER +#pragma message("NAPI_EXPERIMENTAL is enabled. " \ + "Experimental features may be unstable.") +#else +#warning "NAPI_EXPERIMENTAL is enabled. " \ + "Experimental features may be unstable." +#endif +#endif + // This file needs to be compatible with C compilers. // This is a public include file, and these includes have essentially // became part of it's API. From ee3fb636b08a24a78ec236783d1828ac6ffee615 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 31 Oct 2025 14:59:37 +0100 Subject: [PATCH 2/2] src: move `napi_addon_register_func` to `node_api_types.h` This means that `node.h` can include only this file, instead of the entirety of `node_api.h`. Split out from https://github.com/nodejs/node/pull/60496 since it was rightfully pointed out that the breaking part of the change should not touch Node-API headers. --- src/node_api.h | 4 ---- src/node_api_types.h | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/node_api.h b/src/node_api.h index 35e5c3e49dd426..46dbb02b47d24b 100644 --- a/src/node_api.h +++ b/src/node_api.h @@ -33,10 +33,6 @@ struct uv_loop_s; // Forward declaration. #define NAPI_NO_RETURN #endif -typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env, - napi_value exports); -typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void); - // Used by deprecated registration method napi_module_register. typedef struct napi_module { int nm_version; diff --git a/src/node_api_types.h b/src/node_api_types.h index 9c2f03f4d09c08..2580f15c030d22 100644 --- a/src/node_api_types.h +++ b/src/node_api_types.h @@ -3,6 +3,10 @@ #include "js_native_api_types.h" +typedef napi_value(NAPI_CDECL* napi_addon_register_func)(napi_env env, + napi_value exports); +typedef int32_t(NAPI_CDECL* node_api_addon_get_api_version_func)(void); + typedef struct napi_callback_scope__* napi_callback_scope; typedef struct napi_async_context__* napi_async_context; typedef struct napi_async_work__* napi_async_work;