wrangler 0.0.0-e33bea9b → 0.0.0-e351afcf

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 (105) hide show
  1. package/miniflare-dist/index.mjs +167 -93
  2. package/package.json +14 -9
  3. package/src/__tests__/api-devregistry.test.ts +121 -0
  4. package/src/__tests__/api.test.ts +27 -5
  5. package/src/__tests__/configuration.test.ts +59 -12
  6. package/src/__tests__/constellation.test.ts +371 -0
  7. package/src/__tests__/d1/execute.test.ts +2 -0
  8. package/src/__tests__/d1/migrate.test.ts +102 -0
  9. package/src/__tests__/delete.test.ts +6 -0
  10. package/src/__tests__/deployments.test.ts +335 -95
  11. package/src/__tests__/dev.test.tsx +71 -56
  12. package/src/__tests__/generate.test.ts +3 -4
  13. package/src/__tests__/helpers/mock-console.ts +6 -0
  14. package/src/__tests__/helpers/msw/handlers/deployments.ts +70 -3
  15. package/src/__tests__/helpers/msw/index.ts +4 -2
  16. package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
  17. package/src/__tests__/index.test.ts +14 -6
  18. package/src/__tests__/init.test.ts +127 -96
  19. package/src/__tests__/jest.setup.ts +4 -0
  20. package/src/__tests__/kv.test.ts +9 -9
  21. package/src/__tests__/logger.test.ts +68 -2
  22. package/src/__tests__/middleware.scheduled.test.ts +2 -2
  23. package/src/__tests__/middleware.test.ts +2 -2
  24. package/src/__tests__/mtls-certificates.test.ts +7 -3
  25. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  26. package/src/__tests__/pages/functions-build.test.ts +70 -0
  27. package/src/__tests__/pages/project-list.test.ts +2 -0
  28. package/src/__tests__/pages/project-upload.test.ts +43 -24
  29. package/src/__tests__/pages/publish.test.ts +136 -92
  30. package/src/__tests__/publish.test.ts +878 -332
  31. package/src/__tests__/pubsub.test.ts +3 -0
  32. package/src/__tests__/queues.test.ts +5 -2
  33. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  34. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  35. package/src/__tests__/user.test.ts +1 -1
  36. package/src/__tests__/worker-namespace.test.ts +1 -0
  37. package/src/api/dev.ts +12 -18
  38. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  39. package/src/api/pages/publish.tsx +28 -12
  40. package/src/bundle.ts +26 -9
  41. package/src/config/environment.ts +27 -0
  42. package/src/config/index.ts +18 -0
  43. package/src/config/validation.ts +91 -1
  44. package/src/constellation/createProject.tsx +51 -0
  45. package/src/constellation/deleteProject.ts +51 -0
  46. package/src/constellation/deleteProjectModel.ts +68 -0
  47. package/src/constellation/index.ts +75 -0
  48. package/src/constellation/listCatalog.tsx +35 -0
  49. package/src/constellation/listModel.tsx +41 -0
  50. package/src/constellation/listProject.tsx +28 -0
  51. package/src/constellation/listRuntime.tsx +28 -0
  52. package/src/constellation/options.ts +17 -0
  53. package/src/constellation/types.ts +17 -0
  54. package/src/constellation/uploadModel.tsx +64 -0
  55. package/src/constellation/utils.ts +90 -0
  56. package/src/create-worker-upload-form.ts +18 -1
  57. package/src/d1/backups.tsx +19 -15
  58. package/src/d1/create.tsx +45 -39
  59. package/src/d1/delete.ts +1 -1
  60. package/src/d1/execute.tsx +23 -20
  61. package/src/d1/list.tsx +14 -12
  62. package/src/d1/migrations/apply.tsx +36 -30
  63. package/src/d1/migrations/create.tsx +15 -12
  64. package/src/d1/migrations/helpers.ts +5 -8
  65. package/src/d1/migrations/list.tsx +10 -7
  66. package/src/deployments.ts +260 -8
  67. package/src/dev/dev.tsx +2 -0
  68. package/src/dev/local.tsx +48 -20
  69. package/src/dev/start-server.ts +49 -46
  70. package/src/dev/use-esbuild.ts +52 -49
  71. package/src/dev-registry.ts +2 -1
  72. package/src/dev.tsx +11 -5
  73. package/src/docs/helpers.ts +50 -0
  74. package/src/docs/index.ts +25 -68
  75. package/src/entry.ts +19 -8
  76. package/src/environment-variables/factory.ts +2 -1
  77. package/src/generate/index.ts +2 -2
  78. package/src/index.ts +86 -23
  79. package/src/init.ts +144 -135
  80. package/src/kv/helpers.ts +7 -4
  81. package/src/logger.ts +23 -4
  82. package/src/metrics/send-event.ts +2 -1
  83. package/src/miniflare-cli/index.ts +2 -2
  84. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  85. package/src/module-collection.ts +92 -26
  86. package/src/pages/build.ts +29 -17
  87. package/src/pages/deployments.tsx +3 -5
  88. package/src/pages/dev.ts +24 -6
  89. package/src/pages/functions/buildPlugin.ts +1 -0
  90. package/src/pages/functions/buildWorker.ts +59 -8
  91. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  92. package/src/pages/projects.tsx +2 -5
  93. package/src/pages/upload.tsx +24 -4
  94. package/src/publish/publish.ts +10 -26
  95. package/src/queues/cli/commands/consumer/add.ts +6 -0
  96. package/src/queues/client.ts +1 -0
  97. package/src/secret/index.ts +1 -0
  98. package/src/sites.ts +164 -52
  99. package/src/traverse-module-graph.ts +53 -0
  100. package/src/user/user.ts +1 -0
  101. package/src/utils/render.ts +93 -0
  102. package/src/worker.ts +10 -0
  103. package/wrangler-dist/cli.d.ts +29 -2
  104. package/wrangler-dist/cli.js +23270 -22110
  105. package/src/__tests__/api-devregistry.test.js +0 -64
