@auto_js/napi_exports 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CMakeLists.txt CHANGED
@@ -7,6 +7,12 @@ if(NOT DEFINED NAPI_VERSION)
7
7
  endif()
8
8
  target_compile_definitions(nodejs PUBLIC "NAPI_VERSION=${NAPI_VERSION}")
9
9
 
10
+ # Architecture, for window linkage
11
+ string(TOLOWER ${CMAKE_HOST_SYSTEM_PROCESSOR} NODE_ARCH)
12
+ if(NODE_ARCH STREQUAL amd64)
13
+ set(NODE_ARCH x64)
14
+ endif()
15
+
10
16
  # Acquire or locate nodejs headers
11
17
  if(NOT DEFINED NODE_DIST_DIR)
12
18
  if(DEFINED ENV{NODE_DIST_DIR})
@@ -16,20 +22,46 @@ if(NOT DEFINED NODE_DIST_DIR)
16
22
  endif()
17
23
  endif()
18
24
  if(NOT DEFINED NODE_DIST_DIR)
25
+ if(DEFINED ENV{NODE_VERSION})
26
+ set(NODE_VERSION "$ENV{NODE_VERSION}")
27
+ message(STATUS "Using Node.js version '${NODE_VERSION}'")
28
+ else()
29
+ execute_process(COMMAND sh -c "node -v | cut -c2-" OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE NODE_VERSION RESULT_VARIABLE RESULT)
30
+ if(NOT RESULT STREQUAL 0)
31
+ message(FATAL_ERROR "nodejs version not set" )
32
+ endif()
33
+ message(STATUS "Detected Node.js version '${NODE_VERSION}'")
34
+ endif()
35
+ set(NODE_HEADERS_URL "https://nodejs.org/download/release/v${NODE_VERSION}/node-v${NODE_VERSION}-headers.tar.gz")
36
+ message(STATUS "Downloading Node.js headers from '${NODE_HEADERS_URL}'")
19
37
  include(FetchContent)
20
- FetchContent_Declare(
21
- node_headers
22
- URL https://nodejs.org/download/release/v24.0.0/node-v24.0.0-headers.tar.gz
23
- )
38
+ # So much searching to find this 'DOWNLOAD_NO_PROGRESS' option. It's not documented under
39
+ # FetchContent, oh no this is actually an ExternalProject option, you see.
40
+ FetchContent_Declare(node_headers URL "${NODE_HEADERS_URL}" DOWNLOAD_NO_PROGRESS TRUE)
24
41
  FetchContent_MakeAvailable(node_headers)
25
42
  set(NODE_DIST_DIR "${node_headers_SOURCE_DIR}" CACHE STRING "")
43
+ if(WIN32)
44
+ file(DOWNLOAD "https://nodejs.org/download/release/v${NODE_VERSION}/win-${NODE_ARCH}/node.lib" "${NODE_DIST_DIR}/win-${NODE_ARCH}/node.lib")
45
+ endif()
26
46
  endif()
27
47
  if(NOT EXISTS "${NODE_DIST_DIR}/include/node/node.h")
28
- message(FATAL_ERROR "Missing ${NODE_DIST_DIR}/include/node/node.h")
48
+ message(FATAL_ERROR "Missing '${NODE_DIST_DIR}/include/node/node.h'")
29
49
  endif()
30
50
  message(STATUS "Using Node.js headers from '${NODE_DIST_DIR}'")
51
+
52
+ # Configuration
31
53
  target_include_directories(nodejs SYSTEM PUBLIC "${NODE_DIST_DIR}/include/node")
54
+ if(WIN32)
55
+ if(EXISTS "${NODE_DIST_DIR}/win-${NODE_ARCH}/node.lib")
56
+ target_link_directories(nodejs PUBLIC "${NODE_DIST_DIR}/win-${NODE_ARCH}")
57
+ else()
58
+ message(WARNING "Missing '${NODE_DIST_DIR}/win-${NODE_ARCH}/node.lib'")
59
+ endif()
60
+ # nb: `winmm` for `js_clock::now()`
61
+ target_link_libraries(nodejs PUBLIC node winmm)
62
+ endif()
32
63
 
