wrangler 0.0.0-e6e1daba → 0.0.0-e7cf0caa

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 (101) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/miniflare-dist/index.mjs +1 -1
  3. package/package.json +14 -9
  4. package/src/__tests__/api-devregistry.test.ts +121 -0
  5. package/src/__tests__/api.test.ts +27 -5
  6. package/src/__tests__/configuration.test.ts +294 -18
  7. package/src/__tests__/d1/execute.test.ts +3 -1
  8. package/src/__tests__/d1/migrate.test.ts +2 -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 +87 -57
  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 +10 -4
  18. package/src/__tests__/init.test.ts +136 -104
  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 +4 -3
  24. package/src/__tests__/mtls-certificates.test.ts +5 -2
  25. package/src/__tests__/pages/deployment-list.test.ts +2 -0
  26. package/src/__tests__/pages/functions-build.test.ts +91 -41
  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 +267 -148
  30. package/src/__tests__/publish.test.ts +420 -164
  31. package/src/__tests__/pubsub.test.ts +3 -0
  32. package/src/__tests__/queues.test.ts +5 -2
  33. package/src/__tests__/test-old-node-version.js +3 -3
  34. package/src/__tests__/traverse-module-graph.test.ts +220 -0
  35. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  36. package/src/__tests__/type-generation.test.ts +1 -0
  37. package/src/__tests__/user.test.ts +1 -1
  38. package/src/__tests__/worker-namespace.test.ts +1 -0
  39. package/src/api/dev.ts +10 -22
  40. package/src/api/pages/create-worker-bundle-contents.ts +1 -0
  41. package/src/api/pages/publish.tsx +38 -51
  42. package/src/bundle.ts +44 -13
  43. package/src/config/environment.ts +36 -4
  44. package/src/config/index.ts +30 -2
  45. package/src/config/validation-helpers.ts +1 -1
  46. package/src/config/validation.ts +149 -5
  47. package/src/create-worker-upload-form.ts +28 -3
  48. package/src/d1/backups.tsx +15 -11
  49. package/src/d1/create.tsx +20 -16
  50. package/src/d1/execute.tsx +22 -19
  51. package/src/d1/list.tsx +2 -2
  52. package/src/d1/migrations/apply.tsx +35 -29
  53. package/src/d1/migrations/create.tsx +15 -12
  54. package/src/d1/migrations/list.tsx +10 -7
  55. package/src/deployments.ts +260 -8
  56. package/src/dev/dev.tsx +4 -4
  57. package/src/dev/local.tsx +14 -16
  58. package/src/dev/start-server.ts +12 -16
  59. package/src/dev/use-esbuild.ts +11 -13
  60. package/src/dev/validate-dev-props.ts +9 -0
  61. package/src/dev-registry.ts +2 -1
  62. package/src/dev.tsx +28 -13
  63. package/src/entry.ts +18 -8
  64. package/src/generate/index.ts +2 -2
  65. package/src/index.ts +76 -23
  66. package/src/init.ts +144 -134
  67. package/src/logger.ts +18 -3
  68. package/src/metrics/send-event.ts +2 -1
  69. package/src/miniflare-cli/index.ts +1 -1
  70. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  71. package/src/module-collection.ts +91 -25
  72. package/src/pages/build.ts +277 -99
  73. package/src/pages/buildFunctions.ts +20 -10
  74. package/src/pages/deployments.tsx +3 -5
  75. package/src/pages/dev.ts +21 -21
  76. package/src/pages/errors.ts +1 -0
  77. package/src/pages/functions/buildPlugin.ts +57 -34
  78. package/src/pages/functions/buildWorker.ts +34 -31
  79. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  80. package/src/pages/projects.tsx +2 -5
  81. package/src/pages/publish.tsx +1 -10
  82. package/src/pages/upload.tsx +29 -9
  83. package/src/paths.ts +1 -1
  84. package/src/publish/index.ts +1 -1
  85. package/src/publish/publish.ts +29 -34
  86. package/src/queues/cli/commands/consumer/add.ts +6 -0
  87. package/src/queues/client.ts +1 -0
  88. package/src/secret/index.ts +2 -1
  89. package/src/traverse-module-graph.ts +53 -0
  90. package/src/type-generation.ts +1 -1
  91. package/src/user/user.ts +1 -1
  92. package/src/utils/render.ts +93 -0
  93. package/src/worker.ts +18 -1
  94. package/templates/d1-beta-facade.js +5 -2
  95. package/templates/gitignore +1 -0
  96. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  97. package/templates/tsconfig.init.json +1 -2
  98. package/templates/tsconfig.tsbuildinfo +1 -1
  99. package/wrangler-dist/cli.d.ts +33 -13
  100. package/wrangler-dist/cli.js +20732 -19984
  101. package/src/__tests__/api-devregistry.test.js +0 -64
@@ -1,22 +1,22 @@
1
- /* eslint-disable no-shadow */
2
1
  import { Blob } from "node:buffer";
3
2
  import { mkdirSync, writeFileSync } from "node:fs";
4
3
  import { chdir } from "node:process";
5
4
  import { MockedRequest, rest } from "msw";
6
5
  import { FormData } from "undici";
