wrangler 0.0.0-e452a35 → 0.0.0-e4716cc87

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