wrangler 0.0.0-e33bea9b → 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 (105) hide show
  1. package/miniflare-dist/index.mjs +167 -93
  2. package/package.json +14 -9
  3. package/src/__tests__/api-devregistry.test.ts +121 -0
  4. package/src/__tests__/api.test.ts +27 -5
  5. package/src/__tests__/configuration.test.ts +59 -12
  6. package/src/__tests__/constellation.test.ts +371 -0
  7. package/src/__tests__/d1/execute.test.ts +2 -0
  8. package/src/__tests__/d1/migrate.test.ts +102 -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 +71 -56
  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 +14 -6
  18. package/src/__tests__/init.test.ts +127 -96
  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 +2 -2
  24. package/src/__tests__/mtls-certificates.test.ts +7 -3
  25. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  26. package/src/__tests__/pages/functions-build.test.ts +70 -0
  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 +136 -92
  30. package/src/__tests__/publish.test.ts +878 -332
  31. package/src/__tests__/pubsub.test.ts +3 -0
  32. package/src/__tests__/queues.test.ts +5 -2
  33. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  34. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  35. package/src/__tests__/user.test.ts +1 -1
  36. package/src/__tests__/worker-namespace.test.ts +1 -0
  37. package/src/api/dev.ts +12 -18
  38. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  39. package/src/api/pages/publish.tsx +28 -12
  40. package/src/bundle.ts +26 -9
  41. package/src/config/environment.ts +27 -0
  42. package/src/config/index.ts +18 -0
  43. package/src/config/validation.ts +91 -1
  44. package/src/constellation/createProject.tsx +51 -0
  45. package/src/constellation/deleteProject.ts +51 -0
  46. package/src/constellation/deleteProjectModel.ts +68 -0
  47. package/src/constellation/index.ts +75 -0
  48. package/src/constellation/listCatalog.tsx +35 -0
  49. package/src/constellation/listModel.tsx +41 -0
  50. package/src/constellation/listProject.tsx +28 -0
  51. package/src/constellation/listRuntime.tsx +28 -0
  52. package/src/constellation/options.ts +17 -0
  53. package/src/constellation/types.ts +17 -0
  54. package/src/constellation/uploadModel.tsx +64 -0
  55. package/src/constellation/utils.ts +90 -0
  56. package/src/create-worker-upload-form.ts +18 -1
  57. package/src/d1/backups.tsx +19 -15
  58. package/src/d1/create.tsx +45 -39
  59. package/src/d1/delete.ts +1 -1
  60. package/src/d1/execute.tsx +23 -20
  61. package/src/d1/list.tsx +14 -12
  62. package/src/d1/migrations/apply.tsx +36 -30
  63. package/src/d1/migrations/create.tsx +15 -12
  64. package/src/d1/migrations/helpers.ts +5 -8
  65. package/src/d1/migrations/list.tsx +10 -7
  66. package/src/deployments.ts +260 -8
  67. package/src/dev/dev.tsx +2 -0
  68. package/src/dev/local.tsx +48 -20
  69. package/src/dev/start-server.ts +49 -46
  70. package/src/dev/use-esbuild.ts +52 -49
  71. package/src/dev-registry.ts +2 -1
  72. package/src/dev.tsx +11 -5
  73. package/src/docs/helpers.ts +50 -0
  74. package/src/docs/index.ts +25 -68
  75. package/src/entry.ts +19 -8
  76. package/src/environment-variables/factory.ts +2 -1
  77. package/src/generate/index.ts +2 -2
  78. package/src/index.ts +86 -23
  79. package/src/init.ts +144 -135
  80. package/src/kv/helpers.ts +7 -4
  81. package/src/logger.ts +23 -4
  82. package/src/metrics/send-event.ts +2 -1
  83. package/src/miniflare-cli/index.ts +2 -2
  84. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  85. package/src/module-collection.ts +92 -26
  86. package/src/pages/build.ts +29 -17
  87. package/src/pages/deployments.tsx +3 -5
  88. package/src/pages/dev.ts +24 -6
  89. package/src/pages/functions/buildPlugin.ts +1 -0
  90. package/src/pages/functions/buildWorker.ts +59 -8
  91. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  92. package/src/pages/projects.tsx +2 -5
  93. package/src/pages/upload.tsx +24 -4
  94. package/src/publish/publish.ts +10 -26
  95. package/src/queues/cli/commands/consumer/add.ts +6 -0
  96. package/src/queues/client.ts +1 -0
  97. package/src/secret/index.ts +1 -0
  98. package/src/sites.ts +164 -52
  99. package/src/traverse-module-graph.ts +53 -0
  100. package/src/user/user.ts +1 -0
  101. package/src/utils/render.ts +93 -0
  102. package/src/worker.ts +10 -0
  103. package/wrangler-dist/cli.d.ts +29 -2
  104. package/wrangler-dist/cli.js +23270 -22110
  105. package/src/__tests__/api-devregistry.test.js +0 -64
