wrangler 0.0.0-bf67bf2 → 0.0.0-bfbb0be

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 (179) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +27 -14
  3. package/bin/wrangler.js +106 -5
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +4886 -0
  6. package/package.json +76 -36
  7. package/src/__tests__/config-cache.test.ts +36 -0
  8. package/src/__tests__/configuration.test.ts +3548 -0
  9. package/src/__tests__/dev.test.tsx +1055 -0
  10. package/src/__tests__/guess-worker-format.test.ts +85 -0
  11. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  12. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  15. package/src/__tests__/helpers/mock-bin.ts +36 -0
  16. package/src/__tests__/helpers/mock-cfetch.ts +211 -0
  17. package/src/__tests__/helpers/mock-console.ts +97 -0
  18. package/src/__tests__/helpers/mock-dialogs.ts +153 -0
  19. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  20. package/src/__tests__/helpers/mock-istty.ts +32 -0
  21. package/src/__tests__/helpers/mock-kv.ts +33 -0
  22. package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
  23. package/src/__tests__/helpers/mock-process.ts +39 -0
  24. package/src/__tests__/helpers/mock-stdin.ts +108 -0
  25. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  26. package/src/__tests__/helpers/run-in-tmp.ts +39 -0
  27. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  28. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  29. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  30. package/src/__tests__/https-options.test.ts +130 -0
  31. package/src/__tests__/index.test.ts +235 -130
  32. package/src/__tests__/init.test.ts +1992 -0
  33. package/src/__tests__/jest.setup.ts +107 -0
  34. package/src/__tests__/kv.test.ts +1619 -0
  35. package/src/__tests__/logger.test.ts +141 -0
  36. package/src/__tests__/package-manager.test.ts +353 -0
  37. package/src/__tests__/pages.test.ts +1242 -0
  38. package/src/__tests__/parse.test.ts +330 -0
  39. package/src/__tests__/publish.test.ts +6188 -0
  40. package/src/__tests__/r2.test.ts +233 -0
  41. package/src/__tests__/route.test.ts +45 -0
  42. package/src/__tests__/secret.test.ts +486 -0
  43. package/src/__tests__/tail.test.ts +690 -0
  44. package/src/__tests__/user.test.ts +132 -0
  45. package/src/__tests__/whoami.test.tsx +139 -0
  46. package/src/abort.d.ts +3 -0
  47. package/src/bundle-reporter.tsx +29 -0
  48. package/src/bundle.ts +204 -0
  49. package/src/cfetch/index.ts +121 -0
  50. package/src/cfetch/internal.ts +142 -0
  51. package/src/cli.ts +10 -7
  52. package/src/config/README.md +107 -0
  53. package/src/config/config.ts +243 -0
  54. package/src/config/diagnostics.ts +80 -0
  55. package/src/config/environment.ts +420 -0
  56. package/src/config/index.ts +225 -0
  57. package/src/config/validation-helpers.ts +584 -0
  58. package/src/config/validation.ts +1580 -0
  59. package/src/config-cache.ts +44 -0
  60. package/src/create-worker-preview.ts +185 -0
  61. package/src/create-worker-upload-form.ts +254 -0
  62. package/src/dev/dev-vars.ts +36 -0
  63. package/src/dev/dev.tsx +399 -0
  64. package/src/dev/local.tsx +321 -0
  65. package/src/dev/remote.tsx +282 -0
  66. package/src/dev/use-esbuild.ts +112 -0
  67. package/src/dialogs.tsx +68 -18
  68. package/src/durable.ts +102 -0
  69. package/src/entry.ts +328 -0
  70. package/src/environment-variables.ts +35 -0
  71. package/src/errors.ts +11 -0
  72. package/src/git-client.ts +42 -0
  73. package/src/https-options.ts +123 -0
  74. package/src/index.tsx +2092 -1029
  75. package/src/inspect.ts +662 -0
  76. package/src/intl-polyfill.d.ts +139 -0
  77. package/src/kv.ts +408 -0
  78. package/src/logger.ts +73 -0
  79. package/src/miniflare-cli/README.md +30 -0
  80. package/src/miniflare-cli/enum-keys.ts +17 -0
  81. package/src/miniflare-cli/index.ts +41 -0
  82. package/src/miniflare-cli/request-context.ts +40 -0
  83. package/src/module-collection.ts +258 -0
  84. package/src/open-in-browser.ts +17 -0
  85. package/src/package-manager.ts +174 -0
  86. package/src/pages/build.tsx +202 -0
  87. package/src/pages/constants.ts +7 -0
  88. package/src/pages/deployments.tsx +101 -0
  89. package/src/pages/dev.tsx +948 -0
  90. package/src/pages/functions/buildPlugin.ts +105 -0
  91. package/src/pages/functions/buildWorker.ts +151 -0
  92. package/src/pages/functions/filepath-routing.test.ts +234 -0
  93. package/src/pages/functions/filepath-routing.ts +189 -0
  94. package/src/pages/functions/identifiers.ts +78 -0
  95. package/src/pages/functions/routes.ts +151 -0
  96. package/src/pages/index.tsx +84 -0
  97. package/src/pages/projects.tsx +157 -0
  98. package/src/pages/publish.tsx +325 -0
  99. package/src/pages/types.ts +40 -0
  100. package/src/pages/upload.tsx +363 -0
  101. package/src/pages/utils.ts +12 -0
  102. package/src/parse.ts +222 -0
  103. package/src/paths.ts +26 -0
  104. package/src/proxy.ts +476 -0
  105. package/src/publish.ts +661 -272
  106. package/src/r2.ts +50 -0
  107. package/src/selfsigned.d.ts +29 -0
  108. package/src/sites.tsx +316 -59
  109. package/src/tail/filters.ts +279 -0
  110. package/src/tail/index.ts +299 -0
  111. package/src/tail/printing.ts +67 -0
  112. package/src/update-check.ts +19 -0
  113. package/src/user/choose-account.tsx +60 -0
  114. package/src/user/env-vars.ts +17 -0
  115. package/src/user/generate-auth-url.ts +33 -0
  116. package/src/user/generate-random-state.ts +16 -0
  117. package/src/user/index.ts +3 -0
  118. package/src/{user.tsx → user/user.tsx} +380 -276
  119. package/src/whoami.tsx +71 -0
  120. package/src/worker.ts +181 -0
  121. package/src/zones.ts +73 -0
  122. package/templates/gitignore +171 -0
  123. package/templates/new-worker-scheduled.js +17 -0
  124. package/templates/new-worker-scheduled.ts +32 -0
  125. package/templates/new-worker.js +15 -0
  126. package/templates/new-worker.ts +30 -0
  127. package/templates/no-op-worker.js +10 -0
  128. package/templates/pages-template-plugin.ts +155 -0
  129. package/templates/pages-template-worker.ts +161 -0
  130. package/{static-asset-facade.js → templates/static-asset-facade.js} +3 -7
  131. package/templates/tsconfig.json +105 -0
  132. package/wrangler-dist/cli.js +100313 -110298
  133. package/src/__tests__/fixtures/init/.gitkeep +0 -0
  134. package/src/__tests__/mock-cfetch.js +0 -46
  135. package/src/api/form_data.ts +0 -158
  136. package/src/api/inspect.ts +0 -441
  137. package/src/api/preview.ts +0 -123
  138. package/src/api/worker.ts +0 -157
  139. package/src/cfetch.ts +0 -72
  140. package/src/config.ts +0 -124
  141. package/src/dev.tsx +0 -736
  142. package/src/kv.tsx +0 -211
  143. package/src/pages.tsx +0 -340
  144. package/src/tail.tsx +0 -71
  145. package/src/util/fetch.ts +0 -74
  146. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  147. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  148. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  149. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  150. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  151. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  152. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  153. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  154. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  155. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  156. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  157. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  158. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  159. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  160. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  161. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  162. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  163. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  164. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  165. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  166. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  167. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  168. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  169. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  170. package/vendor/wrangler-mime/LICENSE +0 -21
  171. package/vendor/wrangler-mime/Mime.js +0 -97
  172. package/vendor/wrangler-mime/README.md +0 -187
  173. package/vendor/wrangler-mime/cli.js +0 -46
  174. package/vendor/wrangler-mime/index.js +0 -4
  175. package/vendor/wrangler-mime/lite.js +0 -4
  176. package/vendor/wrangler-mime/package.json +0 -52
  177. package/vendor/wrangler-mime/types/other.js +0 -1
  178. package/vendor/wrangler-mime/types/standard.js +0 -1
  179. package/wrangler-dist/cli.js.map +0 -7
