@gadgetinc/substrate 0.1.0-rc.1 → 0.1.0-rc.3
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 +269 -0
- package/dist/assets/kernel.wasm +0 -0
- package/dist/assets/manifest.json +10 -10
- package/dist/boot/index.d.ts +8 -6
- package/dist/boot/index.d.ts.map +1 -1
- package/dist/index.js +8 -18
- package/dist/index.js.map +1 -1
- package/dist/kernel/wasm.d.ts +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
# Substrate
|
|
2
|
+
|
|
3
|
+
Browser-native JavaScript runtime with Node.js compatibility, powered by a Rust/WASM kernel.
|
|
4
|
+
|
|
5
|
+
Substrate runs Node-style code entirely in the browser. It provides a virtual filesystem, process model, and 39 Node.js builtin modules so that tools like Vite, npm, and pnpm work without a server.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @gadgetinc/substrate
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { bootSubstrate } from "@gadgetinc/substrate";
|
|
17
|
+
|
|
18
|
+
const substrate = await bootSubstrate();
|
|
19
|
+
|
|
20
|
+
await substrate.mount({
|
|
21
|
+
"server.js": {
|
|
22
|
+
file: {
|
|
23
|
+
contents: `
|
|
24
|
+
const http = require("http");
|
|
25
|
+
http.createServer((req, res) => {
|
|
26
|
+
res.writeHead(200, { "Content-Type": "text/plain" });
|
|
27
|
+
res.end("Hello from Substrate!");
|
|
28
|
+
}).listen(8080);
|
|
29
|
+
`,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const proc = substrate.spawn("node", ["server.js"]);
|
|
35
|
+
await substrate.waitForPort(8080);
|
|
36
|
+
|
|
37
|
+
const response = await fetch("http://localhost:8080/");
|
|
38
|
+
console.log(await response.text()); // "Hello from Substrate!"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Boot Configuration
|
|
42
|
+
|
|
43
|
+
`bootSubstrate` accepts an optional config object:
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const substrate = await bootSubstrate({
|
|
47
|
+
// Multi-tab coordination — all tabs with the same name share a kernel
|
|
48
|
+
name: "my-app",
|
|
49
|
+
|
|
50
|
+
// Initial working directory (default: "/")
|
|
51
|
+
cwd: "/project",
|
|
52
|
+
|
|
53
|
+
// Environment variables
|
|
54
|
+
env: { NODE_ENV: "development" },
|
|
55
|
+
|
|
56
|
+
// Package managers to install (npm enabled by default, others opt-in)
|
|
57
|
+
binaries: {
|
|
58
|
+
pnpm: true,
|
|
59
|
+
yarn: true,
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// CORS proxy for external requests
|
|
63
|
+
proxyUrl: "https://cors-proxy.example.com",
|
|
64
|
+
neverProxy: ["registry.npmjs.org"],
|
|
65
|
+
|
|
66
|
+
// Persist the virtual filesystem across page reloads via OPFS
|
|
67
|
+
persistence: { storeName: "my-project" },
|
|
68
|
+
|
|
69
|
+
// Runtime logging
|
|
70
|
+
logging: { level: "info" },
|
|
71
|
+
|
|
72
|
+
// Callbacks
|
|
73
|
+
onConsole: (level, args) => console.log(`[${level}]`, ...args),
|
|
74
|
+
onPortListen: (port) => console.log(`Server listening on :${port}`),
|
|
75
|
+
onPortClose: (port) => console.log(`Server closed on :${port}`),
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Mounting Files
|
|
80
|
+
|
|
81
|
+
`mount()` writes a file tree to the virtual filesystem. You can mount source code, `node_modules`, config files — anything the guest process needs.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
await substrate.mount({
|
|
85
|
+
"package.json": {
|
|
86
|
+
file: { contents: JSON.stringify({ name: "my-app", type: "module" }) },
|
|
87
|
+
},
|
|
88
|
+
src: {
|
|
89
|
+
directory: {
|
|
90
|
+
"index.js": {
|
|
91
|
+
file: { contents: `console.log("hello")` },
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Mount accepts an optional second argument for the mount point (default `"/"`):
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
await substrate.mount(tree, "/project");
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Spawning Processes
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const proc = substrate.spawn("node", ["src/index.js"], {
|
|
108
|
+
cwd: "/project",
|
|
109
|
+
env: { DEBUG: "true" },
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// Stream stdout/stderr
|
|
113
|
+
const reader = proc.stdout.getReader();
|
|
114
|
+
while (true) {
|
|
115
|
+
const { value, done } = await reader.read();
|
|
116
|
+
if (done) break;
|
|
117
|
+
console.log(value);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Wait for exit
|
|
121
|
+
const exitCode = await proc.exit;
|
|
122
|
+
|
|
123
|
+
// Or kill the process
|
|
124
|
+
proc.kill();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Package manager commands work the same way:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
const install = substrate.spawn("pnpm", ["install"]);
|
|
131
|
+
await install.exit;
|
|
132
|
+
|
|
133
|
+
const dev = substrate.spawn("pnpm", ["run", "dev"]);
|
|
134
|
+
await substrate.waitForPort(5173);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Virtual Networking
|
|
138
|
+
|
|
139
|
+
Servers started inside Substrate are accessible via `fetch()` from the host page. The Service Worker intercepts requests to `localhost` and routes them to the virtual kernel.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
substrate.spawn("node", ["server.js"]); // Listens on :3000
|
|
143
|
+
await substrate.waitForPort(3000);
|
|
144
|
+
|
|
145
|
+
// fetch() just works — the Service Worker handles routing
|
|
146
|
+
const res = await fetch("http://localhost:3000/api/data");
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
WebSocket connections are also routed through the virtual network automatically:
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
const ws = new WebSocket("ws://localhost:3000");
|
|
153
|
+
ws.onopen = () => ws.send("hello");
|
|
154
|
+
ws.onmessage = (e) => console.log(e.data);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Base Path Routing
|
|
158
|
+
|
|
159
|
+
For embedding in iframes or serving from a subpath:
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
const substrate = await bootSubstrate({
|
|
163
|
+
basePath: "/__preview__",
|
|
164
|
+
basePathPort: 5173,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Navigating to /__preview__/ routes to the virtual server on :5173
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Filesystem Operations
|
|
171
|
+
|
|
172
|
+
Read and write files directly without going through a process:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
await substrate.writeFile("/project/config.json", JSON.stringify(config));
|
|
176
|
+
const contents = await substrate.readFile("/project/config.json");
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Persistence
|
|
180
|
+
|
|
181
|
+
Persist the virtual filesystem to OPFS so it survives page reloads:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
// Enable at boot
|
|
185
|
+
const substrate = await bootSubstrate({
|
|
186
|
+
persistence: { storeName: "my-project" },
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// ... mount files, run processes ...
|
|
190
|
+
|
|
191
|
+
// Save current state
|
|
192
|
+
await substrate.persist();
|
|
193
|
+
|
|
194
|
+
// On next page load, the VFS is restored automatically from the store
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
You can also manage stores after boot:
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
await substrate.mountStore("another-project");
|
|
201
|
+
const stores = await substrate.listStores();
|
|
202
|
+
await substrate.deleteStore("old-project");
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## WASM Package Interception
|
|
206
|
+
|
|
207
|
+
When native Node.js addons are detected during `mount()`, Substrate automatically fetches WASM alternatives from npm. Built-in support is included for rollup, esbuild, and rolldown.
|
|
208
|
+
|
|
209
|
+
You can register additional mappings:
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
const substrate = await bootSubstrate({
|
|
213
|
+
wasmPackages: [
|
|
214
|
+
{
|
|
215
|
+
packageName: "my-native-tool",
|
|
216
|
+
wasmPackage: "my-native-tool-wasm",
|
|
217
|
+
nativeBindingPatterns: ["^@my-native-tool/binding-"],
|
|
218
|
+
wasmExportPath: "dist/index.js",
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Multi-Tab Coordination
|
|
225
|
+
|
|
226
|
+
When multiple tabs boot Substrate with the same `name`, one tab becomes the leader (owns the kernel) and others become followers. Leadership changes are communicated via events:
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
const substrate = await bootSubstrate({ name: "my-app" });
|
|
230
|
+
|
|
231
|
+
console.log(substrate.isLeader); // true or false
|
|
232
|
+
|
|
233
|
+
substrate.on("leadership", (isLeader) => {
|
|
234
|
+
console.log(isLeader ? "Became leader" : "Lost leadership");
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Limitations
|
|
239
|
+
|
|
240
|
+
See [docs/limitations.md](docs/limitations.md) for a full list. Key points:
|
|
241
|
+
|
|
242
|
+
- Native Node.js addons (`.node` files) don't work unless a WASM alternative is available
|
|
243
|
+
- `crypto` supports hashing and HMAC but not ciphers, signing, or key exchange
|
|
244
|
+
- `dns`, `tls`, `http2` are stubbed — the browser handles these natively
|
|
245
|
+
- Brotli compression is not supported (deflate/gzip work)
|
|
246
|
+
- Integration tests run against Chromium; Firefox and Safari are untested
|
|
247
|
+
|
|
248
|
+
## Development
|
|
249
|
+
|
|
250
|
+
Requires [Nix](https://nixos.org/) (via `direnv`) for the development environment.
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
pnpm build # Build kernel + JS bundles
|
|
254
|
+
pnpm test # Unit tests (vitest)
|
|
255
|
+
pnpm test:integration # Integration tests (Playwright)
|
|
256
|
+
pnpm typecheck # Type check (tsgo)
|
|
257
|
+
pnpm lint # Lint (oxlint + oxfmt)
|
|
258
|
+
pnpm dev # Dev server (Vite playground)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Repository structure
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
crates/kernel/ — Rust WASM kernel (filesystem, process table, syscalls)
|
|
265
|
+
packages/substrate/ — TypeScript runtime, node compat, boot API
|
|
266
|
+
packages/playground/ — Dev playgrounds (Vite, Express, Fastify, React Router)
|
|
267
|
+
scripts/ — Build and release tooling
|
|
268
|
+
docs/architecture/ — Architecture deep dives
|
|
269
|
+
```
|
package/dist/assets/kernel.wasm
CHANGED
|
Binary file
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.1.0-rc.
|
|
3
|
-
"generatedAt": "2026-02-
|
|
2
|
+
"version": "0.1.0-rc.3",
|
|
3
|
+
"generatedAt": "2026-02-19T14:58:09.611Z",
|
|
4
4
|
"assets": {
|
|
5
5
|
"kernel.wasm": {
|
|
6
|
-
"size":
|
|
7
|
-
"sri": "sha384-
|
|
6
|
+
"size": 594316,
|
|
7
|
+
"sri": "sha384-RL0puGb1uYew0eH0AuYEzK6h9d6f/Bva7+0REQoPK0sxRmKxje5U74HNZ8q/+oSm"
|
|
8
8
|
},
|
|
9
9
|
"runtime.js": {
|
|
10
10
|
"size": 554001,
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
},
|
|
18
18
|
"binaries": {
|
|
19
19
|
"npm-11.8.0-bundle.tgz": {
|
|
20
|
-
"size":
|
|
21
|
-
"sri": "sha384-
|
|
20
|
+
"size": 2752469,
|
|
21
|
+
"sri": "sha384-yVbzCyhA24T9mVbYD7UtdC4qMzEYVxnXu49JuITXUc+fJV3LZMlN6jw6zEZHuyPb"
|
|
22
22
|
},
|
|
23
23
|
"pnpm-10.6.4-bundle.tgz": {
|
|
24
|
-
"size":
|
|
25
|
-
"sri": "sha384-
|
|
24
|
+
"size": 4494190,
|
|
25
|
+
"sri": "sha384-Um3AcZlxNMB75BiX62uge+m2rRBiEDLv9uDqbstKxyhdAN52jVaS2IPfKEjO698q"
|
|
26
26
|
},
|
|
27
27
|
"yarn-1.22.22-bundle.tgz": {
|
|
28
|
-
"size":
|
|
29
|
-
"sri": "sha384-
|
|
28
|
+
"size": 1247414,
|
|
29
|
+
"sri": "sha384-3BcuZTPptPhMYDh1cGJbV6XExXIug13rh0cmkCbhBmiGn6DTbgWmUAIlLBtSWb9/"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
}
|
package/dist/boot/index.d.ts
CHANGED
|
@@ -32,18 +32,20 @@ export interface SubstrateBootConfig {
|
|
|
32
32
|
*/
|
|
33
33
|
name?: string;
|
|
34
34
|
/**
|
|
35
|
-
* URL to the Substrate kernel WASM
|
|
36
|
-
*
|
|
35
|
+
* URL to the Substrate kernel WASM.
|
|
36
|
+
* Defaults to resolving `./assets/kernel.wasm` relative to this module.
|
|
37
37
|
*/
|
|
38
38
|
kernelUrl?: string;
|
|
39
39
|
/**
|
|
40
40
|
* URL to the Substrate runtime entrypoint.
|
|
41
|
-
*
|
|
41
|
+
* Defaults to resolving `./assets/runtime.js` relative to this module.
|
|
42
42
|
*/
|
|
43
43
|
runtimeUrl?: string | URL;
|
|
44
44
|
/**
|
|
45
|
-
* URL to the Substrate network driver entrypoint.
|
|
46
|
-
*
|
|
45
|
+
* URL to the Substrate network driver (service worker) entrypoint.
|
|
46
|
+
* Must be same-origin. Defaults to resolving `./assets/network-driver.js`
|
|
47
|
+
* relative to this module, which works with bundlers that support the
|
|
48
|
+
* `new URL(path, import.meta.url)` pattern (Vite, webpack 5, etc.).
|
|
47
49
|
*/
|
|
48
50
|
networkDriverUrl?: string;
|
|
49
51
|
/**
|
|
@@ -98,7 +100,7 @@ export interface SubstrateBootConfig {
|
|
|
98
100
|
env?: Record<string, string>;
|
|
99
101
|
/**
|
|
100
102
|
* Binaries to install into the runtime.
|
|
101
|
-
*
|
|
103
|
+
* npm is enabled by default. pnpm and yarn are opt-in.
|
|
102
104
|
*/
|
|
103
105
|
binaries?: {
|
|
104
106
|
npm?: boolean | BinarySpec;
|
package/dist/boot/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/boot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAapD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/boot/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAapD,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,gBAAgB,CAAC;AAO7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AACjF,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAMnC,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,UAAU,CAA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AAE,aAAa,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3571,19 +3571,7 @@ const runtimeLog = createLogger("runtime");
|
|
|
3571
3571
|
/** CDN base URL for all Substrate assets. */
|
|
3572
3572
|
const SUBSTRATE_CDN_BASE = "https://assets.gadget.dev/substrate";
|
|
3573
3573
|
/** Package version — kept in sync by scripts/release.mjs. */
|
|
3574
|
-
const SUBSTRATE_VERSION = "0.1.0-rc.
|
|
3575
|
-
/** Get the CDN URL for the kernel WASM binary. */
|
|
3576
|
-
function getKernelUrl(version = SUBSTRATE_VERSION) {
|
|
3577
|
-
return `${SUBSTRATE_CDN_BASE}/v${version}/kernel.wasm`;
|
|
3578
|
-
}
|
|
3579
|
-
/** Get the CDN URL for the Substrate runtime bundle. */
|
|
3580
|
-
function getRuntimeUrl(version = SUBSTRATE_VERSION) {
|
|
3581
|
-
return `${SUBSTRATE_CDN_BASE}/v${version}/runtime.js`;
|
|
3582
|
-
}
|
|
3583
|
-
/** Get the CDN URL for the Substrate network driver bundle. */
|
|
3584
|
-
function getNetworkDriverUrl(version = SUBSTRATE_VERSION) {
|
|
3585
|
-
return `${SUBSTRATE_CDN_BASE}/v${version}/network-driver.js`;
|
|
3586
|
-
}
|
|
3574
|
+
const SUBSTRATE_VERSION = "0.1.0-rc.3";
|
|
3587
3575
|
/** Get the CDN URL for a binary tarball (e.g., npm, yarn, pnpm). */
|
|
3588
3576
|
function getBinaryTarballUrl(binary, binaryVersion, version = SUBSTRATE_VERSION) {
|
|
3589
3577
|
return `${SUBSTRATE_CDN_BASE}/v${version}/${binary}-${binaryVersion}-bundle.tgz`;
|
|
@@ -3690,6 +3678,8 @@ function getBinaryNames() {
|
|
|
3690
3678
|
* ```
|
|
3691
3679
|
*/
|
|
3692
3680
|
const bootLog = createLogger("boot");
|
|
3681
|
+
const KERNEL_ASSET_URL = new URL("./assets/kernel.wasm", import.meta.url).href;
|
|
3682
|
+
const RUNTIME_ASSET_URL = new URL("./assets/runtime.js", import.meta.url).href;
|
|
3693
3683
|
/** WebSocket ready states */
|
|
3694
3684
|
const WS_CONNECTING = 0;
|
|
3695
3685
|
const WS_OPEN = 1;
|
|
@@ -3904,10 +3894,10 @@ function configureServiceWorker(registration, config) {
|
|
|
3904
3894
|
}
|
|
3905
3895
|
/**
|
|
3906
3896
|
* Get the URL to the Substrate runtime entrypoint.
|
|
3907
|
-
*
|
|
3897
|
+
* Resolves from the npm package assets by default.
|
|
3908
3898
|
*/
|
|
3909
3899
|
function getRuntimeURL() {
|
|
3910
|
-
return new URL(
|
|
3900
|
+
return new URL(RUNTIME_ASSET_URL);
|
|
3911
3901
|
}
|
|
3912
3902
|
/**
|
|
3913
3903
|
* Boot Substrate with Service Worker network interception and multi-tab coordination.
|
|
@@ -3933,7 +3923,7 @@ function getRuntimeURL() {
|
|
|
3933
3923
|
* ```
|
|
3934
3924
|
*/
|
|
3935
3925
|
async function bootSubstrate(config = {}) {
|
|
3936
|
-
const networkDriverUrl = config.networkDriverUrl ??
|
|
3926
|
+
const networkDriverUrl = config.networkDriverUrl ?? new URL("./assets/network-driver.js", import.meta.url).href;
|
|
3937
3927
|
const basePath = config.basePath ?? null;
|
|
3938
3928
|
const basePathPort = config.basePathPort ?? null;
|
|
3939
3929
|
const registration = await registerServiceWorker(networkDriverUrl);
|
|
@@ -4294,13 +4284,13 @@ async function createSubstrateClient(config, routingConfig, registration) {
|
|
|
4294
4284
|
const binaries = {};
|
|
4295
4285
|
for (const binaryName of getBinaryNames()) {
|
|
4296
4286
|
const spec = config.binaries?.[binaryName];
|
|
4297
|
-
if (spec === true || spec === void 0) binaries[binaryName] = { tarUrl: getDefaultTarballUrl(binaryName, config.binaryTarballBaseUrl) };
|
|
4287
|
+
if (spec === true || spec === void 0 && binaryName === "npm") binaries[binaryName] = { tarUrl: getDefaultTarballUrl(binaryName, config.binaryTarballBaseUrl) };
|
|
4298
4288
|
else if (spec) binaries[binaryName] = spec;
|
|
4299
4289
|
}
|
|
4300
4290
|
await send({
|
|
4301
4291
|
type: "init",
|
|
4302
4292
|
id: nextId++,
|
|
4303
|
-
kernel: config.kernelUrl ??
|
|
4293
|
+
kernel: config.kernelUrl ?? KERNEL_ASSET_URL,
|
|
4304
4294
|
cwd: config.cwd ?? "/",
|
|
4305
4295
|
env: config.env ?? { NODE_ENV: "development" },
|
|
4306
4296
|
config: {
|