From 0668a75c39255c9ee96120601410a08ce062160f Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Tue, 9 Jan 2018 15:06:28 -0500 Subject: [PATCH] n-api: expose n-api version in process.versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expose n-api version in process.versions so that it is available for use in javascript by external modules like node-pre-gyp. It was previously accessible through a functon available in the N-API. PR-URL: https://github.com/nodejs/node/pull/18067 Reviewed-By: Anna Henningsen Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel Reviewed-By: Colin Ihrig Reviewed-By: Minwoo Jung Reviewed-By: Gibson Fahnestock Reviewed-By: Tobias Nießn Reviewed-By: Richard Lau --- src/node.cc | 6 ++++++ src/node_api.cc | 2 -- src/node_version.h | 3 +++ test/parallel/test-process-versions.js | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/node.cc b/src/node.cc index 55e5ad3dd71a75..def2b6148776aa 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3368,6 +3368,12 @@ void SetupProcessObject(Environment* env, "nghttp2", FIXED_ONE_BYTE_STRING(env->isolate(), NGHTTP2_VERSION)); + const char node_napi_version[] = NODE_STRINGIFY(NAPI_VERSION); + READONLY_PROPERTY( + versions, + "napi", + FIXED_ONE_BYTE_STRING(env->isolate(), node_napi_version)); + // process._promiseRejectEvent Local promiseRejectEvent = Object::New(env->isolate()); READONLY_DONT_ENUM_PROPERTY(process, diff --git a/src/node_api.cc b/src/node_api.cc index 095f98f64f4e77..2101fcba020d95 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -18,8 +18,6 @@ #include "node_api.h" #include "node_internals.h" -#define NAPI_VERSION 2 - static napi_status napi_set_last_error(napi_env env, napi_status error_code, uint32_t engine_error_code = 0, diff --git a/src/node_version.h b/src/node_version.h index aa271549247d15..7e7a164bf9bc7b 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -108,4 +108,7 @@ */ #define NODE_MODULE_VERSION 59 +// the NAPI_VERSION provided by this version of the runtime +#define NAPI_VERSION 2 + #endif // SRC_NODE_VERSION_H_ diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index 5644ac4658b534..8f706c6954cd2c 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -3,7 +3,7 @@ const common = require('../common'); const assert = require('assert'); const expected_keys = ['ares', 'http_parser', 'modules', 'node', - 'uv', 'v8', 'zlib', 'nghttp2']; + 'uv', 'v8', 'zlib', 'nghttp2', 'napi']; if (common.hasCrypto) { expected_keys.push('openssl');