wrangler 2.4.3 → 2.5.0

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.
@@ -112,8 +112,8 @@ export async function startDevServer(
112
112
  compatibilityFlags: props.compatibilityFlags,
113
113
  bindings: props.bindings,
114
114
  assetPaths: props.assetPaths,
115
- port: props.port,
116
- ip: props.ip,
115
+ initialPort: props.initialPort,
116
+ initialIp: props.initialIp,
117
117
  rules: props.rules,
118
118
  inspectorPort: props.inspectorPort,
119
119
  localPersistencePath: props.localPersistencePath,
@@ -149,8 +149,8 @@ export async function startDevServer(
149
149
  bindings: props.bindings,
150
150
  assetPaths: props.assetPaths,
151
151
  isWorkersSite: props.isWorkersSite,
152
- port: props.port,
153
- ip: props.ip,
152
+ port: props.initialPort,
153
+ ip: props.initialIp,
154
154
  localProtocol: props.localProtocol,
155
155
  inspectorPort: props.inspectorPort,
156
156
  inspect: props.inspect,
@@ -294,12 +294,12 @@ export async function startLocalServer({
294
294
  bindings,
295
295
  workerDefinitions,
296
296
  assetPaths,
297
- port,
297
+ initialPort,
298
298
  inspectorPort,
299
299
  rules,
300
300
  localPersistencePath,
301
301
  liveReload,
302
- ip,
302
+ initialIp,
303
303
  crons,
304
304
  queueConsumers,
305
305
  localProtocol,
@@ -325,14 +325,11 @@ export async function startLocalServer({
325
325
  if (!bundle || !format) return;
326
326
 
327
327
  // port for the worker
328
-
329
- if (port !== 0) {
330
- await waitForPortToBeAvailable(port, {
331
- retryPeriod: 200,
332
- timeout: 2000,
333
- abortSignal: abortController.signal,
334
- });
335
- }
328
+ await waitForPortToBeAvailable(initialPort, {
329
+ retryPeriod: 200,
330
+ timeout: 2000,
331
+ abortSignal: abortController.signal,
332
+ });
336
333
 
337
334
  if (bindings.services && bindings.services.length > 0) {
338
335
  logger.warn(
@@ -373,10 +370,10 @@ export async function startLocalServer({
373
370
 
374
371
  const { forkOptions, miniflareCLIPath, options } = setupMiniflareOptions({
375
372
  workerName,
376
- port,
373
+ port: initialPort,
377
374
  scriptPath,
378
375
  localProtocol,
379
- ip,
376
+ ip: initialIp,
380
377
  format,
381
378
  rules,
382
379
  compatibilityDate,
@@ -429,7 +426,11 @@ export async function startLocalServer({
429
426
  return;
430
427
  }
431
428
 
432
- const nodeOptions = setupNodeOptions({ inspect, ip, inspectorPort });
429
+ const nodeOptions = setupNodeOptions({
430
+ inspect,
431
+ ip: initialIp,
432
+ inspectorPort,
433
+ });
433
434
  logger.log("⎔ Starting a local server...");
434
435
 
435
436
  const child = (local = fork(miniflareCLIPath, forkOptions, {
@@ -446,21 +447,21 @@ export async function startLocalServer({
446
447
  await registerWorker(workerName, {
447
448
  protocol: localProtocol,
448
449
  mode: "local",
449
- port: message.mfPort,
450
- host: ip,
450
+ port: message.port,
451
+ host: initialIp,
451
452
  durableObjects: internalDurableObjects.map((binding) => ({
452
453
  name: binding.name,
453
454
  className: binding.class_name,
454
455
  })),
455
456
  ...(message.durableObjectsPort
456
457
  ? {
457
- durableObjectsHost: ip,
458
+ durableObjectsHost: initialIp,
458
459
  durableObjectsPort: message.durableObjectsPort,
459
460
  }
460
461
  : {}),
461
462
  });
462
463
  }
463
- onReady?.(ip, message.mfPort);
464
+ onReady?.(initialIp, message.port);
464
465
  }
465
466
  });
466
467
 
package/src/dev.tsx CHANGED
@@ -467,11 +467,13 @@ export async function startDev(args: StartDevOptions) {
467
467
  accountId={configParam.account_id || getAccountFromCache()?.id}
468
468
  assetPaths={assetPaths}
469
469
  assetsConfig={configParam.assets}
470
- port={args.port || configParam.dev.port || (await getLocalPort())}
471
- ip={args.ip || configParam.dev.ip}
470
+ initialPort={
471
+ args.port ?? configParam.dev.port ?? (await getLocalPort())
472
+ }
473
+ initialIp={args.ip || configParam.dev.ip}
472
474
  inspectorPort={
473
- args.inspectorPort ||
474
- configParam.dev.inspector_port ||
475
+ args.inspectorPort ??
476
+ configParam.dev.inspector_port ??
475
477
  (await getInspectorPort())
476
478
  }
477
479
  isWorkersSite={Boolean(args.site || configParam.site)}
@@ -584,14 +586,11 @@ export async function startApiDev(args: StartDevOptions) {
584
586
  assetPaths: assetPaths,
585
587
  assetsConfig: configParam.assets,
586
588
  //port can be 0, which means to use a random port
587
- port:
588
- args.port === 0
589
- ? args.port
590
- : args.port || configParam.dev.port || (await getLocalPort()),
591
- ip: args.ip || configParam.dev.ip,
589
+ initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()),
590
+ initialIp: args.ip || configParam.dev.ip,
592
591
  inspectorPort:
593
- args["inspector-port"] ||
594
- configParam.dev.inspector_port ||
592
+ args["inspector-port"] ??
593
+ configParam.dev.inspector_port ??
595
594
  (await getInspectorPort()),
596
595
  isWorkersSite: Boolean(args.site || configParam.site),
597
596
  compatibilityDate: getDevCompatibilityDate(
@@ -3,11 +3,11 @@ import { join } from "node:path";
3
3
  import { createMetadataObject } from "@cloudflare/pages-shared/metadata-generator/createMetadataObject";
4
4
  import { parseHeaders } from "@cloudflare/pages-shared/metadata-generator/parseHeaders";
5
5
  import { parseRedirects } from "@cloudflare/pages-shared/metadata-generator/parseRedirects";
6
- import { fetch as miniflareFetch } from "@miniflare/core";
7
6
  import {
8
7
  Response as MiniflareResponse,
9
8
  Request as MiniflareRequest,
10
9
  } from "@miniflare/core";
10
+ import { upgradingFetch as miniflareFetch } from "@miniflare/web-sockets";
11
11
  import { watch } from "chokidar";
12
12
  import { getType } from "mime";
13
13
  import { hashFile } from "../pages/hash";
@@ -40,7 +40,12 @@ export default async function generateASSETSBinding(options: Options) {
40
40
  try {
41
41
  const url = new URL(miniflareRequest.url);
42
42
  url.host = `localhost:${options.proxyPort}`;
43
- return await miniflareFetch(url, miniflareRequest);
43
+ const proxyRequest = new MiniflareRequest(url, miniflareRequest);
44
+ if (proxyRequest.headers.get("Upgrade") === "websocket") {
45
+ proxyRequest.headers.delete("Sec-WebSocket-Accept");
46
+ proxyRequest.headers.delete("Sec-WebSocket-Key");
47
+ }
48
+ return await miniflareFetch(proxyRequest);
44
49
  } catch (thrown) {
45
50
  options.log.error(new Error(`Could not proxy request: ${thrown}`));
46
51
 
@@ -196,7 +196,7 @@ async function main() {
196
196
  process.send &&
197
197
  process.send(
198
198
  JSON.stringify({
199
- mfPort: mfPort,
199
+ port: mfPort,
200
200
  ready: true,
201
201
  durableObjectsPort: durableObjectsMfPort,
202
202
  })
package/src/pages/dev.tsx CHANGED
@@ -293,7 +293,6 @@ export const Handler = async ({
293
293
  buildOutputDirectory: directory,
294
294
  nodeCompat,
295
295
  local: true,
296
- d1Databases: d1s.map((binding) => binding.toString()),
297
296
  });
298
297
  await metrics.sendMetricsEvent("build pages functions");
299
298
 
@@ -312,7 +311,6 @@ export const Handler = async ({
312
311
  buildOutputDirectory: directory,
313
312
  nodeCompat,
314
313
  local: true,
315
- d1Databases: d1s.map((binding) => binding.toString()),
316
314
  });
317
315
  await metrics.sendMetricsEvent("build pages functions");
318
316
  } catch (e) {
package/src/proxy.ts CHANGED
@@ -651,6 +651,11 @@ export async function waitForPortToBeAvailable(
651
651
  }
652
652
 
653
653
  function checkPort() {
654
+ if (port === 0) {
655
+ doResolve();
656
+ return;
657
+ }
658
+
654
659
  // Testing whether a port is 'available' involves simply
655
660
  // trying to make a server listen on that port, and retrying
656
661
  // until it succeeds.