wrangler 0.0.0-e7a0cd5b → 0.0.0-e7cf0caa

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 (237) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +30 -10
  3. package/miniflare-dist/index.mjs +126 -74
  4. package/package.json +27 -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 +567 -86
  9. package/src/__tests__/d1/d1.test.ts +82 -0
  10. package/src/__tests__/d1/execute.test.ts +66 -0
  11. package/src/__tests__/d1/migrate.test.ts +157 -0
  12. package/src/__tests__/d1/splitter.test.ts +255 -0
  13. package/src/__tests__/delete.test.ts +91 -49
  14. package/src/__tests__/deployments.test.ts +330 -56
  15. package/src/__tests__/dev.test.tsx +198 -90
  16. package/src/__tests__/generate.test.ts +12 -10
  17. package/src/__tests__/guess-worker-format.test.ts +35 -0
  18. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  19. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  20. package/src/__tests__/helpers/mock-console.ts +6 -0
  21. package/src/__tests__/helpers/mock-dialogs.ts +71 -85
  22. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  23. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
  24. package/src/__tests__/helpers/mock-known-routes.ts +7 -2
  25. package/src/__tests__/helpers/mock-kv.ts +29 -16
  26. package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
  27. package/src/__tests__/helpers/mock-process.ts +8 -13
  28. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  29. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  30. package/src/__tests__/helpers/msw/handlers/deployments.ts +128 -27
  31. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  32. package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
  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 +90 -72
  42. package/src/__tests__/init.test.ts +927 -631
  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 +47 -0
  47. package/src/__tests__/metrics.test.ts +94 -51
  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 +588 -0
  51. package/src/__tests__/pages/deployment-list.test.ts +80 -0
  52. package/src/__tests__/pages/functions-build.test.ts +452 -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 +955 -0
  59. package/src/__tests__/parse.test.ts +106 -0
  60. package/src/__tests__/publish.test.ts +1615 -852
  61. package/src/__tests__/pubsub.test.ts +226 -100
  62. package/src/__tests__/queues.test.ts +238 -77
  63. package/src/__tests__/r2.test.ts +55 -57
  64. package/src/__tests__/secret.test.ts +179 -130
  65. package/src/__tests__/tail.test.ts +267 -109
  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 +43 -26
  72. package/src/__tests__/user.test.ts +35 -72
  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 +168 -60
  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 +76 -0
  79. package/src/api/pages/index.ts +5 -0
  80. package/src/api/pages/publish.tsx +355 -0
  81. package/src/bundle.ts +263 -140
  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 +79 -24
  87. package/src/config/index.ts +99 -38
  88. package/src/config/validation-helpers.ts +1 -1
  89. package/src/config/validation.ts +248 -19
  90. package/src/create-worker-preview.ts +19 -8
  91. package/src/create-worker-upload-form.ts +60 -22
  92. package/src/d1/backups.tsx +43 -42
  93. package/src/d1/constants.ts +2 -0
  94. package/src/d1/create.tsx +44 -30
  95. package/src/d1/{delete.tsx → delete.ts} +11 -14
  96. package/src/d1/execute.tsx +209 -151
  97. package/src/d1/index.ts +31 -7
  98. package/src/d1/list.tsx +22 -10
  99. package/src/d1/migrations/apply.tsx +212 -0
  100. package/src/d1/migrations/create.tsx +79 -0
  101. package/src/d1/migrations/helpers.ts +172 -0
  102. package/src/d1/migrations/index.ts +3 -0
  103. package/src/d1/migrations/list.tsx +95 -0
  104. package/src/d1/migrations/options.ts +23 -0
  105. package/src/d1/options.ts +12 -2
  106. package/src/d1/splitter.ts +161 -0
  107. package/src/d1/{types.tsx → types.ts} +11 -0
  108. package/src/d1/utils.ts +12 -2
  109. package/src/delete.ts +8 -16
  110. package/src/deployments.ts +340 -46
  111. package/src/deprecated/index.ts +8 -302
  112. package/src/dev/dev.tsx +57 -44
  113. package/src/dev/local.tsx +294 -91
  114. package/src/dev/remote.tsx +32 -3
  115. package/src/dev/start-server.ts +89 -68
  116. package/src/dev/use-esbuild.ts +17 -18
  117. package/src/dev/validate-dev-props.ts +9 -0
  118. package/src/{dev-registry.tsx → dev-registry.ts} +2 -1
  119. package/src/dev.tsx +178 -118
  120. package/src/dialogs.ts +136 -0
  121. package/src/dispatch-namespace.ts +21 -17
  122. package/src/docs/index.ts +97 -0
  123. package/src/entry.ts +19 -11
  124. package/src/environment-variables/factory.ts +88 -0
  125. package/src/environment-variables/misc-variables.ts +30 -0
  126. package/src/generate/index.ts +298 -0
  127. package/src/git-client.ts +15 -4
  128. package/src/{index.tsx → index.ts} +137 -63
  129. package/src/init.ts +249 -187
  130. package/src/inspect.ts +16 -1
  131. package/src/jest.d.ts +4 -0
  132. package/src/kv/index.ts +15 -17
  133. package/src/logger.ts +32 -5
  134. package/src/metrics/metrics-config.ts +3 -3
  135. package/src/metrics/send-event.ts +6 -1
  136. package/src/miniflare-cli/assets.ts +64 -28
  137. package/src/miniflare-cli/index.ts +4 -7
  138. package/src/miniflare-cli/tsconfig.json +9 -0
  139. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  140. package/src/miniflare-cli/types.ts +11 -0
  141. package/src/module-collection.ts +91 -25
  142. package/src/mtls-certificate/cli.ts +155 -0
  143. package/src/pages/build.ts +410 -0
  144. package/src/pages/buildFunctions.ts +140 -0
  145. package/src/pages/deployment-tails.ts +281 -0
  146. package/src/pages/deployments.tsx +11 -33
  147. package/src/pages/{dev.tsx → dev.ts} +147 -124
  148. package/src/pages/errors.ts +1 -0
  149. package/src/pages/functions/buildPlugin.ts +72 -69
  150. package/src/pages/functions/buildWorker.ts +249 -114
  151. package/src/pages/functions/tsconfig.json +8 -0
  152. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  153. package/src/pages/{functions.tsx → functions.ts} +8 -4
  154. package/src/pages/{index.tsx → index.ts} +11 -3
  155. package/src/pages/projects.tsx +12 -22
  156. package/src/pages/prompt-select-project.tsx +31 -0
  157. package/src/pages/publish.tsx +45 -214
  158. package/src/pages/types.ts +6 -9
  159. package/src/pages/upload.tsx +58 -14
  160. package/src/pages/utils.ts +14 -3
  161. package/src/parse.ts +23 -1
  162. package/src/paths.ts +1 -1
  163. package/src/proxy.ts +5 -0
  164. package/src/publish/index.ts +20 -16
  165. package/src/publish/publish.ts +72 -47
  166. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +19 -20
  167. package/src/queues/cli/commands/consumer/add.ts +24 -24
  168. package/src/queues/cli/commands/consumer/index.ts +3 -6
  169. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  170. package/src/queues/cli/commands/create.ts +8 -8
  171. package/src/queues/cli/commands/delete.ts +8 -8
  172. package/src/queues/cli/commands/index.ts +6 -4
  173. package/src/queues/cli/commands/list.ts +8 -8
  174. package/src/queues/client.ts +1 -0
  175. package/src/queues/utils.ts +18 -0
  176. package/src/r2/constants.ts +4 -0
  177. package/src/r2/helpers.ts +1 -0
  178. package/src/r2/index.ts +40 -28
  179. package/src/secret/index.ts +14 -17
  180. package/src/{sites.tsx → sites.ts} +1 -1
  181. package/src/tail/createTail.ts +94 -3
  182. package/src/tail/filters.ts +1 -1
  183. package/src/tail/index.ts +8 -11
  184. package/src/tail/printing.ts +15 -0
  185. package/src/traverse-module-graph.ts +53 -0
  186. package/src/tsconfig-sanity.ts +16 -0
  187. package/src/type-generation.ts +79 -57
  188. package/src/user/access.ts +0 -1
  189. package/src/user/auth-variables.ts +113 -0
  190. package/src/user/choose-account.tsx +1 -31
  191. package/src/user/index.ts +0 -1
  192. package/src/user/{user.tsx → user.ts} +123 -82
  193. package/src/utils/render.ts +93 -0
  194. package/src/{whoami.tsx → whoami.ts} +37 -71
  195. package/src/worker.ts +35 -3
  196. package/src/yargs-types.ts +22 -5
  197. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  198. package/templates/__tests__/tsconfig.json +8 -0
  199. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  200. package/templates/checked-fetch.js +9 -3
  201. package/templates/d1-beta-facade.js +95 -25
  202. package/templates/facade.d.ts +14 -0
  203. package/templates/first-party-worker-module-facade.ts +4 -3
  204. package/templates/format-dev-errors.ts +8 -6
  205. package/templates/gitignore +1 -0
  206. package/templates/init-tests/test-jest-new-worker.js +3 -5
  207. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  208. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  209. package/templates/middleware/loader-modules.ts +2 -2
  210. package/templates/middleware/loader-sw.ts +51 -31
  211. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  212. package/templates/new-worker.ts +3 -0
  213. package/templates/pages-dev-pipeline.ts +4 -1
  214. package/templates/pages-shim.ts +4 -1
  215. package/templates/pages-template-plugin.ts +19 -10
  216. package/templates/serve-static-assets.ts +17 -14
  217. package/templates/service-bindings-module-facade.js +1 -0
  218. package/templates/tsconfig-sanity.ts +11 -0
  219. package/templates/tsconfig.init.json +105 -0
  220. package/templates/tsconfig.json +5 -103
  221. package/templates/tsconfig.tsbuildinfo +1 -0
  222. package/wrangler-dist/cli.d.ts +826 -77
  223. package/wrangler-dist/cli.js +130734 -140838
  224. package/wrangler-dist/wasm-sync.wasm +0 -0
  225. package/src/__tests__/api-devregistry.test.js +0 -57
  226. package/src/__tests__/d1.test.ts +0 -72
  227. package/src/__tests__/dialogs.test.tsx +0 -40
  228. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  229. package/src/__tests__/pages.test.ts +0 -2223
  230. package/src/dialogs.tsx +0 -163
  231. package/src/environment-variables.ts +0 -50
  232. package/src/pages/build.tsx +0 -238
  233. package/src/user/env-vars.ts +0 -46
  234. package/templates/experimental-local-cache-stubs.js +0 -27
  235. /package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  236. /package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  237. /package/src/pages/{hash.tsx → hash.ts} +0 -0
