wrangler 0.0.0-e95e5a0 → 0.0.0-e981d0be5

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