wrangler 0.0.0-e41c7e41 → 0.0.0-e44afaf79

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 (275) hide show
  1. package/README.md +35 -45
  2. package/bin/wrangler.js +27 -102
  3. package/config-schema.json +2487 -0
  4. package/package.json +179 -192
  5. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  6. package/templates/__tests__/tsconfig.json +8 -0
  7. package/templates/checked-fetch.js +19 -6
  8. package/templates/facade.d.ts +19 -0
  9. package/templates/gitignore +2 -3
  10. package/templates/init-tests/test-jest-new-worker.js +3 -5
  11. package/templates/init-tests/test-vitest-new-worker.js +4 -6
  12. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  13. package/templates/middleware/common.ts +9 -4
  14. package/templates/middleware/loader-modules.ts +94 -44
  15. package/templates/middleware/loader-sw.ts +6 -4
  16. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  17. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  18. package/templates/middleware/middleware-patch-console-prefix.d.ts +3 -0
  19. package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
  20. package/templates/middleware/middleware-scheduled.ts +15 -1
  21. package/templates/mixedMode/proxyServerWorker/index.ts +40 -0
  22. package/templates/mixedMode/proxyServerWorker/wrangler.jsonc +4 -0
  23. package/templates/modules-watch-stub.js +4 -0
  24. package/templates/new-worker-scheduled.ts +1 -1
  25. package/templates/new-worker.ts +4 -1
  26. package/templates/pages-dev-pipeline.ts +8 -3
  27. package/templates/pages-dev-util.ts +4 -1
  28. package/templates/pages-shim.ts +1 -1
  29. package/templates/pages-template-plugin.ts +33 -14
  30. package/templates/pages-template-worker.ts +12 -3
  31. package/templates/startDevWorker/InspectorProxyWorker.ts +679 -0
  32. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  33. package/templates/strip-cf-connecting-ip-header.js +13 -0
  34. package/templates/tsconfig-sanity.ts +11 -0
  35. package/templates/tsconfig.init.json +22 -0
  36. package/templates/tsconfig.json +12 -103
  37. package/templates/tsconfig.tsbuildinfo +1 -0
  38. package/wrangler-dist/InspectorProxyWorker.js +471 -0
  39. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  40. package/wrangler-dist/ProxyWorker.js +238 -0
  41. package/wrangler-dist/ProxyWorker.js.map +6 -0
  42. package/wrangler-dist/cli.d.ts +2054 -512
  43. package/wrangler-dist/cli.js +172903 -159717
  44. package/wrangler-dist/cli.js.map +1 -0
  45. package/wrangler-dist/metafile-cjs.json +1 -0
  46. package/Cloudflare_CA.pem +0 -18
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/miniflare-dist/index.mjs +0 -6316
  52. package/src/__tests__/access.test.ts +0 -25
  53. package/src/__tests__/api-dev.test.ts +0 -209
  54. package/src/__tests__/api-devregistry.test.js +0 -56
  55. package/src/__tests__/api.test.ts +0 -80
  56. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  57. package/src/__tests__/config-cache.test.ts +0 -42
  58. package/src/__tests__/configuration.test.ts +0 -3981
  59. package/src/__tests__/d1.test.ts +0 -80
  60. package/src/__tests__/delete.test.ts +0 -230
  61. package/src/__tests__/deployments.test.ts +0 -91
  62. package/src/__tests__/dev.test.tsx +0 -1536
  63. package/src/__tests__/dialogs.test.tsx +0 -40
  64. package/src/__tests__/generate.test.ts +0 -235
  65. package/src/__tests__/get-host-from-url.test.ts +0 -16
  66. package/src/__tests__/guess-worker-format.test.ts +0 -85
  67. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  68. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  69. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  70. package/src/__tests__/helpers/mock-bin.ts +0 -36
  71. package/src/__tests__/helpers/mock-cfetch.ts +0 -333
  72. package/src/__tests__/helpers/mock-console.ts +0 -106
  73. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  74. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -8
  75. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  76. package/src/__tests__/helpers/mock-istty.ts +0 -74
  77. package/src/__tests__/helpers/mock-known-routes.ts +0 -7
  78. package/src/__tests__/helpers/mock-kv.ts +0 -33
  79. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -252
  80. package/src/__tests__/helpers/mock-process.ts +0 -39
  81. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  82. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  83. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  84. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -59
  85. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -104
  86. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -36
  87. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -80
  88. package/src/__tests__/helpers/msw/handlers/script.ts +0 -75
  89. package/src/__tests__/helpers/msw/handlers/user.ts +0 -63
  90. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -22
  91. package/src/__tests__/helpers/msw/index.ts +0 -21
  92. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  93. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  94. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  95. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  96. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  97. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  98. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  99. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  100. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  101. package/src/__tests__/https-options.test.ts +0 -163
  102. package/src/__tests__/index.test.ts +0 -264
  103. package/src/__tests__/init.test.ts +0 -2900
  104. package/src/__tests__/jest.setup.ts +0 -202
  105. package/src/__tests__/kv.test.ts +0 -1675
  106. package/src/__tests__/logger.test.ts +0 -141
  107. package/src/__tests__/metrics.test.ts +0 -450
  108. package/src/__tests__/middleware.scheduled.test.ts +0 -135
  109. package/src/__tests__/middleware.test.ts +0 -726
  110. package/src/__tests__/package-manager.test.ts +0 -353
  111. package/src/__tests__/pages-deployment-tail.test.ts +0 -820
  112. package/src/__tests__/pages.test.ts +0 -2442
  113. package/src/__tests__/parse.test.ts +0 -330
  114. package/src/__tests__/paths.test.ts +0 -39
  115. package/src/__tests__/publish.test.ts +0 -7633
  116. package/src/__tests__/pubsub.test.ts +0 -370
  117. package/src/__tests__/queues.test.ts +0 -371
  118. package/src/__tests__/r2.test.ts +0 -393
  119. package/src/__tests__/route.test.ts +0 -45
  120. package/src/__tests__/secret.test.ts +0 -644
  121. package/src/__tests__/tail.test.ts +0 -800
  122. package/src/__tests__/test-old-node-version.js +0 -31
  123. package/src/__tests__/type-generation.test.ts +0 -226
  124. package/src/__tests__/user.test.ts +0 -155
  125. package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
  126. package/src/__tests__/validate-dev-props.test.ts +0 -56
  127. package/src/__tests__/version.test.ts +0 -35
  128. package/src/__tests__/whoami.test.tsx +0 -278
  129. package/src/__tests__/worker-namespace.test.ts +0 -326
  130. package/src/abort.d.ts +0 -3
  131. package/src/api/dev.ts +0 -210
  132. package/src/api/index.ts +0 -2
  133. package/src/bundle-reporter.tsx +0 -68
  134. package/src/bundle.ts +0 -823
  135. package/src/cfetch/index.ts +0 -160
  136. package/src/cfetch/internal.ts +0 -263
  137. package/src/cli.ts +0 -28
  138. package/src/config/README.md +0 -107
  139. package/src/config/config.ts +0 -275
  140. package/src/config/diagnostics.ts +0 -80
  141. package/src/config/environment.ts +0 -561
  142. package/src/config/index.ts +0 -334
  143. package/src/config/validation-helpers.ts +0 -597
  144. package/src/config/validation.ts +0 -2103
  145. package/src/config-cache.ts +0 -85
  146. package/src/create-worker-preview.ts +0 -282
  147. package/src/create-worker-upload-form.ts +0 -316
  148. package/src/d1/backups.tsx +0 -218
  149. package/src/d1/constants.ts +0 -2
  150. package/src/d1/create.tsx +0 -63
  151. package/src/d1/delete.tsx +0 -56
  152. package/src/d1/execute.tsx +0 -352
  153. package/src/d1/formatTimeAgo.ts +0 -14
  154. package/src/d1/index.ts +0 -99
  155. package/src/d1/list.tsx +0 -48
  156. package/src/d1/migrations.tsx +0 -446
  157. package/src/d1/options.ts +0 -22
  158. package/src/d1/types.tsx +0 -24
  159. package/src/d1/utils.ts +0 -48
  160. package/src/delete.ts +0 -108
  161. package/src/deployments.ts +0 -77
  162. package/src/deprecated/index.ts +0 -438
  163. package/src/dev/dev-vars.ts +0 -39
  164. package/src/dev/dev.tsx +0 -590
  165. package/src/dev/get-local-persistence-path.tsx +0 -31
  166. package/src/dev/local.tsx +0 -886
  167. package/src/dev/remote.tsx +0 -603
  168. package/src/dev/start-server.ts +0 -538
  169. package/src/dev/use-esbuild.ts +0 -204
  170. package/src/dev/validate-dev-props.ts +0 -31
  171. package/src/dev-registry.tsx +0 -201
  172. package/src/dev.tsx +0 -905
  173. package/src/dialogs.tsx +0 -168
  174. package/src/dispatch-namespace.ts +0 -207
  175. package/src/durable.ts +0 -102
  176. package/src/entry.ts +0 -329
  177. package/src/environment-variables.ts +0 -50
  178. package/src/errors.ts +0 -11
  179. package/src/git-client.ts +0 -124
  180. package/src/global-wrangler-config-path.ts +0 -26
  181. package/src/https-options.ts +0 -127
  182. package/src/index.tsx +0 -682
  183. package/src/init.ts +0 -970
  184. package/src/inspect.ts +0 -767
  185. package/src/intl-polyfill.d.ts +0 -139
  186. package/src/is-ci.ts +0 -14
  187. package/src/is-interactive.ts +0 -16
  188. package/src/kv/helpers.ts +0 -430
  189. package/src/kv/index.ts +0 -596
  190. package/src/logger.ts +0 -92
  191. package/src/metrics/index.ts +0 -5
  192. package/src/metrics/metrics-config.ts +0 -239
  193. package/src/metrics/metrics-dispatcher.ts +0 -96
  194. package/src/metrics/metrics-usage-headers.ts +0 -24
  195. package/src/metrics/send-event.ts +0 -96
  196. package/src/miniflare-cli/README.md +0 -30
  197. package/src/miniflare-cli/assets.ts +0 -215
  198. package/src/miniflare-cli/index.ts +0 -213
  199. package/src/miniflare-cli/request-context.ts +0 -40
  200. package/src/module-collection.ts +0 -267
  201. package/src/open-in-browser.ts +0 -17
  202. package/src/package-manager.ts +0 -219
  203. package/src/pages/build.tsx +0 -270
  204. package/src/pages/constants.ts +0 -18
  205. package/src/pages/deployment-tails.tsx +0 -284
  206. package/src/pages/deployments.tsx +0 -84
  207. package/src/pages/dev.tsx +0 -708
  208. package/src/pages/errors.ts +0 -66
  209. package/src/pages/functions/buildPlugin.ts +0 -107
  210. package/src/pages/functions/buildWorker.ts +0 -166
  211. package/src/pages/functions/filepath-routing.test.ts +0 -234
  212. package/src/pages/functions/filepath-routing.ts +0 -189
  213. package/src/pages/functions/identifiers.ts +0 -78
  214. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  215. package/src/pages/functions/routes-consolidation.ts +0 -73
  216. package/src/pages/functions/routes-transformation.test.ts +0 -282
  217. package/src/pages/functions/routes-transformation.ts +0 -115
  218. package/src/pages/functions/routes-validation.test.ts +0 -403
  219. package/src/pages/functions/routes-validation.ts +0 -202
  220. package/src/pages/functions/routes.ts +0 -151
  221. package/src/pages/functions.tsx +0 -82
  222. package/src/pages/hash.tsx +0 -13
  223. package/src/pages/index.tsx +0 -102
  224. package/src/pages/projects.tsx +0 -169
  225. package/src/pages/prompt-select-project.tsx +0 -31
  226. package/src/pages/publish.tsx +0 -451
  227. package/src/pages/types.ts +0 -41
  228. package/src/pages/upload.tsx +0 -426
  229. package/src/pages/utils.ts +0 -23
  230. package/src/parse.ts +0 -286
  231. package/src/paths.ts +0 -71
  232. package/src/proxy.ts +0 -689
  233. package/src/publish/index.ts +0 -270
  234. package/src/publish/publish.ts +0 -1035
  235. package/src/pubsub/index.ts +0 -286
  236. package/src/pubsub/pubsub-commands.tsx +0 -624
  237. package/src/queues/cli/commands/consumer/add.ts +0 -71
  238. package/src/queues/cli/commands/consumer/index.ts +0 -22
  239. package/src/queues/cli/commands/consumer/remove.ts +0 -38
  240. package/src/queues/cli/commands/create.ts +0 -25
  241. package/src/queues/cli/commands/delete.ts +0 -26
  242. package/src/queues/cli/commands/index.ts +0 -33
  243. package/src/queues/cli/commands/list.ts +0 -25
  244. package/src/queues/client.ts +0 -135
  245. package/src/r2/constants.ts +0 -4
  246. package/src/r2/helpers.ts +0 -131
  247. package/src/r2/index.ts +0 -289
  248. package/src/routes.ts +0 -140
  249. package/src/secret/index.ts +0 -378
  250. package/src/selfsigned.d.ts +0 -29
  251. package/src/sites.tsx +0 -372
  252. package/src/tail/createTail.ts +0 -379
  253. package/src/tail/filters.ts +0 -277
  254. package/src/tail/index.ts +0 -214
  255. package/src/tail/printing.ts +0 -107
  256. package/src/type-generation.ts +0 -173
  257. package/src/update-check.ts +0 -19
  258. package/src/user/access.ts +0 -69
  259. package/src/user/choose-account.tsx +0 -69
  260. package/src/user/env-vars.ts +0 -46
  261. package/src/user/generate-auth-url.ts +0 -33
  262. package/src/user/generate-random-state.ts +0 -16
  263. package/src/user/index.ts +0 -3
  264. package/src/user/user.tsx +0 -1192
  265. package/src/utils/collectKeyValues.ts +0 -14
  266. package/src/whoami.tsx +0 -169
  267. package/src/worker.ts +0 -245
  268. package/src/yargs-types.ts +0 -24
  269. package/src/zones.ts +0 -191
  270. package/templates/d1-beta-facade.js +0 -205
  271. package/templates/first-party-worker-module-facade.ts +0 -18
  272. package/templates/format-dev-errors.ts +0 -32
  273. package/templates/serve-static-assets.ts +0 -63
  274. package/templates/service-bindings-module-facade.js +0 -54
  275. package/templates/service-bindings-sw-facade.js +0 -42
