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