stem-mqtt 0.6.1 → 0.8.1

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/README.md CHANGED
@@ -23,10 +23,13 @@ hand-written napi-rs addon `stem-mqtt-client`, which had no broker.
23
23
 
24
24
  - Node.js 16+ (ESM — use `"type": "module"` or `.mjs`). **Server-side only**; there is no browser build
25
25
  (browsers can talk to the broker's WebSocket port with any MQTT.js client instead).
26
- - The package bundles the native library under `client/prebuilds/<platform>-<arch>[-libc]/` and
27
- `broker/prebuilds/…` for the platforms the release built — **Linux x86_64 (glibc) today**. `package.json`
28
- lists exactly those platforms in `os` / `cpu`, so `npm install` on another platform fails immediately
29
- (`EBADPLATFORM`) instead of at first use. Other platforms: build the library (below) or ask for it to be added.
26
+ - The native libraries come in one package per platform, installed automatically: `stem-mqtt` lists
27
+ `stem-mqtt-linux-x64-gnu`, `stem-mqtt-linux-arm64-gnu`, `stem-mqtt-darwin-x64`, `stem-mqtt-darwin-arm64`
28
+ and `@greenspand/stem-mqtt-win32-x64-msvc` (scoped: npmjs.org's spam detection rejects the unscoped
29
+ Windows name) as optional dependencies, each restricted to its `os` / `cpu` (and glibc), so
30
+ npm installs only the one your machine needs. On any other platform `npm install` fails up front
31
+ (`EBADPLATFORM`). With `--omit=optional` (or a lockfile made on another OS) the platform package is
32
+ missing: install it explicitly, e.g. `npm install stem-mqtt-linux-x64-gnu`.
30
33
  - No compiler is needed at install time: `koffi` ships prebuilt binaries.
31
34
 
32
35
  ## Quick start
@@ -154,9 +157,9 @@ nu scripts/publish_packages.nu stage node # dist/node/{client,broker,runtim
154
157
  cd dist/node && npm pack
155
158
  ```
156
159
 
157
- To ship more platforms in one package, build `stage` on each OS and merge the extra libraries in:
158
- `nu scripts/publish_packages.nu stage node --add-native /path/to/other-stage/native` (a directory containing
159
- `<platform>/` folders such as `linux-x86_64/` or `macos-aarch64/`).
160
+ Publishing (`publish_packages.nu publish node …`) moves the libraries into one package per platform under
161
+ `dist/node/platforms/<target>/` and publishes those before the main package. Release CI passes
162
+ `--natives native-libs`: every target's libraries, built by `scripts/ci/native_libs.nu`.
160
163
 
161
164
  The package layout is `client/`, `broker/` and one shared `runtime/` — the generator emits a copy of the runtime
162
165
  per component, and two copies cannot be loaded into one process because they register the same named types in
@@ -169,9 +172,11 @@ The end-to-end test is [`tests/bindings/node/smoke.mjs`](https://github.com/sori
169
172
 
170
173
  - **`Cannot find module './client/index.js'`** — import the package entry points
171
174
  (`stem-mqtt/client`), not a path.
172
- - **`EBADPLATFORM` on install, or `Failed to load shared library`** — the package has no native library for your
173
- OS/arch; build from source and copy `libmqtt_client.*` / `libmqtt_broker.*` into
174
- `client/prebuilds/<platform>-<arch>/` and `broker/prebuilds/<platform>-<arch>/`.
175
+ - **`EBADPLATFORM` on install** — there is no package for your OS/arch; build from source and copy
176
+ `libmqtt_client.*` / `libmqtt_broker.*` into `client/prebuilds/<platform>-<arch>/` and
177
+ `broker/prebuilds/<platform>-<arch>/` of the installed package.
178
+ - **`Failed to load shared library`** — the platform package was not installed (optional dependencies
179
+ omitted); `npm install stem-mqtt-<platform>-<arch>[-gnu]` (on Windows `@greenspand/stem-mqtt-win32-x64-msvc`) of the same version.
175
180
  - **`Duplicate type name 'RustBuffer'`** — you are using separately generated components; the published
176
181
  package shares one `runtime/` between client and broker precisely to avoid this.
177
182
  - **`SyntaxError: Cannot use import statement`** — the file isn't ESM; use `.mjs` or `"type": "module"`.
@@ -1,3 +1,18 @@
1
+ import { createRequire as uniffiCreateRequire } from "node:module";
2
+
3
+ // stem-mqtt: the native library ships in a per-platform package (an optional dependency).
4
+ const uniffiPlatformPackages = {"darwin-arm64":"stem-mqtt-darwin-arm64","darwin-x64":"stem-mqtt-darwin-x64","linux-arm64-gnu":"stem-mqtt-linux-arm64-gnu","linux-x64-gnu":"stem-mqtt-linux-x64-gnu","win32-x64":"@greenspand/stem-mqtt-win32-x64-msvc"};
5
+ function uniffiPlatformLibrary(target, filename) {
6
+ const name = uniffiPlatformPackages[target];
7
+ if (name === undefined) return null;
8
+ try {
9
+ const manifest = uniffiCreateRequire(import.meta.url).resolve(`${name}/package.json`);
10
+ return join(dirname(manifest), "broker", filename);
11
+ } catch {
12
+ return null;
13
+ }
14
+ }
15
+
1
16
  import { existsSync, realpathSync } from "node:fs";
2
17
  import { dirname, isAbsolute, join } from "node:path";
3
18
  import { fileURLToPath } from "node:url";
@@ -169,7 +184,7 @@ function defaultBundledLibrary() {
169
184
  return Object.freeze({
170
185
  target,
171
186
  packageRelativePath: `prebuilds/${target}/${filename}`,
172
- libraryPath: join(moduleDirectory, "prebuilds", target, filename),
187
+ libraryPath: uniffiPlatformLibrary(target, filename) ?? join(moduleDirectory, "prebuilds", target, filename),
173
188
  });
174
189
  }
175
190
 
@@ -1,3 +1,18 @@
1
+ import { createRequire as uniffiCreateRequire } from "node:module";
2
+
3
+ // stem-mqtt: the native library ships in a per-platform package (an optional dependency).
4
+ const uniffiPlatformPackages = {"darwin-arm64":"stem-mqtt-darwin-arm64","darwin-x64":"stem-mqtt-darwin-x64","linux-arm64-gnu":"stem-mqtt-linux-arm64-gnu","linux-x64-gnu":"stem-mqtt-linux-x64-gnu","win32-x64":"@greenspand/stem-mqtt-win32-x64-msvc"};
5
+ function uniffiPlatformLibrary(target, filename) {
6
+ const name = uniffiPlatformPackages[target];
7
+ if (name === undefined) return null;
8
+ try {
9
+ const manifest = uniffiCreateRequire(import.meta.url).resolve(`${name}/package.json`);
10
+ return join(dirname(manifest), "client", filename);
11
+ } catch {
12
+ return null;
13
+ }
14
+ }
15
+
1
16
  import { existsSync, realpathSync } from "node:fs";
2
17
  import { dirname, isAbsolute, join } from "node:path";
3
18
  import { fileURLToPath } from "node:url";
@@ -157,7 +172,7 @@ function defaultBundledLibrary() {
157
172
  return Object.freeze({
158
173
  target,
159
174
  packageRelativePath: `prebuilds/${target}/${filename}`,
160
- libraryPath: join(moduleDirectory, "prebuilds", target, filename),
175
+ libraryPath: uniffiPlatformLibrary(target, filename) ?? join(moduleDirectory, "prebuilds", target, filename),
161
176
  });
162
177
  }
163
178
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stem-mqtt",
3
- "version": "0.6.1",
3
+ "version": "0.8.1",
4
4
  "description": "MQTT 3.1.1 / 5.0 client and broker (Rust core, UniFFI Node bindings)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -43,10 +43,20 @@
43
43
  "registry": "https://registry.npmjs.org/",
44
44
  "access": "public"
45
45
  },
46
+ "optionalDependencies": {
47
+ "stem-mqtt-darwin-arm64": "0.8.1",
48
+ "stem-mqtt-darwin-x64": "0.8.1",
49
+ "stem-mqtt-linux-arm64-gnu": "0.8.1",
50
+ "stem-mqtt-linux-x64-gnu": "0.8.1",
51
+ "@greenspand/stem-mqtt-win32-x64-msvc": "0.8.1"
52
+ },
46
53
  "os": [
47
- "linux"
54
+ "darwin",
55
+ "linux",
56
+ "win32"
48
57
  ],
49
58
  "cpu": [
59
+ "arm64",
50
60
  "x64"
51
61
  ]
52
62
  }