koffi 2.5.9 → 2.5.10

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/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  ### Koffi 2.5
6
6
 
7
+ #### Koffi 2.5.10
8
+
9
+ - Fix CMake regression when client has to build Koffi
10
+
7
11
  #### Koffi 2.5.9
8
12
 
9
13
  **Main changes:**
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/doc/packaging.md CHANGED
@@ -6,42 +6,43 @@
6
6
 
7
7
  Koffi uses native modules to work. The NPM package contains binaries for various platforms and architectures, and the appropriate module is selected at runtime.
8
8
 
9
- In theory, the bundlers should be able to find recorgnize all native modules because they are explictly listed in the Javascript file, as static strings.
9
+ In theory, the **packagers/bundlers should be able to find all native modules** because they are explictly listed in the Javascript file (as static strings) and package them somehow.
10
10
 
11
11
  If that is not the case, you can manually arrange to copy the `node_modules/koffi/build/koffi` directory next to your bundled script.
12
12
 
13
13
  Here is an example that would work:
14
14
 
15
15
  ```
16
- koffi/
17
- win32_x64/
18
- koffi.node
19
- linux_x64/
20
- koffi.node
21
- ...
22
- MyBundle.js
16
+ koffi/
17
+ win32_x64/
18
+ koffi.node
19
+ linux_x64/
20
+ koffi.node
21
+ ...
22
+ MyBundle.js
23
23
  ```
24
24
 
25
25
  When running in Electron, Koffi will also try to find the native module in `process.resourcesPath`. For an Electron app you could do something like this
26
26
 
27
27
  ```
28
- locales/
29
- resources/
30
- koffi/
31
- darwin_arm64/
32
- koffi.node
33
- darwin_x64/
34
- koffi.node
35
- MyApp.exe
28
+ locales/
29
+ resources/
30
+ koffi/
31
+ win32_ia32/
32
+ koffi.node
33
+ win32_x64/
34
+ koffi.node
35
+ ...
36
+ MyApp.exe
36
37
  ```
37
38
 
38
39
  ## Packaging examples
39
40
 
40
41
  ### Electron with electron-builder
41
42
 
42
- Packaging with electron-builder should work as-is:
43
+ Packaging with electron-builder should work as-is.
43
44
 
44
- You can also go take a look at the full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/electron-builder).
45
+ Take a look at the full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/electron-builder).
45
46
 
46
47
  ### Electron Forge
47
48
 
@@ -51,10 +52,20 @@ Packaging with Electron Force should work as-is, even when using webpack as conf
51
52
  npm init electron-app@latest my-app -- --template=webpack
52
53
  ```
53
54
 
54
- You can also go take a look at the full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/electron-forge).
55
+ Take a look at the full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/electron-forge).
55
56
 
56
57
  ### NW.js
57
58
 
58
59
  Packagers such as nw-builder should work as-is.
59
60
 
60
61
  You can find a full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/nwjs).
62
+
63
+ ### Node.js and esbuild
64
+
65
+ You can easily tell esbuild to copy the native files with the copy loader and things should just work. Use something like:
66
+
67
+ ```sh
68
+ esbuild index.js --platform=node --bundle --loader:.node=copy --outdir=dist/
69
+ ```
70
+
71
+ You can find a full [working example in the repository](https://github.com/Koromix/rygel/tree/master/src/koffi/examples/node-esbuild).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "2.5.9",
4
- "stable": "2.5.9",
3
+ "version": "2.5.10",
4
+ "stable": "2.5.10",
5
5
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
6
6
  "keywords": [
7
7
  "foreign",
@@ -4832,7 +4832,8 @@ const char *GetTemporaryDirectory()
4832
4832
 
4833
4833
  #endif
4834
4834
 
4835
- const char *FindConfigFile(const char *name, Allocator *alloc, LocalArray<const char *, 4> *out_possibilities)
4835
+ const char *FindConfigFile(Span<const char *const> names, Allocator *alloc,
4836
+ LocalArray<const char *, 4> *out_possibilities)
4836
4837
  {
4837
4838
  decltype(GetUserConfigPath) *funcs[] = {
4838
4839
  [](const char *name, Allocator *alloc) {
@@ -4850,16 +4851,19 @@ const char *FindConfigFile(const char *name, Allocator *alloc, LocalArray<const
4850
4851
  const char *filename = nullptr;
4851
4852
 
4852
4853
  for (const auto &func: funcs) {
4853
- const char *path = func(name, alloc);
4854
+ for (const char *name: names) {
4855
+ const char *path = func(name, alloc);
4854
4856
 
4855
- if (!path)
4856
- continue;
4857
+ if (!path)
4858
+ continue;
4857
4859
 
4858
- if (TestFile(path, FileType::File)) {
4859
- filename = path;
4860
- }
4861
- if (out_possibilities) {
4862
- out_possibilities->Append(path);
4860
+ if (TestFile(path, FileType::File)) {
4861
+ filename = path;
4862
+ }
4863
+ if (out_possibilities) {
4864
+ out_possibilities->Append(path);
4865
+ break;
4866
+ }
4863
4867
  }
4864
4868
  }
4865
4869
 
@@ -4114,7 +4114,8 @@ const char *GetUserCachePath(const char *name, Allocator *alloc); // Can return
4114
4114
  const char *GetSystemConfigPath(const char *name, Allocator *alloc);
4115
4115
  const char *GetTemporaryDirectory();
4116
4116
 
4117
- const char *FindConfigFile(const char *name, Allocator *alloc, LocalArray<const char *, 4> *out_possibilities = nullptr);
4117
+ const char *FindConfigFile(Span<const char *const> names, Allocator *alloc,
4118
+ LocalArray<const char *, 4> *out_possibilities = nullptr);
4118
4119
 
4119
4120
  const char *CreateUniqueFile(Span<const char> directory, const char *prefix, const char *extension,
4120
4121
  Allocator *alloc, FILE **out_fp = nullptr);
package/src/index.js CHANGED
@@ -21,14 +21,14 @@
21
21
 
22
22
  'use strict';
23
23
 
24
- const cnoke = require('./cnoke/src/index.js');
25
24
  const util = require('util');
26
25
  const fs = require('fs');
26
+ const { get_napi_version, determine_arch } = require('./cnoke/src/tools.js');
27
27
  const pkg = require('../package.json');
28
28
 
29
29
  if (process.versions.napi == null || process.versions.napi < pkg.cnoke.napi) {
30
30
  let major = parseInt(process.versions.node, 10);
31
- let required = cnoke.get_napi_version(pkg.cnoke.napi, major);
31
+ let required = get_napi_version(pkg.cnoke.napi, major);
32
32
 
33
33
  if (required != null) {
34
34
  throw new Error(`Project ${pkg.name} requires Node >= ${required} in the Node ${major}.x branch (N-API >= ${pkg.cnoke.napi})`);
@@ -37,7 +37,7 @@ if (process.versions.napi == null || process.versions.napi < pkg.cnoke.napi) {
37
37
  }
38
38
  }
39
39
 
40
- let arch = cnoke.determine_arch();
40
+ let arch = determine_arch();
41
41
  let triplet = `${process.platform}_${arch}`;
42
42
 
43
43
  let native = null;
@@ -47,7 +47,11 @@ endif()
47
47
 
48
48
  # ---- Koffi ----
49
49
 
50
- file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package.json PKG)
50
+ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/package.json)
51
+ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package.json PKG)
52
+ else()
53
+ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../../package.json PKG)
54
+ endif()
51
55
  string(REGEX MATCH "\"version\": \"([^\"]+)\"" XX "${PKG}")
52
56
  set(KOFFI_VERSION ${CMAKE_MATCH_1})
53
57
 
@@ -3,18 +3,6 @@ This is a simple example shows:
3
3
  - How to communicate with Koffi from a renderer window
4
4
  - How to use electron-builder with an application that uses Koffi
5
5
 
6
- One of the important piece for the packaging is in `package.json`, specifically this part:
7
-
8
- ```json
9
- "build": {
10
- "extraResources": [
11
- { "from": "node_modules/koffi/build", "to": "koffi" }
12
- ]
13
- }
14
- ```
15
-
16
- This instructs electron-builder to copy the native koffi modules to a place where your application will find them.
17
-
18
6
  Use the following commands to package the app for your system:
19
7
 
20
8
  ```sh
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "Koffi Config",
2
+ "name": "KoffiConfig",
3
3
  "version": "1.0.0",
