wrangler 0.0.0-e6733a3 → 0.0.0-e9307365
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.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +51 -14
- package/bin/wrangler.js +159 -27
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +5416 -0
- package/package.json +171 -124
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +42 -0
- package/src/__tests__/configuration.test.ts +4022 -0
- package/src/__tests__/dev.test.tsx +1290 -62
- package/src/__tests__/generate.test.ts +93 -0
- package/src/__tests__/guess-worker-format.test.ts +85 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/mock-account-id.ts +48 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/helpers/mock-cfetch.ts +263 -0
- package/src/__tests__/helpers/mock-console.ts +97 -0
- package/src/__tests__/helpers/mock-dialogs.ts +153 -0
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +74 -0
- package/src/__tests__/helpers/mock-kv.ts +33 -0
- package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +108 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +38 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +163 -0
- package/src/__tests__/index.test.ts +242 -284
- package/src/__tests__/init.test.ts +1992 -0
- package/src/__tests__/jest.setup.ts +138 -10
- package/src/__tests__/kv.test.ts +1459 -886
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/metrics.test.ts +450 -0
- package/src/__tests__/package-manager.test.ts +353 -0
- package/src/__tests__/pages.test.ts +1261 -0
- package/src/__tests__/parse.test.ts +330 -0
- package/src/__tests__/publish.test.ts +6914 -0
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +317 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +492 -0
- package/src/__tests__/tail.test.ts +698 -0
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/user.test.ts +144 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/version.test.ts +35 -0
- package/src/__tests__/whoami.test.tsx +289 -0
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +3 -0
- package/src/api/dev.ts +86 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +472 -0
- package/src/cfetch/index.ts +88 -69
- package/src/cfetch/internal.ts +156 -44
- package/src/cli.ts +24 -6
- package/src/config/README.md +107 -0
- package/src/config/config.ts +263 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +485 -0
- package/src/config/index.ts +251 -0
- package/src/config/validation-helpers.ts +584 -0
- package/src/config/validation.ts +1856 -0
- package/src/config-cache.ts +84 -0
- package/src/create-worker-preview.ts +257 -0
- package/src/create-worker-upload-form.ts +288 -0
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +531 -0
- package/src/dev/local.tsx +385 -0
- package/src/dev/remote.tsx +413 -0
- package/src/dev/use-esbuild.ts +175 -0
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +157 -0
- package/src/dev.tsx +603 -758
- package/src/dialogs.tsx +117 -59
- package/src/durable.ts +102 -0
- package/src/entry.ts +328 -0
- package/src/environment-variables.ts +35 -0
- package/src/errors.ts +11 -0
- package/src/faye-websocket.d.ts +6 -0
- package/src/generate.ts +131 -0
- package/src/git-client.ts +42 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +127 -0
- package/src/index.tsx +2166 -1956
- package/src/init.ts +549 -0
- package/src/inspect.ts +703 -477
- package/src/intl-polyfill.d.ts +139 -0
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +430 -0
- package/src/logger.ts +73 -0
- package/src/metrics/index.ts +5 -0
- package/src/metrics/is-ci.ts +14 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +96 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +92 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/assets.ts +543 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +85 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +247 -53
- package/src/open-in-browser.ts +17 -0
- package/src/package-manager.ts +219 -0
- package/src/pages/build.tsx +204 -0
- package/src/pages/constants.ts +8 -0
- package/src/pages/deployments.tsx +106 -0
- package/src/pages/dev.tsx +414 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/src/pages/functions/filepath-routing.test.ts +234 -0
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +163 -0
- package/src/pages/publish.tsx +338 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +415 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +286 -0
- package/src/paths.ts +26 -0
- package/src/preview.ts +31 -0
- package/src/proxy.ts +434 -252
- package/src/publish.ts +794 -345
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +623 -0
- package/src/r2.ts +118 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +357 -99
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +67 -0
- package/src/update-check.ts +19 -0
- package/src/user/choose-account.tsx +69 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1189 -0
- package/src/whoami.tsx +169 -0
- package/src/worker-namespace.ts +206 -0
- package/src/worker.ts +203 -0
- package/src/zones.ts +76 -0
- package/templates/checked-fetch.js +17 -0
- package/templates/first-party-worker-module-facade.ts +18 -0
- package/templates/format-dev-errors.ts +32 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +30 -0
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/serve-static-assets.ts +63 -0
- package/templates/service-bindings-module-facade.js +51 -0
- package/templates/service-bindings-sw-facade.js +39 -0
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.d.ts +327 -0
- package/wrangler-dist/cli.js +134880 -109997
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -39
- package/pages/functions/filepath-routing.ts +0 -221
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -158
- package/pages/functions/template-worker.ts +0 -144
- package/src/__tests__/mock-cfetch.ts +0 -171
- package/src/__tests__/mock-dialogs.ts +0 -65
- package/src/__tests__/run-in-tmp.ts +0 -19
- package/src/__tests__/run-wrangler.ts +0 -32
- package/src/api/form_data.ts +0 -131
- package/src/api/preview.ts +0 -128
- package/src/api/worker.ts +0 -155
- package/src/config.ts +0 -487
- package/src/kv.tsx +0 -267
- package/src/pages.tsx +0 -1031
- package/src/tail.tsx +0 -73
- package/src/user.tsx +0 -1025
- package/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
package/src/dev.tsx
CHANGED
|
@@ -1,771 +1,616 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { readFile } from "fs/promises";
|
|
3
|
-
import { existsSync } from "fs";
|
|
4
|
-
import type { DirectoryResult } from "tmp-promise";
|
|
5
|
-
import tmp from "tmp-promise";
|
|
6
|
-
import type { CfPreviewToken } from "./api/preview";
|
|
7
|
-
import { Box, Text, useApp, useInput } from "ink";
|
|
8
|
-
import React, { useState, useEffect, useRef } from "react";
|
|
9
|
-
import path from "path";
|
|
10
|
-
import open from "open";
|
|
11
|
-
import useInspector from "./inspect";
|
|
12
|
-
import type { CfModule } from "./api/worker";
|
|
13
|
-
import { createWorker } from "./api/worker";
|
|
14
|
-
import type { CfWorkerInit } from "./api/worker";
|
|
15
|
-
import { spawn } from "child_process";
|
|
16
|
-
import onExit from "signal-exit";
|
|
17
|
-
import { syncAssets } from "./sites";
|
|
18
|
-
import clipboardy from "clipboardy";
|
|
19
|
-
import commandExists from "command-exists";
|
|
20
|
-
import assert from "assert";
|
|
21
|
-
import { getAPIToken } from "./user";
|
|
22
|
-
import fetch from "node-fetch";
|
|
23
|
-
import makeModuleCollector from "./module-collection";
|
|
24
|
-
import { withErrorBoundary, useErrorHandler } from "react-error-boundary";
|
|
25
|
-
import { usePreviewServer } from "./proxy";
|
|
26
|
-
import { execa } from "execa";
|
|
1
|
+
import path from "node:path";
|
|
27
2
|
import { watch } from "chokidar";
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
bindings={props.bindings}
|
|
99
|
-
site={props.site}
|
|
100
|
-
public={props.public}
|
|
101
|
-
port={props.port}
|
|
102
|
-
/>
|
|
103
|
-
) : (
|
|
104
|
-
<Remote
|
|
105
|
-
name={props.name}
|
|
106
|
-
bundle={bundle}
|
|
107
|
-
format={props.format}
|
|
108
|
-
accountId={props.accountId}
|
|
109
|
-
apiToken={apiToken}
|
|
110
|
-
bindings={props.bindings}
|
|
111
|
-
site={props.site}
|
|
112
|
-
public={props.public}
|
|
113
|
-
port={props.port}
|
|
114
|
-
compatibilityDate={props.compatibilityDate}
|
|
115
|
-
compatibilityFlags={props.compatibilityFlags}
|
|
116
|
-
usageModel={props.usageModel}
|
|
117
|
-
/>
|
|
118
|
-
)}
|
|
119
|
-
<Box borderStyle="round" paddingLeft={1} paddingRight={1}>
|
|
120
|
-
<Text>
|
|
121
|
-
{`B to open a browser, D to open Devtools, S to ${
|
|
122
|
-
toggles.tunnel ? "turn off" : "turn on"
|
|
123
|
-
} (experimental) sharing, L to ${
|
|
124
|
-
toggles.local ? "turn off" : "turn on"
|
|
125
|
-
} local mode, X to exit`}
|
|
126
|
-
</Text>
|
|
127
|
-
</Box>
|
|
128
|
-
</>
|
|
129
|
-
);
|
|
3
|
+
import getPort from "get-port";
|
|
4
|
+
import { render } from "ink";
|
|
5
|
+
import React from "react";
|
|
6
|
+
import { fetch } from "undici";
|
|
7
|
+
import { findWranglerToml, printBindings, readConfig } from "./config";
|
|
8
|
+
import Dev from "./dev/dev";
|
|
9
|
+
import { getVarsForDev } from "./dev/dev-vars";
|
|
10
|
+
|
|
11
|
+
import { getEntry } from "./entry";
|
|
12
|
+
import { logger } from "./logger";
|
|
13
|
+
import * as metrics from "./metrics";
|
|
14
|
+
import { getAssetPaths, getSiteAssetPaths } from "./sites";
|
|
15
|
+
import { getAccountFromCache } from "./user";
|
|
16
|
+
import { getZoneIdFromHost, getZoneForRoute, getHostFromRoute } from "./zones";
|
|
17
|
+
import {
|
|
18
|
+
printWranglerBanner,
|
|
19
|
+
DEFAULT_LOCAL_PORT,
|
|
20
|
+
type ConfigPath,
|
|
21
|
+
getScriptName,
|
|
22
|
+
getDevCompatibilityDate,
|
|
23
|
+
getRules,
|
|
24
|
+
isLegacyEnv,
|
|
25
|
+
DEFAULT_INSPECTOR_PORT,
|
|
26
|
+
} from "./index";
|
|
27
|
+
|
|
28
|
+
import type { Config } from "./config";
|
|
29
|
+
import type { Route } from "./config/environment";
|
|
30
|
+
import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli";
|
|
31
|
+
import type { CfWorkerInit } from "./worker";
|
|
32
|
+
import type { RequestInit } from "undici";
|
|
33
|
+
import type { Argv, ArgumentsCamelCase } from "yargs";
|
|
34
|
+
|
|
35
|
+
interface DevArgs {
|
|
36
|
+
config?: string;
|
|
37
|
+
script?: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
bundle?: boolean;
|
|
40
|
+
build?: boolean;
|
|
41
|
+
format?: string;
|
|
42
|
+
env?: string;
|
|
43
|
+
"compatibility-date"?: string;
|
|
44
|
+
"compatibility-flags"?: string[];
|
|
45
|
+
latest?: boolean;
|
|
46
|
+
ip?: string;
|
|
47
|
+
inspect?: boolean;
|
|
48
|
+
port?: number;
|
|
49
|
+
"inspector-port"?: number;
|
|
50
|
+
routes?: string[];
|
|
51
|
+
host?: string;
|
|
52
|
+
"local-protocol"?: "http" | "https";
|
|
53
|
+
"local-upstream"?: string | undefined;
|
|
54
|
+
"experimental-public"?: string;
|
|
55
|
+
public?: string;
|
|
56
|
+
assets?: string;
|
|
57
|
+
site?: string;
|
|
58
|
+
"site-include"?: string[];
|
|
59
|
+
"site-exclude"?: string[];
|
|
60
|
+
"upstream-protocol"?: "http" | "https";
|
|
61
|
+
"jsx-factory"?: string;
|
|
62
|
+
"jsx-fragment"?: string;
|
|
63
|
+
tsconfig?: string;
|
|
64
|
+
local?: boolean;
|
|
65
|
+
minify?: boolean;
|
|
66
|
+
"node-compat"?: boolean;
|
|
67
|
+
"experimental-enable-local-persistence"?: boolean;
|
|
68
|
+
"live-reload"?: boolean;
|
|
69
|
+
onReady?: () => void;
|
|
70
|
+
logLevel?: "none" | "error" | "log" | "warn" | "debug";
|
|
71
|
+
logPrefix?: string;
|
|
72
|
+
showInteractiveDevSession?: boolean;
|
|
130
73
|
}
|
|
131
74
|
|
|
132
|
-
function
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
75
|
+
export function devOptions(yargs: Argv): Argv<DevArgs> {
|
|
76
|
+
return (
|
|
77
|
+
yargs
|
|
78
|
+
.positional("script", {
|
|
79
|
+
describe: "The path to an entry point for your worker",
|
|
80
|
+
type: "string",
|
|
81
|
+
})
|
|
82
|
+
.option("name", {
|
|
83
|
+
describe: "Name of the worker",
|
|
84
|
+
type: "string",
|
|
85
|
+
requiresArg: true,
|
|
86
|
+
})
|
|
87
|
+
// We want to have a --no-bundle flag, but yargs requires that
|
|
88
|
+
// we also have a --bundle flag (that it adds the --no to by itself)
|
|
89
|
+
// So we make a --bundle flag, but hide it, and then add a --no-bundle flag
|
|
90
|
+
// that's visible to the user but doesn't "do" anything.
|
|
91
|
+
.option("bundle", {
|
|
92
|
+
describe: "Run wrangler's compilation step before publishing",
|
|
93
|
+
type: "boolean",
|
|
94
|
+
hidden: true,
|
|
95
|
+
})
|
|
96
|
+
.option("no-bundle", {
|
|
97
|
+
describe: "Skip internal build steps and directly publish script",
|
|
98
|
+
type: "boolean",
|
|
99
|
+
default: false,
|
|
100
|
+
})
|
|
101
|
+
.option("format", {
|
|
102
|
+
choices: ["modules", "service-worker"] as const,
|
|
103
|
+
describe: "Choose an entry type",
|
|
104
|
+
deprecated: true,
|
|
105
|
+
})
|
|
106
|
+
.option("env", {
|
|
107
|
+
describe: "Perform on a specific environment",
|
|
108
|
+
type: "string",
|
|
109
|
+
requiresArg: true,
|
|
110
|
+
alias: "e",
|
|
111
|
+
})
|
|
112
|
+
.option("compatibility-date", {
|
|
113
|
+
describe: "Date to use for compatibility checks",
|
|
114
|
+
type: "string",
|
|
115
|
+
requiresArg: true,
|
|
116
|
+
})
|
|
117
|
+
.option("compatibility-flags", {
|
|
118
|
+
describe: "Flags to use for compatibility checks",
|
|
119
|
+
alias: "compatibility-flag",
|
|
120
|
+
type: "string",
|
|
121
|
+
requiresArg: true,
|
|
122
|
+
array: true,
|
|
123
|
+
})
|
|
124
|
+
.option("latest", {
|
|
125
|
+
describe: "Use the latest version of the worker runtime",
|
|
126
|
+
type: "boolean",
|
|
127
|
+
default: true,
|
|
128
|
+
})
|
|
129
|
+
.option("ip", {
|
|
130
|
+
describe: "IP address to listen on, defaults to `localhost`",
|
|
131
|
+
type: "string",
|
|
132
|
+
requiresArg: true,
|
|
133
|
+
})
|
|
134
|
+
.option("port", {
|
|
135
|
+
describe: "Port to listen on",
|
|
136
|
+
type: "number",
|
|
137
|
+
})
|
|
138
|
+
.option("inspector-port", {
|
|
139
|
+
describe: "Port for devtools to connect to",
|
|
140
|
+
type: "number",
|
|
141
|
+
})
|
|
142
|
+
.option("routes", {
|
|
143
|
+
describe: "Routes to upload",
|
|
144
|
+
alias: "route",
|
|
145
|
+
type: "string",
|
|
146
|
+
requiresArg: true,
|
|
147
|
+
array: true,
|
|
148
|
+
})
|
|
149
|
+
.option("host", {
|
|
150
|
+
type: "string",
|
|
151
|
+
requiresArg: true,
|
|
152
|
+
describe:
|
|
153
|
+
"Host to forward requests to, defaults to the zone of project",
|
|
154
|
+
})
|
|
155
|
+
.option("local-protocol", {
|
|
156
|
+
describe: "Protocol to listen to requests on, defaults to http.",
|
|
157
|
+
choices: ["http", "https"] as const,
|
|
158
|
+
})
|
|
159
|
+
.options("local-upstream", {
|
|
160
|
+
type: "string",
|
|
161
|
+
describe:
|
|
162
|
+
"Host to act as origin in local mode, defaults to dev.host or route",
|
|
163
|
+
})
|
|
164
|
+
.option("experimental-public", {
|
|
165
|
+
describe: "Static assets to be served",
|
|
166
|
+
type: "string",
|
|
167
|
+
requiresArg: true,
|
|
168
|
+
deprecated: true,
|
|
169
|
+
hidden: true,
|
|
170
|
+
})
|
|
171
|
+
.option("assets", {
|
|
172
|
+
describe: "Static assets to be served",
|
|
173
|
+
type: "string",
|
|
174
|
+
requiresArg: true,
|
|
175
|
+
})
|
|
176
|
+
.option("site", {
|
|
177
|
+
describe: "Root folder of static assets for Workers Sites",
|
|
178
|
+
type: "string",
|
|
179
|
+
requiresArg: true,
|
|
180
|
+
})
|
|
181
|
+
.option("site-include", {
|
|
182
|
+
describe:
|
|
183
|
+
"Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded.",
|
|
184
|
+
type: "string",
|
|
185
|
+
requiresArg: true,
|
|
186
|
+
array: true,
|
|
187
|
+
})
|
|
188
|
+
.option("site-exclude", {
|
|
189
|
+
describe:
|
|
190
|
+
"Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded.",
|
|
191
|
+
type: "string",
|
|
192
|
+
requiresArg: true,
|
|
193
|
+
array: true,
|
|
194
|
+
})
|
|
195
|
+
.option("upstream-protocol", {
|
|
196
|
+
describe: "Protocol to forward requests to host on, defaults to https.",
|
|
197
|
+
choices: ["http", "https"] as const,
|
|
198
|
+
})
|
|
199
|
+
.option("jsx-factory", {
|
|
200
|
+
describe: "The function that is called for each JSX element",
|
|
201
|
+
type: "string",
|
|
202
|
+
requiresArg: true,
|
|
203
|
+
})
|
|
204
|
+
.option("jsx-fragment", {
|
|
205
|
+
describe: "The function that is called for each JSX fragment",
|
|
206
|
+
type: "string",
|
|
207
|
+
requiresArg: true,
|
|
208
|
+
})
|
|
209
|
+
.option("tsconfig", {
|
|
210
|
+
describe: "Path to a custom tsconfig.json file",
|
|
211
|
+
type: "string",
|
|
212
|
+
requiresArg: true,
|
|
213
|
+
})
|
|
214
|
+
.option("local", {
|
|
215
|
+
alias: "l",
|
|
216
|
+
describe: "Run on my machine",
|
|
217
|
+
type: "boolean",
|
|
218
|
+
default: false, // I bet this will a point of contention. We'll revisit it.
|
|
219
|
+
})
|
|
220
|
+
.option("minify", {
|
|
221
|
+
describe: "Minify the script",
|
|
222
|
+
type: "boolean",
|
|
223
|
+
})
|
|
224
|
+
.option("node-compat", {
|
|
225
|
+
describe: "Enable node.js compatibility",
|
|
226
|
+
type: "boolean",
|
|
227
|
+
})
|
|
228
|
+
.option("experimental-enable-local-persistence", {
|
|
229
|
+
describe: "Enable persistence for this session (only for local mode)",
|
|
230
|
+
type: "boolean",
|
|
231
|
+
})
|
|
232
|
+
.option("live-reload", {
|
|
233
|
+
// TODO: Add back in once we have remote `--live-reload`
|
|
234
|
+
hidden: true,
|
|
235
|
+
// describe: "Auto reload HTML pages when change is detected",
|
|
236
|
+
type: "boolean",
|
|
237
|
+
})
|
|
238
|
+
.option("inspect", {
|
|
239
|
+
describe: "Enable dev tools",
|
|
240
|
+
type: "boolean",
|
|
241
|
+
deprecated: true,
|
|
242
|
+
})
|
|
243
|
+
.option("legacy-env", {
|
|
244
|
+
type: "boolean",
|
|
245
|
+
describe: "Use legacy environments",
|
|
246
|
+
hidden: true,
|
|
247
|
+
})
|
|
248
|
+
);
|
|
194
249
|
}
|
|
195
250
|
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const removeSignalExitListener = useRef<() => void>();
|
|
207
|
-
const [inspectorUrl, setInspectorUrl] = useState<string | undefined>();
|
|
208
|
-
useEffect(() => {
|
|
209
|
-
async function startLocalWorker() {
|
|
210
|
-
if (!bundle) return;
|
|
211
|
-
if (format === "modules" && bundle.type === "commonjs") {
|
|
212
|
-
console.error("⎔ Cannot use modules with a commonjs bundle.");
|
|
213
|
-
// TODO: a much better error message here, with what to do next
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (format === "service-worker" && bundle.type !== "esm") {
|
|
217
|
-
console.error("⎔ Cannot use service-worker with a esm bundle.");
|
|
218
|
-
// TODO: a much better error message here, with what to do next
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
console.log("⎔ Starting a local server...");
|
|
223
|
-
// TODO: just use execa for this
|
|
224
|
-
local.current = spawn("node", [
|
|
225
|
-
"--experimental-vm-modules",
|
|
226
|
-
"--inspect",
|
|
227
|
-
require.resolve("miniflare/cli"),
|
|
228
|
-
bundle.path,
|
|
229
|
-
"--watch",
|
|
230
|
-
"--wrangler-config",
|
|
231
|
-
path.join(__dirname, "../miniflare-config-stubs/wrangler.empty.toml"),
|
|
232
|
-
"--env",
|
|
233
|
-
path.join(__dirname, "../miniflare-config-stubs/.env.empty"),
|
|
234
|
-
"--package",
|
|
235
|
-
path.join(__dirname, "../miniflare-config-stubs/package.empty.json"),
|
|
236
|
-
"--port",
|
|
237
|
-
port.toString(),
|
|
238
|
-
"--kv-persist",
|
|
239
|
-
"--cache-persist",
|
|
240
|
-
"--do-persist",
|
|
241
|
-
...Object.entries(bindings.vars || {}).flatMap(([key, value]) => {
|
|
242
|
-
return ["--binding", `${key}=${value}`];
|
|
243
|
-
}),
|
|
244
|
-
...(bindings.kv_namespaces || []).flatMap(({ binding }) => {
|
|
245
|
-
return ["--kv", binding];
|
|
246
|
-
}),
|
|
247
|
-
...(bindings.durable_objects?.bindings || []).flatMap(
|
|
248
|
-
({ name, class_name }) => {
|
|
249
|
-
return ["--do", `${name}=${class_name}`];
|
|
250
|
-
}
|
|
251
|
-
),
|
|
252
|
-
"--modules",
|
|
253
|
-
format ||
|
|
254
|
-
(bundle.type === "esm" ? "modules" : "service-worker") === "modules"
|
|
255
|
-
? "true"
|
|
256
|
-
: "false",
|
|
257
|
-
]);
|
|
258
|
-
console.log(`⬣ Listening at http://localhost:${port}`);
|
|
259
|
-
|
|
260
|
-
local.current.on("close", (code) => {
|
|
261
|
-
if (code !== null) {
|
|
262
|
-
console.log(`miniflare process exited with code ${code}`);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
local.current.stdout.on("data", (data: Buffer) => {
|
|
267
|
-
console.log(`${data.toString()}`);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
local.current.stderr.on("data", (data: Buffer) => {
|
|
271
|
-
console.error(`${data.toString()}`);
|
|
272
|
-
const matches =
|
|
273
|
-
/Debugger listening on (ws:\/\/127\.0\.0\.1:9229\/[A-Za-z0-9-]+)/.exec(
|
|
274
|
-
data.toString()
|
|
275
|
-
);
|
|
276
|
-
if (matches) {
|
|
277
|
-
setInspectorUrl(matches[1]);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
local.current.on("exit", (code) => {
|
|
282
|
-
if (code !== 0) {
|
|
283
|
-
console.error(`miniflare process exited with code ${code}`);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
local.current.on("error", (error: Error) => {
|
|
288
|
-
console.error(`miniflare process failed to spawn`);
|
|
289
|
-
console.error(error);
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
removeSignalExitListener.current = onExit((_code, _signal) => {
|
|
293
|
-
console.log("⎔ Shutting down local server.");
|
|
294
|
-
local.current?.kill();
|
|
295
|
-
local.current = undefined;
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
startLocalWorker().catch((err) => {
|
|
300
|
-
console.error("local worker:", err);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
return () => {
|
|
304
|
-
if (local.current) {
|
|
305
|
-
console.log("⎔ Shutting down local server.");
|
|
306
|
-
local.current?.kill();
|
|
307
|
-
local.current = undefined;
|
|
308
|
-
removeSignalExitListener.current && removeSignalExitListener.current();
|
|
309
|
-
removeSignalExitListener.current = undefined;
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
}, [
|
|
313
|
-
bundle,
|
|
314
|
-
format,
|
|
315
|
-
port,
|
|
316
|
-
bindings.durable_objects?.bindings,
|
|
317
|
-
bindings.kv_namespaces,
|
|
318
|
-
bindings.vars,
|
|
319
|
-
]);
|
|
320
|
-
return { inspectorUrl };
|
|
251
|
+
export async function devHandler(args: ArgumentsCamelCase<DevArgs>) {
|
|
252
|
+
let watcher;
|
|
253
|
+
try {
|
|
254
|
+
const devInstance = await startDev(args);
|
|
255
|
+
watcher = devInstance.watcher;
|
|
256
|
+
const { waitUntilExit } = devInstance.devReactElement;
|
|
257
|
+
await waitUntilExit();
|
|
258
|
+
} finally {
|
|
259
|
+
await watcher?.close();
|
|
260
|
+
}
|
|
321
261
|
}
|
|
322
262
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
create().catch((err) => {
|
|
339
|
-
// we want to break here
|
|
340
|
-
// we can't do much without a temp dir anyway
|
|
341
|
-
handleError(err);
|
|
342
|
-
});
|
|
343
|
-
return () => {
|
|
344
|
-
dir.cleanup().catch(() => {
|
|
345
|
-
// extremely unlikely,
|
|
346
|
-
// but it's 2021 after all
|
|
347
|
-
console.error("failed to cleanup tmp dir");
|
|
348
|
-
});
|
|
349
|
-
};
|
|
350
|
-
}, [handleError]);
|
|
351
|
-
return directory?.path;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function useCustomBuild(
|
|
355
|
-
expectedEntry: string,
|
|
356
|
-
props: {
|
|
357
|
-
command?: undefined | string;
|
|
358
|
-
cwd?: undefined | string;
|
|
359
|
-
watch_dir?: undefined | string;
|
|
360
|
-
}
|
|
361
|
-
): undefined | string {
|
|
362
|
-
const [entry, setEntry] = useState<string | undefined>(
|
|
363
|
-
// if there's no build command, just return the expected entry
|
|
364
|
-
props.command ? null : expectedEntry
|
|
365
|
-
);
|
|
366
|
-
const { command, cwd, watch_dir } = props;
|
|
367
|
-
useEffect(() => {
|
|
368
|
-
if (!command) return;
|
|
369
|
-
let cmd, interval;
|
|
370
|
-
console.log("running:", command);
|
|
371
|
-
const commandPieces = command.split(" ");
|
|
372
|
-
cmd = execa(commandPieces[0], commandPieces.slice(1), {
|
|
373
|
-
...(cwd && { cwd }),
|
|
374
|
-
stderr: "inherit",
|
|
375
|
-
stdout: "inherit",
|
|
376
|
-
});
|
|
377
|
-
if (watch_dir) {
|
|
378
|
-
watch(watch_dir, { persistent: true, ignoreInitial: true }).on(
|
|
379
|
-
"all",
|
|
380
|
-
(_event, _path) => {
|
|
381
|
-
console.log(`The file ${path} changed, restarting build...`);
|
|
382
|
-
cmd.kill();
|
|
383
|
-
cmd = execa(commandPieces[0], commandPieces.slice(1), {
|
|
384
|
-
...(cwd && { cwd }),
|
|
385
|
-
stderr: "inherit",
|
|
386
|
-
stdout: "inherit",
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// check every so often whether `expectedEntry` exists
|
|
393
|
-
// if it does, we're done
|
|
394
|
-
const startedAt = Date.now();
|
|
395
|
-
interval = setInterval(() => {
|
|
396
|
-
if (existsSync(expectedEntry)) {
|
|
397
|
-
clearInterval(interval);
|
|
398
|
-
setEntry(expectedEntry);
|
|
399
|
-
} else {
|
|
400
|
-
const elapsed = Date.now() - startedAt;
|
|
401
|
-
// timeout after 30 seconds of waiting
|
|
402
|
-
if (elapsed > 1000 * 60 * 30) {
|
|
403
|
-
console.error("⎔ Build timed out.");
|
|
404
|
-
clearInterval(interval);
|
|
405
|
-
cmd.kill();
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}, 200);
|
|
409
|
-
// TODO: we could probably timeout here after a while
|
|
410
|
-
|
|
411
|
-
return () => {
|
|
412
|
-
if (cmd) {
|
|
413
|
-
cmd.kill();
|
|
414
|
-
cmd = undefined;
|
|
415
|
-
}
|
|
416
|
-
clearInterval(interval);
|
|
417
|
-
interval = undefined;
|
|
418
|
-
};
|
|
419
|
-
}, [command, cwd, expectedEntry, watch_dir]);
|
|
420
|
-
return entry;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
type EsbuildBundle = {
|
|
424
|
-
id: number;
|
|
425
|
-
path: string;
|
|
426
|
-
entry: string;
|
|
427
|
-
type: "esm" | "commonjs";
|
|
428
|
-
exports: string[];
|
|
429
|
-
modules: CfModule[];
|
|
263
|
+
export type AdditionalDevProps = {
|
|
264
|
+
vars?: {
|
|
265
|
+
[key: string]: unknown;
|
|
266
|
+
};
|
|
267
|
+
kv?: {
|
|
268
|
+
binding: string;
|
|
269
|
+
id: string;
|
|
270
|
+
preview_id?: string;
|
|
271
|
+
}[];
|
|
272
|
+
durableObjects?: {
|
|
273
|
+
name: string;
|
|
274
|
+
class_name: string;
|
|
275
|
+
script_name?: string | undefined;
|
|
276
|
+
environment?: string | undefined;
|
|
277
|
+
}[];
|
|
430
278
|
};
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
279
|
+
type StartDevOptions = ArgumentsCamelCase<DevArgs> &
|
|
280
|
+
// These options can be passed in directly when called with the `wrangler.dev()` API.
|
|
281
|
+
// They aren't exposed as CLI arguments.
|
|
282
|
+
AdditionalDevProps & {
|
|
283
|
+
forceLocal?: boolean;
|
|
284
|
+
enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
export async function startDev(args: StartDevOptions) {
|
|
288
|
+
let watcher: ReturnType<typeof watch> | undefined;
|
|
289
|
+
let rerender: (node: React.ReactNode) => void | undefined;
|
|
290
|
+
try {
|
|
291
|
+
if (args.logLevel) {
|
|
292
|
+
// we don't define a "none" logLevel, so "error" will do for now.
|
|
293
|
+
logger.loggerLevel = args.logLevel === "none" ? "error" : args.logLevel;
|
|
294
|
+
}
|
|
295
|
+
await printWranglerBanner();
|
|
296
|
+
|
|
297
|
+
const configPath =
|
|
298
|
+
(args.config as ConfigPath) ||
|
|
299
|
+
((args.script &&
|
|
300
|
+
findWranglerToml(path.dirname(args.script))) as ConfigPath);
|
|
301
|
+
let config = readConfig(configPath, args);
|
|
302
|
+
|
|
303
|
+
if (config.configPath) {
|
|
304
|
+
watcher = watch(config.configPath, {
|
|
305
|
+
persistent: true,
|
|
306
|
+
}).on("change", async (_event) => {
|
|
307
|
+
// TODO: Do we need to handle different `_event` types differently?
|
|
308
|
+
// e.g. what if the file is deleted, or added?
|
|
309
|
+
config = readConfig(configPath, args);
|
|
310
|
+
if (config.configPath) {
|
|
311
|
+
logger.log(`${path.basename(config.configPath)} changed...`);
|
|
312
|
+
rerender(await getDevReactElement(config));
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const entry = await getEntry(
|
|
318
|
+
{ assets: args.assets, script: args.script },
|
|
319
|
+
config,
|
|
320
|
+
"dev"
|
|
321
|
+
);
|
|
322
|
+
|
|
323
|
+
await metrics.sendMetricsEvent(
|
|
324
|
+
"run dev",
|
|
325
|
+
{
|
|
326
|
+
local: args.local,
|
|
327
|
+
usesTypeScript: /\.tsx?$/.test(entry.file),
|
|
328
|
+
},
|
|
329
|
+
{ sendMetrics: config.send_metrics, offline: args.local }
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
if (config.services && config.services.length > 0) {
|
|
333
|
+
logger.warn(
|
|
334
|
+
`This worker is bound to live services: ${config.services
|
|
335
|
+
.map(
|
|
336
|
+
(service) =>
|
|
337
|
+
`${service.binding} (${service.service}${
|
|
338
|
+
service.environment ? `@${service.environment}` : ""
|
|
339
|
+
})`
|
|
340
|
+
)
|
|
341
|
+
.join(", ")}`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (args.inspect) {
|
|
346
|
+
//devtools are enabled by default, but we still need to disable them if the caller doesn't want them
|
|
347
|
+
logger.warn(
|
|
348
|
+
"Passing --inspect is unnecessary, now you can always connect to devtools."
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
if (args["experimental-public"]) {
|
|
353
|
+
throw new Error(
|
|
354
|
+
"The --experimental-public field has been renamed to --assets"
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (args.public) {
|
|
359
|
+
throw new Error("The --public field has been renamed to --assets");
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if ((args.assets || config.assets) && (args.site || config.site)) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
"Cannot use Assets and Workers Sites in the same Worker."
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (args.assets) {
|
|
369
|
+
logger.warn(
|
|
370
|
+
"The --assets argument is experimental and may change or break at any time"
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const upstreamProtocol =
|
|
375
|
+
args["upstream-protocol"] || config.dev.upstream_protocol;
|
|
376
|
+
if (upstreamProtocol === "http") {
|
|
377
|
+
logger.warn(
|
|
378
|
+
"Setting upstream-protocol to http is not currently implemented.\n" +
|
|
379
|
+
"If this is required in your project, please add your use case to the following issue:\n" +
|
|
380
|
+
"https://github.com/cloudflare/wrangler2/issues/583."
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// TODO: if worker_dev = false and no routes, then error (only for dev)
|
|
385
|
+
|
|
386
|
+
// Compute zone info from the `host` and `route` args and config;
|
|
387
|
+
let host = args.host || config.dev.host;
|
|
388
|
+
let zoneId: string | undefined;
|
|
389
|
+
const routes: Route[] | undefined =
|
|
390
|
+
args.routes || (config.route && [config.route]) || config.routes;
|
|
391
|
+
|
|
392
|
+
if (args.forceLocal) {
|
|
393
|
+
args.local = true;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (!args.local) {
|
|
397
|
+
if (host) {
|
|
398
|
+
zoneId = await getZoneIdFromHost(host);
|
|
399
|
+
}
|
|
400
|
+
if (!zoneId && routes) {
|
|
401
|
+
const firstRoute = routes[0];
|
|
402
|
+
const zone = await getZoneForRoute(firstRoute);
|
|
403
|
+
if (zone) {
|
|
404
|
+
zoneId = zone.id;
|
|
405
|
+
host = zone.host;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
} else if (!host) {
|
|
409
|
+
if (routes) {
|
|
410
|
+
const firstRoute = routes[0];
|
|
411
|
+
host = getHostFromRoute(firstRoute);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const nodeCompat = args.nodeCompat ?? config.node_compat;
|
|
416
|
+
if (nodeCompat) {
|
|
417
|
+
logger.warn(
|
|
418
|
+
"Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const getLocalPort = memoizeGetPort(DEFAULT_LOCAL_PORT);
|
|
423
|
+
const getInspectorPort = memoizeGetPort(DEFAULT_INSPECTOR_PORT);
|
|
424
|
+
|
|
425
|
+
// eslint-disable-next-line no-inner-declarations
|
|
426
|
+
async function getDevReactElement(configParam: Config) {
|
|
427
|
+
// now log all available bindings into the terminal
|
|
428
|
+
const bindings = await getBindings(configParam, {
|
|
429
|
+
kv: args.kv,
|
|
430
|
+
vars: args.vars,
|
|
431
|
+
durableObjects: args.durableObjects,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// mask anything that was overridden in .dev.vars
|
|
435
|
+
// so that we don't log potential secrets into the terminal
|
|
436
|
+
const maskedVars = { ...bindings.vars };
|
|
437
|
+
for (const key of Object.keys(maskedVars)) {
|
|
438
|
+
if (maskedVars[key] !== configParam.vars[key]) {
|
|
439
|
+
// This means it was overridden in .dev.vars
|
|
440
|
+
// so let's mask it
|
|
441
|
+
maskedVars[key] = "(hidden)";
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
printBindings({
|
|
446
|
+
...bindings,
|
|
447
|
+
vars: maskedVars,
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
const assetPaths =
|
|
451
|
+
args.assets || config.assets
|
|
452
|
+
? getAssetPaths(config, args.assets)
|
|
453
|
+
: getSiteAssetPaths(
|
|
454
|
+
config,
|
|
455
|
+
args.site,
|
|
456
|
+
args.siteInclude,
|
|
457
|
+
args.siteExclude
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
return (
|
|
461
|
+
<Dev
|
|
462
|
+
name={getScriptName({ name: args.name, env: args.env }, config)}
|
|
463
|
+
noBundle={!(args.bundle ?? !config.no_bundle)}
|
|
464
|
+
entry={entry}
|
|
465
|
+
env={args.env}
|
|
466
|
+
zone={zoneId}
|
|
467
|
+
host={host}
|
|
468
|
+
routes={routes}
|
|
469
|
+
rules={getRules(config)}
|
|
470
|
+
legacyEnv={isLegacyEnv(config)}
|
|
471
|
+
minify={args.minify ?? config.minify}
|
|
472
|
+
nodeCompat={nodeCompat}
|
|
473
|
+
build={config.build || {}}
|
|
474
|
+
define={config.define}
|
|
475
|
+
initialMode={args.local ? "local" : "remote"}
|
|
476
|
+
jsxFactory={args["jsx-factory"] || config.jsx_factory}
|
|
477
|
+
jsxFragment={args["jsx-fragment"] || config.jsx_fragment}
|
|
478
|
+
tsconfig={args.tsconfig ?? config.tsconfig}
|
|
479
|
+
upstreamProtocol={upstreamProtocol}
|
|
480
|
+
localProtocol={args.localProtocol || config.dev.local_protocol}
|
|
481
|
+
localUpstream={args["local-upstream"] || host}
|
|
482
|
+
enableLocalPersistence={
|
|
483
|
+
args.experimentalEnableLocalPersistence || false
|
|
484
|
+
}
|
|
485
|
+
liveReload={args.liveReload || false}
|
|
486
|
+
accountId={config.account_id || getAccountFromCache()?.id}
|
|
487
|
+
assetPaths={assetPaths}
|
|
488
|
+
assetsConfig={config.assets}
|
|
489
|
+
port={args.port || config.dev.port || (await getLocalPort())}
|
|
490
|
+
ip={args.ip || config.dev.ip}
|
|
491
|
+
inspectorPort={
|
|
492
|
+
args["inspector-port"] ||
|
|
493
|
+
config.dev.inspector_port ||
|
|
494
|
+
(await getInspectorPort())
|
|
495
|
+
}
|
|
496
|
+
isWorkersSite={Boolean(args.site || config.site)}
|
|
497
|
+
compatibilityDate={getDevCompatibilityDate(
|
|
498
|
+
config,
|
|
499
|
+
args["compatibility-date"]
|
|
500
|
+
)}
|
|
501
|
+
compatibilityFlags={
|
|
502
|
+
args["compatibility-flags"] || config.compatibility_flags
|
|
503
|
+
}
|
|
504
|
+
usageModel={config.usage_model}
|
|
505
|
+
bindings={bindings}
|
|
506
|
+
crons={config.triggers.crons}
|
|
507
|
+
logLevel={args.logLevel}
|
|
508
|
+
logPrefix={args.logPrefix}
|
|
509
|
+
onReady={args.onReady}
|
|
510
|
+
inspect={args.inspect ?? true}
|
|
511
|
+
showInteractiveDevSession={args.showInteractiveDevSession}
|
|
512
|
+
forceLocal={args.forceLocal}
|
|
513
|
+
enablePagesAssetsServiceBinding={args.enablePagesAssetsServiceBinding}
|
|
514
|
+
firstPartyWorker={config.first_party_worker}
|
|
515
|
+
sendMetrics={config.send_metrics}
|
|
516
|
+
/>
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
const devReactElement = render(await getDevReactElement(config));
|
|
520
|
+
rerender = devReactElement.rerender;
|
|
521
|
+
return {
|
|
522
|
+
devReactElement,
|
|
523
|
+
watcher,
|
|
524
|
+
stop: async () => {
|
|
525
|
+
devReactElement.unmount();
|
|
526
|
+
await watcher?.close();
|
|
527
|
+
},
|
|
528
|
+
fetch: async (init?: RequestInit) => {
|
|
529
|
+
//TODO: we are not guaranteed to be assigned this port, we should fix this ASAP
|
|
530
|
+
const port = args.port || config.dev.port || (await getLocalPort());
|
|
531
|
+
const address = args.ip || config.dev.ip || "localhost";
|
|
532
|
+
|
|
533
|
+
return await fetch(`http://${address}:${port}/`, init);
|
|
534
|
+
},
|
|
535
|
+
};
|
|
536
|
+
} finally {
|
|
537
|
+
await watcher?.close();
|
|
538
|
+
}
|
|
502
539
|
}
|
|
503
540
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
sitesFolder: undefined | string;
|
|
513
|
-
port: number;
|
|
514
|
-
compatibilityDate: string | undefined;
|
|
515
|
-
compatibilityFlags: string[] | undefined;
|
|
516
|
-
usageModel: undefined | "bundled" | "unbound";
|
|
517
|
-
}): CfPreviewToken | undefined {
|
|
518
|
-
const {
|
|
519
|
-
name,
|
|
520
|
-
bundle,
|
|
521
|
-
format,
|
|
522
|
-
modules,
|
|
523
|
-
accountId,
|
|
524
|
-
apiToken,
|
|
525
|
-
bindings,
|
|
526
|
-
sitesFolder,
|
|
527
|
-
compatibilityDate,
|
|
528
|
-
compatibilityFlags,
|
|
529
|
-
usageModel,
|
|
530
|
-
port,
|
|
531
|
-
} = props;
|
|
532
|
-
const [token, setToken] = useState<CfPreviewToken | undefined>();
|
|
533
|
-
|
|
534
|
-
// This is the most reliable way to detect whether
|
|
535
|
-
// something's "happened" in our system; We make a ref and
|
|
536
|
-
// mark it once we log our initial message. Refs are vars!
|
|
537
|
-
const startedRef = useRef(false);
|
|
538
|
-
|
|
539
|
-
useEffect(() => {
|
|
540
|
-
async function start() {
|
|
541
|
-
setToken(undefined); // reset token in case we're re-running
|
|
542
|
-
|
|
543
|
-
if (!bundle) return;
|
|
544
|
-
if (format === "modules" && bundle.type === "commonjs") {
|
|
545
|
-
console.error("⎔ Cannot use modules with a commonjs bundle.");
|
|
546
|
-
// TODO: a much better error message here, with what to do next
|
|
547
|
-
return;
|
|
548
|
-
}
|
|
549
|
-
if (format === "service-worker" && bundle.type !== "esm") {
|
|
550
|
-
console.error("⎔ Cannot use service-worker with a esm bundle.");
|
|
551
|
-
// TODO: a much better error message here, with what to do next
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
if (!startedRef.current) {
|
|
556
|
-
startedRef.current = true;
|
|
557
|
-
} else {
|
|
558
|
-
console.log("⎔ Detected changes, restarting server...");
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
const assets = sitesFolder
|
|
562
|
-
? await syncAssets(
|
|
563
|
-
accountId,
|
|
564
|
-
path.basename(bundle.path),
|
|
565
|
-
sitesFolder,
|
|
566
|
-
true,
|
|
567
|
-
undefined // TODO: env
|
|
568
|
-
)
|
|
569
|
-
: {
|
|
570
|
-
manifest: undefined,
|
|
571
|
-
namespace: undefined,
|
|
572
|
-
}; // TODO: cancellable?
|
|
573
|
-
|
|
574
|
-
const content = await readFile(bundle.path, "utf-8");
|
|
575
|
-
const init: CfWorkerInit = {
|
|
576
|
-
name,
|
|
577
|
-
main: {
|
|
578
|
-
name: path.basename(bundle.path),
|
|
579
|
-
type: format || bundle.type === "esm" ? "esm" : "commonjs",
|
|
580
|
-
content,
|
|
581
|
-
},
|
|
582
|
-
modules: modules.concat(
|
|
583
|
-
assets.manifest
|
|
584
|
-
? {
|
|
585
|
-
name: "__STATIC_CONTENT_MANIFEST",
|
|
586
|
-
content: JSON.stringify(assets.manifest),
|
|
587
|
-
type: "text",
|
|
588
|
-
}
|
|
589
|
-
: []
|
|
590
|
-
),
|
|
591
|
-
bindings: {
|
|
592
|
-
...bindings,
|
|
593
|
-
kv_namespaces: (bindings.kv_namespaces || []).concat(
|
|
594
|
-
assets.namespace
|
|
595
|
-
? { binding: "__STATIC_CONTENT", id: assets.namespace }
|
|
596
|
-
: []
|
|
597
|
-
),
|
|
598
|
-
},
|
|
599
|
-
migrations: undefined, // no migrations in dev
|
|
600
|
-
compatibility_date: compatibilityDate,
|
|
601
|
-
compatibility_flags: compatibilityFlags,
|
|
602
|
-
usage_model: usageModel,
|
|
603
|
-
};
|
|
604
|
-
setToken(
|
|
605
|
-
await createWorker(init, {
|
|
606
|
-
accountId,
|
|
607
|
-
apiToken,
|
|
608
|
-
})
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
start().catch((err) => {
|
|
612
|
-
// we want to log the error, but not end the process
|
|
613
|
-
// since it could recover after the developer fixes whatever's wrong
|
|
614
|
-
console.error("remote worker:", err);
|
|
615
|
-
});
|
|
616
|
-
}, [
|
|
617
|
-
name,
|
|
618
|
-
bundle,
|
|
619
|
-
format,
|
|
620
|
-
accountId,
|
|
621
|
-
apiToken,
|
|
622
|
-
port,
|
|
623
|
-
sitesFolder,
|
|
624
|
-
compatibilityDate,
|
|
625
|
-
compatibilityFlags,
|
|
626
|
-
usageModel,
|
|
627
|
-
bindings,
|
|
628
|
-
modules,
|
|
629
|
-
]);
|
|
630
|
-
return token;
|
|
541
|
+
/**
|
|
542
|
+
* Avoiding calling `getPort()` multiple times by memoizing the first result.
|
|
543
|
+
*/
|
|
544
|
+
function memoizeGetPort(defaultPort: number) {
|
|
545
|
+
let portValue: number;
|
|
546
|
+
return async () => {
|
|
547
|
+
return portValue || (portValue = await getPort({ port: defaultPort }));
|
|
548
|
+
};
|
|
631
549
|
}
|
|
632
550
|
|
|
633
|
-
function
|
|
634
|
-
|
|
551
|
+
async function getBindings(
|
|
552
|
+
configParam: Config,
|
|
553
|
+
args: AdditionalDevProps
|
|
554
|
+
): Promise<CfWorkerInit["bindings"]> {
|
|
555
|
+
const bindings = {
|
|
556
|
+
kv_namespaces: [
|
|
557
|
+
...(configParam.kv_namespaces || []).map(
|
|
558
|
+
({ binding, preview_id, id: _id }) => {
|
|
559
|
+
// In `dev`, we make folks use a separate kv namespace called
|
|
560
|
+
// `preview_id` instead of `id` so that they don't
|
|
561
|
+
// break production data. So here we check that a `preview_id`
|
|
562
|
+
// has actually been configured.
|
|
563
|
+
// This whole block of code will be obsoleted in the future
|
|
564
|
+
// when we have copy-on-write for previews on edge workers.
|
|
565
|
+
if (!preview_id) {
|
|
566
|
+
// TODO: This error has to be a _lot_ better, ideally just asking
|
|
567
|
+
// to create a preview namespace for the user automatically
|
|
568
|
+
throw new Error(
|
|
569
|
+
`In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "${binding}" in your wrangler.toml`
|
|
570
|
+
); // Ugh, I really don't like this message very much
|
|
571
|
+
}
|
|
572
|
+
return {
|
|
573
|
+
binding,
|
|
574
|
+
id: preview_id,
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
),
|
|
578
|
+
...(args.kv || []),
|
|
579
|
+
],
|
|
580
|
+
// Use a copy of combinedVars since we're modifying it later
|
|
581
|
+
vars: {
|
|
582
|
+
...getVarsForDev(configParam),
|
|
583
|
+
...args.vars,
|
|
584
|
+
},
|
|
585
|
+
wasm_modules: configParam.wasm_modules,
|
|
586
|
+
text_blobs: configParam.text_blobs,
|
|
587
|
+
data_blobs: configParam.data_blobs,
|
|
588
|
+
durable_objects: {
|
|
589
|
+
bindings: [
|
|
590
|
+
...(configParam.durable_objects || { bindings: [] }).bindings,
|
|
591
|
+
...(args.durableObjects || []),
|
|
592
|
+
],
|
|
593
|
+
},
|
|
594
|
+
r2_buckets: configParam.r2_buckets?.map(
|
|
595
|
+
({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
|
|
596
|
+
// same idea as kv namespace preview id,
|
|
597
|
+
// same copy-on-write TODO
|
|
598
|
+
if (!preview_bucket_name) {
|
|
599
|
+
throw new Error(
|
|
600
|
+
`In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml`
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
return {
|
|
604
|
+
binding,
|
|
605
|
+
bucket_name: preview_bucket_name,
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
),
|
|
609
|
+
worker_namespaces: configParam.worker_namespaces,
|
|
610
|
+
services: configParam.services,
|
|
611
|
+
unsafe: configParam.unsafe?.bindings,
|
|
612
|
+
logfwdr: configParam.logfwdr,
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
return bindings;
|
|
635
616
|
}
|
|
636
|
-
const SLEEP_DURATION = 2000;
|
|
637
|
-
// really need a first class api for this
|
|
638
|
-
const hostNameRegex = /userHostname="(.*)"/g;
|
|
639
|
-
async function findTunnelHostname() {
|
|
640
|
-
let hostName: string | undefined;
|
|
641
|
-
while (!hostName) {
|
|
642
|
-
try {
|
|
643
|
-
const resp = await fetch("http://localhost:8789/metrics");
|
|
644
|
-
const data = await resp.text();
|
|
645
|
-
const matches = Array.from(data.matchAll(hostNameRegex));
|
|
646
|
-
hostName = matches[0][1];
|
|
647
|
-
} catch (err) {
|
|
648
|
-
await sleep(SLEEP_DURATION);
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
return hostName;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
function useTunnel(toggle: boolean) {
|
|
655
|
-
const tunnel = useRef<ReturnType<typeof spawn>>();
|
|
656
|
-
const removeSignalExitListener = useRef<() => void>();
|
|
657
|
-
// TODO: test if cloudflared is available, if not
|
|
658
|
-
// point them to a url where they can get docs to install it
|
|
659
|
-
useEffect(() => {
|
|
660
|
-
async function startTunnel() {
|
|
661
|
-
if (toggle) {
|
|
662
|
-
try {
|
|
663
|
-
await commandExists("cloudflared");
|
|
664
|
-
} catch (e) {
|
|
665
|
-
console.error(
|
|
666
|
-
"To share your worker on the internet, please install `cloudflared` from https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation"
|
|
667
|
-
);
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
console.log("⎔ Starting a tunnel...");
|
|
671
|
-
tunnel.current = spawn("cloudflared", [
|
|
672
|
-
"tunnel",
|
|
673
|
-
"--url",
|
|
674
|
-
"http://localhost:8787",
|
|
675
|
-
"--metrics",
|
|
676
|
-
"localhost:8789",
|
|
677
|
-
]);
|
|
678
|
-
|
|
679
|
-
tunnel.current.on("close", (code) => {
|
|
680
|
-
if (code !== 0) {
|
|
681
|
-
console.log(`Tunnel process exited with code ${code}`);
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
removeSignalExitListener.current = onExit((_code, _signal) => {
|
|
686
|
-
console.log("⎔ Shutting down local tunnel.");
|
|
687
|
-
tunnel.current?.kill();
|
|
688
|
-
tunnel.current = undefined;
|
|
689
|
-
});
|
|
690
|
-
|
|
691
|
-
const hostName = await findTunnelHostname();
|
|
692
|
-
await clipboardy.write(hostName);
|
|
693
|
-
console.log(`⬣ Sharing at ${hostName}, copied to clipboard.`);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
startTunnel().catch((err) => {
|
|
698
|
-
console.error("tunnel:", err);
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
return () => {
|
|
702
|
-
if (tunnel.current) {
|
|
703
|
-
console.log("⎔ Shutting down tunnel.");
|
|
704
|
-
tunnel.current?.kill();
|
|
705
|
-
tunnel.current = undefined;
|
|
706
|
-
removeSignalExitListener.current && removeSignalExitListener.current();
|
|
707
|
-
removeSignalExitListener.current = undefined;
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
}, [toggle]);
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
type useHotkeysInitialState = {
|
|
714
|
-
local: boolean;
|
|
715
|
-
tunnel: boolean;
|
|
716
|
-
};
|
|
717
|
-
function useHotkeys(initial: useHotkeysInitialState, port: number) {
|
|
718
|
-
// UGH, we should put port in context instead
|
|
719
|
-
const [toggles, setToggles] = useState(initial);
|
|
720
|
-
useInput(
|
|
721
|
-
async (
|
|
722
|
-
input,
|
|
723
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
724
|
-
key
|
|
725
|
-
) => {
|
|
726
|
-
switch (input) {
|
|
727
|
-
case "b": // open browser
|
|
728
|
-
await open(`http://localhost:${port}/`);
|
|
729
|
-
break;
|
|
730
|
-
case "d": // toggle inspector
|
|
731
|
-
await open(
|
|
732
|
-
`https://built-devtools.pages.dev/js_app?experiments=true&v8only=true&ws=localhost:9229/ws`
|
|
733
|
-
);
|
|
734
|
-
break;
|
|
735
|
-
case "s": // toggle tunnel
|
|
736
|
-
setToggles((previousToggles) => ({
|
|
737
|
-
...previousToggles,
|
|
738
|
-
tunnel: !previousToggles.tunnel,
|
|
739
|
-
}));
|
|
740
|
-
break;
|
|
741
|
-
case "l": // toggle local
|
|
742
|
-
setToggles((previousToggles) => ({
|
|
743
|
-
...previousToggles,
|
|
744
|
-
local: !previousToggles.local,
|
|
745
|
-
}));
|
|
746
|
-
break;
|
|
747
|
-
case "q": // shut down
|
|
748
|
-
case "x": // shut down
|
|
749
|
-
process.exit(0);
|
|
750
|
-
break;
|
|
751
|
-
default:
|
|
752
|
-
// nothing?
|
|
753
|
-
break;
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
);
|
|
757
|
-
return toggles;
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
function ErrorFallback(props: { error: Error }) {
|
|
761
|
-
const { exit } = useApp();
|
|
762
|
-
useEffect(() => exit(new Error()));
|
|
763
|
-
return (
|
|
764
|
-
<>
|
|
765
|
-
<Text>Something went wrong:</Text>
|
|
766
|
-
<Text>{props.error.message}</Text>
|
|
767
|
-
</>
|
|
768
|
-
);
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
export default withErrorBoundary(Dev, { FallbackComponent: ErrorFallback });
|