wrangler 0.0.0-cd66b67 → 0.0.0-ce00a44c

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