koffi 3.0.1 → 3.1.0

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +32 -3
  2. package/cnoke.cjs +2 -2
  3. package/doc/benchmarks.md +1 -1
  4. package/doc/callbacks.md +7 -26
  5. package/doc/{input.md → composites.md} +161 -147
  6. package/doc/contribute.md +3 -2
  7. package/doc/index.md +0 -14
  8. package/doc/{functions.md → load.md} +54 -113
  9. package/doc/migration.md +4 -7
  10. package/doc/misc.md +0 -103
  11. package/doc/output.md +5 -11
  12. package/doc/pointers.md +76 -17
  13. package/doc/primitives.md +151 -0
  14. package/doc/start.md +3 -13
  15. package/doc/types.md +88 -0
  16. package/doc/unions.md +0 -186
  17. package/doc/values.md +134 -0
  18. package/index.d.ts +375 -308
  19. package/lib/native/base/base.cc +66 -24
  20. package/lib/native/base/base.hh +55 -153
  21. package/package.json +16 -16
  22. package/src/koffi/CMakeLists.txt +20 -17
  23. package/src/koffi/index.cjs +30 -111
  24. package/src/koffi/index.js +22 -96
  25. package/src/koffi/indirect.cjs +30 -111
  26. package/src/koffi/indirect.js +24 -24
  27. package/src/koffi/src/abi/arm64.cc +48 -62
  28. package/src/koffi/src/abi/riscv64.cc +39 -57
  29. package/src/koffi/src/abi/x64sysv.cc +39 -57
  30. package/src/koffi/src/abi/x64win.cc +48 -65
  31. package/src/koffi/src/abi/x86.cc +47 -59
  32. package/src/koffi/src/call.cc +426 -209
  33. package/src/koffi/src/call.hh +7 -11
  34. package/src/koffi/src/ffi.cc +534 -303
  35. package/src/koffi/src/ffi.hh +71 -15
  36. package/src/koffi/src/parser.cc +5 -3
  37. package/src/koffi/src/parser.hh +2 -2
  38. package/src/koffi/src/static.cjs +122 -0
  39. package/src/koffi/src/static.js +125 -0
  40. package/src/koffi/src/type.cc +725 -0
  41. package/src/koffi/src/type.hh +71 -0
  42. package/src/koffi/src/util.cc +117 -1202
  43. package/src/koffi/src/util.hh +158 -156
  44. package/src/koffi/src/uv.cc +17 -11
  45. package/src/koffi/src/uv.hh +2 -1
  46. package/vendor/node-addon-api/README.md +1 -1
  47. package/vendor/node-addon-api/napi-inl.h +213 -35
  48. package/vendor/node-addon-api/napi.h +118 -7
  49. package/doc/variables.md +0 -102
  50. package/indirect.d.ts +0 -322
@@ -4,11 +4,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
7
+ var __esm = (fn, res, err) => function __init() {
8
+ if (err) throw err[0];
9
+ try {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ } catch (e) {
12
+ throw err = [e], e;
13
+ }
12
14
  };
