wrangler 0.0.0-e33294b0 → 0.0.0-e351afcf

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 (127) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +183 -92
  3. package/package.json +15 -10
  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__/constellation.test.ts +371 -0
  8. package/src/__tests__/d1/execute.test.ts +3 -1
  9. package/src/__tests__/d1/migrate.test.ts +102 -0
  10. package/src/__tests__/delete.test.ts +6 -0
  11. package/src/__tests__/deployments.test.ts +335 -95
  12. package/src/__tests__/dev.test.tsx +87 -57
  13. package/src/__tests__/generate.test.ts +3 -4
  14. package/src/__tests__/guess-worker-format.test.ts +35 -0
  15. package/src/__tests__/helpers/mock-console.ts +6 -0
  16. package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
  17. package/src/__tests__/helpers/msw/index.ts +4 -2
  18. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  19. package/src/__tests__/index.test.ts +14 -6
  20. package/src/__tests__/init.test.ts +136 -104
  21. package/src/__tests__/jest.setup.ts +4 -0
  22. package/src/__tests__/kv.test.ts +9 -9
  23. package/src/__tests__/logger.test.ts +68 -2
  24. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  25. package/src/__tests__/middleware.test.ts +4 -3
  26. package/src/__tests__/mtls-certificates.test.ts +7 -3
  27. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  28. package/src/__tests__/pages/functions-build.test.ts +159 -39
  29. package/src/__tests__/pages/project-list.test.ts +2 -0
  30. package/src/__tests__/pages/project-upload.test.ts +43 -24
  31. package/src/__tests__/pages/publish.test.ts +267 -148
  32. package/src/__tests__/publish.test.ts +1040 -339
  33. package/src/__tests__/pubsub.test.ts +3 -0
  34. package/src/__tests__/queues.test.ts +5 -2
  35. package/src/__tests__/test-old-node-version.js +3 -3
  36. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  37. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  38. package/src/__tests__/type-generation.test.ts +1 -0
  39. package/src/__tests__/user.test.ts +2 -2
  40. package/src/__tests__/worker-namespace.test.ts +1 -0
  41. package/src/api/dev.ts +15 -22
  42. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  43. package/src/api/pages/publish.tsx +64 -61
  44. package/src/bundle.ts +51 -16
  45. package/src/config/environment.ts +36 -4
  46. package/src/config/index.ts +30 -2
  47. package/src/config/validation-helpers.ts +1 -1
  48. package/src/config/validation.ts +149 -5
  49. package/src/constellation/createProject.tsx +51 -0
  50. package/src/constellation/deleteProject.ts +51 -0
  51. package/src/constellation/deleteProjectModel.ts +68 -0
  52. package/src/constellation/index.ts +75 -0
  53. package/src/constellation/listCatalog.tsx +35 -0
  54. package/src/constellation/listModel.tsx +41 -0
  55. package/src/constellation/listProject.tsx +28 -0
  56. package/src/constellation/listRuntime.tsx +28 -0
  57. package/src/constellation/options.ts +17 -0
  58. package/src/constellation/types.ts +17 -0
  59. package/src/constellation/uploadModel.tsx +64 -0
  60. package/src/constellation/utils.ts +90 -0
  61. package/src/create-worker-preview.ts +19 -8
  62. package/src/create-worker-upload-form.ts +28 -3
  63. package/src/d1/backups.tsx +19 -15
  64. package/src/d1/create.tsx +45 -39
  65. package/src/d1/delete.ts +1 -1
  66. package/src/d1/execute.tsx +23 -20
  67. package/src/d1/list.tsx +14 -12
  68. package/src/d1/migrations/apply.tsx +36 -30
  69. package/src/d1/migrations/create.tsx +15 -12
  70. package/src/d1/migrations/helpers.ts +5 -8
  71. package/src/d1/migrations/list.tsx +10 -7
  72. package/src/deployments.ts +260 -8
  73. package/src/dev/dev.tsx +6 -4
  74. package/src/dev/local.tsx +65 -40
  75. package/src/dev/start-server.ts +57 -52
  76. package/src/dev/use-esbuild.ts +59 -52
  77. package/src/dev/validate-dev-props.ts +9 -0
  78. package/src/dev-registry.ts +2 -1
  79. package/src/dev.tsx +38 -18
  80. package/src/docs/helpers.ts +50 -0
  81. package/src/docs/index.ts +25 -68
  82. package/src/entry.ts +19 -9
  83. package/src/environment-variables/factory.ts +2 -1
  84. package/src/generate/index.ts +2 -2
  85. package/src/index.ts +87 -24
  86. package/src/init.ts +144 -134
  87. package/src/inspect.ts +16 -1
  88. package/src/kv/helpers.ts +7 -4
  89. package/src/logger.ts +23 -4
  90. package/src/metrics/send-event.ts +2 -1
  91. package/src/miniflare-cli/assets.ts +8 -7
  92. package/src/miniflare-cli/index.ts +3 -3
  93. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  94. package/src/module-collection.ts +92 -26
  95. package/src/pages/build.ts +290 -100
  96. package/src/pages/buildFunctions.ts +20 -10
  97. package/src/pages/deployments.tsx +3 -5
  98. package/src/pages/dev.ts +44 -26
  99. package/src/pages/errors.ts +1 -0
  100. package/src/pages/functions/buildPlugin.ts +57 -34
  101. package/src/pages/functions/buildWorker.ts +91 -31
  102. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  103. package/src/pages/projects.tsx +2 -5
  104. package/src/pages/publish.tsx +1 -10
  105. package/src/pages/upload.tsx +29 -9
  106. package/src/paths.ts +1 -1
  107. package/src/publish/index.ts +1 -1
  108. package/src/publish/publish.ts +29 -34
  109. package/src/queues/cli/commands/consumer/add.ts +6 -0
  110. package/src/queues/client.ts +1 -0
  111. package/src/r2/helpers.ts +1 -0
  112. package/src/secret/index.ts +2 -1
  113. package/src/sites.ts +164 -52
  114. package/src/traverse-module-graph.ts +53 -0
  115. package/src/type-generation.ts +1 -1
  116. package/src/user/user.ts +2 -1
  117. package/src/utils/render.ts +93 -0
  118. package/src/worker.ts +18 -1
  119. package/templates/d1-beta-facade.js +5 -2
  120. package/templates/gitignore +1 -0
  121. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  122. package/templates/pages-template-plugin.ts +7 -3
  123. package/templates/tsconfig.init.json +1 -2
  124. package/templates/tsconfig.tsbuildinfo +1 -1
  125. package/wrangler-dist/cli.d.ts +552 -16
  126. package/wrangler-dist/cli.js +32141 -24052
  127. package/src/__tests__/api-devregistry.test.js +0 -64
