wrangler 2.8.0 → 2.8.1

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 (44) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/d1/d1.test.ts +12 -8
  3. package/src/__tests__/deployments.test.ts +4 -4
  4. package/src/__tests__/helpers/msw/handlers/deployments.ts +10 -18
  5. package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
  6. package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
  7. package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
  8. package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
  9. package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
  10. package/src/__tests__/pages.test.ts +34 -37
  11. package/src/__tests__/publish.test.ts +126 -0
  12. package/src/__tests__/r2.test.ts +11 -35
  13. package/src/__tests__/tail.test.ts +6 -18
  14. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  15. package/src/__tests__/user.test.ts +0 -1
  16. package/src/__tests__/whoami.test.tsx +6 -17
  17. package/src/__tests__/worker-namespace.test.ts +56 -48
  18. package/src/api/index.ts +1 -0
  19. package/src/api/pages/index.ts +5 -0
  20. package/src/api/pages/publish.tsx +321 -0
  21. package/src/bundle.ts +62 -10
  22. package/src/cli.ts +2 -2
  23. package/src/config/environment.ts +12 -10
  24. package/src/d1/utils.ts +1 -1
  25. package/src/deployments.ts +16 -6
  26. package/src/dev/local.tsx +1 -10
  27. package/src/dev/start-server.ts +5 -10
  28. package/src/dev/use-esbuild.ts +1 -0
  29. package/src/entry.ts +1 -2
  30. package/src/index.ts +1 -1
  31. package/src/metrics/send-event.ts +2 -1
  32. package/src/pages/build.ts +4 -124
  33. package/src/pages/buildFunctions.ts +129 -0
  34. package/src/pages/dev.ts +12 -2
  35. package/src/pages/functions/buildPlugin.ts +1 -0
  36. package/src/pages/functions/buildWorker.ts +8 -2
  37. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  38. package/src/pages/publish.tsx +9 -235
  39. package/src/publish/publish.ts +1 -0
  40. package/templates/d1-beta-facade.js +1 -1
  41. package/templates/middleware/loader-modules.ts +2 -0
  42. package/templates/tsconfig.tsbuildinfo +1 -1
  43. package/wrangler-dist/cli.d.ts +132 -10
  44. package/wrangler-dist/cli.js +486 -388
