wrangler 0.0.0-e8e684c7 → 0.0.0-e9106dfa5

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 (207) hide show
  1. package/README.md +35 -49
  2. package/bin/wrangler.js +25 -100
  3. package/config-schema.json +2277 -0
  4. package/package.json +182 -174
  5. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  6. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  7. package/templates/__tests__/tsconfig.json +8 -0
  8. package/templates/checked-fetch.js +19 -6
  9. package/templates/facade.d.ts +19 -0
  10. package/templates/gitignore +2 -3
  11. package/templates/init-tests/test-jest-new-worker.js +23 -0
  12. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  13. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  14. package/templates/middleware/common.ts +67 -0
  15. package/templates/middleware/loader-modules.ts +134 -0
  16. package/templates/middleware/loader-sw.ts +229 -0
  17. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  18. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  19. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  20. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  21. package/templates/middleware/middleware-patch-console-prefix.d.ts +3 -0
  22. package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
  23. package/templates/middleware/middleware-pretty-error.ts +40 -0
  24. package/templates/middleware/middleware-scheduled.ts +29 -0
  25. package/templates/modules-watch-stub.js +4 -0
  26. package/templates/new-worker-scheduled.ts +1 -1
  27. package/templates/new-worker.js +1 -1
  28. package/templates/new-worker.ts +4 -1
  29. package/templates/pages-dev-pipeline.ts +33 -0
  30. package/templates/pages-dev-util.ts +55 -0
  31. package/templates/pages-shim.ts +1 -1
  32. package/templates/pages-template-plugin.ts +37 -14
  33. package/templates/pages-template-worker.ts +33 -7
  34. package/templates/startDevWorker/InspectorProxyWorker.ts +679 -0
  35. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  36. package/templates/tsconfig-sanity.ts +11 -0
  37. package/templates/tsconfig.init.json +22 -0
  38. package/templates/tsconfig.json +12 -102
  39. package/templates/tsconfig.tsbuildinfo +1 -0
  40. package/wrangler-dist/InspectorProxyWorker.js +471 -0
  41. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  42. package/wrangler-dist/ProxyWorker.js +238 -0
  43. package/wrangler-dist/ProxyWorker.js.map +6 -0
  44. package/wrangler-dist/cli.d.ts +26527 -172
  45. package/wrangler-dist/cli.js +148646 -148093
  46. package/Cloudflare_CA.pem +0 -18
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/miniflare-dist/index.mjs +0 -5542
  52. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  53. package/src/__tests__/config-cache.test.ts +0 -42
  54. package/src/__tests__/configuration.test.ts +0 -4026
  55. package/src/__tests__/dev.test.tsx +0 -1318
  56. package/src/__tests__/generate.test.ts +0 -91
  57. package/src/__tests__/guess-worker-format.test.ts +0 -85
  58. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  59. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  60. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  61. package/src/__tests__/helpers/mock-bin.ts +0 -36
  62. package/src/__tests__/helpers/mock-cfetch.ts +0 -296
  63. package/src/__tests__/helpers/mock-console.ts +0 -97
  64. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  65. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -8
  66. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  67. package/src/__tests__/helpers/mock-istty.ts +0 -74
  68. package/src/__tests__/helpers/mock-known-routes.ts +0 -7
  69. package/src/__tests__/helpers/mock-kv.ts +0 -33
  70. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -250
  71. package/src/__tests__/helpers/mock-process.ts +0 -39
  72. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  73. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  74. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  75. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  76. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  77. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  78. package/src/__tests__/https-options.test.ts +0 -163
  79. package/src/__tests__/index.test.ts +0 -245
  80. package/src/__tests__/init.test.ts +0 -2170
  81. package/src/__tests__/jest.setup.ts +0 -157
  82. package/src/__tests__/kv.test.ts +0 -1671
  83. package/src/__tests__/logger.test.ts +0 -141
  84. package/src/__tests__/metrics.test.ts +0 -450
  85. package/src/__tests__/package-manager.test.ts +0 -353
  86. package/src/__tests__/pages.test.ts +0 -1275
  87. package/src/__tests__/parse.test.ts +0 -330
  88. package/src/__tests__/publish.test.ts +0 -6955
  89. package/src/__tests__/pubsub.test.ts +0 -367
  90. package/src/__tests__/r2.test.ts +0 -336
  91. package/src/__tests__/route.test.ts +0 -45
  92. package/src/__tests__/secret.test.ts +0 -492
  93. package/src/__tests__/tail.test.ts +0 -802
  94. package/src/__tests__/test-old-node-version.js +0 -31
  95. package/src/__tests__/user.test.ts +0 -155
  96. package/src/__tests__/validate-dev-props.test.ts +0 -56
  97. package/src/__tests__/version.test.ts +0 -35
  98. package/src/__tests__/whoami.test.tsx +0 -289
  99. package/src/__tests__/worker-namespace.test.ts +0 -329
  100. package/src/abort.d.ts +0 -3
  101. package/src/api/dev.ts +0 -93
  102. package/src/api/index.ts +0 -1
  103. package/src/bundle-reporter.tsx +0 -29
  104. package/src/bundle.ts +0 -473
  105. package/src/cfetch/index.ts +0 -121
  106. package/src/cfetch/internal.ts +0 -298
  107. package/src/cli.ts +0 -27
  108. package/src/config/README.md +0 -107
  109. package/src/config/config.ts +0 -263
  110. package/src/config/diagnostics.ts +0 -80
  111. package/src/config/environment.ts +0 -485
  112. package/src/config/index.ts +0 -251
  113. package/src/config/validation-helpers.ts +0 -597
  114. package/src/config/validation.ts +0 -1862
  115. package/src/config-cache.ts +0 -85
  116. package/src/create-worker-preview.ts +0 -257
  117. package/src/create-worker-upload-form.ts +0 -291
  118. package/src/dev/dev-vars.ts +0 -36
  119. package/src/dev/dev.tsx +0 -545
  120. package/src/dev/local.tsx +0 -449
  121. package/src/dev/remote.tsx +0 -422
  122. package/src/dev/use-esbuild.ts +0 -178
  123. package/src/dev/validate-dev-props.ts +0 -31
  124. package/src/dev-registry.tsx +0 -160
  125. package/src/dev.tsx +0 -696
  126. package/src/dialogs.tsx +0 -135
  127. package/src/dispatch-namespace.ts +0 -206
  128. package/src/durable.ts +0 -102
  129. package/src/entry.ts +0 -328
  130. package/src/environment-variables.ts +0 -35
  131. package/src/errors.ts +0 -11
  132. package/src/faye-websocket.d.ts +0 -6
  133. package/src/generate.ts +0 -131
  134. package/src/git-client.ts +0 -42
  135. package/src/global-wrangler-config-path.ts +0 -26
  136. package/src/https-options.ts +0 -127
  137. package/src/index.tsx +0 -2260
  138. package/src/init.ts +0 -622
  139. package/src/inspect.ts +0 -747
  140. package/src/intl-polyfill.d.ts +0 -139
  141. package/src/is-ci.ts +0 -14
  142. package/src/is-interactive.ts +0 -12
  143. package/src/kv.ts +0 -430
  144. package/src/logger.ts +0 -73
  145. package/src/metrics/index.ts +0 -5
  146. package/src/metrics/metrics-config.ts +0 -239
  147. package/src/metrics/metrics-dispatcher.ts +0 -96
  148. package/src/metrics/metrics-usage-headers.ts +0 -24
  149. package/src/metrics/send-event.ts +0 -92
  150. package/src/miniflare-cli/README.md +0 -30
  151. package/src/miniflare-cli/assets.ts +0 -554
  152. package/src/miniflare-cli/enum-keys.ts +0 -17
  153. package/src/miniflare-cli/index.ts +0 -207
  154. package/src/miniflare-cli/request-context.ts +0 -40
  155. package/src/module-collection.ts +0 -258
  156. package/src/open-in-browser.ts +0 -17
  157. package/src/package-manager.ts +0 -219
  158. package/src/pages/build.tsx +0 -238
  159. package/src/pages/constants.ts +0 -12
  160. package/src/pages/deployments.tsx +0 -106
  161. package/src/pages/dev.tsx +0 -528
  162. package/src/pages/errors.ts +0 -22
  163. package/src/pages/functions/buildPlugin.ts +0 -109
  164. package/src/pages/functions/buildWorker.ts +0 -155
  165. package/src/pages/functions/filepath-routing.test.ts +0 -234
  166. package/src/pages/functions/filepath-routing.ts +0 -189
  167. package/src/pages/functions/identifiers.ts +0 -78
  168. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  169. package/src/pages/functions/routes-consolidation.ts +0 -73
  170. package/src/pages/functions/routes-transformation.test.ts +0 -271
  171. package/src/pages/functions/routes-transformation.ts +0 -122
  172. package/src/pages/functions/routes.ts +0 -151
  173. package/src/pages/functions.tsx +0 -96
  174. package/src/pages/index.tsx +0 -94
  175. package/src/pages/projects.tsx +0 -169
  176. package/src/pages/publish.tsx +0 -391
  177. package/src/pages/types.ts +0 -49
  178. package/src/pages/upload.tsx +0 -413
  179. package/src/pages/utils.ts +0 -12
  180. package/src/parse.ts +0 -286
  181. package/src/paths.ts +0 -26
  182. package/src/preview.ts +0 -31
  183. package/src/proxy.ts +0 -486
  184. package/src/publish.ts +0 -822
  185. package/src/pubsub/index.ts +0 -286
  186. package/src/pubsub/pubsub-commands.tsx +0 -623
  187. package/src/r2.ts +0 -131
  188. package/src/selfsigned.d.ts +0 -29
  189. package/src/sites.tsx +0 -372
  190. package/src/tail/filters.ts +0 -281
  191. package/src/tail/index.ts +0 -312
  192. package/src/tail/printing.ts +0 -107
  193. package/src/update-check.ts +0 -19
  194. package/src/user/choose-account.tsx +0 -69
  195. package/src/user/env-vars.ts +0 -46
  196. package/src/user/generate-auth-url.ts +0 -33
  197. package/src/user/generate-random-state.ts +0 -16
  198. package/src/user/index.ts +0 -3
  199. package/src/user/user.tsx +0 -1191
  200. package/src/whoami.tsx +0 -169
  201. package/src/worker.ts +0 -204
  202. package/src/zones.ts +0 -167
  203. package/templates/first-party-worker-module-facade.ts +0 -18
  204. package/templates/format-dev-errors.ts +0 -32
  205. package/templates/serve-static-assets.ts +0 -63
  206. package/templates/service-bindings-module-facade.js +0 -54
  207. package/templates/service-bindings-sw-facade.js +0 -42
