@gadgetinc/substrate 0.1.0-rc.1

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 (181) hide show
  1. package/dist/assets/kernel.wasm +0 -0
  2. package/dist/assets/manifest.json +32 -0
  3. package/dist/assets/network-driver.js +2 -0
  4. package/dist/assets/network-driver.js.map +1 -0
  5. package/dist/assets/runtime.js +264 -0
  6. package/dist/assets/runtime.js.map +1 -0
  7. package/dist/binaries.d.ts +58 -0
  8. package/dist/binaries.d.ts.map +1 -0
  9. package/dist/boot/index.d.ts +318 -0
  10. package/dist/boot/index.d.ts.map +1 -0
  11. package/dist/index.d.ts +8 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +4589 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/kernel/bridge.d.ts +64 -0
  16. package/dist/kernel/bridge.d.ts.map +1 -0
  17. package/dist/kernel/types.d.ts +518 -0
  18. package/dist/kernel/types.d.ts.map +1 -0
  19. package/dist/kernel/wasm.d.ts +20 -0
  20. package/dist/kernel/wasm.d.ts.map +1 -0
  21. package/dist/node/assert.d.ts +99 -0
  22. package/dist/node/assert.d.ts.map +1 -0
  23. package/dist/node/async_hooks.d.ts +88 -0
  24. package/dist/node/async_hooks.d.ts.map +1 -0
  25. package/dist/node/buffer.d.ts +62 -0
  26. package/dist/node/buffer.d.ts.map +1 -0
  27. package/dist/node/child_process.d.ts +300 -0
  28. package/dist/node/child_process.d.ts.map +1 -0
  29. package/dist/node/cluster.d.ts +37 -0
  30. package/dist/node/cluster.d.ts.map +1 -0
  31. package/dist/node/constants.d.ts +306 -0
  32. package/dist/node/constants.d.ts.map +1 -0
  33. package/dist/node/crypto.d.ts +176 -0
  34. package/dist/node/crypto.d.ts.map +1 -0
  35. package/dist/node/dgram.d.ts +44 -0
  36. package/dist/node/dgram.d.ts.map +1 -0
  37. package/dist/node/diagnostics_channel.d.ts +57 -0
  38. package/dist/node/diagnostics_channel.d.ts.map +1 -0
  39. package/dist/node/dns.d.ts +278 -0
  40. package/dist/node/dns.d.ts.map +1 -0
  41. package/dist/node/domain.d.ts +21 -0
  42. package/dist/node/domain.d.ts.map +1 -0
  43. package/dist/node/events.d.ts +54 -0
  44. package/dist/node/events.d.ts.map +1 -0
  45. package/dist/node/fs/promises.d.ts +116 -0
  46. package/dist/node/fs/promises.d.ts.map +1 -0
  47. package/dist/node/fs.d.ts +536 -0
  48. package/dist/node/fs.d.ts.map +1 -0
  49. package/dist/node/http.d.ts +471 -0
  50. package/dist/node/http.d.ts.map +1 -0
  51. package/dist/node/http2.d.ts +508 -0
  52. package/dist/node/http2.d.ts.map +1 -0
  53. package/dist/node/https.d.ts +42 -0
  54. package/dist/node/https.d.ts.map +1 -0
  55. package/dist/node/inspector.d.ts +25 -0
  56. package/dist/node/inspector.d.ts.map +1 -0
  57. package/dist/node/net.d.ts +231 -0
  58. package/dist/node/net.d.ts.map +1 -0
  59. package/dist/node/os.d.ts +318 -0
  60. package/dist/node/os.d.ts.map +1 -0
  61. package/dist/node/path.d.ts +144 -0
  62. package/dist/node/path.d.ts.map +1 -0
  63. package/dist/node/process.d.ts +105 -0
  64. package/dist/node/process.d.ts.map +1 -0
  65. package/dist/node/punycode.d.ts +34 -0
  66. package/dist/node/punycode.d.ts.map +1 -0
  67. package/dist/node/querystring.d.ts +49 -0
  68. package/dist/node/querystring.d.ts.map +1 -0
  69. package/dist/node/readline.d.ts +99 -0
  70. package/dist/node/readline.d.ts.map +1 -0
  71. package/dist/node/stream.d.ts +409 -0
  72. package/dist/node/stream.d.ts.map +1 -0
  73. package/dist/node/string_decoder.d.ts +46 -0
  74. package/dist/node/string_decoder.d.ts.map +1 -0
  75. package/dist/node/timers.d.ts +79 -0
  76. package/dist/node/timers.d.ts.map +1 -0
  77. package/dist/node/tls.d.ts +159 -0
  78. package/dist/node/tls.d.ts.map +1 -0
  79. package/dist/node/trace_events.d.ts +18 -0
  80. package/dist/node/trace_events.d.ts.map +1 -0
  81. package/dist/node/tty.d.ts +67 -0
  82. package/dist/node/tty.d.ts.map +1 -0
  83. package/dist/node/url.d.ts +85 -0
  84. package/dist/node/url.d.ts.map +1 -0
  85. package/dist/node/util.d.ts +252 -0
  86. package/dist/node/util.d.ts.map +1 -0
  87. package/dist/node/v8.d.ts +134 -0
  88. package/dist/node/v8.d.ts.map +1 -0
  89. package/dist/node/vm.d.ts +89 -0
  90. package/dist/node/vm.d.ts.map +1 -0
  91. package/dist/node/wasi.d.ts +25 -0
  92. package/dist/node/wasi.d.ts.map +1 -0
  93. package/dist/node/worker_threads.d.ts +206 -0
  94. package/dist/node/worker_threads.d.ts.map +1 -0
  95. package/dist/node/ws.d.ts +110 -0
  96. package/dist/node/ws.d.ts.map +1 -0
  97. package/dist/node/zlib.d.ts +328 -0
  98. package/dist/node/zlib.d.ts.map +1 -0
  99. package/dist/persistence/opfs-store.d.ts +93 -0
  100. package/dist/persistence/opfs-store.d.ts.map +1 -0
  101. package/dist/runtime/async-function-shim.d.ts +27 -0
  102. package/dist/runtime/async-function-shim.d.ts.map +1 -0
  103. package/dist/runtime/fs-interface.d.ts +60 -0
  104. package/dist/runtime/fs-interface.d.ts.map +1 -0
  105. package/dist/runtime/index.d.ts +113 -0
  106. package/dist/runtime/index.d.ts.map +1 -0
  107. package/dist/runtime/loader.d.ts +50 -0
  108. package/dist/runtime/loader.d.ts.map +1 -0
  109. package/dist/runtime/loaders/async-transform.d.ts +40 -0
  110. package/dist/runtime/loaders/async-transform.d.ts.map +1 -0
  111. package/dist/runtime/loaders/cjs.d.ts +37 -0
  112. package/dist/runtime/loaders/cjs.d.ts.map +1 -0
  113. package/dist/runtime/loaders/detect-module-type.d.ts +21 -0
  114. package/dist/runtime/loaders/detect-module-type.d.ts.map +1 -0
  115. package/dist/runtime/loaders/esm.d.ts +140 -0
  116. package/dist/runtime/loaders/esm.d.ts.map +1 -0
  117. package/dist/runtime/loaders/source-map-registry.d.ts +43 -0
  118. package/dist/runtime/loaders/source-map-registry.d.ts.map +1 -0
  119. package/dist/runtime/loaders/source-map.d.ts +50 -0
  120. package/dist/runtime/loaders/source-map.d.ts.map +1 -0
  121. package/dist/runtime/loaders/utils.d.ts +6 -0
  122. package/dist/runtime/loaders/utils.d.ts.map +1 -0
  123. package/dist/runtime/native-globals.d.ts +24 -0
  124. package/dist/runtime/native-globals.d.ts.map +1 -0
  125. package/dist/runtime/network-driver.d.ts +78 -0
  126. package/dist/runtime/network-driver.d.ts.map +1 -0
  127. package/dist/runtime/process-context.d.ts +96 -0
  128. package/dist/runtime/process-context.d.ts.map +1 -0
  129. package/dist/runtime/process-event-loop.d.ts +356 -0
  130. package/dist/runtime/process-event-loop.d.ts.map +1 -0
  131. package/dist/runtime/process-handler.d.ts +71 -0
  132. package/dist/runtime/process-handler.d.ts.map +1 -0
  133. package/dist/runtime/process-handlers/node.d.ts +22 -0
  134. package/dist/runtime/process-handlers/node.d.ts.map +1 -0
  135. package/dist/runtime/process-handlers/npm.d.ts +20 -0
  136. package/dist/runtime/process-handlers/npm.d.ts.map +1 -0
  137. package/dist/runtime/process-handlers/npx.d.ts +11 -0
  138. package/dist/runtime/process-handlers/npx.d.ts.map +1 -0
  139. package/dist/runtime/process-handlers/pnpm.d.ts +12 -0
  140. package/dist/runtime/process-handlers/pnpm.d.ts.map +1 -0
  141. package/dist/runtime/process-handlers/shell.d.ts +24 -0
  142. package/dist/runtime/process-handlers/shell.d.ts.map +1 -0
  143. package/dist/runtime/process-handlers/yarn.d.ts +12 -0
  144. package/dist/runtime/process-handlers/yarn.d.ts.map +1 -0
  145. package/dist/runtime/process-helpers.d.ts +17 -0
  146. package/dist/runtime/process-helpers.d.ts.map +1 -0
  147. package/dist/runtime/process-manager.d.ts +87 -0
  148. package/dist/runtime/process-manager.d.ts.map +1 -0
  149. package/dist/runtime/process-scheduler.d.ts +123 -0
  150. package/dist/runtime/process-scheduler.d.ts.map +1 -0
  151. package/dist/runtime/process-waker.d.ts +24 -0
  152. package/dist/runtime/process-waker.d.ts.map +1 -0
  153. package/dist/runtime/promise.d.ts +44 -0
  154. package/dist/runtime/promise.d.ts.map +1 -0
  155. package/dist/runtime/stack-trace.d.ts +52 -0
  156. package/dist/runtime/stack-trace.d.ts.map +1 -0
  157. package/dist/runtime/wasm-package-interceptor.d.ts +141 -0
  158. package/dist/runtime/wasm-package-interceptor.d.ts.map +1 -0
  159. package/dist/runtime/web-streams.d.ts +57 -0
  160. package/dist/runtime/web-streams.d.ts.map +1 -0
  161. package/dist/runtime/websocket.d.ts +102 -0
  162. package/dist/runtime/websocket.d.ts.map +1 -0
  163. package/dist/shim/websocket-shim-inline.d.ts +9 -0
  164. package/dist/shim/websocket-shim-inline.d.ts.map +1 -0
  165. package/dist/shim/websocket-shim.d.ts +15 -0
  166. package/dist/shim/websocket-shim.d.ts.map +1 -0
  167. package/dist/sw/index.d.ts +53 -0
  168. package/dist/sw/index.d.ts.map +1 -0
  169. package/dist/utils/debug.d.ts +75 -0
  170. package/dist/utils/debug.d.ts.map +1 -0
  171. package/dist/utils/path.d.ts +20 -0
  172. package/dist/utils/path.d.ts.map +1 -0
  173. package/dist/utils/tarball.d.ts +37 -0
  174. package/dist/utils/tarball.d.ts.map +1 -0
  175. package/dist/utils/websocket-protocol.d.ts +102 -0
  176. package/dist/utils/websocket-protocol.d.ts.map +1 -0
  177. package/dist/worker/host.d.ts +14 -0
  178. package/dist/worker/host.d.ts.map +1 -0
  179. package/dist/worker/types.d.ts +209 -0
  180. package/dist/worker/types.d.ts.map +1 -0
  181. package/package.json +53 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/runtime/websocket.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAGL,KAAK,mBAAmB,EASzB,MAAM,gCAAgC,CAAC;AAQxC,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3B,OAAO,EA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AE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAO3D;IAED,IAAI,UAAU,IAAI,mBAAmB,CAEpC;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;OAEG;IACH,OAAO,CAAC,QAAQ;YA6DF,aAAa;IAuC3B;;OAEG;IACH,OAAO,CAAC,aAAa;IAmBrB;;OAEG;IACH,OAAO,CAAC,WAAW;IAyDnB;;OAEG;IACH,OAAO,CAAC,cAAc;IAgEtB;;OAEG;IACH,OAAO,CAAC,UAAU;IAkBlB;;OAEG;IACH,OAAO,CAAC,eAAe;IAKvB;;OAEG;IACH,OAAO,CAAC,QAAQ;IA8BhB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,UAAU;IAYlB;;OAEG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,IAAI,CAoBlD;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,SAAO,EAAE,MAAM,SAAK,GAAG,IAAI,CAqBpC;CACF"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Inline WebSocket Shim