package/src/dev.tsx CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  printWranglerBanner,
29
29
  } from "./index";
30
30
  import type { Config, Environment } from "./config";
31
- import type { Route } from "./config/environment";
31
+ import type { Route, Rule } from "./config/environment";
32
32
  import type { LoggerLevel } from "./logger";
33
33
  import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types";
34
34
  import type { CfWorkerInit } from "./worker";
@@ -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", {
@@ -334,6 +334,9 @@ export type AdditionalDevProps = {
334
334
  preview_bucket_name?: string;
335
335
  }[];
336
336
  d1Databases?: Environment["d1_databases"];
337
+ processEntrypoint?: boolean;
338
+ moduleRoot?: string;
339
+ rules?: Rule[];
337
340
  };
338
341
 
339
342
  type StartDevOptions = DevArguments &
@@ -344,7 +347,6 @@ type StartDevOptions = DevArguments &
344
347
  disableDevRegistry?: boolean;
345
348
  enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
346
349
  onReady?: (ip: string, port: number) => void;
347
- logPrefix?: string;
348
350
  showInteractiveDevSession?: boolean;
349
351
  };
350
352
 
@@ -388,7 +390,8 @@ export async function startDev(args: StartDevOptions) {
388
390
 
389
391
  const {
390
392
  entry,
391
- nodeCompat,
393
+ legacyNodeCompat,
394
+ nodejsCompat,
392
395
  upstreamProtocol,
393
396
  zoneId,
394
397
  host,
@@ -424,10 +427,12 @@ export async function startDev(args: StartDevOptions) {
424
427
  zone={zoneId}
425
428
  host={host}
426
429
  routes={routes}
427
- rules={getRules(configParam)}
430
+ processEntrypoint={!!args.processEntrypoint}
431
+ rules={args.rules ?? getRules(configParam)}
428
432
  legacyEnv={isLegacyEnv(configParam)}
429
433
  minify={args.minify ?? configParam.minify}
430
- nodeCompat={nodeCompat}
434
+ legacyNodeCompat={legacyNodeCompat}
435
+ nodejsCompat={nodejsCompat}
431
436
  build={configParam.build || {}}
432
437
  define={{ ...configParam.define, ...cliDefines }}
433
438
  initialMode={
@@ -465,7 +470,6 @@ export async function startDev(args: StartDevOptions) {
465
470
  bindings={bindings}
466
471
  crons={configParam.triggers.crons}
467
472
  queueConsumers={configParam.queues.consumers}
468
- logPrefix={args.logPrefix}
469
473
  onReady={args.onReady}
470
474
  inspect={args.inspect ?? true}
471
475
  showInteractiveDevSession={args.showInteractiveDevSession}
@@ -523,7 +527,8 @@ export async function startApiDev(args: StartDevOptions) {
523
527
 
524
528
  const {
525
529
  entry,
526
- nodeCompat,
530
+ legacyNodeCompat,
531
+ nodejsCompat,
527
532
  upstreamProtocol,
528
533
  zoneId,
529
534
  host,
@@ -559,10 +564,12 @@ export async function startApiDev(args: StartDevOptions) {
559
564
  zone: zoneId,
560
565
  host: host,
561
566
  routes: routes,
562
- rules: getRules(configParam),
567
+ processEntrypoint: !!args.processEntrypoint,
568
+ rules: args.rules ?? getRules(configParam),
563
569
  legacyEnv: isLegacyEnv(configParam),
564
570
  minify: args.minify ?? configParam.minify,
565
- nodeCompat: nodeCompat,
571
+ legacyNodeCompat,
572
+ nodejsCompat,
566
573
  build: configParam.build || {},
567
574
  define: { ...config.define, ...cliDefines },
568
575
  initialMode: args.local ? "local" : "remote",
@@ -596,7 +603,6 @@ export async function startApiDev(args: StartDevOptions) {
596
603
  bindings: bindings,
597
604
  crons: configParam.triggers.crons,
598
605
  queueConsumers: configParam.queues.consumers,
599
- logPrefix: args.logPrefix,
600
606
  onReady: args.onReady,
601
607
  inspect: args.inspect ?? true,
602
608
  showInteractiveDevSession: args.showInteractiveDevSession,
@@ -660,7 +666,7 @@ async function getZoneIdHostAndRoutes(args: StartDevOptions, config: Config) {
660
666
  args.local = true;
661
667
  }
662
668
 
663
- if (!args.local) {
669
+ if (!args.local && !args.experimentalLocal) {
664
670
  if (host) {
665
671
  zoneId = await getZoneIdFromHost(host);
666
672
  }
@@ -686,7 +692,7 @@ async function validateDevServerSettings(
686
692
  config: Config
687
693
  ) {
688
694
  const entry = await getEntry(
689
- { assets: args.assets, script: args.script },
695
+ { assets: args.assets, script: args.script, moduleRoot: args.moduleRoot },
690
696
  config,
691
697
  "dev"
692
698
  );
@@ -742,10 +748,19 @@ async function validateDevServerSettings(
742
748
  "https://github.com/cloudflare/workers-sdk/issues/583."
743
749
  );
744
750
  }
745
- const nodeCompat = args.nodeCompat ?? config.node_compat;
746
- if (nodeCompat) {
751
+ const legacyNodeCompat = args.nodeCompat ?? config.node_compat;
752
+ if (legacyNodeCompat) {
747
753
  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."
754
+ "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."
755
+ );
756
+ }
757
+
758
+ const compatibilityFlags =
759
+ args.compatibilityFlags ?? config.compatibility_flags;
760
+ const nodejsCompat = compatibilityFlags?.includes("nodejs_compat");
761
+ if (legacyNodeCompat && nodejsCompat) {
762
+ throw new Error(
763
+ "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
764
  );
750
765
  }
751
766
 
@@ -768,7 +783,8 @@ async function validateDevServerSettings(
768
783
  return {
769
784
  entry,
770
785
  upstreamProtocol,
771
- nodeCompat,
786
+ legacyNodeCompat,
787
+ nodejsCompat,
772
788
  getLocalPort,
773
789
  getInspectorPort,
774
790
  zoneId,
@@ -841,6 +857,7 @@ function getBindings(
841
857
  ),
842
858
  ...(args.kv || []),
843
859
  ],
860
+ send_email: configParam.send_email,
844
861
  // Use a copy of combinedVars since we're modifying it later
845
862
  vars: {
846
863
  ...getVarsForDev(configParam, env),
@@ -882,7 +899,10 @@ function getBindings(
882
899
  mtls_certificates: configParam.mtls_certificates,
883
900
  services: configParam.services,
884
901
  analytics_engine_datasets: configParam.analytics_engine_datasets,
885
- unsafe: configParam.unsafe?.bindings,
902
+ unsafe: {
903
+ bindings: configParam.unsafe.bindings,
904
+ metadata: configParam.unsafe.metadata,
905
+ },
886
906
  logfwdr: configParam.logfwdr,
887
907
  d1_databases: identifyD1BindingsAsBeta([
888
908
  ...(configParam.d1_databases ?? []).map((d1Db) => {
@@ -0,0 +1,50 @@
1
+ import assert from "node:assert";
2
+ import { fetch } from "undici";
3
+ import { logger } from "../logger";
4
+
5
+ // The ALGOLIA_APP_ID and ALGOLIA_PUBLIC_KEY are provided at esbuild time as a `define` for production and beta releases.
6
+ // Otherwise it is left undefined, which disables search.
7
+ declare const ALGOLIA_APP_ID: string;
8
+ declare const ALGOLIA_PUBLIC_KEY: string;
9
+
10
+ export async function runSearch(searchTerm: string) {
11
+ const id = ALGOLIA_APP_ID;
12
+ const index = "developers-cloudflare2";
13
+ const key = ALGOLIA_PUBLIC_KEY;
14
+ const params = new URLSearchParams({
15
+ query: searchTerm,
16
+ hitsPerPage: "1",
17
+ getRankingInfo: "0",
18
+ });
19
+
20
+ assert(id, "Missing Algolia App ID");
21
+ assert(key, "Missing Algolia Key");
22
+
23
+ const searchResp = await fetch(
24
+ `https://${id}-dsn.algolia.net/1/indexes/${index}/query`,
25
+ {
26
+ method: "POST",
27
+ body: JSON.stringify({
28
+ params: params.toString(),
29
+ }),
30
+ headers: {
31
+ "X-Algolia-API-Key": key,
32
+ "X-Algolia-Application-Id": id,
33
+ },
34
+ }
35
+ );
36
+ if (!searchResp.ok) {
37
+ logger.error(`Could not search the docs. Please try again later.`);
38
+ return;
39
+ }
40
+ const searchData = (await searchResp.json()) as { hits: { url: string }[] };
41
+ logger.debug("searchData: ", searchData);
42
+ if (searchData.hits[0]) {
43
+ return searchData.hits[0].url;
44
+ } else {
45
+ logger.error(
46
+ `Could not find docs for: ${searchTerm}. Please try again with another search term.`
47
+ );
48
+ return;
49
+ }
50
+ }
package/src/docs/index.ts CHANGED
@@ -3,89 +3,46 @@ import { readConfig } from "../config";
3
3
  import { logger } from "../logger";
4
4
  import * as metrics from "../metrics";
5
5
  import openInBrowser from "../open-in-browser";
6
-
6
+ import { runSearch } from "./helpers";
7
7
  import type {
8
8
  CommonYargsArgv,
9
9
  StrictYargsOptionsToInterface,
10
10
  } from "../yargs-types";
11
11
 
12
- const argToUrlHash = {
13
- d1: "d1",
14
- docs: "docs",
15
- init: "init",
16
- generate: "generate",
17
- dev: "dev",
18
- publish: "publish",
19
- delete: "delete",
20
- "kv:namespace": "kvnamespace",
21
- "kv:key": "kvkey",
22
- "kv:bulk": "kvbulk",
23
- "r2 bucket": "r2-bucket",
24
- "r2 object": "r2-object",
25
- secret: "secret",
26
- "secret:bulk": "secretbulk",
27
- tail: "tail",
28
- pages: "pages",
29
- login: "login",
30
- logout: "logout",
31
- whoami: "whoami",
32
- types: "types",
33
- deployments: "deployments",
34
- };
35
-
36
12
  export function docsOptions(yargs: CommonYargsArgv) {
37
- return yargs.positional("command", {
38
- describe: "Enter the wrangler command you want to know more about",
39
- type: "string",
40
- // requiresArg: true,
41
- choices: [
42
- "docs",
43
- "init",
44
- "generate",
45
- "dev",
46
- "publish",
47
- "delete",
48
- "tail",
49
- "secret",
50
- "secret:bulk",
51
- "kv:namespace",
52
- "kv:key",
53
- "kv:bulk",
54
- "pages",
55
- // "queues", //TODO: Undocumented
56
- "r2 object",
57
- "r2 bucket",
58
- // "dispatch-namespace", // TODO: Undocumented - Workers for Platforms
59
- "d1",
60
- // "pubsub", //TODO: Undocumented
61
- "login",
62
- "logout",
63
- "whoami",
64
- "types",
65
- "deployments",
66
- "api",
67
- ],
68
- });
69
- }
70
-
71
- function isValidParam(k: string): k is keyof typeof argToUrlHash {
72
- return k in argToUrlHash;
13
+ return yargs
14
+ .positional("command", {
15
+ describe: "Enter the wrangler command you want to know more about",
16
+ type: "string",
17
+ array: true,
18
+ })
19
+ .option("yes", {
20
+ alias: "y",
21
+ type: "boolean",
22
+ description: "Takes you to the docs, even if search fails",
23
+ });
73
24
  }
74
25
 
75
26
  export async function docsHandler(
76
27
  args: StrictYargsOptionsToInterface<typeof docsOptions>
77
28
  ) {
29
+ //if no command is provided, open the docs homepage
30
+ //or, if a command IS provided, but we can't find anything, open the docs homepage
78
31
  let urlToOpen =
79
- "https://developers.cloudflare.com/workers/wrangler/commands/";
32
+ args.yes || !args.command || args.command.length === 0
33
+ ? "https://developers.cloudflare.com/workers/wrangler/commands/"
34
+ : "";
35
+
36
+ if (args.command && args.command.length > 0) {
37
+ const searchTerm = args.command.join(" ");
38
+ const searchResult = await runSearch(searchTerm);
80
39
 
81
- if (args.command === "api") {
82
- //if api, take them to the API docs
83
- urlToOpen = "https://developers.cloudflare.com/workers/wrangler/api/";
84
- } else if (args.command && isValidParam(args.command)) {
85
- //otherwise, they get the wrangler commands page
86
- urlToOpen += `#${argToUrlHash[args.command]}`;
40
+ urlToOpen = searchResult ?? urlToOpen;
87
41
  }
88
42
 
43
+ if (!urlToOpen) {
44
+ return;
45
+ }
89
46
  await printWranglerBanner();
90
47
 
91
48
  logger.log(`Opening a link in your default browser: ${urlToOpen}`);
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.
@@ -25,6 +35,7 @@ export async function getEntry(
25
35
  script?: string;
26
36
  format?: CfScriptFormat | undefined;
27
37
  assets?: string | undefined;
38
+ moduleRoot?: string;
28
39
  },
29
40
  config: Config,
30
41
  command: "dev" | "publish" | "types"
@@ -99,7 +110,12 @@ export async function getEntry(
99
110
  );
100
111
  }
101
112
 
102
- return { file, directory, format };
113
+ return {
114
+ file,
115
+ directory,
116
+ format,
117
+ moduleRoot: args.moduleRoot ?? config.base_dir ?? path.dirname(file),
118
+ };
103
119
  }
104
120
 
105
121
  export async function runCustomBuild(
@@ -147,18 +163,12 @@ export default async function guessWorkerFormat(
147
163
  tsconfig?: string | undefined
148
164
  ): Promise<CfScriptFormat> {
149
165
  const result = await esbuild.build({
166
+ ...COMMON_ESBUILD_OPTIONS,
150
167
  entryPoints: [entryFile],
151
168
  absWorkingDir: entryWorkingDirectory,
152
169
  metafile: true,
153
170
  bundle: false,
154
- format: "esm",
155
- target: "es2020",
156
171
  write: false,
157
- loader: {
158
- ".js": "jsx",
159
- ".mjs": "jsx",
160
- ".cjs": "jsx",
161
- },
162
172
  ...(tsconfig && { tsconfig }),
163
173
  });
164
174
  // result.metafile is defined because of the `metafile: true` option above.
@@ -14,7 +14,8 @@ type VariableNames =
14
14
  | "WRANGLER_AUTH_URL"
15
15
  | "WRANGLER_TOKEN_URL"
16
16
  | "WRANGLER_REVOKE_URL"
17
- | "WRANGLER_CF_AUTHORIZATION_TOKEN";
17
+ | "WRANGLER_CF_AUTHORIZATION_TOKEN"
18
+ | "NO_CONSTELLATION_WARNING";
18
19
 
19
20
  type DeprecatedNames =
20
21
  | "CF_ACCOUNT_ID"
@@ -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
@@ -7,9 +7,15 @@ import makeCLI from "yargs";
7
7
  import { version as wranglerVersion } from "../package.json";
8
8
  import { isBuildFailure } from "./bundle";
9
9
  import { loadDotEnv, readConfig } from "./config";
10
+ import { constellation } from "./constellation";
10
11
  import { d1 } from "./d1";
11
12
  import { deleteHandler, deleteOptions } from "./delete";
12
- import { deployments } from "./deployments";
13
+ import {
14
+ deployments,
15
+ commonDeploymentCMDSetup,
16
+ rollbackDeployment,
17
+ viewDeployment,
18
+ } from "./deployments";
13
19
  import {
14
20
  buildHandler,
15
21
  buildOptions,
@@ -41,13 +47,7 @@ import { secret, secretBulkHandler, secretBulkOptions } from "./secret";
41
47
  import { tailOptions, tailHandler } from "./tail";
42
48
  import { generateTypes } from "./type-generation";
43
49
  import { updateCheck } from "./update-check";
44
- import {
45
- listScopes,
46
- login,
47
- logout,
48
- requireAuth,
49
- validateScopeKeys,
50
- } from "./user";
50
+ import { listScopes, login, logout, validateScopeKeys } from "./user";
51
51
  import { whoami } from "./whoami";
52
52
 
53
53
  import type { Config } from "./config";
@@ -272,7 +272,7 @@ export function createCLIParser(argv: string[]) {
272
272
 
273
273
  // docs
274
274
  wrangler.command(
275
- "docs [command]",
275
+ "docs [command..]",
276
276
  "📚 Open wrangler's docs in your browser",
277
277
  docsOptions,
278
278
  docsHandler
@@ -432,6 +432,15 @@ export function createCLIParser(argv: string[]) {
432
432
  return d1(d1Yargs.command(subHelp));
433
433
  });
434
434
 
435
+ // ai
436
+ wrangler.command(
437
+ "constellation",
438
+ "🤖 Interact with Constellation AI models",
439
+ (aiYargs) => {
440
+ return constellation(aiYargs.command(subHelp));
441
+ }
442
+ );
443
+
435
444
  // pubsub
436
445
  wrangler.command(
437
446
  "pubsub",
@@ -567,7 +576,7 @@ export function createCLIParser(argv: string[]) {
567
576
  analytics_engine_datasets: config.analytics_engine_datasets,
568
577
  dispatch_namespaces: config.dispatch_namespaces,
569
578
  logfwdr: config.logfwdr,
570
- unsafe: { bindings: config.unsafe?.bindings },
579
+ unsafe: config.unsafe,
571
580
  rules: config.rules,
572
581
  queues: config.queues,
573
582
  };
@@ -581,27 +590,81 @@ export function createCLIParser(argv: string[]) {
581
590
  "🚧`wrangler deployments` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose";
582
591
  wrangler.command(
583
592
  "deployments",
584
- "🚢 Displays the 10 most recent deployments for a worker",
593
+ "🚢 List and view details for deployments",
585
594
  (yargs) =>
586
595
  yargs
587
596
  .option("name", {
588
597
  describe: "The name of your worker",
589
598
  type: "string",
590
599
  })
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
- }
600
+ .command(
601
+ "list",
602
+ "🚢 Displays the 10 most recent deployments for a worker",
603
+ async (listYargs) => listYargs,
604
+ async (listYargs) => {
605
+ const { accountId, scriptName, config } =
606
+ await commonDeploymentCMDSetup(listYargs, deploymentsWarning);
607
+ await deployments(accountId, scriptName, config);
608
+ }
609
+ )
610
+ .command(
611
+ "view [deployment-id]",
612
+ "🔍 View a deployment",
613
+ async (viewYargs) =>
614
+ viewYargs.positional("deployment-id", {
615
+ describe: "The ID of the deployment you want to inspect",
616
+ type: "string",
617
+ demandOption: false,
618
+ }),
619
+ async (viewYargs) => {
620
+ const { accountId, scriptName, config } =
621
+ await commonDeploymentCMDSetup(viewYargs, deploymentsWarning);
622
+
623
+ await viewDeployment(
624
+ accountId,
625
+ scriptName,
626
+ config,
627
+ viewYargs.deploymentId
628
+ );
629
+ }
630
+ )
631
+ .command(subHelp)
632
+ .epilogue(deploymentsWarning)
604
633
  );
634
+ const rollbackWarning =
635
+ "🚧`wrangler rollback` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose";
636
+ wrangler
637
+ .command(
638
+ "rollback [deployment-id]",
639
+ "🔙 Rollback a deployment",
640
+ (rollbackYargs) =>
641
+ rollbackYargs
642
+ .positional("deployment-id", {
643
+ describe: "The ID of the deployment to rollback to",
644
+ type: "string",
645
+ demandOption: false,
646
+ })
647
+ .option("message", {
648
+ alias: "m",
649
+ describe:
650
+ "Skip confirmation and message prompts, uses provided argument as message",
651
+ type: "string",
652
+ default: undefined,
653
+ }),
654
+ async (rollbackYargs) => {
655
+ const { accountId, scriptName, config } =
656
+ await commonDeploymentCMDSetup(rollbackYargs, rollbackWarning);
657
+
658
+ await rollbackDeployment(
659
+ accountId,
660
+ scriptName,
661
+ config,
662
+ rollbackYargs.deploymentId,
663
+ rollbackYargs.message
664
+ );
665
+ }
666
+ )
667
+ .epilogue(rollbackWarning);
605
668
 
606
669
  // This set to false to allow overwrite of default behaviour
607
670
  wrangler.version(false);