wrangler 0.0.0-ecc8b172 → 0.0.0-ecded1af1

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 (250) hide show
  1. package/README.md +17 -19
  2. package/bin/wrangler.js +24 -93
  3. package/config-schema.json +3115 -0
  4. package/package.json +197 -190
  5. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  6. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  7. package/templates/__tests__/tsconfig.json +8 -0
  8. package/templates/checked-fetch.js +19 -6
  9. package/templates/facade.d.ts +19 -0
  10. package/templates/gitignore +2 -3
  11. package/templates/init-tests/test-jest-new-worker.js +3 -5
  12. package/templates/init-tests/test-vitest-new-worker.js +4 -6
  13. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  14. package/templates/middleware/common.ts +9 -4
  15. package/templates/middleware/loader-modules.ts +94 -44
  16. package/templates/middleware/loader-sw.ts +48 -32
  17. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  18. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  19. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  20. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -1
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.ts +1 -1
  26. package/templates/new-worker.ts +4 -1
  27. package/templates/pages-dev-pipeline.ts +10 -13
  28. package/templates/pages-dev-util.ts +55 -0
  29. package/templates/pages-shim.ts +1 -1
  30. package/templates/pages-template-plugin.ts +37 -14
  31. package/templates/pages-template-worker.ts +33 -7
  32. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  33. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  34. package/templates/tsconfig-sanity.ts +11 -0
  35. package/templates/tsconfig.init.json +22 -0
  36. package/templates/tsconfig.json +5 -102
  37. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  38. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  39. package/wrangler-dist/ProxyWorker.js +241 -0
  40. package/wrangler-dist/ProxyWorker.js.map +6 -0
  41. package/wrangler-dist/cli.d.ts +26095 -471
  42. package/wrangler-dist/cli.js +178062 -122008
  43. package/wrangler-dist/wasm-sync.wasm +0 -0
  44. package/Cloudflare_CA.pem +0 -18
  45. package/import_meta_url.js +0 -3
  46. package/miniflare-config-stubs/.env.empty +0 -0
  47. package/miniflare-config-stubs/package.empty.json +0 -1
  48. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  49. package/miniflare-dist/index.mjs +0 -6310
  50. package/src/__tests__/api-dev.test.ts +0 -209
  51. package/src/__tests__/api-devregistry.test.js +0 -56
  52. package/src/__tests__/api.test.ts +0 -80
  53. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  54. package/src/__tests__/config-cache.test.ts +0 -42
  55. package/src/__tests__/configuration.test.ts +0 -3864
  56. package/src/__tests__/d1.test.ts +0 -70
  57. package/src/__tests__/delete.test.ts +0 -116
  58. package/src/__tests__/dev.test.tsx +0 -1357
  59. package/src/__tests__/dialogs.test.tsx +0 -40
  60. package/src/__tests__/generate.test.ts +0 -235
  61. package/src/__tests__/get-host-from-url.test.ts +0 -16
  62. package/src/__tests__/guess-worker-format.test.ts +0 -85
  63. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  64. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  65. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  66. package/src/__tests__/helpers/mock-bin.ts +0 -36
  67. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  68. package/src/__tests__/helpers/mock-console.ts +0 -106
  69. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  70. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -8
  71. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  72. package/src/__tests__/helpers/mock-istty.ts +0 -74
  73. package/src/__tests__/helpers/mock-known-routes.ts +0 -7
  74. package/src/__tests__/helpers/mock-kv.ts +0 -33
  75. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -252
  76. package/src/__tests__/helpers/mock-process.ts +0 -39
  77. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  78. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  79. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -104
  80. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -36
  81. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -80
  82. package/src/__tests__/helpers/msw/handlers/script.ts +0 -75
  83. package/src/__tests__/helpers/msw/handlers/user.ts +0 -63
  84. package/src/__tests__/helpers/msw/index.ts +0 -15
  85. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  86. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  87. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  88. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  89. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  90. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  91. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  92. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  93. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  94. package/src/__tests__/https-options.test.ts +0 -163
  95. package/src/__tests__/index.test.ts +0 -251
  96. package/src/__tests__/init.test.ts +0 -2816
  97. package/src/__tests__/jest.setup.ts +0 -191
  98. package/src/__tests__/kv.test.ts +0 -1675
  99. package/src/__tests__/logger.test.ts +0 -141
  100. package/src/__tests__/metrics.test.ts +0 -450
  101. package/src/__tests__/middleware.scheduled.test.ts +0 -135
  102. package/src/__tests__/middleware.test.ts +0 -726
  103. package/src/__tests__/package-manager.test.ts +0 -353
  104. package/src/__tests__/pages.test.ts +0 -2111
  105. package/src/__tests__/parse.test.ts +0 -330
  106. package/src/__tests__/paths.test.ts +0 -39
  107. package/src/__tests__/publish.test.ts +0 -7119
  108. package/src/__tests__/pubsub.test.ts +0 -367
  109. package/src/__tests__/r2.test.ts +0 -371
  110. package/src/__tests__/route.test.ts +0 -45
  111. package/src/__tests__/secret.test.ts +0 -644
  112. package/src/__tests__/tail.test.ts +0 -800
  113. package/src/__tests__/test-old-node-version.js +0 -31
  114. package/src/__tests__/user.test.ts +0 -155
  115. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  116. package/src/__tests__/validate-dev-props.test.ts +0 -56
  117. package/src/__tests__/version.test.ts +0 -35
  118. package/src/__tests__/whoami.test.tsx +0 -278
  119. package/src/__tests__/worker-namespace.test.ts +0 -321
  120. package/src/abort.d.ts +0 -3
  121. package/src/api/dev.ts +0 -208
  122. package/src/api/index.ts +0 -2
  123. package/src/bundle-reporter.tsx +0 -29
  124. package/src/bundle.ts +0 -756
  125. package/src/cfetch/index.ts +0 -160
  126. package/src/cfetch/internal.ts +0 -263
  127. package/src/cli.ts +0 -29
  128. package/src/config/README.md +0 -107
  129. package/src/config/config.ts +0 -275
  130. package/src/config/diagnostics.ts +0 -80
  131. package/src/config/environment.ts +0 -505
  132. package/src/config/index.ts +0 -293
  133. package/src/config/validation-helpers.ts +0 -597
  134. package/src/config/validation.ts +0 -1930
  135. package/src/config-cache.ts +0 -85
  136. package/src/create-worker-preview.ts +0 -275
  137. package/src/create-worker-upload-form.ts +0 -301
  138. package/src/d1/backups.tsx +0 -212
  139. package/src/d1/create.tsx +0 -54
  140. package/src/d1/delete.tsx +0 -56
  141. package/src/d1/execute.tsx +0 -294
  142. package/src/d1/formatTimeAgo.ts +0 -14
  143. package/src/d1/index.ts +0 -75
  144. package/src/d1/list.tsx +0 -48
  145. package/src/d1/options.ts +0 -12
  146. package/src/d1/types.tsx +0 -14
  147. package/src/d1/utils.ts +0 -39
  148. package/src/delete.ts +0 -86
  149. package/src/deprecated/index.ts +0 -453
  150. package/src/dev/dev-vars.ts +0 -36
  151. package/src/dev/dev.tsx +0 -575
  152. package/src/dev/get-local-persistence-path.tsx +0 -31
  153. package/src/dev/local.tsx +0 -686
  154. package/src/dev/remote.tsx +0 -601
  155. package/src/dev/start-server.ts +0 -506
  156. package/src/dev/use-esbuild.ts +0 -197
  157. package/src/dev/validate-dev-props.ts +0 -31
  158. package/src/dev-registry.tsx +0 -201
  159. package/src/dev.tsx +0 -865
  160. package/src/dialogs.tsx +0 -163
  161. package/src/dispatch-namespace.ts +0 -206
  162. package/src/durable.ts +0 -102
  163. package/src/entry.ts +0 -329
  164. package/src/environment-variables.ts +0 -50
  165. package/src/errors.ts +0 -11
  166. package/src/git-client.ts +0 -124
  167. package/src/global-wrangler-config-path.ts +0 -26
  168. package/src/https-options.ts +0 -127
  169. package/src/index.tsx +0 -582
  170. package/src/init.ts +0 -970
  171. package/src/inspect.ts +0 -747
  172. package/src/intl-polyfill.d.ts +0 -139
  173. package/src/is-ci.ts +0 -14
  174. package/src/is-interactive.ts +0 -12
  175. package/src/kv/helpers.ts +0 -430
  176. package/src/kv/index.ts +0 -645
  177. package/src/logger.ts +0 -80
  178. package/src/metrics/index.ts +0 -5
  179. package/src/metrics/metrics-config.ts +0 -239
  180. package/src/metrics/metrics-dispatcher.ts +0 -96
  181. package/src/metrics/metrics-usage-headers.ts +0 -24
  182. package/src/metrics/send-event.ts +0 -94
  183. package/src/miniflare-cli/README.md +0 -30
  184. package/src/miniflare-cli/assets.ts +0 -215
  185. package/src/miniflare-cli/index.ts +0 -208
  186. package/src/miniflare-cli/request-context.ts +0 -40
  187. package/src/module-collection.ts +0 -267
  188. package/src/open-in-browser.ts +0 -17
  189. package/src/package-manager.ts +0 -219
  190. package/src/pages/build.tsx +0 -238
  191. package/src/pages/constants.ts +0 -16
  192. package/src/pages/deployments.tsx +0 -106
  193. package/src/pages/dev.tsx +0 -689
  194. package/src/pages/errors.ts +0 -66
  195. package/src/pages/functions/buildPlugin.ts +0 -110
  196. package/src/pages/functions/buildWorker.ts +0 -156
  197. package/src/pages/functions/filepath-routing.test.ts +0 -234
  198. package/src/pages/functions/filepath-routing.ts +0 -189
  199. package/src/pages/functions/identifiers.ts +0 -78
  200. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  201. package/src/pages/functions/routes-consolidation.ts +0 -73
  202. package/src/pages/functions/routes-transformation.test.ts +0 -282
  203. package/src/pages/functions/routes-transformation.ts +0 -115
  204. package/src/pages/functions/routes-validation.test.ts +0 -403
  205. package/src/pages/functions/routes-validation.ts +0 -202
  206. package/src/pages/functions/routes.ts +0 -151
  207. package/src/pages/functions.tsx +0 -82
  208. package/src/pages/hash.tsx +0 -13
  209. package/src/pages/index.tsx +0 -94
  210. package/src/pages/projects.tsx +0 -169
  211. package/src/pages/publish.tsx +0 -436
  212. package/src/pages/types.ts +0 -49
  213. package/src/pages/upload.tsx +0 -398
  214. package/src/pages/utils.ts +0 -12
  215. package/src/parse.ts +0 -286
  216. package/src/paths.ts +0 -71
  217. package/src/proxy.ts +0 -657
  218. package/src/publish/index.ts +0 -267
  219. package/src/publish/publish.ts +0 -913
  220. package/src/pubsub/index.ts +0 -286
  221. package/src/pubsub/pubsub-commands.tsx +0 -623
  222. package/src/r2/helpers.ts +0 -131
  223. package/src/r2/index.ts +0 -277
  224. package/src/routes.ts +0 -140
  225. package/src/secret/index.ts +0 -403
  226. package/src/selfsigned.d.ts +0 -29
  227. package/src/sites.tsx +0 -372
  228. package/src/tail/createTail.ts +0 -315
  229. package/src/tail/filters.ts +0 -277
  230. package/src/tail/index.ts +0 -217
  231. package/src/tail/printing.ts +0 -107
  232. package/src/update-check.ts +0 -19
  233. package/src/user/choose-account.tsx +0 -69
  234. package/src/user/env-vars.ts +0 -46
  235. package/src/user/generate-auth-url.ts +0 -33
  236. package/src/user/generate-random-state.ts +0 -16
  237. package/src/user/index.ts +0 -3
  238. package/src/user/user.tsx +0 -1192
  239. package/src/utils/collectKeyValues.ts +0 -14
  240. package/src/whoami.tsx +0 -169
  241. package/src/worker.ts +0 -234
  242. package/src/yargs-types.ts +0 -7
  243. package/src/zones.ts +0 -165
  244. package/templates/d1-beta-facade.js +0 -174
  245. package/templates/experimental-local-cache-stubs.js +0 -27
  246. package/templates/first-party-worker-module-facade.ts +0 -18
  247. package/templates/format-dev-errors.ts +0 -32
  248. package/templates/serve-static-assets.ts +0 -63
  249. package/templates/service-bindings-module-facade.js +0 -54
  250. package/templates/service-bindings-sw-facade.js +0 -42