64
+ # Sources
33
65
  target_sources(nodejs
34
66
  PUBLIC FILE_SET CXX_MODULES FILES
35
67
  js_native_api_types.cc
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2017 Marcel Laverdet
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
package/js_native_api.cc CHANGED
@@ -1,4 +1,6 @@
1
1
  module;
2
+ #include "version.h"
3
+ // https://nodejs.org/api/n-api.html
2
4
  #include <js_native_api.h>
3
5
  export module nodejs:js_native_api;
4
6
  // NOLINTBEGIN(misc-unused-using-decls)
@@ -9,11 +11,14 @@ export using ::napi_check_object_type_tag;
9
11
  export using ::napi_close_handle_scope;
10
12
  export using ::napi_coerce_to_bool;
11
13
  export using ::napi_coerce_to_object;
14
+ export using ::napi_coerce_to_string;
12
15
  export using ::napi_create_array_with_length;
13
16
  export using ::napi_create_array;
17
+ export using ::napi_create_arraybuffer;
14
18
  export using ::napi_create_bigint_int64;
15
19
  export using ::napi_create_bigint_uint64;
16
20
  export using ::napi_create_bigint_words;
21
+ export using ::napi_create_dataview;
17
22
  export using ::napi_create_date;
18
23
  export using ::napi_create_double;
19
24
  export using ::napi_create_error;
@@ -29,14 +34,18 @@ export using ::napi_create_string_latin1;
29
34
  export using ::napi_create_string_utf16;
30
35
  export using ::napi_create_string_utf8;
31
36
  export using ::napi_create_type_error;
37
+ export using ::napi_create_typedarray;
32
38
  export using ::napi_create_uint32;
33
39
  export using ::napi_define_class;
34
40
  export using ::napi_define_properties;
35
41
  export using ::napi_delete_reference;
42
+ export using ::napi_get_all_property_names;
36
43
  export using ::napi_get_and_clear_last_exception;
37
44
  export using ::napi_get_array_length;
45
+ export using ::napi_get_arraybuffer_info;
38
46
  export using ::napi_get_boolean;
39
47
  export using ::napi_get_cb_info;
48
+ export using ::napi_get_dataview_info;
40
49
  export using ::napi_get_date_value;
41
50
  export using ::napi_get_element;
42
51
  export using ::napi_get_instance_data;
@@ -44,6 +53,7 @@ export using ::napi_get_null;
44
53
  export using ::napi_get_property_names;
45
54
  export using ::napi_get_property;
46
55
  export using ::napi_get_reference_value;
56
+ export using ::napi_get_typedarray_info;
47
57
  export using ::napi_get_undefined;
48
58
  export using ::napi_get_value_bigint_int64;
49
59
  export using ::napi_get_value_bigint_uint64;
@@ -59,8 +69,11 @@ export using ::napi_get_value_string_utf8;
59
69
  export using ::napi_get_value_uint32;
60
70
  export using ::napi_has_own_property;
61
71
  export using ::napi_is_array;
72
+ export using ::napi_is_arraybuffer;
73
+ export using ::napi_is_dataview;
62
74
  export using ::napi_is_date;
63
75
  export using ::napi_is_promise;
76
+ export using ::napi_is_typedarray;
64
77
  export using ::napi_new_instance;
65
78
  export using ::napi_open_handle_scope;
66
79
  export using ::napi_reference_ref;
@@ -69,6 +82,7 @@ export using ::napi_reject_deferred;
69
82
  export using ::napi_resolve_deferred;
70
83
  export using ::napi_set_element;
71
84
  export using ::napi_set_instance_data;
85
+ export using ::napi_set_named_property;
72
86
  export using ::napi_set_property;
73
87
  export using ::napi_throw_type_error;
74
88
  export using ::napi_throw;
@@ -1,4 +1,5 @@
1
1
  module;
2
+ #include "version.h"
2
3
  #include <js_native_api_types.h>
3
4
  export module nodejs:js_native_api_types;
4
5
  // NOLINTBEGIN(misc-unused-using-decls)
@@ -21,33 +22,32 @@ export using ::napi_type_tag;
21
22
  export using ::node_api_basic_finalize;
22
23
  export using ::node_api_nogc_finalize;
23
24
 
24
- // napi_valuetype
25
- export using ::napi_valuetype;
26
- export using ::napi_bigint;
27
- export using ::napi_boolean;
28
- export using ::napi_external;
29
- export using ::napi_function;
30
- export using ::napi_null;
31
- export using ::napi_number;
32
- export using ::napi_object;
33
- export using ::napi_string;
34
- export using ::napi_symbol;
35
- export using ::napi_undefined;
25
+ // napi_key_collection_mode
26
+ export using ::napi_key_collection_mode;
27
+ export using ::napi_key_include_prototypes;
28
+ export using ::napi_key_own_only;
36
29
 
37
- // napi_typedarray_type
38
- export using ::napi_typedarray_type;
39
- export using ::napi_bigint64_array;
40
- export using ::napi_biguint64_array;
41
- export using ::napi_float32_array;
42
- export using ::napi_float64_array;
43
- export using ::napi_int16_array;
44
- export using ::napi_int32_array;
45
- export using ::napi_int8_array;
46
- export using ::napi_typedarray_type;
47
- export using ::napi_uint16_array;
48
- export using ::napi_uint32_array;
49
- export using ::napi_uint8_array;
50
- export using ::napi_uint8_clamped_array;
30
+ // napi_key_conversion
31
+ export using ::napi_key_conversion;
32
+ export using ::napi_key_keep_numbers;
33
+ export using ::napi_key_numbers_to_strings;
34
+
35
+ // napi_key_filter
36
+ export using ::napi_key_filter;
37
+ export using ::napi_key_all_properties;
38
+ export using ::napi_key_configurable;
39
+ export using ::napi_key_enumerable;
40
+ export using ::napi_key_skip_strings;
41
+ export using ::napi_key_skip_symbols;
42
+ export using ::napi_key_writable;
43
+
44
+ // napi_property_attributes
45
+ export using ::napi_property_attributes;
46
+ export using ::napi_default;
47
+ export using ::napi_writable;
48
+ export using ::napi_enumerable;
49
+ export using ::napi_configurable;
50
+ export using ::napi_static;
51
51
 
52
52
  // napi_status
53
53
  export using ::napi_status;
@@ -76,12 +76,36 @@ export using ::napi_queue_full;
76
76
  export using ::napi_string_expected;
77
77
  export using ::napi_would_deadlock;
78
78
 
79
- // napi_property_attributes
80
- export using ::napi_property_attributes;
81
- export using ::napi_default;
82
- export using ::napi_writable;
83
- export using ::napi_enumerable;
84
- export using ::napi_configurable;
85
- export using ::napi_static;
79
+ // napi_typedarray_type
80
+ export using ::napi_typedarray_type;
81
+ export using ::napi_bigint64_array;
82
+ export using ::napi_biguint64_array;
83
+ export using ::napi_float32_array;
84
+ export using ::napi_float64_array;
85
+ export using ::napi_int16_array;
86
+ export using ::napi_int32_array;
87
+ export using ::napi_int8_array;
88
+ export using ::napi_uint16_array;
89
+ export using ::napi_uint32_array;
90
+ export using ::napi_uint8_array;
91
+ export using ::napi_uint8_clamped_array;
92
+ #if NODE_VERSION_AT_LEAST(25, 5, 0) || NODE_EQ_VERSION_AT_LEAST(24, 13, 1)
93
+ export using ::napi_float16_array;
94
+ #else
95
+ export constexpr auto napi_float16_array = static_cast<napi_typedarray_type>(napi_biguint64_array + 1);
96
+ #endif
97
+
98
+ // napi_valuetype
99
+ export using ::napi_valuetype;
100
+ export using ::napi_bigint;
101
+ export using ::napi_boolean;
102
+ export using ::napi_external;
103
+ export using ::napi_function;
104
+ export using ::napi_null;
105
+ export using ::napi_number;
106
+ export using ::napi_object;
107
+ export using ::napi_string;
108
+ export using ::napi_symbol;
109
+ export using ::napi_undefined;
86
110
 
87
111
  // NOLINTEND(misc-unused-using-decls)
package/node_api.cc CHANGED
@@ -1,8 +1,13 @@
1
1
  module;
2
+ #include "version.h"
2
3
  #include <node_api.h>
3
4
  export module nodejs:node_api;
4
5
  // NOLINTBEGIN(misc-unused-using-decls)
5
6
 
7
+ export using ::napi_add_async_cleanup_hook;
8
+ export using ::napi_add_env_cleanup_hook;
9
+ export using ::napi_async_cleanup_hook_handle;
6
10
  export using ::napi_get_uv_event_loop;
11
+ export using ::napi_remove_async_cleanup_hook;
7
12
 
8
13
  // NOLINTEND(misc-unused-using-decls)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auto_js/napi_exports",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "C++ module exports for nodejs & n-api",
5
5
  "author": "https://github.com/laverdet/",
6
6
  "homepage": "https://github.com/laverdet/isolated-vm/tree/experimental/packages/third_party/nodejs",
@@ -9,4 +9,4 @@
9
9
  "type": "git",
10
10
  "url": "git+https://github.com/laverdet/isolated-vm.git"
11
11
  }
