wrangler 0.0.0-eab9542 → 0.0.0-eaf71b86c

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 (180) hide show
  1. package/README.md +29 -13
  2. package/bin/wrangler.js +50 -88
  3. package/config-schema.json +3074 -0
  4. package/package.json +196 -157
  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 +2 -3
  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 +134 -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-mock-analytics-engine.d.ts +3 -0
  20. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  21. package/templates/middleware/middleware-pretty-error.ts +40 -0
  22. package/templates/middleware/middleware-scheduled.ts +29 -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/modules-watch-stub.js +4 -0
  26. package/templates/new-worker-scheduled.ts +1 -1
  27. package/templates/new-worker.js +1 -1
  28. package/templates/new-worker.ts +4 -1
  29. package/templates/pages-dev-pipeline.ts +32 -0
  30. package/templates/pages-dev-util.ts +55 -0
  31. package/templates/pages-shim.ts +9 -0
  32. package/templates/pages-template-plugin.ts +53 -18
  33. package/templates/pages-template-worker.ts +49 -12
  34. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  35. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  36. package/templates/tsconfig-sanity.ts +11 -0
  37. package/templates/tsconfig.init.json +22 -0
  38. package/templates/tsconfig.json +5 -102
  39. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  40. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  41. package/wrangler-dist/ProxyWorker.js +241 -0
  42. package/wrangler-dist/ProxyWorker.js.map +6 -0
  43. package/wrangler-dist/cli.d.ts +26465 -0
  44. package/wrangler-dist/cli.js +198587 -108581
  45. package/wrangler-dist/wasm-sync.wasm +0 -0
  46. package/Cloudflare_CA.pem +0 -18
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/miniflare-dist/index.mjs +0 -4894
  52. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  53. package/src/__tests__/config-cache.test.ts +0 -42
  54. package/src/__tests__/configuration.test.ts +0 -3946
  55. package/src/__tests__/dev.test.tsx +0 -1159
  56. package/src/__tests__/guess-worker-format.test.ts +0 -85
  57. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  58. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  59. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  60. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  61. package/src/__tests__/helpers/mock-bin.ts +0 -36
  62. package/src/__tests__/helpers/mock-cfetch.ts +0 -211
  63. package/src/__tests__/helpers/mock-console.ts +0 -97
  64. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  65. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  66. package/src/__tests__/helpers/mock-istty.ts +0 -74
  67. package/src/__tests__/helpers/mock-kv.ts +0 -33
  68. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -250
  69. package/src/__tests__/helpers/mock-process.ts +0 -39
  70. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  71. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  72. package/src/__tests__/helpers/run-in-tmp.ts +0 -39
  73. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  74. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  75. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  76. package/src/__tests__/https-options.test.ts +0 -130
  77. package/src/__tests__/index.test.ts +0 -262
  78. package/src/__tests__/init.test.ts +0 -1992
  79. package/src/__tests__/jest.setup.ts +0 -107
  80. package/src/__tests__/kv.test.ts +0 -1619
  81. package/src/__tests__/logger.test.ts +0 -141
  82. package/src/__tests__/package-manager.test.ts +0 -353
  83. package/src/__tests__/pages.test.ts +0 -1254
  84. package/src/__tests__/parse.test.ts +0 -330
  85. package/src/__tests__/publish.test.ts +0 -6569
  86. package/src/__tests__/pubsub.test.ts +0 -367
  87. package/src/__tests__/r2.test.ts +0 -233
  88. package/src/__tests__/route.test.ts +0 -45
  89. package/src/__tests__/secret.test.ts +0 -486
  90. package/src/__tests__/tail.test.ts +0 -690
  91. package/src/__tests__/user.test.ts +0 -143
  92. package/src/__tests__/whoami.test.tsx +0 -220
  93. package/src/__tests__/worker-namespace.test.ts +0 -327
  94. package/src/abort.d.ts +0 -3
  95. package/src/api/dev.ts +0 -52
  96. package/src/api/index.ts +0 -1
  97. package/src/bundle-reporter.tsx +0 -29
  98. package/src/bundle.ts +0 -212
  99. package/src/cfetch/index.ts +0 -121
  100. package/src/cfetch/internal.ts +0 -149
  101. package/src/cli.ts +0 -27
  102. package/src/config/README.md +0 -107
  103. package/src/config/config.ts +0 -243
  104. package/src/config/diagnostics.ts +0 -80
  105. package/src/config/environment.ts +0 -453
  106. package/src/config/index.ts +0 -238
  107. package/src/config/validation-helpers.ts +0 -584
  108. package/src/config/validation.ts +0 -1745
  109. package/src/config-cache.ts +0 -83
  110. package/src/create-worker-preview.ts +0 -255
  111. package/src/create-worker-upload-form.ts +0 -263
  112. package/src/dev/dev-vars.ts +0 -36
  113. package/src/dev/dev.tsx +0 -417
  114. package/src/dev/local.tsx +0 -352
  115. package/src/dev/remote.tsx +0 -382
  116. package/src/dev/use-esbuild.ts +0 -150
  117. package/src/dev.tsx +0 -538
  118. package/src/dialogs.tsx +0 -135
  119. package/src/durable.ts +0 -102
  120. package/src/entry.ts +0 -328
  121. package/src/environment-variables.ts +0 -35
  122. package/src/errors.ts +0 -11
  123. package/src/generate.ts +0 -33
  124. package/src/git-client.ts +0 -42
  125. package/src/https-options.ts +0 -123
  126. package/src/index.tsx +0 -1871
  127. package/src/init.ts +0 -549
  128. package/src/inspect.ts +0 -662
  129. package/src/intl-polyfill.d.ts +0 -139
  130. package/src/is-interactive.ts +0 -12
  131. package/src/kv.ts +0 -408
  132. package/src/logger.ts +0 -73
  133. package/src/miniflare-cli/README.md +0 -30
  134. package/src/miniflare-cli/enum-keys.ts +0 -17
  135. package/src/miniflare-cli/index.ts +0 -53
  136. package/src/miniflare-cli/request-context.ts +0 -40
  137. package/src/module-collection.ts +0 -258
  138. package/src/open-in-browser.ts +0 -17
  139. package/src/package-manager.ts +0 -174
  140. package/src/pages/build.tsx +0 -202
  141. package/src/pages/constants.ts +0 -7
  142. package/src/pages/deployments.tsx +0 -101
  143. package/src/pages/dev.tsx +0 -964
  144. package/src/pages/functions/buildPlugin.ts +0 -105
  145. package/src/pages/functions/buildWorker.ts +0 -151
  146. package/src/pages/functions/filepath-routing.test.ts +0 -234
  147. package/src/pages/functions/filepath-routing.ts +0 -189
  148. package/src/pages/functions/identifiers.ts +0 -78
  149. package/src/pages/functions/routes.ts +0 -151
  150. package/src/pages/index.tsx +0 -84
  151. package/src/pages/projects.tsx +0 -157
  152. package/src/pages/publish.tsx +0 -335
  153. package/src/pages/types.ts +0 -40
  154. package/src/pages/upload.tsx +0 -384
  155. package/src/pages/utils.ts +0 -12
  156. package/src/parse.ts +0 -286
  157. package/src/paths.ts +0 -26
  158. package/src/preview.ts +0 -31
  159. package/src/proxy.ts +0 -476
  160. package/src/publish.ts +0 -767
  161. package/src/pubsub/index.ts +0 -286
  162. package/src/pubsub/pubsub-commands.tsx +0 -577
  163. package/src/r2.ts +0 -50
  164. package/src/selfsigned.d.ts +0 -29
  165. package/src/sites.tsx +0 -372
  166. package/src/tail/filters.ts +0 -279
  167. package/src/tail/index.ts +0 -299
  168. package/src/tail/printing.ts +0 -67
  169. package/src/update-check.ts +0 -19
  170. package/src/user/choose-account.tsx +0 -60
  171. package/src/user/env-vars.ts +0 -46
  172. package/src/user/generate-auth-url.ts +0 -33
  173. package/src/user/generate-random-state.ts +0 -16
  174. package/src/user/index.ts +0 -3
  175. package/src/user/user.tsx +0 -1161
  176. package/src/whoami.tsx +0 -90
  177. package/src/worker-namespace.ts +0 -190
  178. package/src/worker.ts +0 -191
  179. package/src/zones.ts +0 -76
  180. package/templates/static-asset-facade.js +0 -43
