wrangler 0.0.0-e2f9bb2 → 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 (258) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +30 -4
  3. package/bin/wrangler.js +154 -34
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +1437 -21
  6. package/package.json +185 -148
  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 +30 -24
  12. package/src/__tests__/configuration.test.ts +4121 -3114
  13. package/src/__tests__/dev.test.tsx +1331 -738
  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 +68 -68
  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 +199 -94
  21. package/src/__tests__/helpers/mock-console.ts +58 -39
  22. package/src/__tests__/helpers/mock-dialogs.ts +115 -51
  23. package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
  24. package/src/__tests__/helpers/mock-http-server.ts +30 -30
  25. package/src/__tests__/helpers/mock-istty.ts +65 -18
  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 +225 -228
  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 +27 -28
  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 +16 -16
  46. package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
  47. package/src/__tests__/https-options.test.ts +142 -109
  48. package/src/__tests__/index.test.ts +231 -231
  49. package/src/__tests__/init.test.ts +2689 -1014
  50. package/src/__tests__/jest.setup.ts +147 -30
  51. package/src/__tests__/kv.test.ts +1311 -1094
  52. package/src/__tests__/logger.test.ts +100 -74
  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 +1988 -322
  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 +6955 -4743
  61. package/src/__tests__/pubsub.test.ts +367 -0
  62. package/src/__tests__/r2.test.ts +363 -206
  63. package/src/__tests__/route.test.ts +18 -18
  64. package/src/__tests__/secret.test.ts +624 -426
  65. package/src/__tests__/tail.test.ts +650 -565
  66. package/src/__tests__/test-old-node-version.js +31 -0
  67. package/src/__tests__/user.test.ts +140 -116
  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 +259 -91
  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 +721 -134
  77. package/src/cfetch/index.ts +83 -66
  78. package/src/cfetch/internal.ts +267 -90
  79. package/src/cli.ts +23 -7
  80. package/src/config/config.ts +236 -195
  81. package/src/config/diagnostics.ts +61 -61
  82. package/src/config/environment.ts +450 -339
  83. package/src/config/index.ts +258 -38
  84. package/src/config/validation-helpers.ts +379 -357
  85. package/src/config/validation.ts +1769 -1263
  86. package/src/config-cache.ts +81 -41
  87. package/src/create-worker-preview.ts +232 -132
  88. package/src/create-worker-upload-form.ts +285 -224
  89. package/src/d1/backups.tsx +212 -0
  90. package/src/d1/create.tsx +54 -0
  91. package/src/d1/delete.tsx +56 -0
  92. package/src/d1/execute.tsx +294 -0
  93. package/src/d1/formatTimeAgo.ts +14 -0
  94. package/src/d1/index.ts +75 -0
  95. package/src/d1/list.tsx +48 -0
  96. package/src/d1/options.ts +12 -0
  97. package/src/d1/types.tsx +14 -0
  98. package/src/d1/utils.ts +39 -0
  99. package/src/dev/dev-vars.ts +13 -13
  100. package/src/dev/dev.tsx +500 -353
  101. package/src/dev/get-local-persistence-path.tsx +31 -0
  102. package/src/dev/local.tsx +628 -290
  103. package/src/dev/remote.tsx +397 -197
  104. package/src/dev/start-server.ts +443 -0
  105. package/src/dev/use-esbuild.ts +173 -94
  106. package/src/dev/validate-dev-props.ts +31 -0
  107. package/src/dev-registry.tsx +190 -0
  108. package/src/dev.tsx +869 -0
  109. package/src/dialogs.tsx +134 -63
  110. package/src/dispatch-namespace.ts +206 -0
  111. package/src/durable.ts +102 -0
  112. package/src/entry.ts +248 -186
  113. package/src/environment-variables.ts +38 -23
  114. package/src/errors.ts +6 -6
  115. package/src/faye-websocket.d.ts +6 -0
  116. package/src/generate.ts +131 -0
  117. package/src/git-client.ts +42 -0
  118. package/src/global-wrangler-config-path.ts +26 -0
  119. package/src/https-options.ts +84 -80
  120. package/src/index.tsx +2288 -2534
  121. package/src/init.ts +967 -0
  122. package/src/inspect.ts +686 -562
  123. package/src/intl-polyfill.d.ts +123 -123
  124. package/src/is-ci.ts +14 -0
  125. package/src/is-interactive.ts +12 -0
  126. package/src/kv.ts +353 -242
  127. package/src/logger.ts +53 -39
  128. package/src/metrics/index.ts +5 -0
  129. package/src/metrics/metrics-config.ts +239 -0
  130. package/src/metrics/metrics-dispatcher.ts +96 -0
  131. package/src/metrics/metrics-usage-headers.ts +24 -0
  132. package/src/metrics/send-event.ts +93 -0
  133. package/src/miniflare-cli/assets.ts +215 -0
  134. package/src/miniflare-cli/index.ts +200 -33
  135. package/src/miniflare-cli/request-context.ts +18 -18
  136. package/src/module-collection.ts +212 -212
  137. package/src/open-in-browser.ts +5 -14
  138. package/src/package-manager.ts +182 -90
  139. package/src/pages/build.tsx +238 -0
  140. package/src/pages/constants.ts +16 -0
  141. package/src/pages/deployments.tsx +106 -0
  142. package/src/pages/dev.tsx +684 -0
  143. package/src/pages/errors.ts +66 -0
  144. package/src/pages/functions/buildPlugin.ts +110 -0
  145. package/src/pages/functions/buildWorker.ts +156 -0
  146. package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
  147. package/src/pages/functions/filepath-routing.ts +189 -0
  148. package/src/pages/functions/identifiers.ts +78 -0
  149. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  150. package/src/pages/functions/routes-consolidation.ts +73 -0
  151. package/src/pages/functions/routes-transformation.test.ts +282 -0
  152. package/src/pages/functions/routes-transformation.ts +115 -0
  153. package/src/pages/functions/routes-validation.test.ts +403 -0
  154. package/src/pages/functions/routes-validation.ts +202 -0
  155. package/src/pages/functions/routes.ts +151 -0
  156. package/src/pages/functions.tsx +82 -0
  157. package/src/pages/hash.tsx +13 -0
  158. package/src/pages/index.tsx +94 -0
  159. package/src/pages/projects.tsx +169 -0
  160. package/src/pages/publish.tsx +419 -0
  161. package/src/pages/types.ts +49 -0
  162. package/src/pages/upload.tsx +398 -0
  163. package/src/pages/utils.ts +12 -0
  164. package/src/parse.ts +223 -120
  165. package/src/paths.ts +53 -8
  166. package/src/preview.ts +31 -0
  167. package/src/proxy.ts +435 -383
  168. package/src/publish.ts +837 -441
  169. package/src/pubsub/index.ts +286 -0
  170. package/src/pubsub/pubsub-commands.tsx +623 -0
  171. package/src/r2.ts +100 -19
  172. package/src/selfsigned.d.ts +23 -23
  173. package/src/sites.tsx +279 -200
  174. package/src/tail/filters.ts +108 -110
  175. package/src/tail/index.ts +234 -218
  176. package/src/tail/printing.ts +86 -46
  177. package/src/update-check.ts +11 -11
  178. package/src/user/choose-account.tsx +69 -0
  179. package/src/user/env-vars.ts +46 -0
  180. package/src/user/generate-auth-url.ts +33 -0
  181. package/src/user/generate-random-state.ts +16 -0
  182. package/src/user/index.ts +3 -0
  183. package/src/user/user.tsx +1192 -0
  184. package/src/whoami.tsx +141 -42
  185. package/src/worker.ts +163 -101
  186. package/src/zones.ts +167 -0
  187. package/templates/checked-fetch.js +17 -0
  188. package/templates/d1-beta-facade.js +174 -0
  189. package/templates/experimental-local-cache-stubs.js +27 -0
  190. package/templates/first-party-worker-module-facade.ts +18 -0
  191. package/templates/format-dev-errors.ts +32 -0
  192. package/templates/init-tests/test-jest-new-worker.js +25 -0
  193. package/templates/init-tests/test-vitest-new-worker.js +26 -0
  194. package/templates/middleware/common.ts +62 -0
  195. package/templates/middleware/loader-modules.ts +84 -0
  196. package/templates/middleware/loader-sw.ts +213 -0
  197. package/templates/middleware/middleware-pretty-error.ts +40 -0
  198. package/templates/middleware/middleware-scheduled.ts +15 -0
  199. package/templates/new-worker-scheduled.js +17 -0
  200. package/templates/new-worker-scheduled.ts +32 -0
  201. package/templates/new-worker.js +3 -3
  202. package/templates/new-worker.ts +18 -3
  203. package/templates/no-op-worker.js +10 -0
  204. package/templates/pages-dev-pipeline.ts +35 -0
  205. package/templates/pages-shim.ts +9 -0
  206. package/templates/pages-template-plugin.ts +167 -0
  207. package/templates/pages-template-worker.ts +172 -0
  208. package/templates/serve-static-assets.ts +63 -0
  209. package/templates/service-bindings-module-facade.js +54 -0
  210. package/templates/service-bindings-sw-facade.js +42 -0
  211. package/templates/tsconfig.json +95 -95
  212. package/wrangler-dist/cli.d.ts +841 -0
  213. package/wrangler-dist/cli.js +120834 -70331
  214. package/pages/functions/buildPlugin.ts +0 -92
  215. package/pages/functions/buildWorker.ts +0 -138
  216. package/pages/functions/filepath-routing.ts +0 -189
  217. package/pages/functions/identifiers.ts +0 -78
  218. package/pages/functions/routes.ts +0 -156
  219. package/pages/functions/template-plugin.ts +0 -146
  220. package/pages/functions/template-worker.ts +0 -143
  221. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  222. package/src/miniflare-cli/enum-keys.ts +0 -17
  223. package/src/pages.tsx +0 -1866
  224. package/src/user.tsx +0 -1193
  225. package/templates/static-asset-facade.js +0 -47
  226. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  227. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  228. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  229. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  230. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  231. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  232. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  233. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  234. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  235. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  236. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  237. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  238. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  239. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  240. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  241. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  242. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  243. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  244. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  245. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  246. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  247. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  248. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  249. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  250. package/vendor/wrangler-mime/LICENSE +0 -21
  251. package/vendor/wrangler-mime/Mime.js +0 -97
  252. package/vendor/wrangler-mime/README.md +0 -187
  253. package/vendor/wrangler-mime/cli.js +0 -46
  254. package/vendor/wrangler-mime/index.js +0 -4
  255. package/vendor/wrangler-mime/lite.js +0 -4
  256. package/vendor/wrangler-mime/package.json +0 -52
  257. package/vendor/wrangler-mime/types/other.js +0 -1
  258. package/vendor/wrangler-mime/types/standard.js +0 -1