@@ -5771,6 +5771,77 @@ addEventListener('fetch', event => {});`
5771
5771
  expect(std.warn).toMatchInlineSnapshot(`""`);
5772
5772
  });
5773
5773
 
5774
+ it("should support durable objects and D1", async () => {
5775
+ writeWranglerToml({
5776
+ main: "index.js",
5777
+ durable_objects: {
5778
+ bindings: [
5779
+ {
5780
+ name: "EXAMPLE_DO_BINDING",
5781
+ class_name: "ExampleDurableObject",
5782
+ },
5783
+ ],
5784
+ },
5785
+ migrations: [{ tag: "v1", new_classes: ["ExampleDurableObject"] }],
5786
+ d1_databases: [
5787
+ {
5788
+ binding: "DB",
5789
+ database_name: "test-d1-db",
5790
+ database_id: "UUID-1-2-3-4",
5791
+ preview_database_id: "UUID-1-2-3-4",
5792
+ },
5793
+ ],
5794
+ });
5795
+ const scriptContent = `export class ExampleDurableObject {}; export default{};`;
5796
+ fs.writeFileSync("index.js", scriptContent);
5797
+ mockSubDomainRequest();
5798
+ mockLegacyScriptData({
5799
+ scripts: [{ id: "test-name", migration_tag: "v1" }],
5800
+ });
5801
+ mockUploadWorkerRequest({
5802
+ expectedType: "esm",
5803
+ expectedBindings: [
5804
+ {
5805
+ name: "EXAMPLE_DO_BINDING",
5806
+ class_name: "ExampleDurableObject",
5807
+ type: "durable_object_namespace",
5808
+ },
5809
+ { name: "DB", type: "d1_database" },
5810
+ ],
5811
+ });
5812
+
5813
+ await runWrangler("publish index.js --outdir tmp --dry-run");
5814
+ expect(std.out).toMatchInlineSnapshot(`
5815
+ "Total Upload: xx KiB / gzip: xx KiB
5816
+ Your worker has access to the following bindings:
5817
+ - Durable Objects:
5818
+ - EXAMPLE_DO_BINDING: ExampleDurableObject
5819
+ - D1 Databases:
5820
+ - DB: test-d1-db (UUID-1-2-3-4), Preview: (UUID-1-2-3-4)
5821
+ --dry-run: exiting now."
5822
+ `);
5823
+ expect(std.err).toMatchInlineSnapshot(`""`);
5824
+ expect(std.warn).toMatchInlineSnapshot(`
5825
+ "â–² [WARNING] Processing wrangler.toml configuration:
5826
+
5827
+ - D1 Bindings are currently in alpha to allow the API to evolve before general availability.
5828
+ Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
5829
+ Note: Run this command with the environment variable NO_D1_WARNING=true to hide this message
5830
+
5831
+ For example: \`export NO_D1_WARNING=true && wrangler <YOUR COMMAND HERE>\`
5832
+
5833
+ "
5834
+ `);
5835
+ const output = fs.readFileSync("tmp/d1-beta-facade.entry.js", "utf-8");
5836
+ expect(output).toContain(
5837
+ `var ExampleDurableObject2 = maskDurableObjectDefinition(ExampleDurableObject);`
5838
+ );
5839
+ expect(output).toContain(
5840
+ `ExampleDurableObject2 as ExampleDurableObject,`
5841
+ );
5842
+ expect(output).toContain(`shim_default as default`);
5843
+ });
5844
+
5774
5845
  it("should error when detecting a service-worker worker implementing durable objects", async () => {
5775
5846
  writeWranglerToml({
5776
5847
  durable_objects: {
@@ -6472,6 +6543,61 @@ addEventListener('fetch', event => {});`
6472
6543
  }
6473
6544
  `);
6474
6545
  });
6546
+
6547
+ it("should copy any module imports related assets at --outdir if specified", async () => {
6548
+ writeWranglerToml();
6549
+ fs.writeFileSync(
6550
+ "./index.js",
6551
+ `
6552
+ import txt from './textfile.txt';
6553
+ import hello from './hello.wasm';
6554
+ export default{
6555
+ async fetch(){
6556
+ const module = await WebAssembly.instantiate(hello);
6557
+ return new Response(txt + module.exports.hello);
6558
+ }
6559
+ }
6560
+ `
6561
+ );
6562
+ fs.writeFileSync("./textfile.txt", "Hello, World!");
6563
+ fs.writeFileSync("./hello.wasm", "Hello wasm World!");
6564
+ mockSubDomainRequest();
6565
+ mockUploadWorkerRequest({
6566
+ expectedModules: {
6567
+ "./0a0a9f2a6772942557ab5355d76af442f8f65e01-textfile.txt":
6568
+ "Hello, World!",
6569
+ "./d025a03cd31e98e96fb5bd5bce87f9bca4e8ce2c-hello.wasm":
6570
+ "Hello wasm World!",
6571
+ },
6572
+ });
6573
+ await runWrangler("publish index.js --outdir some-dir");
6574
+
6575
+ expect(fs.existsSync("some-dir/index.js")).toBe(true);
6576
+ expect(fs.existsSync("some-dir/index.js.map")).toBe(true);
6577
+ expect(fs.existsSync("some-dir/README.md")).toBe(true);
6578
+ expect(
6579
+ fs.existsSync(
6580
+ "some-dir/0a0a9f2a6772942557ab5355d76af442f8f65e01-textfile.txt"
6581
+ )
6582
+ ).toBe(true);
6583
+ expect(
6584
+ fs.existsSync(
6585
+ "some-dir/d025a03cd31e98e96fb5bd5bce87f9bca4e8ce2c-hello.wasm"
6586
+ )
6587
+ ).toBe(true);
6588
+ expect(std).toMatchInlineSnapshot(`
6589
+ Object {
6590
+ "debug": "",
6591
+ "err": "",
6592
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6593
+ Uploaded test-name (TIMINGS)
6594
+ Published test-name (TIMINGS)
6595
+ https://test-name.test-sub-domain.workers.dev
6596
+ Current Deployment ID: Galaxy-Class",
6597
+ "warn": "",
6598
+ }
6599
+ `);
6600
+ });
6475
6601
  });
6476
6602
 
