wrangler 2.0.24 → 2.0.25

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 (39) hide show
  1. package/miniflare-dist/index.mjs +130 -16
  2. package/package.json +1 -1
  3. package/src/__tests__/configuration.test.ts +1 -1
  4. package/src/__tests__/dev.test.tsx +26 -4
  5. package/src/__tests__/helpers/mock-cfetch.ts +2 -2
  6. package/src/__tests__/r2.test.ts +18 -0
  7. package/src/__tests__/tail.test.ts +93 -39
  8. package/src/api/dev.ts +6 -0
  9. package/src/bundle.ts +3 -2
  10. package/src/config/config.ts +1 -1
  11. package/src/config/validation.ts +1 -1
  12. package/src/dev/dev.tsx +12 -2
  13. package/src/dev/local.tsx +69 -5
  14. package/src/dev/use-esbuild.ts +3 -0
  15. package/src/dev-registry.tsx +3 -0
  16. package/src/dev.tsx +26 -17
  17. package/src/index.tsx +51 -21
  18. package/src/inspect.ts +1 -4
  19. package/src/miniflare-cli/assets.ts +19 -16
  20. package/src/miniflare-cli/index.ts +121 -2
  21. package/src/pages/build.tsx +36 -28
  22. package/src/pages/constants.ts +3 -0
  23. package/src/pages/deployments.tsx +9 -9
  24. package/src/pages/dev.tsx +85 -27
  25. package/src/pages/functions/buildPlugin.ts +4 -0
  26. package/src/pages/functions/buildWorker.ts +4 -0
  27. package/src/pages/functions/routes-consolidation.test.ts +66 -0
  28. package/src/pages/functions/routes-consolidation.ts +29 -0
  29. package/src/pages/functions/routes-transformation.test.ts +271 -0
  30. package/src/pages/functions/routes-transformation.ts +125 -0
  31. package/src/pages/projects.tsx +9 -3
  32. package/src/pages/publish.tsx +56 -14
  33. package/src/pages/types.ts +9 -0
  34. package/src/pages/upload.tsx +6 -8
  35. package/src/r2.ts +13 -0
  36. package/src/tail/index.ts +15 -2
  37. package/src/tail/printing.ts +41 -3
  38. package/wrangler-dist/cli.d.ts +6 -0
  39. package/wrangler-dist/cli.js +385 -89
@@ -129850,7 +129850,7 @@ init_import_meta_url();
129850
129850
 
129851
129851
  // src/dev.tsx
129852
129852
  init_import_meta_url();
129853
- var import_node_path29 = __toESM(require("node:path"));
129853
+ var import_node_path30 = __toESM(require("node:path"));
129854
129854
  var import_chokidar4 = require("chokidar");
129855
129855
 
129856
129856
  // ../../node_modules/get-port/index.js
@@ -131085,7 +131085,7 @@ function normalizeAndValidateMainField(configPath, rawMain, deprecatedUpload) {
131085
131085
  }