3
+ *
4
+ * This exports the WebSocket shim as a string that can be injected into HTML pages.
5
+ * The shim patches globalThis.WebSocket to route localhost connections through
6
+ * the Service Worker to Substrate's virtual network.
7
+ */
8
+ export declare const WEBSOCKET_SHIM_SCRIPT: string;
9
+ //# sourceMappingURL=websocket-shim-inline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-shim-inline.d.ts","sourceRoot":"","sources":["../../src/shim/websocket-shim-inline.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,qBAAqB,QA2L1B,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * WebSocket Shim for Pages Served by Substrate
3
+ *
4
+ * This script is injected into HTML pages served by Substrate's virtual server.
5
+ * It patches globalThis.WebSocket to route connections through the Service Worker
6
+ * back to the virtual server running in the worker.
7
+ *
8
+ * Communication flow:
9
+ * Page (ShimWebSocket) → SW (postMessage) → Main Thread (BroadcastChannel) → Worker → Virtual Server
10
+ *
11
+ * This is necessary because Service Workers cannot intercept WebSocket connections,
12
+ * only fetch requests. By patching WebSocket in served pages, we can route HMR
13
+ * connections (e.g., Vite's /__vite_hmr) through our virtual network.
14
+ */
15
+ //# sourceMappingURL=websocket-shim.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-shim.d.ts","sourceRoot":"","sources":["../../src/shim/websocket-shim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Substrate Service Worker
3
+ *
4
+ * Origin-aware network driver that intercepts requests and routes them
5
+ * to the Substrate kernel running in the leader tab's Web Worker.
6
+ *
7
+ * Routing rules (in priority order):
8
+ * 1. Same-origin + basePath prefix → Kernel (prefix stripped, port from config)
9
+ * 2. Same-origin + tracked basePath client → Kernel (port from client tracking)
10
+ * 3. localhost + listening port → Kernel
11
+ * 4. External origin → CORS Proxy (if configured)
12
+ * 5. Everything else → Passthrough to real network
13
+ *
14
+ * BasePath client tracking: When a navigation request matches basePath, the
15
+ * resultingClientId is recorded. Subsequent same-origin requests from that
16
+ * client (e.g., root-relative URLs from an iframe) are automatically routed
17
+ * to the same kernel port, even though they lack the basePath prefix.
18
+ */
19
+ import { type LogLevel } from "../utils/debug.js";
20
+ export interface RoutingConfig {
21
+ /** Base path - all requests below this path go to kernel */
22
+ basePath: string | null;
23
+ /** Port to rewrite basePath requests to (so substrateFetch can route by port) */
24
+ basePathPort: number | null;
25
+ /** Localhost ports that have virtual servers listening */
26
+ listeningPorts: number[];
27
+ /** CORS proxy URL for external requests (optional) */
28
+ proxyUrl?: string;
29
+ /** Domains that don't need proxying (CORS-friendly) */
30
+ neverProxy: string[];
31
+ /** Logging configuration */
32
+ logging?: {
33
+ level?: LogLevel;
34
+ components?: string[];
35
+ };
36
+ }
37
+ declare let config: RoutingConfig;
38
+ /**
39
+ * Tracks Service Worker clients that were served via basePath routing.
40
+ * Maps clientId → basePathPort. When a navigation request matches basePath,
41
+ * we record the resultingClientId so that subsequent sub-resource requests
42
+ * from that client (which won't have the basePath prefix) are routed to
43
+ * the correct kernel port.
44
+ */
45
+ declare const basePathClients: Map<string, number>;
46
+ /**
47
+ * Determine route for non-basePath requests.
48
+ * BasePath routing (prefix match + client tracking) is handled directly
49
+ * in the fetch event handler before this function is called.
50
+ */
51
+ declare function determineRoute(url: URL): "kernel" | "proxy" | "passthrough";
52
+ export { determineRoute, config, basePathClients };
53
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sw/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,EAA+C,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAW/F,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,iFAAiF;IACjF,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,0DAA0D;IAC1D,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,4BAA4B;IAC5B,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,QAAQ,CAAC;QACjB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACvB,CAAC;CACH;AA2ED,QAAA,IAAI,MAAM,EAAE,aAMX,CAAC;AA6BF;;;;;;GAMG;AACH,QAAA,MAAM,eAAe,qBAA4B,CAAC;AAuTlD;;;;GAIG;AACH,iBAAS,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,GAAG,OAAO,GAAG,aAAa,CAwBpE;AA+QD,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Substrate Logging Utility
3
+ *
4
+ * A unified logging system with configurable levels and component filtering.
5
+ *
6
+ * Configuration via globals:
7
+ * - __SUBSTRATE_LOG_LEVEL: "off" | "error" | "warn" | "info" | "debug" | "trace"
8
+ * - __SUBSTRATE_LOG_COMPONENTS: string[] - filter to specific components (empty = all)
9
+ *
10
+ * Or via API:
11
+ * - setLogLevel("debug")
12
+ * - setLogComponents(["vfs", "proc"])
13
+ */
14
+ export type LogLevel = "off" | "error" | "warn" | "info" | "debug" | "trace";
15
+ export interface LogConfig {
16
+ level: LogLevel;
17
+ components: string[];
18
+ }
19
+ export interface Logger {
20
+ error: (...args: unknown[]) => void;
21
+ warn: (...args: unknown[]) => void;
22
+ info: (...args: unknown[]) => void;
23
+ debug: (...args: unknown[]) => void;
24
+ trace: (...args: unknown[]) => void;
25
+ /** Log at a specific level */
26
+ log: (level: LogLevel, ...args: unknown[]) => void;
27
+ }
28
+ /** Get current log level from global config */
29
+ export declare function getLogLevel(): LogLevel;
30
+ /** Set log level at runtime */
31
+ export declare function setLogLevel(level: LogLevel): void;
32
+ /** Get component filter */
33
+ export declare function getLogComponents(): string[];
34
+ export declare function withNoLogging(fn: () => void): void;
35
+ /** Set component filter at runtime */
36
+ export declare function setLogComponents(components: string[]): void;
37
+ /** Get full log config */
38
+ export declare function getLogConfig(): LogConfig;
39
+ /** Set full log config at runtime */
40
+ export declare function setLogConfig(config: Partial<LogConfig>): void;
41
+ /** Check if a log should be emitted based on current config */
42
+ export declare function shouldLog(level: LogLevel, component: string): boolean;
43
+ /** Create a logger for a specific component */
44
+ export declare function createLogger(component: string): Logger;
45
+ /** Kernel logger */
46
+ export declare const kernelLog: Logger;
47
+ /** VFS logger */
48
+ export declare const vfsLog: Logger;
49
+ /** Process logger */
50
+ export declare const procLog: Logger;
51
+ /** Network logger */
52
+ export declare const netLog: Logger;
53
+ /** Event loop logger */
54
+ export declare const eventLog: Logger;
55
+ /** Module loader logger */
56
+ export declare const moduleLog: Logger;
57
+ /** ESM loader logger */
58
+ export declare const esmLog: Logger;
59
+ /** HTTP logger */
60
+ export declare const httpLog: Logger;
61
+ /** WebSocket logger */
62
+ export declare const wsLog: Logger;
63
+ /** Child process logger */
64
+ export declare const childLog: Logger;
65
+ /** Buffer logger */
66
+ export declare const bufferLog: Logger;
67
+ /** Stream logger */
68
+ export declare const streamLog: Logger;
69
+ /** FS logger */
70
+ export declare const fsLog: Logger;
71
+ /** Worker logger (for worker/client communication) */
72
+ export declare const workerLog: Logger;
73
+ /** Runtime logger */
74
+ export declare const runtimeLog: Logger;
75
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/utils/debug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4BH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAE7E,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,QAAQ,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,8BAA8B;IAC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AACvB,eAAO,MAAM,KAAK,QAAqB,CAAC;AAExC,2BAA2B;AAC3B,eAAO,MAAM,QAAQ,QAAgC,CAAC;AAEtD,oBAAoB;AACpB,eAAO,MAAM,SAAS,QAAyB,CAAC;AAEhD,oBAAoB;AACpB,eAAO,MAAM,SAAS,QAAyB,CAAC;AAEhD,gBAAgB;AAChB,eAAO,MAAM,KAAK,QAAqB,CAAC;AAExC,sDAAsD;AACtD,eAAO,MAAM,SAAS,QAAyB,CAAC;AAEhD,qBAAqB;AACrB,eAAO,MAAM,UAAU,QAA0B,CAAC"}
@@ -0,0 +1,20 @@
1
+ export declare function dirname(path: string): string;
2
+ export declare function basename(path: string, ext?: string): string;
3
+ export declare function extname(path: string): string;
4
+ /**
5
+ * Normalize a path, resolving '..' and '.' segments
6
+ */
7
+ export declare function normalize(path: string): string;
8
+ /**
9
+ * Join path segments
10
+ */
11
+ export declare function join(...paths: string[]): string;
12
+ /**
13
+ * Resolve a sequence of paths to an absolute path
14
+ */
15
+ export declare function resolve(...paths: string[]): string;
16
+ /**
17
+ * Check if path is absolute
18
+ */
19
+ export declare function isAbsolute(path: string): boolean;
20
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA2B5C;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAwB3D;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA0C5C;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAmC9C;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAe/C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,GAAG,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAoBlD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Tarball Extraction Utility
3
+ *
4
+ * Extracts .tgz (gzipped tar) files - commonly used for npm packages.
5
+ * Uses fflate for decompression and implements tar parsing.
6
+ */
7
+ export interface TarEntry {
8
+ name: string;
9
+ type: "file" | "directory" | "symlink";
10
+ mode: number;
11
+ size: number;
12
+ mtime: Date;
13
+ content?: Uint8Array;
14
+ linkname?: string;
15
+ }
16
+ export interface ExtractOptions {
17
+ /** Strip leading path components (default: 1 for npm packages which have "package/" prefix) */
18
+ strip?: number;
19
+ /** Filter function to include/exclude entries */
20
+ filter?: (entry: TarEntry) => boolean;
21
+ }
22
+ /**
23
+ * Extract entries from a .tgz (gzipped tar) buffer
24
+ */
25
+ export declare function extractTgz(tgzBuffer: Uint8Array | ArrayBuffer, options?: ExtractOptions): TarEntry[];
26
+ /**
27
+ * Extract a .tgz to a target directory in the virtual filesystem
28
+ */
29
+ export declare function extractTgzToFs(tgzBuffer: Uint8Array | ArrayBuffer, targetDir: string, fsDriver: {
30
+ mkdir: (path: string, recursive: boolean) => void;
31
+ writeFile: (path: string, bytes: Uint8Array) => void;
32
+ symlink?: (target: string, path: string) => void;
33
+ }, options?: ExtractOptions): Promise<{
34
+ files: number;
35
+ directories: number;
36
+ }>;
37
+ //# sourceMappingURL=tarball.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tarball.d.ts","sourceRoot":"","sources":["../../src/utils/tarball.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,+FAA+F;IAC/F,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC;CACvC;AAoJD;;GAEG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,UAAU,GAAG,WAAW,EACnC,OAAO,GAAE,cAAmB,GAC3B,QAAQ,EAAE,CAwCZ;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,UAAU,GAAG,WAAW,EACnC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE;IACR,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IAClD,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;IACrD,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD,EACD,OAAO,GAAE,cAAmB,GAC3B,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAyDjD"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * WebSocket Protocol Utilities
3
+ *
4
+ * Shared WebSocket protocol implementation used by both:
5
+ * - Runtime-level WebSocket (src/runtime/websocket.ts) - uses syscalls directly
6
+ * - Node.js compat WebSocket (src/node/ws.ts) - uses net.Socket
7
+ *
8
+ * This module contains only protocol logic with no I/O dependencies,
9
+ * making it suitable for use in both contexts.
10
+ */
11
+ /** WebSocket GUID for handshake (RFC 6455) */
12
+ export declare const WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
13
+ /** WebSocket opcodes */
14
+ export declare const OPCODES: {
15
+ readonly CONTINUATION: 0;
16
+ readonly TEXT: 1;
17
+ readonly BINARY: 2;
18
+ readonly CLOSE: 8;
19
+ readonly PING: 9;
20
+ readonly PONG: 10;
21
+ };
22
+ /** WebSocket ready states */
23
+ export declare const READY_STATE: {
24
+ readonly CONNECTING: 0;
25
+ readonly OPEN: 1;
26
+ readonly CLOSING: 2;
27
+ readonly CLOSED: 3;
28
+ };
29
+ export type WebSocketReadyState = (typeof READY_STATE)[keyof typeof READY_STATE];
30
+ export interface ParsedFrame {
31
+ fin: boolean;
32
+ opcode: number;
33
+ masked: boolean;
34
+ payload: Uint8Array;
35
+ frameLength: number;
36
+ }
37
+ export interface WebSocketCloseEvent {
38
+ code: number;
39
+ reason: string;
40
+ wasClean: boolean;
41
+ }
42
+ export interface WebSocketMessageEvent {
43
+ data: string | ArrayBuffer;
44
+ }
45
+ export interface WebSocketErrorEvent {
46
+ type: "error";
47
+ message?: string;
48
+ }
49
+ export interface WebSocketOpenEvent {
50
+ type: "open";
51
+ }
52
+ /**
53
+ * Parse a WebSocket frame from bytes.
54
+ * Returns null if there isn't enough data for a complete frame.
55
+ */
56
+ export declare function parseFrame(data: Uint8Array): ParsedFrame | null;
57
+ /**
58
+ * Create a WebSocket frame.
59
+ *
60
+ * @param opcode - Frame opcode (TEXT, BINARY, CLOSE, PING, PONG)
61
+ * @param payload - Frame payload data
62
+ * @param mask - Whether to mask the frame (clients must mask, servers must not)
63
+ */
64
+ export declare function createFrame(opcode: number, payload: Uint8Array, mask?: boolean): Uint8Array;
65
+ /**
66
+ * Create a close frame payload with code and reason.
67
+ */
68
+ export declare function createClosePayload(code: number, reason: string): Uint8Array;
69
+ /**
70
+ * Parse a close frame payload to extract code and reason.
71
+ */
72
+ export declare function parseClosePayload(payload: Uint8Array): {
73
+ code: number;
74
+ reason: string;
75
+ };
76
+ /**
77
+ * Generate a random WebSocket key for the client handshake.
78
+ */
79
+ export declare function generateWebSocketKey(): string;
80
+ /**
81
+ * Compute the Sec-WebSocket-Accept key for handshake validation.
82
+ * Uses the browser's SubtleCrypto API (async).
83
+ */
84
+ export declare function computeAcceptKeyAsync(key: string): Promise<string>;
85
+ /**
86
+ * Build the HTTP upgrade request headers for WebSocket handshake.
87
+ */
88
+ export declare function buildUpgradeRequest(host: string, port: number, path: string, key: string, protocols?: string[]): string;
89
+ /**
90
+ * Parse HTTP response headers from handshake response.
91
+ * Returns null if headers are incomplete.
92
+ */
93
+ export declare function parseHandshakeResponse(data: Uint8Array): {
94
+ statusLine: string;
95
+ headers: Map<string, string>;
96
+ headerEndIndex: number;
97
+ } | null;
98
+ /**
99
+ * Check if headers indicate a WebSocket upgrade request.
100
+ */
101
+ export declare function isUpgradeRequest(headers: Map<string, string> | Record<string, string>): boolean;
102
+ //# sourceMappingURL=websocket-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket-protocol.d.ts","sourceRoot":"","sources":["../../src/utils/websocket-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,8CAA8C;AAC9C,eAAO,MAAM,OAAO,yCAAyC,CAAC;AAE9D,wBAAwB;AACxB,eAAO,MAAM,OAAO;;;;;;;CAOV,CAAC;AAEX,6BAA6B;AAC7B,eAAO,MAAM,WAAW;;;;;CAKd,CAAC;AAMX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAEjF,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,OAAO,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,UAAU,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MA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,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAsB/F"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Substrate Worker Host
3
+ *
4
+ * This script runs inside a Web Worker and hosts the Substrate runtime.
5
+ * It receives messages from the main thread and executes them against the kernel.
6
+ *
7
+ * Usage:
8
+ * ```ts
9
+ * import { bootSubstrate } from '@gadgetinc/substrate/boot';
10
+ * const substrate = await bootSubstrate();
11
+ * ```
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/worker/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Worker Message Types
3
+ *
4
+ * Defines the protocol for communication between the main thread and the Substrate Worker.
5
+ */
6
+ import type { BinarySpec } from "../binaries.js";
7
+ import type { WasmPackageMapping } from "../runtime/wasm-package-interceptor.js";
8
+ export interface InitRequest {
9
+ type: "init";
10
+ id: number;
11
+ kernel: string;
12
+ cwd?: string;
13
+ env?: Record<string, string>;
14
+ argv?: string[];
15
+ config?: {
16
+ limits?: {
17
+ max_file_bytes?: number;
18
+ max_total_bytes?: number;
19
+ max_conn_buffer_bytes?: number;
20
+ };
21
+ features?: {
22
+ net_listen?: boolean;
23
+ proc_spawn?: boolean;
24
+ fs_watch?: boolean;
25
+ timers?: boolean;
26
+ };
27
+ /** OPFS store name for persistence. When set, the worker opens an OpfsStore
28
+ * and wires host imports before WASM instantiation. */
29
+ storeName?: string;
30
+ };
31
+ /** Logging configuration for the worker */
32
+ logging?: {
33
+ level?: "off" | "error" | "warn" | "info" | "debug" | "trace";
34
+ components?: string[];
35
+ };
36
+ /** Debug options */
37
+ debug?: {
38
+ /** Track VFS writes (logs file paths and sizes) */
39
+ trackVfs?: boolean;
40
+ };
41
+ /** Binaries to bootstrap during init */
42
+ binaries?: {
43
+ npm?: BinarySpec;
44
+ };
45
+ /** Custom WASM package mappings */
46
+ wasmPackages?: WasmPackageMapping[];
47
+ }
48
+ export interface SyscallRequest {
49
+ type: "syscall";
50
+ id: number;
51
+ pid?: number;
52
+ op: string;
53
+ args?: Record<string, unknown>;
54
+ }
55
+ export interface DeliverRequest {
56
+ type: "deliver";
57
+ id: number;
58
+ msg: Record<string, unknown>;
59
+ }
60
+ export interface HttpListenRequest {
61
+ type: "http_listen";
62
+ id: number;
63
+ port: number;
64
+ }
65
+ export interface HttpFetchRequest {
66
+ type: "http_fetch";
67
+ id: number;
68
+ url: string;
69
+ method: string;
70
+ headers: Array<[string, string]>;
71
+ body?: Uint8Array;
72
+ }
73
+ export interface ShutdownRequest {
74
+ type: "shutdown";
75
+ id: number;
76
+ }
77
+ /** Create a WebSocket connection to a virtual server */
78
+ export interface WsConnectRequest {
79
+ type: "ws_connect";
80
+ id: number;
81
+ wsId: number;
82
+ url: string;
83
+ protocols?: string[];
84
+ }
85
+ /** Send data on a WebSocket connection */
86
+ export interface WsSendRequest {
87
+ type: "ws_send";
88
+ id: number;
89
+ wsId: number;
90
+ data: string | Uint8Array;
91
+ }
92
+ /** Close a WebSocket connection */
93
+ export interface WsCloseRequest {
94
+ type: "ws_close";
95
+ id: number;
96
+ wsId: number;
97
+ code?: number;
98
+ reason?: string;
99
+ }
100
+ /** Flush dirty inodes to persistent store and save VFS metadata */
101
+ export interface FlushRequest {
102
+ type: "flush";
103
+ id: number;
104
+ }
105
+ /** Open an OPFS store and mount its VFS (lazy, metadata-only) */
106
+ export interface MountStoreRequest {
107
+ type: "mount_store";
108
+ id: number;
109
+ storeName: string;
110
+ }
111
+ /** List available OPFS store names */
112
+ export interface ListStoresRequest {
113
+ type: "list_stores";
114
+ id: number;
115
+ }
116
+ /** Delete an OPFS store and all its data */
117
+ export interface DeleteStoreRequest {
118
+ type: "delete_store";
119
+ id: number;
120
+ storeName: string;
121
+ }
122
+ export type WorkerRequest = InitRequest | SyscallRequest | DeliverRequest | HttpListenRequest | HttpFetchRequest | ShutdownRequest | WsConnectRequest | WsSendRequest | WsCloseRequest | FlushRequest | MountStoreRequest | ListStoresRequest | DeleteStoreRequest;
123
+ export interface SuccessResponse {
124
+ type: "success";
125
+ id: number;
126
+ result: unknown;
127
+ }
128
+ export interface ErrorResponse {
129
+ type: "error";
130
+ id: number;
131
+ error: {
132
+ message: string;
133
+ code?: string;
134
+ stack?: string;
135
+ };
136
+ }
137
+ export interface HttpResponseMessage {
138
+ type: "http_response";
139
+ id: number;
140
+ status: number;
141
+ headers: Array<[string, string]>;
142
+ body: Uint8Array;
143
+ }
144
+ export type ConsoleLogLevel = "log" | "info" | "warn" | "error" | "debug";
145
+ export interface LogMessage {
146
+ type: "log";
147
+ level: ConsoleLogLevel;
148
+ args: unknown[];
149
+ }
150
+ export interface ReadyMessage {
151
+ type: "ready";
152
+ }
153
+ /** Sent when server.listen() is called in the worker */
154
+ export interface PortListenMessage {
155
+ type: "port_listen";
156
+ port: number;
157
+ hostname?: string;
158
+ }
159
+ /** Sent when server.close() is called in the worker */
160
+ export interface PortCloseMessage {
161
+ type: "port_close";
162
+ port: number;
163
+ }
164
+ /** WebSocket connection opened successfully */
165
+ export interface WsOpenMessage {
166
+ type: "ws_open";
167
+ wsId: number;
168
+ protocol: string;
169
+ }
170
+ /** WebSocket received a message */
171
+ export interface WsMessageMessage {
172
+ type: "ws_message";
173
+ wsId: number;
174
+ data: string | Uint8Array;
175
+ }
176
+ /** WebSocket connection closed */
177
+ export interface WsCloseMessage {
178
+ type: "ws_close";
179
+ wsId: number;
180
+ code: number;
181
+ reason: string;
182
+ wasClean: boolean;
183
+ }
184
+ /** WebSocket error occurred */
185
+ export interface WsErrorMessage {
186
+ type: "ws_error";
187
+ wsId: number;
188
+ message: string;
189
+ }
190
+ /** Process exited */
191
+ export interface ProcExitMessage {
192
+ type: "proc_exit";
193
+ pid: number;
194
+ exitCode: number;
195
+ }
196
+ /** Process stdout data */
197
+ export interface ProcStdoutMessage {
198
+ type: "proc_stdout";
199
+ pid: number;
200
+ data: string;
201
+ }
202
+ /** Process stderr data */
203
+ export interface ProcStderrMessage {
204
+ type: "proc_stderr";
205
+ pid: number;
206
+ data: string;
207
+ }
208
+ export type WorkerResponse = SuccessResponse | ErrorResponse | HttpResponseMessage | LogMessage | ReadyMessage | PortListenMessage | PortCloseMessage | WsOpenMessage | WsMessageMessage | WsCloseMessage | WsErrorMessage | ProcExitMessage | ProcStdoutMessage | ProcStderrMessage;
209
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/worker/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAMjF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE;QACP,MAAM,CAAC,EAAE;YACP,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,eAAe,CAAC,EAAE,MAAM,CAAC;YACzB,qBAAqB,CAAC,EAAE,MAAM,CAAC;SAChC,CAAC;QACF,QAAQ,CAAC,EAAE;YACT,UAAU,CAAC,EAAE,OAAO,CAAC;YACrB,UAAU,CAAC,EAAE,OAAO,CAAC;YACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB,MAAM,CAAC,EAAE,OAAO,CAAC;SAClB,CAAC;QACF;gEACwD;QACxD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+ "name": "@gadgetinc/substrate",
3
+ "version": "0.1.0-rc.1",
4
+ "license": "UNLICENSED",
5
+ "files": [
6
+ "README.md",
7
+ "dist/**/*"
8
+ ],
9
+ "type": "module",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ },
17
+ "./assets/*": "./dist/assets/*"
18
+ },
19
+ "scripts": {
20
+ "build": "tsgo -p tsconfig.build.json && node ../../scripts/build-bundles.mjs",
21
+ "build:release": "node ../../scripts/build-release.mjs",
22
+ "dev": "tsc --watch",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "test:integration": "playwright test",
26
+ "test:integration:ui": "playwright test --ui",
27
+ "test:integration:headed": "playwright test --headed",
28
+ "test:all": "vitest run && playwright test",
29
+ "bench": "vitest bench --config bench/vitest.bench.config.ts",
30
+ "bench:json": "vitest bench --config bench/vitest.bench.config.ts --outputJson bench/.results.json",
31
+ "bench:compare": "node bench/compare.mjs",
32
+ "bench:baseline": "vitest bench --config bench/vitest.bench.config.ts --outputJson bench/baselines.json"
33
+ },
34
+ "dependencies": {
35
+ "@jridgewell/sourcemap-codec": "^1.5.0",
36
+ "@msgpack/msgpack": "^3.1.3",
37
+ "@noble/hashes": "^2.0.1",
38
+ "acorn": "^8.15.0",
39
+ "es-module-lexer": "^2.0.0",
40
+ "fflate": "^0.8.2",
41
+ "magic-string": "^0.30.0",
42
+ "thumbdrive": "^0.3.0"
43
+ },
44
+ "devDependencies": {
45
+ "@playwright/test": "^1.57.0",
46
+ "@types/node": "^22.0.0",
47
+ "@typescript/native-preview": "^7.0.0-dev.20250601",
48
+ "happy-dom": "^20.0.2",
49
+ "minipass-fetch": "^5.0.0",
50
+ "rolldown": "^1.0.0-beta.8",
51
+ "vitest": "^2.1.0"
52
+ }
53
+ }