4
4
  "description": "Koffi Electron Example",
5
5
  "main": "src/app.js",
@@ -16,6 +16,6 @@
16
16
  "esbuild": "^0.18.17"
17
17
  },
18
18
  "dependencies": {
19
- "koffi": "^2.5.8"
19
+ "koffi": "^2.5.9"
20
20
  }
21
21
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "name": "Koffi Config",
2
+ "name": "KoffiConfig",
3
3
  "version": "1.0.0",
4
4
  "description": "Koffi Electron Example",
5
5
  "main": ".webpack/main",
@@ -32,6 +32,6 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "electron-squirrel-startup": "^1.0.0",
35
- "koffi": "^2.5.8"
35
+ "koffi": "^2.5.9"
36
36
  }
37
37
  }
@@ -21,7 +21,7 @@ const createWindow = () => {
21
21
  mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
22
22
 
23
23
  // Open the DevTools.
24
- mainWindow.webContents.openDevTools();
24
+ // mainWindow.webContents.openDevTools();
25
25
  };
26
26
 
27
27
  // This method will be called when Electron has finished
@@ -0,0 +1,19 @@
1
+ This is a simple example to bundle a CLI node.js app that uses Koffi, using esbuild.
2
+
3
+ To run the app, execute the following:
4
+
5
+ ```sh
6
+ cd examples/node-esbuild
7
+ npm install
8
+ npm start
9
+ ```
10
+
11
+ You can bundle the script and the native modules with the following command
12
+
13
+ ```sh
14
+ cd examples/node-esbuild
15
+ npm install
16
+ npm run bundle
17
+ ```
18
+
19
+ Internally, this uses the esbuild copy loader to handle the native `.node` modules.
@@ -0,0 +1,2 @@
1
+ const koffi = require('koffi');
2
+ console.log(koffi.config());
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "KoffiConfig",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js",
8
+ "bundle": "esbuild index.js --platform=node --bundle --loader:.node=copy --outdir=dist/"
9
+ },
10
+ "author": "",
11
+ "license": "ISC",
12
+ "dependencies": {
13
+ "esbuild": "^0.18.17",
14
+ "koffi": "^2.5.9"
15
+ }
16
+ }
@@ -1,9 +1,10 @@
1
1
  {
2
- "name": "Koffi Config",
2
+ "name": "KoffiConfig",
3
+ "version": "1.0.0",
3
4
  "main": "index.html",
4
5
  "author": "Niels Martignène <niels.martignene@protonmail.com>",
5
6
  "license": "MIT",
6
7
  "dependencies": {
7
- "koffi": "^2.5.8"
8
+ "koffi": "^2.5.9"
8
9
  }
9
10
  }