wrangler 0.0.0-e2b7352 → 0.0.0-e305903a

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 (264) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +51 -14
  3. package/bin/wrangler.js +154 -31
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +6244 -21
  6. package/package.json +185 -141
  7. package/src/__tests__/api-dev.test.ts +209 -0
  8. package/src/__tests__/api-devregistry.test.js +56 -0
  9. package/src/__tests__/api.test.ts +80 -0
  10. package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
  11. package/src/__tests__/config-cache.test.ts +42 -0
  12. package/src/__tests__/configuration.test.ts +4122 -2810
  13. package/src/__tests__/dev.test.tsx +1341 -527
  14. package/src/__tests__/dialogs.test.tsx +40 -0
  15. package/src/__tests__/generate.test.ts +91 -0
  16. package/src/__tests__/guess-worker-format.test.ts +74 -57
  17. package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
  18. package/src/__tests__/helpers/mock-account-id.ts +24 -24
  19. package/src/__tests__/helpers/mock-bin.ts +20 -20
  20. package/src/__tests__/helpers/mock-cfetch.ts +202 -93
  21. package/src/__tests__/helpers/mock-console.ts +68 -32
  22. package/src/__tests__/helpers/mock-dialogs.ts +121 -33
  23. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  24. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  25. package/src/__tests__/helpers/mock-istty.ts +74 -0
  26. package/src/__tests__/helpers/mock-known-routes.ts +7 -0
  27. package/src/__tests__/helpers/mock-kv.ts +26 -26
  28. package/src/__tests__/helpers/mock-oauth-flow.ts +252 -0
  29. package/src/__tests__/helpers/mock-process.ts +39 -0
  30. package/src/__tests__/helpers/mock-stdin.ts +82 -77
  31. package/src/__tests__/helpers/mock-web-socket.ts +21 -21
  32. package/src/__tests__/helpers/msw/handlers/index.ts +13 -0
  33. package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
  34. package/src/__tests__/helpers/msw/handlers/oauth.ts +36 -0
  35. package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
  36. package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
  37. package/src/__tests__/helpers/msw/index.ts +4 -0
  38. package/src/__tests__/helpers/run-in-tmp.ts +28 -22
  39. package/src/__tests__/helpers/run-wrangler.ts +8 -8
  40. package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
  41. package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
  42. package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
  43. package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
  44. package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
  45. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  46. package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
  47. package/src/__tests__/https-options.test.ts +144 -108
  48. package/src/__tests__/index.test.ts +233 -967
  49. package/src/__tests__/init.test.ts +2717 -0
  50. package/src/__tests__/jest.setup.ts +151 -34
  51. package/src/__tests__/kv.test.ts +1376 -1085
  52. package/src/__tests__/logger.test.ts +141 -0
  53. package/src/__tests__/metrics.test.ts +450 -0
  54. package/src/__tests__/middleware.scheduled.test.ts +135 -0
  55. package/src/__tests__/middleware.test.ts +726 -0
  56. package/src/__tests__/package-manager.test.ts +312 -165
  57. package/src/__tests__/pages.test.ts +1990 -77
  58. package/src/__tests__/parse.test.ts +253 -245
  59. package/src/__tests__/paths.test.ts +39 -0
  60. package/src/__tests__/publish.test.ts +6989 -3411
  61. package/src/__tests__/pubsub.test.ts +367 -0
  62. package/src/__tests__/r2.test.ts +363 -190
  63. package/src/__tests__/route.test.ts +22 -22
  64. package/src/__tests__/secret.test.ts +626 -407
  65. package/src/__tests__/tail.test.ts +653 -516
  66. package/src/__tests__/test-old-node-version.js +31 -0
  67. package/src/__tests__/user.test.ts +155 -0
  68. package/src/__tests__/validate-dev-props.test.ts +56 -0
  69. package/src/__tests__/version.test.ts +35 -0
  70. package/src/__tests__/whoami.test.tsx +261 -88
  71. package/src/__tests__/worker-namespace.test.ts +319 -0
  72. package/src/abort.d.ts +3 -0
  73. package/src/api/dev.ts +206 -0
  74. package/src/api/index.ts +2 -0
  75. package/src/bundle-reporter.tsx +29 -0
  76. package/src/bundle.ts +723 -122
  77. package/src/cfetch/index.ts +83 -66
  78. package/src/cfetch/internal.ts +267 -92
  79. package/src/cli.ts +24 -14
  80. package/src/config/README.md +1 -1
  81. package/src/config/config.ts +236 -179
  82. package/src/config/diagnostics.ts +61 -61
  83. package/src/config/environment.ts +450 -316
  84. package/src/config/index.ts +259 -38
  85. package/src/config/validation-helpers.ts +385 -342
  86. package/src/config/validation.ts +1797 -1099
  87. package/src/config-cache.ts +85 -0
  88. package/src/create-worker-preview.ts +233 -124
  89. package/src/create-worker-upload-form.ts +285 -201
  90. package/src/d1/backups.tsx +212 -0
  91. package/src/d1/create.tsx +54 -0
  92. package/src/d1/delete.tsx +56 -0
  93. package/src/d1/execute.tsx +294 -0
  94. package/src/d1/formatTimeAgo.ts +14 -0
  95. package/src/d1/index.ts +75 -0
  96. package/src/d1/list.tsx +48 -0
  97. package/src/d1/options.ts +12 -0
  98. package/src/d1/types.tsx +14 -0
  99. package/src/d1/utils.ts +39 -0
  100. package/src/dev/dev-vars.ts +36 -0
  101. package/src/dev/dev.tsx +501 -328
  102. package/src/dev/get-local-persistence-path.tsx +31 -0
  103. package/src/dev/local.tsx +629 -211
  104. package/src/dev/remote.tsx +398 -188
  105. package/src/dev/start-server.ts +443 -0
  106. package/src/dev/use-esbuild.ts +175 -82
  107. package/src/dev/validate-dev-props.ts +31 -0
  108. package/src/dev-registry.tsx +190 -0
  109. package/src/dev.tsx +869 -0
  110. package/src/dialogs.tsx +138 -57
  111. package/src/dispatch-namespace.ts +206 -0
  112. package/src/durable.ts +102 -0
  113. package/src/entry.ts +260 -171
  114. package/src/environment-variables.ts +40 -23
  115. package/src/errors.ts +11 -0
  116. package/src/faye-websocket.d.ts +6 -0
  117. package/src/generate.ts +131 -0
  118. package/src/git-client.ts +42 -0
  119. package/src/global-wrangler-config-path.ts +26 -0
  120. package/src/https-options.ts +85 -80
  121. package/src/index.tsx +2295 -2315
  122. package/src/init.ts +967 -0
  123. package/src/inspect.ts +687 -557
  124. package/src/intl-polyfill.d.ts +123 -123
  125. package/src/is-ci.ts +14 -0
  126. package/src/is-interactive.ts +12 -0
  127. package/src/kv.ts +353 -242
  128. package/src/logger.ts +80 -0
  129. package/src/metrics/index.ts +5 -0
  130. package/src/metrics/metrics-config.ts +239 -0
  131. package/src/metrics/metrics-dispatcher.ts +96 -0
  132. package/src/metrics/metrics-usage-headers.ts +24 -0
  133. package/src/metrics/send-event.ts +93 -0
  134. package/src/miniflare-cli/assets.ts +215 -0
  135. package/src/miniflare-cli/index.ts +201 -30
  136. package/src/miniflare-cli/request-context.ts +40 -0
  137. package/src/module-collection.ts +213 -213
  138. package/src/open-in-browser.ts +8 -16
  139. package/src/package-manager.ts +183 -90
  140. package/src/pages/build.tsx +238 -0
  141. package/src/pages/constants.ts +16 -0
  142. package/src/pages/deployments.tsx +106 -0
  143. package/src/pages/dev.tsx +684 -0
  144. package/src/pages/errors.ts +66 -0
  145. package/src/pages/functions/buildPlugin.ts +110 -0
  146. package/src/pages/functions/buildWorker.ts +156 -0
  147. package/src/pages/functions/filepath-routing.test.ts +234 -0
  148. package/src/pages/functions/filepath-routing.ts +189 -0
  149. package/src/pages/functions/identifiers.ts +78 -0
  150. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  151. package/src/pages/functions/routes-consolidation.ts +73 -0
  152. package/src/pages/functions/routes-transformation.test.ts +282 -0
  153. package/src/pages/functions/routes-transformation.ts +115 -0
  154. package/src/pages/functions/routes-validation.test.ts +403 -0
  155. package/src/pages/functions/routes-validation.ts +202 -0
  156. package/src/pages/functions/routes.ts +151 -0
  157. package/src/pages/functions.tsx +82 -0
  158. package/src/pages/hash.tsx +13 -0
  159. package/src/pages/index.tsx +94 -0
  160. package/src/pages/projects.tsx +169 -0
  161. package/src/pages/publish.tsx +419 -0
  162. package/src/pages/types.ts +49 -0
  163. package/src/pages/upload.tsx +398 -0
  164. package/src/pages/utils.ts +12 -0
  165. package/src/parse.ts +224 -121
  166. package/src/paths.ts +53 -8
  167. package/src/preview.ts +31 -0
  168. package/src/proxy.ts +436 -370
  169. package/src/publish.ts +839 -324
  170. package/src/pubsub/index.ts +286 -0
  171. package/src/pubsub/pubsub-commands.tsx +623 -0
  172. package/src/r2.ts +100 -19
  173. package/src/selfsigned.d.ts +23 -23
  174. package/src/sites.tsx +281 -189
  175. package/src/tail/filters.ts +108 -110
  176. package/src/tail/index.ts +234 -218
  177. package/src/tail/printing.ts +92 -47
  178. package/src/update-check.ts +19 -0
  179. package/src/user/choose-account.tsx +69 -0
  180. package/src/user/env-vars.ts +46 -0
  181. package/src/user/generate-auth-url.ts +33 -0
  182. package/src/user/generate-random-state.ts +16 -0
  183. package/src/user/index.ts +3 -0
  184. package/src/user/user.tsx +1192 -0
  185. package/src/whoami.tsx +142 -42
  186. package/src/worker.ts +171 -100
  187. package/src/zones.ts +167 -0
  188. package/templates/checked-fetch.js +17 -0
  189. package/templates/d1-beta-facade.js +174 -0
  190. package/templates/experimental-local-cache-stubs.js +27 -0
  191. package/templates/first-party-worker-module-facade.ts +18 -0
  192. package/templates/format-dev-errors.ts +32 -0
  193. package/templates/gitignore +171 -0
  194. package/templates/init-tests/test-jest-new-worker.js +25 -0
  195. package/templates/init-tests/test-vitest-new-worker.js +26 -0
  196. package/templates/middleware/common.ts +62 -0
  197. package/templates/middleware/loader-modules.ts +84 -0
  198. package/templates/middleware/loader-sw.ts +213 -0
  199. package/templates/middleware/middleware-pretty-error.ts +40 -0
  200. package/templates/middleware/middleware-scheduled.ts +15 -0
  201. package/templates/new-worker-scheduled.js +17 -0
  202. package/templates/new-worker-scheduled.ts +32 -0
  203. package/templates/new-worker.js +3 -3
  204. package/templates/new-worker.ts +18 -3
  205. package/templates/no-op-worker.js +10 -0
  206. package/templates/pages-dev-pipeline.ts +35 -0
  207. package/templates/pages-shim.ts +9 -0
  208. package/templates/pages-template-plugin.ts +167 -0
  209. package/templates/pages-template-worker.ts +172 -0
  210. package/templates/serve-static-assets.ts +63 -0
  211. package/templates/service-bindings-module-facade.js +54 -0
  212. package/templates/service-bindings-sw-facade.js +42 -0
  213. package/templates/tsconfig.json +95 -95
  214. package/wrangler-dist/cli.d.ts +841 -0
  215. package/wrangler-dist/cli.js +129492 -108210
  216. package/miniflare-dist/index.mjs.map +0 -7
  217. package/pages/functions/buildWorker.ts +0 -62
  218. package/pages/functions/filepath-routing.test.ts +0 -223
  219. package/pages/functions/filepath-routing.ts +0 -181
  220. package/pages/functions/identifiers.ts +0 -78
  221. package/pages/functions/routes.ts +0 -151
  222. package/pages/functions/template-worker.ts +0 -130
  223. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  224. package/src/__tests__/logout.test.ts +0 -52
  225. package/src/__tests__/sentry.test.ts +0 -146
  226. package/src/miniflare-cli/enum-keys.ts +0 -17
  227. package/src/pages.tsx +0 -1061
  228. package/src/reporting.ts +0 -131
  229. package/src/user.tsx +0 -1127
  230. package/templates/static-asset-facade.js +0 -47
  231. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  232. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  233. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  234. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  235. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  236. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  237. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  238. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  239. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  240. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  241. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  242. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  243. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  244. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  245. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  246. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  247. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  248. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  249. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  250. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  251. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  252. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  253. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  254. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  255. package/vendor/wrangler-mime/LICENSE +0 -21
  256. package/vendor/wrangler-mime/Mime.js +0 -97
  257. package/vendor/wrangler-mime/README.md +0 -187
  258. package/vendor/wrangler-mime/cli.js +0 -46
  259. package/vendor/wrangler-mime/index.js +0 -4
  260. package/vendor/wrangler-mime/lite.js +0 -4
  261. package/vendor/wrangler-mime/package.json +0 -52
  262. package/vendor/wrangler-mime/types/other.js +0 -1
  263. package/vendor/wrangler-mime/types/standard.js +0 -1
  264. package/wrangler-dist/cli.js.map +0 -7
