wrangler 0.0.0-e98613f8 → 0.0.0-e9a45766c

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 (244) hide show
  1. package/README.md +10 -4
  2. package/bin/wrangler.js +10 -2
  3. package/miniflare-dist/index.mjs +257 -132
  4. package/package.json +26 -19
  5. package/src/__tests__/api-dev.test.ts +65 -36
  6. package/src/__tests__/api-devregistry.test.ts +121 -0
  7. package/src/__tests__/api.test.ts +27 -5
  8. package/src/__tests__/configuration.test.ts +575 -39
  9. package/src/__tests__/constellation.test.ts +371 -0
  10. package/src/__tests__/d1/d1.test.ts +82 -0
  11. package/src/__tests__/d1/execute.test.ts +66 -0
  12. package/src/__tests__/d1/migrate.test.ts +257 -0
  13. package/src/__tests__/d1/splitter.test.ts +255 -0
  14. package/src/__tests__/delete.test.ts +11 -2
  15. package/src/__tests__/deployments.test.ts +330 -52
  16. package/src/__tests__/dev.test.tsx +146 -82
  17. package/src/__tests__/generate.test.ts +10 -8
  18. package/src/__tests__/guess-worker-format.test.ts +35 -0
  19. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  20. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  21. package/src/__tests__/helpers/mock-console.ts +6 -0
  22. package/src/__tests__/helpers/mock-dialogs.ts +71 -85
  23. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  24. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  25. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  26. package/src/__tests__/helpers/mock-kv.ts +29 -16
  27. package/src/__tests__/helpers/mock-oauth-flow.ts +99 -92
  28. package/src/__tests__/helpers/mock-process.ts +8 -13
  29. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  30. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  31. package/src/__tests__/helpers/msw/handlers/deployments.ts +127 -26
  32. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  33. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  34. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  35. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  36. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  37. package/src/__tests__/helpers/msw/index.ts +32 -1
  38. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  39. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  40. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  41. package/src/__tests__/index.test.ts +92 -74
  42. package/src/__tests__/init.test.ts +909 -628
  43. package/src/__tests__/jest.setup.ts +19 -42
  44. package/src/__tests__/kv.test.ts +355 -231
  45. package/src/__tests__/logger.test.ts +68 -2
  46. package/src/__tests__/logout.test.ts +1 -1
  47. package/src/__tests__/metrics.test.ts +93 -50
  48. package/src/__tests__/middleware.scheduled.test.ts +42 -32
  49. package/src/__tests__/middleware.test.ts +212 -122
  50. package/src/__tests__/mtls-certificates.test.ts +589 -0
  51. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  52. package/src/__tests__/pages/functions-build.test.ts +528 -0
  53. package/src/__tests__/pages/pages.test.ts +81 -0
  54. package/src/__tests__/pages/project-create.test.ts +63 -0
  55. package/src/__tests__/pages/project-list.test.ts +110 -0
  56. package/src/__tests__/pages/project-upload.test.ts +500 -0
  57. package/src/__tests__/pages/publish.test.ts +2864 -0
  58. package/src/__tests__/pages-deployment-tail.test.ts +239 -102
  59. package/src/__tests__/parse.test.ts +106 -0
  60. package/src/__tests__/publish.test.ts +2218 -1002
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +42 -32
  63. package/src/__tests__/r2.test.ts +37 -56
  64. package/src/__tests__/secret.test.ts +179 -130
  65. package/src/__tests__/tail.test.ts +113 -23
  66. package/src/__tests__/test-old-node-version.js +3 -3
  67. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  68. package/src/__tests__/tsconfig-sanity.ts +12 -0
  69. package/src/__tests__/tsconfig.json +8 -0
  70. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  71. package/src/__tests__/type-generation.test.ts +8 -0
  72. package/src/__tests__/user.test.ts +7 -18
  73. package/src/__tests__/whoami.test.tsx +8 -114
  74. package/src/__tests__/worker-namespace.test.ts +83 -69
  75. package/src/api/dev.ts +172 -61
  76. package/src/api/index.ts +10 -1
  77. package/src/api/mtls-certificate.ts +148 -0
  78. package/src/api/pages/create-worker-bundle-contents.ts +77 -0
  79. package/src/api/pages/index.ts +5 -0
  80. package/src/api/pages/publish.tsx +371 -0
  81. package/src/bundle.ts +139 -33
  82. package/src/cfetch/index.ts +0 -2
  83. package/src/cfetch/internal.ts +16 -21
  84. package/src/cli.ts +4 -4
  85. package/src/config/config.ts +14 -7
  86. package/src/config/environment.ts +80 -16
  87. package/src/config/index.ts +99 -30
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +275 -9
  90. package/src/constellation/createProject.tsx +51 -0
  91. package/src/constellation/deleteProject.ts +51 -0
  92. package/src/constellation/deleteProjectModel.ts +68 -0
  93. package/src/constellation/index.ts +75 -0
  94. package/src/constellation/listCatalog.tsx +35 -0
  95. package/src/constellation/listModel.tsx +41 -0
  96. package/src/constellation/listProject.tsx +28 -0
  97. package/src/constellation/listRuntime.tsx +28 -0
  98. package/src/constellation/options.ts +17 -0
  99. package/src/constellation/types.ts +17 -0
  100. package/src/constellation/uploadModel.tsx +64 -0
  101. package/src/constellation/utils.ts +90 -0
  102. package/src/create-worker-preview.ts +19 -8
  103. package/src/create-worker-upload-form.ts +52 -5
  104. package/src/d1/backups.tsx +40 -44
  105. package/src/d1/create.tsx +50 -43
  106. package/src/d1/{delete.tsx → delete.ts} +8 -11
  107. package/src/d1/execute.tsx +171 -166
  108. package/src/d1/index.ts +5 -6
  109. package/src/d1/list.tsx +27 -13
  110. package/src/d1/migrations/apply.tsx +92 -64
  111. package/src/d1/migrations/create.tsx +31 -29
  112. package/src/d1/migrations/helpers.ts +66 -44
  113. package/src/d1/migrations/list.tsx +47 -31
  114. package/src/d1/migrations/options.ts +7 -2
  115. package/src/d1/options.ts +3 -3
  116. package/src/d1/splitter.ts +161 -0
  117. package/src/d1/{types.tsx → types.ts} +1 -0
  118. package/src/d1/utils.ts +2 -1
  119. package/src/delete.ts +8 -16
  120. package/src/deployments.ts +333 -42
  121. package/src/deprecated/index.ts +8 -302
  122. package/src/dev/dev.tsx +13 -22
  123. package/src/dev/local.tsx +131 -69
  124. package/src/dev/remote.tsx +35 -3
  125. package/src/dev/start-server.ts +83 -77
  126. package/src/dev/use-esbuild.ts +63 -52
  127. package/src/dev/validate-dev-props.ts +9 -0
  128. package/src/{dev-registry.tsx → dev-registry.ts} +9 -8
  129. package/src/dev.tsx +131 -110
  130. package/src/dialogs.ts +136 -0
  131. package/src/dispatch-namespace.ts +21 -17
  132. package/src/docs/helpers.ts +50 -0
  133. package/src/docs/index.ts +54 -0
  134. package/src/entry.ts +26 -11
  135. package/src/environment-variables/factory.ts +89 -0
  136. package/src/environment-variables/misc-variables.ts +30 -0
  137. package/src/generate/index.ts +298 -0
  138. package/src/{index.tsx → index.ts} +137 -56
  139. package/src/init.ts +254 -187
  140. package/src/inspect.ts +170 -9
  141. package/src/jest.d.ts +4 -0
  142. package/src/kv/helpers.ts +7 -4
  143. package/src/kv/index.ts +15 -17
  144. package/src/logger.ts +36 -5
  145. package/src/metrics/metrics-config.ts +1 -1
  146. package/src/metrics/send-event.ts +4 -1
  147. package/src/miniflare-cli/assets.ts +66 -31
  148. package/src/miniflare-cli/index.ts +5 -8
  149. package/src/miniflare-cli/tsconfig.json +9 -0
  150. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  151. package/src/miniflare-cli/types.ts +11 -0
  152. package/src/module-collection.ts +92 -26
  153. package/src/mtls-certificate/cli.ts +155 -0
  154. package/src/pages/build.ts +423 -0
  155. package/src/pages/buildFunctions.ts +140 -0
  156. package/src/pages/{deployment-tails.tsx → deployment-tails.ts} +7 -10
  157. package/src/pages/deployments.tsx +9 -9
  158. package/src/pages/{dev.tsx → dev.ts} +167 -139
  159. package/src/pages/errors.ts +1 -0
  160. package/src/pages/functions/buildPlugin.ts +61 -54
  161. package/src/pages/functions/buildWorker.ts +217 -33
  162. package/src/pages/functions/tsconfig.json +8 -0
  163. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  164. package/src/pages/{functions.tsx → functions.ts} +8 -4
  165. package/src/pages/{index.tsx → index.ts} +3 -3
  166. package/src/pages/projects.tsx +12 -22
  167. package/src/pages/publish.tsx +43 -227
  168. package/src/pages/types.ts +5 -0
  169. package/src/pages/upload.tsx +57 -14
  170. package/src/pages/utils.ts +1 -1
  171. package/src/parse.ts +23 -1
  172. package/src/paths.ts +1 -1
  173. package/src/publish/index.ts +20 -16
  174. package/src/publish/publish.ts +76 -46
  175. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  176. package/src/queues/cli/commands/consumer/add.ts +24 -24
  177. package/src/queues/cli/commands/consumer/index.ts +3 -6
  178. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  179. package/src/queues/cli/commands/create.ts +8 -8
  180. package/src/queues/cli/commands/delete.ts +8 -8
  181. package/src/queues/cli/commands/index.ts +3 -4
  182. package/src/queues/cli/commands/list.ts +8 -8
  183. package/src/queues/client.ts +1 -0
  184. package/src/r2/helpers.ts +1 -0
  185. package/src/r2/index.ts +28 -28
  186. package/src/secret/index.ts +15 -16
  187. package/src/{sites.tsx → sites.ts} +165 -53
  188. package/src/tail/createTail.ts +37 -1
  189. package/src/tail/filters.ts +1 -1
  190. package/src/tail/index.ts +8 -11
  191. package/src/tail/printing.ts +25 -0
  192. package/src/traverse-module-graph.ts +54 -0
  193. package/src/tsconfig-sanity.ts +16 -0
  194. package/src/type-generation.ts +11 -3
  195. package/src/user/access.ts +0 -1
  196. package/src/user/auth-variables.ts +113 -0
  197. package/src/user/choose-account.tsx +1 -31
  198. package/src/user/index.ts +0 -1
  199. package/src/user/{user.tsx → user.ts} +114 -77
  200. package/src/utils/render.ts +93 -0
  201. package/src/{whoami.tsx → whoami.ts} +37 -71
  202. package/src/worker.ts +35 -1
  203. package/src/yargs-types.ts +18 -5
  204. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  205. package/templates/__tests__/tsconfig.json +8 -0
  206. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  207. package/templates/checked-fetch.js +9 -3
  208. package/templates/d1-beta-facade.js +42 -3
  209. package/templates/facade.d.ts +14 -0
  210. package/templates/first-party-worker-module-facade.ts +4 -3
  211. package/templates/format-dev-errors.ts +8 -6
  212. package/templates/gitignore +1 -0
  213. package/templates/init-tests/test-jest-new-worker.js +3 -5
  214. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  215. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  216. package/templates/middleware/loader-modules.ts +2 -2
  217. package/templates/middleware/loader-sw.ts +6 -0
  218. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  219. package/templates/new-worker.ts +3 -0
  220. package/templates/pages-dev-pipeline.ts +4 -1
  221. package/templates/pages-shim.ts +4 -1
  222. package/templates/pages-template-plugin.ts +19 -10
  223. package/templates/serve-static-assets.ts +17 -14
  224. package/templates/service-bindings-module-facade.js +1 -0
  225. package/templates/tsconfig-sanity.ts +11 -0
  226. package/templates/tsconfig.init.json +105 -0
  227. package/templates/tsconfig.json +5 -103
  228. package/templates/tsconfig.tsbuildinfo +1 -0
  229. package/wrangler-dist/cli.d.ts +871 -73
  230. package/wrangler-dist/cli.js +80512 -90686
  231. package/wrangler-dist/wasm-sync.wasm +0 -0
  232. package/src/__tests__/api-devregistry.test.js +0 -56
  233. package/src/__tests__/d1.test.ts +0 -80
  234. package/src/__tests__/dialogs.test.tsx +0 -40
  235. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  236. package/src/__tests__/pages.test.ts +0 -2442
  237. package/src/dialogs.tsx +0 -168
  238. package/src/environment-variables.ts +0 -50
  239. package/src/pages/build.tsx +0 -270
  240. package/src/user/env-vars.ts +0 -46
  241. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  242. /package/src/d1/migrations/{index.tsx → index.ts} +0 -0
  243. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  244. /package/src/pages/{hash.tsx → hash.ts} +0 -0
