Skip to content

Commit 69c0e1f

Browse files
committed
docs: update readme
1 parent 269b65b commit 69c0e1f

File tree

1 file changed

+11
-41
lines changed

1 file changed

+11
-41
lines changed

README.md

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,13 @@
22

33
There is some setup that needs to be done to modernise the react-native runtime.
44

5-
1. Turn on [exports map support](https://reactnative.dev/blog/2023/06/21/package-exports-support)
6-
7-
```js
8-
// metro.config.js
9-
module.exports = {
10-
resolver: {
11-
unstable_enablePackageExports: true,
12-
}
13-
}
14-
```
15-
16-
2. Shimming globals
5+
1. Shimming globals
176

187
Some standard JS APIs aren't available in React Native, these need to be polyfilled, hopefully [not forever](https://github.com/facebook/hermes/discussions/1072).
198

20-
```js
21-
// globals.js - this should be imported at the top of your App.js file
22-
import '@azure/core-asynciterator-polyfill'
23-
import 'react-native-url-polyfill/auto'
24-
import 'react-native-get-random-values'
25-
import 'weakmap-polyfill'
26-
import { TextEncoder, TextDecoder } from 'text-encoding'
27-
import { EventTarget, Event } from 'event-target-shim'
28-
import { Buffer } from '@craftzdog/react-native-buffer'
29-
import { Crypto } from '@peculiar/webcrypto'
30-
31-
global.TextEncoder = TextEncoder
32-
global.TextDecoder = TextDecoder
33-
global.EventTarget = EventTarget
34-
global.Event = Event
35-
36-
global.AbortSignal.timeout = (ms) => {
37-
const controller = new AbortController()
38-
setTimeout(() => {
39-
controller.abort(new Error('Aborted'))
40-
}, ms)
41-
}
42-
global.Buffer = Buffer
43-
global.crypto.subtle = new Crypto().subtle
44-
```
9+
See [./globals.js](./globals.js) for the changes you need to make.
4510

46-
3. Enable modern JS features
11+
2. Enable modern JS features
4712

4813
- libp2p uses [ES2022 private properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties) in some places, so enable transpiling them for use with React Native. At the time of writing [loose mode](https://2ality.com/2015/12/babel6-loose-mode.html) is also required.
4914

@@ -61,6 +26,12 @@ module.exports = {
6126
}
6227
```
6328

29+
3. Add support for missing Node.js APIs
30+
31+
Some dependencies use Node.js APIs so these need to be added to the module resolver.
32+
33+
See [./babel-config.js](./babel-config.js) for the changes you need to make.
34+
6435
## Running
6536

6637
### Prerequisites
@@ -94,15 +65,14 @@ $ npx expo run:ios --device
9465

9566
## Notes
9667

97-
- By default this demo uses pure-js crypto - it's not efficient enough to run on an actual device, `crypto-browserify` should be replaced with `react-native-quick-crypto` in `babel.config.js` for native builds
98-
- `@libp2p/webrtc` can also only run on a device since it needs native code
68+
- `@libp2p/webrtc` can only run on a device since it needs native code
9969

10070
### Debugging
10171

10272
Put this at the top of your app file:
10373

10474
```js
105-
import debug from 'debug'
75+
import debug from 'weald'
10676

10777
debug.enable('libp2p:*')
10878
```

0 commit comments

Comments
 (0)