wrangler 2.0.27 → 2.1.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.
Files changed (65) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +1141 -369
  3. package/package.json +6 -4
  4. package/src/__tests__/api-dev.test.ts +19 -0
  5. package/src/__tests__/configuration.test.ts +27 -27
  6. package/src/__tests__/dev.test.tsx +8 -6
  7. package/src/__tests__/helpers/hello-world-worker.js +5 -0
  8. package/src/__tests__/helpers/mock-cfetch.ts +4 -4
  9. package/src/__tests__/helpers/mock-console.ts +11 -2
  10. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  11. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  12. package/src/__tests__/index.test.ts +37 -37
  13. package/src/__tests__/init.test.ts +356 -5
  14. package/src/__tests__/jest.setup.ts +13 -0
  15. package/src/__tests__/middleware.test.ts +768 -0
  16. package/src/__tests__/pages.test.ts +829 -104
  17. package/src/__tests__/paths.test.ts +17 -0
  18. package/src/__tests__/publish.test.ts +512 -445
  19. package/src/__tests__/tail.test.ts +79 -72
  20. package/src/__tests__/test-old-node-version.js +3 -3
  21. package/src/__tests__/worker-namespace.test.ts +37 -35
  22. package/src/api/dev.ts +93 -28
  23. package/src/bundle.ts +239 -12
  24. package/src/cfetch/internal.ts +64 -3
  25. package/src/cli.ts +1 -1
  26. package/src/config/environment.ts +1 -1
  27. package/src/config/index.ts +4 -4
  28. package/src/config/validation.ts +3 -3
  29. package/src/create-worker-upload-form.ts +29 -26
  30. package/src/dev/dev.tsx +3 -1
  31. package/src/dev/local.tsx +319 -171
  32. package/src/dev/remote.tsx +16 -4
  33. package/src/dev/start-server.ts +416 -0
  34. package/src/dev/use-esbuild.ts +4 -0
  35. package/src/dev.tsx +340 -166
  36. package/src/dialogs.tsx +12 -0
  37. package/src/{worker-namespace.ts → dispatch-namespace.ts} +18 -18
  38. package/src/entry.ts +2 -1
  39. package/src/index.tsx +59 -12
  40. package/src/init.ts +291 -16
  41. package/src/metrics/send-event.ts +6 -5
  42. package/src/miniflare-cli/assets.ts +130 -476
  43. package/src/miniflare-cli/index.ts +39 -33
  44. package/src/pages/constants.ts +3 -0
  45. package/src/pages/dev.tsx +8 -3
  46. package/src/pages/functions/buildPlugin.ts +2 -1
  47. package/src/pages/functions/buildWorker.ts +2 -1
  48. package/src/pages/functions/routes-transformation.test.ts +12 -1
  49. package/src/pages/functions/routes-transformation.ts +7 -1
  50. package/src/pages/hash.tsx +13 -0
  51. package/src/pages/publish.tsx +82 -38
  52. package/src/pages/upload.tsx +3 -18
  53. package/src/paths.ts +20 -1
  54. package/src/publish.ts +49 -8
  55. package/src/tail/filters.ts +1 -5
  56. package/src/tail/index.ts +6 -3
  57. package/src/worker.ts +10 -9
  58. package/src/zones.ts +91 -0
  59. package/templates/middleware/common.ts +62 -0
  60. package/templates/middleware/loader-modules.ts +84 -0
  61. package/templates/middleware/loader-sw.ts +213 -0
  62. package/templates/middleware/middleware-pretty-error.ts +40 -0
  63. package/templates/middleware/middleware-scheduled.ts +14 -0
  64. package/wrangler-dist/cli.d.ts +22 -8
  65. package/wrangler-dist/cli.js +71020 -65212
package/src/dev.tsx CHANGED
@@ -3,11 +3,11 @@ import { watch } from "chokidar";
3
3
  import getPort from "get-port";
4
4
  import { render } from "ink";
5
5
  import React from "react";
6
- import { fetch } from "undici";
7
6
  import { findWranglerToml, printBindings, readConfig } from "./config";
8
7
  import Dev from "./dev/dev";