@@ -0,0 +1,399 @@
1
+ import { spawn } from "node:child_process";
2
+ import * as path from "node:path";
3
+ import { watch } from "chokidar";
4
+ import clipboardy from "clipboardy";
5
+ import commandExists from "command-exists";
6
+ import { Box, Text, useApp, useInput, useStdin } from "ink";
7
+ import React, { useState, useEffect, useRef } from "react";
8
+ import { withErrorBoundary, useErrorHandler } from "react-error-boundary";
9
+ import onExit from "signal-exit";
10
+ import tmp from "tmp-promise";
11
+ import { fetch } from "undici";
12
+ import { runCustomBuild } from "../entry";
13
+ import { openInspector } from "../inspect";
14
+ import { logger } from "../logger";
15
+ import openInBrowser from "../open-in-browser";
16
+ import { Local } from "./local";
17
+ import { Remote } from "./remote";
18
+ import { useEsbuild } from "./use-esbuild";
19
+ import type { Config } from "../config";
20
+ import type { Entry } from "../entry";
21
+ import type { AssetPaths } from "../sites";
22
+ import type { CfWorkerInit } from "../worker";
23
+
24
+ export type DevProps = {
25
+ name?: string;
26
+ entry: Entry;
27
+ port: number;
28
+ ip: string;
29
+ inspectorPort: number;
30
+ rules: Config["rules"];
31
+ accountId: string | undefined;
32
+ initialMode: "local" | "remote";
33
+ jsxFactory: string | undefined;
34
+ jsxFragment: string | undefined;
35
+ tsconfig: string | undefined;
36
+ upstreamProtocol: "https" | "http";
37
+ localProtocol: "https" | "http";
38
+ enableLocalPersistence: boolean;
39
+ bindings: CfWorkerInit["bindings"];
40
+ crons: Config["triggers"]["crons"];
41
+ isWorkersSite: boolean;
42
+ assetPaths: AssetPaths | undefined;
43
+ compatibilityDate: string;
44
+ compatibilityFlags: string[] | undefined;
45
+ usageModel: "bundled" | "unbound" | undefined;
46
+ minify: boolean | undefined;
47
+ nodeCompat: boolean | undefined;
48
+ build: Config["build"];
49
+ env: string | undefined;
50
+ legacyEnv: boolean;
51
+ zone: string | undefined;
52
+ host: string | undefined;
53
+ };
54
+
55
+ export function DevImplementation(props: DevProps): JSX.Element {
56
+ if (
57
+ !props.isWorkersSite &&
58
+ props.assetPaths &&
59
+ props.entry.format === "service-worker"
60
+ ) {
61
+ throw new Error(
62
+ "You cannot use the service-worker format with an `assets` directory yet. For information on how to migrate to the module-worker format, see: https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/"
63
+ );
64
+ }
65
+
66
+ if (props.bindings.wasm_modules && props.entry.format === "modules") {
67
+ throw new Error(
68
+ "You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code"
69
+ );
70
+ }
71
+
72
+ if (props.bindings.text_blobs && props.entry.format === "modules") {
73
+ throw new Error(
74
+ "You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure `[rules]` in your wrangler.toml"
75
+ );
76
+ }
77
+
78
+ if (props.bindings.data_blobs && props.entry.format === "modules") {
79
+ throw new Error(
80
+ "You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure `[rules]` in your wrangler.toml"
81
+ );
82
+ }
83
+
84
+ // only load the UI if we're running in a supported environment
85
+ const { isRawModeSupported } = useStdin();
86
+ return isRawModeSupported ? (
87
+ <InteractiveDevSession {...props} />
88
+ ) : (
89
+ <DevSession {...props} local={props.initialMode === "local"} />
90
+ );
91
+ }
92
+
93
+ function InteractiveDevSession(props: DevProps) {
94
+ const toggles = useHotkeys(
95
+ {
96
+ local: props.initialMode === "local",
97
+ tunnel: false,
98
+ },
99
+ props.port,
100
+ props.ip,
101
+ props.inspectorPort,
102
+ props.localProtocol
103
+ );
104
+
105
+ useTunnel(toggles.tunnel);
106
+
107
+ return (
108
+ <>
109
+ <DevSession {...props} local={toggles.local} />
110
+ <Box borderStyle="round" paddingLeft={1} paddingRight={1}>
111
+ <Text bold={true}>[b]</Text>
112
+ <Text> open a browser, </Text>
113
+ <Text bold={true}>[d]</Text>
114
+ <Text> open Devtools, </Text>
115
+ <Text bold={true}>[l]</Text>
116
+ <Text> {toggles.local ? "turn off" : "turn on"} local mode, </Text>
117
+ <Text bold={true}>[c]</Text>
118
+ <Text> clear console, </Text>
119
+ <Text bold={true}>[x]</Text>
120
+ <Text> to exit</Text>
121
+ </Box>
122
+ </>
123
+ );
124
+ }
125
+
126
+ type DevSessionProps = DevProps & {
127
+ local: boolean;
128
+ };
129
+
130
+ function DevSession(props: DevSessionProps) {
131
+ useCustomBuild(props.entry, props.build);
132
+
133
+ const directory = useTmpDir();
134
+
135
+ const bundle = useEsbuild({
136
+ entry: props.entry,
137
+ destination: directory,
138
+ jsxFactory: props.jsxFactory,
139
+ rules: props.rules,
140
+ jsxFragment: props.jsxFragment,
141
+ serveAssetsFromWorker: Boolean(
142
+ props.assetPaths && !props.isWorkersSite && props.local
143
+ ),
144
+ tsconfig: props.tsconfig,
145
+ minify: props.minify,
146
+ nodeCompat: props.nodeCompat,
147
+ });
148
+
149
+ return props.local ? (
150
+ <Local
151
+ name={props.name}
152
+ bundle={bundle}
153
+ format={props.entry.format}
154
+ compatibilityDate={props.compatibilityDate}
155
+ localProtocol={props.localProtocol}
156
+ compatibilityFlags={props.compatibilityFlags}
157
+ bindings={props.bindings}
158
+ assetPaths={props.assetPaths}
159
+ isWorkersSite={props.isWorkersSite}
160
+ port={props.port}
161
+ ip={props.ip}
162
+ rules={props.rules}
163
+ inspectorPort={props.inspectorPort}
164
+ enableLocalPersistence={props.enableLocalPersistence}
165
+ crons={props.crons}
166
+ />
167
+ ) : (
168
+ <Remote
169
+ name={props.name}
170
+ bundle={bundle}
171
+ format={props.entry.format}
172
+ accountId={props.accountId}
173
+ bindings={props.bindings}
174
+ assetPaths={props.assetPaths}
175
+ isWorkersSite={props.isWorkersSite}
176
+ port={props.port}
177
+ ip={props.ip}
178
+ localProtocol={props.localProtocol}
179
+ inspectorPort={props.inspectorPort}
180
+ compatibilityDate={props.compatibilityDate}
181
+ compatibilityFlags={props.compatibilityFlags}
182
+ usageModel={props.usageModel}
183
+ env={props.env}
184
+ legacyEnv={props.legacyEnv}
185
+ zone={props.zone}
186
+ host={props.host}
187
+ />
188
+ );
189
+ }
190
+
191
+ export interface DirectorySyncResult {
192
+ name: string;
193
+ removeCallback: () => void;
194
+ }
195
+
196
+ function useTmpDir(): string | undefined {
197
+ const [directory, setDirectory] = useState<DirectorySyncResult>();
198
+ const handleError = useErrorHandler();
199
+ useEffect(() => {
200
+ let dir: DirectorySyncResult | undefined;
201
+ try {
202
+ dir = tmp.dirSync({ unsafeCleanup: true });
203
+ setDirectory(dir);
204
+ return;
205
+ } catch (err) {
206
+ logger.error(
207
+ "Failed to create temporary directory to store built files."
208
+ );
209
+ handleError(err);
210
+ }
211
+ return () => {
212
+ dir?.removeCallback();
213
+ };
214
+ }, [handleError]);
215
+ return directory?.name;
216
+ }
217
+
218
+ function useCustomBuild(expectedEntry: Entry, build: Config["build"]): void {
219
+ useEffect(() => {
220
+ if (!build.command) return;
221
+ let watcher: ReturnType<typeof watch> | undefined;
222
+ if (build.watch_dir) {
223
+ watcher = watch(build.watch_dir, {
224
+ persistent: true,
225
+ ignoreInitial: true,
226
+ }).on("all", (_event, filePath) => {
227
+ const relativeFile =
228
+ path.relative(expectedEntry.directory, expectedEntry.file) || ".";
229
+ //TODO: we should buffer requests to the proxy until this completes
230
+ logger.log(`The file ${filePath} changed, restarting build...`);
231
+ runCustomBuild(expectedEntry.file, relativeFile, build).catch((err) => {
232
+ logger.error("Custom build failed:", err);
233
+ });
234
+ });
235
+ }
236
+
237
+ return () => {
238
+ watcher?.close();
239
+ };
240
+ }, [build, expectedEntry]);
241
+ }
242
+
243
+ function sleep(period: number) {
244
+ return new Promise((resolve) => setTimeout(resolve, period));
245
+ }
246
+ const SLEEP_DURATION = 2000;
247
+ // really need a first class api for this
248
+ const hostNameRegex = /userHostname="(.*)"/g;
249
+ async function findTunnelHostname() {
250
+ let hostName: string | undefined;
251
+ while (!hostName) {
252
+ try {
253
+ const resp = await fetch("http://localhost:8789/metrics");
254
+ const data = await resp.text();
255
+ const matches = Array.from(data.matchAll(hostNameRegex));
256
+ hostName = matches[0][1];
257
+ } catch (err) {
258
+ await sleep(SLEEP_DURATION);
259
+ }
260
+ }
261
+ return hostName;
262
+ }
263
+
264
+ /**
265
+ * Create a tunnel to the remote worker.
266
+ * We've disabled this for now until we figure out a better user experience.
267
+ */
268
+ function useTunnel(toggle: boolean) {
269
+ const tunnel = useRef<ReturnType<typeof spawn>>();
270
+ const removeSignalExitListener = useRef<() => void>();
271
+ // TODO: test if cloudflared is available, if not
272
+ // point them to a url where they can get docs to install it
273
+ useEffect(() => {
274
+ async function startTunnel() {
275
+ if (toggle) {
276
+ try {
277
+ await commandExists("cloudflared");
278
+ } catch (e) {
279
+ logger.warn(
280
+ "To share your worker on the Internet, please install `cloudflared` from https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation"
281
+ );
282
+ return;
283
+ }
284
+ logger.log("⎔ Starting a tunnel...");
285
+ tunnel.current = spawn("cloudflared", [
286
+ "tunnel",
287
+ "--url",
288
+ "http://localhost:8787",
289
+ "--metrics",
290
+ "localhost:8789",
291
+ ]);
292
+
293
+ tunnel.current.on("close", (code) => {
294
+ if (code) {
295
+ logger.log(`Tunnel process exited with code ${code}`);
296
+ }
297
+ });
298
+
299
+ removeSignalExitListener.current = onExit((_code, _signal) => {
300
+ logger.log("⎔ Shutting down local tunnel.");
301
+ tunnel.current?.kill();
302
+ tunnel.current = undefined;
303
+ });
304
+
305
+ const hostName = await findTunnelHostname();
306
+ await clipboardy.write(hostName);
307
+ logger.log(`⬣ Sharing at ${hostName}, copied to clipboard.`);
308
+ }
309
+ }
310
+
311
+ startTunnel().catch(async (err) => {
312
+ logger.error("tunnel:", err);
313
+ });
314
+
315
+ return () => {
316
+ if (tunnel.current) {
317
+ logger.log("⎔ Shutting down tunnel.");
318
+ tunnel.current?.kill();
319
+ tunnel.current = undefined;
320
+ removeSignalExitListener.current && removeSignalExitListener.current();
321
+ removeSignalExitListener.current = undefined;
322
+ }
323
+ };
324
+ }, [toggle]);
325
+ }
326
+
327
+ type useHotkeysInitialState = {
328
+ local: boolean;
329
+ tunnel: boolean;
330
+ };
331
+ function useHotkeys(
332
+ initial: useHotkeysInitialState,
333
+ port: number,
334
+ ip: string,
335
+ inspectorPort: number,
336
+ localProtocol: "http" | "https"
337
+ ) {
338
+ // UGH, we should put port in context instead
339
+ const [toggles, setToggles] = useState(initial);
340
+ const { exit } = useApp();
341
+ useInput(
342
+ async (
343
+ input,
344
+ // eslint-disable-next-line unused-imports/no-unused-vars
345
+ key
346
+ ) => {
347
+ switch (input.toLowerCase()) {
348
+ // clear console
349
+ case "c":
350
+ console.clear();
351
+ // This console.log causes Ink to re-render the `DevSession` component.
352
+ // Couldn't find a better way to tell it to do so...
353
+ console.log();
354
+ break;
355
+ // open browser
356
+ case "b": {
357
+ await openInBrowser(`${localProtocol}://${ip}:${port}`);
358
+ break;
359
+ }
360
+ // toggle inspector
361
+ case "d": {
362
+ await openInspector(inspectorPort);
363
+ break;
364
+ }
365
+ // toggle local
366
+ case "l":
367
+ setToggles((previousToggles) => ({
368
+ ...previousToggles,
369
+ local: !previousToggles.local,
370
+ }));
371
+ break;
372
+ // shut down
373
+ case "q":
374
+ case "x":
375
+ exit();
376
+ break;
377
+ default:
378
+ // nothing?
379
+ break;
380
+ }
381
+ }
382
+ );
383
+ return toggles;
384
+ }
385
+
386
+ function ErrorFallback(props: { error: Error }) {
387
+ const { exit } = useApp();
388
+ useEffect(() => exit(props.error));
389
+ return (
390
+ <>
391
+ <Text>Something went wrong:</Text>
392
+ <Text>{props.error.stack}</Text>
393
+ </>
394
+ );
395
+ }
396
+
397
+ export default withErrorBoundary(DevImplementation, {
398
+ FallbackComponent: ErrorFallback,
399
+ });