package/src/bundle.ts CHANGED
@@ -1,155 +1,756 @@
1
1
  import assert from "node:assert";
2
2
  import * as fs from "node:fs";
3
+ import { builtinModules } from "node:module";
3
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";
4
7
  import * as esbuild from "esbuild";
8
+ import tmp from "tmp-promise";
5
9
  import createModuleCollector from "./module-collection";
10
+ import { getBasePath, toUrlPath } from "./paths";
6
11
  import type { Config } from "./config";
12
+ import type { WorkerRegistry } from "./dev-registry";
7
13
  import type { Entry } from "./entry";
8
14
  import type { CfModule } from "./worker";
9
15
 
10
16
  type BundleResult = {
11
- modules: CfModule[];
12
- resolvedEntryPointPath: string;
13
- bundleType: "esm" | "commonjs";
14
- stop: (() => void) | undefined;
17
+ modules: CfModule[];
18
+ resolvedEntryPointPath: string;
19
+ bundleType: "esm" | "commonjs";
20
+ stop: (() => void) | undefined;
21
+ sourceMapPath?: string | undefined;
22
+ };
23
+
24
+ type StaticAssetsConfig =
25
+ | (Config["assets"] & {
26
+ bypassCache: boolean | undefined;
27
+ })
28
+ | undefined;
29
+
30
+ /**
31
+ * Searches for any uses of node's builtin modules, and throws an error if it
32
+ * finds anything. This plugin is only used when nodeCompat is not enabled.
33
+ * Supports both regular node builtins, and the new "node:<MODULE>" format.
34
+ */
35
+ const checkForNodeBuiltinsPlugin = {
36
+ name: "checkForNodeBuiltins",
37
+ setup(build: esbuild.PluginBuild) {
38
+ build.onResolve(
39
+ {
40
+ filter: new RegExp(
41
+ "^(" +
42
+ builtinModules.join("|") +
43
+ "|" +
44
+ builtinModules.map((module) => "node:" + module).join("|") +
45
+ ")$"
46
+ ),
47
+ },
48
+ () => {
49
+ throw new Error(
50
+ `Detected a Node builtin module import while Node compatibility is disabled.\nAdd node_compat = true to your wrangler.toml file to enable Node compatibility.`
51
+ );
52
+ }
53
+ );
54
+ },
15
55
  };
