bare-stow-target-react-native 0.1.1 → 0.2.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.
Files changed (3) hide show
  1. package/README.md +11 -2
  2. package/index.js +38 -32
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -15,7 +15,7 @@ const stow = require('bare-stow')
15
15
  const target = require('bare-stow-target-react-native')
16
16
 
17
17
  const entry = new URL('file:///app/core.js')
18
- const out = new URL('file:///app/out/index.js')
18
+ const out = new URL('file:///app/core-harness/')
19
19
 
20
20
  for await (const artifact of stow(entry, target, out)) {
21
21
  console.log(artifact.url.href)
@@ -25,7 +25,16 @@ for await (const artifact of stow(entry, target, out)) {
25
25
  On the command line, `bare-stow` resolves `--target react-native` to this package:
26
26
 
27
27
  ```console
28
- $ bare-stow --target react-native --out ./out/index.js ./core.js
28
+ $ bare-stow pack --target react-native --out ./core-harness ./core.js
29
+ ```
30
+
31
+ The harness imports `bare-stow-host` and `react-native-bare-kit`, which the generated `package.json` declares as dependencies, along with the RPC library when a `client` is requested.
32
+
33
+ The addons and assets of the bundle are left to the application, which links those of all of its bundles once with `bare-stow link`:
34
+
35
+ ```console
36
+ $ bare-stow link --target bare-kit --language swift --out ./ios/BareKitAddons ./core.js ./push.js
37
+ $ bare-stow link --target bare-kit --language kotlin --language-option package=com.example.addons --out ./android/addons ./core.js ./push.js
29
38
  ```
30
39
 
31
40
  ## License
package/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  exports.name = 'react-native'
2
+ exports.isolation = 'thread'
2
3
  exports.linked = true
4
+ exports.linking = 'app'
3
5
  exports.offload = false
4
6
  exports.format = 'bundle.mjs'
5
7
  exports.encoding = 'utf8'
6
8
  exports.extension = '.bundle.mjs'
7
- exports.module = 'esm'
8
9
  exports.hosts = [
9
10
  'ios-arm64',
10
11
  'ios-arm64-simulator',
@@ -15,54 +16,59 @@ exports.hosts = [
15
16
  'android-x64'
16
17
  ]
17
18
 
18
- exports.generate = function generate(opts) {
19
- const { bundleSpecifier, ipc, rpc, client = null } = opts
19
+ exports.languages = {
20
+ javascript: {
21
+ options: { module: 'esm' },
22
+ generate: javascript
23
+ }
24
+ }
20
25
 
21
- const returned = client ? `{ ${ipc}, ${rpc} }` : `{ ${ipc} }`
26
+ function javascript(context) {
27
+ const { bundle, client, resources } = context
22
28
 
23
29
  const handle = client
24
- ? `{ ${ipc}: import('bare-stow/host').IPC; ${rpc}: ${client.type} }`
25
- : `{ ${ipc}: import('bare-stow/host').IPC }`
30
+ ? `{ ipc: import('bare-stow-host').IPC; rpc: ReturnType<typeof import(${JSON.stringify(client)}).attach> }`
31
+ : `{ ipc: import('bare-stow-host').IPC }`
26
32
 
27
- return [
28
- {
29
- source: `\
33
+ const source = `\
30
34
  import { Worklet } from 'react-native-bare-kit'
31
- import stow from 'bare-stow/host'
32
- import bundle from ${JSON.stringify(bundleSpecifier)}
33
-
35
+ import stow from 'bare-stow-host'
36
+ import bundle from ${JSON.stringify(bundle)}
37
+ ${client ? `import * as client from ${JSON.stringify(client)}\n` : ''}
34
38
  export default {
35
- async start(opts = {}) {
39
+ async start({ timeout, grace, ${client ? 'handlers = () => {}, ' : ''}...opts } = {}) {
36
40
  const worklet = new Worklet(opts)
37
41
 
38
- worklet.start('/core.bundle', bundle)
42
+ worklet.start(${JSON.stringify(resources + '.bundle')}, bundle)
39
43
 
40
- const ${ipc} = stow.wrap(worklet.IPC)
41
- ${client ? '\n' + indent(client.source, 4) : ''}
42
- await ${ipc}.ready
44
+ const ipc = stow.wrap(worklet.IPC, { kill: () => worklet.terminate(), timeout, grace })
43
45
 
44
- return ${returned}
46
+ ipc.on('exit', () => worklet.terminate())
47
+ ${client ? '\n const rpc = client.attach(ipc, handlers)\n' : ''}
48
+ await ipc.ready
49
+
50
+ return ${client ? '{ ipc, rpc }' : '{ ipc }'}
45
51
  }
46
52
  }
47
53
  `
48
- },
49
- {
50
- extension: '.d.ts',
51
- source: `\
54
+
55
+ const types = `\
52
56
  declare const harness: {
53
- start(opts?: import('react-native-bare-kit').WorkletOptions): Promise<${handle}>
57
+ start(
58
+ opts?: import('react-native-bare-kit').WorkletOptions &
59
+ Omit<import('bare-stow-host').IPCOptions, 'kill'>${client ? ` & { handlers?: import(${JSON.stringify(client)}).Handlers }` : ''}
60
+ ): Promise<${handle}>
54
61
  }
55
62
 
56
63
  export default harness
57
64
  `
58
- }
59
- ]
60
- }
61
65
 
62
- function indent(source, spaces) {
63
- const pad = ' '.repeat(spaces)
64
- return source
65
- .split('\n')
66
- .map((line) => (line.length === 0 ? line : pad + line))
67
- .join('\n')
66
+ return {
67
+ source,
68
+ types,
69
+ dependencies: {
70
+ 'bare-stow-host': '^0.1.0',
71
+ 'react-native-bare-kit': '^0.16.0'
72
+ }
73
+ }
68
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-stow-target-react-native",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "React Native target for bare-stow",
5
5
  "exports": {
6
6
  "./package": "./package.json",
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "homepage": "https://github.com/holepunchto/bare-stow-target-react-native#readme",
33
33
  "peerDependencies": {
34
- "bare-stow": "^0.1.0"
34
+ "bare-stow": "^0.2.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "brittle": "^4.0.2",