koffi 3.0.1 → 3.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.
@@ -1,9 +1,9 @@
1
- // src/init.js
1
+ // src/koffi/src/init.js
2
2
  import util from "node:util";
3
3
  import fs2 from "node:fs";
4
4
  import { createRequire } from "node:module";
5
5
 
6
- // ../cnoke/src/abi.js
6
+ // src/cnoke/src/abi.js
7
7
  import fs from "node:fs";
8
8
  function determineAbi() {
9
9
  let abi = process.arch.toString();
@@ -93,11 +93,11 @@ function decodeElfHeader(buf) {
93
93
  return header;
94
94
  }
95
95
 
96
- // package.json
97
- var package_default = { name: "koffi", version: "3.0.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
96
+ // src/koffi/package.json
97
+ var package_default = { name: "koffi", version: "3.0.2", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
98
98
 
99
- // src/init.js
100
- var requireNative = createRequire(import.meta.url);
99
+ // src/koffi/src/init.js
100
+ var require2 = createRequire(import.meta.url);
101
101
  function detectPlatform() {
102
102
  if (process.versions.napi == null || process.versions.napi < package_default.cnoke.napi) {
103
103
  let major = parseInt(process.versions.node, 10);
@@ -110,13 +110,20 @@ function detectPlatform() {
110
110
  triplets2.push(`musl_${abi}`);
111
111
  return [package_default.version, pkg2, triplets2];
112
112
  }
113
- function loadDynamic(root, pkg2, triplets2) {
113
+ function loadDynamic(dirname, pkg2, triplets2) {
114
+ let suffix = "/../../build/koffi";
115
+ let root = dirname + suffix;
114
116
  let roots = [root];
115
117
  let native2 = null;
116
118
  let err = null;
117
119
  if (process["resourcesPath"] != null) {
118
- roots.push(process["resourcesPath"]);
119
- roots.push(process["resourcesPath"] + "/node_modules/koffi");
120
+ let suffixes = [
121
+ "/koffi",
122
+ "/koffi/build",
123
+ "/node_modules/koffi/build"
124
+ ];
125
+ for (let suffix2 of suffixes)
126
+ roots.push(process["resourcesPath"] + suffix2);
120
127
  }
121
128
  let names = [
122
129
  `${import.meta.dirname}/../../../@koromix/koffi-${pkg2}`,
@@ -126,19 +133,21 @@ function loadDynamic(root, pkg2, triplets2) {
126
133
  if (!fs2.existsSync(name))
127
134
  continue;
128
135
  try {
129
- native2 = requireNative(name);
136
+ native2 = require2(name);
130
137
  break;
131
138
  } catch (e) {
132
139
  err ??= e;
133
140
  }
134
141
  }
135
- if (native2 == null) {
136
- err ??= new Error("Cannot find the native Koffi module; did you bundle it correctly?");
142
+ if (native2 == null && err != null)
137
143
  throw err;
138
- }
139
144
  return native2;
140
145
  }
141
- function wrapNative(native2) {
146
+ function wrapNative(native2, version2) {
147
+ if (native2 == null)
148
+ throw new Error("Cannot find the native Koffi module; did you bundle it correctly?");
149
+ if (native2.version != version2)
150
+ throw new Error("Mismatched native Koffi modules");
142
151
  let load = native2.load;
143
152
  let register = native2.register;
144
153
  let introspect = native2.introspect ?? native2.type;
@@ -177,19 +186,10 @@ function wrapNative(native2) {
177
186
  }
178
187
  }
179
188
 
180
- // src/static.js
181
- import { createRequire as createRequire2 } from "node:module";
182
- var requireNative2 = createRequire2(import.meta.url);
183
- var BINARY_ROOT = import.meta.dirname + "/../../build/koffi";
184
-
185
- // index.js
189
+ // src/koffi/indirect.js
186
190
  var [version, pkg, triplets] = detectPlatform();
187
- var native = null;
188
- if (native == null)
189
- native = loadDynamic(BINARY_ROOT, pkg, triplets);
190
- if (native.version != version)
191
- throw new Error("Mismatched native Koffi modules");
192
- wrapNative(native);
191
+ var native = loadDynamic(import.meta.dirname, pkg, triplets);
192
+ wrapNative(native, version);
193
193
  var mod_LibraryHandle = native.LibraryHandle;
194
194
  var mod_TypeObject = native.TypeObject;
195
195
  var mod_Union = native.Union;
@@ -232,7 +232,7 @@ var mod_union = native.union;
232
232
  var mod_unregister = native.unregister;
233
233
  var mod_version = native.version;
234
234
  var mod_view = native.view;
235
- var index_default = native;
235
+ var indirect_default = native;
236
236
  export {
237
237
  mod_LibraryHandle as LibraryHandle,
238
238
  mod_TypeObject as TypeObject,
@@ -246,7 +246,7 @@ export {
246
246
  mod_call as call,
247
247
  mod_config as config,
248
248
  mod_decode as decode,
249
- index_default as default,
249
+ indirect_default as default,
250
250
  mod_disposable as disposable,
251
251
  mod_encode as encode,
252
252
  mod_enumeration as enumeration,
@@ -6,6 +6,7 @@
6
6
  #include "lib/native/base/base.hh"
7
7
  #include "../ffi.hh"
8
8
  #include "../call.hh"
9
+ #include "../type.hh"
9
10
  #include "../util.hh"
10
11
  #if defined(_WIN32)
11
12
  #include "../win32.hh"
@@ -6,6 +6,7 @@
6
6
  #include "lib/native/base/base.hh"
7
7
  #include "../ffi.hh"
8
8
  #include "../call.hh"
9
+ #include "../type.hh"
9
10
  #include "../util.hh"
10
11
 
11
12
  #include <napi.h>
@@ -6,6 +6,7 @@
6
6
  #include "lib/native/base/base.hh"
7
7
  #include "../ffi.hh"
8
8
  #include "../call.hh"
9
+ #include "../type.hh"
9
10
  #include "../util.hh"
10
11
 
11
12
  #include <napi.h>
@@ -6,6 +6,7 @@
6
6
  #include "lib/native/base/base.hh"
7
7
  #include "../ffi.hh"
8
8
  #include "../call.hh"
9
+ #include "../type.hh"
9
10
  #include "../util.hh"
10
11
  #include "../win32.hh"
11
12
 
@@ -6,6 +6,7 @@
6
6
  #include "lib/native/base/base.hh"
7
7
  #include "../ffi.hh"
8
8
  #include "../call.hh"
9
+ #include "../type.hh"
9
10
  #include "../util.hh"
10
11
  #if defined(_WIN32)
11
12
  #include "../win32.hh"