6
+ import { version } from "../../../package.json";
7
+ import { ROUTES_SPEC_VERSION } from "../../pages/constants";
8
+ import { isRoutesJSONSpec } from "../../pages/functions/routes-validation";
9
+ import { endEventLoop } from "../helpers/end-event-loop";
10
+ import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
7
11
  import { mockConsoleMethods } from "../helpers/mock-console";
8
12
  import { mockGetUploadTokenRequest } from "../helpers/mock-get-pages-upload-token";
9
13
  import { mockSetTimeout } from "../helpers/mock-set-timeout";
10
- import { version } from "./../../../package.json";
11
- import { ROUTES_SPEC_VERSION } from "./../../pages/constants";
12
- import { isRoutesJSONSpec } from "./../../pages/functions/routes-validation";
13
- import { endEventLoop } from "./../helpers/end-event-loop";
14
- import { mockAccountId, mockApiToken } from "./../helpers/mock-account-id";
15
- import { msw } from "./../helpers/msw";
16
- import { FileReaderSync } from "./../helpers/msw/read-file-sync";
17
- import { runInTempDir } from "./../helpers/run-in-tmp";
18
- import { runWrangler } from "./../helpers/run-wrangler";
19
- import type { Project, UploadPayloadFile } from "./../../pages/types";
14
+ import { msw } from "../helpers/msw";
15
+ import { FileReaderSync } from "../helpers/msw/read-file-sync";
16
+ import { runInTempDir } from "../helpers/run-in-tmp";
17
+ import { runWrangler } from "../helpers/run-wrangler";
18
+ import { normalizeProgressSteps } from "./project-upload.test";
19
+ import type { Project, UploadPayloadFile } from "../../pages/types";
20
20
  import type { RestRequest } from "msw";
21
21
 
22
22
  describe("deployment create", () => {
@@ -69,7 +69,7 @@ describe("deployment create", () => {
69
69
  --commit-message The commit message to attach to this deployment [string]
70
70
  --commit-dirty Whether or not the workspace should be considered dirty for this deployment [boolean]
71
71
  --skip-caching Skip asset caching which speeds up builds [boolean]
72
- --no-bundle Whether to run bundling on \`_worker.js\` before deploying [boolean] [default: true]
72
+ --no-bundle Whether to run bundling on \`_worker.js\` before deploying [boolean] [default: false]
73
73
 
74
74
  🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose"
75
75
  `);
@@ -171,11 +171,11 @@ describe("deployment create", () => {
171
171
 
172
172
  await runWrangler("pages publish . --project-name=foo");
173
173
 
174
- expect(std.out).toMatchInlineSnapshot(`
175
- "✨ Success! Uploaded 1 files (TIMINGS)
174
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
175
+ "✨ Success! Uploaded 1 files (TIMINGS)
176
176
 
177
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
178
- `);
177
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
178
+ `);
179
179
  });
180
180
 
181
181
  it("should retry uploads", async () => {
@@ -300,11 +300,11 @@ describe("deployment create", () => {
300
300
 
301
301
  await runWrangler("pages publish . --project-name=foo");
302
302
 
303
- expect(std.out).toMatchInlineSnapshot(`
304
- "✨ Success! Uploaded 1 files (TIMINGS)
303
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
304
+ "✨ Success! Uploaded 1 files (TIMINGS)
305
305
 
306
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
307
- `);
306
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
307
+ `);
308
308
  });
309
309
 
310
310
  it("should refetch a JWT if it expires while uploading", async () => {
@@ -437,11 +437,11 @@ describe("deployment create", () => {
437
437
  "Bearer <<funfetti-auth-jwt2>>"
438
438
  );
439
439
 
440
- expect(std.out).toMatchInlineSnapshot(`
441
- "✨ Success! Uploaded 1 files (TIMINGS)
440
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
441
+ "✨ Success! Uploaded 1 files (TIMINGS)
442
442
 
443
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
444
- `);
443
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
444
+ `);
445
445
  });
446
446
 
447
447
  it("should try to use multiple buckets (up to the max concurrency)", async () => {
@@ -592,11 +592,11 @@ describe("deployment create", () => {
592
592
  ])
593
593
  );
594
594
 
595
- expect(std.out).toMatchInlineSnapshot(`
596
- "✨ Success! Uploaded 4 files (TIMINGS)
595
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
596
+ "✨ Success! Uploaded 4 files (TIMINGS)
597
597
 
598
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
599
- `);
598
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
599
+ `);
600
600
  });
601
601
 
602
602
  it("should resolve child directories correctly", async () => {
@@ -744,11 +744,11 @@ describe("deployment create", () => {
744
744
  ])
745
745
  );
746
746
 
747
- expect(std.out).toMatchInlineSnapshot(`
748
- "✨ Success! Uploaded 4 files (TIMINGS)
747
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
748
+ "✨ Success! Uploaded 4 files (TIMINGS)
749
749
 
750
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
751
- `);
750
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
751
+ `);
752
752
  });
753
753
 
754
754
  it("should resolve the current directory correctly", async () => {
@@ -897,11 +897,11 @@ describe("deployment create", () => {
897
897
  ])
898
898
  );
899
899
 
900
- expect(std.out).toMatchInlineSnapshot(`
901
- "✨ Success! Uploaded 4 files (TIMINGS)
900
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
901
+ "✨ Success! Uploaded 4 files (TIMINGS)
902
902
 
903
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
904
- `);
903
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
904
+ `);
905
905
  });