package/src/dev.tsx DELETED
@@ -1,538 +0,0 @@
1
- import path from "node:path";
2
- import { watch } from "chokidar";
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 { getAssetPaths, getSiteAssetPaths } from "./sites";
14
- import { getAccountFromCache } from "./user";
15
- import { getZoneIdFromHost, getZoneForRoute, getHostFromRoute } from "./zones";
16
- import {
17
- printWranglerBanner,
18
- DEFAULT_LOCAL_PORT,
19
- type ConfigPath,
20
- getScriptName,
21
- getDevCompatibilityDate,
22
- getRules,
23
- isLegacyEnv,
24
- } from "./index";
25
-
26
- import type { Config } from "./config";
27
- import type { Route } from "./config/environment";
28
- import type { CfWorkerInit } from "./worker";
29
- import type { RequestInit } from "undici";
30
- import type { Argv, ArgumentsCamelCase } from "yargs";
31
-
32
- interface DevArgs {
33
- config?: string;
34
- script?: string;
35
- name?: string;
36
- bundle?: boolean;
37
- build?: boolean;
38
- format?: string;
39
- env?: string;
40
- "compatibility-date"?: string;
41
- "compatibility-flags"?: string[];
42
- latest?: boolean;
43
- ip?: string;
44
- inspect?: boolean;
45
- port?: number;
46
- "inspector-port"?: number;
47
- routes?: string[];
48
- host?: string;
49
- "local-protocol"?: "http" | "https";
50
- "local-upstream"?: string | undefined;
51
- "experimental-public"?: string;
52
- public?: string;
53
- assets?: string;
54
- site?: string;
55
- "site-include"?: string[];
56
- "site-exclude"?: string[];
57
- "upstream-protocol"?: "http" | "https";
58
- "jsx-factory"?: string;
59
- "jsx-fragment"?: string;
60
- tsconfig?: string;
61
- local?: boolean;
62
- minify?: boolean;
63
- "node-compat"?: boolean;
64
- "experimental-enable-local-persistence"?: boolean;
65
- onReady?: () => void;
66
- logLevel?: "none" | "error" | "log" | "warn" | "debug";
67
- showInteractiveDevSession?: boolean;
68
- }
69
-
70
- export function devOptions(yargs: Argv): Argv<DevArgs> {
71
- return (
72
- yargs
73
- .positional("script", {
74
- describe: "The path to an entry point for your worker",
75
- type: "string",
76
- })
77
- .option("name", {
78
- describe: "Name of the worker",
79
- type: "string",
80
- requiresArg: true,
81
- })
82
- // We want to have a --no-bundle flag, but yargs requires that
83
- // we also have a --bundle flag (that it adds the --no to by itself)
84
- // So we make a --bundle flag, but hide it, and then add a --no-bundle flag
85
- // that's visible to the user but doesn't "do" anything.
86
- .option("bundle", {
87
- describe: "Run wrangler's compilation step before publishing",
88
- type: "boolean",
89
- hidden: true,
90
- })
91
- .option("no-bundle", {
92
- describe: "Skip internal build steps and directly publish script",
93
- type: "boolean",
94
- default: false,
95
- })
96
- .option("format", {
97
- choices: ["modules", "service-worker"] as const,
98
- describe: "Choose an entry type",
99
- deprecated: true,
100
- })
101
- .option("env", {
102
- describe: "Perform on a specific environment",
103
- type: "string",
104
- requiresArg: true,
105
- alias: "e",
106
- })
107
- .option("compatibility-date", {
108
- describe: "Date to use for compatibility checks",
109
- type: "string",
110
- requiresArg: true,
111
- })
112
- .option("compatibility-flags", {
113
- describe: "Flags to use for compatibility checks",
114
- alias: "compatibility-flag",
115
- type: "string",
116
- requiresArg: true,
117
- array: true,
118
- })
119
- .option("latest", {
120
- describe: "Use the latest version of the worker runtime",
121
- type: "boolean",
122
- default: true,
123
- })
124
- .option("ip", {
125
- describe: "IP address to listen on, defaults to `localhost`",
126
- type: "string",
127
- requiresArg: true,
128
- })
129
- .option("port", {
130
- describe: "Port to listen on",
131
- type: "number",
132
- })
133
- .option("inspector-port", {
134
- describe: "Port for devtools to connect to",
135
- type: "number",
136
- })
137
- .option("routes", {
138
- describe: "Routes to upload",
139
- alias: "route",
140
- type: "string",
141
- requiresArg: true,
142
- array: true,
143
- })
144
- .option("host", {
145
- type: "string",
146
- requiresArg: true,
147
- describe:
148
- "Host to forward requests to, defaults to the zone of project",
149
- })
150
- .option("local-protocol", {
151
- describe: "Protocol to listen to requests on, defaults to http.",
152
- choices: ["http", "https"] as const,
153
- })
154
- .options("local-upstream", {
155
- type: "string",
156
- describe:
157
- "Host to act as origin in local mode, defaults to dev.host or route",
158
- })
159
- .option("experimental-public", {
160
- describe: "Static assets to be served",
161
- type: "string",
162
- requiresArg: true,
163
- deprecated: true,
164
- hidden: true,
165
- })
166
- .option("assets", {
167
- describe: "Static assets to be served",
168
- type: "string",
169
- requiresArg: true,
170
- })
171
- .option("site", {
172
- describe: "Root folder of static assets for Workers Sites",
173
- type: "string",
174
- requiresArg: true,
175
- })
176
- .option("site-include", {
177
- describe:
178
- "Array of .gitignore-style patterns that match file or directory names from the sites directory. Only matched items will be uploaded.",
179
- type: "string",
180
- requiresArg: true,
181
- array: true,
182
- })
183
- .option("site-exclude", {
184
- describe:
185
- "Array of .gitignore-style patterns that match file or directory names from the sites directory. Matched items will not be uploaded.",
186
- type: "string",
187
- requiresArg: true,
188
- array: true,
189
- })
190
- .option("upstream-protocol", {
191
- describe: "Protocol to forward requests to host on, defaults to https.",
192
- choices: ["http", "https"] as const,
193
- })
194
- .option("jsx-factory", {
195
- describe: "The function that is called for each JSX element",
196
- type: "string",
197
- requiresArg: true,
198
- })
199
- .option("jsx-fragment", {
200
- describe: "The function that is called for each JSX fragment",
201
- type: "string",
202
- requiresArg: true,
203
- })
204
- .option("tsconfig", {
205
- describe: "Path to a custom tsconfig.json file",
206
- type: "string",
207
- requiresArg: true,
208
- })
209
- .option("local", {
210
- alias: "l",
211
- describe: "Run on my machine",
212
- type: "boolean",
213
- default: false, // I bet this will a point of contention. We'll revisit it.
214
- })
215
- .option("minify", {
216
- describe: "Minify the script",
217
- type: "boolean",
218
- })
219
- .option("node-compat", {
220
- describe: "Enable node.js compatibility",
221
- type: "boolean",
222
- })
223
- .option("experimental-enable-local-persistence", {
224
- describe: "Enable persistence for this session (only for local mode)",
225
- type: "boolean",
226
- })
227
- .option("inspect", {
228
- describe: "Enable dev tools",
229
- type: "boolean",
230
- deprecated: true,
231
- })
232
- .option("legacy-env", {
233
- type: "boolean",
234
- describe: "Use legacy environments",
235
- hidden: true,
236
- })
237
- );
238
- }
239
-
240
- export async function devHandler(args: ArgumentsCamelCase<DevArgs>) {
241
- let watcher;
242
- try {
243
- const devInstance = await startDev(args);
244
- watcher = devInstance.watcher;
245
- const { waitUntilExit } = devInstance.devReactElement;
246
- await waitUntilExit();
247
- } finally {
248
- await watcher?.close();
249
- }
250
- }
251
-
252
- export async function startDev(args: ArgumentsCamelCase<DevArgs>) {
253
- let watcher: ReturnType<typeof watch> | undefined;
254
- let rerender: (node: React.ReactNode) => void | undefined;
255
- try {
256
- if (args.logLevel) {
257
- // we don't define a "none" logLevel, so "error" will do for now.
258
- logger.loggerLevel = args.logLevel === "none" ? "error" : args.logLevel;
259
- }
260
- await printWranglerBanner();
261
-
262
- const configPath =
263
- (args.config as ConfigPath) ||
264
- ((args.script &&
265
- findWranglerToml(path.dirname(args.script))) as ConfigPath);
266
- let config = readConfig(configPath, args);
267
-
268
- if (config.configPath) {
269
- watcher = watch(config.configPath, {
270
- persistent: true,
271
- }).on("change", async (_event) => {
272
- // TODO: Do we need to handle different `_event` types differently?
273
- // e.g. what if the file is deleted, or added?
274
- config = readConfig(configPath, args);
275
- if (config.configPath) {
276
- logger.log(`${path.basename(config.configPath)} changed...`);
277
- rerender(await getDevReactElement(config));
278
- }
279
- });
280
- }
281
-
282
- const entry = await getEntry(
283
- { assets: args.assets, script: args.script },
284
- config,
285
- "dev"
286
- );
287
-
288
- if (config.services && config.services.length > 0) {
289
- logger.warn(
290
- `This worker is bound to live services: ${config.services
291
- .map(
292
- (service) =>
293
- `${service.binding} (${service.service}${
294
- service.environment ? `@${service.environment}` : ""
295
- })`
296
- )
297
- .join(", ")}`
298
- );
299
- }
300
-
301
- if (args.inspect) {
302
- //devtools are enabled by default, but we still need to disable them if the caller doesn't want them
303
- logger.warn(
304
- "Passing --inspect is unnecessary, now you can always connect to devtools."
305
- );
306
- }
307
-
308
- if (args["experimental-public"]) {
309
- throw new Error(
310
- "The --experimental-public field has been renamed to --assets"
311
- );
312
- }
313
-
314
- if (args.public) {
315
- throw new Error("The --public field has been renamed to --assets");
316
- }
317
-
318
- if ((args.assets || config.assets) && (args.site || config.site)) {
319
- throw new Error(
320
- "Cannot use Assets and Workers Sites in the same Worker."
321
- );
322
- }
323
-
324
- if (args.assets) {
325
- logger.warn(
326
- "The --assets argument is experimental and may change or break at any time"
327
- );
328
- }
329
-
330
- const upstreamProtocol =
331
- args["upstream-protocol"] || config.dev.upstream_protocol;
332
- if (upstreamProtocol === "http") {
333
- logger.warn(
334
- "Setting upstream-protocol to http is not currently implemented.\n" +
335
- "If this is required in your project, please add your use case to the following issue:\n" +
336
- "https://github.com/cloudflare/wrangler2/issues/583."
337
- );
338
- }
339
-
340
- // TODO: if worker_dev = false and no routes, then error (only for dev)
341
-
342
- // Compute zone info from the `host` and `route` args and config;
343
- let host = args.host || config.dev.host;
344
- let zoneId: string | undefined;
345
- const routes: Route[] | undefined =
346
- args.routes || (config.route && [config.route]) || config.routes;
347
-
348
- if (!args.local) {
349
- if (host) {
350
- zoneId = await getZoneIdFromHost(host);
351
- }
352
- if (!zoneId && routes) {
353
- const firstRoute = routes[0];
354
- const zone = await getZoneForRoute(firstRoute);
355
- if (zone) {
356
- zoneId = zone.id;
357
- host = zone.host;
358
- }
359
- }
360
- } else if (!host) {
361
- if (routes) {
362
- const firstRoute = routes[0];
363
- host = getHostFromRoute(firstRoute);
364
- }
365
- }
366
-
367
- const nodeCompat = args["node-compat"] ?? config.node_compat;
368
- if (nodeCompat) {
369
- logger.warn(
370
- "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."
371
- );
372
- }
373
-
374
- // eslint-disable-next-line no-inner-declarations
375
- async function getBindings(
376
- configParam: Config
377
- ): Promise<CfWorkerInit["bindings"]> {
378
- return {
379
- kv_namespaces: configParam.kv_namespaces?.map(
380
- ({ binding, preview_id, id: _id }) => {
381
- // In `dev`, we make folks use a separate kv namespace called
382
- // `preview_id` instead of `id` so that they don't
383
- // break production data. So here we check that a `preview_id`
384
- // has actually been configured.
385
- // This whole block of code will be obsoleted in the future
386
- // when we have copy-on-write for previews on edge workers.
387
- if (!preview_id) {
388
- // TODO: This error has to be a _lot_ better, ideally just asking
389
- // to create a preview namespace for the user automatically
390
- throw new Error(
391
- `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`
392
- ); // Ugh, I really don't like this message very much
393
- }
394
- return {
395
- binding,
396
- id: preview_id,
397
- };
398
- }
399
- ),
400
- // Use a copy of combinedVars since we're modifying it later
401
- vars: getVarsForDev(configParam),
402
- wasm_modules: configParam.wasm_modules,
403
- text_blobs: configParam.text_blobs,
404
- data_blobs: configParam.data_blobs,
405
- durable_objects: configParam.durable_objects,
406
- r2_buckets: configParam.r2_buckets?.map(
407
- ({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
408
- // same idea as kv namespace preview id,
409
- // same copy-on-write TODO
410
- if (!preview_bucket_name) {
411
- throw new Error(
412
- `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`
413
- );
414
- }
415
- return {
416
- binding,
417
- bucket_name: preview_bucket_name,
418
- };
419
- }
420
- ),
421
- worker_namespaces: configParam.worker_namespaces,
422
- services: configParam.services,
423
- unsafe: configParam.unsafe?.bindings,
424
- };
425
- }
426
-
427
- const getLocalPort = memoizeGetPort(DEFAULT_LOCAL_PORT);
428
- const getInspectorPort = memoizeGetPort(9229);
429
-
430
- // eslint-disable-next-line no-inner-declarations
431
- async function getDevReactElement(configParam: Config) {
432
- // now log all available bindings into the terminal
433
- const bindings = await getBindings(configParam);
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["local-protocol"] || config.dev.local_protocol}
481
- localUpstream={args["local-upstream"] || host}
482
- enableLocalPersistence={
483
- args["experimental-enable-local-persistence"] || false
484
- }
485
- accountId={config.account_id || getAccountFromCache()?.id}
486
- assetPaths={assetPaths}
487
- port={args.port || config.dev.port || (await getLocalPort())}
488
- ip={args.ip || config.dev.ip}
489
- inspectorPort={args["inspector-port"] ?? (await getInspectorPort())}
490
- isWorkersSite={Boolean(args.site || config.site)}
491
- compatibilityDate={getDevCompatibilityDate(
492
- config,
493
- args["compatibility-date"]
494
- )}
495
- compatibilityFlags={
496
- args["compatibility-flags"] || config.compatibility_flags
497
- }
498
- usageModel={config.usage_model}
499
- bindings={bindings}
500
- crons={config.triggers.crons}
501
- logLevel={args.logLevel}
502
- onReady={args.onReady}
503
- inspect={args.inspect}
504
- showInteractiveDevSession={args.showInteractiveDevSession}
505
- />
506
- );
507
- }
508
- const devReactElement = render(await getDevReactElement(config));
509
- rerender = devReactElement.rerender;
510
- return {
511
- devReactElement,
512
- watcher,
513
- stop: async () => {
514
- devReactElement.unmount();
515
- await watcher?.close();
516
- },
517
- fetch: async (init?: RequestInit) => {
518
- //TODO: we are not guaranteed to be assigned this port, we should fix this ASAP
519
- const port = args.port || config.dev.port || (await getLocalPort());
520
- const address = args.ip || config.dev.ip || "localhost";
521
-
522
- return await fetch(`http://${address}:${port}/`, init);
523
- },
524
- };
525
- } finally {
526
- await watcher?.close();
527
- }
528
- }
529
-
530
- /**
531
- * Avoiding calling `getPort()` multiple times by memoizing the first result.
532
- */
533
- function memoizeGetPort(defaultPort: number) {
534
- let portValue: number;
535
- return async () => {
536
- return portValue || (portValue = await getPort({ port: defaultPort }));
537
- };
538
- }
package/src/dialogs.tsx DELETED
@@ -1,135 +0,0 @@
1
- import chalk from "chalk";
2
- import { Box, Text, useInput, render } from "ink";
3
- import SelectInput from "ink-select-input";
4
- import TextInput from "ink-text-input";
5
- import * as React from "react";
6
- import { useState } from "react";
7
- import { logger } from "./logger";
8
- type ConfirmProps = {
9
- text: string;
10
- onConfirm: (answer: boolean) => void;
11
- };
12
- function Confirm(props: ConfirmProps) {
13
- useInput((input: string, key) => {
14
- if (input === "y" || key.return === true) {
15
- props.onConfirm(true);
16
- } else if (input === "n") {
17
- props.onConfirm(false);
18
- } else {
19
- logger.warn("Unrecognised input:", input);
20
- }
21
- });
22
- return (
23
- <Box>
24
- <Text>
25
- {props.text} ({chalk.bold("y")}/n)
26
- </Text>
27
- </Box>
28
- );
29
- }
30
-
31
- export function confirm(text: string): Promise<boolean> {
32
- return new Promise((resolve) => {
33
- const { unmount } = render(
34
- <Confirm
35
- text={text}
36
- onConfirm={(answer: boolean) => {
37
- unmount();
38
- resolve(answer);
39
- }}
40
- />
41
- );
42
- });
43
- }
44
-
45
- type PromptProps = {
46
- text: string;
47
- defaultValue?: string;
48
- type?: "text" | "password";
49
- onSubmit: (text: string) => void;
50
- };
51
-
52
- function Prompt(props: PromptProps) {
53
- const [value, setValue] = useState(props.defaultValue || "");
54
-
55
- return (
56
- <Box>
57
- <Text>{props.text} </Text>
58
- <Box>
59
- <TextInput
60
- mask={props.type === "password" ? "*" : undefined}
61
- value={value}
62
- onChange={setValue}
63
- onSubmit={props.onSubmit}
64
- />
65
- </Box>
66
- </Box>
67
- );
68
- }
69
-
70
- export async function prompt(
71
- text: string,
72
- type: "text" | "password" = "text",
73
- defaultValue?: string
74
- ): Promise<string> {
75
- return new Promise((resolve) => {
76
- const { unmount } = render(
77
- <Prompt
78
- text={text}
79
- defaultValue={defaultValue}
80
- type={type}
81
- onSubmit={(inputText) => {
82
- unmount();
83
- resolve(inputText);
84
- }}
85
- />
86
- );
87
- });
88
- }
89
-
90
- type SelectOption = {
91
- value: string;
92
- label: string;
93
- };
94
-
95
- type SelectProps = {
96
- text: string;
97
- options: SelectOption[];
98
- initialIndex: number;
99
- onSelect: (value: string) => void;
100
- };
101
-
102
- function Select(props: SelectProps) {
103
- return (
104
- <Box flexDirection="column">
105
- <Text>{props.text}</Text>
106
- <SelectInput
107
- initialIndex={props.initialIndex}
108
- items={props.options}
109
- onSelect={async (selected) => {
110
- props.onSelect(selected.value);
111
- }}
112
- />
113
- </Box>
114
- );
115
- }
116
-
117
- export function select(
118
- text: string,
119
- options: SelectOption[],
120
- initialIndex: number
121
- ): Promise<string> {
122
- return new Promise((resolve) => {
123
- const { unmount } = render(
124
- <Select
125
- text={text}
126
- options={options}
127
- initialIndex={initialIndex}
128
- onSelect={(option: string) => {
129
- unmount();
130
- resolve(option);
131
- }}
132
- />
133
- );
134
- });
135
- }