package/src/d1/list.tsx DELETED
@@ -1,48 +0,0 @@
1
- import { render } from "ink";
2
- import Table from "ink-table";
3
- import React from "react";
4
- import { fetchResult } from "../cfetch";
5
- import { logger } from "../logger";
6
- import { requireAuth } from "../user";
7
- import { d1BetaWarning } from "./utils";
8
- import type { Database } from "./types";
9
- import type { ArgumentsCamelCase, Argv } from "yargs";
10
-
11
- type ListArgs = Record<string, never>;
12
-
13
- export function Options(d1ListYargs: Argv): Argv<ListArgs> {
14
- return d1ListYargs.epilogue(d1BetaWarning);
15
- }
16
-
17
- export async function Handler(_: ArgumentsCamelCase<ListArgs>): Promise<void> {
18
- const accountId = await requireAuth({});
19
- logger.log(d1BetaWarning);
20
-
21
- const dbs: Array<Database> = await listDatabases(accountId);
22
-
23
- render(<Table data={dbs}></Table>);
24
- }
25
-
26
- export const listDatabases = async (
27
- accountId: string
28
- ): Promise<Array<Database>> => {
29
- const pageSize = 10;
30
- let page = 1;
31
- const results = [];
32
- while (results.length % pageSize === 0) {
33
- const json: Array<Database> = await fetchResult(
34
- `/accounts/${accountId}/d1/database`,
35
- {},
36
- new URLSearchParams({
37
- per_page: pageSize.toString(),
38
- page: page.toString(),
39
- })
40
- );
41
- page++;
42
- results.push(...json);
43
- if (json.length < pageSize) {
44
- break;
45
- }
46
- }
47
- return results;
48
- };
package/src/d1/options.ts DELETED
@@ -1,12 +0,0 @@
1
- import { d1BetaWarning } from "./utils";
2
- import type { Argv } from "yargs";
3
-
4
- export function Name(yargs: Argv) {
5
- return yargs
6
- .positional("name", {
7
- describe: "The name or binding of the DB",
8
- type: "string",
9
- demandOption: true,
10
- })
11
- .epilogue(d1BetaWarning);
12
- }
package/src/d1/types.tsx DELETED
@@ -1,14 +0,0 @@
1
- export type Database = {
2
- uuid: string;
3
- name: string;
4
- };
5
-
6
- export type Backup = {
7
- id: string;
8
- database_id: string;
9
- created_at: string;
10
- state: "progress" | "done";
11
- num_tables: number;
12
- file_size: number;
13
- size?: string;
14
- };
package/src/d1/utils.ts DELETED
@@ -1,39 +0,0 @@
1
- import { listDatabases } from "./list";
2
- import type { Config } from "../config";
3
- import type { Database } from "./types";
4
-
5
- export function getDatabaseInfoFromConfig(config: Config, name: string) {
6
- for (const d1Database of config.d1_databases) {
7
- if (
8
- d1Database.database_id &&
9
- (name === d1Database.database_name || name === d1Database.binding)
10
- ) {
11
- return {
12
- uuid: d1Database.database_id,
13
- binding: d1Database.binding,
14
- name: d1Database.database_name,
15
- };
16
- }
17
- }
18
- return null;
19
- }
20
-
21
- export const getDatabaseByNameOrBinding = async (
22
- config: Config,
23
- accountId: string,
24
- name: string
25
- ): Promise<Database> => {
26
- const dbFromConfig = getDatabaseInfoFromConfig(config, name);
27
- if (dbFromConfig) return dbFromConfig;
28
-
29
- const allDBs = await listDatabases(accountId);
30
- const matchingDB = allDBs.find((db) => db.name === name);
31
- if (!matchingDB) {
32
- throw new Error(`Couldn't find DB with name '${name}'`);
33
- }
34
- return matchingDB;
35
- };
36
-
37
- export const d1BetaWarning = process.env.NO_D1_WARNING
38
- ? ""
39
- : "🚧 'wrangler d1 <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose";
package/src/delete.ts DELETED
@@ -1,86 +0,0 @@
1
- import path from "path";
2
- import { fetchResult } from "./cfetch";
3
- import { findWranglerToml, readConfig } from "./config";
4
- import { confirm } from "./dialogs";
5
- import { CI } from "./is-ci";
6
- import isInteractive from "./is-interactive";
7
- import { logger } from "./logger";
8
- import * as metrics from "./metrics";
9
- import { requireAuth } from "./user";
10
- import { getScriptName, printWranglerBanner } from "./index";
11
- import type { ConfigPath } from "./index";
12
- import type { YargsOptionsToInterface } from "./yargs-types";
13
- import type { Argv, ArgumentsCamelCase } from "yargs";
14
-
15
- export function deleteOptions(yargs: Argv) {
16
- return yargs
17
- .option("env", {
18
- type: "string",
19
- requiresArg: true,
20
- describe: "Perform on a specific environment",
21
- alias: "e",
22
- })
23
- .positional("script", {
24
- describe: "The path to an entry point for your worker",
25
- type: "string",
26
- requiresArg: true,
27
- })
28
- .option("name", {
29
- describe: "Name of the worker",
30
- type: "string",
31
- requiresArg: true,
32
- })
33
- .option("dry-run", {
34
- describe: "Don't actually delete",
35
- type: "boolean",
36
- })
37
- .option("legacy-env", {
38
- type: "boolean",
39
- describe: "Use legacy environments",
40
- hidden: true,
41
- });
42
- }
43
-
44
- type DeleteArgs = YargsOptionsToInterface<typeof deleteOptions>;
45
-
46
- export async function deleteHandler(args: ArgumentsCamelCase<DeleteArgs>) {
47
- await printWranglerBanner();
48
-
49
- const configPath =
50
- (args.config as ConfigPath) ||
51
- (args.script && findWranglerToml(path.dirname(args.script)));
52
- const config = readConfig(configPath, args);
53
- await metrics.sendMetricsEvent(
54
- "delete worker script",
55
- {},
56
- { sendMetrics: config.send_metrics }
57
- );
58
-
59
- const accountId = args.dryRun ? undefined : await requireAuth(config);
60
-
61
- const scriptName = getScriptName(args, config);
62
-
63
- if (args.dryRun) {
64
- logger.log(`--dry-run: exiting now.`);
65
- return;
66
- }
67
-
68
- let confirmed = true;
69
- if (isInteractive() || !CI.isCI()) {
70
- confirmed = await confirm(
71
- `Are you sure you want to delete ${scriptName}? This action cannot be undone.`
72
- );
73
- }
74
-
75
- if (confirmed) {
76
- await fetchResult(
77
- `/accounts/${accountId}/workers/services/${scriptName}`,
78
- { method: "DELETE" },
79
- new URLSearchParams({ force: "true" })
80
- );
81
-
82
- logger.log("Successfully deleted", scriptName);
83
- }
84
-
85
- // TODO: maybe delete sites/assets kv namespace as well?
86
- }
@@ -1,453 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { DeprecationError } from "../errors";
4
- import { cloneIntoDirectory, initializeGit } from "../git-client";
5
- import {
6
- CommandLineArgsError,
7
- createCLIParser,
8
- printWranglerBanner,
9
- } from "../index";
10
- import { initHandler } from "../init";
11
- import { logger } from "../logger";
12
- import { formatMessage } from "../parse";
13
- import type { YargsOptionsToInterface } from "../yargs-types";
14
- import type { Argv, ArgumentsCamelCase, BuilderCallback } from "yargs";
15
-
16
- // https://github.com/cloudflare/wrangler/blob/master/src/cli/mod.rs#L106-L123
17
- interface GenerateArgs {
18
- name?: string;
19
- template?: string;
20
- type?: string;
21
- site?: boolean;
22
- }
23
-
24
- export function generateOptions(yargs: Argv) {
25
- return yargs
26
- .positional("name", {
27
- describe: "Name of the Workers project",
28
- type: "string",
29
- })
30
- .positional("template", {
31
- type: "string",
32
- describe: "The URL of a GitHub template",
33
- })
34
- .option("type", {
35
- alias: "t",
36
- type: "string",
37
- hidden: true,
38
- deprecated: true,
39
- })
40
- .option("site", {
41
- alias: "s",
42
- type: "boolean",
43
- hidden: true,
44
- deprecated: true,
45
- });
46
- }
47
-
48
- export async function generateHandler({
49
- // somehow, `init` marks name as required but then also runs fine
50
- // with the name omitted, and then substitutes it at runtime with ""
51
- name = "",
52
- template,
53
- type,
54
- site,
55
- ...args
56
- }: ArgumentsCamelCase<GenerateArgs>) {
57
- // delegate to `wrangler init` if no template is specified
58
- if (template === undefined) {
59
- return initHandler({ name, ...args });
60
- }
61
-
62
- // print down here cuz `init` prints it own its own
63
- await printWranglerBanner();
64
-
65
- if (type) {
66
- let message = "The --type option is no longer supported.";
67
- if (args.type === "webpack") {
68
- message +=
69
- "\nIf you wish to use webpack then you will need to create a custom build.";
70
- // TODO: Add a link to docs
71
- }
72
- throw new CommandLineArgsError(message);
73
- }
74
-
75
- if (isRemote(name)) {
76
- [template, name] = [name, template];
77
- }
78
-
79
- const creationDirectory = generateWorkerDirectoryName(name);
80
-
81
- if (site) {
82
- const gitDirectory =
83
- creationDirectory !== process.cwd()
84
- ? path.basename(creationDirectory)
85
- : "my-site";
86
- const message =
87
- "The --site option is no longer supported.\n" +
88
- "If you wish to create a brand new Worker Sites project then clone the `worker-sites-template` starter repository:\n\n" +
89
- "```\n" +
90
- `git clone --depth=1 --branch=wrangler2 https://github.com/cloudflare/worker-sites-template ${gitDirectory}\n` +
91
- `cd ${gitDirectory}\n` +
92
- "```\n\n" +
93
- "Find out more about how to create and maintain Sites projects at https://developers.cloudflare.com/workers/platform/sites.\n" +
94
- "Have you considered using Cloudflare Pages instead? See https://pages.cloudflare.com/.";
95
- throw new CommandLineArgsError(message);
96
- }
97
-
98
- logger.log(
99
- `Creating a worker in ${path.basename(creationDirectory)} from ${template}`
100
- );
101
-
102
- const { remote, subdirectory } = parseTemplatePath(template);
103
-
104
- await cloneIntoDirectory(remote, creationDirectory, subdirectory);
105
- await initializeGit(creationDirectory);
106
-
107
- logger.log("✨ Success!");
108
- }
109
-
110
- /**
111
- * Creates a path based on the current working directory and a worker name.
112
- * Automatically increments a counter when searching for an available directory.
113
- *
114
- * Running `wrangler generate worker https://some-git-repo` in a directory
115
- * with the structure:
116
- * ```
117
- * - workers
118
- * |
119
- * | - worker
120
- * | | - wrangler.toml
121
- * | | ...
122
- * |
123
- * | - worker-1
124
- * | | - wrangler.toml
125
- * | | ...
126
- * ```
127
- *
128
- * will result in a new worker called `worker-2` being generated.
129
- *
130
- * @param workerName the name of the generated worker
131
- * @returns an absolute path to the directory to generate the worker into
132
- */
133
- function generateWorkerDirectoryName(workerName: string): string {
134
- let workerDirectoryPath = path.resolve(process.cwd(), workerName);
135
- let i = 1;
136
-
137
- while (fs.existsSync(workerDirectoryPath)) {
138
- workerDirectoryPath = path.resolve(process.cwd(), `${workerName}-${i}`);
139
- i++;
140
- }
141
-
142
- return workerDirectoryPath;
143
- }
144
-
145
- /**
146
- * Checks if an arg is a template, which can be useful if the order
147
- * of template & worker name args is switched
148
- *
149
- * @param arg a template to generate from, or a folder to generate into
150
- * @returns true if the given arg was remote (a template)
151
- */
152
- function isRemote(arg: string) {
153
- return /^(https?|ftps?|file|git|ssh):\/\//.test(arg) || arg.includes(":");
154
- }
155
-
156
- /**
157
- * unreadable regex basically copied from degit. i put some named capture groups in,
158
- * but uhh...there's not much to do short of using pomsky or some other tool.
159
- *
160
- * notably: this only supports `https://` and `git@` urls,
161
- * and is missing support for:
162
- * - `http`
163
- * - `ftp(s)`
164
- * - `file`
165
- * - `ssh`
166
- */
167
- const TEMPLATE_REGEX =
168
- /^(?:(?:https:\/\/)?(?<httpsUrl>[^:/]+\.[^:/]+)\/|git@(?<gitUrl>[^:/]+)[:/]|(?<shorthandUrl>[^/]+):)?(?<user>[^/\s]+)\/(?<repository>[^/\s#]+)(?:(?<subdirectoryPath>(?:\/[^/\s#]+)+))?(?:\/)?(?:#(?<tag>.+))?/;
169
-
170
- // there are a few URL formats we support:
171
- // - `user/repo` -> assume github, use "https://github.com/user/repo.git"
172
- // - `https://<httpsUrl>
173
- // - `git@<gitUrl>`
174
- // - `(bb|bitbucket|gh|github|gl|gitlab):user/repo` -> parse shorthand into https url
175
-
176
- /**
177
- * There's no URL, so assume a github repo
178
- */
179
- type NoUrl = {
180
- httpsUrl: undefined;
181
- gitUrl: undefined;
182
- shorthandUrl: undefined;
183
- };
184
-
185
- /**
186
- * A https url (e.g. https://bitbucket.org/user/repo)
187
- */
188
- type HttpsUrl = Omit<NoUrl, "httpsUrl"> & { httpsUrl: string };
189
-
190
- /**
191
- * A git url (e.g. git@gitlab.com:user/repo)
192
- */
193
- type GitUrl = Omit<NoUrl, "gitUrl"> & { gitUrl: string };
194
-
195
- /**
196
- * A shorthand url (e.g. github:user/repo)
197
- */
198
- type ShorthandUrl = Omit<NoUrl, "shorthandUrl"> & { shorthandUrl: string };
199
-
200
- /**
201
- * Union of all possible URL groups. Exactly one will be present, the rest
202
- * will be `undefined`.
203
- */
204
- type TemplateRegexUrlGroup = NoUrl | HttpsUrl | GitUrl | ShorthandUrl;
205
-
206
- /**
207
- * Possible matches of `TEMPLATE_REGEX` against a passed-in template arg
208
- */
209
- type TemplateRegexGroups = {
210
- /** The user the repo is under */
211
- user: string;
212
-
213
- /** The repo name */
214
- repository: string;
215
-
216
- /** Optional, path to subdirectory containing template. Begins with `/` */
217
- subdirectoryPath?: string;
218
-
219
- /** Optional tag (or branch, etc.) to clone */
220
- tag?: string;
221
- } & TemplateRegexUrlGroup;
222
-
223
- /**
224
- * Parses a regex match on any of the URL groups into a URL base
225
- *
226
- * @param urlGroup a regex hit for a URL of any sort
227
- * @returns the protocol and domain name of the url to clone from
228
- */
229
- function toUrlBase({ httpsUrl, gitUrl, shorthandUrl }: TemplateRegexUrlGroup) {
230
- if (httpsUrl !== undefined) {
231
- return `https://${httpsUrl}`;
232
- }
233
-
234
- if (gitUrl !== undefined) {
235
- return `git@${gitUrl}`;
236
- }
237
-
238
- if (shorthandUrl !== undefined) {
239
- switch (shorthandUrl) {
240
- case "github":
241
- case "gh":
242
- return "https://github.com";
243
- case "gitlab":
244
- case "gl":
245
- return "https://gitlab.com";
246
- case "bitbucket":
247
- case "bb":
248
- return "https://bitbucket.org";
249
- default:
250
- throw new Error(
251
- `Unable to parse shorthand ${shorthandUrl}. Supported options are "bitbucket" ("bb"), "github" ("gh"), and "gitlab" ("gl")`
252
- );
253
- }
254
- }
255
-
256
- return "https://github.com";
257
- }
258
-
259
- /**
260
- * Parses a template string (e.g. "user/repo", "github:user/repo/path/to/subdirectory")
261
- * into a remote URL to clone from and an optional subdirectory to filter for
262
- *
263
- * @param templatePath the template string to parse
264
- * @returns an object containing the remote url and an optional subdirectory to clone
265
- */
266
- function parseTemplatePath(templatePath: string): {
267
- remote: string;
268
- subdirectory?: string;
269
- } {
270
- if (!templatePath.includes("/")) {
271
- // template is a cloudflare canonical template, it doesn't include a slash in the name
272
- return {
273
- remote: "https://github.com/cloudflare/templates.git",
274
- subdirectory: templatePath,
275
- };
276
- }
277
-
278
- const groups = TEMPLATE_REGEX.exec(templatePath)?.groups as unknown as
279
- | TemplateRegexGroups
280
- | undefined;
281
-
282
- if (!groups) {
283
- throw new Error(`Unable to parse ${templatePath} as a template`);
284
- }
285
-
286
- const { user, repository, subdirectoryPath, tag, ...urlGroups } = groups;
287
-
288
- const urlBase = toUrlBase(urlGroups);
289
- const isHttp = urlBase.startsWith("http");
290
-
291
- const remote = `${urlBase}${isHttp ? "/" : ":"}${user}/${repository}.git${
292
- tag ? `#${tag}` : ""
293
- }`;
294
-
295
- // remove starting /
296
- const subdirectory = subdirectoryPath?.slice(1);
297
-
298
- return { remote, subdirectory };
299
- }
300
-
301
- export function buildOptions(yargs: Argv) {
302
- return yargs.option("env", {
303
- describe: "Perform on a specific environment",
304
- type: "string",
305
- });
306
- }
307
- type BuildArgs = YargsOptionsToInterface<typeof buildOptions>;
308
- export async function buildHandler(buildArgs: BuildArgs) {
309
- // "[DEPRECATED] 🦀 Build your project (if applicable)",
310
-
311
- const envFlag = buildArgs.env ? ` --env=${buildArgs.env}` : "";
312
- logger.log(
313
- formatMessage({
314
- kind: "warning",
315
- text: "Deprecation: `wrangler build` has been deprecated.",
316
- notes: [
317
- {
318
- text: "Please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build for more information.",
319
- },
320
- {
321
- text: `Attempting to run \`wrangler publish --dry-run --outdir=dist${envFlag}\` for you instead:`,
322
- },
323
- ],
324
- })
325
- );
326
-
327
- await createCLIParser([
328
- "publish",
329
- "--dry-run",
330
- "--outdir=dist",
331
- ...(buildArgs.env ? ["--env", buildArgs.env] : []),
332
- ]).parse();
333
- }
334
-
335
- export const noOpOptions = () => {};
336
- export const configHandler = () => {
337
- // "🕵️ Authenticate Wrangler with a Cloudflare API Token",
338
- throw new DeprecationError(
339
- "`wrangler config` has been deprecated, please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#config for alternatives"
340
- );
341
- };
342
-
343
- export function previewOptions(yargs: Argv) {
344
- return yargs
345
- .positional("method", {
346
- type: "string",
347
- describe: "Type of request to preview your worker",
348
- })
349
- .positional("body", {
350
- type: "string",
351
- describe: "Body string to post to your preview worker request.",
352
- })
353
- .option("env", {
354
- type: "string",
355
- requiresArg: true,
356
- describe: "Perform on a specific environment",
357
- })
358
- .option("watch", {
359
- default: true,
360
- describe: "Enable live preview",
361
- type: "boolean",
362
- });
363
- }
364
-
365
- export function previewHandler() {
366
- throw new DeprecationError(
367
- "The `wrangler preview` command has been deprecated.\n" +
368
- "Try using `wrangler dev` to to try out a worker during development.\n"
369
- );
370
- }
371
-
372
- export const route: BuilderCallback<unknown, unknown> = (routeYargs: Argv) => {
373
- return routeYargs
374
- .command(
375
- "list",
376
- "List the routes associated with a zone",
377
- (yargs) => {
378
- return yargs
379
- .option("env", {
380
- type: "string",
381
- requiresArg: true,
382
- describe: "Perform on a specific environment",
383
- })
384
- .option("zone", {
385
- type: "string",
386
- requiresArg: true,
387
- describe: "Zone id",
388
- })
389
- .positional("zone", {
390
- describe: "Zone id",
391
- type: "string",
392
- });
393
- },
394
- () => {
395
- // "👯 [DEPRECATED]. Use wrangler.toml to manage routes.
396
- const deprecationNotice = "`wrangler route list` has been deprecated.";
397
- const futureRoutes =
398
- "Refer to wrangler.toml for a list of routes the worker will be deployed to upon publishing.";
399
- const presentRoutes =
400
- "Refer to the Cloudflare Dashboard to see the routes this worker is currently running on.";
401
- throw new DeprecationError(
402
- `${deprecationNotice}\n${futureRoutes}\n${presentRoutes}`
403
- );
404
- }
405
- )
406
- .command(
407
- "delete [id]",
408
- "Delete a route associated with a zone",
409
- (yargs) => {
410
- return yargs
411
- .positional("id", {
412
- describe: "The hash of the route ID to delete.",
413
- type: "string",
414
- })
415
- .option("zone", {
416
- type: "string",
417
- requiresArg: true,
418
- describe: "zone id",
419
- })
420
- .option("env", {
421
- type: "string",
422
- requiresArg: true,
423
- describe: "Perform on a specific environment",
424
- });
425
- },
426
- () => {
427
- // "👯 [DEPRECATED]. Use wrangler.toml to manage routes.
428
- const deprecationNotice =
429
- "`wrangler route delete` has been deprecated.";
430
- const shouldDo =
431
- "Remove the unwanted route(s) from wrangler.toml and run `wrangler publish` to remove your worker from those routes.";
432
- throw new DeprecationError(`${deprecationNotice}\n${shouldDo}`);
433
- }
434
- );
435
- };
436
-
437
- export const routeHandler = () => {
438
- // "[DEPRECATED]. Use wrangler.toml to manage routes.
439
- const deprecationNotice = "`wrangler route` has been deprecated.";
440
- const shouldDo =
441
- "Please use wrangler.toml and/or `wrangler publish --routes` to modify routes";
442
- throw new DeprecationError(`${deprecationNotice}\n${shouldDo}`);
443
- };
444
-
445
- export const subdomainOptions = (yargs: Argv) => {
446
- return yargs.positional("name", { type: "string" });
447
- };
448
-
449
- export const subdomainHandler = () => {
450
- throw new DeprecationError(
451
- "`wrangler subdomain` has been deprecated, please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#subdomain for alternatives"
452
- );
453
- };
@@ -1,36 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as path from "node:path";
3
- import dotenv from "dotenv";
4
- import { logger } from "../logger";
5
- import type { Config } from "../config";
6
-
7
- /**
8
- * Get the Worker `vars` bindings for a `wrangler dev` instance of a Worker.
9
- *
10
- * The `vars` bindings can be specified in the `wrangler.toml` configuration file.
11
- * But "secret" `vars` are usually only provided at the server -
12
- * either by creating them in the Dashboard UI, or using the `wrangler secret` command.
13
- *
14
- * It is useful during development, to provide these types of variable locally.
15
- * When running `wrangler dev` we will look for a file called `.dev.vars`, situated
16
- * next to the `wrangler.toml` file (or in the current working directory if there is no
17
- * `wrangler.toml`).
18
- *
19
- * Any values in this file, formatted like a `dotenv` file, will add to or override `vars`
20
- * bindings provided in the `wrangler.toml`.
21
- */
22
- export function getVarsForDev(config: Config): Config["vars"] {
23
- const configDir = path.resolve(path.dirname(config.configPath ?? "."));
24
- const devVarsPath = path.resolve(configDir, ".dev.vars");
25
- if (fs.existsSync(devVarsPath)) {
26
- const devVarsRelativePath = path.relative(process.cwd(), devVarsPath);
27
- logger.log(`Using vars defined in ${devVarsRelativePath}`);
28
- const devVars = dotenv.parse(fs.readFileSync(devVarsPath, "utf8"));
29
- return {
30
- ...config.vars,
31
- ...devVars,
32
- };
33
- } else {
34
- return config.vars;
35
- }
36
- }