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
@@ -1,6 +1,5 @@
1
1
  import { fork } from "node:child_process";
2
2
  import { realpathSync } from "node:fs";
3
- import { writeFile } from "node:fs/promises";
4
3
  import * as path from "node:path";
5
4
  import * as util from "node:util";
6
5
  import onExit from "signal-exit";
@@ -15,6 +14,7 @@ import {
15
14
  import { runCustomBuild } from "../entry";
16
15
  import { logger } from "../logger";
17
16
  import { waitForPortToBeAvailable } from "../proxy";
17
+ import traverseModuleGraph from "../traverse-module-graph";
18
18
  import {
19
19
  setupBindings,
20
20
  getMiniflare3,
@@ -27,6 +27,7 @@ import { startRemoteServer } from "./remote";
27
27
  import { validateDevProps } from "./validate-dev-props";
28
28
 
29
29
  import type { Config } from "../config";
30
+ import type { DurableObjectBindings } from "../config/environment";
30
31
  import type { WorkerRegistry } from "../dev-registry";
31
32
  import type { Entry } from "../entry";
32
33
  import type { DevProps, DirectorySyncResult } from "./dev";
@@ -39,6 +40,7 @@ import type { ChildProcess } from "node:child_process";
39
40
  export async function startDevServer(
40
41
  props: DevProps & {
41
42
  local: boolean;
43
+ disableDevRegistry: boolean;
42
44
  }
43
45
  ) {
44
46
  try {
@@ -62,17 +64,24 @@ export async function startDevServer(
62
64
  }
63
65
 
64
66
  //start the worker registry
65
- startWorkerRegistry().catch((err) => {
66
- logger.error("failed to start worker registry", err);
67
- });
68
- if (props.local) {
69
- const boundRegisteredWorkers = await getBoundRegisteredWorkers({
70
- services: props.bindings.services,
71
- durableObjects: props.bindings.durable_objects,
72
- });
67
+ logger.log("disableDevRegistry: ", props.disableDevRegistry);
68
+ if (!props.disableDevRegistry) {
69
+ try {
70
+ await startWorkerRegistry();
71
+ if (props.local) {
72
+ const boundRegisteredWorkers = await getBoundRegisteredWorkers({
73
+ services: props.bindings.services,
74
+ durableObjects: props.bindings.durable_objects,
75
+ });
73
76
 
74
- if (!util.isDeepStrictEqual(boundRegisteredWorkers, workerDefinitions)) {
75
- workerDefinitions = boundRegisteredWorkers || {};
77
+ if (
78
+ !util.isDeepStrictEqual(boundRegisteredWorkers, workerDefinitions)
79
+ ) {
80
+ workerDefinitions = boundRegisteredWorkers || {};
81
+ }
82
+ }
83
+ } catch (err) {
84
+ logger.error("failed to start worker registry", err);
76
85
  }
77
86
  }
78
87
 
@@ -83,6 +92,7 @@ export async function startDevServer(
83
92
  entry: props.entry,
84
93
  destination: directory.name,
85
94
  jsxFactory: props.jsxFactory,
95
+ processEntrypoint: props.processEntrypoint,
86
96
  rules: props.rules,
87
97
  jsxFragment: props.jsxFragment,
88
98
  serveAssetsFromWorker: Boolean(
@@ -90,7 +100,8 @@ export async function startDevServer(
90
100
  ),
91
101
  tsconfig: props.tsconfig,
92
102
  minify: props.minify,
93
- nodeCompat: props.nodeCompat,
103
+ legacyNodeCompat: props.legacyNodeCompat,
104
+ nodejsCompat: props.nodejsCompat,
94
105
  define: props.define,
95
106
  noBundle: props.noBundle,
96
107
  assets: props.assetsConfig,
@@ -101,6 +112,7 @@ export async function startDevServer(
101
112
  testScheduled: props.testScheduled,
102
113
  local: props.local,
103
114
  experimentalLocal: props.experimentalLocal,
115
+ doBindings: props.bindings.durable_objects?.bindings ?? [],
104
116
  });
105
117
 
106
118
  if (props.local) {
@@ -122,7 +134,6 @@ export async function startDevServer(
122
134
  queueConsumers: props.queueConsumers,
123
135
  localProtocol: props.localProtocol,
124
136
  localUpstream: props.localUpstream,
125
- logPrefix: props.logPrefix,
126
137
  inspect: props.inspect,
127
138
  onReady: props.onReady,
128
139
  enablePagesAssetsServiceBinding: props.enablePagesAssetsServiceBinding,
@@ -131,6 +142,7 @@ export async function startDevServer(
131
142
  experimentalLocal: props.experimentalLocal,
132
143
  accountId: props.accountId,
133
144
  experimentalLocalRemoteKv: props.experimentalLocalRemoteKv,
145
+ sourceMapPath: bundle?.sourceMapPath,
134
146
  });
135
147
 
136
148
  return {
@@ -195,13 +207,15 @@ async function runEsbuild({
195
207
  destination,
196
208
  jsxFactory,
197
209
  jsxFragment,
210
+ processEntrypoint,
198
211
  rules,
199
212
  assets,
200
213
  betaD1Shims,
201
214
  serveAssetsFromWorker,
202
215
  tsconfig,
203
216
  minify,
204
- nodeCompat,
217
+ legacyNodeCompat,
218
+ nodejsCompat,
205
219
  define,
206
220
  noBundle,
207
221
  workerDefinitions,
@@ -210,11 +224,13 @@ async function runEsbuild({
210
224
  testScheduled,
211
225
  local,
212
226
  experimentalLocal,
227
+ doBindings,
213
228
  }: {
214
229
  entry: Entry;
215
230
  destination: string | undefined;
216
231
  jsxFactory: string | undefined;
217
232
  jsxFragment: string | undefined;
233
+ processEntrypoint: boolean;
218
234
  rules: Config["rules"];
219
235
  assets: Config["assets"];
220
236
  betaD1Shims?: string[];
@@ -223,64 +239,68 @@ async function runEsbuild({
223
239
  serveAssetsFromWorker: boolean;
224
240
  tsconfig: string | undefined;
225
241
  minify: boolean | undefined;
226
- nodeCompat: boolean | undefined;
242
+ legacyNodeCompat: boolean | undefined;
243
+ nodejsCompat: boolean | undefined;
227
244
  noBundle: boolean;
228
245
  workerDefinitions: WorkerRegistry;
229
246
  firstPartyWorkerDevFacade: boolean | undefined;
230
247
  testScheduled?: boolean;
231
248
  local: boolean;
232
249
  experimentalLocal: boolean | undefined;
250
+ doBindings: DurableObjectBindings;
233
251
  }): Promise<EsbuildBundle | undefined> {
234
252
  if (!destination) return;
235
253
 
236
- const {
237
- resolvedEntryPointPath,
238
- bundleType,
239
- modules,
240
- dependencies,
241
- sourceMapPath,
242
- }: Awaited<ReturnType<typeof bundleWorker>> = noBundle
243
- ? {
244
- modules: [],
245
- dependencies: {},
246
- resolvedEntryPointPath: entry.file,
247
- bundleType: entry.format === "modules" ? "esm" : "commonjs",
248
- stop: undefined,
249
- sourceMapPath: undefined,
250
- }
251
- : await bundleWorker(entry, destination, {
252
- serveAssetsFromWorker,
253
- jsxFactory,
254
- jsxFragment,
255
- rules,
256
- tsconfig,
257
- minify,
258
- nodeCompat,
259
- define,
260
- checkFetch: true,
261
- assets: assets && {
262
- ...assets,
263
- // disable the cache in dev
264
- bypassCache: true,
265
- },
266
- betaD1Shims,
267
- workerDefinitions,
268
- services,
269
- firstPartyWorkerDevFacade,
270
- targetConsumer: "dev", // We are starting a dev server
271
- testScheduled,
272
- local,
273
- experimentalLocal,
274
- });
254
+ let traverseModuleGraphResult:
255
+ | Awaited<ReturnType<typeof bundleWorker>>
256
+ | undefined;
257
+ let bundleResult: Awaited<ReturnType<typeof bundleWorker>> | undefined;
258
+ if (noBundle) {
259
+ traverseModuleGraphResult = await traverseModuleGraph(entry, rules);
260
+ }
261
+
262
+ if (processEntrypoint || !noBundle) {
263
+ bundleResult = await bundleWorker(entry, destination, {
264
+ bundle: !noBundle,
265
+ disableModuleCollection: noBundle,
266
+ serveAssetsFromWorker,
267
+ jsxFactory,
268
+ jsxFragment,
269
+ rules,
270
+ tsconfig,
271
+ minify,
272
+ legacyNodeCompat,
273
+ nodejsCompat,
274
+ define,
275
+ checkFetch: true,
276
+ assets: assets && {
277
+ ...assets,
278
+ // disable the cache in dev
279
+ bypassCache: true,
280
+ },
281
+ betaD1Shims,
282
+ workerDefinitions,
283
+ services,
284
+ firstPartyWorkerDevFacade,
285
+ targetConsumer: "dev", // We are starting a dev server
286
+ testScheduled,
287
+ local,
288
+ experimentalLocal,
289
+ doBindings,
290
+ });
291
+ }
275
292
 
276
293
  return {
277
294
  id: 0,
278
295
  entry,
279
- path: resolvedEntryPointPath,
280
- type: bundleType,
281
- modules,
282
- dependencies,
283
- sourceMapPath,
296
+ path: bundleResult?.resolvedEntryPointPath ?? entry.file,
297
+ type:
298
+ bundleResult?.bundleType ??
299
+ (entry.format === "modules" ? "esm" : "commonjs"),
300
+ modules: traverseModuleGraphResult?.modules ?? bundleResult?.modules ?? [],
301
+ dependencies: bundleResult?.dependencies ?? {},
302
+ sourceMapPath: bundleResult?.sourceMapPath,
303
+ sourceMapMetadata: bundleResult?.sourceMapMetadata,
284
304
  };
285
305
  }
286
306
 
@@ -306,7 +326,6 @@ export async function startLocalServer({
306
326
  localUpstream,
307
327
  inspect,
308
328
  onReady,
309
- logPrefix,
310
329
  enablePagesAssetsServiceBinding,
311
330
  experimentalLocal,
312
331
  accountId,
@@ -337,15 +356,6 @@ export async function startLocalServer({
337
356
  );
338
357
  }
339
358
 
340
- // In local mode, we want to copy all referenced modules into
341
- // the output bundle directory before starting up
342
- for (const module of bundle.modules) {
343
- await writeFile(
344
- path.join(path.dirname(bundle.path), module.name),
345
- module.content
346
- );
347
- }
348
-
349
359
  const scriptPath = realpathSync(bundle.path);
350
360
 
351
361
  const upstream =
@@ -395,13 +405,12 @@ export async function startLocalServer({
395
405
  dataBlobBindings,
396
406
  crons,
397
407
  upstream,
398
- logPrefix,
399
408
  workerDefinitions,
400
409
  enablePagesAssetsServiceBinding,
401
410
  });
402
411
 
403
412
  if (experimentalLocal) {
404
- const log = await buildMiniflare3Logger(logPrefix);
413
+ const log = await buildMiniflare3Logger();
405
414
  const mf3Options = await transformMf2OptionsToMf3Options({
406
415
  miniflare2Options: options,
407
416
  format,
@@ -409,6 +418,7 @@ export async function startLocalServer({
409
418
  log,
410
419
  kvNamespaces: bindings?.kv_namespaces,
411
420
  r2Buckets: bindings?.r2_buckets,
421
+ d1Databases: bindings?.d1_databases,
412
422
  authenticatedAccountId: accountId,
413
423
  kvRemote: experimentalLocalRemoteKv,
414
424
  inspectorPort,
@@ -419,18 +429,14 @@ export async function startLocalServer({
419
429
  experimentalLocalRef = mf;
420
430
  removeSignalExitListener = onExit((_code, _signal) => {
421
431
  logger.log("⎔ Shutting down experimental local server.");
422
- mf.dispose();
432
+ void mf.dispose();
423
433
  experimentalLocalRef = undefined;
424
434
  });
425
435
  onReady?.(runtimeURL.hostname, parseInt(runtimeURL.port ?? 8787));
426
436
  return;
427
437
  }
428
438
 
429
- const nodeOptions = setupNodeOptions({
430
- inspect,
431
- ip: initialIp,
432
- inspectorPort,
433
- });
439
+ const nodeOptions = setupNodeOptions({ inspect, inspectorPort });
434
440
  logger.log("⎔ Starting a local server...");
435
441
 
436
442
  const child = (local = fork(miniflareCLIPath, forkOptions, {
@@ -4,9 +4,11 @@ import { useApp } from "ink";
4
4
  import { useState, useEffect } from "react";
5
5
  import { bundleWorker, rewriteNodeCompatBuildFailure } from "../bundle";
6
6
  import { logBuildFailure, logger } from "../logger";
7
+ import traverseModuleGraph from "../traverse-module-graph";
7
8
  import type { Config } from "../config";
8
9
  import type { WorkerRegistry } from "../dev-registry";
9
10
  import type { Entry } from "../entry";
11
+ import type { SourceMapMetadata } from "../inspect";
10
12
  import type { CfModule } from "../worker";
11
13
  import type { WatchMode, Metafile } from "esbuild";
12
14
 
@@ -18,6 +20,7 @@ export type EsbuildBundle = {
18
20
  modules: CfModule[];
19
21
  dependencies: Metafile["outputs"][string]["inputs"];
20
22
  sourceMapPath: string | undefined;
23
+ sourceMapMetadata: SourceMapMetadata | undefined;
21
24
  };
22
25
 
23
26
  export function useEsbuild({
@@ -25,12 +28,14 @@ export function useEsbuild({
25
28
  destination,
26
29
  jsxFactory,
27
30
  jsxFragment,
31
+ processEntrypoint,
28
32
  rules,
29
33
  assets,
30
34
  serveAssetsFromWorker,
31
35
  tsconfig,
32
36
  minify,
33
- nodeCompat,
37
+ legacyNodeCompat,
38
+ nodejsCompat,
34
39
  betaD1Shims,
35
40
  define,
36
41
  noBundle,
@@ -47,6 +52,7 @@ export function useEsbuild({
47
52
  destination: string | undefined;
48
53
  jsxFactory: string | undefined;
49
54
  jsxFragment: string | undefined;
55
+ processEntrypoint: boolean;
50
56
  rules: Config["rules"];
51
57
  assets: Config["assets"];
52
58
  define: Config["define"];
@@ -54,7 +60,8 @@ export function useEsbuild({
54
60
  serveAssetsFromWorker: boolean;
55
61
  tsconfig: string | undefined;
56
62
  minify: boolean | undefined;
57
- nodeCompat: boolean | undefined;
63
+ legacyNodeCompat: boolean | undefined;
64
+ nodejsCompat: boolean | undefined;
58
65
  betaD1Shims?: string[];
59
66
  noBundle: boolean;
60
67
  workerDefinitions: WorkerRegistry;
@@ -85,7 +92,7 @@ export function useEsbuild({
85
92
  const watchMode: WatchMode = {
86
93
  async onRebuild(error) {
87
94
  if (error !== null) {
88
- if (!nodeCompat) rewriteNodeCompatBuildFailure(error);
95
+ if (!legacyNodeCompat) rewriteNodeCompatBuildFailure(error);
89
96
  logBuildFailure(error);
90
97
  logger.error("Watch build failed:", error.message);
91
98
  } else {
@@ -97,50 +104,48 @@ export function useEsbuild({
97
104
  async function build() {
98
105
  if (!destination) return;
99
106
 
100
- const {
101
- resolvedEntryPointPath,
102
- bundleType,
103
- modules,
104
- dependencies,
105
- stop,
106
- sourceMapPath,
107
- }: Awaited<ReturnType<typeof bundleWorker>> = noBundle
108
- ? {
109
- modules: [],
110
- dependencies: {},
111
- resolvedEntryPointPath: entry.file,
112
- bundleType: entry.format === "modules" ? "esm" : "commonjs",
113
- stop: undefined,
114
- sourceMapPath: undefined,
115
- }
116
- : await bundleWorker(entry, destination, {
117
- serveAssetsFromWorker,
118
- jsxFactory,
119
- jsxFragment,
120
- rules,
121
- watch: watchMode,
122
- tsconfig,
123
- minify,
124
- nodeCompat,
125
- betaD1Shims,
126
- define,
127
- checkFetch: true,
128
- assets: assets && {
129
- ...assets,
130
- // disable the cache in dev
131
- bypassCache: true,
132
- },
133
- workerDefinitions,
134
- services,
135
- firstPartyWorkerDevFacade,
136
- local,
137
- targetConsumer,
138
- testScheduled,
139
- experimentalLocal,
140
- });
107
+ let traverseModuleGraphResult:
108
+ | Awaited<ReturnType<typeof bundleWorker>>
109
+ | undefined;
110
+ let bundleResult: Awaited<ReturnType<typeof bundleWorker>> | undefined;
111
+ if (noBundle) {
112
+ traverseModuleGraphResult = await traverseModuleGraph(entry, rules);
113
+ }
114
+
115
+ if (processEntrypoint || !noBundle) {
116
+ bundleResult = await bundleWorker(entry, destination, {
117
+ bundle: !noBundle,
118
+ disableModuleCollection: noBundle,
119
+ serveAssetsFromWorker,
120
+ jsxFactory,
121
+ jsxFragment,
122
+ rules,
123
+ watch: watchMode,
124
+ tsconfig,
125
+ minify,
126
+ legacyNodeCompat,
127
+ nodejsCompat,
128
+ betaD1Shims,
129
+ doBindings: durableObjects.bindings,
130
+ define,
131
+ checkFetch: true,
132
+ assets: assets && {
133
+ ...assets,
134
+ // disable the cache in dev
135
+ bypassCache: true,
136
+ },
137
+ workerDefinitions,
138
+ services,
139
+ firstPartyWorkerDevFacade,
140
+ local,
141
+ targetConsumer,
142
+ testScheduled,
143
+ experimentalLocal,
144
+ });
145
+ }
141
146
 
142
147
  // Capture the `stop()` method to use as the `useEffect()` destructor.
143
- stopWatching = stop;
148
+ stopWatching = bundleResult?.stop;
144
149
 
145
150
  // if "noBundle" is true, then we need to manually watch the entry point and
146
151
  // trigger "builds" when it changes
@@ -152,17 +157,21 @@ export function useEsbuild({
152
157
  });
153
158
 
154
159
  stopWatching = () => {
155
- watcher.close();
160
+ void watcher.close();
156
161
  };
157
162
  }
158
163
  setBundle({
159
164
  id: 0,
160
165
  entry,
161
- path: resolvedEntryPointPath,
162
- type: bundleType,
163
- modules,
164
- dependencies,
165
- sourceMapPath,
166
+ path: bundleResult?.resolvedEntryPointPath ?? entry.file,
167
+ type:
168
+ bundleResult?.bundleType ??
169
+ (entry.format === "modules" ? "esm" : "commonjs"),
170
+ modules:
171
+ traverseModuleGraphResult?.modules ?? bundleResult?.modules ?? [],
172
+ dependencies: bundleResult?.dependencies ?? {},
173
+ sourceMapPath: bundleResult?.sourceMapPath,
174
+ sourceMapMetadata: bundleResult?.sourceMapMetadata,
166
175
  });
167
176
  }
168
177
 
@@ -182,12 +191,14 @@ export function useEsbuild({
182
191
  jsxFactory,
183
192
  jsxFragment,
184
193
  serveAssetsFromWorker,
194
+ processEntrypoint,
185
195
  rules,
186
196
  tsconfig,
187
197
  exit,
188
198
  noBundle,
189
199
  minify,
190
- nodeCompat,
200
+ legacyNodeCompat,
201
+ nodejsCompat,
191
202
  define,
192
203
  assets,
193
204
  services,
@@ -28,4 +28,13 @@ export function validateDevProps(props: DevProps) {
28
28
  "You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure `[rules]` in your wrangler.toml"
29
29
  );
30
30
  }
31
+
32
+ if (
33
+ props.compatibilityFlags?.includes("nodejs_compat") &&
34
+ props.legacyNodeCompat
35
+ ) {
36
+ throw new Error(
37
+ "You cannot use the `nodejs_compat` compatibility flag in conjunction with the legacy `--node-compat` flag. If you want to use the new runtime Node.js compatibility features, please remove the `--node-compat` argument from your CLI command or your config file."
38
+ );
39
+ }
31
40
  }
@@ -1,5 +1,5 @@
1
- import http from "http";
2
1
  import net from "net";
2
+ import { createServer } from "node:http";
3
3
  import bodyParser from "body-parser";
4
4
  import express from "express";
5
5
  import { createHttpTerminator } from "http-terminator";
@@ -7,13 +7,13 @@ import { fetch } from "undici";
7
7
  import { logger } from "./logger";
8
8
 
9
9
  import type { Config } from "./config";
10
- import type { Server } from "http";
11
10
  import type { HttpTerminator } from "http-terminator";
11
+ import type { Server } from "node:http";
12
12
 
13
- const DEV_REGISTRY_PORT = "6284";
14
- const DEV_REGISTRY_HOST = `http://localhost:${DEV_REGISTRY_PORT}`;
13
+ const DEV_REGISTRY_PORT = 6284;
14
+ const DEV_REGISTRY_HOST = `http://127.0.0.1:${DEV_REGISTRY_PORT}`;
15
15
 
16
- let server: Server;
16
+ let server: Server | null;
17
17
  let terminator: HttpTerminator;
18
18
 
19
19
  export type WorkerRegistry = Record<string, WorkerDefinition>;
@@ -48,7 +48,7 @@ async function isPortAvailable() {
48
48
  netServer.close();
49
49
  resolve(true);
50
50
  });
51
- netServer.listen(DEV_REGISTRY_PORT);
51
+ netServer.listen(DEV_REGISTRY_PORT, "127.0.0.1");
52
52
  });
53
53
  }
54
54
 
@@ -80,9 +80,9 @@ export async function startWorkerRegistry() {
80
80
  workers = {};
81
81
  res.json(null);
82
82
  });
83
- server = http.createServer(app);
83
+ server = createServer(app);
84
84
  terminator = createHttpTerminator({ server });
85
- server.listen(DEV_REGISTRY_PORT);
85
+ server.listen(DEV_REGISTRY_PORT, "127.0.0.1");
86
86
 
87
87
  /**
88
88
  * The registry server may have already been started by another wrangler process.
@@ -102,6 +102,7 @@ export async function startWorkerRegistry() {
102
102
  */
103
103
  export async function stopWorkerRegistry() {
104
104
  await terminator?.terminate();
105
+ server = null;
105
106
  }
106
107
 
107
108
  /**