package/src/dev/local.tsx DELETED
@@ -1,449 +0,0 @@
1
- import { fork } from "node:child_process";
2
- import { realpathSync } from "node:fs";
3
- import { writeFile } from "node:fs/promises";
4
- import path from "node:path";
5
- import { useState, useEffect, useRef } from "react";
6
- import onExit from "signal-exit";
7
- import { registerWorker } from "../dev-registry";
8
- import useInspector from "../inspect";
9
- import { logger } from "../logger";
10
- import { DEFAULT_MODULE_RULES } from "../module-collection";
11
- import { waitForPortToBeAvailable } from "../proxy";
12
- import type { Config } from "../config";
13
- import type { WorkerRegistry } from "../dev-registry";
14
- import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli";
15
- import type { AssetPaths } from "../sites";
16
- import type { CfWorkerInit, CfScriptFormat } from "../worker";
17
- import type { EsbuildBundle } from "./use-esbuild";
18
- import type { MiniflareOptions } from "miniflare";
19
- import type { ChildProcess } from "node:child_process";
20
- interface LocalProps {
21
- name: string | undefined;
22
- bundle: EsbuildBundle | undefined;
23
- format: CfScriptFormat | undefined;
24
- compatibilityDate: string;
25
- compatibilityFlags: string[] | undefined;
26
- usageModel: "bundled" | "unbound" | undefined;
27
- bindings: CfWorkerInit["bindings"];
28
- workerDefinitions: WorkerRegistry;
29
- assetPaths: AssetPaths | undefined;
30
- port: number;
31
- ip: string;
32
- rules: Config["rules"];
33
- inspectorPort: number;
34
- enableLocalPersistence: boolean;
35
- liveReload: boolean;
36
- crons: Config["triggers"]["crons"];
37
- localProtocol: "http" | "https";
38
- localUpstream: string | undefined;
39
- inspect: boolean;
40
- onReady: (() => void) | undefined;
41
- logLevel: "none" | "error" | "log" | "warn" | "debug" | undefined;
42
- logPrefix?: string;
43
- enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
44
- }
45
-
46
- export function Local(props: LocalProps) {
47
- const { inspectorUrl } = useLocalWorker(props);
48
- useInspector({
49
- inspectorUrl,
50
- port: props.inspectorPort,
51
- logToTerminal: false,
52
- });
53
- return null;
54
- }
55
-
56
- function useLocalWorker({
57
- name: workerName,
58
- bundle,
59
- format,
60
- compatibilityDate,
61
- compatibilityFlags,
62
- usageModel,
63
- bindings,
64
- workerDefinitions,
65
- assetPaths,
66
- port,
67
- inspectorPort,
68
- rules,
69
- enableLocalPersistence,
70
- liveReload,
71
- ip,
72
- crons,
73
- localProtocol,
74
- localUpstream,
75
- inspect,
76
- onReady,
77
- logLevel,
78
- logPrefix,
79
- enablePagesAssetsServiceBinding,
80
- }: LocalProps) {
81
- // TODO: pass vars via command line
82
- const local = useRef<ChildProcess>();
83
- const removeSignalExitListener = useRef<() => void>();
84
- const [inspectorUrl, setInspectorUrl] = useState<string | undefined>();
85
- // if we're using local persistence for data, we should use the cwd
86
- // as an explicit path, or else it'll use the temp dir
87
- // which disappears when dev ends
88
- const localPersistencePath = enableLocalPersistence
89
- ? // Maybe we could make the path configurable as well?
90
- path.join(process.cwd(), "wrangler-local-state")
91
- : // We otherwise choose null, but choose true later
92
- // so that it's persisted in the temp dir across a dev session
93
- // even when we change source and reload
94
- null;
95
-
96
- useEffect(() => {
97
- if (bindings.services && bindings.services.length > 0) {
98
- logger.warn(
99
- "⎔ Support for service bindings in local mode is experimental and may change."
100
- );
101
- }
102
- }, [bindings.services]);
103
-
104
- useEffect(() => {
105
- const externalDurableObjects = (
106
- bindings.durable_objects?.bindings || []
107
- ).filter((binding) => binding.script_name);
108
-
109
- if (externalDurableObjects.length > 0) {
110
- logger.warn(
111
- "⎔ Support for external Durable Objects in local mode is experimental and may change."
112
- );
113
- }
114
- }, [bindings.durable_objects?.bindings]);
115
-
116
- useEffect(() => {
117
- const abortController = new AbortController();
118
- async function startLocalWorker() {
119
- if (!bundle || !format) return;
120
-
121
- // port for the worker
122
- await waitForPortToBeAvailable(port, {
123
- retryPeriod: 200,
124
- timeout: 2000,
125
- abortSignal: abortController.signal,
126
- });
127
-
128
- // In local mode, we want to copy all referenced modules into
129
- // the output bundle directory before starting up
130
- for (const module of bundle.modules) {
131
- await writeFile(
132
- path.join(path.dirname(bundle.path), module.name),
133
- module.content
134
- );
135
- }
136
-
137
- const scriptPath = realpathSync(bundle.path);
138
-
139
- // the wasm_modules/text_blobs/data_blobs bindings are
140
- // relative to process.cwd(), but the actual worker bundle
141
- // is in the temp output directory; so we rewrite the paths to be absolute,
142
- // letting miniflare resolve them correctly
143
-
144
- // wasm
145
- const wasmBindings: Record<string, string> = {};
146
- for (const [name, filePath] of Object.entries(
147
- bindings.wasm_modules || {}
148
- )) {
149
- wasmBindings[name] = path.join(process.cwd(), filePath);
150
- }
151
-
152
- // text
153
- const textBlobBindings: Record<string, string> = {};
154
- for (const [name, filePath] of Object.entries(
155
- bindings.text_blobs || {}
156
- )) {
157
- textBlobBindings[name] = path.join(process.cwd(), filePath);
158
- }
159
-
160
- // data
161
- const dataBlobBindings: Record<string, string> = {};
162
- for (const [name, filePath] of Object.entries(
163
- bindings.data_blobs || {}
164
- )) {
165
- dataBlobBindings[name] = path.join(process.cwd(), filePath);
166
- }
167
-
168
- if (format === "service-worker") {
169
- for (const { type, name } of bundle.modules) {
170
- if (type === "compiled-wasm") {
171
- // In service-worker format, .wasm modules are referenced by global identifiers,
172
- // so we convert it here.
173
- // This identifier has to be a valid JS identifier, so we replace all non alphanumeric
174
- // characters with an underscore.
175
- const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
176
- wasmBindings[identifier] = name;
177
- } else if (type === "text") {
178
- // In service-worker format, text modules are referenced by global identifiers,
179
- // so we convert it here.
180
- // This identifier has to be a valid JS identifier, so we replace all non alphanumeric
181
- // characters with an underscore.
182
- const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
183
- textBlobBindings[identifier] = name;
184
- } else if (type === "buffer") {
185
- // In service-worker format, data blobs are referenced by global identifiers,
186
- // so we convert it here.
187
- // This identifier has to be a valid JS identifier, so we replace all non alphanumeric
188
- // characters with an underscore.
189
- const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
190
- dataBlobBindings[identifier] = name;
191
- }
192
- }
193
- }
194
-
195
- const upstream =
196
- typeof localUpstream === "string"
197
- ? `${localProtocol}://${localUpstream}`
198
- : undefined;
199
-
200
- const internalDurableObjects = (
201
- bindings.durable_objects?.bindings || []
202
- ).filter((binding) => !binding.script_name);
203
- const externalDurableObjects = (
204
- bindings.durable_objects?.bindings || []
205
- ).filter((binding) => binding.script_name);
206
-
207
- // TODO: This was already messy with the custom `disableLogs` and `logOptions`.
208
- // It's now getting _really_ messy now with Pages ASSETS binding outside and the external Durable Objects inside.
209
- const options: MiniflareOptions = {
210
- name: workerName,
211
- port,
212
- scriptPath,
213
- https: localProtocol === "https",
214
- host: ip,
215
- modules: format === "modules",
216
- modulesRules: (rules || [])
217
- .concat(DEFAULT_MODULE_RULES)
218
- .map(({ type, globs: include, fallthrough }) => ({
219
- type,
220
- include,
221
- fallthrough,
222
- })),
223
- compatibilityDate,
224
- compatibilityFlags,
225
- usageModel,
226
- kvNamespaces: bindings.kv_namespaces?.map((kv) => kv.binding),
227
- r2Buckets: bindings.r2_buckets?.map((r2) => r2.binding),
228
- durableObjects: Object.fromEntries(
229
- internalDurableObjects.map((binding) => [
230
- binding.name,
231
- binding.class_name,
232
- ])
233
- ),
234
- externalDurableObjects: Object.fromEntries(
235
- externalDurableObjects
236
- .map((binding) => {
237
- const service = workerDefinitions[binding.script_name as string];
238
- if (!service) return [binding.name, undefined];
239
-
240
- const name = service.durableObjects.find(
241
- (durableObject) =>
242
- durableObject.className === binding.class_name
243
- )?.name;
244
- if (!name) return [binding.name, undefined];
245
-
246
- return [
247
- binding.name,
248
- {
249
- name,
250
- host: service.durableObjectsHost,
251
- port: service.durableObjectsPort,
252
- },
253
- ];
254
- })
255
- .filter(([_, details]) => !!details)
256
- ),
257
- ...(localPersistencePath
258
- ? {
259
- cachePersist: path.join(localPersistencePath, "cache"),
260
- durableObjectsPersist: path.join(localPersistencePath, "do"),
261
- kvPersist: path.join(localPersistencePath, "kv"),
262
- r2Persist: path.join(localPersistencePath, "r2"),
263
- }
264
- : {
265
- // We mark these as true, so that they'll
266
- // persist in the temp directory.
267
- // This means they'll persist across a dev session,
268
- // even if we change source and reload,
269
- // and be deleted when the dev session ends
270
- cachePersist: true,
271
- durableObjectsPersist: true,
272
- kvPersist: true,
273
- r2Persist: true,
274
- }),
275
-
276
- liveReload,
277
- sitePath: assetPaths?.assetDirectory
278
- ? path.join(assetPaths.baseDirectory, assetPaths.assetDirectory)
279
- : undefined,
280
- siteInclude: assetPaths?.includePatterns.length
281
- ? assetPaths?.includePatterns
282
- : undefined,
283
- siteExclude: assetPaths?.excludePatterns.length
284
- ? assetPaths.excludePatterns
285
- : undefined,
286
- bindings: bindings.vars,
287
- wasmBindings,
288
- textBlobBindings,
289
- dataBlobBindings,
290
- sourceMap: true,
291
- logUnhandledRejections: true,
292
- crons,
293
- upstream,
294
- disableLogs: logLevel === "none",
295
- logOptions: logPrefix ? { prefix: logPrefix } : undefined,
296
- };
297
-
298
- // The path to the Miniflare CLI assumes that this file is being run from
299
- // `wrangler-dist` and that the CLI is found in `miniflare-dist`.
300
- // If either of those paths change this line needs updating.
301
- const miniflareCLIPath = path.resolve(
302
- __dirname,
303
- "../miniflare-dist/index.mjs"
304
- );
305
- const miniflareOptions = JSON.stringify(options, null);
306
-
307
- logger.log("⎔ Starting a local server...");
308
- const nodeOptions = [
309
- "--experimental-vm-modules", // ensures that Miniflare can run ESM Workers
310
- "--no-warnings", // hide annoying Node warnings
311
- // "--log=VERBOSE", // uncomment this to Miniflare to log "everything"!
312
- ];
313
- if (inspect) {
314
- nodeOptions.push("--inspect=" + `${ip}:${inspectorPort}`); // start Miniflare listening for a debugger to attach
315
- }
316
-
317
- const forkOptions = [miniflareOptions];
318
-
319
- if (enablePagesAssetsServiceBinding) {
320
- forkOptions.push(JSON.stringify(enablePagesAssetsServiceBinding));
321
- }
322
-
323
- const child = (local.current = fork(miniflareCLIPath, forkOptions, {
324
- cwd: path.dirname(scriptPath),
325
- execArgv: nodeOptions,
326
- stdio: "pipe",
327
- }));
328
-
329
- child.on("message", async (messageString) => {
330
- const message = JSON.parse(messageString as string);
331
- if (message.ready) {
332
- // Let's register our presence in the dev registry
333
- if (workerName) {
334
- await registerWorker(workerName, {
335
- protocol: localProtocol,
336
- mode: "local",
337
- port,
338
- host: ip,
339
- durableObjects: internalDurableObjects.map((binding) => ({
340
- name: binding.name,
341
- className: binding.class_name,
342
- })),
343
- ...(message.durableObjectsPort
344
- ? {
345
- durableObjectsHost: ip,
346
- durableObjectsPort: message.durableObjectsPort,
347
- }
348
- : {}),
349
- });
350
- }
351
- onReady?.();
352
- }
353
- });
354
-
355
- child.on("close", (code) => {
356
- if (code) {
357
- logger.log(`Miniflare process exited with code ${code}`);
358
- }
359
- });
360
-
361
- child.stdout?.on("data", (data: Buffer) => {
362
- process.stdout.write(data);
363
- });
364
-
365
- // parse the node inspector url (which may be received in chunks) from stderr
366
- let stderrData = "";
367
- let inspectorUrlFound = false;
368
- child.stderr?.on("data", (data: Buffer) => {
369
- if (!inspectorUrlFound) {
370
- stderrData += data.toString();
371
- const matches =
372
- /Debugger listening on (ws:\/\/127\.0\.0\.1:\d+\/[A-Za-z0-9-]+)[\r|\n]/.exec(
373
- stderrData
374
- );
375
- if (matches) {
376
- inspectorUrlFound = true;
377
- setInspectorUrl(matches[1]);
378
- }
379
- }
380
-
381
- process.stderr.write(data);
382
- });
383
-
384
- child.on("exit", (code) => {
385
- if (code) {
386
- logger.error(`Miniflare process exited with code ${code}`);
387
- }
388
- });
389
-
390
- child.on("error", (error: Error) => {
391
- logger.error(`Miniflare process failed to spawn`);
392
- logger.error(error);
393
- });
394
-
395
- removeSignalExitListener.current = onExit((_code, _signal) => {
396
- logger.log("⎔ Shutting down local server.");
397
- child.kill();
398
- local.current = undefined;
399
- });
400
- }
401
-
402
- startLocalWorker().catch((err) => {
403
- logger.error("local worker:", err);
404
- });
405
-
406
- return () => {
407
- abortController.abort();
408
- if (local.current) {
409
- logger.log("⎔ Shutting down local server.");
410
- local.current?.kill();
411
- local.current = undefined;
412
- removeSignalExitListener.current && removeSignalExitListener.current();
413
- removeSignalExitListener.current = undefined;
414
- }
415
- };
416
- }, [
417
- bundle,
418
- workerName,
419
- format,
420
- port,
421
- inspectorPort,
422
- ip,
423
- bindings.durable_objects?.bindings,
424
- bindings.kv_namespaces,
425
- bindings.r2_buckets,
426
- bindings.vars,
427
- bindings.services,
428
- workerDefinitions,
429
- compatibilityDate,
430
- compatibilityFlags,
431
- usageModel,
432
- localPersistencePath,
433
- liveReload,
434
- assetPaths,
435
- rules,
436
- bindings.wasm_modules,
437
- bindings.text_blobs,
438
- bindings.data_blobs,
439
- crons,
440
- localProtocol,
441
- localUpstream,
442
- inspect,
443
- logLevel,
444
- logPrefix,
445
- onReady,
446
- enablePagesAssetsServiceBinding,
447
- ]);
448
- return { inspectorUrl };
449
- }