906
906
 
907
907
  it("should not error when directory names contain periods and houses a extensionless file", async () => {
@@ -1116,10 +1116,10 @@ describe("deployment create", () => {
1116
1116
  const body = await (req as RestRequestWithFormData).formData();
1117
1117
  const manifest = JSON.parse(body.get("manifest") as string);
1118
1118
 
1119
- // for Functions projects, we auto-generate a `_worker.js`,
1119
+ // for Functions projects, we auto-generate a `_worker.bundle`,
1120
1120
  // `functions-filepath-routing-config.json`, and `_routes.json`
1121
1121
  // file, based on the contents of `/functions`
1122
- const generatedWorkerJS = body.get("_worker.js") as string;
1122
+ const generatedWorkerBundle = body.get("_worker.bundle") as string;
1123
1123
  const generatedRoutesJSON = body.get("_routes.json") as string;
1124
1124
  const generatedFilepathRoutingConfig = body.get(
1125
1125
  "functions-filepath-routing-config.json"
@@ -1129,7 +1129,7 @@ describe("deployment create", () => {
1129
1129
  expect([...body.keys()]).toEqual([
1130
1130
  "manifest",
1131
1131
  "functions-filepath-routing-config.json",
1132
- "_worker.js",
1132
+ "_worker.bundle",
1133
1133
  "_routes.json",
1134
1134
  ]);
1135
1135
 
@@ -1139,14 +1139,14 @@ describe("deployment create", () => {
1139
1139
  }
1140
1140
  `);
1141
1141
 
1142
- // the contents of the generated `_worker.js` file is pretty massive, so I don't
1142
+ // the contents of the generated `_worker.bundle` file is pretty massive, so I don't
1143
1143
  // think snapshot testing makes much sense here. Plus, calling
1144
1144
  // `.toMatchInlineSnapshot()` without any arguments, in order to generate that
1145
1145
  // snapshot value, doesn't generate anything in this case (probably because the
1146
- // file contents is too big). So for now, let's test that _worker.js was indeed
1146
+ // file contents is too big). So for now, let's test that _worker.bundle was indeed
1147
1147
  // generated and that the file size is greater than zero
1148
- expect(generatedWorkerJS).not.toBeNull();
1149
- expect(generatedWorkerJS.length).toBeGreaterThan(0);
1148
+ expect(generatedWorkerBundle).not.toBeNull();
1149
+ expect(generatedWorkerBundle.length).toBeGreaterThan(0);
1150
1150
 
1151
1151
  const maybeRoutesJSONSpec = JSON.parse(generatedRoutesJSON);
1152
1152
  expect(isRoutesJSONSpec(maybeRoutesJSONSpec)).toBe(true);
@@ -1211,13 +1211,13 @@ describe("deployment create", () => {
1211
1211
 
1212
1212
  await runWrangler("pages publish public --project-name=foo");
1213
1213
 
1214
- expect(std.out).toMatchInlineSnapshot(`
1215
- "✨ Compiled Worker successfully
1216
- ✨ Success! Uploaded 1 files (TIMINGS)
1214
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
1215
+ "✨ Compiled Worker successfully
1216
+ ✨ Success! Uploaded 1 files (TIMINGS)
1217
1217
 
1218
- ✨ Uploading Functions
1219
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
1220
- `);
1218
+ ✨ Uploading Functions bundle
1219
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
1220
+ `);
1221
1221
 
1222
1222
  expect(std.err).toMatchInlineSnapshot('""');
1223
1223
  });
@@ -1301,11 +1301,11 @@ describe("deployment create", () => {
1301
1301
  expect(req.params.accountId).toEqual("some-account-id");
1302
1302
  const body = await (req as RestRequestWithFormData).formData();
1303
1303
  const manifest = JSON.parse(body.get("manifest") as string);
1304
- const customWorkerJS = body.get("_worker.js");
1304
+ const workerBundle = body.get("_worker.bundle");
1305
1305
 
1306
1306
  // make sure this is all we uploaded
1307
1307
  expect([...body.keys()].sort()).toEqual(
1308
- ["manifest", "_worker.js"].sort()
1308
+ ["manifest", "_worker.bundle"].sort()
1309
1309
  );
1310
1310
 
1311
1311
  expect(manifest).toMatchInlineSnapshot(`
@@ -1314,8 +1314,8 @@ describe("deployment create", () => {
1314
1314
  }
1315
1315
  `);
1316
1316
 
1317
- expect(workerHasD1Shim(customWorkerJS as string)).toBeTruthy();
1318
- expect(customWorkerJS).toContain(
1317
+ expect(workerHasD1Shim(workerBundle as string)).toBeTruthy();
1318
+ expect(workerBundle).toContain(
1319
1319
  `console.log("SOMETHING FROM WITHIN THE WORKER");`
1320
1320
  );
1321
1321
 
@@ -1359,15 +1359,15 @@ describe("deployment create", () => {
1359
1359
  )
1360
1360
  );
1361
1361
 
1362
- await runWrangler("pages publish public --project-name=foo --bundle");
1362
+ await runWrangler("pages publish public --project-name=foo");
1363
1363
 
1364
- expect(std.out).toMatchInlineSnapshot(`
1365
- "✨ Success! Uploaded 1 files (TIMINGS)
1364
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
1365
+ "✨ Success! Uploaded 1 files (TIMINGS)
1366
1366
 
1367
- ✨ Compiled Worker successfully
1368
- ✨ Uploading _worker.js
1369
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
1370
- `);
1367
+ ✨ Compiled Worker successfully
1368
+ ✨ Uploading Worker bundle
1369
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
1370
+ `);
1371
1371
 
1372
1372
  expect(std.err).toMatchInlineSnapshot('""');
1373
1373
  });
@@ -1489,7 +1489,7 @@ describe("deployment create", () => {
1489
1489
  expect(req.params.accountId).toEqual("some-account-id");
1490
1490
  const body = await (req as RestRequestWithFormData).formData();
1491
1491
  const manifest = JSON.parse(body.get("manifest") as string);
1492
- const generatedWorkerJS = body.get("_worker.js") as string;
1492
+ const generatedWorkerBundle = body.get("_worker.bundle") as string;
1493
1493
  const customRoutesJSON = body.get("_routes.json") as string;
1494
1494
  const generatedFilepathRoutingConfig = body.get(
1495
1495
  "functions-filepath-routing-config.json"
@@ -1500,7 +1500,7 @@ describe("deployment create", () => {
1500
1500
  [
1501
1501
  "manifest",
1502
1502
  "functions-filepath-routing-config.json",
1503
- "_worker.js",
1503
+ "_worker.bundle",
1504
1504
  "_routes.json",
1505
1505
  ].sort()
1506
1506
  );
@@ -1511,9 +1511,9 @@ describe("deployment create", () => {
1511
1511
  }
1512
1512
  `);
1513
1513
 
1514
- // file content of generated `_worker.js` is too massive to snapshot test
1515
- expect(generatedWorkerJS).not.toBeNull();
1516
- expect(generatedWorkerJS.length).toBeGreaterThan(0);
1514
+ // file content of generated `_worker.bundle` is too massive to snapshot test
1515
+ expect(generatedWorkerBundle).not.toBeNull();
1516
+ expect(generatedWorkerBundle.length).toBeGreaterThan(0);
1517
1517
 
1518
1518
  const customRoutes = JSON.parse(customRoutesJSON);
1519
1519
  expect(customRoutes).toMatchObject({
@@ -1583,14 +1583,14 @@ describe("deployment create", () => {
1583
1583
 
1584
1584
  await runWrangler("pages publish public --project-name=foo");
1585
1585
 
1586
- expect(std.out).toMatchInlineSnapshot(`
1587
- "✨ Compiled Worker successfully
1588
- ✨ Success! Uploaded 1 files (TIMINGS)
1586
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
1587
+ "✨ Compiled Worker successfully
1588
+ ✨ Success! Uploaded 1 files (TIMINGS)
1589
1589
 
1590
- ✨ Uploading Functions
1591
- ✨ Uploading _routes.json
1592
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
1593
- `);
1590
+ ✨ Uploading Functions bundle
1591
+ ✨ Uploading _routes.json
1592
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
1593
+ `);
1594
1594
 
1595
1595
  expect(std.warn).toMatchInlineSnapshot(`""`);
1596
1596
  expect(std.err).toMatchInlineSnapshot('""');
@@ -1821,13 +1821,13 @@ and that at least one include rule is provided.
1821
1821
  const body = await (req as RestRequestWithFormData).formData();
1822
1822
 
1823
1823
  const manifest = JSON.parse(body.get("manifest") as string);
1824
- const customWorkerJS = body.get("_worker.js") as string;
1824
+ const workerBundle = body.get("_worker.bundle") as string;
1825
1825
  const customRoutesJSON = body.get("_routes.json") as string;
1826
1826
 
1827
1827
  // make sure this is all we uploaded
1828
1828
  expect([...body.keys()]).toEqual([
1829
1829
  "manifest",
1830
- "_worker.js",
1830
+ "_worker.bundle",
1831
1831
  "_routes.json",
1832
1832
  ]);
1833
1833
  expect(req.params.accountId).toEqual("some-account-id");
@@ -1837,15 +1837,45 @@ and that at least one include rule is provided.
1837
1837
  }
1838
1838
  `);
1839
1839
 
1840
- expect(customWorkerJS).toMatchInlineSnapshot(`
1841
- "
1842
- export default {
1843
- async fetch(request, env) {
1844
- const url = new URL(request.url);
1845
- return url.pathname.startsWith('/api/') ? new Response('Ok') : env.ASSETS.fetch(request);
1846
- }
1847
- };
1848
- "
1840
+ // some fields in workerBundle, such as the undici form boundary
1841
+ // or the file hashes, are randomly generated. Let's replace these
1842
+ // dynamic values with static ones so we can properly test the
1843
+ // contents of `workerBundle`
1844
+ // see https://jestjs.io/docs/snapshot-testing#property-matchers
1845
+ let workerBundleWithConstantData = workerBundle.replace(
1846
+ /------formdata-undici-0.[0-9]*/g,
1847
+ "------formdata-undici-0.test"
1848
+ );
1849
+ workerBundleWithConstantData = workerBundleWithConstantData.replace(
1850
+ /bundledWorker-0.[0-9]*.mjs/g,
1851
+ "bundledWorker-0.test.mjs"
1852
+ );
1853
+
1854
+ // we care about a couple of things here, like the presence of `metadata`,
1855
+ // `bundledWorker`, the wasm import, etc., and since `workerBundle` is
1856
+ // small enough, let's go ahead and snapshot test the whole thing
1857
+ expect(workerBundleWithConstantData).toMatchInlineSnapshot(`
1858
+ "------formdata-undici-0.test
1859
+ Content-Disposition: form-data; name=\\"metadata\\"
1860
+
1861
+ {\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
1862
+ ------formdata-undici-0.test
1863
+ Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
1864
+ Content-Type: application/javascript+module
1865
+
1866
+ // _worker.js
1867
+ var worker_default = {
1868
+ async fetch(request, env) {
1869
+ const url = new URL(request.url);
1870
+ return url.pathname.startsWith(\\"/api/\\") ? new Response(\\"Ok\\") : env.ASSETS.fetch(request);
1871
+ }
1872
+ };
1873
+ export {
1874
+ worker_default as default
1875
+ };
1876
+ //# sourceMappingURL=bundledWorker-0.test.mjs.map
1877
+
1878
+ ------formdata-undici-0.test--"
1849
1879
  `);
1850
1880
 
1851
1881
  expect(JSON.parse(customRoutesJSON)).toMatchObject({
@@ -1890,14 +1920,14 @@ and that at least one include rule is provided.
1890
1920
 
1891
1921
  await runWrangler("pages publish public --project-name=foo");
1892
1922
 
1893
- expect(std.out).toMatchInlineSnapshot(`
1894
- "✨ Success! Uploaded 1 files (TIMINGS)
1923
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
1924
+ "✨ Success! Uploaded 1 files (TIMINGS)
1895
1925
 
1896
- ✨ Compiled Worker successfully
1897
- ✨ Uploading _worker.js
1898
- ✨ Uploading _routes.json
1899
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
1900
- `);
1926
+ ✨ Compiled Worker successfully
1927
+ ✨ Uploading Worker bundle
1928
+ ✨ Uploading _routes.json
1929
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
1930
+ `);
1901
1931
 
1902
1932
  expect(std.warn).toMatchInlineSnapshot(`""`);
1903
1933
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -2110,27 +2140,58 @@ and that at least one include rule is provided.
2110
2140
  async (req, res, ctx) => {
2111
2141
  const body = await (req as RestRequestWithFormData).formData();
2112
2142
  const manifest = JSON.parse(body.get("manifest") as string);
2113
- const customWorkerJS = body.get("_worker.js");
2143
+ const customWorkerBundle = body.get("_worker.bundle") as string;
2114
2144
 
2115
2145
  expect(req.params.accountId).toEqual("some-account-id");
2116
2146
  // make sure this is all we uploaded
2117
2147
  expect([...body.keys()].sort()).toEqual(
2118
- ["manifest", "_worker.js"].sort()
2148
+ ["manifest", "_worker.bundle"].sort()
2119
2149
  );
2120
2150
  expect(manifest).toMatchInlineSnapshot(`
2121
2151
  Object {
2122
2152
  "/README.md": "13a03eaf24ae98378acd36ea00f77f2f",
2123
2153
  }
2124
2154
  `);
2125
- expect(customWorkerJS).toMatchInlineSnapshot(`
2126
- "
2127
- export default {
2128
- async fetch(request, env) {
2129
- const url = new URL(request.url);
2130
- return url.pathname.startsWith('/api/') ? new Response('Ok') : env.ASSETS.fetch(request);
2131
- }
2132
- };
2133
- "
2155
+
2156
+ // some fields in workerBundle, such as the undici form boundary
2157
+ // or the file hashes, are randomly generated. Let's replace these
2158
+ // dynamic values with static ones so we can properly test the
2159
+ // contents of `workerBundle`
2160
+ // see https://jestjs.io/docs/snapshot-testing#property-matchers
2161
+ let workerBundleWithConstantData = customWorkerBundle.replace(
2162
+ /------formdata-undici-0.[0-9]*/g,
2163
+ "------formdata-undici-0.test"
2164
+ );
2165
+ workerBundleWithConstantData = workerBundleWithConstantData.replace(
2166
+ /bundledWorker-0.[0-9]*.mjs/g,
2167
+ "bundledWorker-0.test.mjs"
2168
+ );
2169
+
2170
+ // we care about a couple of things here, like the presence of `metadata`,
2171
+ // `bundledWorker`, the wasm import, etc., and since `workerBundle` is
2172
+ // small enough, let's go ahead and snapshot test the whole thing
2173
+ expect(workerBundleWithConstantData).toMatchInlineSnapshot(`
2174
+ "------formdata-undici-0.test
2175
+ Content-Disposition: form-data; name=\\"metadata\\"
2176
+
2177
+ {\\"main_module\\":\\"bundledWorker-0.test.mjs\\"}
2178
+ ------formdata-undici-0.test
2179
+ Content-Disposition: form-data; name=\\"bundledWorker-0.test.mjs\\"; filename=\\"bundledWorker-0.test.mjs\\"
2180
+ Content-Type: application/javascript+module
2181
+
2182
+ // _worker.js
2183
+ var worker_default = {
2184
+ async fetch(request, env) {
2185
+ const url = new URL(request.url);
2186
+ return url.pathname.startsWith(\\"/api/\\") ? new Response(\\"Ok\\") : env.ASSETS.fetch(request);
2187
+ }
2188
+ };
2189
+ export {
2190
+ worker_default as default
2191
+ };
2192
+ //# sourceMappingURL=bundledWorker-0.test.mjs.map
2193
+
2194
+ ------formdata-undici-0.test--"
2134
2195
  `);
2135
2196
 
2136
2197
  return res.once(
@@ -2168,36 +2229,38 @@ and that at least one include rule is provided.
2168
2229
 
2169
2230
  await runWrangler("pages publish public --project-name=foo");
2170
2231
 
2171
- expect(std.out).toMatchInlineSnapshot(`
2172
- "✨ Success! Uploaded 1 files (TIMINGS)
2232
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
2233
+ "✨ Success! Uploaded 1 files (TIMINGS)
2173
2234
 
2174
- ✨ Compiled Worker successfully
2175
- ✨ Uploading _worker.js
2176
- ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
2177
- `);
2235
+ ✨ Compiled Worker successfully
2236
+ ✨ Uploading Worker bundle
2237
+ ✨ Deployment complete! Take a peek over at https://abcxyz.foo.pages.dev/"
2238
+ `);
2178
2239
 
2179
2240
  expect(std.err).toMatchInlineSnapshot('""');
2180
2241
  });
2181
2242
 
2182
- it("should bundle Functions and resolve its external module imports if the `--experimental-worker-bundle` flag is set", async () => {
2243
+ it("should bundle Functions and resolve its external module imports", async () => {
2183
2244
  // set up the directory of static files to upload.
2184
2245
  mkdirSync("public");
2185
2246
  writeFileSync("public/README.md", "This is a readme");
2186
2247
 
2187
- // set up hello.wasm
2188
- mkdirSync("wasm");
2189
- writeFileSync("wasm/hello.wasm", "HELLO WORLD");
2248
+ // set up some "external" modules
2249
+ mkdirSync("external");
2250
+ writeFileSync("external/hello.wasm", "Hello Wasm modules world!");
2251
+ writeFileSync("external/hello.txt", "Hello Text modules world!");
2190
2252
 
2191
2253
  // set up Functions
2192
2254
  mkdirSync("functions");
2193
2255
  writeFileSync(
2194
2256
  "functions/hello.js",
2195
2257
  `
2196
- import hello from "./../wasm/hello.wasm";
2258
+ import wasm from "./../external/hello.wasm";
2259
+ import text from "./../external/hello.txt"
2197
2260
  export async function onRequest() {
2198
- const helloModule = await WebAssembly.instantiate(hello);
2199
- const greeting = helloModule.exports.hello;
2200
- return new Response(greeting);
2261
+ const helloModule = await WebAssembly.instantiate(wasm);
2262
+ const wasmGreeting = helloModule.exports.hello;
2263
+ return new Response(wasmGreeting + text);
2201
2264
  }
2202
2265
  `
2203
2266
  );
@@ -2302,6 +2365,10 @@ and that at least one include rule is provided.
2302
2365
  /[0-9a-z]*-hello.wasm/g,
2303
2366
  "test-hello.wasm"
2304
2367
  );
2368
+ workerBundleWithConstantData = workerBundleWithConstantData.replace(
2369
+ /[0-9a-z]*-hello.txt/g,
2370
+ "test-hello.txt"
2371
+ );
2305
2372
 
2306
2373
  // check we appended the metadata
2307
2374
  expect(workerBundleWithConstantData).toContain(
@@ -2316,18 +2383,29 @@ and that at least one include rule is provided.
2316
2383
  `Content-Disposition: form-data; name="functionsWorker-0.test.js"; filename="functionsWorker-0.test.js"`
2317
2384
  );
2318
2385
  expect(workerBundleWithConstantData).toContain(`
2319
- import hello from "./test-hello.wasm";
2386
+ import wasm from "./test-hello.wasm";
2387
+ import text from "./test-hello.txt";
2320
2388
  async function onRequest() {
2321
- const helloModule = await WebAssembly.instantiate(hello);
2322
- const greeting = helloModule.exports.hello;
2323
- return new Response(greeting);
2389
+ const helloModule = await WebAssembly.instantiate(wasm);
2390
+ const wasmGreeting = helloModule.exports.hello;
2391
+ return new Response(wasmGreeting + text);
2324
2392
  }`);
2325
2393
 
2326
2394
  // check we appended the wasm module
2327
2395
  expect(workerBundleWithConstantData).toContain(
2328
2396
  `Content-Disposition: form-data; name="./test-hello.wasm"; filename="./test-hello.wasm"`
2329
2397
  );
2330
- expect(workerBundleWithConstantData).toContain(`HELLO WORLD`);
2398
+ expect(workerBundleWithConstantData).toContain(
2399
+ `Hello Wasm modules world!`
2400
+ );
2401
+
2402
+ // check we appended the text module
2403
+ expect(workerBundleWithConstantData).toContain(
2404
+ `Content-Disposition: form-data; name="./test-hello.txt"; filename="./test-hello.txt"`
2405
+ );
2406
+ expect(workerBundleWithConstantData).toContain(
2407
+ `Hello Text modules world!`
2408
+ );
2331
2409
 
2332
2410
  return res.once(
2333
2411
  ctx.status(200),
@@ -2364,11 +2442,9 @@ async function onRequest() {
2364
2442
  )
2365
2443
  );
2366
2444
 
2367
- await runWrangler(
2368
- "pages publish public --project-name=foo --experimental-worker-bundle=true"
2369
- );
2445
+ await runWrangler("pages publish public --project-name=foo");
2370
2446
 
2371
- expect(std.out).toMatchInlineSnapshot(`
2447
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
2372
2448
  "✨ Compiled Worker successfully
2373
2449
  ✨ Success! Uploaded 1 files (TIMINGS)
2374
2450
 
@@ -2380,26 +2456,37 @@ async function onRequest() {
2380
2456
  expect(std.err).toMatchInlineSnapshot('""');
2381
2457
  });
2382
2458
 
2383
- it("should bundle _worker.js and resolve its external module imports if the `--experimental-worker-bundle` flag is set", async () => {
2459
+ it("should bundle _worker.js and resolve its external module imports", async () => {
2384
2460
  // set up the directory of static files to upload
2385
2461
  mkdirSync("public");
2386
2462
  writeFileSync("public/README.md", "This is a readme");
2387
2463
 
2388
2464
  // set up hello.wasm
2389
- mkdirSync("wasm");
2390
- writeFileSync("wasm/hello.wasm", "HELLO");
2465
+ mkdirSync("external");
2466
+ writeFileSync("external/hello.wasm", "Hello wasm modules");
2467
+ writeFileSync(
2468
+ "external/hello.html",
2469
+ "<html><body>Hello text modules</body></html>"
2470
+ );
2391
2471
 
2392
2472
  // set up _worker.js
2393
2473
  writeFileSync(
2394
2474
  "public/_worker.js",
2395
2475
  `
2396
- import hello from "./../wasm/hello.wasm";
2476
+ import wasm from "./../external/hello.wasm";
2477
+ import html from "./../external/hello.html";
2397
2478
  export default {
2398
2479
  async fetch(request, env) {
2399
2480
  const url = new URL(request.url);
2400
- const helloModule = await WebAssembly.instantiate(hello);
2401
- const greeting = helloModule.exports.hello;
2402
- return url.pathname.startsWith('/hello') ? new Response(greeting) : env.ASSETS.fetch(request);
2481
+ const helloModule = await WebAssembly.instantiate(wasm);
2482
+ const wasmGreeting = helloModule.exports.hello;
2483
+ if(url.pathname.startsWith('/hello-wasm')) {
2484
+ return new Response(wasmGreeting);
2485
+ }
2486
+ if(url.pathname.startsWith('/hello-text')) {
2487
+ return new Response(html);
2488
+ }
2489
+ return env.ASSETS.fetch(request);
2403
2490
  }
2404
2491
  };
2405
2492
  `
@@ -2499,6 +2586,10 @@ async function onRequest() {
2499
2586
  /[0-9a-z]*-hello.wasm/g,
2500
2587
  "test-hello.wasm"
2501
2588
  );
2589
+ workerBundleWithConstantData = workerBundleWithConstantData.replace(
2590
+ /[0-9a-z]*-hello.html/g,
2591
+ "test-hello.html"
2592
+ );
2502
2593
 
2503
2594
  // we care about a couple of things here, like the presence of `metadata`,
2504
2595
  // `bundledWorker`, the wasm import, etc., and since `workerBundle` is
@@ -2513,13 +2604,20 @@ async function onRequest() {
2513
2604
  Content-Type: application/javascript+module
2514
2605
 
2515
2606
  // _worker.js
2516
- import hello from \\"./test-hello.wasm\\";
2607
+ import wasm from \\"./test-hello.wasm\\";
2608
+ import html from \\"./test-hello.html\\";
2517
2609
  var worker_default = {
2518
2610
  async fetch(request, env) {
2519
2611
  const url = new URL(request.url);
2520
- const helloModule = await WebAssembly.instantiate(hello);
2521
- const greeting = helloModule.exports.hello;
2522
- return url.pathname.startsWith(\\"/hello\\") ? new Response(greeting) : env.ASSETS.fetch(request);
2612
+ const helloModule = await WebAssembly.instantiate(wasm);
2613
+ const wasmGreeting = helloModule.exports.hello;
2614
+ if (url.pathname.startsWith(\\"/hello-wasm\\")) {
2615
+ return new Response(wasmGreeting);
2616
+ }
2617
+ if (url.pathname.startsWith(\\"/hello-text\\")) {
2618
+ return new Response(html);
2619
+ }
2620
+ return env.ASSETS.fetch(request);
2523
2621
  }
2524
2622
  };
2525
2623
  export {
@@ -2531,7 +2629,12 @@ async function onRequest() {
2531
2629
  Content-Disposition: form-data; name=\\"./test-hello.wasm\\"; filename=\\"./test-hello.wasm\\"
2532
2630
  Content-Type: application/wasm
2533
2631
 
2534
- HELLO
2632
+ Hello wasm modules
2633
+ ------formdata-undici-0.test
2634
+ Content-Disposition: form-data; name=\\"./test-hello.html\\"; filename=\\"./test-hello.html\\"
2635
+ Content-Type: text/plain
2636
+
2637
+ <html><body>Hello text modules</body></html>
2535
2638
  ------formdata-undici-0.test--"
2536
2639
  `);
2537
2640
 
@@ -2570,11 +2673,9 @@ async function onRequest() {
2570
2673
  )
2571
2674
  );
2572
2675
 
2573
- await runWrangler(
2574
- "pages publish public --project-name=foo --experimental-worker-bundle=true"
2575
- );
2676
+ await runWrangler("pages publish public --project-name=foo");
2576
2677
 
2577
- expect(std.out).toMatchInlineSnapshot(`
2678
+ expect(normalizeProgressSteps(std.out)).toMatchInlineSnapshot(`
2578
2679
  "✨ Success! Uploaded 1 files (TIMINGS)
2579
2680
 
2580
2681
  ✨ Compiled Worker successfully
@@ -2605,7 +2706,7 @@ async function onRequest() {
2605
2706
  contents.includes("worker_default as default");
2606
2707
 
2607
2708
  const simulateServer = (
2608
- generatedWorkerJsCheck: (workerJsContent: string) => void
2709
+ generatedWorkerBundleCheck: (workerJsContent: string) => void
2609
2710
  ) => {
2610
2711
  mockGetUploadTokenRequest(
2611
2712
  "<<funfetti-auth-jwt>>",
@@ -2639,9 +2740,9 @@ async function onRequest() {
2639
2740
  "*/accounts/:accountId/pages/projects/foo/deployments",
2640
2741
  async (req, res, ctx) => {
2641
2742
  const body = await (req as RestRequestWithFormData).formData();
2642
- const generatedWorkerJS = body.get("_worker.js") as string;
2743
+ const generatedWorkerBundle = body.get("_worker.bundle") as string;
2643
2744
 
2644
- generatedWorkerJsCheck(generatedWorkerJS);
2745
+ generatedWorkerBundleCheck(generatedWorkerBundle);
2645
2746
 
2646
2747
  return res.once(
2647
2748
  ctx.status(200),
@@ -2674,12 +2775,30 @@ async function onRequest() {
2674
2775
  );
2675
2776
  };
2676
2777
 
2677
- it("should not bundle the _worker.js when both `--bundle` and `--no-bundle` are omitted", async () => {
2778
+ it("should bundle the _worker.js when both `--bundle` and `--no-bundle` are omitted", async () => {
2678
2779
  simulateServer((generatedWorkerJS) =>
2679
- expect(workerIsBundled(generatedWorkerJS)).toBeFalsy()
2780
+ expect(workerIsBundled(generatedWorkerJS)).toBeTruthy()
2680
2781
  );
2681
2782
  await runWrangler("pages publish public --project-name=foo");
2682
- expect(std.out).toContain("✨ Uploading _worker.js");
2783
+ expect(std.out).toContain("✨ Uploading Worker bundle");
2784
+ });
2785
+
2786
+ it("should not bundle the _worker.js when `--no-bundle` is set", async () => {
2787
+ simulateServer((generatedWorkerJS) =>
2788
+ expect(workerIsBundled(generatedWorkerJS)).toBeFalsy()
2789
+ );
2790
+ await runWrangler("pages publish public --project-name=foo --no-bundle");
2791
+ expect(std.out).toContain("✨ Uploading Worker bundle");
2792
+ });
2793
+
2794
+ it("should not bundle the _worker.js when `--bundle` is set to false", async () => {
2795
+ simulateServer((generatedWorkerJS) =>
2796
+ expect(workerIsBundled(generatedWorkerJS)).toBeFalsy()
2797
+ );
2798
+ await runWrangler(
2799
+ "pages publish public --project-name=foo --bundle=false"
2800
+ );
2801
+ expect(std.out).toContain("✨ Uploading Worker bundle");
2683
2802
  });
2684
2803
 
2685
2804
  it("should bundle the _worker.js when the `--no-bundle` is set to false", async () => {
@@ -2689,7 +2808,7 @@ async function onRequest() {
2689
2808
  await runWrangler(
2690
2809
  "pages publish public --no-bundle=false --project-name=foo"
2691
2810
  );
2692
- expect(std.out).toContain("✨ Uploading _worker.js");
2811
+ expect(std.out).toContain("✨ Uploading Worker bundle");
2693
2812
  });
2694
2813
 
2695
2814
  it("should bundle the _worker.js when the `--bundle` is set to true", async () => {
@@ -2699,7 +2818,7 @@ async function onRequest() {
2699
2818
  await runWrangler(
2700
2819
  "pages publish public --bundle=true --project-name=foo"
2701
2820
  );
2702
- expect(std.out).toContain("✨ Uploading _worker.js");
2821
+ expect(std.out).toContain("✨ Uploading Worker bundle");
2703
2822
  });
2704
2823
  });
2705
2824
  });