package/src/init.ts DELETED
@@ -1,970 +0,0 @@
1
- import * as fs from "node:fs";
2
- import { writeFile, mkdir } from "node:fs/promises";
3
- import path from "node:path";
4
- import TOML from "@iarna/toml";
5
- import { findUp } from "find-up";
6
- import { version as wranglerVersion } from "../package.json";
7
-
8
- import { fetchResult } from "./cfetch";
9
- import { fetchDashboardScript } from "./cfetch/internal";
10
- import { readConfig } from "./config";
11
- import { confirm, select } from "./dialogs";
12
- import { initializeGit, getGitVersioon, isInsideGitRepo } from "./git-client";
13
- import { logger } from "./logger";
14
- import { getPackageManager } from "./package-manager";
15
- import { parsePackageJSON, parseTOML, readFileSync } from "./parse";
16
- import { getBasePath } from "./paths";
17
- import { requireAuth } from "./user";
18
- import { CommandLineArgsError, printWranglerBanner } from "./index";
19
-
20
- import type { RawConfig } from "./config";
21
- import type { Route, SimpleRoute } from "./config/environment";
22
- import type { WorkerMetadata } from "./create-worker-upload-form";
23
- import type { ConfigPath } from "./index";
24
- import type { PackageManager } from "./package-manager";
25
- import type { CommonYargsOptions } from "./yargs-types";
26
- import type { Argv, ArgumentsCamelCase } from "yargs";
27
-
28
- export async function initOptions(yargs: Argv<CommonYargsOptions>) {
29
- return yargs
30
- .positional("name", {
31
- describe: "The name of your worker",
32
- type: "string",
33
- })
34
- .option("type", {
35
- describe: "The type of worker to create",
36
- type: "string",
37
- choices: ["rust", "javascript", "webpack"],
38
- hidden: true,
39
- deprecated: true,
40
- })
41
- .option("site", {
42
- hidden: true,
43
- type: "boolean",
44
- deprecated: true,
45
- })
46
- .option("yes", {
47
- describe: 'Answer "yes" to any prompts for new projects',
48
- type: "boolean",
49
- alias: "y",
50
- })
51
- .option("from-dash", {
52
- describe: "Download script from the dashboard for local development",
53
- type: "string",
54
- requiresArg: true,
55
- });
56
- }
57
-
58
- interface InitArgs {
59
- name: string;
60
- type?: string;
61
- site?: boolean;
62
- yes?: boolean;
63
- }
64
-
65
- export type ServiceMetadataRes = {
66
- id: string;
67
- default_environment: {
68
- environment: string;
69
- created_on: string;
70
- modified_on: string;
71
- script: {
72
- id: string;
73
- tag: string;
74
- etag: string;
75
- handlers: string[];
76
- modified_on: string;
77
- created_on: string;
78
- migration_tag: string;
79
- usage_model: "bundled" | "unbound";
80
- compatibility_date: string;
81
- last_deployed_from?: "wrangler" | "dash" | "api";
82
- };
83
- };
84
- created_on: string;
85
- modified_on: string;
86
- usage_model: "bundled" | "unbound";
87
- environments: [
88
- {
89
- environment: string;
90
- created_on: string;
91
- modified_on: string;
92
- }
93
- ];
94
- };
95
-
96
- export type RawSimpleRoute = { pattern: string };
97
- export type RawRoutes = (RawSimpleRoute | Exclude<Route, SimpleRoute>) & {
98
- id: string;
99
- };
100
- export type RoutesRes = RawRoutes[];
101
-
102
- export type CronTriggersRes = {
103
- schedules: [
104
- {
105
- cron: string;
106
- created_on: Date;
107
- modified_on: Date;
108
- }
109
- ];
110
- };
111
-
112
- export async function initHandler(args: ArgumentsCamelCase<InitArgs>) {
113
- await printWranglerBanner();
114
- if (args.type) {
115
- let message = "The --type option is no longer supported.";
116
- if (args.type === "webpack") {
117
- message +=
118
- "\nIf you wish to use webpack then you will need to create a custom build.";
119
- // TODO: Add a link to docs
120
- }
121
- throw new CommandLineArgsError(message);
122
- }
123
-
124
- const devDepsToInstall: string[] = [];
125
- const instructions: string[] = [];
126
- let shouldRunPackageManagerInstall = false;
127
- const fromDashScriptName = args["from-dash"] as string;
128
- const creationDirectory = path.resolve(
129
- process.cwd(),
130
- (args.name ? args.name : fromDashScriptName) ?? ""
131
- );
132
-
133
- if (args.site) {
134
- const gitDirectory =
135
- creationDirectory !== process.cwd()
136
- ? path.basename(creationDirectory)
137
- : "my-site";
138
- const message =
139
- "The --site option is no longer supported.\n" +
140
- "If you wish to create a brand new Worker Sites project then clone the `worker-sites-template` starter repository:\n\n" +
141
- "```\n" +
142
- `git clone --depth=1 --branch=wrangler2 https://github.com/cloudflare/worker-sites-template ${gitDirectory}\n` +
143
- `cd ${gitDirectory}\n` +
144
- "```\n\n" +
145
- "Find out more about how to create and maintain Sites projects at https://developers.cloudflare.com/workers/platform/sites.\n" +
146
- "Have you considered using Cloudflare Pages instead? See https://pages.cloudflare.com/.";
147
- throw new CommandLineArgsError(message);
148
- }
149
-
150
- // TODO: make sure args.name is a valid identifier for a worker name
151
- const workerName = path
152
- .basename(creationDirectory)
153
- .toLowerCase()
154
- .replaceAll(/[^a-z0-9\-_]/gm, "-");
155
-
156
- const packageManager = await getPackageManager(creationDirectory);
157
-
158
- // TODO: ask which directory to make the worker in (defaults to args.name)
159
- // TODO: if args.name isn't provided, ask what to name the worker
160
- // Note: `--from-dash` will be a fallback creationDir/Worker name if none is provided.
161
-
162
- const wranglerTomlDestination = path.join(
163
- creationDirectory,
164
- "./wrangler.toml"
165
- );
166
- let justCreatedWranglerToml = false;
167
-
168
- if (fs.existsSync(wranglerTomlDestination)) {
169
- let shouldContinue = false;
170
- logger.warn(
171
- `${path.relative(process.cwd(), wranglerTomlDestination)} already exists!`
172
- );
173
- if (!fromDashScriptName) {
174
- shouldContinue = await confirm(
175
- "Do you want to continue initializing this project?"
176
- );
177
- }
178
- if (!shouldContinue) {
179
- return;
180
- }
181
- } else {
182
- await mkdir(creationDirectory, { recursive: true });
183
- const compatibilityDate = new Date().toISOString().substring(0, 10);
184
-
185
- try {
186
- await writeFile(
187
- wranglerTomlDestination,
188
- TOML.stringify({
189
- name: workerName,
190
- compatibility_date: compatibilityDate,
191
- }) + "\n"
192
- );
193
-
194
- logger.log(
195
- `✨ Created ${path.relative(process.cwd(), wranglerTomlDestination)}`
196
- );
197
- justCreatedWranglerToml = true;
198
- } catch (err) {
199
- throw new Error(
200
- `Failed to create ${path.relative(
201
- process.cwd(),
202
- wranglerTomlDestination
203
- )}.\n${(err as Error).message ?? err}`
204
- );
205
- }
206
- }
207
-
208
- const yesFlag = args.yes ?? false;
209
-
210
- if (!(await isInsideGitRepo(creationDirectory)) && (await getGitVersioon())) {
211
- const shouldInitGit =
212
- yesFlag ||
213
- (await confirm("Would you like to use git to manage this Worker?"));
214
- if (shouldInitGit) {
215
- await initializeGit(creationDirectory);
216
- await writeFile(
217
- path.join(creationDirectory, ".gitignore"),
218
- readFileSync(path.join(getBasePath(), "templates/gitignore"))
219
- );
220
- logger.log(
221
- args.name && args.name !== "."
222
- ? `✨ Initialized git repository at ${path.relative(
223
- process.cwd(),
224
- creationDirectory
225
- )}`
226
- : `✨ Initialized git repository`
227
- );
228
- }
229
- }
230
-
231
- const isolatedInit = !!args.name;
232
- let pathToPackageJson = await findPath(
233
- isolatedInit,
234
- creationDirectory,
235
- "package.json"
236
- );
237
- let shouldCreatePackageJson = false;
238
- let shouldCreateTests = false;
239
- let newWorkerTestType: "jest" | "vitest" = "jest";
240
-
241
- if (!pathToPackageJson) {
242
- // If no package.json exists, ask to create one
243
- shouldCreatePackageJson =
244
- yesFlag ||
245
- (await confirm("No package.json found. Would you like to create one?"));
246
-
247
- if (shouldCreatePackageJson) {
248
- await writeFile(
249
- path.join(creationDirectory, "./package.json"),
250
- JSON.stringify(
251
- {
252
- name: workerName,
253
- version: "0.0.0",
254
- devDependencies: {
255
- wrangler: wranglerVersion,
256
- },
257
- private: true,
258
- },
259
- null,
260
- " "
261
- ) + "\n"
262
- );
263
-
264
- shouldRunPackageManagerInstall = true;
265
- pathToPackageJson = path.join(creationDirectory, "package.json");
266
- logger.log(
267
- `✨ Created ${path.relative(process.cwd(), pathToPackageJson)}`
268
- );
269
- } else {
270
- return;
271
- }
272
- } else {
273
- // If package.json exists and wrangler isn't installed,
274
- // then ask to add wrangler to devDependencies
275
- const packageJson = parsePackageJSON(
276
- readFileSync(pathToPackageJson),
277
- pathToPackageJson
278
- );
279
- if (
280
- !(
281
- packageJson.devDependencies?.wrangler ||
282
- packageJson.dependencies?.wrangler
283
- )
284
- ) {
285
- const shouldInstall =
286
- yesFlag ||
287
- (await confirm(
288
- `Would you like to install wrangler into ${path.relative(
289
- process.cwd(),
290
- pathToPackageJson
291
- )}?`
292
- ));
293
- if (shouldInstall) {
294
- devDepsToInstall.push(`wrangler@${wranglerVersion}`);
295
- }
296
- }
297
- }
298
-
299
- let isTypescriptProject = false;
300
- let pathToTSConfig = await findPath(
301
- isolatedInit,
302
- creationDirectory,
303
- "tsconfig.json"
304
- );
305
- if (!pathToTSConfig) {
306
- // If there's no tsconfig, offer to create one
307
- // and install @cloudflare/workers-types
308
- if (yesFlag || (await confirm("Would you like to use TypeScript?"))) {
309
- isTypescriptProject = true;
310
- await writeFile(
311
- path.join(creationDirectory, "./tsconfig.json"),
312
- readFileSync(path.join(getBasePath(), "templates/tsconfig.json"))
313
- );
314
- devDepsToInstall.push("@cloudflare/workers-types");
315
- devDepsToInstall.push("typescript");
316
- pathToTSConfig = path.join(creationDirectory, "tsconfig.json");
317
- logger.log(`✨ Created ${path.relative(process.cwd(), pathToTSConfig)}`);
318
- }
319
- } else {
320
- isTypescriptProject = true;
321
- // If there's a tsconfig, check if @cloudflare/workers-types
322
- // is already installed, and offer to install it if not
323
- const packageJson = parsePackageJSON(
324
- readFileSync(pathToPackageJson),
325
- pathToPackageJson
326
- );
327
- if (
328
- !(
329
- packageJson.devDependencies?.["@cloudflare/workers-types"] ||
330
- packageJson.dependencies?.["@cloudflare/workers-types"]
331
- )
332
- ) {
333
- const shouldInstall = await confirm(
334
- "Would you like to install the type definitions for Workers into your package.json?"
335
- );
336
- if (shouldInstall) {
337
- devDepsToInstall.push("@cloudflare/workers-types");
338
- // We don't update the tsconfig.json because
339
- // it could be complicated in existing projects
340
- // and we don't want to break them. Instead, we simply
341
- // tell the user that they need to update their tsconfig.json
342
- instructions.push(
343
- `🚨 Please add "@cloudflare/workers-types" to compilerOptions.types in ${path.relative(
344
- process.cwd(),
345
- pathToTSConfig
346
- )}`
347
- );
348
- }
349
- }
350
- }
351
-
352
- const packageJsonContent = parsePackageJSON(
353
- readFileSync(pathToPackageJson),
354
- pathToPackageJson
355
- );
356
- const shouldWritePackageJsonScripts =
357
- !packageJsonContent.scripts?.start &&
358
- !packageJsonContent.scripts?.publish &&
359
- shouldCreatePackageJson;
360
-
361
- async function writePackageJsonScriptsAndUpdateWranglerToml({
362
- isWritingScripts,
363
- isAddingTests,
364
- testRunner,
365
- isCreatingWranglerToml,
366
- packagePath,
367
- scriptPath,
368
- extraToml,
369
- }: {
370
- isWritingScripts: boolean;
371
- isAddingTests?: boolean;
372
- testRunner?: "jest" | "vitest";
373
- isCreatingWranglerToml: boolean;
374
- packagePath: string;
375
- scriptPath: string;
376
- extraToml: TOML.JsonMap;
377
- }) {
378
- if (isAddingTests && !testRunner) {
379
- logger.error("testRunner is required if isAddingTests");
380
- }
381
- if (isCreatingWranglerToml) {
382
- // rewrite wrangler.toml with main = "path/to/script" and any additional config specified in `extraToml`
383
- const parsedWranglerToml = parseTOML(
384
- readFileSync(wranglerTomlDestination)
385
- );
386
- const newToml = {
387
- name: parsedWranglerToml.name,
388
- main: scriptPath,
389
- compatibility_date: parsedWranglerToml.compatibility_date,
390
- ...extraToml,
391
- };
392
- fs.writeFileSync(wranglerTomlDestination, TOML.stringify(newToml));
393
- }
394
- const isNamedWorker =
395
- isCreatingWranglerToml && path.dirname(packagePath) !== process.cwd();
396
- const isAddingTestScripts =
397
- isAddingTests && !packageJsonContent.scripts?.test;
398
- if (isWritingScripts) {
399
- await writeFile(
400
- packagePath,
401
- JSON.stringify(
402
- {
403
- ...packageJsonContent,
404
- scripts: {
405
- ...packageJsonContent.scripts,
406
- start: isCreatingWranglerToml
407
- ? `wrangler dev`
408
- : `wrangler dev ${scriptPath}`,
409
- deploy: isCreatingWranglerToml
410
- ? `wrangler publish`
411
- : `wrangler publish ${scriptPath}`,
412
- ...(isAddingTestScripts && { test: testRunner }),
413
- },
414
- },
415
- null,
416
- 2
417
- ) + "\n"
418
- );
419
- instructions.push(
420
- `\nTo start developing your Worker, run \`${
421
- isNamedWorker ? `cd ${args.name || fromDashScriptName} && ` : ""
422
- }npm start\``
423
- );
424
- if (isAddingTestScripts) {
425
- instructions.push(`To start testing your Worker, run \`npm test\``);
426
- }
427
- instructions.push(
428
- `To publish your Worker to the Internet, run \`npm run deploy\``
429
- );
430
- } else {
431
- instructions.push(
432
- `\nTo start developing your Worker, run \`npx wrangler dev\`${
433
- isCreatingWranglerToml ? "" : ` ${scriptPath}`
434
- }`
435
- );
436
- instructions.push(
437
- `To publish your Worker to the Internet, run \`npx wrangler publish\`${
438
- isCreatingWranglerToml ? "" : ` ${scriptPath}`
439
- }`
440
- );
441
- }
442
- }
443
-
444
- if (isTypescriptProject) {
445
- if (!fs.existsSync(path.join(creationDirectory, "./src/index.ts"))) {
446
- const newWorkerFilename = path.relative(
447
- process.cwd(),
448
- path.join(creationDirectory, "./src/index.ts")
449
- );
450
- if (fromDashScriptName) {
451
- logger.warn(
452
- `After running "wrangler init --from-dash", modifying your worker via the Cloudflare dashboard is discouraged.
453
- Edits made via the Dashboard will not be synchronized locally and will be overridden by your local code and config when you publish.`
454
- );
455
- const config = readConfig(args.config as ConfigPath, args);
456
- const accountId = await requireAuth(config);
457
- await mkdir(path.join(creationDirectory, "./src"), {
458
- recursive: true,
459
- });
460
- const serviceMetaData = await fetchResult<ServiceMetadataRes>(
461
- `/accounts/${accountId}/workers/services/${fromDashScriptName}`
462
- );
463
- const defaultEnvironment =
464
- serviceMetaData.default_environment.environment;
465
- // I want the default environment, assuming it's the most up to date code.
466
- const dashScript = await fetchDashboardScript(
467
- `/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}/content`
468
- );
469
-
470
- await writeFile(
471
- path.join(creationDirectory, "./src/index.ts"),
472
- dashScript
473
- );
474
-
475
- await writePackageJsonScriptsAndUpdateWranglerToml({
476
- isWritingScripts: shouldWritePackageJsonScripts,
477
- isCreatingWranglerToml: justCreatedWranglerToml,
478
- packagePath: pathToPackageJson,
479
- scriptPath: "src/index.ts",
480
- extraToml: (await getWorkerConfig(accountId, fromDashScriptName, {
481
- defaultEnvironment,
482
- environments: serviceMetaData.environments,
483
- })) as TOML.JsonMap,
484
- });
485
- } else {
486
- const newWorkerType = yesFlag
487
- ? "fetch"
488
- : await getNewWorkerType(newWorkerFilename);
489
-
490
- if (newWorkerType !== "none") {
491
- const template = getNewWorkerTemplate("ts", newWorkerType);
492
-
493
- await mkdir(path.join(creationDirectory, "./src"), {
494
- recursive: true,
495
- });
496
- await writeFile(
497
- path.join(creationDirectory, "./src/index.ts"),
498
- readFileSync(path.join(getBasePath(), `templates/${template}`))
499
- );
500
-
501
- logger.log(
502
- `✨ Created ${path.relative(
503
- process.cwd(),
504
- path.join(creationDirectory, "./src/index.ts")
505
- )}`
506
- );
507
-
508
- await writePackageJsonScriptsAndUpdateWranglerToml({
509
- isWritingScripts: shouldWritePackageJsonScripts,
510
- isCreatingWranglerToml: justCreatedWranglerToml,
511
- packagePath: pathToPackageJson,
512
- scriptPath: "src/index.ts",
513
- extraToml: getNewWorkerToml(newWorkerType),
514
- });
515
- }
516
- }
517
- }
518
- } else {
519
- if (!fs.existsSync(path.join(creationDirectory, "./src/index.js"))) {
520
- const newWorkerFilename = path.relative(
521
- process.cwd(),
522
- path.join(creationDirectory, "./src/index.js")
523
- );
524
-
525
- if (fromDashScriptName) {
526
- logger.warn(
527
- `After running "wrangler init --from-dash", modifying your worker via the Cloudflare dashboard is discouraged.
528
- Edits made via the Dashboard will not be synchronized locally and will be overridden by your local code and config when you publish.`
529
- );
530
- const config = readConfig(args.config as ConfigPath, args);
531
- const accountId = await requireAuth(config);
532
- await mkdir(path.join(creationDirectory, "./src"), {
533
- recursive: true,
534
- });
535
-
536
- const serviceMetaData = await fetchResult<ServiceMetadataRes>(
537
- `/accounts/${accountId}/workers/services/${fromDashScriptName}`
538
- );
539
- const defaultEnvironment =
540
- serviceMetaData.default_environment.environment;
541
-
542
- // I want the default environment, assuming it's the most up to date code.
543
- const dashScript = await fetchDashboardScript(
544
- `/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}/content`
545
- );
546
-
547
- await writeFile(
548
- path.join(creationDirectory, "./src/index.js"),
549
- dashScript
550
- );
551
-
552
- await writePackageJsonScriptsAndUpdateWranglerToml({
553
- isWritingScripts: shouldWritePackageJsonScripts,
554
- isCreatingWranglerToml: justCreatedWranglerToml,
555
- packagePath: pathToPackageJson,
556
- scriptPath: "src/index.ts",
557
- //? Should we have Environment argument for `wrangler init --from-dash` - Jacob
558
- extraToml: (await getWorkerConfig(accountId, fromDashScriptName, {
559
- defaultEnvironment,
560
- environments: serviceMetaData.environments,
561
- })) as TOML.JsonMap,
562
- });
563
- } else {
564
- const newWorkerType = yesFlag
565
- ? "fetch"
566
- : await getNewWorkerType(newWorkerFilename);
567
-
568
- if (newWorkerType !== "none") {
569
- const template = getNewWorkerTemplate("js", newWorkerType);
570
-
571
- await mkdir(path.join(creationDirectory, "./src"), {
572
- recursive: true,
573
- });
574
- await writeFile(
575
- path.join(creationDirectory, "./src/index.js"),
576
- readFileSync(path.join(getBasePath(), `templates/${template}`))
577
- );
578
-
579
- logger.log(
580
- `✨ Created ${path.relative(
581
- process.cwd(),
582
- path.join(creationDirectory, "./src/index.js")
583
- )}`
584
- );
585
-
586
- shouldCreateTests =
587
- yesFlag ||
588
- (await confirm("Would you like us to write your first test?"));
589
-
590
- if (shouldCreateTests) {
591
- newWorkerTestType = await getNewWorkerTestType();
592
- devDepsToInstall.push(newWorkerTestType);
593
- await writeFile(
594
- path.join(creationDirectory, "./src/index.test.js"),
595
- readFileSync(
596
- path.join(
597
- getBasePath(),
598
- `templates/init-tests/test-${newWorkerTestType}-new-worker.js`
599
- )
600
- )
601
- );
602
- logger.log(
603
- `✨ Created ${path.relative(
604
- process.cwd(),
605
- path.join(creationDirectory, "./src/index.test.js")
606
- )}`
607
- );
608
- }
609
-
610
- await writePackageJsonScriptsAndUpdateWranglerToml({
611
- isWritingScripts: shouldWritePackageJsonScripts,
612
- isAddingTests: shouldCreateTests,
613
- testRunner: newWorkerTestType,
614
- isCreatingWranglerToml: justCreatedWranglerToml,
615
- packagePath: pathToPackageJson,
616
- scriptPath: "src/index.js",
617
- extraToml: getNewWorkerToml(newWorkerType),
618
- });
619
- }
620
- }
621
- }
622
- }
623
- // install packages as the final step of init
624
- try {
625
- await installPackages(
626
- shouldRunPackageManagerInstall,
627
- devDepsToInstall,
628
- packageManager
629
- );
630
- } catch (e) {
631
- // fetching packages could fail due to loss of internet, etc
632
- // we should let folks know we failed to fetch, but their
633
- // workers project is still ready to go
634
- logger.error(e instanceof Error ? e.message : e);
635
- instructions.push(
636
- "\n🚨 wrangler was unable to fetch your npm packages, but your project is ready to go"
637
- );
638
- }
639
-
640
- // let users know what to do now
641
- instructions.forEach((instruction) => logger.log(instruction));
642
- }
643
-
644
- /*
645
- * Passes the array of accumulated devDeps to install through to
646
- * the package manager. Also generates a human-readable list
647
- * of packages it installed.
648
- * If there are no devDeps to install, optionally runs
649
- * the package manager's install command.
650
- */
651
- async function installPackages(
652
- shouldRunInstall: boolean,
653
- depsToInstall: string[],
654
- packageManager: PackageManager
655
- ) {
656
- //lets install the devDeps they asked for
657
- //and run their package manager's install command if needed
658
- if (depsToInstall.length > 0) {
659
- const formatter = new Intl.ListFormat("en", {
660
- style: "long",
661
- type: "conjunction",
662
- });
663
- await packageManager.addDevDeps(...depsToInstall);
664
- const versionlessPackages = depsToInstall.map((dep) =>
665
- dep === `wrangler@${wranglerVersion}` ? "wrangler" : dep
666
- );
667
-
668
- logger.log(
669
- `✨ Installed ${formatter.format(
670
- versionlessPackages
671
- )} into devDependencies`
672
- );
673
- } else {
674
- if (shouldRunInstall) {
675
- await packageManager.install();
676
- }
677
- }
678
- }
679
-
680
- async function getNewWorkerType(newWorkerFilename: string) {
681
- return select(
682
- `Would you like to create a Worker at ${newWorkerFilename}?`,
683
- [
684
- {
685
- value: "none",
686
- label: "None",
687
- },
688
- {
689
- value: "fetch",
690
- label: "Fetch handler",
691
- },
692
- {
693
- value: "scheduled",
694
- label: "Scheduled handler",
695
- },
696
- ],
697
- 1
698
- ) as Promise<"none" | "fetch" | "scheduled">;
699
- }
700
-
701
- async function getNewWorkerTestType() {
702
- return select(
703
- `Which test runner would you like to use?`,
704
- [
705
- {
706
- value: "vitest",
707
- label: "Vitest",
708
- },
709
- {
710
- value: "jest",
711
- label: "Jest",
712
- },
713
- ],
714
- 1
715
- ) as Promise<"jest" | "vitest">;
716
- }
717
-
718
- function getNewWorkerTemplate(
719
- lang: "js" | "ts",
720
- workerType: "fetch" | "scheduled"
721
- ) {
722
- const templates = {
723
- "js-fetch": "new-worker.js",
724
- "js-scheduled": "new-worker-scheduled.js",
725
- "ts-fetch": "new-worker.ts",
726
- "ts-scheduled": "new-worker-scheduled.ts",
727
- };
728
-
729
- return templates[`${lang}-${workerType}`];
730
- }
731
-
732
- function getNewWorkerToml(workerType: "fetch" | "scheduled"): TOML.JsonMap {
733
- if (workerType === "scheduled") {
734
- return {
735
- triggers: {
736
- crons: ["1 * * * *"],
737
- },
738
- };
739
- }
740
-
741
- return {};
742
- }
743
-
744
- /**
745
- * Find the path to the given `basename` file from the `cwd`.
746
- *
747
- * If `isolatedInit` is true then we only look in the `cwd` directory for the file.
748
- * Otherwise we also search up the tree.
749
- */
750
- async function findPath(
751
- isolatedInit: boolean,
752
- cwd: string,
753
- basename: string
754
- ): Promise<string | undefined> {
755
- if (isolatedInit) {
756
- return fs.existsSync(path.resolve(cwd, basename))
757
- ? path.resolve(cwd, basename)
758
- : undefined;
759
- } else {
760
- return await findUp(basename, {
761
- cwd: cwd,
762
- });
763
- }
764
- }
765
-
766
- async function getWorkerConfig(
767
- accountId: string,
768
- fromDashScriptName: string,
769
- {
770
- defaultEnvironment,
771
- environments,
772
- }: {
773
- defaultEnvironment: string;
774
- environments: ServiceMetadataRes["environments"];
775
- }
776
- ): Promise<RawConfig> {
777
- const [bindings, routes, serviceEnvMetadata, cronTriggers] =
778
- await Promise.all([
779
- fetchResult<WorkerMetadata["bindings"]>(
780
- `/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}/bindings`
781
- ),
782
- fetchResult<RoutesRes>(
783
- `/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}/routes`
784
- ),
785
- fetchResult<ServiceMetadataRes["default_environment"]>(
786
- `/accounts/${accountId}/workers/services/${fromDashScriptName}/environments/${defaultEnvironment}`
787
- ),
788
- fetchResult<CronTriggersRes>(
789
- `/accounts/${accountId}/workers/scripts/${fromDashScriptName}/schedules`
790
- ),
791
- ]).catch((e) => {
792
- throw new Error(
793
- `Error Occurred ${e}: Unable to fetch bindings, routes, or services metadata from the dashboard. Please try again later.`
794
- );
795
- });
796
-
797
- const mappedBindings = bindings
798
- .filter((binding) => (binding.type as string) !== "secret_text")
799
- // Combine the same types into {[type]: [binding]}
800
- .reduce((configObj, binding) => {
801
- // Some types have different names in wrangler.toml
802
- // I want the type safety of the binding being destructured after the case narrowing the union but type is unused
803
-
804
- switch (binding.type) {
805
- case "plain_text":
806
- {
807
- configObj.vars = {
808
- ...(configObj.vars ?? {}),
809
- [binding.name]: binding.text,
810
- };
811
- }
812
- break;
813
- case "json":
814
- {
815
- configObj.vars = {
816
- ...(configObj.vars ?? {}),
817
- name: binding.name,
818
- json: binding.json,
819
- };
820
- }
821
- break;
822
- case "kv_namespace":
823
- {
824
- configObj.kv_namespaces = [
825
- ...(configObj.kv_namespaces ?? []),
826
- { id: binding.namespace_id, binding: binding.name },
827
- ];
828
- }
829
- break;
830
- case "durable_object_namespace":
831
- {
832
- configObj.durable_objects = {
833
- bindings: [
834
- ...(configObj.durable_objects?.bindings ?? []),
835
- {
836
- name: binding.name,
837
- class_name: binding.class_name,
838
- script_name: binding.script_name,
839
- environment: binding.environment,
840
- },
841
- ],
842
- };
843
- }
844
- break;
845
- case "r2_bucket":
846
- {
847
- configObj.r2_buckets = [
848
- ...(configObj.r2_buckets ?? []),
849
- { binding: binding.name, bucket_name: binding.bucket_name },
850
- ];
851
- }
852
- break;
853
- case "service":
854
- {
855
- configObj.services = [
856
- ...(configObj.services ?? []),
857
- {
858
- binding: binding.name,
859
- service: binding.service,
860
- environment: binding.environment,
861
- },
862
- ];
863
- }
864
- break;
865
- case "namespace":
866
- {
867
- configObj.dispatch_namespaces = [
868
- ...(configObj.dispatch_namespaces ?? []),
869
- { binding: binding.name, namespace: binding.namespace },
870
- ];
871
- }
872
- break;
873
- case "logfwdr":
874
- {
875
- configObj.logfwdr = {
876
- // TODO: Messaging about adding schema file path
877
- schema: "",
878
- bindings: [
879
- ...(configObj.logfwdr?.bindings ?? []),
880
- { name: binding.name, destination: binding.destination },
881
- ],
882
- };
883
- }
884
- break;
885
- case "wasm_module":
886
- {
887
- configObj.wasm_modules = {
888
- ...(configObj.wasm_modules ?? {}),
889
- [binding.name]: binding.part,
890
- };
891
- }
892
- break;
893
- case "text_blob":
894
- {
895
- configObj.text_blobs = {
896
- ...(configObj.text_blobs ?? {}),
897
- [binding.name]: binding.part,
898
- };
899
- }
900
- break;
901
- case "data_blob":
902
- {
903
- configObj.data_blobs = {
904
- ...(configObj.data_blobs ?? {}),
905
- [binding.name]: binding.part,
906
- };
907
- }
908
- break;
909
- default: {
910
- // If we don't know what the type is, its an unsafe binding
911
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
912
- if (!(binding as any)?.type) break;
913
- configObj.unsafe = {
914
- bindings: [...(configObj.unsafe?.bindings ?? []), binding],
915
- };
916
- }
917
- }
918
-
919
- return configObj;
920
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
921
- }, {} as RawConfig);
922
-
923
- const durableObjectClassNames = bindings
924
- .filter((binding) => binding.type === "durable_object_namespace")
925
- .map(
926
- (durableObject) => (durableObject as { class_name: string }).class_name
927
- );
928
-
929
- const routeOrRoutes = routes.map((rawRoute) => {
930
- const { id: _id, ...route } = rawRoute;
931
- if (Object.keys(route).length === 1) {
932
- return route.pattern;
933
- } else {
934
- return route as Route;
935
- }
936
- });
937
- const routeOrRoutesToConfig =
938
- routeOrRoutes.length > 1
939
- ? { routes: routeOrRoutes }
940
- : { route: routeOrRoutes[0] };
941
-
942
- return {
943
- compatibility_date:
944
- serviceEnvMetadata.script.compatibility_date ??
945
- new Date().toISOString().substring(0, 10),
946
- ...routeOrRoutesToConfig,
947
- usage_model: serviceEnvMetadata.script.usage_model,
948
- ...(durableObjectClassNames.length
949
- ? {
950
- migrations: [
951
- {
952
- tag: serviceEnvMetadata.script.migration_tag,
953
- new_classes: durableObjectClassNames,
954
- },
955
- ],
956
- }
957
- : {}),
958
- triggers: {
959
- crons: cronTriggers.schedules.map((scheduled) => scheduled.cron),
960
- },
961
- env: environments
962
- .filter((env) => env.environment !== "production")
963
- // `env` can have multiple Environments, with different configs.
964
- .reduce((envObj, { environment }) => {
965
- return { ...envObj, [environment]: {} };
966
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
967
- }, {} as RawConfig["env"]),
968
- ...mappedBindings,
969
- };
970
- }