13
15
  var __export = (target, all) => {
14
16
  for (var name in all)
@@ -131,7 +133,7 @@ var init_abi = __esm({
131
133
  var package_default;
132
134
  var init_package = __esm({
133
135
  "package.json"() {
134
- package_default = { name: "koffi", version: "3.0.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
136
+ package_default = { name: "koffi", version: "3.1.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
135
137
  }
136
138
  });
137
139
 
@@ -154,13 +156,20 @@ function detectPlatform() {
154
156
  triplets2.push(`musl_${abi}`);
155
157
  return [package_default.version, pkg2, triplets2];
156
158
  }
157
- function loadDynamic(root, pkg2, triplets2) {
159
+ function loadDynamic(dirname, pkg2, triplets2) {
160
+ let suffix = "/../../build/koffi";
161
+ let root = dirname + suffix;
158
162
  let roots = [root];
159
163
  let native2 = null;
160
164
  let err = null;
161
165
  if (process["resourcesPath"] != null) {
162
- roots.push(process["resourcesPath"]);
163
- roots.push(process["resourcesPath"] + "/node_modules/koffi");
166
+ let suffixes = [
167
+ "/koffi",
168
+ "/koffi/build",
169
+ "/node_modules/koffi/build"
170
+ ];
171
+ for (let suffix2 of suffixes)
172
+ roots.push(process["resourcesPath"] + suffix2);
164
173
  }
165
174
  let names = [
166
175
  `${__dirname}/../../../@koromix/koffi-${pkg2}`,
@@ -170,19 +179,21 @@ function loadDynamic(root, pkg2, triplets2) {
170
179
  if (!import_node_fs2.default.existsSync(name))
171
180
  continue;
172
181
  try {
173
- native2 = requireNative(name);
182
+ native2 = require2(name);
174
183
  break;
175
184
  } catch (e) {
176
185
  err ??= e;
177
186
  }
178
187
  }
179
- if (native2 == null) {
180
- err ??= new Error("Cannot find the native Koffi module; did you bundle it correctly?");
188
+ if (native2 == null && err != null)
181
189
  throw err;
182
- }
183
190
  return native2;
184
191
  }
185
- function wrapNative(native2) {
192
+ function wrapNative(native2, version2) {
193
+ if (native2 == null)
194
+ throw new Error("Cannot find the native Koffi module; did you bundle it correctly?");
195
+ if (native2.version != version2)
196
+ throw new Error("Mismatched native Koffi modules");
186
197
  let load = native2.load;
187
198
  let register = native2.register;
188
199
  let introspect = native2.introspect ?? native2.type;
@@ -220,7 +231,7 @@ function wrapNative(native2) {
220
231
  native2.resolve = native2.type;
221
232
  }
222
233
  }
223
- var import_node_util, import_node_fs2, import_node_module, requireNative;
234
+ var import_node_util, import_node_fs2, import_node_module, require2;
224
235
  var init_init = __esm({
225
236
  "src/init.js"() {
226
237
  import_node_util = __toESM(require("node:util"));
@@ -228,108 +239,16 @@ var init_init = __esm({
228
239
  import_node_module = require("node:module");
229
240
  init_abi();
230
241
  init_package();
231
- requireNative = (0, import_node_module.createRequire)(__filename);
232
- }
233
- });
234
-
235
- // src/static.js
236
- var require_static = __commonJS({
237
- "src/static.js"(exports2, module2) {
238
- var { createRequire: createRequire2 } = require("node:module");
239
- var requireNative2 = createRequire2(__filename);
240
- var BINARY_ROOT2 = __dirname + "/../../build/koffi";
241
- function loadStatic2(pkg2) {
242
- let native2 = null;
243
- try {
244
- if (pkg2 == "linux-arm64")
245
- native2 = requireNative2("../../../@koromix/koffi-linux-arm64");
246
- } catch (err) {
247
- }
248
- try {
249
- if (pkg2 == "linux-ia32")
250
- native2 = requireNative2("../../../@koromix/koffi-linux-ia32");
251
- } catch (err) {
252
- }
253
- try {
254
- if (pkg2 == "linux-x64")
255
- native2 = requireNative2("../../../@koromix/koffi-linux-x64");
256
- } catch (err) {
257
- }
258
- try {
259
- if (pkg2 == "linux-riscv64")
260
- native2 = requireNative2("../../../@koromix/koffi-linux-riscv64");
261
- } catch (err) {
262
- }
263
- try {
264
- if (pkg2 == "freebsd-ia32")
265
- native2 = requireNative2("../../../@koromix/koffi-freebsd-ia32");
266
- } catch (err) {
267
- }
268
- try {
269
- if (pkg2 == "freebsd-x64")
270
- native2 = requireNative2("../../../@koromix/koffi-freebsd-x64");
271
- } catch (err) {
272
- }
273
- try {
274
- if (pkg2 == "freebsd-arm64")
275
- native2 = requireNative2("../../../@koromix/koffi-freebsd-arm64");
276
- } catch (err) {
277
- }
278
- try {
279
- if (pkg2 == "openbsd-ia32")
280
- native2 = requireNative2("../../../@koromix/koffi-openbsd-ia32");
281
- } catch (err) {
282
- }
283
- try {
284
- if (pkg2 == "openbsd-x64")
285
- native2 = requireNative2("../../../@koromix/koffi-openbsd-x64");
286
- } catch (err) {
287
- }
288
- try {
289
- if (pkg2 == "win32-ia32")
290
- native2 = requireNative2("../../../@koromix/koffi-win32-ia32");
291
- } catch (err) {
292
- }
293
- try {
294
- if (pkg2 == "win32-x64")
295
- native2 = requireNative2("../../../@koromix/koffi-win32-x64");
296
- } catch (err) {
297
- }
298
- try {
299
- if (pkg2 == "darwin-x64")
300
- native2 = requireNative2("../../../@koromix/koffi-darwin-x64");
301
- } catch (err) {
302
- }
303
- try {
304
- if (pkg2 == "darwin-arm64")
305
- native2 = requireNative2("../../../@koromix/koffi-darwin-arm64");
306
- } catch (err) {
307
- }
308
- try {
309
- if (pkg2 == "linux-loong64")
310
- native2 = requireNative2("../../../@koromix/koffi-linux-loong64");
311
- } catch (err) {
312
- }
313
- return native2;
314
- }
315
- module2.exports = {
316
- BINARY_ROOT: BINARY_ROOT2,
317
- loadStatic: loadStatic2
318
- };
242
+ require2 = (0, import_node_module.createRequire)(__filename);
319
243
  }
320
244
  });
321
245
 
322
246
  // index.cjs
323
247
  var { detectPlatform: detectPlatform2, loadDynamic: loadDynamic2, wrapNative: wrapNative2 } = (init_init(), __toCommonJS(init_exports));
324
- var { BINARY_ROOT, loadStatic } = require_static();
248
+ var { loadStatic } = require("./src/static.cjs");
325
249
  var [version, pkg, triplets] = detectPlatform2();
326
- var native = null;
327
- STATIC: native = loadStatic(pkg);
328
- if (native == null)
329
- native = loadDynamic2(BINARY_ROOT, pkg, triplets);
330
- if (native.version != version)
331
- throw new Error("Mismatched native Koffi modules");
332
- wrapNative2(native);
250
+ var native = loadStatic(pkg) ?? loadDynamic2(__dirname, pkg, triplets);
251
+ wrapNative2(native, version);
333
252
  module.exports = {
334
253
  default: native,
335
254
  "LibraryHandle": native["LibraryHandle"],
@@ -94,10 +94,10 @@ function decodeElfHeader(buf) {
94
94
  }
95
95
 
96
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 } };
97
+ var package_default = { name: "koffi", version: "3.1.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
98
98
 
99
99
  // src/init.js
100
- var requireNative = createRequire(import.meta.url);
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,94 +186,11 @@ 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
- function loadStatic(pkg2) {
185
- let native2 = null;
186
- try {
187
- if (pkg2 == "linux-arm64")
188
- native2 = requireNative2("../../../@koromix/koffi-linux-arm64");
189
- } catch (err) {
190
- }
191
- try {
192
- if (pkg2 == "linux-ia32")
193
- native2 = requireNative2("../../../@koromix/koffi-linux-ia32");
194
- } catch (err) {
195
- }
196
- try {
197
- if (pkg2 == "linux-x64")
198
- native2 = requireNative2("../../../@koromix/koffi-linux-x64");
199
- } catch (err) {
200
- }
201
- try {
202
- if (pkg2 == "linux-riscv64")
203
- native2 = requireNative2("../../../@koromix/koffi-linux-riscv64");
204
- } catch (err) {
205
- }
206
- try {
207
- if (pkg2 == "freebsd-ia32")
208
- native2 = requireNative2("../../../@koromix/koffi-freebsd-ia32");
209
- } catch (err) {
210
- }
211
- try {
212
- if (pkg2 == "freebsd-x64")
213
- native2 = requireNative2("../../../@koromix/koffi-freebsd-x64");
214
- } catch (err) {
215
- }
216
- try {
217
- if (pkg2 == "freebsd-arm64")
218
- native2 = requireNative2("../../../@koromix/koffi-freebsd-arm64");
219
- } catch (err) {
220
- }
221
- try {
222
- if (pkg2 == "openbsd-ia32")
223
- native2 = requireNative2("../../../@koromix/koffi-openbsd-ia32");
224
- } catch (err) {
225
- }
226
- try {
227
- if (pkg2 == "openbsd-x64")
228
- native2 = requireNative2("../../../@koromix/koffi-openbsd-x64");
229
- } catch (err) {
230
- }
231
- try {
232
- if (pkg2 == "win32-ia32")
233
- native2 = requireNative2("../../../@koromix/koffi-win32-ia32");
234
- } catch (err) {
235
- }
236
- try {
237
- if (pkg2 == "win32-x64")
238
- native2 = requireNative2("../../../@koromix/koffi-win32-x64");
239
- } catch (err) {
240
- }
241
- try {
242
- if (pkg2 == "darwin-x64")
243
- native2 = requireNative2("../../../@koromix/koffi-darwin-x64");
244
- } catch (err) {
245
- }
246
- try {
247
- if (pkg2 == "darwin-arm64")
248
- native2 = requireNative2("../../../@koromix/koffi-darwin-arm64");
249
- } catch (err) {
250
- }
251
- try {
252
- if (pkg2 == "linux-loong64")
253
- native2 = requireNative2("../../../@koromix/koffi-linux-loong64");
254
- } catch (err) {
255
- }
256
- return native2;
257
- }
258
-
259
189
  // index.js
190
+ import { loadStatic } from "./src/static.js";
260
191
  var [version, pkg, triplets] = detectPlatform();
261
- var native = null;
262
- STATIC: native = loadStatic(pkg);
263
- if (native == null)
264
- native = loadDynamic(BINARY_ROOT, pkg, triplets);
265
- if (native.version != version)
266
- throw new Error("Mismatched native Koffi modules");
267
- wrapNative(native);
192
+ var native = loadStatic(pkg) ?? loadDynamic(import.meta.dirname, pkg, triplets);
193
+ wrapNative(native, version);
268
194
  var mod_LibraryHandle = native.LibraryHandle;
269
195
  var mod_TypeObject = native.TypeObject;
270
196
  var mod_Union = native.Union;
@@ -4,11 +4,13 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
7
+ var __esm = (fn, res, err) => function __init() {
8
+ if (err) throw err[0];
9
+ try {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ } catch (e) {
12
+ throw err = [e], e;
13
+ }
12
14
  };
13
15
  var __export = (target, all) => {
14
16
  for (var name in all)
@@ -131,7 +133,7 @@ var init_abi = __esm({
131
133
  var package_default;
132
134
  var init_package = __esm({
133
135
  "package.json"() {
134
- package_default = { name: "koffi", version: "3.0.1", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
136
+ package_default = { name: "koffi", version: "3.1.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
135
137
  }
136
138
  });
137
139
 
@@ -154,13 +156,20 @@ function detectPlatform() {
154
156
  triplets2.push(`musl_${abi}`);
155
157
  return [package_default.version, pkg2, triplets2];
156
158
  }
157
- function loadDynamic(root, pkg2, triplets2) {
159
+ function loadDynamic(dirname, pkg2, triplets2) {
160
+ let suffix = "/../../build/koffi";
161
+ let root = dirname + suffix;
158
162
  let roots = [root];
159
163
  let native2 = null;
160
164
  let err = null;
161
165
  if (process["resourcesPath"] != null) {
162
- roots.push(process["resourcesPath"]);
163
- roots.push(process["resourcesPath"] + "/node_modules/koffi");
166
+ let suffixes = [
167
+ "/koffi",
168
+ "/koffi/build",
169
+ "/node_modules/koffi/build"
170
+ ];
171
+ for (let suffix2 of suffixes)
172
+ roots.push(process["resourcesPath"] + suffix2);
164
173
  }
165
174
  let names = [
166
175
  `${__dirname}/../../../@koromix/koffi-${pkg2}`,
@@ -170,19 +179,21 @@ function loadDynamic(root, pkg2, triplets2) {
170
179
  if (!import_node_fs2.default.existsSync(name))
171
180
  continue;
172
181
  try {
173
- native2 = requireNative(name);
182
+ native2 = require2(name);
174
183
  break;
175
184
  } catch (e) {
176
185
  err ??= e;
177
186
  }
178
187
  }
179
- if (native2 == null) {
180
- err ??= new Error("Cannot find the native Koffi module; did you bundle it correctly?");
188
+ if (native2 == null && err != null)
181
189
  throw err;
182
- }
183
190
  return native2;
184
191
  }
185
- function wrapNative(native2) {
192
+ function wrapNative(native2, version2) {
193
+ if (native2 == null)
194
+ throw new Error("Cannot find the native Koffi module; did you bundle it correctly?");
195
+ if (native2.version != version2)
196
+ throw new Error("Mismatched native Koffi modules");
186
197
  let load = native2.load;
187
198
  let register = native2.register;
188
199
  let introspect = native2.introspect ?? native2.type;
@@ -220,7 +231,7 @@ function wrapNative(native2) {
220
231
  native2.resolve = native2.type;
221
232
  }
222
233
  }
223
- var import_node_util, import_node_fs2, import_node_module, requireNative;
234
+ var import_node_util, import_node_fs2, import_node_module, require2;
224
235
  var init_init = __esm({
225
236
  "src/init.js"() {
226
237
  import_node_util = __toESM(require("node:util"));
@@ -228,107 +239,15 @@ var init_init = __esm({
228
239
  import_node_module = require("node:module");
229
240
  init_abi();
230
241
  init_package();
231
- requireNative = (0, import_node_module.createRequire)(__filename);
232
- }
233
- });
234
-
235
- // src/static.js
236
- var require_static = __commonJS({
237
- "src/static.js"(exports2, module2) {
238
- var { createRequire: createRequire2 } = require("node:module");
239
- var requireNative2 = createRequire2(__filename);
240
- var BINARY_ROOT2 = __dirname + "/../../build/koffi";
241
- function loadStatic2(pkg2) {
242
- let native2 = null;
243
- try {
244
- if (pkg2 == "linux-arm64")
245
- native2 = requireNative2("../../../@koromix/koffi-linux-arm64");
246
- } catch (err) {
247
- }
248
- try {
249
- if (pkg2 == "linux-ia32")
250
- native2 = requireNative2("../../../@koromix/koffi-linux-ia32");
251
- } catch (err) {
252
- }
253
- try {
254
- if (pkg2 == "linux-x64")
255
- native2 = requireNative2("../../../@koromix/koffi-linux-x64");
256
- } catch (err) {
257
- }
258
- try {
259
- if (pkg2 == "linux-riscv64")
260
- native2 = requireNative2("../../../@koromix/koffi-linux-riscv64");
261
- } catch (err) {
262
- }
263
- try {
264
- if (pkg2 == "freebsd-ia32")
265
- native2 = requireNative2("../../../@koromix/koffi-freebsd-ia32");
266
- } catch (err) {
267
- }
268
- try {
269
- if (pkg2 == "freebsd-x64")
270
- native2 = requireNative2("../../../@koromix/koffi-freebsd-x64");
271
- } catch (err) {
272
- }
273
- try {
274
- if (pkg2 == "freebsd-arm64")
275
- native2 = requireNative2("../../../@koromix/koffi-freebsd-arm64");
276
- } catch (err) {
277
- }
278
- try {
279
- if (pkg2 == "openbsd-ia32")
280
- native2 = requireNative2("../../../@koromix/koffi-openbsd-ia32");
281
- } catch (err) {
282
- }
283
- try {
284
- if (pkg2 == "openbsd-x64")
285
- native2 = requireNative2("../../../@koromix/koffi-openbsd-x64");
286
- } catch (err) {
287
- }
288
- try {
289
- if (pkg2 == "win32-ia32")
290
- native2 = requireNative2("../../../@koromix/koffi-win32-ia32");
291
- } catch (err) {
292
- }
293
- try {
294
- if (pkg2 == "win32-x64")
295
- native2 = requireNative2("../../../@koromix/koffi-win32-x64");
296
- } catch (err) {
297
- }
298
- try {
299
- if (pkg2 == "darwin-x64")
300
- native2 = requireNative2("../../../@koromix/koffi-darwin-x64");
301
- } catch (err) {
302
- }
303
- try {
304
- if (pkg2 == "darwin-arm64")
305
- native2 = requireNative2("../../../@koromix/koffi-darwin-arm64");
306
- } catch (err) {
307
- }
308
- try {
309
- if (pkg2 == "linux-loong64")
310
- native2 = requireNative2("../../../@koromix/koffi-linux-loong64");
311
- } catch (err) {
312
- }
313
- return native2;
314
- }
315
- module2.exports = {
316
- BINARY_ROOT: BINARY_ROOT2,
317
- loadStatic: loadStatic2
318
- };
242
+ require2 = (0, import_node_module.createRequire)(__filename);
319
243
  }
320
244
  });
321
245
 
322
- // index.cjs
246
+ // indirect.cjs
323
247
  var { detectPlatform: detectPlatform2, loadDynamic: loadDynamic2, wrapNative: wrapNative2 } = (init_init(), __toCommonJS(init_exports));
324
- var { BINARY_ROOT, loadStatic } = require_static();
325
248
  var [version, pkg, triplets] = detectPlatform2();
326
- var native = null;
327
- if (native == null)
328
- native = loadDynamic2(BINARY_ROOT, pkg, triplets);
329
- if (native.version != version)
330
- throw new Error("Mismatched native Koffi modules");
331
- wrapNative2(native);
249
+ var native = loadDynamic2(__dirname, pkg, triplets);
250
+ wrapNative2(native, version);
332
251
  module.exports = {
333
252
  default: native,
334
253
  "LibraryHandle": native["LibraryHandle"],
@@ -94,10 +94,10 @@ function decodeElfHeader(buf) {
94
94
  }
95
95
 
96
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 } };
97
+ var package_default = { name: "koffi", version: "3.1.0", cnoke: { api: "../../vendor/node-api-headers", output: "../../bin/Koffi/{{ toolchain }}", node: 16, napi: 8 } };
98
98
 
99
99
  // src/init.js
100
- var requireNative = createRequire(import.meta.url);
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
+ // 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,