bare-stow 0.1.2 → 0.1.4
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 +3 -3
- package/index.d.ts +3 -4
- package/lib/protocol.d.ts +9 -3
- package/lib/target/bare-worker.js +82 -0
- package/lib/target.js +2 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@ await ipc.ready
|
|
|
118
118
|
|
|
119
119
|
Bundle the module graph rooted at `entry` for a `target` runtime and write the resulting artifacts to disk at and alongside `out`. Returns an async generator that yields `{ url }` objects as each artifact is written, allowing callers to observe progress.
|
|
120
120
|
|
|
121
|
-
`entry` is a `URL` (or `URL`-coercible string) pointing at the entry module. `target` selects the target runtime, given either as
|
|
121
|
+
`entry` is a `URL` (or `URL`-coercible string) pointing at the entry module. `target` selects the target runtime, given either as a built-in name (`'bare-sidecar'` or `'bare-worker'`) or as a [target provider](#targets-and-rpc-providers) object. Other targets ship as their own packages; require one and pass it as the provider. The target determines the harness format, bundle extension, host triples, and whether assets and addons are linked into the bundle or offloaded as sibling files. `out` is the output `URL` of the harness; the bundle is written next to it with the target's extension.
|
|
122
122
|
|
|
123
123
|
The harness artifacts are yielded first: The harness itself at `out`, followed by a TypeScript declaration (`.d.ts`) alongside it so hosts importing the harness are typed. The bundle is yielded next, then any offloaded assets and native addons when the target supports offloading.
|
|
124
124
|
|
|
@@ -139,7 +139,7 @@ opts = {
|
|
|
139
139
|
- `server`: The RPC library to wire into the bundle entry shim as a server, given either as a built-in name (`'bare-rpc'`) or as an [RPC provider](#targets-and-rpc-providers) object.
|
|
140
140
|
- `base`: The base `URL` of the module graph. Defaults to the directory containing `entry`.
|
|
141
141
|
- `hosts`: An array of host triples to build for. Must be a subset of the host triples supported by the target; passing a host the target does not support throws. Defaults to all host triples supported by the target.
|
|
142
|
-
- `resolveTarget`: A function mapping a target name to a [target provider](#targets-and-rpc-providers) object, called when `target` is a name not in the built-in registry (which
|
|
142
|
+
- `resolveTarget`: A function mapping a target name to a [target provider](#targets-and-rpc-providers) object, called when `target` is a name not in the built-in registry (which knows `'bare-sidecar'` and `'bare-worker'`).
|
|
143
143
|
- `resolveRPC`: A function mapping an RPC library name to an [RPC provider](#targets-and-rpc-providers) object, called when `client` or `server` is a name not in the built-in registry (which only knows `'bare-rpc'`).
|
|
144
144
|
|
|
145
145
|
Any additional options are forwarded to `bare-pack`. See <https://github.com/holepunchto/bare-pack> for the full set, including `builtins`, `imports`, `defer`, and `resolve`.
|
|
@@ -220,7 +220,7 @@ Stow the module graph rooted at `<entry>`, writing the harness and bundle to the
|
|
|
220
220
|
|
|
221
221
|
##### `--target <name>`
|
|
222
222
|
|
|
223
|
-
The target runtime. Required. The built-in `bare-sidecar`
|
|
223
|
+
The target runtime. Required. The built-in `bare-sidecar` and `bare-worker` are resolved directly; any other `<name>` is loaded from its `bare-stow-target-<name>` package, or from `<name>` itself as a full module specifier, resolved from the working directory.
|
|
224
224
|
|
|
225
225
|
##### `--client <name>` and `--server <name>`
|
|
226
226
|
|
package/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import URL from 'bare-url'
|
|
2
|
+
import { PackOptions } from 'bare-pack'
|
|
2
3
|
|
|
3
4
|
interface Artifact {
|
|
4
5
|
extension?: string
|
|
5
6
|
source: string
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
type TargetName = 'bare-sidecar'
|
|
9
|
+
type TargetName = 'bare-sidecar' | 'bare-worker'
|
|
9
10
|
|
|
10
11
|
interface TargetContext {
|
|
11
12
|
bundleSpecifier: string
|
|
@@ -46,11 +47,9 @@ interface RPCClient {
|
|
|
46
47
|
type: string
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
interface StowOptions {
|
|
50
|
+
interface StowOptions extends Omit<PackOptions, 'offload' | 'linked' | 'resolve' | 'aliases'> {
|
|
50
51
|
client?: RPC | RPCName
|
|
51
52
|
server?: RPC | RPCName
|
|
52
|
-
base?: URL | string
|
|
53
|
-
hosts?: string[]
|
|
54
53
|
resolveTarget?(name: string): Target
|
|
55
54
|
resolveRPC?(name: string): RPC
|
|
56
55
|
}
|
package/lib/protocol.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { Duplex } from 'bare-stream'
|
|
1
|
+
import { Duplex, DuplexEvents } from 'bare-stream'
|
|
2
2
|
|
|
3
3
|
declare const CONTROL: number
|
|
4
4
|
declare const USER: number
|
|
5
5
|
|
|
6
|
-
interface
|
|
6
|
+
interface ProtocolEvents extends DuplexEvents {
|
|
7
|
+
ready: []
|
|
8
|
+
terminate: []
|
|
9
|
+
exit: [code: number]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface Protocol<E extends ProtocolEvents = ProtocolEvents> extends Duplex<E> {
|
|
7
13
|
send(type: string, payload?: object): Promise<void>
|
|
8
14
|
}
|
|
9
15
|
|
|
@@ -13,4 +19,4 @@ declare class Protocol {
|
|
|
13
19
|
|
|
14
20
|
declare function attach(stream: Duplex): Protocol
|
|
15
21
|
|
|
16
|
-
export { type Protocol, attach, CONTROL, USER }
|
|
22
|
+
export { type Protocol, ProtocolEvents, attach, CONTROL, USER }
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
exports.name = 'bare-worker'
|
|
2
|
+
exports.linked = false
|
|
3
|
+
exports.offload = true
|
|
4
|
+
exports.format = 'bundle'
|
|
5
|
+
exports.encoding = null
|
|
6
|
+
exports.extension = '.bundle'
|
|
7
|
+
exports.hosts = [
|
|
8
|
+
'darwin-arm64',
|
|
9
|
+
'darwin-x64',
|
|
10
|
+
'linux-arm64',
|
|
11
|
+
'linux-x64',
|
|
12
|
+
'win32-arm64',
|
|
13
|
+
'win32-x64'
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
exports.generate = function generate(opts) {
|
|
17
|
+
const { bundleSpecifier, ipc, rpc, module = 'cjs', client = null } = opts
|
|
18
|
+
|
|
19
|
+
const esm = module === 'esm'
|
|
20
|
+
|
|
21
|
+
const returned = client ? `{ ${ipc}, ${rpc} }` : `{ ${ipc} }`
|
|
22
|
+
|
|
23
|
+
const handle = client
|
|
24
|
+
? `{ ${ipc}: import('bare-stow/host').IPC; ${rpc}: ${client.type} }`
|
|
25
|
+
: `{ ${ipc}: import('bare-stow/host').IPC }`
|
|
26
|
+
|
|
27
|
+
const source = esm
|
|
28
|
+
? `\
|
|
29
|
+
import Worker from 'bare-worker'
|
|
30
|
+
import stow from 'bare-stow/host'
|
|
31
|
+
import { fileURLToPath } from 'bare-url'
|
|
32
|
+
|
|
33
|
+
const bundle = fileURLToPath(new URL(${JSON.stringify(bundleSpecifier)}, import.meta.url))
|
|
34
|
+
|
|
35
|
+
export async function start(opts = {}) {
|
|
36
|
+
const worker = new Worker(bundle, opts)
|
|
37
|
+
|
|
38
|
+
const ${ipc} = stow.wrap(worker.IPC)
|
|
39
|
+
${client ? '\n' + indent(client.source, 2) : ''}
|
|
40
|
+
await ${ipc}.ready
|
|
41
|
+
|
|
42
|
+
return ${returned}
|
|
43
|
+
}
|
|
44
|
+
`
|
|
45
|
+
: `\
|
|
46
|
+
const path = require('bare-path')
|
|
47
|
+
const Worker = require('bare-worker')
|
|
48
|
+
const stow = require('bare-stow/host')
|
|
49
|
+
|
|
50
|
+
const bundle = path.join(__dirname, ${JSON.stringify(bundleSpecifier)})
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
async start(opts = {}) {
|
|
54
|
+
const worker = new Worker(bundle, opts)
|
|
55
|
+
|
|
56
|
+
const ${ipc} = stow.wrap(worker.IPC)
|
|
57
|
+
${client ? '\n' + indent(client.source, 4) : ''}
|
|
58
|
+
await ${ipc}.ready
|
|
59
|
+
|
|
60
|
+
return ${returned}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`
|
|
64
|
+
|
|
65
|
+
return [
|
|
66
|
+
{ source },
|
|
67
|
+
{
|
|
68
|
+
extension: '.d.ts',
|
|
69
|
+
source: `\
|
|
70
|
+
export function start(opts?: import('bare-worker').WorkerOptions): Promise<${handle}>
|
|
71
|
+
`
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function indent(source, spaces) {
|
|
77
|
+
const pad = ' '.repeat(spaces)
|
|
78
|
+
return source
|
|
79
|
+
.split('\n')
|
|
80
|
+
.map((line) => (line.length === 0 ? line : pad + line))
|
|
81
|
+
.join('\n')
|
|
82
|
+
}
|
package/lib/target.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-stow",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Module bundling and harness generation for Bare",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package": "./package.json",
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"bare-rpc": "^1.3.2",
|
|
78
78
|
"bare-sidecar": "^0.5.0",
|
|
79
|
+
"bare-worker": "^4.3.0",
|
|
79
80
|
"brittle": "^4.0.2",
|
|
80
81
|
"lunte": "^1.7.0",
|
|
81
82
|
"prettier": "^3.3.3",
|