package/src/dev.tsx CHANGED
@@ -19,7 +19,6 @@ import { collectKeyValues } from "./utils/collectKeyValues";
19
19
  import { identifyD1BindingsAsBeta } from "./worker";
20
20
  import { getHostFromRoute, getZoneForRoute, getZoneIdFromHost } from "./zones";
21
21
  import {
22
- type ConfigPath,
23
22
  DEFAULT_INSPECTOR_PORT,
24
23
  DEFAULT_LOCAL_PORT,
25
24
  getDevCompatibilityDate,
@@ -29,60 +28,16 @@ import {
29
28
  printWranglerBanner,
30
29
  } from "./index";
31
30
  import type { Config, Environment } from "./config";
32
- import type { Route } from "./config/environment";
33
- import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli";
31
+ import type { Route, Rule } from "./config/environment";
32
+ import type { LoggerLevel } from "./logger";
33
+ import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types";
34
34
  import type { CfWorkerInit } from "./worker";
35
- import type { CommonYargsOptions } from "./yargs-types";
36
- import type { Argv, ArgumentsCamelCase } from "yargs";
37
-
38
- interface DevArgs {
39
- config?: string;
40
- script?: string;
41
- name?: string;
42
- bundle?: boolean;
43
- build?: boolean;
44
- format?: string;
45
- env?: string;
46
- "compatibility-date"?: string;
47
- "compatibility-flags"?: string[];
48
- latest?: boolean;
49
- ip?: string;
50
- inspect?: boolean;
51
- port?: number;
52
- "inspector-port"?: number;
53
- routes?: string[];
54
- host?: string;
55
- "local-protocol"?: "http" | "https";
56
- "local-upstream"?: string | undefined;
57
- "experimental-public"?: string;
58
- public?: string;
59
- assets?: string;
60
- site?: string;
61
- "site-include"?: string[];
62
- "site-exclude"?: string[];
63
- "upstream-protocol"?: "http" | "https";
64
- "jsx-factory"?: string;
65
- "jsx-fragment"?: string;
66
- tsconfig?: string;
67
- local?: boolean;
68
- "experimental-local"?: boolean;
69
- "experimental-local-remote-kv"?: boolean;
70
- minify?: boolean;
71
- var?: string[];
72
- define?: string[];
73
- "node-compat"?: boolean;
74
- "experimental-enable-local-persistence"?: boolean;
75
- persist?: boolean;
76
- "persist-to"?: string;
77
- "live-reload"?: boolean;
78
- onReady?: (ip: string, port: number) => void;
79
- logLevel?: "none" | "info" | "error" | "log" | "warn" | "debug";
80
- logPrefix?: string;
81
- showInteractiveDevSession?: boolean;
82
- "test-scheduled"?: boolean;
83
- }
35
+ import type {
36
+ CommonYargsArgv,
37
+ StrictYargsOptionsToInterface,
38
+ } from "./yargs-types";
84
39
 
85
- export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
40
+ export function devOptions(yargs: CommonYargsArgv) {
86
41
  return (
87
42
  yargs
88
43
  .positional("script", {
@@ -177,6 +132,13 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
177
132
  type: "string",
178
133
  requiresArg: true,
179
134
  })
135
+ .option("public", {
136
+ describe: "(Deprecated) Static assets to be served",
137
+ type: "string",
138
+ requiresArg: true,
139
+ deprecated: true,
140
+ hidden: true,
141
+ })
180
142
  .option("site", {
181
143
  describe: "Root folder of static assets for Workers Sites",
182
144
  type: "string",
@@ -267,7 +229,7 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
267
229
  type: "boolean",
268
230
  })
269
231
  .option("node-compat", {
270
- describe: "Enable node.js compatibility",
232
+ describe: "Enable Node.js compatibility",
271
233
  type: "boolean",
272
234
  })
273
235
  .option("experimental-enable-local-persistence", {
@@ -322,13 +284,16 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
322
284
  .option("log-level", {
323
285
  choices: ["debug", "info", "log", "warn", "error", "none"] as const,
324
286
  describe: "Specify logging level",
325
- default: "log",
287
+ // Yargs requires this to type log-level properly
288
+ default: "log" as LoggerLevel,
326
289
  })
327
290
  );
328
291
  }
329
292
 
330
- export async function devHandler(args: ArgumentsCamelCase<DevArgs>) {
331
- if (!args.local) {
293
+ type DevArguments = StrictYargsOptionsToInterface<typeof devOptions>;
294
+
295
+ export async function devHandler(args: DevArguments) {
296
+ if (!(args.local || args.experimentalLocal)) {
332
297
  const isLoggedIn = await loginOrRefreshIfRequired();
333
298
  if (!isLoggedIn) {
334
299
  throw new Error(
@@ -369,14 +334,20 @@ export type AdditionalDevProps = {
369
334
  preview_bucket_name?: string;
370
335
  }[];
371
336
  d1Databases?: Environment["d1_databases"];
337
+ processEntrypoint?: boolean;
338
+ moduleRoot?: string;
339
+ rules?: Rule[];
372
340
  };
373
341
 
374
- type StartDevOptions = ArgumentsCamelCase<DevArgs> &
342
+ type StartDevOptions = DevArguments &
375
343
  // These options can be passed in directly when called with the `wrangler.dev()` API.
376
344
  // They aren't exposed as CLI arguments.
377
345
  AdditionalDevProps & {
378
346
  forceLocal?: boolean;
347
+ disableDevRegistry?: boolean;
379
348
  enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
349
+ onReady?: (ip: string, port: number) => void;
350
+ showInteractiveDevSession?: boolean;
380
351
  };
381
352
 
382
353
  export async function startDev(args: StartDevOptions) {
@@ -399,9 +370,8 @@ export async function startDev(args: StartDevOptions) {
399
370
  }
400
371
 
401
372
  const configPath =
402
- (args.config as ConfigPath) ||
403
- ((args.script &&
404
- findWranglerToml(path.dirname(args.script))) as ConfigPath);
373
+ args.config ||
374
+ (args.script && findWranglerToml(path.dirname(args.script)));
405
375
  let config = readConfig(configPath, args);
406
376
 
407
377
  if (config.configPath) {
@@ -420,7 +390,8 @@ export async function startDev(args: StartDevOptions) {
420
390
 
421
391
  const {
422
392
  entry,
423
- nodeCompat,
393
+ legacyNodeCompat,
394
+ nodejsCompat,
424
395
  upstreamProtocol,
425
396
  zoneId,
426
397
  host,
@@ -442,7 +413,7 @@ export async function startDev(args: StartDevOptions) {
442
413
 
443
414
  // eslint-disable-next-line no-inner-declarations
444
415
  async function getDevReactElement(configParam: Config) {
445
- const { assetPaths, bindings } = await getBindingsAndAssetPaths(
416
+ const { assetPaths, bindings } = getBindingsAndAssetPaths(
446
417
  args,
447
418
  configParam
448
419
  );
@@ -456,21 +427,23 @@ export async function startDev(args: StartDevOptions) {
456
427
  zone={zoneId}
457
428
  host={host}
458
429
  routes={routes}
459
- rules={getRules(configParam)}
430
+ processEntrypoint={!!args.processEntrypoint}
431
+ rules={args.rules ?? getRules(configParam)}
460
432
  legacyEnv={isLegacyEnv(configParam)}
461
433
  minify={args.minify ?? configParam.minify}
462
- nodeCompat={nodeCompat}
434
+ legacyNodeCompat={legacyNodeCompat}
435
+ nodejsCompat={nodejsCompat}
463
436
  build={configParam.build || {}}
464
437
  define={{ ...configParam.define, ...cliDefines }}
465
438
  initialMode={
466
439
  args.local || args.experimentalLocal ? "local" : "remote"
467
440
  }
468
- jsxFactory={args["jsx-factory"] || configParam.jsx_factory}
469
- jsxFragment={args["jsx-fragment"] || configParam.jsx_fragment}
441
+ jsxFactory={args.jsxFactory || configParam.jsx_factory}
442
+ jsxFragment={args.jsxFragment || configParam.jsx_fragment}
470
443
  tsconfig={args.tsconfig ?? configParam.tsconfig}
471
444
  upstreamProtocol={upstreamProtocol}
472
445
  localProtocol={args.localProtocol || configParam.dev.local_protocol}
473
- localUpstream={args["local-upstream"] || host}
446
+ localUpstream={args.localUpstream ?? host}
474
447
  localPersistencePath={localPersistencePath}
475
448
  liveReload={args.liveReload || false}
476
449
  accountId={configParam.account_id || getAccountFromCache()?.id}
@@ -497,7 +470,6 @@ export async function startDev(args: StartDevOptions) {
497
470
  bindings={bindings}
498
471
  crons={configParam.triggers.crons}
499
472
  queueConsumers={configParam.queues.consumers}
500
- logPrefix={args.logPrefix}
501
473
  onReady={args.onReady}
502
474
  inspect={args.inspect ?? true}
503
475
  showInteractiveDevSession={args.showInteractiveDevSession}
@@ -505,18 +477,35 @@ export async function startDev(args: StartDevOptions) {
505
477
  enablePagesAssetsServiceBinding={args.enablePagesAssetsServiceBinding}
506
478
  firstPartyWorker={configParam.first_party_worker}
507
479
  sendMetrics={configParam.send_metrics}
508
- testScheduled={args["test-scheduled"]}
480
+ testScheduled={args.testScheduled}
509
481
  experimentalLocal={args.experimentalLocal}
510
482
  experimentalLocalRemoteKv={args.experimentalLocalRemoteKv}
511
483
  />
512
484
  );
513
485
  }
514
486
  const devReactElement = render(await getDevReactElement(config));
487
+
488
+ // In the bootstrapper script `bin/wrangler.js`, we open an IPC channel, so
489
+ // IPC messages from this process are propagated through the bootstrapper.
490
+ // Normally, Node's SIGINT handler would close this for us, but interactive
491
+ // mode enables raw mode on stdin which disables the built-in handler. The
492
+ // following line disconnects from the IPC channel when we press `x` or
493
+ // CTRL-C in interactive mode, ensuring no open handles, and allowing for a
494
+ // clean exit. Note, if we called `stop()` using the dev API, we don't want
495
+ // to disconnect here, as the user may still need IPC. We also don't want
496
+ // to disconnect if this file was imported in Jest (not the case with E2E
497
+ // tests), as that would stop communication with the test runner.
498
+ let apiStopped = false;
499
+ void devReactElement.waitUntilExit().then(() => {
500
+ if (!apiStopped && typeof jest === "undefined") process.disconnect?.();
501
+ });
502
+
515
503
  rerender = devReactElement.rerender;
516
504
  return {
517
505
  devReactElement,
518
506
  watcher,
519
507
  stop: async () => {
508
+ apiStopped = true;
520
509
  devReactElement.unmount();
521
510
  await watcher?.close();
522
511
  },
@@ -533,14 +522,13 @@ export async function startApiDev(args: StartDevOptions) {
533
522
  await printWranglerBanner();
534
523
 
535
524
  const configPath =
536
- (args.config as ConfigPath) ||
537
- ((args.script &&
538
- findWranglerToml(path.dirname(args.script))) as ConfigPath);
525
+ args.config || (args.script && findWranglerToml(path.dirname(args.script)));
539
526
  const config = readConfig(configPath, args);
540
527
 
541
528
  const {
542
529
  entry,
543
- nodeCompat,
530
+ legacyNodeCompat,
531
+ nodejsCompat,
544
532
  upstreamProtocol,
545
533
  zoneId,
546
534
  host,
@@ -559,7 +547,7 @@ export async function startApiDev(args: StartDevOptions) {
559
547
 
560
548
  // eslint-disable-next-line no-inner-declarations
561
549
  async function getDevServer(configParam: Config) {
562
- const { assetPaths, bindings } = await getBindingsAndAssetPaths(
550
+ const { assetPaths, bindings } = getBindingsAndAssetPaths(
563
551
  args,
564
552
  configParam
565
553
  );
@@ -576,46 +564,45 @@ export async function startApiDev(args: StartDevOptions) {
576
564
  zone: zoneId,
577
565
  host: host,
578
566
  routes: routes,
579
- rules: getRules(configParam),
567
+ processEntrypoint: !!args.processEntrypoint,
568
+ rules: args.rules ?? getRules(configParam),
580
569
  legacyEnv: isLegacyEnv(configParam),
581
570
  minify: args.minify ?? configParam.minify,
582
- nodeCompat: nodeCompat,
571
+ legacyNodeCompat,
572
+ nodejsCompat,
583
573
  build: configParam.build || {},
584
574
  define: { ...config.define, ...cliDefines },
585
575
  initialMode: args.local ? "local" : "remote",
586
- jsxFactory: args["jsx-factory"] || configParam.jsx_factory,
587
- jsxFragment: args["jsx-fragment"] || configParam.jsx_fragment,
576
+ jsxFactory: args.jsxFactory ?? configParam.jsx_factory,
577
+ jsxFragment: args.jsxFragment ?? configParam.jsx_fragment,
588
578
  tsconfig: args.tsconfig ?? configParam.tsconfig,
589
579
  upstreamProtocol: upstreamProtocol,
590
- localProtocol: args.localProtocol || configParam.dev.local_protocol,
591
- localUpstream: args["local-upstream"] || host,
580
+ localProtocol: args.localProtocol ?? configParam.dev.local_protocol,
581
+ localUpstream: args.localUpstream ?? host,
592
582
  localPersistencePath,
593
- liveReload: args.liveReload || false,
594
- accountId: configParam.account_id || getAccountFromCache()?.id,
583
+ liveReload: args.liveReload ?? false,
584
+ accountId: configParam.account_id ?? getAccountFromCache()?.id,
595
585
  assetPaths: assetPaths,
596
586
  assetsConfig: configParam.assets,
597
587
  //port can be 0, which means to use a random port
598
588
  initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()),
599
- initialIp: args.ip || configParam.dev.ip,
589
+ initialIp: args.ip ?? configParam.dev.ip,
600
590
  inspectorPort:
601
- args["inspector-port"] ??
591
+ args.inspectorPort ??
602
592
  configParam.dev.inspector_port ??
603
593
  (await getInspectorPort()),
604
594
  isWorkersSite: Boolean(args.site || configParam.site),
605
595
  compatibilityDate: getDevCompatibilityDate(
606
596
  config,
607
597
  // Only `compatibilityDate` will be set when using `unstable_dev`
608
- args["compatibility-date"] ?? args.compatibilityDate
598
+ args.compatibilityDate
609
599
  ),
610
600
  compatibilityFlags:
611
- args["compatibility-flags"] ??
612
- args.compatibilityFlags ??
613
- configParam.compatibility_flags,
601
+ args.compatibilityFlags ?? configParam.compatibility_flags,
614
602
  usageModel: configParam.usage_model,
615
603
  bindings: bindings,
616
604
  crons: configParam.triggers.crons,
617
605
  queueConsumers: configParam.queues.consumers,
618
- logPrefix: args.logPrefix,
619
606
  onReady: args.onReady,
620
607
  inspect: args.inspect ?? true,
621
608
  showInteractiveDevSession: args.showInteractiveDevSession,
@@ -627,6 +614,7 @@ export async function startApiDev(args: StartDevOptions) {
627
614
  testScheduled: args.testScheduled,
628
615
  experimentalLocal: args.experimentalLocal,
629
616
  experimentalLocalRemoteKv: args.experimentalLocalRemoteKv,
617
+ disableDevRegistry: args.disableDevRegistry ?? false,
630
618
  });
631
619
  }
632
620
 
@@ -678,7 +666,7 @@ async function getZoneIdHostAndRoutes(args: StartDevOptions, config: Config) {
678
666
  args.local = true;
679
667
  }
680
668
 
681
- if (!args.local) {
669
+ if (!args.local && !args.experimentalLocal) {
682
670
  if (host) {
683
671
  zoneId = await getZoneIdFromHost(host);
684
672
  }
@@ -704,7 +692,7 @@ async function validateDevServerSettings(
704
692
  config: Config
705
693
  ) {
706
694
  const entry = await getEntry(
707
- { assets: args.assets, script: args.script },
695
+ { assets: args.assets, script: args.script, moduleRoot: args.moduleRoot },
708
696
  config,
709
697
  "dev"
710
698
  );
@@ -732,8 +720,7 @@ async function validateDevServerSettings(
732
720
  "Passing --inspect is unnecessary, now you can always connect to devtools."
733
721
  );
734
722
  }
735
-
736
- if (args["experimental-public"]) {
723
+ if (args.experimentalPublic) {
737
724
  throw new Error(
738
725
  "The --experimental-public field has been renamed to --assets"
739
726
  );
@@ -743,7 +730,7 @@ async function validateDevServerSettings(
743
730
  throw new Error("The --public field has been renamed to --assets");
744
731
  }
745
732
 
746
- if ((args.assets || config.assets) && (args.site || config.site)) {
733
+ if ((args.assets ?? config.assets) && (args.site ?? config.site)) {
747
734
  throw new Error("Cannot use Assets and Workers Sites in the same Worker.");
748
735
  }
749
736
 
@@ -753,18 +740,27 @@ async function validateDevServerSettings(
753
740
  );
754
741
  }
755
742
  const upstreamProtocol =
756
- args["upstream-protocol"] || config.dev.upstream_protocol;
743
+ args.upstreamProtocol ?? config.dev.upstream_protocol;
757
744
  if (upstreamProtocol === "http") {
758
745
  logger.warn(
759
746
  "Setting upstream-protocol to http is not currently implemented.\n" +
760
747
  "If this is required in your project, please add your use case to the following issue:\n" +
761
- "https://github.com/cloudflare/wrangler2/issues/583."
748
+ "https://github.com/cloudflare/workers-sdk/issues/583."
762
749
  );
763
750
  }
764
- const nodeCompat = args.nodeCompat ?? config.node_compat;
765
- if (nodeCompat) {
751
+ const legacyNodeCompat = args.nodeCompat ?? config.node_compat;
752
+ if (legacyNodeCompat) {
766
753
  logger.warn(
767
- "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."
754
+ "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."
755
+ );
756
+ }
757
+
758
+ const compatibilityFlags =
759
+ args.compatibilityFlags ?? config.compatibility_flags;
760
+ const nodejsCompat = compatibilityFlags?.includes("nodejs_compat");
761
+ if (legacyNodeCompat && nodejsCompat) {
762
+ throw new Error(
763
+ "The `nodejs_compat` compatibility flag cannot be used in conjunction with the legacy `--node-compat` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the `--node-compat` argument from your CLI command or `node_compat = true` from your config file."
768
764
  );
769
765
  }
770
766
 
@@ -787,7 +783,8 @@ async function validateDevServerSettings(
787
783
  return {
788
784
  entry,
789
785
  upstreamProtocol,
790
- nodeCompat,
786
+ legacyNodeCompat,
787
+ nodejsCompat,
791
788
  getLocalPort,
792
789
  getInspectorPort,
793
790
  zoneId,
@@ -798,14 +795,11 @@ async function validateDevServerSettings(
798
795
  };
799
796
  }
800
797
 
801
- async function getBindingsAndAssetPaths(
802
- args: StartDevOptions,
803
- configParam: Config
804
- ) {
798
+ function getBindingsAndAssetPaths(args: StartDevOptions, configParam: Config) {
805
799
  const cliVars = collectKeyValues(args.var);
806
800
 
807
801
  // now log all available bindings into the terminal
808
- const bindings = await getBindings(configParam, args.env, {
802
+ const bindings = getBindings(configParam, args.env, args.local ?? false, {
809
803
  kv: args.kv,
810
804
  vars: { ...args.vars, ...cliVars },
811
805
  durableObjects: args.durableObjects,
@@ -832,11 +826,12 @@ async function getBindingsAndAssetPaths(
832
826
  return { assetPaths, bindings };
833
827
  }
834
828
 
835
- async function getBindings(
829
+ function getBindings(
836
830
  configParam: Config,
837
831
  env: string | undefined,
832
+ local: boolean,
838
833
  args: AdditionalDevProps
839
- ): Promise<CfWorkerInit["bindings"]> {
834
+ ): CfWorkerInit["bindings"] {
840
835
  const bindings = {
841
836
  kv_namespaces: [
842
837
  ...(configParam.kv_namespaces || []).map(
@@ -862,6 +857,7 @@ async function getBindings(
862
857
  ),
863
858
  ...(args.kv || []),
864
859
  ],
860
+ send_email: configParam.send_email,
865
861
  // Use a copy of combinedVars since we're modifying it later
866
862
  vars: {
867
863
  ...getVarsForDev(configParam, env),
@@ -900,11 +896,36 @@ async function getBindings(
900
896
  ...(args.r2 || []),
901
897
  ],
902
898
  dispatch_namespaces: configParam.dispatch_namespaces,
899
+ mtls_certificates: configParam.mtls_certificates,
903
900
  services: configParam.services,
904
- unsafe: configParam.unsafe?.bindings,
901
+ analytics_engine_datasets: configParam.analytics_engine_datasets,
902
+ unsafe: {
903
+ bindings: configParam.unsafe.bindings,
904
+ metadata: configParam.unsafe.metadata,
905
+ },
905
906
  logfwdr: configParam.logfwdr,
906
907
  d1_databases: identifyD1BindingsAsBeta([
907
- ...configParam.d1_databases,
908
+ ...(configParam.d1_databases ?? []).map((d1Db) => {
909
+ //in local dev, bindings don't matter
910
+ if (local) {
911
+ return {
912
+ ...d1Db,
913
+ database_id: "local",
914
+ };
915
+ }
916
+ // if you have a preview_database_id, we'll use it, but we shouldn't force people to use it.
917
+ if (!d1Db.preview_database_id && !process.env.NO_D1_WARNING) {
918
+ logger.log(
919
+ `--------------------\nšŸ’” Recommendation: for development, use a preview D1 database rather than the one you'd use in production.\nšŸ’” Create a new D1 database with "wrangler d1 create <name>" and add its id as preview_database_id to the d1_database "${d1Db.binding}" in your wrangler.toml\n--------------------\n`
920
+ );
921
+ }
922
+ return {
923
+ ...d1Db,
924
+ database_id: d1Db.preview_database_id
925
+ ? d1Db.preview_database_id
926
+ : d1Db.database_id,
927
+ };
928
+ }),
908
929
  ...(args.d1Databases || []),
909
930
  ]),
910
931
  };
package/src/dialogs.ts ADDED
@@ -0,0 +1,136 @@
1
+ import chalk from "chalk";
2
+ import prompts from "prompts";
3
+ import { CI } from "./is-ci";
4
+ import isInteractive from "./is-interactive";
5
+ import { logger } from "./logger";
6
+
7
+ // TODO: Use this function across the codebase.
8
+ function isNonInteractiveOrCI(): boolean {
9
+ return !isInteractive() || CI.isCI();
10
+ }
11
+
12
+ export class NoDefaultValueProvided extends Error {
13
+ constructor() {
14
+ // This is user-facing, so make the message something understandable
15
+ // It _should_ always be caught and replaced with a more descriptive error
16
+ // but this is fine as a fallback.
17
+ super("This command cannot be run in a non-interactive context");
18
+ Object.setPrototypeOf(this, new.target.prototype);
19
+ }
20
+ }
21
+
22
+ interface ConfirmOptions {
23
+ defaultValue?: boolean;
24
+ }
25
+
26
+ export async function confirm(
27
+ text: string,
28
+ { defaultValue = true }: ConfirmOptions = {}
29
+ ): Promise<boolean> {
30
+ if (isNonInteractiveOrCI()) {
31
+ logger.log(`? ${text}`);
32
+ logger.log(
33
+ `šŸ¤– ${chalk.dim(
34
+ "Using default value in non-interactive context:"
35
+ )} ${chalk.white.bold(defaultValue ? "yes" : "no")}`
36
+ );
37
+ return defaultValue;
38
+ }
39
+ const { value } = await prompts({
40
+ type: "confirm",
41
+ name: "value",
42
+ message: text,
43
+ initial: defaultValue,
44
+ onState: (state) => {
45
+ if (state.aborted) {
46
+ process.nextTick(() => {
47
+ process.exit(1);
48
+ });
49
+ }
50
+ },
51
+ });
52
+ return value;
53
+ }
54
+
55
+ interface PromptOptions {
56
+ defaultValue?: string;
57
+ isSecret?: boolean;
58
+ }
59
+
60
+ export async function prompt(
61
+ text: string,
62
+ options: PromptOptions = {}
63
+ ): Promise<string> {
64
+ if (isNonInteractiveOrCI()) {
65
+ if (options?.defaultValue === undefined) {
66
+ throw new NoDefaultValueProvided();
67
+ }
68
+ logger.log(`? ${text}`);
69
+ logger.log(
70
+ `šŸ¤– ${chalk.dim(
71
+ "Using default value in non-interactive context:"
72
+ )} ${chalk.white.bold(options.defaultValue)}`
73
+ );
74
+ return options.defaultValue;
75
+ }
76
+ const { value } = await prompts({
77
+ type: "text",
78
+ name: "value",
79
+ message: text,
80
+ initial: options?.defaultValue,
81
+ style: options?.isSecret ? "password" : "default",
82
+ onState: (state) => {
83
+ if (state.aborted) {
84
+ process.nextTick(() => {
85
+ process.exit(1);
86
+ });
87
+ }
88
+ },
89
+ });
90
+ return value;
91
+ }
92
+
93
+ interface SelectOptions<Values> {
94
+ choices: SelectOption<Values>[];
95
+ defaultOption?: number;
96
+ }
97
+
98
+ interface SelectOption<Values> {
99
+ title: string;
100
+ description?: string;
101
+ value: Values;
102
+ }
103
+
104
+ export async function select<Values extends string>(
105
+ text: string,
106
+ options: SelectOptions<Values>
107
+ ): Promise<Values> {
108
+ if (isNonInteractiveOrCI()) {
109
+ if (options?.defaultOption === undefined) {
110
+ throw new NoDefaultValueProvided();
111
+ }
112
+ logger.log(`? ${text}`);
113
+ logger.log(
114
+ `šŸ¤– ${chalk.dim(
115
+ "Using default value in non-interactive context:"
116
+ )} ${chalk.white.bold(options.choices[options.defaultOption].title)}`
117
+ );
118
+ return options.choices[options.defaultOption].value;
119
+ }
120
+
121
+ const { value } = await prompts({
122
+ type: "select",
123
+ name: "value",
124
+ message: text,
125
+ choices: options.choices,
126
+ initial: options.defaultOption,
127
+ onState: (state) => {
128
+ if (state.aborted) {
129
+ process.nextTick(() => {
130
+ process.exit(1);
131
+ });
132
+ }
133
+ },
134
+ });
135
+ return value;
136
+ }