wrangler 0.0.0-e6e1daba → 0.0.0-e7cf0caa

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 (101) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +1 -1
  3. package/package.json +14 -9
  4. package/src/__tests__/api-devregistry.test.ts +121 -0
  5. package/src/__tests__/api.test.ts +27 -5
  6. package/src/__tests__/configuration.test.ts +294 -18
  7. package/src/__tests__/d1/execute.test.ts +3 -1
  8. package/src/__tests__/d1/migrate.test.ts +2 -0
  9. package/src/__tests__/delete.test.ts +6 -0
  10. package/src/__tests__/deployments.test.ts +335 -95
  11. package/src/__tests__/dev.test.tsx +87 -57
  12. package/src/__tests__/generate.test.ts +3 -4
  13. package/src/__tests__/helpers/mock-console.ts +6 -0
  14. package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
  15. package/src/__tests__/helpers/msw/index.ts +4 -2
  16. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  17. package/src/__tests__/index.test.ts +10 -4
  18. package/src/__tests__/init.test.ts +136 -104
  19. package/src/__tests__/jest.setup.ts +4 -0
  20. package/src/__tests__/kv.test.ts +9 -9
  21. package/src/__tests__/logger.test.ts +68 -2
  22. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  23. package/src/__tests__/middleware.test.ts +4 -3
  24. package/src/__tests__/mtls-certificates.test.ts +5 -2
  25. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  26. package/src/__tests__/pages/functions-build.test.ts +91 -41
  27. package/src/__tests__/pages/project-list.test.ts +2 -0
  28. package/src/__tests__/pages/project-upload.test.ts +43 -24
  29. package/src/__tests__/pages/publish.test.ts +267 -148
  30. package/src/__tests__/publish.test.ts +420 -164
  31. package/src/__tests__/pubsub.test.ts +3 -0
  32. package/src/__tests__/queues.test.ts +5 -2
  33. package/src/__tests__/test-old-node-version.js +3 -3
  34. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  35. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  36. package/src/__tests__/type-generation.test.ts +1 -0
  37. package/src/__tests__/user.test.ts +1 -1
  38. package/src/__tests__/worker-namespace.test.ts +1 -0
  39. package/src/api/dev.ts +10 -22
  40. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  41. package/src/api/pages/publish.tsx +38 -51
  42. package/src/bundle.ts +44 -13
  43. package/src/config/environment.ts +36 -4
  44. package/src/config/index.ts +30 -2
  45. package/src/config/validation-helpers.ts +1 -1
  46. package/src/config/validation.ts +149 -5
  47. package/src/create-worker-upload-form.ts +28 -3
  48. package/src/d1/backups.tsx +15 -11
  49. package/src/d1/create.tsx +20 -16
  50. package/src/d1/execute.tsx +22 -19
  51. package/src/d1/list.tsx +2 -2
  52. package/src/d1/migrations/apply.tsx +35 -29
  53. package/src/d1/migrations/create.tsx +15 -12
  54. package/src/d1/migrations/list.tsx +10 -7
  55. package/src/deployments.ts +260 -8
  56. package/src/dev/dev.tsx +4 -4
  57. package/src/dev/local.tsx +14 -16
  58. package/src/dev/start-server.ts +12 -16
  59. package/src/dev/use-esbuild.ts +11 -13
  60. package/src/dev/validate-dev-props.ts +9 -0
  61. package/src/dev-registry.ts +2 -1
  62. package/src/dev.tsx +28 -13
  63. package/src/entry.ts +18 -8
  64. package/src/generate/index.ts +2 -2
  65. package/src/index.ts +76 -23
  66. package/src/init.ts +144 -134
  67. package/src/logger.ts +18 -3
  68. package/src/metrics/send-event.ts +2 -1
  69. package/src/miniflare-cli/index.ts +1 -1
  70. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  71. package/src/module-collection.ts +91 -25
  72. package/src/pages/build.ts +277 -99
  73. package/src/pages/buildFunctions.ts +20 -10
  74. package/src/pages/deployments.tsx +3 -5
  75. package/src/pages/dev.ts +21 -21
  76. package/src/pages/errors.ts +1 -0
  77. package/src/pages/functions/buildPlugin.ts +57 -34
  78. package/src/pages/functions/buildWorker.ts +34 -31
  79. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  80. package/src/pages/projects.tsx +2 -5
  81. package/src/pages/publish.tsx +1 -10
  82. package/src/pages/upload.tsx +29 -9
  83. package/src/paths.ts +1 -1
  84. package/src/publish/index.ts +1 -1
  85. package/src/publish/publish.ts +29 -34
  86. package/src/queues/cli/commands/consumer/add.ts +6 -0
  87. package/src/queues/client.ts +1 -0
  88. package/src/secret/index.ts +2 -1
  89. package/src/traverse-module-graph.ts +53 -0
  90. package/src/type-generation.ts +1 -1
  91. package/src/user/user.ts +1 -1
  92. package/src/utils/render.ts +93 -0
  93. package/src/worker.ts +18 -1
  94. package/templates/d1-beta-facade.js +5 -2
  95. package/templates/gitignore +1 -0
  96. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  97. package/templates/tsconfig.init.json +1 -2
  98. package/templates/tsconfig.tsbuildinfo +1 -1
  99. package/wrangler-dist/cli.d.ts +33 -13
  100. package/wrangler-dist/cli.js +20732 -19984
  101. package/src/__tests__/api-devregistry.test.js +0 -64
