From baef0468ed8fd6be79debd42be79646b6c3236eb Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 31 Oct 2025 14:57:27 +0100 Subject: [PATCH] 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. PR-URL: https://github.com/nodejs/node/pull/60512 Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig --- src/js_native_api.h | 16 ---------------- src/js_native_api_types.h | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/js_native_api.h b/src/js_native_api.h index 95b220cba1b..f979720b0ca 100644 --- a/src/js_native_api.h +++ b/src/js_native_api.h @@ -5,22 +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 - #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 43e7bb77ff9..e79a360d439 100644 --- a/src/js_native_api_types.h +++ b/src/js_native_api_types.h @@ -1,6 +1,22 @@ #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 + // 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.