16
56
 
17
57
  /**
18
58
  * Generate a bundle for the worker identified by the arguments passed in.
19
59
  */
20
60
  export async function bundleWorker(
21
- entry: Entry,
22
- destination: string,
23
- options: {
24
- serveAssetsFromWorker: boolean;
25
- jsxFactory: string | undefined;
26
- jsxFragment: string | undefined;
27
- rules: Config["rules"];
28
- watch?: esbuild.WatchMode;
29
- tsconfig: string | undefined;
30
- }
61
+ entry: Entry,
62
+ destination: string,
63
+ options: {
64
+ serveAssetsFromWorker: boolean;
65
+ assets: StaticAssetsConfig;
66
+ betaD1Shims?: string[];
67
+ jsxFactory: string | undefined;
68
+ jsxFragment: string | undefined;
69
+ rules: Config["rules"];
70
+ watch?: esbuild.WatchMode;
71
+ tsconfig: string | undefined;
72
+ minify: boolean | undefined;
73
+ nodeCompat: boolean | undefined;
74
+ define: Config["define"];
75
+ checkFetch: boolean;
76
+ services: Config["services"] | undefined;
77
+ workerDefinitions: WorkerRegistry | undefined;
78
+ firstPartyWorkerDevFacade: boolean | undefined;
79
+ targetConsumer: "dev" | "publish";
80
+ local: boolean;
81
+ testScheduled?: boolean | undefined;
82
+ experimentalLocalStubCache: boolean | undefined;
83
+ }
31
84
  ): Promise<BundleResult> {
32
- const {
33
- serveAssetsFromWorker,
34
- jsxFactory,
35
- jsxFragment,
36
- rules,
37
- watch,
38
- tsconfig,
39
- } = options;
40
- const entryDirectory = path.dirname(entry.file);
41
- const moduleCollector = createModuleCollector({
42
- wrangler1xlegacyModuleReferences: {
43
- rootDirectory: entryDirectory,
44
- fileNames: new Set(
45
- fs
46
- .readdirSync(entryDirectory, { withFileTypes: true })
47
- .filter(
48
- (dirEntry) =>
49
- dirEntry.isFile() && dirEntry.name !== path.basename(entry.file)
50
- )
51
- .map((dirEnt) => dirEnt.name)
52
- ),
53
- },
54
- format: entry.format,
55
- rules,
56
- });
57
- const result = await esbuild.build({
58
- ...getEntryPoint(entry.file, serveAssetsFromWorker),
59
- bundle: true,
60
- absWorkingDir: entry.directory,
61
- outdir: destination,
62
- external: ["__STATIC_CONTENT_MANIFEST"],
63
- format: "esm",
64
- sourcemap: true,
65
- metafile: true,
66
- conditions: ["worker", "browser"],
67
- ...(process.env.NODE_ENV && {
68
- define: {
69
- "process.env.NODE_ENV": `"${process.env.NODE_ENV}"`,
70
- },
71
- }),
72
- loader: {
73
- ".js": "jsx",
74
- ".mjs": "jsx",
75
- ".cjs": "jsx",
76
- },
77
- plugins: [moduleCollector.plugin],
78
- ...(jsxFactory && { jsxFactory }),
79
- ...(jsxFragment && { jsxFragment }),
80
- ...(tsconfig && { tsconfig }),
81
- watch,
82
- });
83
-
84
- const entryPointOutputs = Object.entries(result.metafile.outputs).filter(
85
- ([_path, output]) => output.entryPoint !== undefined
86
- );
87
- assert(
88
- entryPointOutputs.length > 0,
89
- `Cannot find entry-point "${entry.file}" in generated bundle.` +
90
- listEntryPoints(entryPointOutputs)
91
- );
92
- assert(
93
- entryPointOutputs.length < 2,
94
- "More than one entry-point found for generated bundle." +
95
- listEntryPoints(entryPointOutputs)
96
- );
97
-
98
- const entryPointExports = entryPointOutputs[0][1].exports;
99
- const bundleType = entryPointExports.length > 0 ? "esm" : "commonjs";
100
-
101
- return {
102
- modules: moduleCollector.modules,
103
- resolvedEntryPointPath: path.resolve(
104
- entry.directory,
105
- entryPointOutputs[0][0]
106
- ),
107
- bundleType,
108
- stop: result.stop,
109
- };
85
+ const {
86
+ serveAssetsFromWorker,
87
+ betaD1Shims,
88
+ jsxFactory,
89
+ jsxFragment,
90
+ rules,
91
+ watch,
92
+ tsconfig,
93
+ minify,
94
+ nodeCompat,
95
+ checkFetch,
96
+ local,
97
+ assets,
98
+ workerDefinitions,
99
+ services,
100
+ firstPartyWorkerDevFacade,
101
+ targetConsumer,
102
+ testScheduled,
103
+ experimentalLocalStubCache,
104
+ } = options;
105
+
106
+ // We create a temporary directory for any oneoff files we
107
+ // need to create. This is separate from the main build
108
+ // directory (`destination`).
109
+ const tmpDir = await tmp.dir({ unsafeCleanup: true });
110
+
111
+ const entryDirectory = path.dirname(entry.file);
112
+ const moduleCollector = createModuleCollector({
113
+ wrangler1xlegacyModuleReferences: {
114
+ rootDirectory: entryDirectory,
115
+ fileNames: new Set(
116
+ fs
117
+ .readdirSync(entryDirectory, { withFileTypes: true })
118
+ .filter(
119
+ (dirEntry) =>
120
+ dirEntry.isFile() && dirEntry.name !== path.basename(entry.file)
121
+ )
122
+ .map((dirEnt) => dirEnt.name)
123
+ ),
124
+ },
125
+ format: entry.format,
126
+ rules,
127
+ });
128
+
129
+ // In dev, we want to patch `fetch()` with a special version that looks
130
+ // for bad usages and can warn the user about them; so we inject
131
+ // `checked-fetch.js` to do so. However, with yarn 3 style pnp,
132
+ // we need to extract that file to an accessible place before injecting
133
+ // it in, hence this code here.
134
+
135
+ const checkedFetchFileToInject = path.join(tmpDir.path, "checked-fetch.js");
136
+
137
+ if (checkFetch && !fs.existsSync(checkedFetchFileToInject)) {
138
+ fs.mkdirSync(tmpDir.path, {
139
+ recursive: true,
140
+ });
141
+ fs.writeFileSync(
142
+ checkedFetchFileToInject,
143
+ fs.readFileSync(path.resolve(getBasePath(), "templates/checked-fetch.js"))
144
+ );
145
+ }
146
+
147
+ // At this point, we take the opportunity to "wrap" any input workers
148
+ // with any extra functionality we may want to add. This is done by
149
+ // passing the entry point through a pipeline of functions that return
150
+ // a new entry point, that we call "middleware" or "facades".
151
+ // Look at implementations of these functions to learn more.
152
+
153
+ // We also have middleware that uses a more "traditional" middleware stack,
154
+ // which is all loaded as one in a stack.
155
+ const middlewareToLoad: MiddlewareLoader[] = [];
156
+
157
+ if (testScheduled) {
158
+ middlewareToLoad.push({
159
+ path: "templates/middleware/middleware-scheduled.ts",
160
+ });
161
+ }
162
+
163
+ type MiddlewareFn = (arg0: Entry) => Promise<Entry>;
164
+ const middleware: (false | undefined | MiddlewareFn)[] = [
165
+ // serve static assets
166
+ serveAssetsFromWorker &&
167
+ ((currentEntry: Entry) => {
168
+ return applyStaticAssetFacade(currentEntry, tmpDir.path, assets);
169
+ }),
170
+ // format errors nicely
171
+ // We use an env var here because we don't actually
172
+ // want to expose this to the user. It's only used internally to
173
+ // experiment with middleware as a teaching exercise.
174
+ process.env.FORMAT_WRANGLER_ERRORS === "true" &&
175
+ ((currentEntry: Entry) => {
176
+ return applyFormatDevErrorsFacade(currentEntry, tmpDir.path);
177
+ }),
178
+ // bind to other dev instances/service bindings
179
+ workerDefinitions &&
180
+ Object.keys(workerDefinitions).length > 0 &&
181
+ services &&
182
+ services.length > 0 &&
183
+ ((currentEntry: Entry) => {
184
+ return applyMultiWorkerDevFacade(
185
+ currentEntry,
186
+ tmpDir.path,
187
+ services,
188
+ workerDefinitions
189
+ );
190
+ }),
191
+ // Simulate internal environment when using first party workers in dev
192
+ firstPartyWorkerDevFacade === true &&
193
+ ((currentEntry: Entry) => {
194
+ return applyFirstPartyWorkerDevFacade(currentEntry, tmpDir.path);
195
+ }),
196
+
197
+ Array.isArray(betaD1Shims) &&
198
+ betaD1Shims.length > 0 &&
199
+ ((currentEntry: Entry) => {
200
+ return applyD1BetaFacade(currentEntry, tmpDir.path, betaD1Shims, local);
201
+ }),
202
+
203
+ // Middleware loader: to add middleware, we add the path to the middleware
204
+ // Currently for demonstration purposes we have two example middlewares
205
+ // Middlewares are togglable by changing the `publish` (default=false) and `dev` (default=true) options
206
+ // As we are not yet supporting user created middlewares yet, if no wrangler applied middleware
207
+ // are found, we will not load any middleware. We also need to check if there are middlewares compatible with
208
+ // the target consumer (dev / publish).
209
+ (middlewareToLoad.filter(
210
+ (m) =>
211
+ (m.publish && targetConsumer === "publish") ||
212
+ (m.dev !== false && targetConsumer === "dev")
213
+ ).length > 0 ||
214
+ process.env.EXPERIMENTAL_MIDDLEWARE === "true") &&
215
+ ((currentEntry: Entry) => {
216
+ return applyMiddlewareLoaderFacade(
217
+ currentEntry,
218
+ tmpDir.path,
219
+ middlewareToLoad.filter(
220
+ // We dynamically filter the middleware depending on where we are bundling for
221
+ (m) =>
222
+ (targetConsumer === "dev" && m.dev !== false) ||
223
+ (m.publish && targetConsumer === "publish")
224
+ ),
225
+ moduleCollector.plugin
226
+ );
227
+ }),
228
+ ].filter(Boolean);
229
+
230
+ let inputEntry = entry;
231
+
232
+ for (const middlewareFn of middleware as MiddlewareFn[]) {
233
+ inputEntry = await middlewareFn(inputEntry);
234
+ }
235
+
236
+ // At this point, inputEntry points to the entry point we want to build.
237
+
238
+ const inject: string[] = [];
239
+ if (checkFetch) inject.push(checkedFetchFileToInject);
240
+ if (experimentalLocalStubCache) {
241
+ inject.push(
242
+ path.resolve(getBasePath(), "templates/experimental-local-cache-stubs.js")
243
+ );
244
+ }
245
+
246
+ const result = await esbuild.build({
247
+ entryPoints: [inputEntry.file],
248
+ bundle: true,
249
+ absWorkingDir: entry.directory,
250
+ outdir: destination,
251
+ inject,
252
+ external: ["__STATIC_CONTENT_MANIFEST"],
253
+ format: entry.format === "modules" ? "esm" : "iife",
254
+ target: "es2020",
255
+ sourcemap: true,
256
+ // Include a reference to the output folder in the sourcemap.
257
+ // This is omitted by default, but we need it to properly resolve source paths in error output.
258
+ sourceRoot: destination,
259
+ minify,
260
+ metafile: true,
261
+ conditions: ["worker", "browser"],
262
+ ...(process.env.NODE_ENV && {
263
+ define: {
264
+ // use process.env["NODE_ENV" + ""] so that esbuild doesn't replace it
265
+ // when we do a build of wrangler. (re: https://github.com/cloudflare/wrangler2/issues/1477)
266
+ "process.env.NODE_ENV": `"${process.env["NODE_ENV" + ""]}"`,
267
+ ...(nodeCompat ? { global: "globalThis" } : {}),
268
+ ...(checkFetch ? { fetch: "checkedFetch" } : {}),
269
+ ...options.define,
270
+ },
271
+ }),
272
+ loader: {
273
+ ".js": "jsx",
274
+ ".mjs": "jsx",
275
+ ".cjs": "jsx",
276
+ },
277
+ plugins: [
278
+ // We run the moduleCollector plugin for service workers as part of the middleware loader
279
+ // so we only run here for modules or with no middleware to load
280
+ ...(entry.format === "modules" || middlewareToLoad.length === 0
281
+ ? [moduleCollector.plugin]
282
+ : []),
283
+ ...(nodeCompat
284
+ ? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
285
+ : // we use checkForNodeBuiltinsPlugin to throw a nicer error
286
+ // if we find node builtins when nodeCompat isn't turned on
287
+ [checkForNodeBuiltinsPlugin]),
288
+ ],
289
+ ...(jsxFactory && { jsxFactory }),
290
+ ...(jsxFragment && { jsxFragment }),
291
+ ...(tsconfig && { tsconfig }),
292
+ watch,
293
+ });
294
+
295
+ const entryPointOutputs = Object.entries(result.metafile.outputs).filter(
296
+ ([_path, output]) => output.entryPoint !== undefined
297
+ );
298
+ assert(
299
+ entryPointOutputs.length > 0,
300
+ `Cannot find entry-point "${entry.file}" in generated bundle.` +
301
+ listEntryPoints(entryPointOutputs)
302
+ );
303
+ assert(
304
+ entryPointOutputs.length < 2,
305
+ "More than one entry-point found for generated bundle." +
306
+ listEntryPoints(entryPointOutputs)
307
+ );
308
+
309
+ const entryPointExports = entryPointOutputs[0][1].exports;
310
+ const bundleType = entryPointExports.length > 0 ? "esm" : "commonjs";
311
+
312
+ const sourceMapPath = Object.keys(result.metafile.outputs).filter((_path) =>
313
+ _path.includes(".map")
314
+ )[0];
315
+
316
+ return {
317
+ modules: moduleCollector.modules,
318
+ resolvedEntryPointPath: path.resolve(
319
+ entry.directory,
320
+ entryPointOutputs[0][0]
321
+ ),
322
+ bundleType,
323
+ stop: result.stop,
324
+ sourceMapPath,
325
+ };
326
+ }
327
+
328
+ /**
329
+ * A simple plugin to alias modules and mark them as external
330
+ */
331
+ export function esbuildAliasExternalPlugin(
332
+ aliases: Record<string, string>
333
+ ): esbuild.Plugin {
334
+ return {
335
+ name: "alias",
336
+ setup(build) {
337
+ build.onResolve({ filter: /.*/g }, (args) => {
338
+ // If it's the entrypoint, let it be as is
339
+ if (args.kind === "entry-point") {
340
+ return {
341
+ path: args.path,
342
+ };
343
+ }
344
+ // If it's not a recognised alias, then throw an error
345
+ if (!Object.keys(aliases).includes(args.path)) {
346
+ throw new Error("unrecognized module: " + args.path);
347
+ }
348
+
349
+ // Otherwise, return the alias
350
+ return {
351
+ path: aliases[args.path as keyof typeof aliases],
352
+ external: true,
353
+ };
354
+ });
355
+ },
356
+ };
110
357
  }
