wrangler 0.0.0-e6e1daba → 0.0.0-e72a5794

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 (299) hide show
  1. package/README.md +10 -12
  2. package/bin/wrangler.js +10 -76
  3. package/package.json +19 -18
  4. package/templates/__tests__/tsconfig.json +1 -1
  5. package/templates/checked-fetch.js +10 -3
  6. package/templates/facade.d.ts +4 -1
  7. package/templates/gitignore +1 -0
  8. package/templates/middleware/common.ts +9 -4
  9. package/templates/middleware/loader-modules.ts +64 -11
  10. package/templates/middleware/loader-sw.ts +2 -7
  11. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  12. package/templates/{d1-beta-facade.js → middleware/middleware-d1-beta.ts} +87 -84
  13. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  14. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  15. package/templates/middleware/middleware-multiworker-dev.ts +59 -0
  16. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  17. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  18. package/templates/new-worker-scheduled.ts +1 -1
  19. package/templates/new-worker.ts +1 -1
  20. package/templates/pages-dev-util.ts +4 -1
  21. package/templates/pages-shim.ts +0 -3
  22. package/templates/pages-template-plugin.ts +12 -2
  23. package/templates/pages-template-worker.ts +11 -2
  24. package/templates/tsconfig.init.json +1 -2
  25. package/templates/tsconfig.json +1 -1
  26. package/wrangler-dist/cli.d.ts +192 -87
  27. package/wrangler-dist/cli.js +76158 -78596
  28. package/import_meta_url.js +0 -3
  29. package/miniflare-config-stubs/.env.empty +0 -0
  30. package/miniflare-config-stubs/package.empty.json +0 -1
  31. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  32. package/miniflare-dist/index.mjs +0 -6368
  33. package/src/__tests__/access.test.ts +0 -25
  34. package/src/__tests__/api-dev.test.ts +0 -238
  35. package/src/__tests__/api-devregistry.test.js +0 -64
  36. package/src/__tests__/api.test.ts +0 -80
  37. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  38. package/src/__tests__/config-cache.test.ts +0 -42
  39. package/src/__tests__/configuration.test.ts +0 -4233
  40. package/src/__tests__/d1/d1.test.ts +0 -82
  41. package/src/__tests__/d1/execute.test.ts +0 -64
  42. package/src/__tests__/d1/migrate.test.ts +0 -155
  43. package/src/__tests__/d1/splitter.test.ts +0 -255
  44. package/src/__tests__/delete.test.ts +0 -266
  45. package/src/__tests__/deployments.test.ts +0 -129
  46. package/src/__tests__/dev.test.tsx +0 -1587
  47. package/src/__tests__/generate.test.ts +0 -238
  48. package/src/__tests__/get-host-from-url.test.ts +0 -16
  49. package/src/__tests__/guess-worker-format.test.ts +0 -120
  50. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  51. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  52. package/src/__tests__/helpers/end-event-loop.ts +0 -6
  53. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  54. package/src/__tests__/helpers/mock-auth-domain.ts +0 -20
  55. package/src/__tests__/helpers/mock-bin.ts +0 -36
  56. package/src/__tests__/helpers/mock-console.ts +0 -106
  57. package/src/__tests__/helpers/mock-dialogs.ts +0 -139
  58. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +0 -25
  59. package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -11
  60. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  61. package/src/__tests__/helpers/mock-istty.ts +0 -74
  62. package/src/__tests__/helpers/mock-known-routes.ts +0 -12
  63. package/src/__tests__/helpers/mock-kv.ts +0 -46
  64. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -263
  65. package/src/__tests__/helpers/mock-process.ts +0 -34
  66. package/src/__tests__/helpers/mock-set-timeout.ts +0 -16
  67. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  68. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  69. package/src/__tests__/helpers/msw/blob-worker.cjs +0 -19
  70. package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
  71. package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -93
  72. package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -81
  73. package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -31
  74. package/src/__tests__/helpers/msw/handlers/r2.ts +0 -60
  75. package/src/__tests__/helpers/msw/handlers/script.ts +0 -56
  76. package/src/__tests__/helpers/msw/handlers/user.ts +0 -52
  77. package/src/__tests__/helpers/msw/handlers/zones.ts +0 -20
  78. package/src/__tests__/helpers/msw/index.ts +0 -50
  79. package/src/__tests__/helpers/msw/read-file-sync.js +0 -61
  80. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  81. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  82. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +0 -28
  83. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
  84. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
  85. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
  86. package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
  87. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
  88. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  89. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  90. package/src/__tests__/https-options.test.ts +0 -163
  91. package/src/__tests__/index.test.ts +0 -274
  92. package/src/__tests__/init.test.ts +0 -3164
  93. package/src/__tests__/jest.setup.ts +0 -175
  94. package/src/__tests__/kv.test.ts +0 -1799
  95. package/src/__tests__/logger.test.ts +0 -141
  96. package/src/__tests__/logout.test.ts +0 -47
  97. package/src/__tests__/metrics.test.ts +0 -493
  98. package/src/__tests__/middleware.scheduled.test.ts +0 -145
  99. package/src/__tests__/middleware.test.ts +0 -815
  100. package/src/__tests__/mtls-certificates.test.ts +0 -585
  101. package/src/__tests__/package-manager.test.ts +0 -353
  102. package/src/__tests__/pages/deployment-list.test.ts +0 -78
  103. package/src/__tests__/pages/functions-build.test.ts +0 -402
  104. package/src/__tests__/pages/pages.test.ts +0 -81
  105. package/src/__tests__/pages/project-create.test.ts +0 -63
  106. package/src/__tests__/pages/project-list.test.ts +0 -108
  107. package/src/__tests__/pages/project-upload.test.ts +0 -481
  108. package/src/__tests__/pages/publish.test.ts +0 -2745
  109. package/src/__tests__/pages-deployment-tail.test.ts +0 -955
  110. package/src/__tests__/parse.test.ts +0 -436
  111. package/src/__tests__/paths.test.ts +0 -39
  112. package/src/__tests__/publish.test.ts +0 -8167
  113. package/src/__tests__/pubsub.test.ts +0 -493
  114. package/src/__tests__/queues.test.ts +0 -529
  115. package/src/__tests__/r2.test.ts +0 -374
  116. package/src/__tests__/route.test.ts +0 -45
  117. package/src/__tests__/secret.test.ts +0 -693
  118. package/src/__tests__/tail.test.ts +0 -958
  119. package/src/__tests__/test-old-node-version.js +0 -31
  120. package/src/__tests__/tsconfig-sanity.ts +0 -12
  121. package/src/__tests__/tsconfig.json +0 -8
  122. package/src/__tests__/tsconfig.tsbuildinfo +0 -1
  123. package/src/__tests__/type-generation.test.ts +0 -233
  124. package/src/__tests__/user.test.ts +0 -118
  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 -172
  129. package/src/__tests__/worker-namespace.test.ts +0 -339
  130. package/src/abort.d.ts +0 -3
  131. package/src/api/dev.ts +0 -328
  132. package/src/api/index.ts +0 -11
  133. package/src/api/mtls-certificate.ts +0 -148
  134. package/src/api/pages/create-worker-bundle-contents.ts +0 -75
  135. package/src/api/pages/index.ts +0 -5
  136. package/src/api/pages/publish.tsx +0 -368
  137. package/src/bundle-reporter.ts +0 -68
  138. package/src/bundle.ts +0 -877
  139. package/src/cfetch/index.ts +0 -158
  140. package/src/cfetch/internal.ts +0 -258
  141. package/src/cli.ts +0 -28
  142. package/src/config/README.md +0 -107
  143. package/src/config/config.ts +0 -282
  144. package/src/config/diagnostics.ts +0 -80
  145. package/src/config/environment.ts +0 -586
  146. package/src/config/index.ts +0 -375
  147. package/src/config/validation-helpers.ts +0 -597
  148. package/src/config/validation.ts +0 -2198
  149. package/src/config-cache.ts +0 -85
  150. package/src/create-worker-preview.ts +0 -293
  151. package/src/create-worker-upload-form.ts +0 -334
  152. package/src/d1/backups.tsx +0 -215
  153. package/src/d1/constants.ts +0 -2
  154. package/src/d1/create.tsx +0 -64
  155. package/src/d1/delete.ts +0 -53
  156. package/src/d1/execute.tsx +0 -354
  157. package/src/d1/formatTimeAgo.ts +0 -14
  158. package/src/d1/index.ts +0 -100
  159. package/src/d1/list.tsx +0 -60
  160. package/src/d1/migrations/apply.tsx +0 -206
  161. package/src/d1/migrations/create.tsx +0 -76
  162. package/src/d1/migrations/helpers.ts +0 -172
  163. package/src/d1/migrations/index.ts +0 -3
  164. package/src/d1/migrations/list.tsx +0 -92
  165. package/src/d1/migrations/options.ts +0 -23
  166. package/src/d1/options.ts +0 -22
  167. package/src/d1/splitter.ts +0 -161
  168. package/src/d1/types.ts +0 -25
  169. package/src/d1/utils.ts +0 -49
  170. package/src/delete.ts +0 -100
  171. package/src/deployments.ts +0 -116
  172. package/src/deprecated/index.ts +0 -144
  173. package/src/dev/dev-vars.ts +0 -39
  174. package/src/dev/dev.tsx +0 -600
  175. package/src/dev/get-local-persistence-path.ts +0 -31
  176. package/src/dev/local.tsx +0 -922
  177. package/src/dev/remote.tsx +0 -632
  178. package/src/dev/start-server.ts +0 -538
  179. package/src/dev/use-esbuild.ts +0 -205
  180. package/src/dev/validate-dev-props.ts +0 -31
  181. package/src/dev-registry.ts +0 -201
  182. package/src/dev.tsx +0 -914
  183. package/src/dialogs.ts +0 -136
  184. package/src/dispatch-namespace.ts +0 -211
  185. package/src/docs/index.ts +0 -97
  186. package/src/durable.ts +0 -102
  187. package/src/entry.ts +0 -327
  188. package/src/environment-variables/factory.ts +0 -88
  189. package/src/environment-variables/misc-variables.ts +0 -30
  190. package/src/errors.ts +0 -11
  191. package/src/generate/index.ts +0 -298
  192. package/src/git-client.ts +0 -135
  193. package/src/global-wrangler-config-path.ts +0 -26
  194. package/src/https-options.ts +0 -127
  195. package/src/index.ts +0 -705
  196. package/src/init.ts +0 -1022
  197. package/src/inspect.ts +0 -782
  198. package/src/intl-polyfill.d.ts +0 -139
  199. package/src/is-ci.ts +0 -14
  200. package/src/is-interactive.ts +0 -16
  201. package/src/jest.d.ts +0 -4
  202. package/src/kv/helpers.ts +0 -430
  203. package/src/kv/index.ts +0 -594
  204. package/src/logger.ts +0 -104
  205. package/src/metrics/index.ts +0 -5
  206. package/src/metrics/metrics-config.ts +0 -239
  207. package/src/metrics/metrics-dispatcher.ts +0 -96
  208. package/src/metrics/metrics-usage-headers.ts +0 -24
  209. package/src/metrics/send-event.ts +0 -98
  210. package/src/miniflare-cli/README.md +0 -30
  211. package/src/miniflare-cli/assets.ts +0 -251
  212. package/src/miniflare-cli/index.ts +0 -210
  213. package/src/miniflare-cli/request-context.ts +0 -40
  214. package/src/miniflare-cli/tsconfig.json +0 -9
  215. package/src/miniflare-cli/tsconfig.tsbuildinfo +0 -1
  216. package/src/miniflare-cli/types.ts +0 -11
  217. package/src/module-collection.ts +0 -267
  218. package/src/mtls-certificate/cli.ts +0 -155
  219. package/src/open-in-browser.ts +0 -17
  220. package/src/package-manager.ts +0 -219
  221. package/src/pages/build.ts +0 -232
  222. package/src/pages/buildFunctions.ts +0 -130
  223. package/src/pages/constants.ts +0 -18
  224. package/src/pages/deployment-tails.ts +0 -281
  225. package/src/pages/deployments.tsx +0 -86
  226. package/src/pages/dev.ts +0 -716
  227. package/src/pages/errors.ts +0 -66
  228. package/src/pages/functions/buildPlugin.ts +0 -90
  229. package/src/pages/functions/buildWorker.ts +0 -288
  230. package/src/pages/functions/filepath-routing.test.ts +0 -234
  231. package/src/pages/functions/filepath-routing.ts +0 -189
  232. package/src/pages/functions/identifiers.ts +0 -78
  233. package/src/pages/functions/routes-consolidation.test.ts +0 -250
  234. package/src/pages/functions/routes-consolidation.ts +0 -73
  235. package/src/pages/functions/routes-transformation.test.ts +0 -282
  236. package/src/pages/functions/routes-transformation.ts +0 -115
  237. package/src/pages/functions/routes-validation.test.ts +0 -403
  238. package/src/pages/functions/routes-validation.ts +0 -202
  239. package/src/pages/functions/routes.ts +0 -151
  240. package/src/pages/functions/tsconfig.json +0 -8
  241. package/src/pages/functions/tsconfig.tsbuildinfo +0 -1
  242. package/src/pages/functions.ts +0 -86
  243. package/src/pages/hash.ts +0 -13
  244. package/src/pages/index.ts +0 -102
  245. package/src/pages/projects.tsx +0 -162
  246. package/src/pages/prompt-select-project.tsx +0 -31
  247. package/src/pages/publish.tsx +0 -276
  248. package/src/pages/types.ts +0 -46
  249. package/src/pages/upload.tsx +0 -449
  250. package/src/pages/utils.ts +0 -23
  251. package/src/parse.ts +0 -308
  252. package/src/paths.ts +0 -71
  253. package/src/proxy.ts +0 -694
  254. package/src/publish/index.ts +0 -274
  255. package/src/publish/publish.ts +0 -1065
  256. package/src/pubsub/index.ts +0 -286
  257. package/src/pubsub/pubsub-commands.ts +0 -623
  258. package/src/queues/cli/commands/consumer/add.ts +0 -65
  259. package/src/queues/cli/commands/consumer/index.ts +0 -19
  260. package/src/queues/cli/commands/consumer/remove.ts +0 -31
  261. package/src/queues/cli/commands/create.ts +0 -25
  262. package/src/queues/cli/commands/delete.ts +0 -26
  263. package/src/queues/cli/commands/index.ts +0 -35
  264. package/src/queues/cli/commands/list.ts +0 -25
  265. package/src/queues/client.ts +0 -135
  266. package/src/queues/utils.ts +0 -18
  267. package/src/r2/constants.ts +0 -4
  268. package/src/r2/helpers.ts +0 -132
  269. package/src/r2/index.ts +0 -289
  270. package/src/routes.ts +0 -140
  271. package/src/secret/index.ts +0 -375
  272. package/src/selfsigned.d.ts +0 -29
  273. package/src/sites.ts +0 -372
  274. package/src/tail/createTail.ts +0 -406
  275. package/src/tail/filters.ts +0 -277
  276. package/src/tail/index.ts +0 -211
  277. package/src/tail/printing.ts +0 -122
  278. package/src/tsconfig-sanity.ts +0 -16
  279. package/src/type-generation.ts +0 -181
  280. package/src/update-check.ts +0 -19
  281. package/src/user/access.ts +0 -68
  282. package/src/user/auth-variables.ts +0 -113
  283. package/src/user/choose-account.tsx +0 -39
  284. package/src/user/generate-auth-url.ts +0 -33
  285. package/src/user/generate-random-state.ts +0 -16
  286. package/src/user/index.ts +0 -2
  287. package/src/user/user.ts +0 -1233
  288. package/src/utils/collectKeyValues.ts +0 -14
  289. package/src/whoami.ts +0 -135
  290. package/src/worker.ts +0 -257
  291. package/src/yargs-types.ts +0 -37
  292. package/src/zones.ts +0 -191
  293. package/templates/__tests__/tsconfig.tsbuildinfo +0 -1
  294. package/templates/first-party-worker-module-facade.ts +0 -19
  295. package/templates/format-dev-errors.ts +0 -34
  296. package/templates/serve-static-assets.ts +0 -66
  297. package/templates/service-bindings-module-facade.js +0 -55
  298. package/templates/service-bindings-sw-facade.js +0 -42
  299. package/templates/tsconfig.tsbuildinfo +0 -1
