Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions docs/content/docs/guides/bare-host.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Bundle for your host without the `react-native` export condition. RNQC's `export

Hermes does not support async generators, so run your bundle through a transform such as `@babel/plugin-transform-async-generator-functions`. The bundle also needs runtime globals such as `global`, `setImmediate`, `process` and `AbortController`.

The shared entry uses `@craftzdog/react-native-buffer`. Off React Native it uses `base64-js`, but your bundler still has to resolve its React Native branch. Alias `react-native-quick-base64` to `base64-js` in your bundler. The shared entry also imports `util` and `string_decoder`, so your host needs polyfills for them.
The shared entry uses `@craftzdog/react-native-buffer` 6.1.3 or newer, which uses `base64-js` unless a React Native bundler redirects it through its `react-native` field, so no base64 alias is needed. The shared entry also imports `util` and `string_decoder`, so your host needs polyfills for them.

If your bundler honors the `browser` condition, packages such as `multiformats` resolve to builds that call `crypto.subtle` instead of `createHash`. Alias those subpaths to their Node builds if you want them to use RNQC's `crypto` export.

Expand All @@ -112,6 +112,5 @@ The pieces a bare host needs, as the script wires them:

1. `margelo::nitro::install(runtime, dispatcher)` before any JavaScript loads RNQC.
2. Registration: `System.loadLibrary("QuickCrypto")` on Android after Nitro core is loaded, and a single `registerHybridClasses()` call on Apple (guard it with `std::call_once` if the runtime is created more than once).
3. A bundle with `react-native-quick-base64` aliased to `base64-js`.
4. A prelude that defines the globals bare Hermes lacks: `global`, `self`, `console`, `AbortController`/`AbortSignal`, and `kCustomPromisifiedSymbol` (read by the bundled `util` polyfill). See `example/test/bare/prelude.ts`.
5. An async-generator transform (`@babel/plugin-transform-async-generator-functions`) over the finished bundle, because Hermes rejects async generators and `for await`. See `example/test/bare/host/hermes-transform.mjs`.
3. A prelude that defines the globals bare Hermes lacks: `global`, `self`, `console`, `AbortController`/`AbortSignal`, and `kCustomPromisifiedSymbol` (read by the bundled `util` polyfill). See `example/test/bare/prelude.ts`.
4. An async-generator transform (`@babel/plugin-transform-async-generator-functions`) over the finished bundle, because Hermes rejects async generators and `for await`. See `example/test/bare/host/hermes-transform.mjs`.
3 changes: 1 addition & 2 deletions example-nitro/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"alias": {
"react-native-quick-crypto": "../packages/react-native-quick-crypto/src/index.ts",
"crypto": "../packages/react-native-quick-crypto/src/index.ts",
"stream": "readable-stream",
"react-native-quick-base64": "base64-js"
"stream": "readable-stream"
}
}
1 change: 0 additions & 1 deletion example-nitro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"typescript": "tsc --noEmit"
},
"dependencies": {
"base64-js": "1.5.1",
"buffer": "6.0.3",
"event-target-polyfill": "0.0.4",
"nitro-ui-cli": "0.1.0",
Expand Down
16 changes: 0 additions & 16 deletions example-nitro/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,4 @@ class TextDecoderPolyfill {
const g = globalThis as Record<string, unknown>;
g.TextEncoder ??= TextEncoderPolyfill;
g.TextDecoder ??= TextDecoderPolyfill;
// RNQC's React Native install() sets these from react-native-quick-base64. Assigned, not
// ??=, because a single-script bundle hoists same-named test helpers onto globalThis.
g.base64ToArrayBuffer = (s: string, removeLinebreaks = false): ArrayBuffer => {
const b = Buffer.from(
removeLinebreaks ? s.replace(/[\r\n]/g, '') : s,
'base64',
);
return b.buffer.slice(
b.byteOffset,
b.byteOffset + b.byteLength,
) as ArrayBuffer;
};
g.base64FromArrayBuffer = (b: ArrayBuffer, urlSafe = false): string => {
const s = Buffer.from(b).toString('base64');
return urlSafe ? s.replace(/\+/g, '-').replace(/\//g, '_') : s;
};
g.structuredClone ??= <T>(obj: T): T => JSON.parse(JSON.stringify(obj)) as T;
1 change: 0 additions & 1 deletion example/test/bare/aliases.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const rnqcEntry = fileURLToPath(
),
);
const aliases = {
'react-native-quick-base64': fileURLToPath(import.meta.resolve('base64-js')),
'react-native-quick-crypto': rnqcEntry,
crypto: rnqcEntry,
'node:crypto': rnqcEntry,
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native-quick-crypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"@craftzdog/react-native-buffer": "^6.1.2",
"base64-js": "1.5.1",
"@craftzdog/react-native-buffer": "^6.1.3",
"events": "3.3.0",
"readable-stream": "4.7.0",
"safe-buffer": "^5.2.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/bare-host.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#
# Prerequisites: Xcode (iphonesimulator SDK and a simulator runtime), bun, cmake,
# ninja, git, rsync, a bun-installed repo (example/node_modules provides the
# base64-js and multiformats packages that aliases.mjs resolves), and network
# multiformats package that aliases.mjs resolves), and network
# access on first run
# (Nitro, Hermes, OpenSSL binary target, simdutf-swift).
#
Expand Down