@@ -1,9 +1,21 @@
1
1
  import { URLSearchParams } from "url";
2
+ import TOML from "@iarna/toml";
3
+ import chalk from "chalk";
4
+ import { FormData } from "undici";
2
5
  import { fetchResult } from "./cfetch";
6
+ import { readConfig } from "./config";
7
+ import { confirm, prompt } from "./dialogs";
8
+ import { mapBindings } from "./init";
3
9
  import { logger } from "./logger";
4
10
  import * as metrics from "./metrics";
11
+ import { requireAuth } from "./user";
12
+ import { getScriptName, printWranglerBanner } from ".";
13
+
5
14
  import type { Config } from "./config";
15
+ import type { WorkerMetadataBinding } from "./create-worker-upload-form";
6
16
  import type { ServiceMetadataRes } from "./init";
17
+ import type { CommonYargsOptions } from "./yargs-types";
18
+ import type { ArgumentsCamelCase } from "yargs";
7
19
 
8
20
  type DeploymentDetails = {
9
21
  id: string;
@@ -11,6 +23,7 @@ type DeploymentDetails = {
11
23
  annotations: {
12
24
  "workers/triggered_by": string;
13
25
  "workers/rollback_from": string;
26
+ "workers/message": string;
14
27
  };
15
28
  metadata: {
16
29
  author_id: string;
@@ -20,8 +33,15 @@ type DeploymentDetails = {
20
33
  modified_on: string;
21
34
  };
22
35
  resources: {
23
- script: string;
24
- bindings: unknown[];
36
+ script: {
37
+ handlers: string[];
38
+ };
39
+ bindings: WorkerMetadataBinding[];
40
+ script_runtime: {
41
+ compatibility_date: string | undefined;
42
+ compatibility_flags: string[] | undefined;
43
+ usage_model: string | undefined;
44
+ };
25
45
  };
26
46
  };
27
47
 
@@ -49,11 +69,12 @@ export async function deployments(
49
69
  }
50
70
  );
51
71
 
52
- const scriptMetadata = await fetchResult<ServiceMetadataRes>(
53
- `/accounts/${accountId}/workers/services/${scriptName}`
54
- );
72
+ const scriptTag = (
73
+ await fetchResult<ServiceMetadataRes>(
74
+ `/accounts/${accountId}/workers/services/${scriptName}`
75
+ )
76
+ ).default_environment.script.tag;
55
77
 
56
- const scriptTag = scriptMetadata.default_environment.script.tag;
57
78
  const params = new URLSearchParams({ order: "asc" });
58
79
  const { items: deploys } = await fetchResult<DeploymentListResult>(
59
80
  `/accounts/${accountId}/workers/deployments/by-script/${scriptTag}`,
@@ -72,12 +93,16 @@ export async function deployments(
72
93
  Deployment ID: ${versions.id}
73
94
  Created on: ${versions.metadata.created_on}
74
95
  Author: ${versions.metadata.author_email}
75
- Trigger: ${triggerStr}`;
96
+ Source: ${triggerStr}`;
76
97
 
77
98
  if (versions.annotations?.["workers/rollback_from"]) {
78
99
  version += `\nRollback from: ${versions.annotations["workers/rollback_from"]}`;
79
100
  }
80
101
 
102
+ if (versions.annotations?.["workers/message"]) {
103
+ version += `\nMessage: ${versions.annotations["workers/message"]}`;
104
+ }
105
+
81
106
  return version + `\n`;
82
107
  });
83
108
 
@@ -99,7 +124,6 @@ function formatSource(source: string): string {
99
124
  return "Other";
100
125
  }
101
126
  }