package/src/bundle.ts DELETED
@@ -1,877 +0,0 @@
1
- import assert from "node:assert";
2
- import * as fs from "node:fs";
3
- import { builtinModules } from "node:module";
4
- import * as path from "node:path";
5
- import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
6
- import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
7
- import * as esbuild from "esbuild";
8
- import tmp from "tmp-promise";
9
- import createModuleCollector from "./module-collection";
10
- import { getBasePath, toUrlPath } from "./paths";
11
- import type { Config } from "./config";
12
- import type { DurableObjectBindings } from "./config/environment";
13
- import type { WorkerRegistry } from "./dev-registry";
14
- import type { Entry } from "./entry";
15
- import type { CfModule } from "./worker";
16
- export type BundleResult = {
17
- modules: CfModule[];
18
- dependencies: esbuild.Metafile["outputs"][string]["inputs"];
19
- resolvedEntryPointPath: string;
20
- bundleType: "esm" | "commonjs";
21
- stop: (() => void) | undefined;
22
- sourceMapPath?: string | undefined;
23
- };
24
-
25
- type StaticAssetsConfig =
26
- | (Config["assets"] & {
27
- bypassCache: boolean | undefined;
28
- })
29
- | undefined;
30
-
31
- /**
32
- * When applying the middleware facade for service workers, we need to inject
33
- * some code at the top of the final output bundle. Applying an inject too early
34
- * will allow esbuild to reorder the code. Additionally, we need to make sure
35
- * user code is bundled in the final esbuild step with `watch` correctly
36
- * configured, so code changes are detected.
37
- *
38
- * This type is used as the return type for the `MiddlewareFn` type representing
39
- * a facade-applying function. Returned injects should be injected with the
40
- * final esbuild step.
41
- */
42
- type EntryWithInject = Entry & { inject?: string[] };
43
-
44
- /**
45
- * RegExp matching against esbuild's error text when it is unable to resolve
46
- * a Node built-in module. If we detect this when node_compat is disabled,
47
- * we'll rewrite the error to suggest enabling it.
48
- */
49
- const nodeBuiltinResolveErrorText = new RegExp(
50
- '^Could not resolve "(' +
51
- builtinModules.join("|") +
52
- "|" +
53
- builtinModules.map((module) => "node:" + module).join("|") +
54
- ')"$'
55
- );
56
-
57
- /**
58
- * Returns true if the passed value looks like an esbuild BuildFailure object
59
- */
60
- export function isBuildFailure(err: unknown): err is esbuild.BuildFailure {
61
- return (
62
- typeof err === "object" &&
63
- err !== null &&
64
- "errors" in err &&
65
- "warnings" in err
66
- );
67
- }
68
-
69
- /**
70
- * Rewrites esbuild BuildFailures for failing to resolve Node built-in modules
71
- * to suggest enabling Node compat as opposed to `platform: "node"`.
72
- */
73
- export function rewriteNodeCompatBuildFailure(err: esbuild.BuildFailure) {
74
- for (const error of err.errors) {
75
- const match = nodeBuiltinResolveErrorText.exec(error.text);
76
- if (match !== null) {
77
- error.notes = [
78
- {
79
- location: null,
80
- text: `The package "${match[1]}" wasn't found on the file system but is built into node.
81
- Add "node_compat = true" to your wrangler.toml file to enable Node compatibility.`,
82
- },
83
- ];
84
- }
85
- }
86
- }
87
-
88
- /**
89
- * Generate a bundle for the worker identified by the arguments passed in.
90
- */
91
- export async function bundleWorker(
92
- entry: Entry,
93
- destination: string,
94
- options: {
95
- serveAssetsFromWorker: boolean;
96
- assets?: StaticAssetsConfig;
97
- betaD1Shims?: string[];
98
- doBindings: DurableObjectBindings;
99
- jsxFactory?: string;
100
- jsxFragment?: string;
101
- rules: Config["rules"];
102
- watch?: esbuild.WatchMode | boolean;
103
- tsconfig?: string;
104
- minify?: boolean;
105
- nodeCompat?: boolean;
106
- define: Config["define"];
107
- checkFetch: boolean;
108
- services?: Config["services"];
109
- workerDefinitions?: WorkerRegistry;
110
- firstPartyWorkerDevFacade?: boolean;
111
- targetConsumer: "dev" | "publish";
112
- local: boolean;
113
- testScheduled?: boolean;
114
- experimentalLocal?: boolean;
115
- inject?: string[];
116
- loader?: Record<string, string>;
117
- sourcemap?: esbuild.CommonOptions["sourcemap"];
118
- plugins?: esbuild.Plugin[];
119
- // TODO: Rip these out https://github.com/cloudflare/workers-sdk/issues/2153
120
- disableModuleCollection?: boolean;
121
- isOutfile?: boolean;
122
- }
123
- ): Promise<BundleResult> {
124
- const {
125
- serveAssetsFromWorker,
126
- betaD1Shims,
127
- doBindings,
128
- jsxFactory,
129
- jsxFragment,
130
- rules,
131
- watch,
132
- tsconfig,
133
- minify,
134
- nodeCompat,
135
- checkFetch,
136
- local,
137
- assets,
138
- workerDefinitions,
139
- services,
140
- firstPartyWorkerDevFacade,
141
- targetConsumer,
142
- testScheduled,
143
- experimentalLocal,
144
- inject: injectOption,
145
- loader,
146
- sourcemap,
147
- plugins,
148
- disableModuleCollection,
149
- isOutfile,
150
- } = options;
151
-
152
- // We create a temporary directory for any oneoff files we
153
- // need to create. This is separate from the main build
154
- // directory (`destination`).
155
- const tmpDir = await tmp.dir({ unsafeCleanup: true });
156
-
157
- const entryDirectory = path.dirname(entry.file);
158
- let moduleCollector = createModuleCollector({
159
- wrangler1xlegacyModuleReferences: {
160
- rootDirectory: entryDirectory,
161
- fileNames: new Set(
162
- fs
163
- .readdirSync(entryDirectory, { withFileTypes: true })
164
- .filter(
165
- (dirEntry) =>
166
- dirEntry.isFile() && dirEntry.name !== path.basename(entry.file)
167
- )
168
- .map((dirEnt) => dirEnt.name)
169
- ),
170
- },
171
- format: entry.format,
172
- rules,
173
- });
174
- if (disableModuleCollection) {
175
- moduleCollector = {
176
- modules: [],
177
- plugin: {
178
- name: moduleCollector.plugin.name,
179
- setup: () => {},
180
- },
181
- };
182
- }
183
-
184
- // In dev, we want to patch `fetch()` with a special version that looks
185
- // for bad usages and can warn the user about them; so we inject
186
- // `checked-fetch.js` to do so. However, with yarn 3 style pnp,
187
- // we need to extract that file to an accessible place before injecting
188
- // it in, hence this code here.
189
-
190
- const checkedFetchFileToInject = path.join(tmpDir.path, "checked-fetch.js");
191
-
192
- if (checkFetch && !fs.existsSync(checkedFetchFileToInject)) {
193
- fs.mkdirSync(tmpDir.path, {
194
- recursive: true,
195
- });
196
- fs.writeFileSync(
197
- checkedFetchFileToInject,
198
- fs.readFileSync(path.resolve(getBasePath(), "templates/checked-fetch.js"))
199
- );
200
- }
201
-
202
- // At this point, we take the opportunity to "wrap" any input workers
203
- // with any extra functionality we may want to add. This is done by
204
- // passing the entry point through a pipeline of functions that return
205
- // a new entry point, that we call "middleware" or "facades".
206
- // Look at implementations of these functions to learn more.
207
-
208
- // We also have middleware that uses a more "traditional" middleware stack,
209
- // which is all loaded as one in a stack.
210
- const middlewareToLoad: MiddlewareLoader[] = [];
211
-
212
- if (testScheduled) {
213
- middlewareToLoad.push({
214
- path: "templates/middleware/middleware-scheduled.ts",
215
- });
216
- }
217
- if (experimentalLocal) {
218
- // In Miniflare 3, we bind the user's worker as a service binding in a
219
- // special entry worker that handles things like injecting `Request.cf`,
220
- // live-reload, and the pretty-error page.
221
- //
222
- // Unfortunately, due to a bug in `workerd`, errors thrown asynchronously by
223
- // native APIs don't have `stack`s. This means Miniflare can't extract the
224
- // `stack` trace from dispatching to the user worker service binding by
225
- // `try/catch`.
226
- //
227
- // As a stop-gap solution, if the `MF-Experimental-Error-Stack` header is
228
- // truthy on responses, the body will be interpreted as a JSON-error of the
229
- // form `{ message?: string, name?: string, stack?: string }`.
230
- //
231
- // This middleware wraps the user's worker in a `try/catch`, and rewrites
232
- // errors in this format so a pretty-error page can be shown.
233
- middlewareToLoad.push({
234
- path: "templates/middleware/middleware-miniflare3-json-error.ts",
235
- dev: true,
236
- });
237
- }
238
-
239
- type MiddlewareFn = (currentEntry: Entry) => Promise<EntryWithInject>;
240
- const middleware: (false | undefined | MiddlewareFn)[] = [
241
- // serve static assets
242
- serveAssetsFromWorker &&
243
- ((currentEntry: Entry) => {
244
- return applyStaticAssetFacade(currentEntry, tmpDir.path, assets);
245
- }),
246
- // format errors nicely
247
- // We use an env var here because we don't actually
248
- // want to expose this to the user. It's only used internally to
249
- // experiment with middleware as a teaching exercise.
250
- process.env.FORMAT_WRANGLER_ERRORS === "true" &&
251
- ((currentEntry: Entry) => {
252
- return applyFormatDevErrorsFacade(currentEntry, tmpDir.path);
253
- }),
254
- // bind to other dev instances/service bindings
255
- workerDefinitions &&
256
- Object.keys(workerDefinitions).length > 0 &&
257
- services &&
258
- services.length > 0 &&
259
- ((currentEntry: Entry) => {
260
- return applyMultiWorkerDevFacade(
261
- currentEntry,
262
- tmpDir.path,
263
- services,
264
- workerDefinitions
265
- );
266
- }),
267
- // Simulate internal environment when using first party workers in dev
268
- firstPartyWorkerDevFacade === true &&
269
- ((currentEntry: Entry) => {
270
- return applyFirstPartyWorkerDevFacade(currentEntry, tmpDir.path);
271
- }),
272
-
273
- Array.isArray(betaD1Shims) &&
274
- betaD1Shims.length > 0 &&
275
- ((currentEntry: Entry) => {
276
- return applyD1BetaFacade(
277
- currentEntry,
278
- tmpDir.path,
279
- betaD1Shims,
280
- local,
281
- doBindings
282
- );
283
- }),
284
-
285
- // Middleware loader: to add middleware, we add the path to the middleware
286
- // Currently for demonstration purposes we have two example middlewares
287
- // Middlewares are togglable by changing the `publish` (default=false) and `dev` (default=true) options
288
- // As we are not yet supporting user created middlewares yet, if no wrangler applied middleware
289
- // are found, we will not load any middleware. We also need to check if there are middlewares compatible with
290
- // the target consumer (dev / publish).
291
- (middlewareToLoad.filter(
292
- (m) =>
293
- (m.publish && targetConsumer === "publish") ||
294
- (m.dev !== false && targetConsumer === "dev")
295
- ).length > 0 ||
296
- process.env.EXPERIMENTAL_MIDDLEWARE === "true") &&
297
- ((currentEntry: Entry) => {
298
- return applyMiddlewareLoaderFacade(
299
- currentEntry,
300
- tmpDir.path,
301
- middlewareToLoad.filter(
302
- // We dynamically filter the middleware depending on where we are bundling for
303
- (m) =>
304
- (targetConsumer === "dev" && m.dev !== false) ||
305
- (m.publish && targetConsumer === "publish")
306
- )
307
- );
308
- }),
309
- ].filter(Boolean);
310
-
311
- const inject: string[] = injectOption ?? [];
312
- if (checkFetch) inject.push(checkedFetchFileToInject);
313
-
314
- let inputEntry: EntryWithInject = entry;
315
- for (const middlewareFn of middleware as MiddlewareFn[]) {
316
- inputEntry = await middlewareFn(inputEntry);
317
- if (inputEntry.inject !== undefined) inject.push(...inputEntry.inject);
318
- }
319
-
320
- // At this point, inputEntry points to the entry point we want to build.
321
-
322
- const buildOptions: esbuild.BuildOptions & { metafile: true } = {
323
- entryPoints: [inputEntry.file],
324
- bundle: true,
325
- absWorkingDir: entry.directory,
326
- outdir: destination,
327
- ...(isOutfile
328
- ? {
329
- outdir: undefined,
330
- outfile: destination,
331
- }
332
- : {}),
333
- inject,
334
- external: ["__STATIC_CONTENT_MANIFEST"],
335
- format: entry.format === "modules" ? "esm" : "iife",
336
- // Our workerd runtime uses the same V8 version as recent Chrome, which is highly ES2022 compliant: https://kangax.github.io/compat-table/es2016plus/
337
- target: "es2022",
338
- sourcemap: sourcemap ?? true, // this needs to use ?? to accept false
339
- // Include a reference to the output folder in the sourcemap.
340
- // This is omitted by default, but we need it to properly resolve source paths in error output.
341
- sourceRoot: destination,
342
- minify,
343
- metafile: true,
344
- conditions: ["workerd", "worker", "browser"],
345
- ...(process.env.NODE_ENV && {
346
- define: {
347
- // use process.env["NODE_ENV" + ""] so that esbuild doesn't replace it
348
- // when we do a build of wrangler. (re: https://github.com/cloudflare/workers-sdk/issues/1477)
349
- "process.env.NODE_ENV": `"${process.env["NODE_ENV" + ""]}"`,
350
- ...(nodeCompat ? { global: "globalThis" } : {}),
351
- ...(checkFetch ? { fetch: "checkedFetch" } : {}),
352
- ...options.define,
353
- },
354
- }),
355
- loader: {
356
- ".js": "jsx",
357
- ".mjs": "jsx",
358
- ".cjs": "jsx",
359
- ...(loader || {}),
360
- },
361
- plugins: [
362
- moduleCollector.plugin,
363
- ...(nodeCompat
364
- ? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
365
- : []),
366
- ...(plugins || []),
367
- ],
368
- ...(jsxFactory && { jsxFactory }),
369
- ...(jsxFragment && { jsxFragment }),
370
- ...(tsconfig && { tsconfig }),
371
- watch,
372
- // The default logLevel is "warning". So that we can rewrite errors before
373
- // logging, we disable esbuild's default logging, and log build failures
374
- // ourselves.
375
- logLevel: "silent",
376
- };
377
- let result;
378
- try {
379
- result = await esbuild.build(buildOptions);
380
- } catch (e) {
381
- if (!nodeCompat && isBuildFailure(e)) rewriteNodeCompatBuildFailure(e);
382
- throw e;
383
- }
384
-
385
- const entryPointOutputs = Object.entries(result.metafile.outputs).filter(
386
- ([_path, output]) => output.entryPoint !== undefined
387
- );
388
- assert(
389
- entryPointOutputs.length > 0,
390
- `Cannot find entry-point "${entry.file}" in generated bundle.` +
391
- listEntryPoints(entryPointOutputs)
392
- );
393
- assert(
394
- entryPointOutputs.length < 2,
395
- "More than one entry-point found for generated bundle." +
396
- listEntryPoints(entryPointOutputs)
397
- );
398
-
399
- const { exports: entryPointExports, inputs: dependencies } =
400
- entryPointOutputs[0][1];
401
- const bundleType = entryPointExports.length > 0 ? "esm" : "commonjs";
402
-
403
- const sourceMapPath = Object.keys(result.metafile.outputs).filter((_path) =>
404
- _path.includes(".map")
405
- )[0];
406
-
407
- const resolvedEntryPointPath = path.resolve(
408
- entry.directory,
409
- entryPointOutputs[0][0]
410
- );
411
-
412
- // copy all referenced modules into the output bundle directory
413
- for (const module of moduleCollector.modules) {
414
- fs.writeFileSync(
415
- path.join(path.dirname(resolvedEntryPointPath), module.name),
416
- module.content
417
- );
418
- }
419
-
420
- return {
421
- modules: moduleCollector.modules,
422
- dependencies,
423
- resolvedEntryPointPath,
424
- bundleType,
425
- stop: result.stop,
426
- sourceMapPath,
427
- };
428
- }
429
-
430
- /**
431
- * A simple plugin to alias modules and mark them as external
432
- */
433
- export function esbuildAliasExternalPlugin(
434
- aliases: Record<string, string>
435
- ): esbuild.Plugin {
436
- return {
437
- name: "alias",
438
- setup(build) {
439
- build.onResolve({ filter: /.*/g }, (args) => {
440
- // If it's the entrypoint, let it be as is
441
- if (args.kind === "entry-point") {
442
- return {
443
- path: args.path,
444
- };
445
- }
446
- // If it's not a recognised alias, then throw an error
447
- if (!Object.keys(aliases).includes(args.path)) {
448
- throw new Error("unrecognized module: " + args.path);
449
- }
450
-
451
- // Otherwise, return the alias
452
- return {
453
- path: aliases[args.path as keyof typeof aliases],
454
- external: true,
455
- };
456
- });
457
- },
458
- };
459
- }
460
-
461
- /**
462
- * A middleware that catches any thrown errors, and instead formats
463
- * them to be rendered in a browser. This middleware is for demonstration
464
- * purposes only, and is not intended to be used in production (or even dev!)
465
- */
466
- async function applyFormatDevErrorsFacade(
467
- entry: Entry,
468
- tmpDirPath: string
469
- ): Promise<Entry> {
470
- const targetPath = path.join(tmpDirPath, "format-dev-errors.entry.js");
471
- await esbuild.build({
472
- entryPoints: [
473
- path.resolve(getBasePath(), "templates/format-dev-errors.ts"),
474
- ],
475
- bundle: true,
476
- sourcemap: true,
477
- format: "esm",
478
- plugins: [
479
- esbuildAliasExternalPlugin({
480
- __ENTRY_POINT__: entry.file,
481
- }),
482
- ],
483
- outfile: targetPath,
484
- });
485
-
486
- return {
487
- ...entry,
488
- file: targetPath,
489
- };
490
- }
491
-
492
- /**
493
- * A facade that acts as a "middleware loader".
494
- * Instead of needing to apply a facade for each individual middleware, this allows
495
- * middleware to be written in a more traditional manner and then be applied all
496
- * at once, requiring just two esbuild steps, rather than 1 per middleware.
497
- */
498
-
499
- interface MiddlewareLoader {
500
- path: string;
501
- // By default all middleware will run on dev, but will not be run when published
502
- publish?: boolean;
503
- dev?: boolean;
504
- }
505
-
506
- async function applyMiddlewareLoaderFacade(
507
- entry: Entry,
508
- tmpDirPath: string,
509
- middleware: MiddlewareLoader[] // a list of paths to middleware files
510
- ): Promise<EntryWithInject> {
511
- // Firstly we need to insert the middleware array into the project,
512
- // and then we load the middleware - this insertion and loading is
513
- // different for each format.
514
-
515
- // Make sure we resolve all files relative to the actual temporary directory,
516
- // otherwise we'll have issues with source maps
517
- tmpDirPath = fs.realpathSync(tmpDirPath);
518
-
519
- const targetPathInsertion = path.join(
520
- tmpDirPath,
521
- "middleware-insertion.entry.js"
522
- );
523
-
524
- // We need to import each of the middlewares, so we need to generate a
525
- // random, unique identifier that we can use for the import.
526
- // Middlewares are required to be default exports so we can import to any name.
527
- const middlewareIdentifiers = middleware.map(
528
- (_, index) => `__MIDDLEWARE_${index}__`
529
- );
530
-
531
- const dynamicFacadePath = path.join(
532
- tmpDirPath,
533
- "middleware-insertion-facade.js"
534
- );
535
-
536
- if (entry.format === "modules") {
537
- // We use a facade to expose the required middleware alongside any user defined
538
- // middleware on the worker object
539
-
540
- const imports = middlewareIdentifiers
541
- .map((m) => `import ${m} from "${m}";`)
542
- .join("\n");
543
-
544
- // write a file with all of the imports required
545
- fs.writeFileSync(
546
- dynamicFacadePath,
547
- `import worker from "__ENTRY_POINT__";
548
- ${imports}
549
- const facade = {
550
- ...worker,
551
- middleware: [
552
- ${middlewareIdentifiers.join(",")}${middlewareIdentifiers.length > 0 ? "," : ""}
553
- ...(worker.middleware ? worker.middleware : []),
554
- ]
555
- }
556
- export * from "__ENTRY_POINT__";
557
- export default facade;`
558
- );
559
-
560
- await esbuild.build({
561
- entryPoints: [dynamicFacadePath],
562
- bundle: true,
563
- sourcemap: true,
564
- format: "esm",
565
- plugins: [
566
- esbuildAliasExternalPlugin({
567
- __ENTRY_POINT__: entry.file,
568
- ...Object.fromEntries(
569
- middleware.map((val, index) => [
570
- middlewareIdentifiers[index],
571
- toUrlPath(path.resolve(getBasePath(), val.path)),
572
- ])
573
- ),
574
- }),
575
- ],
576
- outfile: targetPathInsertion,
577
- });
578
- const targetPathLoader = path.join(
579
- tmpDirPath,
580
- "middleware-loader.entry.js"
581
- );
582
- const loaderPath = path.resolve(
583
- getBasePath(),
584
- "templates/middleware/loader-modules.ts"
585
- );
586
- await esbuild.build({
587
- entryPoints: [loaderPath],
588
- bundle: true,
589
- sourcemap: true,
590
- format: "esm",
591
- plugins: [
592
- esbuildAliasExternalPlugin({
593
- __ENTRY_POINT__: targetPathInsertion,
594
- "./common": path.resolve(
595
- getBasePath(),
596
- "templates/middleware/common.ts"
597
- ),
598
- }),
599
- ],
600
- outfile: targetPathLoader,
601
- });
602
- return {
603
- ...entry,
604
- file: targetPathLoader,
605
- };
606
- } else {
607
- const imports = middlewareIdentifiers
608
- .map((m) => `import ${m} from "${m}";`)
609
- .join("\n");
610
- const contents = `import { __facade_registerInternal__ } from "__LOADER__";
611
- ${imports}
612
- __facade_registerInternal__([${middlewareIdentifiers.join(",")}]);`;
613
- fs.writeFileSync(dynamicFacadePath, contents);
614
-
615
- await esbuild.build({
616
- entryPoints: [dynamicFacadePath],
617
- bundle: true,
618
- sourcemap: true,
619
- format: "iife",
620
- plugins: [
621
- {
622
- name: "dynamic-facade-imports",
623
- setup(build) {
624
- build.onResolve({ filter: /^__LOADER__$/ }, () => {
625
- const loaderPath = path.resolve(
626
- getBasePath(),
627
- "templates/middleware/loader-sw.ts"
628
- );
629
- return { path: loaderPath };
630
- });
631
- const middlewareFilter = /^__MIDDLEWARE_(\d+)__$/;
632
- build.onResolve({ filter: middlewareFilter }, (args) => {
633
- const match = middlewareFilter.exec(args.path);
634
- assert(match !== null);
635
- const middlewareIndex = parseInt(match[1]);
636
- return {
637
- path: path.resolve(
638
- getBasePath(),
639
- middleware[middlewareIndex].path
640
- ),
641
- };
642
- });
643
- },
644
- },
645
- ],
646
- outfile: targetPathInsertion,
647
- });
648
- return {
649
- ...entry,
650
- inject: [targetPathInsertion],
651
- };
652
- }
653
- }
654
-
655
- /**
656
- * A middleware that serves static assets from a worker.
657
- * This powers --assets / config.assets
658
- */
659
-
660
- async function applyStaticAssetFacade(
661
- entry: Entry,
662
- tmpDirPath: string,
663
- assets: StaticAssetsConfig
664
- ): Promise<Entry> {
665
- const targetPath = path.join(tmpDirPath, "serve-static-assets.entry.js");
666
-
667
- await esbuild.build({
668
- entryPoints: [
669
- path.resolve(getBasePath(), "templates/serve-static-assets.ts"),
670
- ],
671
- bundle: true,
672
- format: "esm",
673
- sourcemap: true,
674
- plugins: [
675
- esbuildAliasExternalPlugin({
676
- __ENTRY_POINT__: entry.file,
677
- __KV_ASSET_HANDLER__: path.join(getBasePath(), "kv-asset-handler.js"),
678
- __STATIC_CONTENT_MANIFEST: "__STATIC_CONTENT_MANIFEST",
679
- }),
680
- ],
681
- define: {
682
- __CACHE_CONTROL_OPTIONS__: JSON.stringify(
683
- typeof assets === "object"
684
- ? {
685
- browserTTL:
686
- assets.browser_TTL || 172800 /* 2 days: 2* 60 * 60 * 24 */,
687
- bypassCache: assets.bypassCache,
688
- }
689
- : {}
690
- ),
691
- __SERVE_SINGLE_PAGE_APP__: JSON.stringify(
692
- typeof assets === "object" ? assets.serve_single_page_app : false
693
- ),
694
- },
695
- outfile: targetPath,
696
- });
697
-
698
- return {
699
- ...entry,
700
- file: targetPath,
701
- };
702
- }
703
-
704
- /**
705
- * A middleware that enables service bindings to be used in dev,
706
- * binding to other love wrangler dev instances
707
- */
708
-
709
- async function applyMultiWorkerDevFacade(
710
- entry: Entry,
711
- tmpDirPath: string,
712
- services: Config["services"],
713
- workerDefinitions: WorkerRegistry
714
- ) {
715
- const targetPath = path.join(tmpDirPath, "multiworker-dev-facade.entry.js");
716
- const serviceMap = Object.fromEntries(
717
- (services || []).map((serviceBinding) => [
718
- serviceBinding.binding,
719
- workerDefinitions[serviceBinding.service] || null,
720
- ])
721
- );
722
-
723
- await esbuild.build({
724
- entryPoints: [
725
- path.join(
726
- getBasePath(),
727
- entry.format === "modules"
728
- ? "templates/service-bindings-module-facade.js"
729
- : "templates/service-bindings-sw-facade.js"
730
- ),
731
- ],
732
- bundle: true,
733
- sourcemap: true,
734
- format: "esm",
735
- plugins: [
736
- esbuildAliasExternalPlugin({
737
- __ENTRY_POINT__: entry.file,
738
- }),
739
- ],
740
- define: {
741
- __WORKERS__: JSON.stringify(serviceMap),
742
- },
743
- outfile: targetPath,
744
- });
745
-
746
- return {
747
- ...entry,
748
- file: targetPath,
749
- };
750
- }
751
-
752
- /**
753
- * A middleware that makes first party workers "work" in
754
- * our dev environments. Is applied during wrangler dev
755
- * when config.first_party_worker is true
756
- */
757
- async function applyFirstPartyWorkerDevFacade(
758
- entry: Entry,
759
- tmpDirPath: string
760
- ) {
761
- if (entry.format !== "modules") {
762
- throw new Error(
763
- "First party workers must be in the modules format. See https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/"
764
- );
765
- }
766
-
767
- const targetPath = path.join(
768
- tmpDirPath,
769
- "first-party-worker-module-facade.entry.js"
770
- );
771
-
772
- await esbuild.build({
773
- entryPoints: [
774
- path.resolve(
775
- getBasePath(),
776
- "templates/first-party-worker-module-facade.ts"
777
- ),
778
- ],
779
- bundle: true,
780
- format: "esm",
781
- sourcemap: true,
782
- plugins: [
783
- esbuildAliasExternalPlugin({
784
- __ENTRY_POINT__: entry.file,
785
- }),
786
- ],
787
- outfile: targetPath,
788
- });
789
-
790
- return {
791
- ...entry,
792
- file: targetPath,
793
- };
794
- }
795
-
796
- /**
797
- * A middleware that injects the beta D1 API in JS.
798
- *
799
- * This code be removed from here when the API is in Workers core,
800
- * but moved inside Miniflare for simulating D1.
801
- */
802
- async function applyD1BetaFacade(
803
- entry: Entry,
804
- tmpDirPath: string,
805
- betaD1Shims: string[],
806
- local: boolean,
807
- doBindings: DurableObjectBindings
808
- ): Promise<Entry> {
809
- let entrypointPath = path.resolve(
810
- getBasePath(),
811
- "templates/d1-beta-facade.js"
812
- );
813
- if (Array.isArray(doBindings) && doBindings.length > 0) {
814
- //we have DO bindings, so we need to shim them
815
- const maskedDoBindings = doBindings
816
- // Don't shim anything not local to this worker
817
- .filter((b) => !b.script_name)
818
- // Reexport the DO classnames
819
- .map(
820
- (b) =>
821
- `export const ${b.class_name} = maskDurableObjectDefinition(OTHER_EXPORTS.${b.class_name});`
822
- )
823
- .join("\n");
824
- const baseFile = fs.readFileSync(
825
- path.resolve(getBasePath(), "templates/d1-beta-facade.js"),
826
- "utf8"
827
- );
828
- //getMaskedEnv is already used to shim regular Workers
829
- const contents = `
830
- ${baseFile}
831
-
832
- var maskDurableObjectDefinition = (cls) =>
833
- class extends cls {
834
- constructor(state, env) {
835
- super(state, getMaskedEnv(env));
836
- }
837
- };
838
- ${maskedDoBindings}`;
839
- const doD1FacadePath = path.join(tmpDirPath, "d1-do-facade.js");
840
- //write our shim so we can build it
841
- fs.writeFileSync(doD1FacadePath, contents);
842
- entrypointPath = doD1FacadePath;
843
- }
844
- const targetPath = path.join(tmpDirPath, "d1-beta-facade.entry.js");
845
- await esbuild.build({
846
- entryPoints: [entrypointPath],
847
- bundle: true,
848
- format: "esm",
849
- sourcemap: true,
850
- plugins: [
851
- esbuildAliasExternalPlugin({
852
- __ENTRY_POINT__: entry.file,
853
- }),
854
- ],
855
- define: {
856
- __D1_IMPORTS__: JSON.stringify(betaD1Shims),
857
- __LOCAL_MODE__: JSON.stringify(local),
858
- },
859
- outfile: targetPath,
860
- });
861
-
862
- return {
863
- ...entry,
864
- file: targetPath,
865
- };
866
- }
867
-
868
- /**
869
- * Generate a string that describes the entry-points that were identified by esbuild.
870
- */
871
- function listEntryPoints(
872
- outputs: [string, ValueOf<esbuild.Metafile["outputs"]>][]
873
- ): string {
874
- return outputs.map(([_input, output]) => output.entryPoint).join("\n");
875
- }
876
-
877
- type ValueOf<T> = T[keyof T];