@rnzeus/heimdall-sdk 0.2.4 → 0.3.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.
- package/README.md +44 -1
- package/dist/noop/index.d.ts +7 -0
- package/dist/noop/index.js +10 -0
- package/dist/noop/zustand.d.ts +2 -0
- package/dist/noop/zustand.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/metro/index.cjs +91 -0
- package/noop/index.d.ts +1 -0
- package/noop/index.js +1 -0
- package/noop/zustand.d.ts +1 -0
- package/noop/zustand.js +1 -0
- package/package.json +23 -3
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ Host to use:
|
|
|
83
83
|
| Android emulator | `10.0.2.2` |
|
|
84
84
|
| Real device | LAN IP of the machine running Heimdall |
|
|
85
85
|
|
|
86
|
-
On a real iOS device the first connection triggers the Local Network permission dialog
|
|
86
|
+
On a real iOS device the first connection triggers the Local Network permission dialog. `NSLocalNetworkUsageDescription` in `Info.plist` sets the text of that dialog; it is optional — without it iOS shows a generic message.
|
|
87
87
|
|
|
88
88
|
## Zustand
|
|
89
89
|
|
|
@@ -175,6 +175,49 @@ The cloud only stores accounts, devices and the current address of the desktop.
|
|
|
175
175
|
- When disabled there are no patches, no sockets and no subscriptions.
|
|
176
176
|
- Patches are transparent: original behaviour and return values are preserved, and SDK errors never reach your app.
|
|
177
177
|
- Payloads are capped: JSON bodies at 500 KB, text at 200 KB, everything else at 50 KB, console messages at 8 KB.
|
|
178
|
+
- `enabled: false` turns the SDK off, but its code and native modules stay in the build. To remove them, see below.
|
|
179
|
+
|
|
180
|
+
## Removing the SDK from production builds
|
|
181
|
+
|
|
182
|
+
This is optional: without it the SDK works as described above. With `enabled: false` the SDK is off, but its code and `react-native-tcp-socket` are still in the build. To leave them out of production builds:
|
|
183
|
+
|
|
184
|
+
**1. Replace the SDK with no-ops in `metro.config.js`:**
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
|
|
188
|
+
const { withHeimdall } = require("@rnzeus/heimdall-sdk/metro");
|
|
189
|
+
|
|
190
|
+
const config = mergeConfig(getDefaultConfig(__dirname), {
|
|
191
|
+
// your config
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
module.exports = withHeimdall(config, {
|
|
195
|
+
include: process.env.APP_ENV !== "production",
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
- `include: false` — `@rnzeus/heimdall-sdk` and `@rnzeus/heimdall-sdk/zustand` are replaced with modules that have the same API and do nothing: `connect` and the other calls are no-ops, `<HeimdallConnectPrompt />` renders nothing, `heimdallZustand` returns your store creator as is. Your code does not change.
|
|
200
|
+
- `include: true` — the config is returned unchanged.
|
|
201
|
+
- The `include` option has no default, so the choice is always explicit. Wrap your final config, after any other wrappers.
|
|
202
|
+
- Any other runtime import of the SDK, such as `@rnzeus/heimdall-sdk/dist/...`, fails the build with an error that names the file. Type-only imports (`import type`) are fine.
|
|
203
|
+
|
|
204
|
+
**2. Leave the native module out** in `react-native.config.js`:
|
|
205
|
+
|
|
206
|
+
```js
|
|
207
|
+
const production = process.env.APP_ENV === "production";
|
|
208
|
+
|
|
209
|
+
module.exports = {
|
|
210
|
+
dependencies: production
|
|
211
|
+
? { "react-native-tcp-socket": { platforms: { ios: null, android: null } } }
|
|
212
|
+
: {},
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Do this only together with step 1, otherwise the app crashes on the missing native module. The setting applies to the whole `pod install` run, so run `pod install` again without the variable before a dev or stage build. Leave `react-native-mmkv` alone if your app uses it for anything else.
|
|
217
|
+
|
|
218
|
+
**Which variable to use.** Both files read environment variables of the build process. Use one that is set for the whole build — usually a variable of your CI job, such as the build stage. Values from `.env` files are not visible here. `APP_ENV` above is only an example.
|
|
219
|
+
|
|
220
|
+
A production bundle built this way contains no `heimdall://` strings — only the no-op names, such as `heimdallZustand`. With Expo, step 1 works as is; for step 2 use your own config plugin.
|
|
178
221
|
|
|
179
222
|
## Your data
|
|
180
223
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as Sdk from "../index";
|
|
2
|
+
export type { HeimdallConnectOptions } from "../types/public";
|
|
3
|
+
export type { Channel } from "../core/public";
|
|
4
|
+
export declare const connect: typeof Sdk.connect, disconnect: typeof Sdk.disconnect, configureConnectPrompt: typeof Sdk.configureConnectPrompt, showSDKConnectPrompt: typeof Sdk.showSDKConnectPrompt, HeimdallConnectPrompt: {
|
|
5
|
+
({ onCopyToClipboard, }: import("../public/prompt/types").Props): import("react").JSX.Element | null;
|
|
6
|
+
displayName: string;
|
|
7
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const noop = {
|
|
2
|
+
connect: () => { },
|
|
3
|
+
disconnect: () => { },
|
|
4
|
+
configureConnectPrompt: () => { },
|
|
5
|
+
showSDKConnectPrompt: () => { },
|
|
6
|
+
HeimdallConnectPrompt: Object.assign(() => null, {
|
|
7
|
+
displayName: "HeimdallConnectPrompt",
|
|
8
|
+
}),
|
|
9
|
+
};
|
|
10
|
+
export const { connect, disconnect, configureConnectPrompt, showSDKConnectPrompt, HeimdallConnectPrompt, } = noop;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const heimdallZustand = (_storeName, createState) => createState;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.
|
|
1
|
+
export declare const SDK_VERSION = "0.3.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.
|
|
1
|
+
export const SDK_VERSION = "0.3.0";
|
package/metro/index.cjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const path = require("node:path");
|
|
2
|
+
|
|
3
|
+
const PACKAGE = "@rnzeus/heimdall-sdk";
|
|
4
|
+
|
|
5
|
+
const NOOP_FILES = {
|
|
6
|
+
[PACKAGE]: path.resolve(__dirname, "../dist/noop/index.js"),
|
|
7
|
+
[`${PACKAGE}/zustand`]: path.resolve(__dirname, "../dist/noop/zustand.js"),
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const NOOP_ENTRIES = new Set([`${PACKAGE}/noop`, `${PACKAGE}/noop/zustand`]);
|
|
11
|
+
|
|
12
|
+
const isSdkImport = (moduleName) =>
|
|
13
|
+
moduleName === PACKAGE || moduleName.startsWith(`${PACKAGE}/`);
|
|
14
|
+
|
|
15
|
+
const unsupportedImportError = ({ moduleName, originModulePath }) => {
|
|
16
|
+
const origin = originModulePath
|
|
17
|
+
? path.relative(process.cwd(), originModulePath)
|
|
18
|
+
: "<unknown file>";
|
|
19
|
+
|
|
20
|
+
return new Error(
|
|
21
|
+
[
|
|
22
|
+
`[heimdall] Unsupported import of the Heimdall SDK in a build that excludes it.`,
|
|
23
|
+
``,
|
|
24
|
+
` File: ${origin}`,
|
|
25
|
+
` Import: "${moduleName}"`,
|
|
26
|
+
``,
|
|
27
|
+
`withHeimdall(config, { include: false }) in metro.config.js replaces the SDK with no-ops,`,
|
|
28
|
+
`so none of its code, its native modules or its dependencies end up in this bundle.`,
|
|
29
|
+
`Only these imports can be replaced:`,
|
|
30
|
+
``,
|
|
31
|
+
` "${PACKAGE}" -> no-op connect / disconnect / prompt`,
|
|
32
|
+
` "${PACKAGE}/zustand" -> heimdallZustand passes the store creator through`,
|
|
33
|
+
``,
|
|
34
|
+
`"${moduleName}" is not one of them. Letting it through would put the real SDK into this bundle,`,
|
|
35
|
+
`and if react-native-tcp-socket is unlinked for this build, the app would crash at runtime.`,
|
|
36
|
+
``,
|
|
37
|
+
`How to fix:`,
|
|
38
|
+
` - import from "${PACKAGE}" or "${PACKAGE}/zustand" instead;`,
|
|
39
|
+
` - type-only imports are fine anywhere: use "import type { ... }";`,
|
|
40
|
+
` - if this build should include Heimdall, pass { include: true } to withHeimdall.`,
|
|
41
|
+
].join("\n")
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Wraps a Metro config. With `include: false` imports of the SDK resolve to no-op modules,
|
|
47
|
+
* so the SDK is not bundled. With `include: true` the config is returned unchanged.
|
|
48
|
+
*
|
|
49
|
+
* @template T
|
|
50
|
+
* @param {T} config
|
|
51
|
+
* @param {{ include: boolean }} options
|
|
52
|
+
* @returns {T}
|
|
53
|
+
*/
|
|
54
|
+
function withHeimdall(config, options) {
|
|
55
|
+
if (typeof options?.include !== "boolean") {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`[heimdall] withHeimdall(config, { include }) needs "include" set to true or false explicitly, ` +
|
|
58
|
+
`e.g. { include: process.env.APP_ENV !== "production" }.`
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (options.include) return config;
|
|
63
|
+
|
|
64
|
+
const resolver = config.resolver ?? {};
|
|
65
|
+
const resolveNext = resolver.resolveRequest;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
...config,
|
|
69
|
+
resolver: {
|
|
70
|
+
...resolver,
|
|
71
|
+
resolveRequest: (context, moduleName, platform) => {
|
|
72
|
+
if (isSdkImport(moduleName) && !NOOP_ENTRIES.has(moduleName)) {
|
|
73
|
+
const filePath = NOOP_FILES[moduleName];
|
|
74
|
+
if (!filePath) {
|
|
75
|
+
throw unsupportedImportError({
|
|
76
|
+
moduleName,
|
|
77
|
+
originModulePath: context.originModulePath,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return { type: "sourceFile", filePath };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return resolveNext
|
|
84
|
+
? resolveNext(context, moduleName, platform)
|
|
85
|
+
: context.resolveRequest(context, moduleName, platform);
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { withHeimdall };
|
package/noop/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../dist/noop";
|
package/noop/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../dist/noop/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../dist/noop/zustand";
|
package/noop/zustand.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../dist/noop/zustand.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnzeus/heimdall-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "React Native client for Heimdall — a desktop debug inspector for network, WebSocket, Zustand and console",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Volodymyr Dudkevych",
|
|
@@ -29,7 +29,9 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"files": [
|
|
31
31
|
"dist",
|
|
32
|
-
"zustand"
|
|
32
|
+
"zustand",
|
|
33
|
+
"noop",
|
|
34
|
+
"metro"
|
|
33
35
|
],
|
|
34
36
|
"main": "dist/index.js",
|
|
35
37
|
"types": "dist/index.d.ts",
|
|
@@ -48,11 +50,29 @@
|
|
|
48
50
|
"import": "./zustand/index.js",
|
|
49
51
|
"require": "./zustand/index.js",
|
|
50
52
|
"default": "./zustand/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./noop": {
|
|
55
|
+
"types": "./noop/index.d.ts",
|
|
56
|
+
"react-native": "./noop/index.js",
|
|
57
|
+
"import": "./noop/index.js",
|
|
58
|
+
"require": "./noop/index.js",
|
|
59
|
+
"default": "./noop/index.js"
|
|
60
|
+
},
|
|
61
|
+
"./noop/zustand": {
|
|
62
|
+
"types": "./noop/zustand.d.ts",
|
|
63
|
+
"react-native": "./noop/zustand.js",
|
|
64
|
+
"import": "./noop/zustand.js",
|
|
65
|
+
"require": "./noop/zustand.js",
|
|
66
|
+
"default": "./noop/zustand.js"
|
|
67
|
+
},
|
|
68
|
+
"./metro": {
|
|
69
|
+
"require": "./metro/index.cjs",
|
|
70
|
+
"default": "./metro/index.cjs"
|
|
51
71
|
}
|
|
52
72
|
},
|
|
53
73
|
"scripts": {
|
|
54
74
|
"clean": "rimraf dist",
|
|
55
|
-
"build": "node scripts/write-version.mjs && yarn clean && tsc -p tsconfig.build.json && node scripts/fix-esm-extensions.mjs dist",
|
|
75
|
+
"build": "node scripts/write-version.mjs && yarn clean && tsc -p tsconfig.build.json && node scripts/fix-esm-extensions.mjs dist && node scripts/check-noop.mjs",
|
|
56
76
|
"dev": "tsc -p tsconfig.build.json -w",
|
|
57
77
|
"typecheck": "node scripts/write-version.mjs && tsc -p tsconfig.json --noEmit",
|
|
58
78
|
"knip": "knip",
|