@@ -1,310 +1,16 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
1
  import { DeprecationError } from "../errors";
4
- import { cloneIntoDirectory, initializeGit } from "../git-client";
5
- import {
6
- CommandLineArgsError,
7
- createCLIParser,
8
- printWranglerBanner,
9
- } from "../index";
10
- import { initHandler } from "../init";
2
+ import { createCLIParser } from "../index";
11
3
  import { logger } from "../logger";
12
4
  import { formatMessage } from "../parse";
13
5
  import type {
14
- CommonYargsOptions,
15
- YargsOptionsToInterface,
6
+ CommonYargsArgv,
7
+ StrictYargsOptionsToInterface,
16
8
  } from "../yargs-types";
17
- import type { Argv, ArgumentsCamelCase, BuilderCallback } from "yargs";
18
9
 
19
- // https://github.com/cloudflare/wrangler/blob/master/src/cli/mod.rs#L106-L123
20
- interface GenerateArgs {
21
- name?: string;
22
- template?: string;
23
- type?: string;
24
- site?: boolean;
25
- }
26
-
27
- export function generateOptions(yargs: Argv<CommonYargsOptions>) {
28
- return yargs
29
- .positional("name", {
30
- describe: "Name of the Workers project",
31
- type: "string",
32
- })
33
- .positional("template", {
34
- type: "string",
35
- describe: "The URL of a GitHub template",
36
- })
37
- .option("type", {
38
- alias: "t",
39
- type: "string",
40
- hidden: true,
41
- deprecated: true,
42
- })
43
- .option("site", {
44
- alias: "s",
45
- type: "boolean",
46
- hidden: true,
47
- deprecated: true,
48
- });
49
- }
50
-
51
- export async function generateHandler({
52
- // somehow, `init` marks name as required but then also runs fine
53
- // with the name omitted, and then substitutes it at runtime with ""
54
- name = "",
55
- template,
56
- type,
57
- site,
58
- ...args
59
- }: ArgumentsCamelCase<GenerateArgs>) {
60
- // delegate to `wrangler init` if no template is specified
61
- if (template === undefined) {
62
- return initHandler({ name, ...args });
63
- }
64
-
65
- // print down here cuz `init` prints it own its own
66
- await printWranglerBanner();
67
-
68
- if (type) {
69
- let message = "The --type option is no longer supported.";
70
- if (args.type === "webpack") {
71
- message +=
72
- "\nIf you wish to use webpack then you will need to create a custom build.";
73
- // TODO: Add a link to docs
74
- }
75
- throw new CommandLineArgsError(message);
76
- }
77
-
78
- if (isRemote(name)) {
79
- [template, name] = [name, template];
80
- }
81
-
82
- const creationDirectory = generateWorkerDirectoryName(name);
83
-
84
- if (site) {
85
- const gitDirectory =
86
- creationDirectory !== process.cwd()
87
- ? path.basename(creationDirectory)
88
- : "my-site";
89
- const message =
90
- "The --site option is no longer supported.\n" +
91
- "If you wish to create a brand new Worker Sites project then clone the `worker-sites-template` starter repository:\n\n" +
92
- "```\n" +
93
- `git clone --depth=1 --branch=wrangler2 https://github.com/cloudflare/worker-sites-template ${gitDirectory}\n` +
94
- `cd ${gitDirectory}\n` +
95
- "```\n\n" +
96
- "Find out more about how to create and maintain Sites projects at https://developers.cloudflare.com/workers/platform/sites.\n" +
97
- "Have you considered using Cloudflare Pages instead? See https://pages.cloudflare.com/.";
98
- throw new CommandLineArgsError(message);
99
- }
100
-
101
- logger.log(
102
- `Creating a worker in ${path.basename(creationDirectory)} from ${template}`
103
- );
104
-
105
- const { remote, subdirectory } = parseTemplatePath(template);
106
-
107
- await cloneIntoDirectory(remote, creationDirectory, subdirectory);
108
- await initializeGit(creationDirectory);
109
-
110
- logger.log("✨ Success!");
111
- }
112
-
113
- /**
114
- * Creates a path based on the current working directory and a worker name.
115
- * Automatically increments a counter when searching for an available directory.
116
- *
117
- * Running `wrangler generate worker https://some-git-repo` in a directory
118
- * with the structure:
119
- * ```
120
- * - workers
121
- * |
122
- * | - worker
123
- * | | - wrangler.toml
124
- * | | ...
125
- * |
126
- * | - worker-1
127
- * | | - wrangler.toml
128
- * | | ...
129
- * ```
130
- *
131
- * will result in a new worker called `worker-2` being generated.
132
- *
133
- * @param workerName the name of the generated worker
134
- * @returns an absolute path to the directory to generate the worker into
135
- */
136
- function generateWorkerDirectoryName(workerName: string): string {
137
- let workerDirectoryPath = path.resolve(process.cwd(), workerName);
138
- let i = 1;
139
-
140
- while (fs.existsSync(workerDirectoryPath)) {
141
- workerDirectoryPath = path.resolve(process.cwd(), `${workerName}-${i}`);
142
- i++;
143
- }
144
-
145
- return workerDirectoryPath;
146
- }
147
-
148
- /**
149
- * Checks if an arg is a template, which can be useful if the order
150
- * of template & worker name args is switched
151
- *
152
- * @param arg a template to generate from, or a folder to generate into
153
- * @returns true if the given arg was remote (a template)
154
- */
155
- function isRemote(arg: string) {
156
- return /^(https?|ftps?|file|git|ssh):\/\//.test(arg) || arg.includes(":");
157
- }
158
-
159
- /**
160
- * unreadable regex basically copied from degit. i put some named capture groups in,
161
- * but uhh...there's not much to do short of using pomsky or some other tool.
162
- *
163
- * notably: this only supports `https://` and `git@` urls,
164
- * and is missing support for:
165
- * - `http`
166
- * - `ftp(s)`
167
- * - `file`
168
- * - `ssh`
169
- */
170
- const TEMPLATE_REGEX =
171
- /^(?:(?:https:\/\/)?(?<httpsUrl>[^:/]+\.[^:/]+)\/|git@(?<gitUrl>[^:/]+)[:/]|(?<shorthandUrl>[^/]+):)?(?<user>[^/\s]+)\/(?<repository>[^/\s#]+)(?:(?<subdirectoryPath>(?:\/[^/\s#]+)+))?(?:\/)?(?:#(?<tag>.+))?/;
172
-
173
- // there are a few URL formats we support:
174
- // - `user/repo` -> assume github, use "https://github.com/user/repo.git"
175
- // - `https://<httpsUrl>
176
- // - `git@<gitUrl>`
177
- // - `(bb|bitbucket|gh|github|gl|gitlab):user/repo` -> parse shorthand into https url
178
-
179
- /**
180
- * There's no URL, so assume a github repo
181
- */
182
- type NoUrl = {
183
- httpsUrl: undefined;
184
- gitUrl: undefined;
185
- shorthandUrl: undefined;
186
- };
187
-
188
- /**
189
- * A https url (e.g. https://bitbucket.org/user/repo)
190
- */
191
- type HttpsUrl = Omit<NoUrl, "httpsUrl"> & { httpsUrl: string };
192
-
193
- /**
194
- * A git url (e.g. git@gitlab.com:user/repo)
195
- */
196
- type GitUrl = Omit<NoUrl, "gitUrl"> & { gitUrl: string };
197
-
198
- /**
199
- * A shorthand url (e.g. github:user/repo)
200
- */
201
- type ShorthandUrl = Omit<NoUrl, "shorthandUrl"> & { shorthandUrl: string };
202
-
203
- /**
204
- * Union of all possible URL groups. Exactly one will be present, the rest
205
- * will be `undefined`.
206
- */
207
- type TemplateRegexUrlGroup = NoUrl | HttpsUrl | GitUrl | ShorthandUrl;
208
-
209
- /**
210
- * Possible matches of `TEMPLATE_REGEX` against a passed-in template arg
211
- */
212
- type TemplateRegexGroups = {
213
- /** The user the repo is under */
214
- user: string;
215
-
216
- /** The repo name */
217
- repository: string;
218
-
219
- /** Optional, path to subdirectory containing template. Begins with `/` */
220
- subdirectoryPath?: string;
221
-
222
- /** Optional tag (or branch, etc.) to clone */
223
- tag?: string;
224
- } & TemplateRegexUrlGroup;
225
-
226
- /**
227
- * Parses a regex match on any of the URL groups into a URL base
228
- *
229
- * @param urlGroup a regex hit for a URL of any sort
230
- * @returns the protocol and domain name of the url to clone from
231
- */
232
- function toUrlBase({ httpsUrl, gitUrl, shorthandUrl }: TemplateRegexUrlGroup) {
233
- if (httpsUrl !== undefined) {
234
- return `https://${httpsUrl}`;
235
- }
236
-
237
- if (gitUrl !== undefined) {
238
- return `git@${gitUrl}`;
239
- }
240
-
241
- if (shorthandUrl !== undefined) {
242
- switch (shorthandUrl) {
243
- case "github":
244
- case "gh":
245
- return "https://github.com";
246
- case "gitlab":
247
- case "gl":
248
- return "https://gitlab.com";
249
- case "bitbucket":
250
- case "bb":
251
- return "https://bitbucket.org";
252
- default:
253
- throw new Error(
254
- `Unable to parse shorthand ${shorthandUrl}. Supported options are "bitbucket" ("bb"), "github" ("gh"), and "gitlab" ("gl")`
255
- );
256
- }
257
- }
258
-
259
- return "https://github.com";
260
- }
261
-
262
- /**
263
- * Parses a template string (e.g. "user/repo", "github:user/repo/path/to/subdirectory")
264
- * into a remote URL to clone from and an optional subdirectory to filter for
265
- *
266
- * @param templatePath the template string to parse
267
- * @returns an object containing the remote url and an optional subdirectory to clone
268
- */
269
- function parseTemplatePath(templatePath: string): {
270
- remote: string;
271
- subdirectory?: string;
272
- } {
273
- if (!templatePath.includes("/")) {
274
- // template is a cloudflare canonical template, it doesn't include a slash in the name
275
- return {
276
- remote: "https://github.com/cloudflare/templates.git",
277
- subdirectory: templatePath,
278
- };
279
- }
280
-
281
- const groups = TEMPLATE_REGEX.exec(templatePath)?.groups as unknown as
282
- | TemplateRegexGroups
283
- | undefined;
284
-
285
- if (!groups) {
286
- throw new Error(`Unable to parse ${templatePath} as a template`);
287
- }
288
-
289
- const { user, repository, subdirectoryPath, tag, ...urlGroups } = groups;
290
-
291
- const urlBase = toUrlBase(urlGroups);
292
- const isHttp = urlBase.startsWith("http");
293
-
294
- const remote = `${urlBase}${isHttp ? "/" : ":"}${user}/${repository}.git${
295
- tag ? `#${tag}` : ""
296
- }`;
297
-
298
- // remove starting /
299
- const subdirectory = subdirectoryPath?.slice(1);
300
-
301
- return { remote, subdirectory };
302
- }
303
-
304
- export function buildOptions(yargs: Argv<CommonYargsOptions>) {
10
+ export function buildOptions(yargs: CommonYargsArgv) {
305
11
  return yargs;
306
12
  }
307
- type BuildArgs = YargsOptionsToInterface<typeof buildOptions>;
13
+ type BuildArgs = StrictYargsOptionsToInterface<typeof buildOptions>;
308
14
  export async function buildHandler(buildArgs: BuildArgs) {
309
15
  // "[DEPRECATED] 🦀 Build your project (if applicable)",
310
16
 
@@ -340,7 +46,7 @@ export const configHandler = () => {
340
46
  );
341
47
  };
342
48
 
343
- export function previewOptions(yargs: Argv<CommonYargsOptions>) {
49
+ export function previewOptions(yargs: CommonYargsArgv) {
344
50
  return yargs
345
51
  .positional("method", {
346
52
  type: "string",
@@ -364,7 +70,7 @@ export function previewHandler() {
364
70
  );
365
71
  }
366
72
 
367
- export const route: BuilderCallback<unknown, unknown> = (routeYargs: Argv) => {
73
+ export const route = (routeYargs: CommonYargsArgv) => {
368
74
  return routeYargs
369
75
  .command(
370
76
  "list",
@@ -427,7 +133,7 @@ export const routeHandler = () => {
427
133
  throw new DeprecationError(`${deprecationNotice}\n${shouldDo}`);
428
134
  };
429
135
 
430
- export const subdomainOptions = (yargs: Argv<CommonYargsOptions>) => {
136
+ export const subdomainOptions = (yargs: CommonYargsArgv) => {
431
137
  return yargs.positional("name", { type: "string" });
432
138
  };
433
139
 
package/src/dev/dev.tsx CHANGED
@@ -28,7 +28,7 @@ import type { Config } from "../config";
28
28
  import type { Route } from "../config/environment";
29
29
  import type { WorkerRegistry } from "../dev-registry";
30
30
  import type { Entry } from "../entry";
31
- import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli";
31
+ import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli/types";
32
32
  import type { AssetPaths } from "../sites";
33
33
  import type { CfWorkerInit } from "../worker";
34
34
 
@@ -55,7 +55,7 @@ function useDevRegistry(
55
55
 
56
56
  const interval =
57
57
  // TODO: enable this for remote mode as well
58
- // https://github.com/cloudflare/wrangler2/issues/1182
58
+ // https://github.com/cloudflare/workers-sdk/issues/1182
59
59
  mode === "local"
60
60
  ? setInterval(() => {
61
61
  getBoundRegisteredWorkers({
@@ -113,8 +113,8 @@ export type DevProps = {
113
113
  name: string | undefined;
114
114
  noBundle: boolean;
115
115
  entry: Entry;
116
- port: number;
117
- ip: string;
116
+ initialPort: number;
117
+ initialIp: string;
118
118
  inspectorPort: number;
119
119
  rules: Config["rules"];
120
120
  accountId: string | undefined;
@@ -138,7 +138,8 @@ export type DevProps = {
138
138
  compatibilityFlags: string[] | undefined;
139
139
  usageModel: "bundled" | "unbound" | undefined;
140
140
  minify: boolean | undefined;
141
- nodeCompat: boolean | undefined;
141
+ legacyNodeCompat: boolean | undefined;
142
+ nodejsCompat: boolean | undefined;
142
143
  build: Config["build"];
143
144
  env: string | undefined;
144
145
  legacyEnv: boolean;
@@ -146,7 +147,6 @@ export type DevProps = {
146
147
  host: string | undefined;
147
148
  routes: Route[] | undefined;
148
149
  inspect: boolean;
149
- logPrefix?: string;
150
150
  onReady: ((ip: string, port: number) => void) | undefined;
151
151
  showInteractiveDevSession: boolean | undefined;
152
152
  forceLocal: boolean | undefined;
@@ -155,6 +155,7 @@ export type DevProps = {
155
155
  sendMetrics: boolean | undefined;
156
156
  testScheduled: boolean | undefined;
157
157
  experimentalLocal: boolean | undefined;
158
+ experimentalLocalRemoteKv: boolean | undefined;
158
159
  };
159
160
 
160
161
  export function DevImplementation(props: DevProps): JSX.Element {
@@ -170,25 +171,42 @@ export function DevImplementation(props: DevProps): JSX.Element {
170
171
  );
171
172
  }
172
173
 
174
+ // This is a nasty hack to allow `useHotkeys` and its "[b] open a browser" feature to read these values
175
+ // without triggering a re-render loop when `onReady()` updates them.
176
+ // The initially requested port can be different than what's actually used, if, for example, you request port 0.
177
+ let ip: string;
178
+ let port: number;
179
+
173
180
  function InteractiveDevSession(props: DevProps) {
174
181
  const toggles = useHotkeys({
175
182
  initial: {
176
183
  local: props.initialMode === "local",
177
184
  tunnel: false,
178
185
  },
179
- port: props.port,
180
- ip: props.ip,
181
186
  inspectorPort: props.inspectorPort,
182
187
  inspect: props.inspect,
183
188
  localProtocol: props.localProtocol,
184
189
  forceLocal: props.forceLocal,
185
190
  });
186
191
 
192
+ ip = props.initialIp;
193
+ port = props.initialPort;
194
+
187
195
  useTunnel(toggles.tunnel);
188
196
 
197
+ const onReady = (newIp: string, newPort: number) => {
198
+ if (newIp !== props.initialIp || newPort !== props.initialPort) {
199
+ ip = newIp;
200
+ port = newPort;
201
+ if (props.onReady) {
202
+ props.onReady(newIp, newPort);
203
+ }
204
+ }
205
+ };
206
+
189
207
  return (
190
208
  <>
191
- <DevSession {...props} local={toggles.local} />
209
+ <DevSession {...props} local={toggles.local} onReady={onReady} />
192
210
  <Box borderStyle="round" paddingLeft={1} paddingRight={1}>
193
211
  <Text bold={true}>[b]</Text>
194
212
  <Text> open a browser, </Text>
@@ -231,20 +249,6 @@ function DevSession(props: DevSessionProps) {
231
249
  () => props.bindings.d1_databases?.map((db) => db.binding),
232
250
  [props.bindings.d1_databases]
233
251
  );
234
- const everyD1BindingHasPreview = props.bindings.d1_databases?.every(
235
- (binding) => binding.preview_database_id
236
- );
237
- if (
238
- betaD1Shims &&
239
- betaD1Shims.length > 0 &&
240
- !(props.local || everyD1BindingHasPreview)
241
- ) {
242
- handleError(
243
- new Error(
244
- "D1 bindings require dev --local or preview_database_id for now"
245
- )
246
- );
247
- }
248
252
 
249
253
  // If we are using d1 bindings, and are not bundling the worker
250
254
  // we should error here as the d1 shim won't be added
@@ -274,7 +278,8 @@ function DevSession(props: DevSessionProps) {
274
278
  ),
275
279
  tsconfig: props.tsconfig,
276
280
  minify: props.minify,
277
- nodeCompat: props.nodeCompat,
281
+ legacyNodeCompat: props.legacyNodeCompat,
282
+ nodejsCompat: props.nodejsCompat,
278
283
  betaD1Shims,
279
284
  define: props.define,
280
285
  noBundle: props.noBundle,
@@ -287,7 +292,7 @@ function DevSession(props: DevSessionProps) {
287
292
  // Enable the bundling to know whether we are using dev or publish
288
293
  targetConsumer: "dev",
289
294
  testScheduled: props.testScheduled ?? false,
290
- experimentalLocalStubCache: props.local && props.experimentalLocal,
295
+ experimentalLocal: props.experimentalLocal,
291
296
  });
292
297
 
293
298
  // TODO(queues) support remote wrangler dev
@@ -300,6 +305,22 @@ function DevSession(props: DevSessionProps) {
300
305
  );
301
306
  }
302
307
 
308
+ const announceAndOnReady: typeof props.onReady = (finalIp, finalPort) => {
309
+ if (process.send) {
310
+ process.send(
311
+ JSON.stringify({
312
+ event: "DEV_SERVER_READY",
313
+ ip: finalIp,
314
+ port: finalPort,
315
+ })
316
+ );
317
+ }
318
+
319
+ if (props.onReady) {
320
+ props.onReady(finalIp, finalPort);
321
+ }
322
+ };
323
+
303
324
  return props.local ? (
304
325
  <Local
305
326
  name={props.name}
@@ -311,8 +332,8 @@ function DevSession(props: DevSessionProps) {
311
332
  bindings={props.bindings}
312
333
  workerDefinitions={workerDefinitions}
313
334
  assetPaths={props.assetPaths}
314
- port={props.port}
315
- ip={props.ip}
335
+ initialPort={props.initialPort}
336
+ initialIp={props.initialIp}
316
337
  rules={props.rules}
317
338
  inspectorPort={props.inspectorPort}
318
339
  localPersistencePath={props.localPersistencePath}
@@ -321,11 +342,12 @@ function DevSession(props: DevSessionProps) {
321
342
  queueConsumers={props.queueConsumers}
322
343
  localProtocol={props.localProtocol}
323
344
  localUpstream={props.localUpstream}
324
- logPrefix={props.logPrefix}
325
345
  inspect={props.inspect}
326
- onReady={props.onReady}
346
+ onReady={announceAndOnReady}
327
347
  enablePagesAssetsServiceBinding={props.enablePagesAssetsServiceBinding}
328
348
  experimentalLocal={props.experimentalLocal}
349
+ accountId={props.accountId}
350
+ experimentalLocalRemoteKv={props.experimentalLocalRemoteKv}
329
351
  />
330
352
  ) : (
331
353
  <Remote
@@ -336,8 +358,8 @@ function DevSession(props: DevSessionProps) {
336
358
  bindings={props.bindings}
337
359
  assetPaths={props.assetPaths}
338
360
  isWorkersSite={props.isWorkersSite}
339
- port={props.port}
340
- ip={props.ip}
361
+ port={props.initialPort}
362
+ ip={props.initialIp}
341
363
  localProtocol={props.localProtocol}
342
364
  inspectorPort={props.inspectorPort}
343
365
  // TODO: @threepointone #1167
@@ -351,7 +373,7 @@ function DevSession(props: DevSessionProps) {
351
373
  zone={props.zone}
352
374
  host={props.host}
353
375
  routes={props.routes}
354
- onReady={props.onReady}
376
+ onReady={announceAndOnReady}
355
377
  sourceMapPath={bundle?.sourceMapPath}
356
378
  sendMetrics={props.sendMetrics}
357
379
  />
@@ -405,7 +427,7 @@ function useCustomBuild(expectedEntry: Entry, build: Config["build"]): void {
405
427
  }
406
428
 
407
429
  return () => {
408
- watcher?.close();
430
+ void watcher?.close();
409
431
  };
410
432
  }, [build, expectedEntry]);
411
433
  }
@@ -500,25 +522,16 @@ type useHotkeysInitialState = {
500
522
  };
501
523
  function useHotkeys(props: {
502
524
  initial: useHotkeysInitialState;
503
- port: number;
504
- ip: string;
505
525
  inspectorPort: number;
506
526
  inspect: boolean;
507
527
  localProtocol: "http" | "https";
508
528
  forceLocal: boolean | undefined;
509
529
  }) {
510
- const {
511
- initial,
512
- port,
513
- ip,
514
- inspectorPort,
515
- inspect,
516
- localProtocol,
517
- forceLocal,
518
- } = props;
530
+ const { initial, inspectorPort, inspect, localProtocol, forceLocal } = props;
519
531
  // UGH, we should put port in context instead
520
532
  const [toggles, setToggles] = useState(initial);
521
533
  const { exit } = useApp();
534
+
522
535
  useInput(
523
536
  async (
524
537
  input,