111
358
 
112
- type EntryPoint =
113
- | { stdin: esbuild.StdinOptions; nodePaths: string[] }
114
- | { entryPoints: string[] };
359
+ /**
360
+ * A middleware that catches any thrown errors, and instead formats
361
+ * them to be rendered in a browser. This middleware is for demonstration
362
+ * purposes only, and is not intended to be used in production (or even dev!)
363
+ */
364
+ async function applyFormatDevErrorsFacade(
365
+ entry: Entry,
366
+ tmpDirPath: string
367
+ ): Promise<Entry> {
368
+ const targetPath = path.join(tmpDirPath, "format-dev-errors.entry.js");
369
+ await esbuild.build({
370
+ entryPoints: [
371
+ path.resolve(getBasePath(), "templates/format-dev-errors.ts"),
372
+ ],
373
+ bundle: true,
374
+ sourcemap: true,
375
+ format: "esm",
376
+ plugins: [
377
+ esbuildAliasExternalPlugin({
378
+ __ENTRY_POINT__: entry.file,
379
+ }),
380
+ ],
381
+ outfile: targetPath,
382
+ });
383
+
384
+ return {
385
+ ...entry,
386
+ file: targetPath,
387
+ };
388
+ }
115
389
 
116
390
  /**
117
- * Create an object that describes the entry point for esbuild.
391
+ * A facade that acts as a "middleware loader".
392
+ * Instead of needing to apply a facade for each individual middleware, this allows
393
+ * middleware to be written in a more traditional manner and then be applied all
394
+ * at once, requiring just two esbuild steps, rather than 1 per middleware.
395
+ */
396
+
397
+ interface MiddlewareLoader {
398
+ path: string;
399
+ // By default all middleware will run on dev, but will not be run when published
400
+ publish?: boolean;
401
+ dev?: boolean;
402
+ }
403
+
404
+ async function applyMiddlewareLoaderFacade(
405
+ entry: Entry,
406
+ tmpDirPath: string,
407
+ middleware: MiddlewareLoader[], // a list of paths to middleware files
408
+ moduleCollectorPlugin: esbuild.Plugin
409
+ ): Promise<Entry> {
410
+ // Firstly we need to insert the middleware array into the project,
411
+ // and then we load the middleware - this insertion and loading is
412
+ // different for each format.
413
+
414
+ // STEP 1: Insert the middleware
415
+ const targetPathInsertion = path.join(
416
+ tmpDirPath,
417
+ "middleware-insertion.entry.js"
418
+ );
419
+
420
+ // We need to import each of the middlewares, so we need to generate a
421
+ // random, unique identifier that we can use for the import.
422
+ // Middlewares are required to be default exports so we can import to any name.
423
+ const middlewareIdentifiers = middleware.map(
424
+ (_, index) => `__MIDDLEWARE_${index}__`
425
+ );
426
+
427
+ const dynamicFacadePath = path.join(
428
+ tmpDirPath,
429
+ "middleware-insertion-facade.js"
430
+ );
431
+
432
+ if (entry.format === "modules") {
433
+ // We use a facade to expose the required middleware alongside any user defined
434
+ // middleware on the worker object
435
+
436
+ const imports = middlewareIdentifiers
437
+ .map((m) => `import ${m} from "${m}";`)
438
+ .join("\n");
439
+
440
+ // write a file with all of the imports required
441
+ fs.writeFileSync(
442
+ dynamicFacadePath,
443
+ `import worker from "__ENTRY_POINT__";
444
+ ${imports}
445
+ const facade = {
446
+ ...worker,
447
+ middleware: [
448
+ ${middlewareIdentifiers.join(",")}${middlewareIdentifiers.length > 0 ? "," : ""}
449
+ ...(worker.middleware ? worker.middleware : []),
450
+ ]
451
+ }
452
+ export * from "__ENTRY_POINT__";
453
+ export default facade;`
454
+ );
455
+
456
+ await esbuild.build({
457
+ entryPoints: [path.resolve(getBasePath(), dynamicFacadePath)],
458
+ bundle: true,
459
+ sourcemap: true,
460
+ format: "esm",
461
+ plugins: [
462
+ esbuildAliasExternalPlugin({
463
+ __ENTRY_POINT__: entry.file,
464
+ ...Object.fromEntries(
465
+ middleware.map((val, index) => [
466
+ middlewareIdentifiers[index],
467
+ toUrlPath(path.resolve(getBasePath(), val.path)),
468
+ ])
469
+ ),
470
+ }),
471
+ ],
472
+ outfile: targetPathInsertion,
473
+ });
474
+ } else {
475
+ // We handle service workers slightly differently as we have to overwrite
476
+ // the event listeners and reimplement them
477
+
478
+ await esbuild.build({
479
+ entryPoints: [entry.file],
480
+ bundle: true,
481
+ sourcemap: true,
482
+ define: {
483
+ "process.env.NODE_ENV": `"${process.env["NODE_ENV" + ""]}"`,
484
+ },
485
+ format: "esm",
486
+ outfile: targetPathInsertion,
487
+ plugins: [moduleCollectorPlugin],
488
+ });
489
+
490
+ const imports = middlewareIdentifiers
491
+ .map(
492
+ (m, i) =>
493
+ `import ${m} from "${toUrlPath(
494
+ path.resolve(getBasePath(), middleware[i].path)
495
+ )}";`
496
+ )
497
+ .join("\n");
498
+
499
+ // We add the new modules with imports and then register using the
500
+ // addMiddleware function (which gets rewritten in the next build step)
501
+
502
+ // We choose to run middleware inserted in wrangler before user inserted
503
+ // middleware in the stack
504
+ // To do this, we either need to execute the addMiddleware function first
505
+ // before any user middleware, or use a separate handling function.
506
+ // We choose to do the latter as to prepend, we would have to load the entire
507
+ // script into memory as a prepend function doesn't exist or work in the same
508
+ // way that an append function does.
509
+
510
+ fs.copyFileSync(targetPathInsertion, dynamicFacadePath);
511
+ fs.appendFileSync(
512
+ dynamicFacadePath,
513
+ `
514
+ ${imports}
515
+ addMiddlewareInternal([${middlewareIdentifiers.join(",")}])
516
+ `
517
+ );
518
+ }
519
+
520
+ // STEP 2: Load the middleware
521
+ // We want to get the filename of the orginal entry point
522
+ let targetPathLoader = path.join(tmpDirPath, path.basename(entry.file));
523
+ if (path.extname(entry.file) === "") targetPathLoader += ".js";
524
+
525
+ const loaderPath =
526
+ entry.format === "modules"
527
+ ? path.resolve(getBasePath(), "templates/middleware/loader-modules.ts")
528
+ : dynamicFacadePath;
529
+
530
+ await esbuild.build({
531
+ entryPoints: [loaderPath],
532
+ bundle: true,
533
+ sourcemap: true,
534
+ format: "esm",
535
+ ...(entry.format === "service-worker"
536
+ ? {
537
+ inject: [
538
+ path.resolve(getBasePath(), "templates/middleware/loader-sw.ts"),
539
+ ],
540
+ define: {
541
+ addEventListener: "__facade_addEventListener__",
542
+ removeEventListener: "__facade_removeEventListener__",
543
+ dispatchEvent: "__facade_dispatchEvent__",
544
+ addMiddleware: "__facade_register__",
545
+ addMiddlewareInternal: "__facade_registerInternal__",
546
+ },
547
+ }
548
+ : {
549
+ plugins: [
550
+ esbuildAliasExternalPlugin({
551
+ __ENTRY_POINT__: targetPathInsertion,
552
+ "./common": path.resolve(
553
+ getBasePath(),
554
+ "templates/middleware/common.ts"
555
+ ),
556
+ }),
557
+ ],
558
+ }),
559
+ outfile: targetPathLoader,
560
+ });
561
+
562
+ return {
563
+ ...entry,
564
+ file: targetPathLoader,
565
+ };
566
+ }
567
+
568
+ /**
569
+ * A middleware that serves static assets from a worker.
570
+ * This powers --assets / config.assets
571
+ */
572
+
573
+ async function applyStaticAssetFacade(
574
+ entry: Entry,
575
+ tmpDirPath: string,
576
+ assets: StaticAssetsConfig
577
+ ): Promise<Entry> {
578
+ const targetPath = path.join(tmpDirPath, "serve-static-assets.entry.js");
579
+
580
+ await esbuild.build({
581
+ entryPoints: [
582
+ path.resolve(getBasePath(), "templates/serve-static-assets.ts"),
583
+ ],
584
+ bundle: true,
585
+ format: "esm",
586
+ sourcemap: true,
587
+ plugins: [
588
+ esbuildAliasExternalPlugin({
589
+ __ENTRY_POINT__: entry.file,
590
+ __KV_ASSET_HANDLER__: path.join(getBasePath(), "kv-asset-handler.js"),
591
+ __STATIC_CONTENT_MANIFEST: "__STATIC_CONTENT_MANIFEST",
592
+ }),
593
+ ],
594
+ define: {
595
+ __CACHE_CONTROL_OPTIONS__: JSON.stringify(
596
+ typeof assets === "object"
597
+ ? {
598
+ browserTTL:
599
+ assets.browser_TTL || 172800 /* 2 days: 2* 60 * 60 * 24 */,
600
+ bypassCache: assets.bypassCache,
601
+ }
602
+ : {}
603
+ ),
604
+ __SERVE_SINGLE_PAGE_APP__: JSON.stringify(
605
+ typeof assets === "object" ? assets.serve_single_page_app : false
606
+ ),
607
+ },
608
+ outfile: targetPath,
609
+ });
610
+
611
+ return {
612
+ ...entry,
613
+ file: targetPath,
614
+ };
615
+ }
616
+
617
+ /**
618
+ * A middleware that enables service bindings to be used in dev,
619
+ * binding to other love wrangler dev instances
620
+ */
621
+
622
+ async function applyMultiWorkerDevFacade(
623
+ entry: Entry,
624
+ tmpDirPath: string,
625
+ services: Config["services"],
626
+ workerDefinitions: WorkerRegistry
627
+ ) {
628
+ const targetPath = path.join(tmpDirPath, "multiworker-dev-facade.entry.js");
629
+ const serviceMap = Object.fromEntries(
630
+ (services || []).map((serviceBinding) => [
631
+ serviceBinding.binding,
632
+ workerDefinitions[serviceBinding.service] || null,
633
+ ])
634
+ );
635
+
636
+ await esbuild.build({
637
+ entryPoints: [
638
+ path.join(
639
+ getBasePath(),
640
+ entry.format === "modules"
641
+ ? "templates/service-bindings-module-facade.js"
642
+ : "templates/service-bindings-sw-facade.js"
643
+ ),
644
+ ],
645
+ bundle: true,
646
+ sourcemap: true,
647
+ format: "esm",
648
+ plugins: [
649
+ esbuildAliasExternalPlugin({
650
+ __ENTRY_POINT__: entry.file,
651
+ }),
652
+ ],
653
+ define: {
654
+ __WORKERS__: JSON.stringify(serviceMap),
655
+ },
656
+ outfile: targetPath,
657
+ });
658
+
659
+ return {
660
+ ...entry,
661
+ file: targetPath,
662
+ };
663
+ }
664
+
665
+ /**
666
+ * A middleware that makes first party workers "work" in
667
+ * our dev environments. Is applied during wrangler dev
668
+ * when config.first_party_worker is true
669
+ */
670
+ async function applyFirstPartyWorkerDevFacade(
671
+ entry: Entry,
672
+ tmpDirPath: string
673
+ ) {
674
+ if (entry.format !== "modules") {
675
+ throw new Error(
676
+ "First party workers must be in the modules format. See https://developers.cloudflare.com/workers/learning/migrating-to-module-workers/"
677
+ );
678
+ }
679
+
680
+ const targetPath = path.join(
681
+ tmpDirPath,
682
+ "first-party-worker-module-facade.entry.js"
683
+ );
684
+
685
+ await esbuild.build({
686
+ entryPoints: [
687
+ path.resolve(
688
+ getBasePath(),
689
+ "templates/first-party-worker-module-facade.ts"
690
+ ),
691
+ ],
692
+ bundle: true,
693
+ format: "esm",
694
+ sourcemap: true,
695
+ plugins: [
696
+ esbuildAliasExternalPlugin({
697
+ __ENTRY_POINT__: entry.file,
698
+ }),
699
+ ],
700
+ outfile: targetPath,
701
+ });
702
+
703
+ return {
704
+ ...entry,
705
+ file: targetPath,
706
+ };
707
+ }
708
+
709
+ /**
710
+ * A middleware that injects the beta D1 API in JS.
118
711
  *
119
- * If we are using the experimental asset handling, then the entry point is
120
- * actually a shim worker that will either return an asset from a KV store,
121
- * or delegate to the actual worker.
712
+ * This code be removed from here when the API is in Workers core,
713
+ * but moved inside Miniflare for simulating D1.
122
714
  */