12
- }
12
+ }
package/uv.cc CHANGED
@@ -1,4 +1,5 @@
1
1
  module;
2
+ #include "version.h"
2
3
  #include <uv.h>
3
4
  export module nodejs:uv;
4
5
 
@@ -7,11 +8,16 @@ export module nodejs:uv;
7
8
  export using ::uv_async_t;
8
9
  export using ::uv_handle_t;
9
10
  export using ::uv_handle_type;
11
+ export using ::uv_lib_t;
10
12
  export using ::uv_loop_t;
11
13
 
12
14
  export using ::uv_async_init;
13
15
  export using ::uv_async_send;
14
16
  export using ::uv_close;
17
+ export using ::uv_dlclose;
18
+ export using ::uv_dlerror;
19
+ export using ::uv_dlopen;
20
+ export using ::uv_dlsym;
15
21
  export using ::uv_is_active;
16
22
  export using ::uv_ref;
17
23
  export using ::uv_unref;
package/version.h ADDED
@@ -0,0 +1,10 @@
1
+ #include "node_version.h"
2
+ static_assert(NAPI_VERSION <= NODE_API_SUPPORTED_VERSION_MAX, "NAPI version mismatch");
3
+
4
+ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
5
+ #define NODE_EQ_VERSION_AT_LEAST(major, minor, patch) \
6
+ (((major) == NODE_MAJOR_VERSION && (minor) < NODE_MINOR_VERSION) || \
7
+ ((major) == NODE_MAJOR_VERSION && (minor) == NODE_MINOR_VERSION && (patch) <= NODE_PATCH_VERSION))
8
+
9
+ static_assert(NAPI_VERSION >= 10);
10
+ static_assert(NODE_VERSION_AT_LEAST(23, 6, 0) || NODE_EQ_VERSION_AT_LEAST(22, 14, 0));