package/src/dev.tsx CHANGED
@@ -229,7 +229,7 @@ export function devOptions(yargs: CommonYargsArgv) {
229
229
  type: "boolean",
230
230
  })
231
231
  .option("node-compat", {
232
- describe: "Enable node.js compatibility",
232
+ describe: "Enable Node.js compatibility",
233
233
  type: "boolean",
234
234
  })
235
235
  .option("experimental-enable-local-persistence", {
@@ -344,7 +344,6 @@ type StartDevOptions = DevArguments &
344
344
  disableDevRegistry?: boolean;
345
345
  enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
346
346
  onReady?: (ip: string, port: number) => void;
347
- logPrefix?: string;
348
347
  showInteractiveDevSession?: boolean;
349
348
  };
350
349
 
@@ -388,7 +387,8 @@ export async function startDev(args: StartDevOptions) {
388
387
 
389
388
  const {
390
389
  entry,
391
- nodeCompat,
390
+ legacyNodeCompat,
391
+ nodejsCompat,
392
392
  upstreamProtocol,
393
393
  zoneId,
394
394
  host,
@@ -427,7 +427,8 @@ export async function startDev(args: StartDevOptions) {
427
427
  rules={getRules(configParam)}
428
428
  legacyEnv={isLegacyEnv(configParam)}
429
429
  minify={args.minify ?? configParam.minify}
430
- nodeCompat={nodeCompat}
430
+ legacyNodeCompat={legacyNodeCompat}
431
+ nodejsCompat={nodejsCompat}
431
432
  build={configParam.build || {}}
432
433
  define={{ ...configParam.define, ...cliDefines }}
433
434
  initialMode={
@@ -465,7 +466,6 @@ export async function startDev(args: StartDevOptions) {
465
466
  bindings={bindings}
466
467
  crons={configParam.triggers.crons}
467
468
  queueConsumers={configParam.queues.consumers}
468
- logPrefix={args.logPrefix}
469
469
  onReady={args.onReady}
470
470
  inspect={args.inspect ?? true}
471
471
  showInteractiveDevSession={args.showInteractiveDevSession}
@@ -523,7 +523,8 @@ export async function startApiDev(args: StartDevOptions) {
523
523
 
524
524
  const {
525
525
  entry,
526
- nodeCompat,
526
+ legacyNodeCompat,
527
+ nodejsCompat,
527
528
  upstreamProtocol,
528
529
  zoneId,
529
530
  host,
@@ -562,7 +563,8 @@ export async function startApiDev(args: StartDevOptions) {
562
563
  rules: getRules(configParam),
563
564
  legacyEnv: isLegacyEnv(configParam),
564
565
  minify: args.minify ?? configParam.minify,
565
- nodeCompat: nodeCompat,
566
+ legacyNodeCompat,
567
+ nodejsCompat,
566
568
  build: configParam.build || {},
567
569
  define: { ...config.define, ...cliDefines },
568
570
  initialMode: args.local ? "local" : "remote",
@@ -596,7 +598,6 @@ export async function startApiDev(args: StartDevOptions) {
596
598
  bindings: bindings,
597
599
  crons: configParam.triggers.crons,
598
600
  queueConsumers: configParam.queues.consumers,
599
- logPrefix: args.logPrefix,
600
601
  onReady: args.onReady,
601
602
  inspect: args.inspect ?? true,
602
603
  showInteractiveDevSession: args.showInteractiveDevSession,
@@ -742,10 +743,19 @@ async function validateDevServerSettings(
742
743
  "https://github.com/cloudflare/workers-sdk/issues/583."
743
744
  );
744
745
  }
745
- const nodeCompat = args.nodeCompat ?? config.node_compat;
746
- if (nodeCompat) {
746
+ const legacyNodeCompat = args.nodeCompat ?? config.node_compat;
747
+ if (legacyNodeCompat) {
747
748
  logger.warn(
748
- "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."
749
+ "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."
750
+ );
751
+ }
752
+
753
+ const compatibilityFlags =
754
+ args.compatibilityFlags ?? config.compatibility_flags;
755
+ const nodejsCompat = compatibilityFlags?.includes("nodejs_compat");
756
+ if (legacyNodeCompat && nodejsCompat) {
757
+ throw new Error(
758
+ "The `nodejs_compat` compatibility flag cannot be used in conjunction with the legacy `--node-compat` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the `--node-compat` argument from your CLI command or `node_compat = true` from your config file."
749
759
  );
750
760
  }
751
761
 
@@ -768,7 +778,8 @@ async function validateDevServerSettings(
768
778
  return {
769
779
  entry,
770
780
  upstreamProtocol,
771
- nodeCompat,
781
+ legacyNodeCompat,
782
+ nodejsCompat,
772
783
  getLocalPort,
773
784
  getInspectorPort,
774
785
  zoneId,
@@ -841,6 +852,7 @@ function getBindings(
841
852
  ),
842
853
  ...(args.kv || []),
843
854
  ],
855
+ send_email: configParam.send_email,
844
856
  // Use a copy of combinedVars since we're modifying it later
845
857
  vars: {
846
858
  ...getVarsForDev(configParam, env),
@@ -882,7 +894,10 @@ function getBindings(
882
894
  mtls_certificates: configParam.mtls_certificates,
883
895
  services: configParam.services,
884
896
  analytics_engine_datasets: configParam.analytics_engine_datasets,
885
- unsafe: configParam.unsafe?.bindings,
897
+ unsafe: {
898
+ bindings: configParam.unsafe.bindings,
899
+ metadata: configParam.unsafe.metadata,
900
+ },
886
901
  logfwdr: configParam.logfwdr,
887
902
  d1_databases: identifyD1BindingsAsBeta([
888
903
  ...(configParam.d1_databases ?? []).map((d1Db) => {
package/src/entry.ts CHANGED
@@ -3,6 +3,7 @@ import { existsSync, statSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import * as esbuild from "esbuild";
5
5
  import { execaCommand } from "execa";
6
+ import { COMMON_ESBUILD_OPTIONS } from "./bundle";
6
7
  import { logger } from "./logger";
7
8
  import { getBasePath } from "./paths";
8
9
  import type { Config } from "./config";
@@ -15,7 +16,16 @@ import type { Metafile } from "esbuild";
15
16
  *
16
17
  * It consists not just of a `file`, but also of a `directory` that is used to resolve relative paths.
17
18
  */
18
- export type Entry = { file: string; directory: string; format: CfScriptFormat };
19
+ export type Entry = {
20
+ /** A worker's entrypoint */
21
+ file: string;
22
+ /** A worker's directory. Usually where the wrangler.toml file is located */
23
+ directory: string;
24
+ /** Is this a module worker or a service worker? */
25
+ format: CfScriptFormat;
26
+ /** The directory that contains all of a `--no-bundle` worker's modules. Usually `${directory}/src`. Defaults to path.dirname(file) */
27
+ moduleRoot: string;
28
+ };
19
29
 
20
30
  /**
21
31
  * Compute the entry-point for the Worker.
@@ -99,7 +109,12 @@ export async function getEntry(
99
109
  );
100
110
  }
101
111
 
102
- return { file, directory, format };
112
+ return {
113
+ file,
114
+ directory,
115
+ format,
116
+ moduleRoot: config.base_dir ?? path.dirname(file),
117
+ };
103
118
  }
104
119
 
105
120
  export async function runCustomBuild(
@@ -147,17 +162,12 @@ export default async function guessWorkerFormat(
147
162
  tsconfig?: string | undefined
148
163
  ): Promise<CfScriptFormat> {
149
164
  const result = await esbuild.build({
165
+ ...COMMON_ESBUILD_OPTIONS,
150
166
  entryPoints: [entryFile],
151
167
  absWorkingDir: entryWorkingDirectory,
152
168
  metafile: true,
153
169
  bundle: false,
154
- target: "es2022",
155
170
  write: false,
156
- loader: {
157
- ".js": "jsx",
158
- ".mjs": "jsx",
159
- ".cjs": "jsx",
160
- },
161
171
  ...(tsconfig && { tsconfig }),
162
172
  });
163
173
  // result.metafile is defined because of the `metafile: true` option above.
@@ -269,8 +269,8 @@ function parseTemplatePath(templatePath: string): {
269
269
  if (!templatePath.includes("/")) {
270
270
  // template is a cloudflare canonical template, it doesn't include a slash in the name
271
271
  return {
272
- remote: "https://github.com/cloudflare/templates.git",
273
- subdirectory: templatePath,
272
+ remote: "https://github.com/cloudflare/workers-sdk.git",
273
+ subdirectory: `templates/${templatePath}`,
274
274
  };
275
275
  }
276
276
 
package/src/index.ts CHANGED
@@ -9,7 +9,12 @@ import { isBuildFailure } from "./bundle";
9
9
  import { loadDotEnv, readConfig } from "./config";
10
10
  import { d1 } from "./d1";
11
11
  import { deleteHandler, deleteOptions } from "./delete";
12
- import { deployments } from "./deployments";
12
+ import {
13
+ deployments,
14
+ commonDeploymentCMDSetup,
15
+ rollbackDeployment,
16
+ viewDeployment,
17
+ } from "./deployments";
13
18
  import {
14
19
  buildHandler,
15
20
  buildOptions,
@@ -41,13 +46,7 @@ import { secret, secretBulkHandler, secretBulkOptions } from "./secret";
41
46
  import { tailOptions, tailHandler } from "./tail";
42
47
  import { generateTypes } from "./type-generation";
43
48
  import { updateCheck } from "./update-check";
44
- import {
45
- listScopes,
46
- login,
47
- logout,
48
- requireAuth,
49
- validateScopeKeys,
50
- } from "./user";
49
+ import { listScopes, login, logout, validateScopeKeys } from "./user";
51
50
  import { whoami } from "./whoami";
52
51
 
53
52
  import type { Config } from "./config";
@@ -567,7 +566,7 @@ export function createCLIParser(argv: string[]) {
567
566
  analytics_engine_datasets: config.analytics_engine_datasets,
568
567
  dispatch_namespaces: config.dispatch_namespaces,
569
568
  logfwdr: config.logfwdr,
570
- unsafe: { bindings: config.unsafe?.bindings },
569
+ unsafe: config.unsafe,
571
570
  rules: config.rules,
572
571
  queues: config.queues,
573
572
  };
@@ -581,27 +580,81 @@ export function createCLIParser(argv: string[]) {
581
580
  "🚧`wrangler deployments` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose";
582
581
  wrangler.command(
583
582
  "deployments",
584
- "🚢 Displays the 10 most recent deployments for a worker",
583
+ "🚢 List and view details for deployments",
585
584
  (yargs) =>
586
585
  yargs
587
586
  .option("name", {
588
587
  describe: "The name of your worker",
589
588
  type: "string",
590
589
  })
591
- .epilogue(deploymentsWarning),
592
- async (deploymentsYargs) => {
593
- await printWranglerBanner();
594
- const config = readConfig(deploymentsYargs.config, deploymentsYargs);
595
- const accountId = await requireAuth(config);
596
- const scriptName = getScriptName(
597
- { name: deploymentsYargs.name, env: undefined },
598
- config
599
- );
600
-
601
- logger.log(`${deploymentsWarning}\n`);
602
- await deployments(accountId, scriptName, config);
603
- }
590
+ .command(
591
+ "list",
592
+ "🚢 Displays the 10 most recent deployments for a worker",
593
+ async (listYargs) => listYargs,
594
+ async (listYargs) => {
595
+ const { accountId, scriptName, config } =
596
+ await commonDeploymentCMDSetup(listYargs, deploymentsWarning);
597
+ await deployments(accountId, scriptName, config);
598
+ }
599
+ )
600
+ .command(
601
+ "view [deployment-id]",
602
+ "🔍 View a deployment",
603
+ async (viewYargs) =>
604
+ viewYargs.positional("deployment-id", {
605
+ describe: "The ID of the deployment you want to inspect",
606
+ type: "string",
607
+ demandOption: false,
608
+ }),
609
+ async (viewYargs) => {
610
+ const { accountId, scriptName, config } =
611
+ await commonDeploymentCMDSetup(viewYargs, deploymentsWarning);
612
+
613
+ await viewDeployment(
614
+ accountId,
615
+ scriptName,
616
+ config,
617
+ viewYargs.deploymentId
618
+ );
619
+ }
620
+ )
621
+ .command(subHelp)
622
+ .epilogue(deploymentsWarning)
604
623
  );
624
+ const rollbackWarning =
625
+ "🚧`wrangler rollback` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose";
626
+ wrangler
627
+ .command(
628
+ "rollback [deployment-id]",
629
+ "🔙 Rollback a deployment",
630
+ (rollbackYargs) =>
631
+ rollbackYargs
632
+ .positional("deployment-id", {
633
+ describe: "The ID of the deployment to rollback to",
634
+ type: "string",
635
+ demandOption: false,
636
+ })
637
+ .option("message", {
638
+ alias: "m",
639
+ describe:
640
+ "Skip confirmation and message prompts, uses provided argument as message",
641
+ type: "string",
642
+ default: undefined,
643
+ }),
644
+ async (rollbackYargs) => {
645
+ const { accountId, scriptName, config } =
646
+ await commonDeploymentCMDSetup(rollbackYargs, rollbackWarning);
647
+
648
+ await rollbackDeployment(
649
+ accountId,
650
+ scriptName,
651
+ config,
652
+ rollbackYargs.deploymentId,
653
+ rollbackYargs.message
654
+ );
655
+ }
656
+ )
657
+ .epilogue(rollbackWarning);
605
658
 
606
659
  // This set to false to allow overwrite of default behaviour
607
660
  wrangler.version(false);
package/src/init.ts CHANGED
@@ -19,7 +19,10 @@ import { CommandLineArgsError, printWranglerBanner } from "./index";
19
19
 
20
20
  import type { RawConfig } from "./config";
21
21
  import type { Route, SimpleRoute } from "./config/environment";
22
- import type { WorkerMetadata } from "./create-worker-upload-form";
22
+ import type {
23
+ WorkerMetadata,
24
+ WorkerMetadataBinding,
25
+ } from "./create-worker-upload-form";
23
26
  import type { PackageManager } from "./package-manager";
24
27
  import type { PackageJSON } from "./parse";
25
28
  import type {
@@ -838,139 +841,7 @@ async function getWorkerConfig(
838
841
  );
839
842
  });
840
843
 
841
- const mappedBindings = bindings
842
- .filter((binding) => (binding.type as string) !== "secret_text")
843
- // Combine the same types into {[type]: [binding]}
844
- .reduce((configObj, binding) => {
845
- // Some types have different names in wrangler.toml
846
- // I want the type safety of the binding being destructured after the case narrowing the union but type is unused
847
-
848
- switch (binding.type) {
849
- case "plain_text":
850
- {
851
- configObj.vars = {
852
- ...(configObj.vars ?? {}),
853
- [binding.name]: binding.text,
854
- };
855
- }
856
- break;
857
- case "json":
858
- {
859
- configObj.vars = {
860
- ...(configObj.vars ?? {}),
861
- name: binding.name,
862
- json: binding.json,
863
- };
864
- }
865
- break;
866
- case "kv_namespace":
867
- {
868
- configObj.kv_namespaces = [
869
- ...(configObj.kv_namespaces ?? []),
870
- { id: binding.namespace_id, binding: binding.name },
871
- ];
872
- }
873
- break;
874
- case "durable_object_namespace":
875
- {
876
- configObj.durable_objects = {
877
- bindings: [
878
- ...(configObj.durable_objects?.bindings ?? []),
879
- {
880
- name: binding.name,
881
- class_name: binding.class_name,
882
- script_name: binding.script_name,
883
- environment: binding.environment,
884
- },
885
- ],
886
- };
887
- }
888
- break;
889
- case "r2_bucket":
890
- {
891
- configObj.r2_buckets = [
892
- ...(configObj.r2_buckets ?? []),
893
- { binding: binding.name, bucket_name: binding.bucket_name },
894
- ];
895
- }
896
- break;
897
- case "service":
898
- {
899
- configObj.services = [
900
- ...(configObj.services ?? []),
901
- {
902
- binding: binding.name,
903
- service: binding.service,
904
- environment: binding.environment,
905
- },
906
- ];
907
- }
908
- break;
909
- case "analytics_engine":
910
- {
911
- configObj.analytics_engine_datasets = [
912
- ...(configObj.analytics_engine_datasets ?? []),
913
- { binding: binding.name, dataset: binding.dataset },
914
- ];
915
- }
916
- break;
917
- case "dispatch_namespace":
918
- {
919
- configObj.dispatch_namespaces = [
920
- ...(configObj.dispatch_namespaces ?? []),
921
- { binding: binding.name, namespace: binding.namespace },
922
- ];
923
- }
924
- break;
925
- case "logfwdr":
926
- {
927
- configObj.logfwdr = {
928
- // TODO: Messaging about adding schema file path
929
- schema: "",
930
- bindings: [
931
- ...(configObj.logfwdr?.bindings ?? []),
932
- { name: binding.name, destination: binding.destination },
933
- ],
934
- };
935
- }
936
- break;
937
- case "wasm_module":
938
- {
939
- configObj.wasm_modules = {
940
- ...(configObj.wasm_modules ?? {}),
941
- [binding.name]: binding.part,
942
- };
943
- }
944
- break;
945
- case "text_blob":
946
- {
947
- configObj.text_blobs = {
948
- ...(configObj.text_blobs ?? {}),
949
- [binding.name]: binding.part,
950
- };
951
- }
952
- break;
953
- case "data_blob":
954
- {
955
- configObj.data_blobs = {
956
- ...(configObj.data_blobs ?? {}),
957
- [binding.name]: binding.part,
958
- };
959
- }
960
- break;
961
- default: {
962
- // If we don't know what the type is, its an unsafe binding
963
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
964
- if (!(binding as any)?.type) break;
965
- configObj.unsafe = {
966
- bindings: [...(configObj.unsafe?.bindings ?? []), binding],
967
- };
968
- }
969
- }
970
-
971
- return configObj;
972
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
973
- }, {} as RawConfig);
844
+ const mappedBindings = mapBindings(bindings);
974
845
 
975
846
  const durableObjectClassNames = bindings
976
847
  .filter((binding) => binding.type === "durable_object_namespace")
@@ -1020,3 +891,142 @@ async function getWorkerConfig(
1020
891
  ...mappedBindings,
1021
892
  };
1022
893
  }
894
+
895
+ export function mapBindings(bindings: WorkerMetadataBinding[]): RawConfig {
896
+ return (
897
+ bindings
898
+ .filter((binding) => (binding.type as string) !== "secret_text")
899
+ // Combine the same types into {[type]: [binding]}
900
+ .reduce((configObj, binding) => {
901
+ // Some types have different names in wrangler.toml
902
+ // I want the type safety of the binding being destructured after the case narrowing the union but type is unused
903
+
904
+ switch (binding.type) {
905
+ case "plain_text":
906
+ {
907
+ configObj.vars = {
908
+ ...(configObj.vars ?? {}),
909
+ [binding.name]: binding.text,
910
+ };
911
+ }
912
+ break;
913
+ case "json":
914
+ {
915
+ configObj.vars = {
916
+ ...(configObj.vars ?? {}),
917
+ name: binding.name,
918
+ json: binding.json,
919
+ };
920
+ }
921
+ break;
922
+ case "kv_namespace":
923
+ {
924
+ configObj.kv_namespaces = [
925
+ ...(configObj.kv_namespaces ?? []),
926
+ { id: binding.namespace_id, binding: binding.name },
927
+ ];
928
+ }
929
+ break;
930
+ case "durable_object_namespace":
931
+ {
932
+ configObj.durable_objects = {
933
+ bindings: [
934
+ ...(configObj.durable_objects?.bindings ?? []),
935
+ {
936
+ name: binding.name,
937
+ class_name: binding.class_name,
938
+ script_name: binding.script_name,
939
+ environment: binding.environment,
940
+ },
941
+ ],
942
+ };
943
+ }
944
+ break;
945
+ case "r2_bucket":
946
+ {
947
+ configObj.r2_buckets = [
948
+ ...(configObj.r2_buckets ?? []),
949
+ { binding: binding.name, bucket_name: binding.bucket_name },
950
+ ];
951
+ }
952
+ break;
953
+ case "service":
954
+ {
955
+ configObj.services = [
956
+ ...(configObj.services ?? []),
957
+ {
958
+ binding: binding.name,
959
+ service: binding.service,
960
+ environment: binding.environment,
961
+ },
962
+ ];
963
+ }
964
+ break;
965
+ case "analytics_engine":
966
+ {
967
+ configObj.analytics_engine_datasets = [
968
+ ...(configObj.analytics_engine_datasets ?? []),
969
+ { binding: binding.name, dataset: binding.dataset },
970
+ ];
971
+ }
972
+ break;
973
+ case "dispatch_namespace":
974
+ {
975
+ configObj.dispatch_namespaces = [
976
+ ...(configObj.dispatch_namespaces ?? []),
977
+ { binding: binding.name, namespace: binding.namespace },
978
+ ];
979
+ }
980
+ break;
981
+ case "logfwdr":
982
+ {
983
+ configObj.logfwdr = {
984
+ // TODO: Messaging about adding schema file path
985
+ schema: "",
986
+ bindings: [
987
+ ...(configObj.logfwdr?.bindings ?? []),
988
+ { name: binding.name, destination: binding.destination },
989
+ ],
990
+ };
991
+ }
992
+ break;
993
+ case "wasm_module":
994
+ {
995
+ configObj.wasm_modules = {
996
+ ...(configObj.wasm_modules ?? {}),
997
+ [binding.name]: binding.part,
998
+ };
999
+ }
1000
+ break;
1001
+ case "text_blob":
1002
+ {
1003
+ configObj.text_blobs = {
1004
+ ...(configObj.text_blobs ?? {}),
1005
+ [binding.name]: binding.part,
1006
+ };
1007
+ }
1008
+ break;
1009
+ case "data_blob":
1010
+ {
1011
+ configObj.data_blobs = {
1012
+ ...(configObj.data_blobs ?? {}),
1013
+ [binding.name]: binding.part,
1014
+ };
1015
+ }
1016
+ break;
1017
+ default: {
1018
+ // If we don't know what the type is, its an unsafe binding
1019
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1020
+ if (!(binding as any)?.type) break;
1021
+ configObj.unsafe = {
1022
+ bindings: [...(configObj.unsafe?.bindings ?? []), binding],
1023
+ metadata: configObj.unsafe?.metadata ?? undefined,
1024
+ };
1025
+ }
1026
+ }
1027
+
1028
+ return configObj;
1029
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1030
+ }, {} as RawConfig)
1031
+ );
1032
+ }
package/src/logger.ts CHANGED
@@ -26,15 +26,30 @@ const LOGGER_LEVEL_FORMAT_TYPE_MAP = {
26
26
 
27
27
  const getLogLevelFromEnv = getEnvironmentVariableFactory({
28
28
  variableName: "WRANGLER_LOG",
29
- defaultValue: () => "log",
30
29
  });
31
30
 
31
+ function getLoggerLevel(): LoggerLevel {
32
+ const fromEnv = getLogLevelFromEnv()?.toLowerCase();
33
+ if (fromEnv !== undefined) {
34
+ if (fromEnv in LOGGER_LEVELS) return fromEnv as LoggerLevel;
35
+ const expected = Object.keys(LOGGER_LEVELS)
36
+ .map((level) => `"${level}"`)
37
+ .join(" | ");
38
+ console.warn(
39
+ `Unrecognised WRANGLER_LOG value ${JSON.stringify(
40
+ fromEnv
41
+ )}, expected ${expected}, defaulting to "log"...`
42
+ );
43
+ }
44
+ return "log";
45
+ }
46
+
32
47
  export type TableRow<Keys extends string> = Record<Keys, string>;
33
48
 
34
- class Logger {
49
+ export class Logger {
35
50
  constructor() {}
36
51
 
37
- loggerLevel: LoggerLevel = (getLogLevelFromEnv() as LoggerLevel) ?? "log";
52
+ loggerLevel = getLoggerLevel();
38
53
  columns = process.stdout.columns;
39
54
 
40
55
  debug = (...args: unknown[]) => this.doLog("debug", args);
@@ -57,7 +57,8 @@ export type EventNames =
57
57
  | "run dev (api)"
58
58
  | "run pages dev"
59
59
  | "view docs"
60
- | "view deployments";
60
+ | "view deployments"
61
+ | "rollback deployments";
61
62
 
62
63
  /**
63
64
  * Send a metrics event, with no extra properties, to Cloudflare, if usage tracking is enabled.
@@ -47,7 +47,7 @@ async function main() {
47
47
  config.log =
48
48
  logLevel === MiniflareLogLevel.NONE
49
49
  ? new MiniflareNoOpLog()
50
- : new MiniflareLog(logLevel, config.logOptions);
50
+ : new MiniflareLog(logLevel);
51
51
 
52
52
  if (logLevel === MiniflareLogLevel.DEBUG) {
53
53
  console.log("MINIFLARE OPTIONS:\n", JSON.stringify(config, null, 2));