package/src/bundle.ts CHANGED
@@ -1,169 +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";
4
5
  import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
5
6
  import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
6
7
  import * as esbuild from "esbuild";
8
+ import tmp from "tmp-promise";
7
9
  import createModuleCollector from "./module-collection";
10
+ import { getBasePath, toUrlPath } from "./paths";
8
11
  import type { Config } from "./config";
12
+ import type { WorkerRegistry } from "./dev-registry";
9
13
  import type { Entry } from "./entry";
10
14
  import type { CfModule } from "./worker";
11
15
 
12
16
  type BundleResult = {
13
- modules: CfModule[];
14
- resolvedEntryPointPath: string;
15
- bundleType: "esm" | "commonjs";
16
- 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
+ },
17
55
  };
18
56
 
19
57
  /**
20
58
  * Generate a bundle for the worker identified by the arguments passed in.
21
59
  */
22
60
  export async function bundleWorker(
23
- entry: Entry,
24
- destination: string,
25
- options: {
26
- serveAssetsFromWorker: boolean;
27
- jsxFactory: string | undefined;
28
- jsxFragment: string | undefined;
29
- rules: Config["rules"];
30
- watch?: esbuild.WatchMode;
31
- tsconfig: string | undefined;
32
- minify: boolean | undefined;
33
- nodeCompat: boolean | undefined;
34
- }
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
+ }
35
84
  ): Promise<BundleResult> {
36
- const {
37
- serveAssetsFromWorker,
38
- jsxFactory,
39
- jsxFragment,
40
- rules,
41
- watch,
42
- tsconfig,
43
- minify,
44
- nodeCompat,
45
- } = options;
46
- const entryDirectory = path.dirname(entry.file);
47
- const moduleCollector = createModuleCollector({
48
- wrangler1xlegacyModuleReferences: {
49
- rootDirectory: entryDirectory,
50
- fileNames: new Set(
51
- fs
52
- .readdirSync(entryDirectory, { withFileTypes: true })
53
- .filter(
54
- (dirEntry) =>
55
- dirEntry.isFile() && dirEntry.name !== path.basename(entry.file)
56
- )
57
- .map((dirEnt) => dirEnt.name)
58
- ),
59
- },
60
- format: entry.format,
61
- rules,
62
- });
63
- const result = await esbuild.build({
64
- ...getEntryPoint(entry.file, serveAssetsFromWorker),
65
- bundle: true,
66
- absWorkingDir: entry.directory,
67
- outdir: destination,
68
- external: ["__STATIC_CONTENT_MANIFEST"],
69
- format: "esm",
70
- target: "es2020",
71
- sourcemap: true,
72
- minify,
73
- metafile: true,
74
- conditions: ["worker", "browser"],
75
- ...(process.env.NODE_ENV && {
76
- define: {
77
- "process.env.NODE_ENV": `"${process.env.NODE_ENV}"`,
78
- ...(nodeCompat ? { global: "globalThis" } : {}),
79
- },
80
- }),
81
- loader: {
82
- ".js": "jsx",
83
- ".mjs": "jsx",
84
- ".cjs": "jsx",
85
- },
86
- plugins: [
87
- moduleCollector.plugin,
88
- ...(nodeCompat
89
- ? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
90
- : []),
91
- ],
92
- ...(jsxFactory && { jsxFactory }),
93
- ...(jsxFragment && { jsxFragment }),
94
- ...(tsconfig && { tsconfig }),
95
- watch,
96
- });
97
-
98
- const entryPointOutputs = Object.entries(result.metafile.outputs).filter(
99
- ([_path, output]) => output.entryPoint !== undefined
100
- );
101
- assert(
102
- entryPointOutputs.length > 0,
103
- `Cannot find entry-point "${entry.file}" in generated bundle.` +
104
- listEntryPoints(entryPointOutputs)
105
- );
106
- assert(
107
- entryPointOutputs.length < 2,
108
- "More than one entry-point found for generated bundle." +
109
- listEntryPoints(entryPointOutputs)
110
- );
111
-
112
- const entryPointExports = entryPointOutputs[0][1].exports;
113
- const bundleType = entryPointExports.length > 0 ? "esm" : "commonjs";
114
-
115
- return {
116
- modules: moduleCollector.modules,
117
- resolvedEntryPointPath: path.resolve(
118
- entry.directory,
119
- entryPointOutputs[0][0]
120
- ),
121
- bundleType,
122
- stop: result.stop,
123
- };
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
+ };
124
357
  }