6477
6603
  describe("--dry-run", () => {
@@ -4,7 +4,7 @@ import prettyBytes from "pretty-bytes";
4
4
  import { MAX_UPLOAD_SIZE } from "../r2/constants";
5
5
  import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
6
6
  import { mockConsoleMethods } from "./helpers/mock-console";
7
- import { msw, mswSuccessR2handlers } from "./helpers/msw";
7
+ import { createFetchResult, msw, mswSuccessR2handlers } from "./helpers/msw";
8
8
  import { runInTempDir } from "./helpers/run-in-tmp";
9
9
  import { runWrangler } from "./helpers/run-wrangler";
10
10
  import type { R2BucketInfo } from "../r2/helpers";
@@ -60,12 +60,8 @@ describe("r2", () => {
60
60
  expect(accountId).toEqual("some-account-id");
61
61
  expect(await request.text()).toEqual("");
62
62
  return response.once(
63
- context.status(200),
64
- context.json({
65
- success: true,
66
- errors: [],
67
- messages: [],
68
- result: {
63
+ context.json(
64
+ createFetchResult({
69
65
  buckets: [
70
66
  {
71
67
  name: "bucket-1-local-once",
@@ -76,8 +72,8 @@ describe("r2", () => {
76
72
  creation_date: "01-01-2001",
77
73
  },
78
74
  ],
79
- },
80
- })
75
+ })
76
+ )
81
77
  );
82
78
  }
83
79
  )
@@ -155,15 +151,7 @@ describe("r2", () => {
155
151
  const { accountId } = request.params;
156
152
  expect(accountId).toEqual("some-account-id");
157
153
  expect(await request.json()).toEqual({ name: "testBucket" });
158
- return response.once(
159
- context.status(200),
160
- context.json({
161
- success: true,
162
- errors: [],
163
- messages: [],
164
- result: {},
165
- })
166
- );
154
+ return response.once(context.json(createFetchResult({})));
167
155
  }
168
156
  )
169
157
  );
@@ -245,15 +233,7 @@ describe("r2", () => {
245
233
  "Bearer some-api-token"
246
234
  );
247
235
 
248
- return response.once(
249
- context.status(200),
250
- context.json({
251
- success: true,
252
- errors: [],
253
- messages: [],
254
- result: null,
255
- })
256
- );
236
+ return response.once(context.json(createFetchResult(null)));
257
237
  }
258
238
  )
259
239
  );
@@ -333,17 +313,13 @@ describe("r2", () => {
333
313
  }
334
314
  `);
335
315
  return response.once(
336
- context.status(200),
337
- context.json({
338
- success: true,
339
- errors: [],
340
- messages: [],
341
- result: {
316
+ context.json(
317
+ createFetchResult({
342
318
  accountId: "some-account-id",
343
319
  bucketName: "bucketName-object-test",
344
320
  objectName: "wormhole-img.png",
345
- },
346
- })
321
+ })
322
+ )
347
323
  );
348
324
  }
349
325
  )
@@ -5,7 +5,7 @@ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
5
5
  import { mockConsoleMethods } from "./helpers/mock-console";
6
6
  import { mockConfirm, clearDialogs } from "./helpers/mock-dialogs";
7
7
  import { useMockIsTTY } from "./helpers/mock-istty";
8
- import { msw, mswSucessScriptHandlers } from "./helpers/msw";
8
+ import { createFetchResult, msw, mswSucessScriptHandlers } from "./helpers/msw";
9
9
  import { runInTempDir } from "./helpers/run-in-tmp";
10
10
  import { runWrangler } from "./helpers/run-wrangler";
11
11
  import type {
@@ -743,17 +743,13 @@ function mockCreateTailRequest(
743
743
  expect(req.params.envName).toEqual(env);
744
744
  }
745
745
  return res.once(
746
- ctx.status(200),
747
- ctx.json({
748
- success: true,
749
- errors: [],
750
- messages: [],
751
- result: {
746
+ ctx.json(
747
+ createFetchResult({
752
748
  url: websocketURL,
753
749
  id: "tail-id",
754
750
  expires_at: mockTailExpiration,
755
- },
756
- })
751
+ })
752
+ )
757
753
  );
758
754
  }
759
755
  )
@@ -818,15 +814,7 @@ function mockDeleteTailRequest(
818
814
  }
819
815
  }
820
816
  expect(req.params.tailId).toEqual("tail-id");
821
- return res(
822
- ctx.status(200),
823
- ctx.json({
824
- success: true,
825
- errors: [],
826
- messages: [],
827
- result: null,
828
- })
829
- );
817
+ return res(ctx.json(createFetchResult(null)));
830
818
  }
831
819
  )
832
820
  );