102
-
103
127
  function formatTrigger(trigger: string): string {
104
128
  switch (trigger) {
105
129
  case "upload":
@@ -114,3 +138,231 @@ function formatTrigger(trigger: string): string {
114
138
  return "Unknown";
115
139
  }
116
140
  }
141
+
142
+ export async function rollbackDeployment(
143
+ accountId: string,
144
+ scriptName: string | undefined,
145
+ { send_metrics: sendMetrics }: { send_metrics?: Config["send_metrics"] } = {},
146
+ deploymentId: string | undefined,
147
+ message: string | undefined
148
+ ) {
149
+ if (deploymentId === undefined) {
150
+ const scriptTag = (
151
+ await fetchResult<ServiceMetadataRes>(
152
+ `/accounts/${accountId}/workers/services/${scriptName}`
153
+ )
154
+ ).default_environment.script.tag;
155
+
156
+ const params = new URLSearchParams({ order: "asc" });
157
+ const { items: deploys } = await fetchResult<DeploymentListResult>(
158
+ `/accounts/${accountId}/workers/deployments/by-script/${scriptTag}`,
159
+ undefined,
160
+ params
161
+ );
162
+
163
+ if (deploys.length < 2) {
164
+ throw new Error(
165
+ "Cannot rollback to previous deployment since there are less than 2 deployemnts"
166
+ );
167
+ }
168
+
169
+ deploymentId = deploys.at(-2)?.id;
170
+ if (deploymentId === undefined) {
171
+ throw new Error("Cannot find previous deployment");
172
+ }
173
+ }
174
+
175
+ const firstHash = deploymentId.substring(0, deploymentId.indexOf("-"));
176
+
177
+ let rollbackMessage = "";
178
+ if (message !== undefined) {
179
+ rollbackMessage = message;
180
+ } else {
181
+ if (
182
+ !(await confirm(
183
+ `This deployment ${chalk.underline(
184
+ firstHash
185
+ )} will immediately replace the current deployment and become the active deployment across all your deployed routes and domains. However, your local development environment will not be affected by this rollback. ${chalk.blue.bold(
186
+ "Note:"
187
+ )} Rolling back to a previous deployment will not rollback any of the bound resources (Durable Object, R2, KV, etc.).`
188
+ ))
189
+ ) {
190
+ return;
191
+ }
192
+
193
+ rollbackMessage = await prompt(
194
+ "Please provide a message for this rollback (120 characters max)",
195
+ { defaultValue: "" }
196
+ );
197
+ }
198
+
199
+ let deployment_id = await rollbackRequest(
200
+ accountId,
201
+ scriptName,
202
+ deploymentId,
203
+ rollbackMessage
204
+ );
205
+
206
+ await metrics.sendMetricsEvent(
207
+ "rollback deployments",
208
+ { view: scriptName ? "single" : "all" },
209
+ {
210
+ sendMetrics,
211
+ }
212
+ );
213
+
214
+ deploymentId = addHyphens(deploymentId) ?? deploymentId;
215
+ deployment_id = addHyphens(deployment_id) ?? deployment_id;
216
+
217
+ logger.log(`\nSuccessfully rolled back to Deployment ID: ${deploymentId}`);
218
+ logger.log("Current Deployment ID:", deployment_id);
219
+ }
220
+
221
+ async function rollbackRequest(
222
+ accountId: string,
223
+ scriptName: string | undefined,
224
+ deploymentId: string,
225
+ rollbackReason: string
226
+ ): Promise<string | null> {
227
+ const body = new FormData();
228
+ body.set("message", rollbackReason);
229
+
230
+ const { deployment_id } = await fetchResult<{
231
+ deployment_id: string | null;
232
+ }>(
233
+ `/accounts/${accountId}/workers/scripts/${scriptName}?rollback_to=${deploymentId}`,
234
+ {
235
+ method: "PUT",
236
+ body,
237
+ }
238
+ );
239
+
240
+ return deployment_id;
241
+ }
242
+
243
+ export async function viewDeployment(
244
+ accountId: string,
245
+ scriptName: string | undefined,
246
+ { send_metrics: sendMetrics }: { send_metrics?: Config["send_metrics"] } = {},
247
+ deploymentId: string | undefined
248
+ ) {
249
+ await metrics.sendMetricsEvent(
250
+ "view deployments",
251
+ { view: scriptName ? "single" : "all" },
252
+ {
253
+ sendMetrics,
254
+ }
255
+ );
256
+
257
+ const scriptTag = (
258
+ await fetchResult<ServiceMetadataRes>(
259
+ `/accounts/${accountId}/workers/services/${scriptName}`
260
+ )
261
+ ).default_environment.script.tag;
262
+
263
+ if (deploymentId === undefined) {
264
+ const params = new URLSearchParams({ order: "asc" });
265
+ const { latest } = await fetchResult<DeploymentListResult>(
266
+ `/accounts/${accountId}/workers/deployments/by-script/${scriptTag}`,
267
+ undefined,
268
+ params
269
+ );
270
+
271
+ deploymentId = latest.id;
272
+ if (deploymentId === undefined) {
273
+ throw new Error("Cannot find previous deployment");
274
+ }
275
+ }
276
+
277
+ const deploymentDetails = await fetchResult<DeploymentListResult["latest"]>(
278
+ `/accounts/${accountId}/workers/deployments/by-script/${scriptTag}/detail/${deploymentId}`
279
+ );
280
+
281
+ const triggerStr = deploymentDetails.annotations?.["workers/triggered_by"]
282
+ ? `${formatTrigger(
283
+ deploymentDetails.annotations["workers/triggered_by"]
284
+ )} from ${formatSource(deploymentDetails.metadata.source)}`
285
+ : `${formatSource(deploymentDetails.metadata.source)}`;
286
+
287
+ const rollbackStr = deploymentDetails.annotations?.["workers/rollback_from"]
288
+ ? `\nRollback from: ${deploymentDetails.annotations["workers/rollback_from"]}`
289
+ : ``;
290
+
291
+ const reasonStr = deploymentDetails.annotations?.["workers/message"]
292
+ ? `\nMessage: ${deploymentDetails.annotations["workers/message"]}`
293
+ : ``;
294
+
295
+ const compatDateStr = deploymentDetails.resources.script_runtime
296
+ ?.compatibility_date
297
+ ? `\nCompatibility Date: ${deploymentDetails.resources.script_runtime?.compatibility_date}`
298
+ : ``;
299
+ const compatFlagsStr = deploymentDetails.resources.script_runtime
300
+ ?.compatibility_flags
301
+ ? `\nCompatibility Flags: ${deploymentDetails.resources.script_runtime?.compatibility_flags}`
302
+ : ``;
303
+
304
+ const bindings = deploymentDetails.resources.bindings;
305
+
306
+ const version = `
307
+ Deployment ID: ${deploymentDetails.id}
308
+ Created on: ${deploymentDetails.metadata.created_on}
309
+ Author: ${deploymentDetails.metadata.author_email}
310
+ Source: ${triggerStr}${rollbackStr}${reasonStr}
311
+ ------------------------------------------------------------
312
+ Author ID: ${deploymentDetails.metadata.author_id}
313
+ Usage Model: ${deploymentDetails.resources.script_runtime.usage_model}
314
+ Handlers: ${
315
+ deploymentDetails.resources.script.handlers
316
+ }${compatDateStr}${compatFlagsStr}
317
+ --------------------------bindings--------------------------
318
+ ${
319
+ bindings.length > 0
320
+ ? TOML.stringify(mapBindings(bindings) as TOML.JsonMap)
321
+ : `None`
322
+ }
323
+ `;
324
+
325
+ logger.log(version);
326
+
327
+ // early return to skip the deployments listings
328
+ return;
329
+ }
330
+
331
+ export async function commonDeploymentCMDSetup(
332
+ yargs: ArgumentsCamelCase<CommonYargsOptions>,
333
+ deploymentsWarning: string
334
+ ) {
335
+ await printWranglerBanner();
336
+ const config = readConfig(yargs.config, yargs);
337
+ const accountId = await requireAuth(config);
338
+ const scriptName = getScriptName(
339
+ { name: yargs.name as string, env: undefined },
340
+ config
341
+ );
342
+
343
+ logger.log(`${deploymentsWarning}\n`);
344
+
345
+ return { accountId, scriptName, config };
346
+ }
347
+
348
+ export function addHyphens(uuid: string | null): string | null {
349
+ if (uuid == null) {
350
+ return uuid;
351
+ }
352
+
353
+ if (uuid.length != 32) {
354
+ return null;
355
+ }
356
+
357
+ const uuid_parts: string[] = [];
358
+ uuid_parts.push(uuid.slice(0, 8));
359
+ uuid_parts.push(uuid.slice(8, 12));
360
+ uuid_parts.push(uuid.slice(12, 16));
361
+ uuid_parts.push(uuid.slice(16, 20));
362
+ uuid_parts.push(uuid.slice(20));
363
+
364
+ let hyphenated = "";
365
+ uuid_parts.forEach((part) => (hyphenated += part + "-"));
366
+
367
+ return hyphenated.slice(0, 36);
368
+ }
package/src/dev/dev.tsx CHANGED
@@ -116,6 +116,7 @@ export type DevProps = {
116
116
  initialPort: number;
117
117
  initialIp: string;
118
118
  inspectorPort: number;
119
+ processEntrypoint: boolean;
119
120
  rules: Config["rules"];
120
121
  accountId: string | undefined;
121
122
  initialMode: "local" | "remote";
@@ -271,6 +272,7 @@ function DevSession(props: DevSessionProps) {
271
272
  entry: props.entry,
272
273
  destination: directory,
273
274
  jsxFactory: props.jsxFactory,
275
+ processEntrypoint: props.processEntrypoint,
274
276
  rules: props.rules,
275
277
  jsxFragment: props.jsxFragment,
276
278
  serveAssetsFromWorker: Boolean(
package/src/dev/local.tsx CHANGED
@@ -695,6 +695,7 @@ export function setupMiniflareOptions({
695
695
  durableObjectsPersist: true,
696
696
  kvPersist: true,
697
697
  r2Persist: true,
698
+ d1Persist: true,
698
699
  }),
699
700
 
700
701
  liveReload,
@@ -792,6 +793,18 @@ export async function buildMiniflare3Logger(): Promise<Miniflare3LogType> {
792
793
  return logLevel === LogLevel.NONE ? new NoOpLog() : new Log(logLevel);
793
794
  }
794
795
 
796
+ function transformMf2PersistToMf3(persist?: boolean | string) {
797
+ // Wrangler reuses Miniflare 3 instances between reloads but not Miniflare 2
798
+ // ones. We previously set `*Persist` options to `true` by default to
799
+ // persist data between reloads in the temporary script directory (Miniflare
800
+ // 2's working directory). However, with Miniflare 3, the working directory
801
+ // is the current working directory, so we want to set these to `false`
802
+ // and use Miniflare 3's native in-memory persistence.
803
+ //
804
+ // See https://github.com/cloudflare/workers-sdk/issues/2995.
805
+ return persist === true ? false : persist;
806
+ }
807
+
795
808
  export async function transformMf2OptionsToMf3Options({
796
809
  miniflare2Options,
797
810
  format,
@@ -819,8 +832,9 @@ export async function transformMf2OptionsToMf3Options({
819
832
  };
820
833
  }
821
834
 
822
- const options: Miniflare3Options = {
835
+ let options: Partial<Miniflare3Options> = {
823
836
  ...miniflare2Options,
837
+
824
838
  // Miniflare 3 distinguishes between binding name and namespace/bucket IDs.
825
839
  kvNamespaces: Object.fromEntries(
826
840
  kvNamespaces?.map(({ binding, id }) => [binding, id]) ?? []
@@ -834,8 +848,17 @@ export async function transformMf2OptionsToMf3Options({
834
848
  preview_database_id ?? database_id,
835
849
  ]) ?? []
836
850
  ),
851
+
852
+ cachePersist: transformMf2PersistToMf3(miniflare2Options.cachePersist),
853
+ durableObjectsPersist: transformMf2PersistToMf3(
854
+ miniflare2Options.durableObjectsPersist
855
+ ),
856
+ kvPersist: transformMf2PersistToMf3(miniflare2Options.kvPersist),
857
+ r2Persist: transformMf2PersistToMf3(miniflare2Options.r2Persist),
858
+ d1Persist: transformMf2PersistToMf3(miniflare2Options.d1Persist),
859
+
837
860
  inspectorPort,
838
- verbose: true,
861
+ verbose: logger.loggerLevel === "debug",
839
862
  cloudflareFetch,
840
863
  log,
841
864
  };
@@ -873,22 +896,27 @@ export async function transformMf2OptionsToMf3Options({
873
896
  const root = path.dirname(bundle.path);
874
897
 
875
898
  assert.strictEqual(bundle.type, "esm");
876
- // Required for source mapped paths to resolve correctly
877
- options.modulesRoot = root;
878
- options.modules = [
879
- // Entrypoint
880
- {
881
- type: "ESModule",
882
- path: bundle.path,
883
- contents: await readFile(bundle.path, "utf-8"),
884
- },
885
- // Misc (WebAssembly, etc, ...)
886
- ...bundle.modules.map((module) => ({
887
- type: ModuleTypeToRuleType[module.type ?? "esm"],
888
- path: path.resolve(root, module.name),
889
- contents: module.content,
890
- })),
891
- ];
899
+ options = {
900
+ // Creating a new options object ensures types check (Miniflare's
901
+ // options type requires source code to be specified)
902
+ ...options,
903
+ // Required for source mapped paths to resolve correctly
904
+ modulesRoot: root,
905
+ modules: [
906
+ // Entrypoint
907
+ {
908
+ type: "ESModule",
909
+ path: bundle.path,
910
+ contents: await readFile(bundle.path, "utf-8"),
911
+ },
912
+ // Misc (WebAssembly, etc, ...)
913
+ ...bundle.modules.map((module) => ({
914
+ type: ModuleTypeToRuleType[module.type ?? "esm"],
915
+ path: path.resolve(root, module.name),
916
+ contents: module.content,
917
+ })),
918
+ ],
919
+ };
892
920
  }
893
921
 
894
922
  if (kvRemote) {
@@ -906,7 +934,7 @@ export async function transformMf2OptionsToMf3Options({
906
934
  options.kvPersist = `remote:?cache=${encodeURIComponent(kvRemoteCache)}`;
907
935
  }
908
936
 
909
- return options;
937
+ return options as Miniflare3Options;
910
938
  }
911
939
 
912
940
  // Caching of the `npx-import`ed `@miniflare/tre` package
@@ -916,5 +944,5 @@ export async function getMiniflare3(): Promise<
916
944
  // eslint-disable-next-line @typescript-eslint/consistent-type-imports
917
945
  typeof import("@miniflare/tre")
918
946
  > {
919
- return (miniflare3Module ??= await npxImport("@miniflare/tre@3.0.0-next.12"));
947
+ return (miniflare3Module ??= await npxImport("@miniflare/tre@3.0.0-next.13"));
920
948
  }
@@ -14,6 +14,7 @@ import {
14
14
  import { runCustomBuild } from "../entry";
15
15
  import { logger } from "../logger";
16
16
  import { waitForPortToBeAvailable } from "../proxy";
17
+ import traverseModuleGraph from "../traverse-module-graph";
17
18
  import {
18
19
  setupBindings,
19
20
  getMiniflare3,
@@ -91,6 +92,7 @@ export async function startDevServer(
91
92
  entry: props.entry,
92
93
  destination: directory.name,
93
94
  jsxFactory: props.jsxFactory,
95
+ processEntrypoint: props.processEntrypoint,
94
96
  rules: props.rules,
95
97
  jsxFragment: props.jsxFragment,
96
98
  serveAssetsFromWorker: Boolean(
@@ -204,6 +206,7 @@ async function runEsbuild({
204
206
  destination,
205
207
  jsxFactory,
206
208
  jsxFragment,
209
+ processEntrypoint,
207
210
  rules,
208
211
  assets,
209
212
  betaD1Shims,
@@ -226,6 +229,7 @@ async function runEsbuild({
226
229
  destination: string | undefined;
227
230
  jsxFactory: string | undefined;
228
231
  jsxFragment: string | undefined;
232
+ processEntrypoint: boolean;
229
233
  rules: Config["rules"];
230
234
  assets: Config["assets"];
231
235
  betaD1Shims?: string[];
@@ -246,56 +250,55 @@ async function runEsbuild({
246
250
  }): Promise<EsbuildBundle | undefined> {
247
251
  if (!destination) return;
248
252
 
249
- const {
250
- resolvedEntryPointPath,
251
- bundleType,
252
- modules,
253
- dependencies,
254
- sourceMapPath,
255
- }: Awaited<ReturnType<typeof bundleWorker>> = noBundle
256
- ? {
257
- modules: [],
258
- dependencies: {},
259
- resolvedEntryPointPath: entry.file,
260
- bundleType: entry.format === "modules" ? "esm" : "commonjs",
261
- stop: undefined,
262
- sourceMapPath: undefined,
263
- }
264
- : await bundleWorker(entry, destination, {
265
- serveAssetsFromWorker,
266
- jsxFactory,
267
- jsxFragment,
268
- rules,
269
- tsconfig,
270
- minify,
271
- legacyNodeCompat,
272
- nodejsCompat,
273
- define,
274
- checkFetch: true,
275
- assets: assets && {
276
- ...assets,
277
- // disable the cache in dev
278
- bypassCache: true,
279
- },
280
- betaD1Shims,
281
- workerDefinitions,
282
- services,
283
- firstPartyWorkerDevFacade,
284
- targetConsumer: "dev", // We are starting a dev server
285
- testScheduled,
286
- local,
287
- experimentalLocal,
288
- doBindings,
289
- });
253
+ let traverseModuleGraphResult:
254
+ | Awaited<ReturnType<typeof bundleWorker>>
255
+ | undefined;
256
+ let bundleResult: Awaited<ReturnType<typeof bundleWorker>> | undefined;
257
+ if (noBundle) {
258
+ traverseModuleGraphResult = await traverseModuleGraph(entry, rules);
259
+ }
260
+
261
+ if (processEntrypoint || !noBundle) {
262
+ bundleResult = await bundleWorker(entry, destination, {
263
+ bundle: !noBundle,
264
+ disableModuleCollection: noBundle,
265
+ serveAssetsFromWorker,
266
+ jsxFactory,
267
+ jsxFragment,
268
+ rules,
269
+ tsconfig,
270
+ minify,
271
+ legacyNodeCompat,
272
+ nodejsCompat,
273
+ define,
274
+ checkFetch: true,
275
+ assets: assets && {
276
+ ...assets,
277
+ // disable the cache in dev
278
+ bypassCache: true,
279
+ },
280
+ betaD1Shims,
281
+ workerDefinitions,
282
+ services,
283
+ firstPartyWorkerDevFacade,
284
+ targetConsumer: "dev", // We are starting a dev server
285
+ testScheduled,
286
+ local,
287
+ experimentalLocal,
288
+ doBindings,
289
+ });
290
+ }
290
291
 
291
292
  return {
292
293
  id: 0,
293
294
  entry,
294
- path: resolvedEntryPointPath,
295
- type: bundleType,
296
- modules,
297
- dependencies,
298
- sourceMapPath,
295
+ path: bundleResult?.resolvedEntryPointPath ?? entry.file,
296
+ type:
297
+ bundleResult?.bundleType ??
298
+ (entry.format === "modules" ? "esm" : "commonjs"),
299
+ modules: traverseModuleGraphResult?.modules ?? bundleResult?.modules ?? [],
300
+ dependencies: bundleResult?.dependencies ?? {},
301
+ sourceMapPath: bundleResult?.sourceMapPath,
299
302
  };
300
303
  }
301
304