123
- function getEntryPoint(
124
- entryFile: string,
125
- serveAssetsFromWorker: boolean
126
- ): EntryPoint {
127
- if (serveAssetsFromWorker) {
128
- return {
129
- stdin: {
130
- contents: fs
131
- .readFileSync(
132
- path.join(__dirname, "../templates/static-asset-facade.js"),
133
- "utf8"
134
- )
135
- .replace("__ENTRY_POINT__", entryFile),
136
- sourcefile: "static-asset-facade.js",
137
- resolveDir: path.dirname(entryFile),
138
- },
139
- nodePaths: [path.join(__dirname, "../vendor")],
140
- };
141
- } else {
142
- return { entryPoints: [entryFile] };
143
- }
715
+
716
+ async function applyD1BetaFacade(
717
+ entry: Entry,
718
+ tmpDirPath: string,
719
+ betaD1Shims: string[],
720
+ local: boolean
721
+ ): Promise<Entry> {
722
+ const targetPath = path.join(tmpDirPath, "d1-beta-facade.entry.js");
723
+
724
+ await esbuild.build({
725
+ entryPoints: [path.resolve(getBasePath(), "templates/d1-beta-facade.js")],
726
+ bundle: true,
727
+ format: "esm",
728
+ sourcemap: true,
729
+ plugins: [
730
+ esbuildAliasExternalPlugin({
731
+ __ENTRY_POINT__: entry.file,
732
+ }),
733
+ ],
734
+ define: {
735
+ __D1_IMPORTS__: JSON.stringify(betaD1Shims),
736
+ __LOCAL_MODE__: JSON.stringify(local),
737
+ },
738
+ outfile: targetPath,
739
+ });
740
+
741
+ return {
742
+ ...entry,
743
+ file: targetPath,
744
+ };
144
745
  }
145
746
 
146
747
  /**
147
748
  * Generate a string that describes the entry-points that were identified by esbuild.
148
749
  */
149
750
  function listEntryPoints(
150
- outputs: [string, ValueOf<esbuild.Metafile["outputs"]>][]
751
+ outputs: [string, ValueOf<esbuild.Metafile["outputs"]>][]
151
752
  ): string {
152
- return outputs.map(([_input, output]) => output.entryPoint).join("\n");
753
+ return outputs.map(([_input, output]) => output.entryPoint).join("\n");
153
754
  }
154
755
 
155
756
  type ValueOf<T> = T[keyof T];