9
8
  import { getVarsForDev } from "./dev/dev-vars";
10
9
 
10
+ import { startDevServer } from "./dev/start-server";
11
11
  import { getEntry } from "./entry";
12
12
  import { logger } from "./logger";
13
13
  import * as metrics from "./metrics";
@@ -29,7 +29,6 @@ import type { Config } from "./config";
29
29
  import type { Route } from "./config/environment";
30
30
  import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli";
31
31
  import type { CfWorkerInit } from "./worker";
32
- import type { RequestInit } from "undici";
33
32
  import type { Argv, ArgumentsCamelCase } from "yargs";
34
33
 
35
34
  interface DevArgs {
@@ -63,10 +62,12 @@ interface DevArgs {
63
62
  tsconfig?: string;
64
63
  local?: boolean;
65
64
  minify?: boolean;
65
+ var?: string[];
66
+ define?: string[];
66
67
  "node-compat"?: boolean;
67
68
  "experimental-enable-local-persistence"?: boolean;
68
69
  "live-reload"?: boolean;
69
- onReady?: () => void;
70
+ onReady?: (ip: string, port: number) => void;
70
71
  logLevel?: "none" | "error" | "log" | "warn" | "debug";
71
72
  logPrefix?: string;
72
73
  showInteractiveDevSession?: boolean;
@@ -129,7 +130,6 @@ export function devOptions(yargs: Argv): Argv<DevArgs> {
129
130
  .option("ip", {
130
131
  describe: "IP address to listen on",
131
132
  type: "string",
132
- default: "0.0.0.0",
133
133
  })
134
134
  .option("port", {
135
135
  describe: "Port to listen on",
@@ -196,6 +196,19 @@ export function devOptions(yargs: Argv): Argv<DevArgs> {
196
196
  describe: "Protocol to forward requests to host on, defaults to https.",
197
197
  choices: ["http", "https"] as const,
198
198
  })
199
+ .option("var", {
200
+ describe:
201
+ "A key-value pair to be injected into the script as a variable",
202
+ type: "string",
203
+ requiresArg: true,
204
+ array: true,
205
+ })
206
+ .option("define", {
207
+ describe: "A key-value pair to be substituted in the script",
208
+ type: "string",
209
+ requiresArg: true,
210
+ array: true,
211
+ })
199
212
  .option("jsx-factory", {
200
213
  describe: "The function that is called for each JSX element",
201
214
  type: "string",
@@ -319,11 +332,17 @@ export async function startDev(args: StartDevOptions) {
319
332
  });
320
333
  }
321
334
 
322
- const entry = await getEntry(
323
- { assets: args.assets, script: args.script },
324
- config,
325
- "dev"
326
- );
335
+ const {
336
+ entry,
337
+ nodeCompat,
338
+ upstreamProtocol,
339
+ zoneId,
340
+ host,
341
+ routes,
342
+ getLocalPort,
343
+ getInspectorPort,
344
+ cliDefines,
345
+ } = await validateDevServerSettings(args, config);
327
346
 
328
347
  await metrics.sendMetricsEvent(
329
348
  "run dev",
@@ -334,182 +353,60 @@ export async function startDev(args: StartDevOptions) {
334
353
  { sendMetrics: config.send_metrics, offline: args.local }
335
354
  );
336
355
 
337
- if (config.services && config.services.length > 0) {
338
- logger.warn(
339
- `This worker is bound to live services: ${config.services
340
- .map(
341
- (service) =>
342
- `${service.binding} (${service.service}${
343
- service.environment ? `@${service.environment}` : ""
344
- })`
345
- )
346
- .join(", ")}`
347
- );
348
- }
349
-
350
- if (args.inspect) {
351
- //devtools are enabled by default, but we still need to disable them if the caller doesn't want them
352
- logger.warn(
353
- "Passing --inspect is unnecessary, now you can always connect to devtools."
354
- );
355
- }
356
-
357
- if (args["experimental-public"]) {
358
- throw new Error(
359
- "The --experimental-public field has been renamed to --assets"
360
- );
361
- }
362
-
363
- if (args.public) {
364
- throw new Error("The --public field has been renamed to --assets");
365
- }
366
-
367
- if ((args.assets || config.assets) && (args.site || config.site)) {
368
- throw new Error(
369
- "Cannot use Assets and Workers Sites in the same Worker."
370
- );
371
- }
372
-
373
- if (args.assets) {
374
- logger.warn(
375
- "The --assets argument is experimental and may change or break at any time"
376
- );
377
- }
378
-
379
- const upstreamProtocol =
380
- args["upstream-protocol"] || config.dev.upstream_protocol;
381
- if (upstreamProtocol === "http") {
382
- logger.warn(
383
- "Setting upstream-protocol to http is not currently implemented.\n" +
384
- "If this is required in your project, please add your use case to the following issue:\n" +
385
- "https://github.com/cloudflare/wrangler2/issues/583."
386
- );
387
- }
388
-
389
- // TODO: if worker_dev = false and no routes, then error (only for dev)
390
-
391
- // Compute zone info from the `host` and `route` args and config;
392
- let host = args.host || config.dev.host;
393
- let zoneId: string | undefined;
394
- const routes: Route[] | undefined =
395
- args.routes || (config.route && [config.route]) || config.routes;
396
-
397
- if (args.forceLocal) {
398
- args.local = true;
399
- }
400
-
401
- if (!args.local) {
402
- if (host) {
403
- zoneId = await getZoneIdFromHost(host);
404
- }
405
- if (!zoneId && routes) {
406
- const firstRoute = routes[0];
407
- const zone = await getZoneForRoute(firstRoute);
408
- if (zone) {
409
- zoneId = zone.id;
410
- host = zone.host;
411
- }
412
- }
413
- } else if (!host) {
414
- if (routes) {
415
- const firstRoute = routes[0];
416
- host = getHostFromRoute(firstRoute);
417
- }
418
- }
419
-
420
- const nodeCompat = args.nodeCompat ?? config.node_compat;
421
- if (nodeCompat) {
422
- logger.warn(
423
- "Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
424
- );
425
- }
426
-
427
- const getLocalPort = memoizeGetPort(DEFAULT_LOCAL_PORT);
428
- const getInspectorPort = memoizeGetPort(DEFAULT_INSPECTOR_PORT);
429
-
430
356
  // eslint-disable-next-line no-inner-declarations
431
357
  async function getDevReactElement(configParam: Config) {
432
- // now log all available bindings into the terminal
433
- const bindings = await getBindings(configParam, {
434
- kv: args.kv,
435
- vars: args.vars,
436
- durableObjects: args.durableObjects,
437
- r2: args.r2,
438
- });
439
-
440
- // mask anything that was overridden in .dev.vars
441
- // so that we don't log potential secrets into the terminal
442
- const maskedVars = { ...bindings.vars };
443
- for (const key of Object.keys(maskedVars)) {
444
- if (maskedVars[key] !== configParam.vars[key]) {
445
- // This means it was overridden in .dev.vars
446
- // so let's mask it
447
- maskedVars[key] = "(hidden)";
448
- }
449
- }
450
-
451
- printBindings({
452
- ...bindings,
453
- vars: maskedVars,
454
- });
455
-
456
- const assetPaths =
457
- args.assets || config.assets
458
- ? getAssetPaths(config, args.assets)
459
- : getSiteAssetPaths(
460
- config,
461
- args.site,
462
- args.siteInclude,
463
- args.siteExclude
464
- );
358
+ const { assetPaths, bindings } = await getBindingsAndAssetPaths(
359
+ args,
360
+ configParam
361
+ );
465
362
 
466
363
  return (
467
364
  <Dev
468
- name={getScriptName({ name: args.name, env: args.env }, config)}
469
- noBundle={!(args.bundle ?? !config.no_bundle)}
365
+ name={getScriptName({ name: args.name, env: args.env }, configParam)}
366
+ noBundle={!(args.bundle ?? !configParam.no_bundle)}
470
367
  entry={entry}
471
368
  env={args.env}
472
369
  zone={zoneId}
473
370
  host={host}
474
371
  routes={routes}
475
- rules={getRules(config)}
476
- legacyEnv={isLegacyEnv(config)}
477
- minify={args.minify ?? config.minify}
372
+ rules={getRules(configParam)}
373
+ legacyEnv={isLegacyEnv(configParam)}
374
+ minify={args.minify ?? configParam.minify}
478
375
  nodeCompat={nodeCompat}
479
- build={config.build || {}}
480
- define={config.define}
376
+ build={configParam.build || {}}
377
+ define={{ ...configParam.define, ...cliDefines }}
481
378
  initialMode={args.local ? "local" : "remote"}
482
- jsxFactory={args["jsx-factory"] || config.jsx_factory}
483
- jsxFragment={args["jsx-fragment"] || config.jsx_fragment}
484
- tsconfig={args.tsconfig ?? config.tsconfig}
379
+ jsxFactory={args["jsx-factory"] || configParam.jsx_factory}
380
+ jsxFragment={args["jsx-fragment"] || configParam.jsx_fragment}
381
+ tsconfig={args.tsconfig ?? configParam.tsconfig}
485
382
  upstreamProtocol={upstreamProtocol}
486
- localProtocol={args.localProtocol || config.dev.local_protocol}
383
+ localProtocol={args.localProtocol || configParam.dev.local_protocol}
487
384
  localUpstream={args["local-upstream"] || host}
488
385
  enableLocalPersistence={
489
386
  args.experimentalEnableLocalPersistence || false
490
387
  }
491
388
  liveReload={args.liveReload || false}
492
- accountId={config.account_id || getAccountFromCache()?.id}
389
+ accountId={configParam.account_id || getAccountFromCache()?.id}
493
390
  assetPaths={assetPaths}
494
- assetsConfig={config.assets}
495
- port={args.port || config.dev.port || (await getLocalPort())}
496
- ip={args.ip || config.dev.ip}
391
+ assetsConfig={configParam.assets}
392
+ port={args.port || configParam.dev.port || (await getLocalPort())}
393
+ ip={args.ip || configParam.dev.ip}
497
394
  inspectorPort={
498
395
  args.inspectorPort ||
499
- config.dev.inspector_port ||
396
+ configParam.dev.inspector_port ||
500
397
  (await getInspectorPort())
501
398
  }
502
- isWorkersSite={Boolean(args.site || config.site)}
399
+ isWorkersSite={Boolean(args.site || configParam.site)}
503
400
  compatibilityDate={getDevCompatibilityDate(
504
- config,
401
+ configParam,
505
402
  args.compatibilityDate
506
403
  )}
507
404
  compatibilityFlags={
508
- args.compatibilityFlags || config.compatibility_flags
405
+ args.compatibilityFlags || configParam.compatibility_flags
509
406
  }
510
- usageModel={config.usage_model}
407
+ usageModel={configParam.usage_model}
511
408
  bindings={bindings}
512
- crons={config.triggers.crons}
409
+ crons={configParam.triggers.crons}
513
410
  logLevel={args.logLevel}
514
411
  logPrefix={args.logPrefix}
515
412
  onReady={args.onReady}
@@ -517,8 +414,8 @@ export async function startDev(args: StartDevOptions) {
517
414
  showInteractiveDevSession={args.showInteractiveDevSession}
518
415
  forceLocal={args.forceLocal}
519
416
  enablePagesAssetsServiceBinding={args.enablePagesAssetsServiceBinding}
520
- firstPartyWorker={config.first_party_worker}
521
- sendMetrics={config.send_metrics}
417
+ firstPartyWorker={configParam.first_party_worker}
418
+ sendMetrics={configParam.send_metrics}
522
419
  />
523
420
  );
524
421
  }
@@ -531,19 +428,120 @@ export async function startDev(args: StartDevOptions) {
531
428
  devReactElement.unmount();
532
429
  await watcher?.close();
533
430
  },
534
- fetch: async (init?: RequestInit) => {
535
- //TODO: we are not guaranteed to be assigned this port, we should fix this ASAP
536
- const port = args.port || config.dev.port || (await getLocalPort());
537
- const address = args.ip || config.dev.ip || "localhost";
538
-
539
- return await fetch(`http://${address}:${port}/`, init);
540
- },
541
431
  };
542
432
  } finally {
543
433
  await watcher?.close();
544
434
  }
545
435
  }
546
436
 
437
+ export async function startApiDev(args: StartDevOptions) {
438
+ if (args.logLevel) {
439
+ // we don't define a "none" logLevel, so "error" will do for now.
440
+ logger.loggerLevel = args.logLevel === "none" ? "error" : args.logLevel;
441
+ }
442
+ await printWranglerBanner();
443
+
444
+ const configPath =
445
+ (args.config as ConfigPath) ||
446
+ ((args.script &&
447
+ findWranglerToml(path.dirname(args.script))) as ConfigPath);
448
+ const config = readConfig(configPath, args);
449
+
450
+ const {
451
+ entry,
452
+ nodeCompat,
453
+ upstreamProtocol,
454
+ zoneId,
455
+ host,
456
+ routes,
457
+ getLocalPort,
458
+ getInspectorPort,
459
+ cliDefines,
460
+ } = await validateDevServerSettings(args, config);
461
+
462
+ await metrics.sendMetricsEvent(
463
+ "run dev (api)",
464
+ { local: args.local },
465
+ { sendMetrics: config.send_metrics, offline: args.local }
466
+ );
467
+
468
+ // eslint-disable-next-line no-inner-declarations
469
+ async function getDevServer(configParam: Config) {
470
+ const { assetPaths, bindings } = await getBindingsAndAssetPaths(
471
+ args,
472
+ configParam
473
+ );
474
+
475
+ return await startDevServer({
476
+ name: getScriptName({ name: args.name, env: args.env }, configParam),
477
+ noBundle: !(args.bundle ?? !configParam.no_bundle),
478
+ entry: entry,
479
+ env: args.env,
480
+ zone: zoneId,
481
+ host: host,
482
+ routes: routes,
483
+ rules: getRules(configParam),
484
+ legacyEnv: isLegacyEnv(configParam),
485
+ minify: args.minify ?? configParam.minify,
486
+ nodeCompat: nodeCompat,
487
+ build: configParam.build || {},
488
+ define: { ...config.define, ...cliDefines },
489
+ initialMode: args.local ? "local" : "remote",
490
+ jsxFactory: args["jsx-factory"] || configParam.jsx_factory,
491
+ jsxFragment: args["jsx-fragment"] || configParam.jsx_fragment,
492
+ tsconfig: args.tsconfig ?? configParam.tsconfig,
493
+ upstreamProtocol: upstreamProtocol,
494
+ localProtocol: args.localProtocol || configParam.dev.local_protocol,
495
+ localUpstream: args["local-upstream"] || host,
496
+ enableLocalPersistence: args.experimentalEnableLocalPersistence || false,
497
+ liveReload: args.liveReload || false,
498
+ accountId: configParam.account_id || getAccountFromCache()?.id,
499
+ assetPaths: assetPaths,
500
+ assetsConfig: configParam.assets,
501
+ //port can be 0, which means to use a random port
502
+ port:
503
+ args.port === 0
504
+ ? args.port
505
+ : args.port || configParam.dev.port || (await getLocalPort()),
506
+ ip: args.ip || configParam.dev.ip,
507
+ inspectorPort:
508
+ args["inspector-port"] ||
509
+ configParam.dev.inspector_port ||
510
+ (await getInspectorPort()),
511
+ isWorkersSite: Boolean(args.site || configParam.site),
512
+ compatibilityDate: getDevCompatibilityDate(
513
+ config,
514
+ args["compatibility-date"]
515
+ ),
516
+ compatibilityFlags:
517
+ args["compatibility-flags"] || configParam.compatibility_flags,
518
+ usageModel: configParam.usage_model,
519
+ bindings: bindings,
520
+ crons: configParam.triggers.crons,
521
+ logLevel: args.logLevel,
522
+ logPrefix: args.logPrefix,
523
+ onReady: args.onReady,
524
+ inspect: args.inspect ?? true,
525
+ showInteractiveDevSession: args.showInteractiveDevSession,
526
+ forceLocal: args.forceLocal,
527
+ enablePagesAssetsServiceBinding: args.enablePagesAssetsServiceBinding,
528
+ local: true,
529
+ firstPartyWorker: undefined,
530
+ sendMetrics: undefined,
531
+ });
532
+ }
533
+
534
+ const devServer = await getDevServer(config);
535
+ if (!devServer) {
536
+ throw logger.error("Failed to start dev server.");
537
+ }
538
+
539
+ return {
540
+ stop: async () => {
541
+ await devServer.stop();
542
+ },
543
+ };
544
+ }
547
545
  /**
548
546
  * Avoiding calling `getPort()` multiple times by memoizing the first result.
549
547
  */
@@ -553,6 +551,182 @@ function memoizeGetPort(defaultPort: number) {
553
551
  return portValue || (portValue = await getPort({ port: defaultPort }));
554
552
  };
555
553
  }
554
+ /**
555
+ * mask anything that was overridden in .dev.vars
556
+ * so that we don't log potential secrets into the terminal
557
+ */
558
+ function maskVars(bindings: CfWorkerInit["bindings"], configParam: Config) {
559
+ const maskedVars = { ...bindings.vars };
560
+ for (const key of Object.keys(maskedVars)) {
561
+ if (maskedVars[key] !== configParam.vars[key]) {
562
+ // This means it was overridden in .dev.vars
563
+ // so let's mask it
564
+ maskedVars[key] = "(hidden)";
565
+ }
566
+ }
567
+ return maskedVars;
568
+ }
569
+
570
+ async function getZoneIdHostAndRoutes(args: StartDevOptions, config: Config) {
571
+ // TODO: if worker_dev = false and no routes, then error (only for dev)
572
+ // Compute zone info from the `host` and `route` args and config;
573
+ let host = args.host || config.dev.host;
574
+ let zoneId: string | undefined;
575
+ const routes: Route[] | undefined =
576
+ args.routes || (config.route && [config.route]) || config.routes;
577
+
578
+ if (args.forceLocal) {
579
+ args.local = true;
580
+ }
581
+
582
+ if (!args.local) {
583
+ if (host) {
584
+ zoneId = await getZoneIdFromHost(host);
585
+ }
586
+ if (!zoneId && routes) {
587
+ const firstRoute = routes[0];
588
+ const zone = await getZoneForRoute(firstRoute);
589
+ if (zone) {
590
+ zoneId = zone.id;
591
+ host = zone.host;
592
+ }
593
+ }
594
+ } else if (!host) {
595
+ if (routes) {
596
+ const firstRoute = routes[0];
597
+ host = getHostFromRoute(firstRoute);
598
+ }
599
+ }
600
+ return { host, routes, zoneId };
601
+ }
602
+
603
+ async function validateDevServerSettings(
604
+ args: StartDevOptions,
605
+ config: Config
606
+ ) {
607
+ const entry = await getEntry(
608
+ { assets: args.assets, script: args.script },
609
+ config,
610
+ "dev"
611
+ );
612
+
613
+ const { zoneId, host, routes } = await getZoneIdHostAndRoutes(args, config);
614
+ const getLocalPort = memoizeGetPort(DEFAULT_LOCAL_PORT);
615
+ const getInspectorPort = memoizeGetPort(DEFAULT_INSPECTOR_PORT);
616
+
617
+ if (config.services && config.services.length > 0) {
618
+ logger.warn(
619
+ `This worker is bound to live services: ${config.services
620
+ .map(
621
+ (service) =>
622
+ `${service.binding} (${service.service}${
623
+ service.environment ? `@${service.environment}` : ""
624
+ })`
625
+ )
626
+ .join(", ")}`
627
+ );
628
+ }
629
+
630
+ if (args.inspect) {
631
+ //devtools are enabled by default, but we still need to disable them if the caller doesn't want them
632
+ logger.warn(
633
+ "Passing --inspect is unnecessary, now you can always connect to devtools."
634
+ );
635
+ }
636
+
637
+ if (args["experimental-public"]) {
638
+ throw new Error(
639
+ "The --experimental-public field has been renamed to --assets"
640
+ );
641
+ }
642
+
643
+ if (args.public) {
644
+ throw new Error("The --public field has been renamed to --assets");
645
+ }
646
+
647
+ if ((args.assets || config.assets) && (args.site || config.site)) {
648
+ throw new Error("Cannot use Assets and Workers Sites in the same Worker.");
649
+ }
650
+
651
+ if (args.assets) {
652
+ logger.warn(
653
+ "The --assets argument is experimental and may change or break at any time"
654
+ );
655
+ }
656
+
657
+ const upstreamProtocol =
658
+ args["upstream-protocol"] || config.dev.upstream_protocol;
659
+ if (upstreamProtocol === "http") {
660
+ logger.warn(
661
+ "Setting upstream-protocol to http is not currently implemented.\n" +
662
+ "If this is required in your project, please add your use case to the following issue:\n" +
663
+ "https://github.com/cloudflare/wrangler2/issues/583."
664
+ );
665
+ }
666
+ const nodeCompat = args.nodeCompat ?? config.node_compat;
667
+ if (nodeCompat) {
668
+ logger.warn(
669
+ "Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
670
+ );
671
+ }
672
+
673
+ const cliDefines =
674
+ args.define?.reduce<Record<string, string>>((collectDefines, d) => {
675
+ const [key, ...value] = d.split(":");
676
+ collectDefines[key] = value.join("");
677
+ return collectDefines;
678
+ }, {}) || {};
679
+
680
+ return {
681
+ entry,
682
+ upstreamProtocol,
683
+ nodeCompat,
684
+ getLocalPort,
685
+ getInspectorPort,
686
+ zoneId,
687
+ host,
688
+ routes,
689
+ cliDefines,
690
+ };
691
+ }
692
+
693
+ async function getBindingsAndAssetPaths(
694
+ args: StartDevOptions,
695
+ configParam: Config
696
+ ) {
697
+ const cliVars =
698
+ args.var?.reduce<Record<string, string>>((collectVars, v) => {
699
+ const [key, ...value] = v.split(":");
700
+ collectVars[key] = value.join("");
701
+ return collectVars;
702
+ }, {}) || {};
703
+
704
+ // now log all available bindings into the terminal
705
+ const bindings = await getBindings(configParam, {
706
+ kv: args.kv,
707
+ vars: { ...args.vars, ...cliVars },
708
+ durableObjects: args.durableObjects,
709
+ r2: args.r2,
710
+ });
711
+
712
+ const maskedVars = maskVars(bindings, configParam);
713
+
714
+ printBindings({
715
+ ...bindings,
716
+ vars: maskedVars,
717
+ });
718
+
719
+ const assetPaths =
720
+ args.assets || configParam.assets
721
+ ? getAssetPaths(configParam, args.assets)
722
+ : getSiteAssetPaths(
723
+ configParam,
724
+ args.site,
725
+ args.siteInclude,
726
+ args.siteExclude
727
+ );
728
+ return { assetPaths, bindings };
729
+ }
556
730
 
557
731
  async function getBindings(
558
732
  configParam: Config,
@@ -615,7 +789,7 @@ async function getBindings(
615
789
  ) || []),
616
790
  ...(args.r2 || []),
617
791
  ],
618
- worker_namespaces: configParam.worker_namespaces,
792
+ dispatch_namespaces: configParam.dispatch_namespaces,
619
793
  services: configParam.services,
620
794
  unsafe: configParam.unsafe?.bindings,
621
795
  logfwdr: configParam.logfwdr,
package/src/dialogs.tsx CHANGED
@@ -133,3 +133,15 @@ export function select(
133
133
  );
134
134
  });
135
135
  }
136
+
137
+ export async function fromDashMessagePrompt(
138
+ deploySource: string
139
+ ): Promise<boolean | void> {
140
+ if (deploySource === "dash") {
141
+ logger.warn(
142
+ `You are about to publish a Workers Service that was last published via the Cloudflare Dashboard.
143
+ Edits that have been made via the dashboard will be overridden by your local code and config.`
144
+ );
145
+ return await confirm("Would you like to continue?");
146
+ }
147
+ }