125
358
 
126
- type EntryPoint =
127
- | { stdin: esbuild.StdinOptions; nodePaths: string[] }
128
- | { 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
+ }
129
389
 
130
390
  /**
131
- * 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.
132
711
  *
133
- * If we are using the experimental asset handling, then the entry point is
134
- * actually a shim worker that will either return an asset from a KV store,
135
- * 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.
136
714
  */
137
- function getEntryPoint(
138
- entryFile: string,
139
- serveAssetsFromWorker: boolean
140
- ): EntryPoint {
141
- if (serveAssetsFromWorker) {
142
- return {
143
- stdin: {
144
- contents: fs
145
- .readFileSync(
146
- path.join(__dirname, "../templates/static-asset-facade.js"),
147
- "utf8"
148
- )
149
- .replace("__ENTRY_POINT__", entryFile),
150
- sourcefile: "static-asset-facade.js",
151
- resolveDir: path.dirname(entryFile),
152
- },
153
- nodePaths: [path.join(__dirname, "../vendor")],
154
- };
155
- } else {
156
- return { entryPoints: [entryFile] };
157
- }
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
+ };
158
745
  }
159
746
 
160
747
  /**
161
748
  * Generate a string that describes the entry-points that were identified by esbuild.
162
749
  */
163
750
  function listEntryPoints(
164
- outputs: [string, ValueOf<esbuild.Metafile["outputs"]>][]
751
+ outputs: [string, ValueOf<esbuild.Metafile["outputs"]>][]
165
752
  ): string {
166
- return outputs.map(([_input, output]) => output.entryPoint).join("\n");
753
+ return outputs.map(([_input, output]) => output.entryPoint).join("\n");
167
754
  }
168
755
 
169
756
  type ValueOf<T> = T[keyof T];