wrangler 0.0.0-bfbb0be → 0.0.0-bfbe49d0

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