131086
131086
  function normalizeAndValidateDev(diagnostics, rawDev) {
131087
131087
  const {
131088
- ip = "localhost",
131088
+ ip = "0.0.0.0",
131089
131089
  port,
131090
131090
  inspector_port,
131091
131091
  local_protocol = "http",
@@ -133987,7 +133987,7 @@ var import_websocket_server = __toESM(require_websocket_server2(), 1);
133987
133987
  var wrapper_default = import_websocket.default;
133988
133988
 
133989
133989
  // package.json
133990
- var version = "2.0.24";
133990
+ var version = "2.0.25";
133991
133991
  var package_default = {
133992
133992
  name: "wrangler",
133993
133993
  version,
@@ -134741,10 +134741,7 @@ function useInspector(props) {
134741
134741
  if (pos && pos.line != null) {
134742
134742
  const convertedFnName = pos.name || functionName || "";
134743
134743
  exceptionLines.push(
134744
- ` at ${convertedFnName} (${pos.source?.replace(
134745
- `${mapContent.sourceRoot}/`,
134746
- ""
134747
- )}:${pos.line}:${pos.column})`
134744
+ ` at ${convertedFnName} (${pos.source}:${pos.line}:${pos.column})`
134748
134745
  );
134749
134746
  }
134750
134747
  }
@@ -135237,7 +135234,9 @@ function useLocalWorker({
135237
135234
  format: format4,
135238
135235
  compatibilityDate,
135239
135236
  compatibilityFlags,
135237
+ usageModel,
135240
135238
  bindings,
135239
+ workerDefinitions,
135241
135240
  assetPaths,
135242
135241
  port,
135243
135242
  inspectorPort,
@@ -135265,6 +135264,14 @@ function useLocalWorker({
135265
135264
  );
135266
135265
  }
135267
135266
  }, [bindings.services]);
135267
+ (0, import_react3.useEffect)(() => {
135268
+ const externalDurableObjects = (bindings.durable_objects?.bindings || []).filter((binding) => binding.script_name);
135269
+ if (externalDurableObjects.length > 0) {
135270
+ logger.warn(
135271
+ "\u2394 Support for external Durable Objects in local mode is experimental and may change."
135272
+ );
135273
+ }
135274
+ }, [bindings.durable_objects?.bindings]);
135268
135275
  (0, import_react3.useEffect)(() => {
135269
135276
  const abortController = new AbortController();
135270
135277
  async function startLocalWorker() {
@@ -135315,6 +135322,8 @@ function useLocalWorker({
135315
135322
  }
135316
135323
  }
135317
135324
  const upstream = typeof localUpstream === "string" ? `${localProtocol}://${localUpstream}` : void 0;
135325
+ const internalDurableObjects = (bindings.durable_objects?.bindings || []).filter((binding) => !binding.script_name);
135326
+ const externalDurableObjects = (bindings.durable_objects?.bindings || []).filter((binding) => binding.script_name);
135318
135327
  const options = {
135319
135328
  name: workerName,
135320
135329
  port,
@@ -135329,12 +135338,34 @@ function useLocalWorker({
135329
135338
  })),
135330
135339
  compatibilityDate,
135331
135340
  compatibilityFlags,
135341
+ usageModel,
135332
135342
  kvNamespaces: bindings.kv_namespaces?.map((kv) => kv.binding),
135333
135343
  r2Buckets: bindings.r2_buckets?.map((r2) => r2.binding),
135334
135344
  durableObjects: Object.fromEntries(
135335
- (bindings.durable_objects?.bindings ?? []).map(
135336
- (value) => [value.name, value.class_name]
135337
- )
135345
+ internalDurableObjects.map((binding) => [
135346
+ binding.name,
135347
+ binding.class_name
135348
+ ])
135349
+ ),
135350
+ externalDurableObjects: Object.fromEntries(
135351
+ externalDurableObjects.map((binding) => {
135352
+ const service = workerDefinitions[binding.script_name];
135353
+ if (!service)
135354
+ return [binding.name, void 0];
135355
+ const name = service.durableObjects.find(
135356
+ (durableObject) => durableObject.className === binding.class_name
135357
+ )?.name;
135358
+ if (!name)
135359
+ return [binding.name, void 0];
135360
+ return [
135361
+ binding.name,
135362
+ {
135363
+ name,
135364
+ host: service.durableObjectsHost,
135365
+ port: service.durableObjectsPort
135366
+ }
135367
+ ];
135368
+ }).filter(([_2, details]) => !!details)
135338
135369
  ),
135339
135370
  ...localPersistencePath ? {
135340
135371
  cachePersist: import_node_path12.default.join(localPersistencePath, "cache"),
@@ -135384,14 +135415,23 @@ function useLocalWorker({
135384
135415
  execArgv: nodeOptions,
135385
135416
  stdio: "pipe"
135386
135417
  });
135387
- child.on("message", async (message) => {
135388
- if (message === "ready") {
135418
+ child.on("message", async (messageString) => {
135419
+ const message = JSON.parse(messageString);
135420
+ if (message.ready) {
135389
135421
  if (workerName) {
135390
135422
  await registerWorker(workerName, {
135391
135423
  protocol: localProtocol,
135392
135424
  mode: "local",
135393
135425
  port,
135394
- host: ip
135426
+ host: ip,
135427
+ durableObjects: internalDurableObjects.map((binding) => ({
135428
+ name: binding.name,
135429
+ className: binding.class_name
135430
+ })),
135431
+ ...message.durableObjectsPort ? {
135432
+ durableObjectsHost: ip,
135433
+ durableObjectsPort: message.durableObjectsPort
135434
+ } : {}
135395
135435
  });
135396
135436
  }
135397
135437
  onReady?.();
@@ -135460,8 +135500,10 @@ function useLocalWorker({
135460
135500
  bindings.r2_buckets,
135461
135501
  bindings.vars,
135462
135502
  bindings.services,
135503
+ workerDefinitions,
135463
135504
  compatibilityDate,
135464
135505
  compatibilityFlags,
135506
+ usageModel,
135465
135507
  localPersistencePath,
135466
135508
  liveReload,
135467
135509
  assetPaths,
@@ -137629,7 +137671,7 @@ async function bundleWorker(entry, destination, options) {
137629
137671
  format: entry.format === "modules" ? "esm" : "iife",
137630
137672
  target: "es2020",
137631
137673
  sourcemap: true,
137632
- sourceRoot: entryDirectory,
137674
+ sourceRoot: destination,
137633
137675
  minify,
137634
137676
  metafile: true,
137635
137677
  conditions: ["worker", "browser"],
@@ -137841,6 +137883,7 @@ function useEsbuild({
137841
137883
  noBundle,
137842
137884
  workerDefinitions,
137843
137885
  services,
137886
+ durableObjects,
137844
137887
  firstPartyWorkerDevFacade
137845
137888
  }) {
137846
137889
  const [bundle, setBundle] = (0, import_react7.useState)();
@@ -137940,6 +137983,7 @@ function useEsbuild({
137940
137983
  define2,
137941
137984
  assets,
137942
137985
  services,
137986
+ durableObjects,
137943
137987
  workerDefinitions,
137944
137988
  firstPartyWorkerDevFacade
137945
137989
  ]);
@@ -137972,7 +138016,7 @@ function validateDevProps(props) {
137972
138016
  }
137973
138017
 
137974
138018
  // src/dev/dev.tsx
137975
- function useDevRegistry(name, services, mode) {
138019
+ function useDevRegistry(name, services, durableObjects, mode) {
137976
138020
  const [workers, setWorkers] = (0, import_react8.useState)({});
137977
138021
  (0, import_react8.useEffect)(() => {
137978
138022
  startWorkerRegistry().catch((err2) => {
@@ -137981,12 +138025,13 @@ function useDevRegistry(name, services, mode) {
137981
138025
  const serviceNames = (services || []).map(
137982
138026
  (serviceBinding) => serviceBinding.service
137983
138027
  );
138028
+ const durableObjectServices = (durableObjects || { bindings: [] }).bindings.map((durableObjectBinding) => durableObjectBinding.script_name);
137984
138029
  const interval2 = mode === "local" ? setInterval(() => {
137985
138030
  getRegisteredWorkers().then(
137986
138031
  (workerDefinitions) => {
137987
138032
  const filteredWorkers = Object.fromEntries(
137988
138033
  Object.entries(workerDefinitions || {}).filter(
137989
- ([key2, _value]) => serviceNames.includes(key2)
138034
+ ([key2, _value]) => serviceNames.includes(key2) || durableObjectServices.includes(key2)
137990
138035
  )
137991
138036
  );
137992
138037
  setWorkers((prevWorkers) => {
@@ -138026,7 +138071,7 @@ function useDevRegistry(name, services, mode) {
138026
138071
  }
138027
138072
  );
138028
138073
  };
138029
- }, [name, services, mode]);
138074
+ }, [name, services, durableObjects, mode]);
138030
138075
  return workers;
138031
138076
  }
138032
138077
  function DevImplementation(props) {
@@ -138078,6 +138123,7 @@ function DevSession(props) {
138078
138123
  const workerDefinitions = useDevRegistry(
138079
138124
  props.name,
138080
138125
  props.bindings.services,
138126
+ props.bindings.durable_objects,
138081
138127
  props.local ? "local" : "remote"
138082
138128
  );
138083
138129
  const bundle = useEsbuild({
@@ -138097,6 +138143,7 @@ function DevSession(props) {
138097
138143
  assets: props.assetsConfig,
138098
138144
  workerDefinitions,
138099
138145
  services: props.bindings.services,
138146
+ durableObjects: props.bindings.durable_objects || { bindings: [] },
138100
138147
  firstPartyWorkerDevFacade: props.firstPartyWorker
138101
138148
  });
138102
138149
  return props.local ? /* @__PURE__ */ import_react8.default.createElement(Local, {
@@ -138105,7 +138152,9 @@ function DevSession(props) {
138105
138152
  format: props.entry.format,
138106
138153
  compatibilityDate: props.compatibilityDate,
138107
138154
  compatibilityFlags: props.compatibilityFlags,
138155
+ usageModel: props.usageModel,
138108
138156
  bindings: props.bindings,
138157
+ workerDefinitions,
138109
138158
  assetPaths: props.assetPaths,
138110
138159
  port: props.port,
138111
138160
  ip: props.ip,
@@ -138678,7 +138727,7 @@ async function getZoneIdFromHost(host) {
138678
138727
  // src/index.tsx
138679
138728
  init_import_meta_url();
138680
138729
  var fs11 = __toESM(require("node:fs"));
138681
- var import_node_path28 = __toESM(require("node:path"));
138730
+ var import_node_path29 = __toESM(require("node:path"));
138682
138731
  var stream = __toESM(require("node:stream"));
138683
138732
  var import_node_string_decoder = require("node:string_decoder");
138684
138733
  var import_promises12 = require("node:timers/promises");
@@ -142708,7 +142757,7 @@ init_import_meta_url();
142708
142757
  init_import_meta_url();
142709
142758
  var import_node_fs10 = require("node:fs");
142710
142759
  var import_node_os8 = require("node:os");
142711
- var import_node_path23 = require("node:path");
142760
+ var import_node_path24 = require("node:path");
142712
142761
 
142713
142762
  // src/paths.ts
142714
142763
  init_import_meta_url();
@@ -142731,6 +142780,8 @@ var MAX_UPLOAD_ATTEMPTS = 5;
142731
142780
  var MAX_CHECK_MISSING_ATTEMPTS = 5;
142732
142781
  var SECONDS_TO_WAIT_FOR_PROXY = 5;
142733
142782
  var isInPagesCI = !!process.env.CF_PAGES;
142783
+ var MAX_FUNCTIONS_ROUTES_RULES = 100;
142784
+ var ROUTES_SPEC_VERSION = 1;
142734
142785
 
142735
142786
  // src/pages/functions/buildPlugin.ts
142736
142787
  init_import_meta_url();
@@ -142755,6 +142806,10 @@ function buildPlugin({
142755
142806
  bundle: true,
142756
142807
  format: "esm",
142757
142808
  target: "esnext",
142809
+ loader: {
142810
+ ".html": "text",
142811
+ ".txt": "text"
142812
+ },
142758
142813
  outfile,
142759
142814
  minify,
142760
142815
  sourcemap,
@@ -142878,6 +142933,10 @@ function buildWorker({
142878
142933
  bundle: true,
142879
142934
  format: "esm",
142880
142935
  target: "esnext",
142936
+ loader: {
142937
+ ".html": "text",
142938
+ ".txt": "text"
142939
+ },
142881
142940
  outfile,
142882
142941
  minify,
142883
142942
  sourcemap,
@@ -143265,6 +143324,85 @@ export const routes = [
143265
143324
  ]`;
143266
143325
  }
143267
143326
 
143327
+ // src/pages/functions/routes-transformation.ts
143328
+ init_import_meta_url();
143329
+ var import_node_path23 = require("node:path");
143330
+
143331
+ // src/pages/functions/routes-consolidation.ts
143332
+ init_import_meta_url();
143333
+ function consolidateRoutes(routes) {
143334
+ const routesMap = /* @__PURE__ */ new Map();
143335
+ for (const route of routes) {
143336
+ routesMap.set(route, true);
143337
+ }
143338
+ for (const route of routes.filter((r) => r.endsWith("/*"))) {
143339
+ if (routesMap.has(route)) {
143340
+ const routeTrimmed = route.substring(0, route.length - 1);
143341
+ for (const nextRoute of routesMap.keys()) {
143342
+ if (nextRoute !== route && nextRoute.startsWith(routeTrimmed)) {
143343
+ routesMap.delete(nextRoute);
143344
+ }
143345
+ }
143346
+ }
143347
+ }
143348
+ return Array.from(routesMap.keys());
143349
+ }
143350
+
143351
+ // src/pages/functions/routes-transformation.ts
143352
+ function convertRoutesToGlobPatterns(routes) {
143353
+ const convertedRoutes = routes.map(({ routePath, middleware }) => {
143354
+ const globbedRoutePath = routePath.replace(/:\w+\*?.*/, "*");
143355
+ if (typeof middleware === "string" || Array.isArray(middleware) && middleware.length > 0) {
143356
+ if (!globbedRoutePath.endsWith("*")) {
143357
+ return toUrlPath((0, import_node_path23.join)(globbedRoutePath, "*"));
143358
+ }
143359
+ }
143360
+ return toUrlPath(globbedRoutePath);
143361
+ });
143362
+ return Array.from(new Set(convertedRoutes));
143363
+ }
143364
+ function convertRoutesToRoutesJSONSpec(routes) {
143365
+ const reversedRoutes = [...routes].reverse();
143366
+ const include = convertRoutesToGlobPatterns(reversedRoutes);
143367
+ return optimizeRoutesJSONSpec({
143368
+ version: ROUTES_SPEC_VERSION,
143369
+ include,
143370
+ exclude: []
143371
+ });
143372
+ }
143373
+ function optimizeRoutesJSONSpec(spec) {
143374
+ const optimizedSpec = { ...spec };
143375
+ let consolidatedRoutes = consolidateRoutes(optimizedSpec.include);
143376
+ if (consolidatedRoutes.length > MAX_FUNCTIONS_ROUTES_RULES) {
143377
+ consolidatedRoutes = ["/*"];
143378
+ }
143379
+ consolidatedRoutes.sort((a, b) => compareRoutes2(b, a));
143380
+ optimizedSpec.include = consolidatedRoutes;
143381
+ return optimizedSpec;
143382
+ }
143383
+ function compareRoutes2(routeA, routeB) {
143384
+ function parseRoutePath(routePath) {
143385
+ return routePath.slice(1).split("/").filter(Boolean);
143386
+ }
143387
+ const segmentsA = parseRoutePath(routeA);
143388
+ const segmentsB = parseRoutePath(routeB);
143389
+ if (segmentsA.length !== segmentsB.length) {
143390
+ return segmentsB.length - segmentsA.length;
143391
+ }
143392
+ for (let i2 = 0; i2 < segmentsA.length; i2++) {
143393
+ const isWildcardA = segmentsA[i2].includes("*");
143394
+ const isWildcardB = segmentsB[i2].includes("*");
143395
+ if (isWildcardA && !isWildcardB)
143396
+ return 1;
143397
+ if (!isWildcardA && isWildcardB)
143398
+ return -1;
143399
+ }
143400
+ return routeA.localeCompare(routeB);
143401
+ }
143402
+ function isRoutesJSONSpec(data) {
143403
+ return typeof data === "object" && data && "version" in data && typeof data.version === "number" && data.version === ROUTES_SPEC_VERSION && Array.isArray(data.include) && Array.isArray(data.exclude) || false;
143404
+ }
143405
+
143268
143406
  // src/pages/utils.ts
143269
143407
  init_import_meta_url();
143270
143408
  var RUNNING_BUILDERS = [];
@@ -143291,6 +143429,10 @@ function Options(yargs) {
143291
143429
  type: "string",
143292
143430
  description: "The location for the output config file"
143293
143431
  },
143432
+ "output-routes-path": {
143433
+ type: "string",
143434
+ description: "The location for the output _routes.json file"
143435
+ },
143294
143436
  minify: {
143295
143437
  type: "boolean",
143296
143438
  default: false,
@@ -143331,14 +143473,15 @@ function Options(yargs) {
143331
143473
  var Handler = async ({
143332
143474
  directory,
143333
143475
  outfile,
143334
- "output-config-path": outputConfigPath,
143476
+ outputConfigPath,
143477
+ outputRoutesPath: routesOutputPath,
143335
143478
  minify,
143336
143479
  sourcemap,
143337
143480
  fallbackService,
143338
143481
  watch: watch5,
143339
143482
  plugin,
143340
- "build-output-directory": buildOutputDirectory,
143341
- "node-compat": nodeCompat
143483
+ buildOutputDirectory,
143484
+ nodeCompat
143342
143485
  }) => {
143343
143486
  if (!isInPagesCI) {
143344
143487
  logger.log(pagesBetaWarning);
@@ -143348,7 +143491,7 @@ var Handler = async ({
143348
143491
  "Enabling node.js compatibility mode for builtins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
143349
143492
  );
143350
143493
  }
143351
- buildOutputDirectory ??= (0, import_node_path23.dirname)(outfile);
143494
+ buildOutputDirectory ??= (0, import_node_path24.dirname)(outfile);
143352
143495
  await buildFunctions({
143353
143496
  outfile,
143354
143497
  outputConfigPath,
@@ -143359,7 +143502,8 @@ var Handler = async ({
143359
143502
  watch: watch5,
143360
143503
  plugin,
143361
143504
  buildOutputDirectory,
143362
- nodeCompat
143505
+ nodeCompat,
143506
+ routesOutputPath
143363
143507
  });
143364
143508
  await sendMetricsEvent("build pages functions");
143365
143509
  };
@@ -143374,17 +143518,22 @@ async function buildFunctions({
143374
143518
  onEnd,
143375
143519
  plugin = false,
143376
143520
  buildOutputDirectory,
143521
+ routesOutputPath,
143377
143522
  nodeCompat
143378
143523
  }) {
143379
143524
  RUNNING_BUILDERS.forEach(
143380
143525
  (runningBuilder) => runningBuilder.stop && runningBuilder.stop()
143381
143526
  );
143382
- const routesModule = (0, import_node_path23.join)((0, import_node_os8.tmpdir)(), `./functionsRoutes-${Math.random()}.mjs`);
143527
+ const routesModule = (0, import_node_path24.join)((0, import_node_os8.tmpdir)(), `./functionsRoutes-${Math.random()}.mjs`);
143383
143528
  const baseURL = toUrlPath("/");
143384
143529
  const config = await generateConfigFromFileTree({
143385
143530
  baseDir: functionsDirectory,
143386
143531
  baseURL
143387
143532
  });
143533
+ if (config.routes && routesOutputPath) {
143534
+ const routesJSON = convertRoutesToRoutesJSONSpec(config.routes);
143535
+ (0, import_node_fs10.writeFileSync)(routesOutputPath, JSON.stringify(routesJSON, null, 2));
143536
+ }
143388
143537
  if (outputConfigPath) {
143389
143538
  (0, import_node_fs10.writeFileSync)(
143390
143539
  outputConfigPath,
@@ -143523,10 +143672,16 @@ async function CreateHandler({
143523
143672
  } catch (err2) {
143524
143673
  isGitDir = false;
143525
143674
  }
143675
+ if (isGitDir) {
143676
+ try {
143677
+ productionBranch = (0, import_node_child_process4.execSync)(`git rev-parse --abbrev-ref HEAD`).toString().trim();
143678
+ } catch (err2) {
143679
+ }
143680
+ }
143526
143681
  productionBranch = await prompt(
143527
143682
  "Enter the production branch name:",
143528
143683
  "text",
143529
- isGitDir ? (0, import_node_child_process4.execSync)(`git rev-parse --abbrev-ref HEAD`).toString().trim() : "production"
143684
+ productionBranch ?? "production"
143530
143685
  );
143531
143686
  }
143532
143687
  if (!productionBranch) {
@@ -143564,9 +143719,7 @@ function ListOptions2(yargs) {
143564
143719
  }
143565
143720
  }).epilogue(pagesBetaWarning);
143566
143721
  }
143567
- async function ListHandler2({
143568
- projectName
143569
- }) {
143722
+ async function ListHandler2({ projectName }) {
143570
143723
  const config = getConfigCache(PAGES_CONFIG_CACHE_FILENAME);
143571
143724
  const accountId = await requireAuth(config);
143572
143725
  projectName ??= config.project_name;
@@ -143630,8 +143783,12 @@ init_import_meta_url();
143630
143783
  var import_node_child_process5 = require("node:child_process");
143631
143784
  var import_node_fs11 = require("node:fs");
143632
143785
  var import_node_os9 = require("node:os");
143633
- var import_node_path24 = require("node:path");
143786
+ var import_node_path25 = require("node:path");
143634
143787
  var import_chokidar3 = require("chokidar");
143788
+ var import_esbuild6 = require("esbuild");
143789
+ var DURABLE_OBJECTS_BINDING_REGEXP = new RegExp(
143790
+ /^(?<binding>[^=]+)=(?<className>[^@\s]+)(@(?<scriptName>.*)$)?$/
143791
+ );
143635
143792
  function Options2(yargs) {
143636
143793
  return yargs.positional("directory", {
143637
143794
  type: "string",
@@ -143647,11 +143804,20 @@ function Options2(yargs) {
143647
143804
  default: true,
143648
143805
  description: "Run on my machine"
143649
143806
  },
143807
+ ip: {
143808
+ type: "string",
143809
+ default: "0.0.0.0",
143810
+ description: "The IP address to listen on"
143811
+ },
143650
143812
  port: {
143651
143813
  type: "number",
143652
143814
  default: 8788,
143653
143815
  description: "The port to listen on (serve from)"
143654
143816
  },
143817
+ "inspector-port": {
143818
+ type: "number",
143819
+ describe: "Port for devtools to connect to"
143820
+ },
143655
143821
  proxy: {
143656
143822
  type: "number",
143657
143823
  description: "The port to proxy (where the static assets are served)"
@@ -143668,14 +143834,18 @@ function Options2(yargs) {
143668
143834
  },
143669
143835
  kv: {
143670
143836
  type: "array",
143671
- description: "KV namespace to bind",
143837
+ description: "KV namespace to bind (--kv KV_BINDING)",
143672
143838
  alias: "k"
143673
143839
  },
143674
143840
  do: {
143675
143841
  type: "array",
143676
- description: "Durable Object to bind (NAME=CLASS)",
143842
+ description: "Durable Object to bind (--do NAME=CLASS)",
143677
143843
  alias: "o"
143678
143844
  },
143845
+ r2: {
143846
+ type: "array",
143847
+ description: "R2 bucket to bind (--r2 R2_BINDING)"
143848
+ },
143679
143849
  "live-reload": {
143680
143850
  type: "boolean",
143681
143851
  default: false,
@@ -143706,12 +143876,15 @@ function Options2(yargs) {
143706
143876
  var Handler2 = async ({
143707
143877
  local,
143708
143878
  directory,
143879
+ ip,
143709
143880
  port,
143881
+ "inspector-port": inspectorPort,
143710
143882
  proxy: requestedProxyPort,
143711
143883
  "script-path": singleWorkerScriptPath,
143712
143884
  binding: bindings = [],
143713
143885
  kv: kvs = [],
143714
143886
  do: durableObjects = [],
143887
+ r2: r2s = [],
143715
143888
  "live-reload": liveReload,
143716
143889
  "local-protocol": localProtocol,
143717
143890
  "experimental-enable-local-persistence": experimentalEnableLocalPersistence,
@@ -143743,7 +143916,7 @@ var Handler2 = async ({
143743
143916
  if (proxyPort === void 0)
143744
143917
  return void 0;
143745
143918
  } else {
143746
- directory = (0, import_node_path24.resolve)(directory);
143919
+ directory = (0, import_node_path25.resolve)(directory);
143747
143920
  }
143748
143921
  let scriptReadyResolve;
143749
143922
  const scriptReadyPromise = new Promise(
@@ -143751,7 +143924,7 @@ var Handler2 = async ({
143751
143924
  );
143752
143925
  let scriptPath;
143753
143926
  if (usingFunctions) {
143754
- const outfile = (0, import_node_path24.join)((0, import_node_os9.tmpdir)(), `./functionsWorker-${Math.random()}.js`);
143927
+ const outfile = (0, import_node_path25.join)((0, import_node_os9.tmpdir)(), `./functionsWorker-${Math.random()}.js`);
143755
143928
  scriptPath = outfile;
143756
143929
  if (nodeCompat) {
143757
143930
  console.warn(
@@ -143789,17 +143962,37 @@ var Handler2 = async ({
143789
143962
  });
143790
143963
  } else {
143791
143964
  scriptReadyResolve();
143792
- scriptPath = directory !== void 0 ? (0, import_node_path24.join)(directory, singleWorkerScriptPath) : singleWorkerScriptPath;
143965
+ scriptPath = directory !== void 0 ? (0, import_node_path25.join)(directory, singleWorkerScriptPath) : singleWorkerScriptPath;
143793
143966
  if (!(0, import_node_fs11.existsSync)(scriptPath)) {
143794
143967
  logger.log("No functions. Shimming...");
143795
- scriptPath = (0, import_node_path24.resolve)(__dirname, "../templates/pages-shim.ts");
143968
+ scriptPath = (0, import_node_path25.resolve)(__dirname, "../templates/pages-shim.ts");
143969
+ } else {
143970
+ const runBuild = async () => {
143971
+ try {
143972
+ await (0, import_esbuild6.build)({
143973
+ entryPoints: [scriptPath],
143974
+ write: false,
143975
+ plugins: [blockWorkerJsImports]
143976
+ });
143977
+ } catch {
143978
+ }
143979
+ };
143980
+ await runBuild();
143981
+ (0, import_chokidar3.watch)([scriptPath], {
143982
+ persistent: true,
143983
+ ignoreInitial: true
143984
+ }).on("all", async () => {
143985
+ await runBuild();
143986
+ });
143796
143987
  }
143797
143988
  }
143798
143989
  await scriptReadyPromise;
143799
143990
  const { stop, waitUntilExit } = await unstable_dev(
143800
143991
  scriptPath,
143801
143992
  {
143993
+ ip,
143802
143994
  port,
143995
+ inspectorPort,
143803
143996
  watch: true,
143804
143997
  localProtocol,
143805
143998
  liveReload,
@@ -143813,11 +144006,22 @@ var Handler2 = async ({
143813
144006
  id: ""
143814
144007
  })),
143815
144008
  durableObjects: durableObjects.map((durableObject) => {
143816
- const [name, class_name] = durableObject.toString().split("=");
144009
+ const { binding, className, scriptName } = DURABLE_OBJECTS_BINDING_REGEXP.exec(durableObject.toString())?.groups || {};
144010
+ if (!binding || !className) {
144011
+ logger.warn(
144012
+ "Could not parse Durable Object binding:",
144013
+ durableObject.toString()
144014
+ );
144015
+ return;
144016
+ }
143817
144017
  return {
143818
- name,
143819
- class_name
144018
+ name: binding,
144019
+ class_name: className,
144020
+ script_name: scriptName
143820
144021
  };
144022
+ }).filter(Boolean),
144023
+ r2: r2s.map((binding) => {
144024
+ return { binding: binding.toString(), bucket_name: "" };
143821
144025
  }),
143822
144026
  enablePagesAssetsServiceBinding: {
143823
144027
  proxyPort,
@@ -143950,13 +144154,25 @@ async function spawnProxyProcess({
143950
144154
  }
143951
144155
  return port;
143952
144156
  }
144157
+ var blockWorkerJsImports = {
144158
+ name: "block-worker-js-imports",
144159
+ setup(build6) {
144160
+ build6.onResolve({ filter: /.*/g }, (_args) => {
144161
+ logger.error(
144162
+ `_worker.js is importing from another file. This will throw an error if deployed.
144163
+ You should bundle your Worker or remove the import if it is unused.`
144164
+ );
144165
+ return null;
144166
+ });
144167
+ }
144168
+ };
143953
144169
 
143954
144170
  // src/pages/publish.tsx
143955
144171
  init_import_meta_url();
143956
144172
  var import_node_child_process6 = require("node:child_process");
143957
144173
  var import_node_fs12 = require("node:fs");
143958
144174
  var import_node_os10 = require("node:os");
143959
- var import_node_path26 = require("node:path");
144175
+ var import_node_path27 = require("node:path");
143960
144176
  var import_node_process7 = require("node:process");
143961
144177
  var import_ink9 = __toESM(require_build2());
143962
144178
  var import_ink_select_input4 = __toESM(require_build3());
@@ -143966,7 +144182,7 @@ var import_undici9 = __toESM(require_undici());
143966
144182
  // src/pages/upload.tsx
143967
144183
  init_import_meta_url();
143968
144184
  var import_promises11 = require("node:fs/promises");
143969
- var import_node_path25 = require("node:path");
144185
+ var import_node_path26 = require("node:path");
143970
144186
  var import_blake3_wasm = require("blake3-wasm");
143971
144187
  var import_ink8 = __toESM(require_build2());
143972
144188
  var import_ink_spinner = __toESM(require_build5());
@@ -144513,7 +144729,7 @@ var Handler3 = async ({
144513
144729
  jwt: process.env.CF_PAGES_UPLOAD_JWT
144514
144730
  });
144515
144731
  if (outputManifestPath) {
144516
- await (0, import_promises11.mkdir)((0, import_node_path25.dirname)(outputManifestPath), { recursive: true });
144732
+ await (0, import_promises11.mkdir)((0, import_node_path26.dirname)(outputManifestPath), { recursive: true });
144517
144733
  await (0, import_promises11.writeFile)(outputManifestPath, JSON.stringify(manifest));
144518
144734
  }
144519
144735
  logger.log(`\u2728 Upload complete!`);
@@ -144532,16 +144748,17 @@ var upload = async (args) => {
144532
144748
  "_worker.js",
144533
144749
  "_redirects",
144534
144750
  "_headers",
144751
+ "_routes.json",
144535
144752
  ".DS_Store",
144536
144753
  "node_modules",
144537
144754
  ".git"
144538
144755
  ];
144539
- const directory = (0, import_node_path25.resolve)(args.directory);
144756
+ const directory = (0, import_node_path26.resolve)(args.directory);
144540
144757
  const walk = async (dir, fileMap2 = /* @__PURE__ */ new Map(), startingDir = dir) => {
144541
144758
  const files2 = await (0, import_promises11.readdir)(dir);
144542
144759
  await Promise.all(
144543
144760
  files2.map(async (file) => {
144544
- const filepath = (0, import_node_path25.join)(dir, file);
144761
+ const filepath = (0, import_node_path26.join)(dir, file);
144545
144762
  const filestat = await (0, import_promises11.stat)(filepath);
144546
144763
  if (IGNORE_LIST.includes(file)) {
144547
144764
  return;
@@ -144552,10 +144769,10 @@ var upload = async (args) => {
144552
144769
  if (filestat.isDirectory()) {
144553
144770
  fileMap2 = await walk(filepath, fileMap2, startingDir);
144554
144771
  } else {
144555
- const name = (0, import_node_path25.relative)(startingDir, filepath).split(import_node_path25.sep).join("/");
144772
+ const name = (0, import_node_path26.relative)(startingDir, filepath).split(import_node_path26.sep).join("/");
144556
144773
  const fileContent = await (0, import_promises11.readFile)(filepath);
144557
144774
  const base64Content = fileContent.toString("base64");
144558
- const extension = (0, import_node_path25.extname)((0, import_node_path25.basename)(name)).substring(1);
144775
+ const extension = (0, import_node_path26.extname)((0, import_node_path26.basename)(name)).substring(1);
144559
144776
  if (filestat.size > 25 * 1024 * 1024) {
144560
144777
  throw new FatalError(
144561
144778
  `Error: Pages only supports files up to ${prettyBytes(
@@ -144945,15 +145162,17 @@ To silence this warning, pass in --commit-dirty=true`
144945
145162
  }
144946
145163
  }
144947
145164
  let builtFunctions = void 0;
144948
- const functionsDirectory = (0, import_node_path26.join)((0, import_node_process7.cwd)(), "functions");
145165
+ const functionsDirectory = (0, import_node_path27.join)((0, import_node_process7.cwd)(), "functions");
145166
+ const routesOutputPath = (0, import_node_path27.join)((0, import_node_os10.tmpdir)(), `_routes-${Math.random()}.json`);
144949
145167
  if ((0, import_node_fs12.existsSync)(functionsDirectory)) {
144950
- const outfile = (0, import_node_path26.join)((0, import_node_os10.tmpdir)(), `./functionsWorker-${Math.random()}.js`);
145168
+ const outfile = (0, import_node_path27.join)((0, import_node_os10.tmpdir)(), `./functionsWorker-${Math.random()}.js`);
144951
145169
  await new Promise(
144952
145170
  (resolve13) => buildFunctions({
144953
145171
  outfile,
144954
145172
  functionsDirectory,
144955
145173
  onEnd: () => resolve13(null),
144956
- buildOutputDirectory: (0, import_node_path26.dirname)(outfile)
145174
+ buildOutputDirectory: (0, import_node_path27.dirname)(outfile),
145175
+ routesOutputPath
144957
145176
  })
144958
145177
  );
144959
145178
  builtFunctions = (0, import_node_fs12.readFileSync)(outfile, "utf-8");
@@ -144973,17 +145192,21 @@ To silence this warning, pass in --commit-dirty=true`
144973
145192
  if (commitDirty !== void 0) {
144974
145193
  formData.append("commit_dirty", commitDirty);
144975
145194
  }
144976
- let _headers, _redirects, _workerJS;
145195
+ let _headers, _redirects, _routes, _workerJS;
144977
145196
  try {
144978
- _headers = (0, import_node_fs12.readFileSync)((0, import_node_path26.join)(directory, "_headers"), "utf-8");
145197
+ _headers = (0, import_node_fs12.readFileSync)((0, import_node_path27.join)(directory, "_headers"), "utf-8");
144979
145198
  } catch {
144980
145199
  }
144981
145200
  try {
144982
- _redirects = (0, import_node_fs12.readFileSync)((0, import_node_path26.join)(directory, "_redirects"), "utf-8");
145201
+ _redirects = (0, import_node_fs12.readFileSync)((0, import_node_path27.join)(directory, "_redirects"), "utf-8");
144983
145202
  } catch {
144984
145203
  }
144985
145204
  try {
144986
- _workerJS = (0, import_node_fs12.readFileSync)((0, import_node_path26.join)(directory, "_worker.js"), "utf-8");
145205
+ _routes = (0, import_node_fs12.readFileSync)(routesOutputPath, "utf-8");
145206
+ } catch {
145207
+ }
145208
+ try {
145209
+ _workerJS = (0, import_node_fs12.readFileSync)((0, import_node_path27.join)(directory, "_worker.js"), "utf-8");
144987
145210
  } catch {
144988
145211
  }
144989
145212
  if (_headers) {
@@ -144992,10 +145215,32 @@ To silence this warning, pass in --commit-dirty=true`
144992
145215
  if (_redirects) {
144993
145216
  formData.append("_redirects", new import_undici9.File([_redirects], "_redirects"));
144994
145217
  }
145218
+ if (_routes) {
145219
+ formData.append("_routes.json", new import_undici9.File([_routes], "_routes.json"));
145220
+ }
144995
145221
  if (builtFunctions) {
144996
145222
  formData.append("_worker.js", new import_undici9.File([builtFunctions], "_worker.js"));
144997
145223
  } else if (_workerJS) {
144998
145224
  formData.append("_worker.js", new import_undici9.File([_workerJS], "_worker.js"));
145225
+ try {
145226
+ const routesPath = (0, import_node_path27.join)(directory, "_routes.json");
145227
+ const advancedModeRoutesString = (0, import_node_fs12.readFileSync)(routesPath, "utf-8");
145228
+ const advancedModeRoutes = JSON.parse(advancedModeRoutesString);
145229
+ if (!isRoutesJSONSpec(advancedModeRoutes)) {
145230
+ throw new FatalError(
145231
+ "Invalid _routes.json file found at:" + routesPath,
145232
+ 1
145233
+ );
145234
+ }
145235
+ _routes = JSON.stringify(optimizeRoutesJSONSpec(advancedModeRoutes));
145236
+ logger.warn(
145237
+ `\u{1F6A8} _routes.json is an experimental feature and is subject to change. Don't use unless you really must!`
145238
+ );
145239
+ } catch (e2) {
145240
+ if (e2 instanceof FatalError) {
145241
+ throw e2;
145242
+ }
145243
+ }
144999
145244
  }
145000
145245
  const deploymentResponse = await fetchResult(
145001
145246
  `/accounts/${accountId}/pages/projects/${projectName}/deployments`,
@@ -145105,7 +145350,7 @@ function previewHandler() {
145105
145350
  init_import_meta_url();
145106
145351
  var import_node_assert9 = __toESM(require("node:assert"));
145107
145352
  var import_node_fs13 = require("node:fs");
145108
- var import_node_path27 = __toESM(require("node:path"));
145353
+ var import_node_path28 = __toESM(require("node:path"));
145109
145354
  var import_node_url11 = require("node:url");
145110
145355
  var import_tmp_promise3 = __toESM(require_tmp_promise());
145111
145356
 
@@ -145338,7 +145583,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
145338
145583
  );
145339
145584
  if (props.outDir) {
145340
145585
  (0, import_node_fs13.mkdirSync)(props.outDir, { recursive: true });
145341
- const readmePath = import_node_path27.default.join(props.outDir, "README.md");
145586
+ const readmePath = import_node_path28.default.join(props.outDir, "README.md");
145342
145587
  (0, import_node_fs13.writeFileSync)(
145343
145588
  readmePath,
145344
145589
  `This folder contains the built output assets for the worker "${scriptName}" generated at ${new Date().toISOString()}.`
@@ -145377,7 +145622,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
145377
145622
  const destinationDir = typeof destination === "string" ? destination : destination.path;
145378
145623
  (0, import_node_fs13.mkdirSync)(destinationDir, { recursive: true });
145379
145624
  (0, import_node_fs13.writeFileSync)(
145380
- import_node_path27.default.join(destinationDir, import_node_path27.default.basename(props.entry.file)),
145625
+ import_node_path28.default.join(destinationDir, import_node_path28.default.basename(props.entry.file)),
145381
145626
  (0, import_node_fs13.readFileSync)(props.entry.file, "utf-8")
145382
145627
  );
145383
145628
  }
@@ -145458,7 +145703,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
145458
145703
  const worker = {
145459
145704
  name: scriptName,
145460
145705
  main: {
145461
- name: import_node_path27.default.basename(resolvedEntryPointPath),
145706
+ name: import_node_path28.default.basename(resolvedEntryPointPath),
145462
145707
  content,
145463
145708
  type: bundleType
145464
145709
  },
@@ -145470,7 +145715,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
145470
145715
  usage_model: config.usage_model
145471
145716
  };
145472
145717
  void printBundleSize(
145473
- { name: import_node_path27.default.basename(resolvedEntryPointPath), content },
145718
+ { name: import_node_path28.default.basename(resolvedEntryPointPath), content },
145474
145719
  modules
145475
145720
  );
145476
145721
  const withoutStaticAssets = {
@@ -146376,6 +146621,12 @@ async function putR2Object(accountId, bucketName, objectName, object, options) {
146376
146621
  }
146377
146622
  );
146378
146623
  }
146624
+ async function deleteR2Object(accountId, bucketName, objectName) {
146625
+ await fetchR2Objects(
146626
+ `/accounts/${accountId}/r2/buckets/${bucketName}/objects/${objectName}`,
146627
+ { method: "DELETE" }
146628
+ );
146629
+ }
146379
146630
 
146380
146631
  // src/tail/index.ts
146381
146632
  init_import_meta_url();
@@ -146468,7 +146719,7 @@ function prettyPrintLogs(data) {
146468
146719
  ).toLocaleString();
146469
146720
  const outcome = prettifyOutcome(eventMessage.outcome);
146470
146721
  logger.log(`"${cronPattern}" @ ${datetime} - ${outcome}`);
146471
- } else {
146722
+ } else if (isRequestEvent(eventMessage.event)) {
146472
146723
  const requestMethod = eventMessage.event?.request.method.toUpperCase();
146473
146724
  const url3 = eventMessage.event?.request.url;
146474
146725
  const outcome = prettifyOutcome(eventMessage.outcome);
@@ -146476,6 +146727,16 @@ function prettyPrintLogs(data) {
146476
146727
  logger.log(
146477
146728
  url3 ? `${requestMethod} ${url3} - ${outcome} @ ${datetime}` : `[missing request] - ${outcome} @ ${datetime}`
146478
146729
  );
146730
+ } else if (isAlarmEvent(eventMessage.event)) {
146731
+ const outcome = prettifyOutcome(eventMessage.outcome);
146732
+ const datetime = new Date(
146733
+ eventMessage.event.scheduledTime
146734
+ ).toLocaleString();
146735
+ logger.log(`Alarm @ ${datetime} - ${outcome}`);
146736
+ } else {
146737
+ const outcome = prettifyOutcome(eventMessage.outcome);
146738
+ const datetime = new Date(eventMessage.eventTimestamp).toLocaleString();
146739
+ logger.log(`Unknown Event - ${outcome} @ ${datetime}`);
146479
146740
  }
146480
146741
  if (eventMessage.logs.length > 0) {
146481
146742
  eventMessage.logs.forEach(({ level, message }) => {
@@ -146491,9 +146752,15 @@ function prettyPrintLogs(data) {
146491
146752
  function jsonPrintLogs(data) {
146492
146753
  console.log(JSON.stringify(JSON.parse(data.toString()), null, 2));
146493
146754
  }
146755
+ function isRequestEvent(event) {
146756
+ return Boolean(event && "request" in event);
146757
+ }
146494
146758
  function isScheduledEvent(event) {
146495
146759
  return Boolean(event && "cron" in event);
146496
146760
  }
146761
+ function isAlarmEvent(event) {
146762
+ return Boolean(event && "scheduledTime" in event && !("cron" in event));
146763
+ }
146497
146764
  function prettifyOutcome(outcome) {
146498
146765
  switch (outcome) {
146499
146766
  case "ok":
@@ -147097,7 +147364,7 @@ function createCLIParser(argv) {
147097
147364
  },
147098
147365
  async (args) => {
147099
147366
  await printWranglerBanner();
147100
- const configPath = args.config || args.script && findWranglerToml(import_node_path28.default.dirname(args.script));
147367
+ const configPath = args.config || args.script && findWranglerToml(import_node_path29.default.dirname(args.script));
147101
147368
  const config = readConfig(configPath, args);
147102
147369
  const entry = await getEntry(args, config, "publish");
147103
147370
  await sendMetricsEvent(
@@ -148066,8 +148333,8 @@ Expected an array of strings.
148066
148333
  return r2ObjectYargs.command(
148067
148334
  "get <objectPath>",
148068
148335
  "Fetch an object from an R2 bucket",
148069
- (yargs) => {
148070
- return yargs.positional("objectPath", {
148336
+ (Objectyargs) => {
148337
+ return Objectyargs.positional("objectPath", {
148071
148338
  describe: "The source object path in the form of {bucket}/{key}",
148072
148339
  type: "string"
148073
148340
  }).option("file", {
@@ -148083,12 +148350,15 @@ Expected an array of strings.
148083
148350
  type: "boolean"
148084
148351
  });
148085
148352
  },
148086
- async (args) => {
148087
- const config = readConfig(args.config, args);
148353
+ async (objectGetYargs) => {
148354
+ const config = readConfig(
148355
+ objectGetYargs.config,
148356
+ objectGetYargs
148357
+ );
148088
148358
  const accountId = await requireAuth(config);
148089
- const { objectPath, pipe } = args;
148359
+ const { objectPath, pipe } = objectGetYargs;
148090
148360
  const { bucket, key: key2 } = bucketAndKeyFromObjectPath(objectPath);
148091
- let file = args.file;
148361
+ let file = objectGetYargs.file;
148092
148362
  if (!file && !pipe) {
148093
148363
  file = key2;
148094
148364
  }
@@ -148109,8 +148379,8 @@ Expected an array of strings.
148109
148379
  ).command(
148110
148380
  "put <objectPath>",
148111
148381
  "Create an object in an R2 bucket",
148112
- (yargs) => {
148113
- return yargs.positional("objectPath", {
148382
+ (Objectyargs) => {
148383
+ return Objectyargs.positional("objectPath", {
148114
148384
  describe: "The destination object path in the form of {bucket}/{key}",
148115
148385
  type: "string"
148116
148386
  }).option("file", {
@@ -148156,11 +148426,14 @@ Expected an array of strings.
148156
148426
  type: "string"
148157
148427
  });
148158
148428
  },
148159
- async (args) => {
148429
+ async (objectPutYargs) => {
148160
148430
  await printWranglerBanner();
148161
- const config = readConfig(args.config, args);
148431
+ const config = readConfig(
148432
+ objectPutYargs.config,
148433
+ objectPutYargs
148434
+ );
148162
148435
  const accountId = await requireAuth(config);
148163
- const { objectPath, file, pipe, ...options } = args;
148436
+ const { objectPath, file, pipe, ...options } = objectPutYargs;
148164
148437
  const { bucket, key: key2 } = bucketAndKeyFromObjectPath(objectPath);
148165
148438
  if (!file && !pipe) {
148166
148439
  throw new CommandLineArgsError(
@@ -148197,6 +148470,25 @@ Expected an array of strings.
148197
148470
  });
148198
148471
  logger.log("Upload complete.");
148199
148472
  }
148473
+ ).command(
148474
+ "delete <objectPath>",
148475
+ "Delete an object in an R2 bucket",
148476
+ (objectDeleteYargs) => {
148477
+ return objectDeleteYargs.positional("objectPath", {
148478
+ describe: "The destination object path in the form of {bucket}/{key}",
148479
+ type: "string"
148480
+ });
148481
+ },
148482
+ async (args) => {
148483
+ const { objectPath } = args;
148484
+ await printWranglerBanner();
148485
+ const config = readConfig(args.config, args);
148486
+ const accountId = await requireAuth(config);
148487
+ const { bucket, key: key2 } = bucketAndKeyFromObjectPath(objectPath);
148488
+ logger.log(`Deleting object "${key2}" from bucket "${bucket}".`);
148489
+ await deleteR2Object(accountId, bucket, key2);
148490
+ logger.log("Delete complete.");
148491
+ }
148200
148492
  );
148201
148493
  }).command("bucket", "Manage R2 buckets", (r2BucketYargs) => {
148202
148494
  r2BucketYargs.command(
@@ -148449,9 +148741,9 @@ function devOptions(yargs) {
148449
148741
  type: "boolean",
148450
148742
  default: true
148451
148743
  }).option("ip", {
148452
- describe: "IP address to listen on, defaults to `localhost`",
148744
+ describe: "IP address to listen on",
148453
148745
  type: "string",
148454
- requiresArg: true
148746
+ default: "0.0.0.0"
148455
148747
  }).option("port", {
148456
148748
  describe: "Port to listen on",
148457
148749
  type: "number"
@@ -148559,7 +148851,7 @@ async function startDev(args) {
148559
148851
  logger.loggerLevel = args.logLevel === "none" ? "error" : args.logLevel;
148560
148852
  }
148561
148853
  await printWranglerBanner();
148562
- const configPath = args.config || args.script && findWranglerToml(import_node_path29.default.dirname(args.script));
148854
+ const configPath = args.config || args.script && findWranglerToml(import_node_path30.default.dirname(args.script));
148563
148855
  let config = readConfig(configPath, args);
148564
148856
  if (config.configPath) {
148565
148857
  watcher = (0, import_chokidar4.watch)(config.configPath, {
@@ -148567,7 +148859,7 @@ async function startDev(args) {
148567
148859
  }).on("change", async (_event) => {
148568
148860
  config = readConfig(configPath, args);
148569
148861
  if (config.configPath) {
148570
- logger.log(`${import_node_path29.default.basename(config.configPath)} changed...`);
148862
+ logger.log(`${import_node_path30.default.basename(config.configPath)} changed...`);
148571
148863
  rerender(await getDevReactElement(config));
148572
148864
  }
148573
148865
  });
@@ -148657,7 +148949,8 @@ async function startDev(args) {
148657
148949
  const bindings = await getBindings(configParam, {
148658
148950
  kv: args.kv,
148659
148951
  vars: args.vars,
148660
- durableObjects: args.durableObjects
148952
+ durableObjects: args.durableObjects,
148953
+ r2: args.r2
148661
148954
  });
148662
148955
  const maskedVars = { ...bindings.vars };
148663
148956
  for (const key2 of Object.keys(maskedVars)) {
@@ -148703,7 +148996,7 @@ async function startDev(args) {
148703
148996
  assetsConfig: config.assets,
148704
148997
  port: args.port || config.dev.port || await getLocalPort(),
148705
148998
  ip: args.ip || config.dev.ip,
148706
- inspectorPort: args["inspector-port"] || config.dev.inspector_port || await getInspectorPort(),
148999
+ inspectorPort: args.inspectorPort || config.dev.inspector_port || await getInspectorPort(),
148707
149000
  isWorkersSite: Boolean(args.site || config.site),
148708
149001
  compatibilityDate: getDevCompatibilityDate(
148709
149002
  config,
@@ -148780,19 +149073,22 @@ async function getBindings(configParam, args) {
148780
149073
  ...args.durableObjects || []
148781
149074
  ]
148782
149075
  },
148783
- r2_buckets: configParam.r2_buckets?.map(
148784
- ({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
148785
- if (!preview_bucket_name) {
148786
- throw new Error(
148787
- `In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml`
148788
- );
149076
+ r2_buckets: [
149077
+ ...configParam.r2_buckets?.map(
149078
+ ({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
149079
+ if (!preview_bucket_name) {
149080
+ throw new Error(
149081
+ `In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml`
149082
+ );
149083
+ }
149084
+ return {
149085
+ binding,
149086
+ bucket_name: preview_bucket_name
149087
+ };
148789
149088
  }
148790
- return {
148791
- binding,
148792
- bucket_name: preview_bucket_name
148793
- };
148794
- }
148795
- ),
149089
+ ) || [],
149090
+ ...args.r2 || []
149091
+ ],
148796
149092
  worker_namespaces: configParam.worker_namespaces,
148797
149093
  services: configParam.services,
148798
149094
  unsafe: configParam.unsafe?.bindings,