@@ -4,6 +4,7 @@ import { useApp } from "ink";
4
4
  import { useState, useEffect } from "react";
5
5
  import { bundleWorker, rewriteNodeCompatBuildFailure } from "../bundle";
6
6
  import { logBuildFailure, logger } from "../logger";
7
+ import traverseModuleGraph from "../traverse-module-graph";
7
8
  import type { Config } from "../config";
8
9
  import type { WorkerRegistry } from "../dev-registry";
9
10
  import type { Entry } from "../entry";
@@ -25,6 +26,7 @@ export function useEsbuild({
25
26
  destination,
26
27
  jsxFactory,
27
28
  jsxFragment,
29
+ processEntrypoint,
28
30
  rules,
29
31
  assets,
30
32
  serveAssetsFromWorker,
@@ -48,6 +50,7 @@ export function useEsbuild({
48
50
  destination: string | undefined;
49
51
  jsxFactory: string | undefined;
50
52
  jsxFragment: string | undefined;
53
+ processEntrypoint: boolean;
51
54
  rules: Config["rules"];
52
55
  assets: Config["assets"];
53
56
  define: Config["define"];
@@ -99,52 +102,48 @@ export function useEsbuild({
99
102
  async function build() {
100
103
  if (!destination) return;
101
104
 
102
- const {
103
- resolvedEntryPointPath,
104
- bundleType,
105
- modules,
106
- dependencies,
107
- stop,
108
- sourceMapPath,
109
- }: Awaited<ReturnType<typeof bundleWorker>> = noBundle
110
- ? {
111
- modules: [],
112
- dependencies: {},
113
- resolvedEntryPointPath: entry.file,
114
- bundleType: entry.format === "modules" ? "esm" : "commonjs",
115
- stop: undefined,
116
- sourceMapPath: undefined,
117
- }
118
- : await bundleWorker(entry, destination, {
119
- serveAssetsFromWorker,
120
- jsxFactory,
121
- jsxFragment,
122
- rules,
123
- watch: watchMode,
124
- tsconfig,
125
- minify,
126
- legacyNodeCompat,
127
- nodejsCompat,
128
- betaD1Shims,
129
- doBindings: durableObjects.bindings,
130
- define,
131
- checkFetch: true,
132
- assets: assets && {
133
- ...assets,
134
- // disable the cache in dev
135
- bypassCache: true,
136
- },
137
- workerDefinitions,
138
- services,
139
- firstPartyWorkerDevFacade,
140
- local,
141
- targetConsumer,
142
- testScheduled,
143
- experimentalLocal,
144
- });
105
+ let traverseModuleGraphResult:
106
+ | Awaited<ReturnType<typeof bundleWorker>>
107
+ | undefined;
108
+ let bundleResult: Awaited<ReturnType<typeof bundleWorker>> | undefined;
109
+ if (noBundle) {
110
+ traverseModuleGraphResult = await traverseModuleGraph(entry, rules);
111
+ }
112
+
113
+ if (processEntrypoint || !noBundle) {
114
+ bundleResult = await bundleWorker(entry, destination, {
115
+ bundle: !noBundle,
116
+ disableModuleCollection: noBundle,
117
+ serveAssetsFromWorker,
118
+ jsxFactory,
119
+ jsxFragment,
120
+ rules,
121
+ watch: watchMode,
122
+ tsconfig,
123
+ minify,
124
+ legacyNodeCompat,
125
+ nodejsCompat,
126
+ betaD1Shims,
127
+ doBindings: durableObjects.bindings,
128
+ define,
129
+ checkFetch: true,
130
+ assets: assets && {
131
+ ...assets,
132
+ // disable the cache in dev
133
+ bypassCache: true,
134
+ },
135
+ workerDefinitions,
136
+ services,
137
+ firstPartyWorkerDevFacade,
138
+ local,
139
+ targetConsumer,
140
+ testScheduled,
141
+ experimentalLocal,
142
+ });
143
+ }
145
144
 
146
145
  // Capture the `stop()` method to use as the `useEffect()` destructor.
147
- stopWatching = stop;
146
+ stopWatching = bundleResult?.stop;
148
147
 
149
148
  // if "noBundle" is true, then we need to manually watch the entry point and
150
149
  // trigger "builds" when it changes
@@ -162,11 +161,14 @@ export function useEsbuild({
162
161
  setBundle({
163
162
  id: 0,
164
163
  entry,
165
- path: resolvedEntryPointPath,
166
- type: bundleType,
167
- modules,
168
- dependencies,
169
- sourceMapPath,
164
+ path: bundleResult?.resolvedEntryPointPath ?? entry.file,
165
+ type:
166
+ bundleResult?.bundleType ??
167
+ (entry.format === "modules" ? "esm" : "commonjs"),
168
+ modules:
169
+ traverseModuleGraphResult?.modules ?? bundleResult?.modules ?? [],
170
+ dependencies: bundleResult?.dependencies ?? {},
171
+ sourceMapPath: bundleResult?.sourceMapPath,
170
172
  });
171
173
  }
172
174
 
@@ -186,6 +188,7 @@ export function useEsbuild({
186
188
  jsxFactory,
187
189
  jsxFragment,
188
190
  serveAssetsFromWorker,
191
+ processEntrypoint,
189
192
  rules,
190
193
  tsconfig,
191
194
  exit,
@@ -13,7 +13,7 @@ import type { HttpTerminator } from "http-terminator";
13
13
  const DEV_REGISTRY_PORT = "6284";
14
14
  const DEV_REGISTRY_HOST = `http://localhost:${DEV_REGISTRY_PORT}`;
15
15
 
16
- let server: Server;
16
+ let server: Server | null;
17
17
  let terminator: HttpTerminator;
18
18
 
19
19
  export type WorkerRegistry = Record<string, WorkerDefinition>;
@@ -102,6 +102,7 @@ export async function startWorkerRegistry() {
102
102
  */
103
103
  export async function stopWorkerRegistry() {
104
104
  await terminator?.terminate();
105
+ server = null;
105
106
  }
106
107
 
107
108
  /**
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";
@@ -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 &
@@ -424,7 +427,8 @@ 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
434
  legacyNodeCompat={legacyNodeCompat}
@@ -560,7 +564,8 @@ export async function startApiDev(args: StartDevOptions) {
560
564
  zone: zoneId,
561
565
  host: host,
562
566
  routes: routes,
563
- rules: getRules(configParam),
567
+ processEntrypoint: !!args.processEntrypoint,
568
+ rules: args.rules ?? getRules(configParam),
564
569
  legacyEnv: isLegacyEnv(configParam),
565
570
  minify: args.minify ?? configParam.minify,
566
571
  legacyNodeCompat,
@@ -661,7 +666,7 @@ async function getZoneIdHostAndRoutes(args: StartDevOptions, config: Config) {
661
666
  args.local = true;
662
667
  }
663
668
 
664
- if (!args.local) {
669
+ if (!args.local && !args.experimentalLocal) {
665
670
  if (host) {
666
671
  zoneId = await getZoneIdFromHost(host);
667
672
  }
@@ -687,7 +692,7 @@ async function validateDevServerSettings(
687
692
  config: Config
688
693
  ) {
689
694
  const entry = await getEntry(
690
- { assets: args.assets, script: args.script },
695
+ { assets: args.assets, script: args.script, moduleRoot: args.moduleRoot },
691
696
  config,
692
697
  "dev"
693
698
  );
@@ -852,6 +857,7 @@ function getBindings(
852
857
  ),
853
858
  ...(args.kv || []),
854
859
  ],
860
+ send_email: configParam.send_email,
855
861
  // Use a copy of combinedVars since we're modifying it later
856
862
  vars: {
857
863
  ...getVarsForDev(configParam, env),
@@ -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,17 +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
- target: "es2022",
155
171
  write: false,
156
- loader: {
157
- ".js": "jsx",
158
- ".mjs": "jsx",
159
- ".cjs": "jsx",
160
- },
161
172
  ...(tsconfig && { tsconfig }),
162
173
  });
163
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",
@@ -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);