wrangler 2.0.24 → 2.0.27

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 (63) hide show
  1. package/miniflare-dist/index.mjs +142 -16
  2. package/package.json +3 -3
  3. package/src/__tests__/configuration.test.ts +7 -3
  4. package/src/__tests__/dev.test.tsx +26 -4
  5. package/src/__tests__/generate.test.ts +2 -4
  6. package/src/__tests__/helpers/mock-cfetch.ts +35 -2
  7. package/src/__tests__/init.test.ts +537 -359
  8. package/src/__tests__/jest.setup.ts +7 -0
  9. package/src/__tests__/metrics.test.ts +1 -1
  10. package/src/__tests__/pages.test.ts +14 -0
  11. package/src/__tests__/r2.test.ts +22 -3
  12. package/src/__tests__/tail.test.ts +112 -42
  13. package/src/__tests__/user.test.ts +11 -0
  14. package/src/api/dev.ts +7 -0
  15. package/src/bundle.ts +3 -2
  16. package/src/cfetch/internal.ts +56 -0
  17. package/src/config/config.ts +1 -1
  18. package/src/config/validation-helpers.ts +19 -6
  19. package/src/config/validation.ts +9 -3
  20. package/src/config-cache.ts +2 -1
  21. package/src/dev/dev.tsx +16 -2
  22. package/src/dev/local.tsx +69 -5
  23. package/src/dev/use-esbuild.ts +3 -0
  24. package/src/dev-registry.tsx +3 -0
  25. package/src/dev.tsx +28 -19
  26. package/src/generate.ts +1 -1
  27. package/src/index.tsx +51 -21
  28. package/src/init.ts +111 -38
  29. package/src/inspect.ts +1 -4
  30. package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
  31. package/src/metrics/metrics-config.ts +1 -1
  32. package/src/miniflare-cli/assets.ts +27 -16
  33. package/src/miniflare-cli/index.ts +124 -2
  34. package/src/pages/build.tsx +75 -41
  35. package/src/pages/constants.ts +4 -0
  36. package/src/pages/deployments.tsx +9 -9
  37. package/src/pages/dev.tsx +178 -64
  38. package/src/pages/errors.ts +22 -0
  39. package/src/pages/functions/buildPlugin.ts +4 -0
  40. package/src/pages/functions/buildWorker.ts +4 -0
  41. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  42. package/src/pages/functions/routes-consolidation.ts +73 -0
  43. package/src/pages/functions/routes-transformation.test.ts +271 -0
  44. package/src/pages/functions/routes-transformation.ts +122 -0
  45. package/src/pages/functions.tsx +96 -0
  46. package/src/pages/index.tsx +65 -55
  47. package/src/pages/projects.tsx +9 -3
  48. package/src/pages/publish.tsx +75 -22
  49. package/src/pages/types.ts +9 -0
  50. package/src/pages/upload.tsx +6 -8
  51. package/src/proxy.ts +10 -0
  52. package/src/r2.ts +17 -4
  53. package/src/tail/filters.ts +3 -1
  54. package/src/tail/index.ts +15 -2
  55. package/src/tail/printing.ts +43 -3
  56. package/src/user/user.tsx +6 -4
  57. package/src/whoami.tsx +5 -5
  58. package/templates/pages-template-plugin.ts +16 -4
  59. package/templates/pages-template-worker.ts +16 -5
  60. package/templates/service-bindings-module-facade.js +10 -7
  61. package/templates/service-bindings-sw-facade.js +10 -7
  62. package/wrangler-dist/cli.d.ts +7 -0
  63. package/wrangler-dist/cli.js +1681 -1091
@@ -5,6 +5,8 @@ import { execa, execaSync } from "execa";
5
5
  import { parseConfigFileTextToJson } from "typescript";
6
6
  import { version as wranglerVersion } from "../../package.json";
7
7
  import { getPackageManager } from "../package-manager";
8
+ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
9
+ import { setMockFetchDashScript, unsetAllMocks } from "./helpers/mock-cfetch";
8
10
  import { mockConsoleMethods } from "./helpers/mock-console";
9
11
  import {
10
12
  mockConfirm,
@@ -62,16 +64,16 @@ describe("init", () => {
62
64
  });
63
65
 
64
66
  expect(std.out).toMatchInlineSnapshot(`
65
- "✨ Created wrangler.toml
66
- ✨ Initialized git repository
67
- ✨ Created package.json
68
- ✨ Created tsconfig.json
69
- ✨ Created src/index.ts
70
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
71
-
72
- To start developing your Worker, run \`npm start\`
73
- To publish your Worker to the Internet, run \`npm run deploy\`"
74
- `);
67
+ "✨ Created wrangler.toml
68
+ ✨ Initialized git repository
69
+ ✨ Created package.json
70
+ ✨ Created tsconfig.json
71
+ ✨ Created src/index.ts
72
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
73
+
74
+ To start developing your Worker, run \`npm start\`
75
+ To publish your Worker to the Internet, run \`npm run deploy\`"
76
+ `);
75
77
  expect(std.err).toMatchInlineSnapshot(`""`);
76
78
  expect(std.warn).toMatchInlineSnapshot(`""`);
77
79
  });
@@ -93,16 +95,16 @@ describe("init", () => {
93
95
  });
94
96
 
95
97
  expect(std.out).toMatchInlineSnapshot(`
96
- "✨ Created my-worker/wrangler.toml
97
- ✨ Initialized git repository at my-worker
98
- ✨ Created my-worker/package.json
99
- ✨ Created my-worker/tsconfig.json
100
- ✨ Created my-worker/src/index.ts
101
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
102
-
103
- To start developing your Worker, run \`cd my-worker && npm start\`
104
- To publish your Worker to the Internet, run \`npm run deploy\`"
105
- `);
98
+ "✨ Created my-worker/wrangler.toml
99
+ ✨ Initialized git repository at my-worker
100
+ ✨ Created my-worker/package.json
101
+ ✨ Created my-worker/tsconfig.json
102
+ ✨ Created my-worker/src/index.ts
103
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
104
+
105
+ To start developing your Worker, run \`cd my-worker && npm start\`
106
+ To publish your Worker to the Internet, run \`npm run deploy\`"
107
+ `);
106
108
  expect(std.err).toMatchInlineSnapshot(`""`);
107
109
  expect(std.warn).toMatchInlineSnapshot(`""`);
108
110
  });
@@ -121,21 +123,21 @@ describe("init", () => {
121
123
  });
122
124
 
123
125
  expect(std).toMatchInlineSnapshot(`
124
- Object {
125
- "debug": "",
126
- "err": "",
127
- "out": "✨ Created wrangler.toml
128
- ✨ Initialized git repository
129
- ✨ Created package.json
130
- ✨ Created tsconfig.json
131
- ✨ Created src/index.ts
132
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
133
-
134
- To start developing your Worker, run \`npm start\`
135
- To publish your Worker to the Internet, run \`npm run deploy\`",
136
- "warn": "",
137
- }
138
- `);
126
+ Object {
127
+ "debug": "",
128
+ "err": "",
129
+ "out": "✨ Created wrangler.toml
130
+ ✨ Initialized git repository
131
+ ✨ Created package.json
132
+ ✨ Created tsconfig.json
133
+ ✨ Created src/index.ts
134
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
135
+
136
+ To start developing your Worker, run \`npm start\`
137
+ To publish your Worker to the Internet, run \`npm run deploy\`",
138
+ "warn": "",
139
+ }
140
+ `);
139
141
  });
140
142
 
141
143
  it("should error if `--type javascript` is used", async () => {
@@ -204,13 +206,13 @@ describe("init", () => {
204
206
  });
205
207
 
206
208
  expect(std).toMatchInlineSnapshot(`
207
- Object {
208
- "debug": "",
209
- "err": "",
210
- "out": "✨ Created wrangler.toml",
211
- "warn": "",
212
- }
213
- `);
209
+ Object {
210
+ "debug": "",
211
+ "err": "",
212
+ "out": "✨ Created wrangler.toml",
213
+ "warn": "",
214
+ }
215
+ `);
214
216
  });
215
217
 
216
218
  it("should create a wrangler.toml and a directory for a named Worker ", async () => {
@@ -238,13 +240,13 @@ describe("init", () => {
238
240
  });
239
241
 
240
242
  expect(std).toMatchInlineSnapshot(`
241
- Object {
242
- "debug": "",
243
- "err": "",
244
- "out": "✨ Created my-worker/wrangler.toml",
245
- "warn": "",
246
- }
247
- `);
243
+ Object {
244
+ "debug": "",
245
+ "err": "",
246
+ "out": "✨ Created my-worker/wrangler.toml",
247
+ "warn": "",
248
+ }
249
+ `);
248
250
  });
249
251
 
250
252
  it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
@@ -276,15 +278,15 @@ describe("init", () => {
276
278
  });
277
279
 
278
280
  expect(std).toMatchInlineSnapshot(`
279
- Object {
280
- "debug": "",
281
- "err": "",
282
- "out": "",
283
- "warn": "▲ [WARNING] wrangler.toml already exists!
284
-
285
- ",
286
- }
287
- `);
281
+ Object {
282
+ "debug": "",
283
+ "err": "",
284
+ "out": "",
285
+ "warn": "▲ [WARNING] wrangler.toml already exists!
286
+
287
+ ",
288
+ }
289
+ `);
288
290
  });
289
291
 
290
292
  it("should display warning when wrangler.toml already exists in the target directory, and exit if user does not want to carry on", async () => {
@@ -313,15 +315,15 @@ describe("init", () => {
313
315
  },
314
316
  });
315
317
  expect(std).toMatchInlineSnapshot(`
316
- Object {
317
- "debug": "",
318
- "err": "",
319
- "out": "",
320
- "warn": "▲ [WARNING] path/to/worker/wrangler.toml already exists!
321
-
322
- ",
323
- }
324
- `);
318
+ Object {
319
+ "debug": "",
320
+ "err": "",
321
+ "out": "",
322
+ "warn": "▲ [WARNING] path/to/worker/wrangler.toml already exists!
323
+
324
+ ",
325
+ }
326
+ `);
325
327
  });
326
328
 
327
329
  it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
@@ -401,15 +403,15 @@ describe("init", () => {
401
403
  },
402
404
  });
403
405
  expect(std).toMatchInlineSnapshot(`
404
- Object {
405
- "debug": "",
406
- "err": "",
407
- "out": "",
408
- "warn": "▲ [WARNING] wrangler.toml already exists!
409
-
410
- ",
411
- }
412
- `);
406
+ Object {
407
+ "debug": "",
408
+ "err": "",
409
+ "out": "",
410
+ "warn": "▲ [WARNING] wrangler.toml already exists!
411
+
412
+ ",
413
+ }
414
+ `);
413
415
  });
414
416
 
415
417
  it("should not add a Cron Trigger to wrangler.toml when creating a Scheduled Worker if wrangler.toml already exists", async () => {
@@ -513,14 +515,14 @@ describe("init", () => {
513
515
  },
514
516
  });
515
517
  expect(std).toMatchInlineSnapshot(`
516
- Object {
517
- "debug": "",
518
- "err": "",
519
- "out": "✨ Created wrangler.toml
520
- ✨ Initialized git repository",
521
- "warn": "",
522
- }
523
- `);
518
+ Object {
519
+ "debug": "",
520
+ "err": "",
521
+ "out": "✨ Created wrangler.toml
522
+ ✨ Initialized git repository",
523
+ "warn": "",
524
+ }
525
+ `);
524
526
  expect((await execa("git", ["branch", "--show-current"])).stdout).toEqual(
525
527
  "main"
526
528
  );
@@ -545,20 +547,20 @@ describe("init", () => {
545
547
 
546
548
  // Note the lack of "✨ Initialized git repository" in the log
547
549
  expect(std).toMatchInlineSnapshot(`
548
- Object {
549
- "debug": "",
550
- "err": "",
551
- "out": "✨ Created wrangler.toml
552
- ✨ Created package.json
553
- ✨ Created tsconfig.json
554
- ✨ Created src/index.ts
555
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
556
-
557
- To start developing your Worker, run \`npm start\`
558
- To publish your Worker to the Internet, run \`npm run deploy\`",
559
- "warn": "",
560
- }
561
- `);
550
+ Object {
551
+ "debug": "",
552
+ "err": "",
553
+ "out": "✨ Created wrangler.toml
554
+ ✨ Created package.json
555
+ ✨ Created tsconfig.json
556
+ ✨ Created src/index.ts
557
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
558
+
559
+ To start developing your Worker, run \`npm start\`
560
+ To publish your Worker to the Internet, run \`npm run deploy\`",
561
+ "warn": "",
562
+ }
563
+ `);
562
564
  });
563
565
 
564
566
  it("should not offer to initialize a git repo if it's already inside one (when using a path as name)", async () => {
@@ -570,20 +572,20 @@ describe("init", () => {
570
572
 
571
573
  // Note the lack of "✨ Initialized git repository" in the log
572
574
  expect(std).toMatchInlineSnapshot(`
573
- Object {
574
- "debug": "",
575
- "err": "",
576
- "out": "✨ Created path/to/worker/my-worker/wrangler.toml
577
- ✨ Created path/to/worker/my-worker/package.json
578
- ✨ Created path/to/worker/my-worker/tsconfig.json
579
- ✨ Created path/to/worker/my-worker/src/index.ts
580
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
581
-
582
- To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
583
- To publish your Worker to the Internet, run \`npm run deploy\`",
584
- "warn": "",
585
- }
586
- `);
575
+ Object {
576
+ "debug": "",
577
+ "err": "",
578
+ "out": "✨ Created path/to/worker/my-worker/wrangler.toml
579
+ ✨ Created path/to/worker/my-worker/package.json
580
+ ✨ Created path/to/worker/my-worker/tsconfig.json
581
+ ✨ Created path/to/worker/my-worker/src/index.ts
582
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
583
+
584
+ To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
585
+ To publish your Worker to the Internet, run \`npm run deploy\`",
586
+ "warn": "",
587
+ }
588
+ `);
587
589
  });
588
590
 
589
591
  // I... don't know how to test this lol
@@ -604,14 +606,14 @@ describe("init", () => {
604
606
  );
605
607
  await runWrangler("init");
606
608
  expect(std).toMatchInlineSnapshot(`
607
- Object {
608
- "debug": "",
609
- "err": "",
610
- "out": "✨ Created wrangler.toml
611
- ✨ Initialized git repository",
612
- "warn": "",
613
- }
614
- `);
609
+ Object {
610
+ "debug": "",
611
+ "err": "",
612
+ "out": "✨ Created wrangler.toml
613
+ ✨ Initialized git repository",
614
+ "warn": "",
615
+ }
616
+ `);
615
617
 
616
618
  expect(execaSync("git", ["symbolic-ref", "HEAD"]).stdout).toEqual(
617
619
  "refs/heads/main"
@@ -658,14 +660,14 @@ describe("init", () => {
658
660
  });
659
661
  expect(mockPackageManager.install).toHaveBeenCalled();
660
662
  expect(std).toMatchInlineSnapshot(`
661
- Object {
662
- "debug": "",
663
- "err": "",
664
- "out": "✨ Created wrangler.toml
665
- ✨ Created package.json",
666
- "warn": "",
667
- }
668
- `);
663
+ Object {
664
+ "debug": "",
665
+ "err": "",
666
+ "out": "✨ Created wrangler.toml
667
+ ✨ Created package.json",
668
+ "warn": "",
669
+ }
670
+ `);
669
671
  });
670
672
 
671
673
  it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
@@ -705,14 +707,14 @@ describe("init", () => {
705
707
  },
706
708
  });
707
709
  expect(std).toMatchInlineSnapshot(`
708
- Object {
709
- "debug": "",
710
- "err": "",
711
- "out": "✨ Created my-worker/wrangler.toml
712
- ✨ Created my-worker/package.json",
713
- "warn": "",
714
- }
715
- `);
710
+ Object {
711
+ "debug": "",
712
+ "err": "",
713
+ "out": "✨ Created my-worker/wrangler.toml
714
+ ✨ Created my-worker/package.json",
715
+ "warn": "",
716
+ }
717
+ `);
716
718
  });
717
719
 
718
720
  it("should not touch an existing package.json in the same directory", async () => {
@@ -748,13 +750,13 @@ describe("init", () => {
748
750
  },
749
751
  });
750
752
  expect(std).toMatchInlineSnapshot(`
751
- Object {
752
- "debug": "",
753
- "err": "",
754
- "out": "✨ Created wrangler.toml",
755
- "warn": "",
756
- }
757
- `);
753
+ Object {
754
+ "debug": "",
755
+ "err": "",
756
+ "out": "✨ Created wrangler.toml",
757
+ "warn": "",
758
+ }
759
+ `);
758
760
  });
759
761
 
760
762
  it("should not touch an existing package.json in an ancestor directory, when a name is passed", async () => {
@@ -798,14 +800,14 @@ describe("init", () => {
798
800
  },
799
801
  });
800
802
  expect(std).toMatchInlineSnapshot(`
801
- Object {
802
- "debug": "",
803
- "err": "",
804
- "out": "✨ Created path/to/worker/my-worker/wrangler.toml
805
- ✨ Created path/to/worker/my-worker/package.json",
806
- "warn": "",
807
- }
808
- `);
803
+ Object {
804
+ "debug": "",
805
+ "err": "",
806
+ "out": "✨ Created path/to/worker/my-worker/wrangler.toml
807
+ ✨ Created path/to/worker/my-worker/package.json",
808
+ "warn": "",
809
+ }
810
+ `);
809
811
  });
810
812
 
811
813
  it("should offer to install wrangler into an existing package.json", async () => {
@@ -848,14 +850,14 @@ describe("init", () => {
848
850
  `wrangler@${wranglerVersion}`
849
851
  );
850
852
  expect(std).toMatchInlineSnapshot(`
851
- Object {
852
- "debug": "",
853
- "err": "",
854
- "out": "✨ Created wrangler.toml
855
- ✨ Installed wrangler into devDependencies",
856
- "warn": "",
857
- }
858
- `);
853
+ Object {
854
+ "debug": "",
855
+ "err": "",
856
+ "out": "✨ Created wrangler.toml
857
+ ✨ Installed wrangler into devDependencies",
858
+ "warn": "",
859
+ }
860
+ `);
859
861
  });
860
862
 
861
863
  it("should offer to install wrangler into a package.json relative to the target directory, if no name is provided", async () => {
@@ -902,14 +904,14 @@ describe("init", () => {
902
904
  );
903
905
  expect(mockPackageManager.cwd).toBe(process.cwd());
904
906
  expect(std).toMatchInlineSnapshot(`
905
- Object {
906
- "debug": "",
907
- "err": "",
908
- "out": "✨ Created wrangler.toml
909
- ✨ Installed wrangler into devDependencies",
910
- "warn": "",
911
- }
912
- `);
907
+ Object {
908
+ "debug": "",
909
+ "err": "",
910
+ "out": "✨ Created wrangler.toml
911
+ ✨ Installed wrangler into devDependencies",
912
+ "warn": "",
913
+ }
914
+ `);
913
915
  });
914
916
 
915
917
  it("should not touch an existing package.json in an ancestor directory", async () => {
@@ -951,13 +953,13 @@ describe("init", () => {
951
953
  },
952
954
  });
953
955
  expect(std).toMatchInlineSnapshot(`
954
- Object {
955
- "debug": "",
956
- "err": "",
957
- "out": "✨ Created wrangler.toml",
958
- "warn": "",
959
- }
960
- `);
956
+ Object {
957
+ "debug": "",
958
+ "err": "",
959
+ "out": "✨ Created wrangler.toml",
960
+ "warn": "",
961
+ }
962
+ `);
961
963
  });
962
964
  });
963
965
 
@@ -1002,17 +1004,17 @@ describe("init", () => {
1002
1004
  },
1003
1005
  });
1004
1006
  expect(std).toMatchInlineSnapshot(`
1005
- Object {
1006
- "debug": "",
1007
- "err": "",
1008
- "out": "✨ Created wrangler.toml
1009
- ✨ Created src/index.js
1010
-
1011
- To start developing your Worker, run \`npx wrangler dev\`
1012
- To publish your Worker to the Internet, run \`npx wrangler publish\`",
1013
- "warn": "",
1014
- }
1015
- `);
1007
+ Object {
1008
+ "debug": "",
1009
+ "err": "",
1010
+ "out": "✨ Created wrangler.toml
1011
+ ✨ Created src/index.js
1012
+
1013
+ To start developing your Worker, run \`npx wrangler dev\`
1014
+ To publish your Worker to the Internet, run \`npx wrangler publish\`",
1015
+ "warn": "",
1016
+ }
1017
+ `);
1016
1018
  });
1017
1019
 
1018
1020
  it("should offer to create a worker in a typescript project", async () => {
@@ -1051,19 +1053,19 @@ describe("init", () => {
1051
1053
  },
1052
1054
  });
1053
1055
  expect(std).toMatchInlineSnapshot(`
1054
- Object {
1055
- "debug": "",
1056
- "err": "",
1057
- "out": "✨ Created wrangler.toml
1058
- ✨ Created tsconfig.json
1059
- ✨ Created src/index.ts
1060
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1061
-
1062
- To start developing your Worker, run \`npx wrangler dev\`
1063
- To publish your Worker to the Internet, run \`npx wrangler publish\`",
1064
- "warn": "",
1065
- }
1066
- `);
1056
+ Object {
1057
+ "debug": "",
1058
+ "err": "",
1059
+ "out": "✨ Created wrangler.toml
1060
+ ✨ Created tsconfig.json
1061
+ ✨ Created src/index.ts
1062
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1063
+
1064
+ To start developing your Worker, run \`npx wrangler dev\`
1065
+ To publish your Worker to the Internet, run \`npx wrangler publish\`",
1066
+ "warn": "",
1067
+ }
1068
+ `);
1067
1069
  });
1068
1070
 
1069
1071
  it("should add scripts for a typescript project with .ts extension", async () => {
@@ -1109,15 +1111,15 @@ describe("init", () => {
1109
1111
  },
1110
1112
  });
1111
1113
  expect(std.out).toMatchInlineSnapshot(`
1112
- "✨ Created wrangler.toml
1113
- ✨ Created package.json
1114
- ✨ Created tsconfig.json
1115
- ✨ Created src/index.ts
1116
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1117
-
1118
- To start developing your Worker, run \`npm start\`
1119
- To publish your Worker to the Internet, run \`npm run deploy\`"
1120
- `);
1114
+ "✨ Created wrangler.toml
1115
+ ✨ Created package.json
1116
+ ✨ Created tsconfig.json
1117
+ ✨ Created src/index.ts
1118
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1119
+
1120
+ To start developing your Worker, run \`npm start\`
1121
+ To publish your Worker to the Internet, run \`npm run deploy\`"
1122
+ `);
1121
1123
  });
1122
1124
 
1123
1125
  it("should not overwrite package.json scripts for a typescript project", async () => {
@@ -1169,14 +1171,14 @@ describe("init", () => {
1169
1171
  },
1170
1172
  });
1171
1173
  expect(std.out).toMatchInlineSnapshot(`
1172
- "✨ Created wrangler.toml
1173
- ✨ Created tsconfig.json
1174
- ✨ Created src/index.ts
1175
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1176
-
1177
- To start developing your Worker, run \`npx wrangler dev\`
1178
- To publish your Worker to the Internet, run \`npx wrangler publish\`"
1179
- `);
1174
+ "✨ Created wrangler.toml
1175
+ ✨ Created tsconfig.json
1176
+ ✨ Created src/index.ts
1177
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1178
+
1179
+ To start developing your Worker, run \`npx wrangler dev\`
1180
+ To publish your Worker to the Internet, run \`npx wrangler publish\`"
1181
+ `);
1180
1182
  });
1181
1183
 
1182
1184
  it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
@@ -1211,15 +1213,15 @@ describe("init", () => {
1211
1213
  },
1212
1214
  });
1213
1215
  expect(std).toMatchInlineSnapshot(`
1214
- Object {
1215
- "debug": "",
1216
- "err": "",
1217
- "out": "✨ Created wrangler.toml
1218
- ✨ Created tsconfig.json
1219
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1220
- "warn": "",
1221
- }
1222
- `);
1216
+ Object {
1217
+ "debug": "",
1218
+ "err": "",
1219
+ "out": "✨ Created wrangler.toml
1220
+ ✨ Created tsconfig.json
1221
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1222
+ "warn": "",
1223
+ }
1224
+ `);
1223
1225
  });
1224
1226
 
1225
1227
  it("should not offer to create a worker in a ts project for a named worker if a file already exists at the location", async () => {
@@ -1258,16 +1260,16 @@ describe("init", () => {
1258
1260
  },
1259
1261
  });
1260
1262
  expect(std).toMatchInlineSnapshot(`
1261
- Object {
1262
- "debug": "",
1263
- "err": "",
1264
- "out": "✨ Created my-worker/wrangler.toml
1265
- ✨ Created my-worker/package.json
1266
- ✨ Created my-worker/tsconfig.json
1267
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1268
- "warn": "",
1269
- }
1270
- `);
1263
+ Object {
1264
+ "debug": "",
1265
+ "err": "",
1266
+ "out": "✨ Created my-worker/wrangler.toml
1267
+ ✨ Created my-worker/package.json
1268
+ ✨ Created my-worker/tsconfig.json
1269
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1270
+ "warn": "",
1271
+ }
1272
+ `);
1271
1273
  });
1272
1274
 
1273
1275
  it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
@@ -1311,16 +1313,16 @@ describe("init", () => {
1311
1313
  "typescript"
1312
1314
  );
1313
1315
  expect(std).toMatchInlineSnapshot(`
1314
- Object {
1315
- "debug": "",
1316
- "err": "",
1317
- "out": "✨ Created wrangler.toml
1318
- ✨ Created package.json
1319
- ✨ Created tsconfig.json
1320
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1321
- "warn": "",
1322
- }
1323
- `);
1316
+ Object {
1317
+ "debug": "",
1318
+ "err": "",
1319
+ "out": "✨ Created wrangler.toml
1320
+ ✨ Created package.json
1321
+ ✨ Created tsconfig.json
1322
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies",
1323
+ "warn": "",
1324
+ }
1325
+ `);
1324
1326
  });
1325
1327
 
1326
1328
  it("should not touch an existing tsconfig.json in the same directory", async () => {
@@ -1358,17 +1360,17 @@ describe("init", () => {
1358
1360
  },
1359
1361
  });
1360
1362
  expect(std).toMatchInlineSnapshot(`
1361
- Object {
1362
- "debug": "",
1363
- "err": "",
1364
- "out": "✨ Created wrangler.toml
1365
- ✨ Created src/index.ts
1366
-
1367
- To start developing your Worker, run \`npx wrangler dev\`
1368
- To publish your Worker to the Internet, run \`npx wrangler publish\`",
1369
- "warn": "",
1370
- }
1371
- `);
1363
+ Object {
1364
+ "debug": "",
1365
+ "err": "",
1366
+ "out": "✨ Created wrangler.toml
1367
+ ✨ Created src/index.ts
1368
+
1369
+ To start developing your Worker, run \`npx wrangler dev\`
1370
+ To publish your Worker to the Internet, run \`npx wrangler publish\`",
1371
+ "warn": "",
1372
+ }
1373
+ `);
1372
1374
  });
1373
1375
 
1374
1376
  it("should not touch an existing tsconfig.json in the ancestor of a target directory, if a name is passed", async () => {
@@ -1416,20 +1418,20 @@ describe("init", () => {
1416
1418
  },
1417
1419
  });
1418
1420
  expect(std).toMatchInlineSnapshot(`
1419
- Object {
1420
- "debug": "",
1421
- "err": "",
1422
- "out": "✨ Created path/to/worker/my-worker/wrangler.toml
1423
- ✨ Created path/to/worker/my-worker/package.json
1424
- ✨ Created path/to/worker/my-worker/tsconfig.json
1425
- ✨ Created path/to/worker/my-worker/src/index.ts
1426
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1427
-
1428
- To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
1429
- To publish your Worker to the Internet, run \`npm run deploy\`",
1430
- "warn": "",
1431
- }
1432
- `);
1421
+ Object {
1422
+ "debug": "",
1423
+ "err": "",
1424
+ "out": "✨ Created path/to/worker/my-worker/wrangler.toml
1425
+ ✨ Created path/to/worker/my-worker/package.json
1426
+ ✨ Created path/to/worker/my-worker/tsconfig.json
1427
+ ✨ Created path/to/worker/my-worker/src/index.ts
1428
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1429
+
1430
+ To start developing your Worker, run \`cd path/to/worker/my-worker && npm start\`
1431
+ To publish your Worker to the Internet, run \`npm run deploy\`",
1432
+ "warn": "",
1433
+ }
1434
+ `);
1433
1435
  });
1434
1436
 
1435
1437
  it("should offer to install type definitions in an existing typescript project", async () => {
@@ -1475,15 +1477,15 @@ describe("init", () => {
1475
1477
  "@cloudflare/workers-types"
1476
1478
  );
1477
1479
  expect(std).toMatchInlineSnapshot(`
1478
- Object {
1479
- "debug": "",
1480
- "err": "",
1481
- "out": "✨ Created wrangler.toml
1482
- ✨ Installed @cloudflare/workers-types into devDependencies
1483
- 🚨 Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
1484
- "warn": "",
1485
- }
1486
- `);
1480
+ Object {
1481
+ "debug": "",
1482
+ "err": "",
1483
+ "out": "✨ Created wrangler.toml
1484
+ ✨ Installed @cloudflare/workers-types into devDependencies
1485
+ 🚨 Please add \\"@cloudflare/workers-types\\" to compilerOptions.types in tsconfig.json",
1486
+ "warn": "",
1487
+ }
1488
+ `);
1487
1489
  });
1488
1490
 
1489
1491
  it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
@@ -1523,17 +1525,17 @@ describe("init", () => {
1523
1525
  },
1524
1526
  });
1525
1527
  expect(std).toMatchInlineSnapshot(`
1526
- Object {
1527
- "debug": "",
1528
- "err": "",
1529
- "out": "✨ Created wrangler.toml
1530
- ✨ Created src/index.ts
1531
-
1532
- To start developing your Worker, run \`npx wrangler dev\`
1533
- To publish your Worker to the Internet, run \`npx wrangler publish\`",
1534
- "warn": "",
1535
- }
1536
- `);
1528
+ Object {
1529
+ "debug": "",
1530
+ "err": "",
1531
+ "out": "✨ Created wrangler.toml
1532
+ ✨ Created src/index.ts
1533
+
1534
+ To start developing your Worker, run \`npx wrangler dev\`
1535
+ To publish your Worker to the Internet, run \`npx wrangler publish\`",
1536
+ "warn": "",
1537
+ }
1538
+ `);
1537
1539
  });
1538
1540
  });
1539
1541
 
@@ -1581,13 +1583,13 @@ describe("init", () => {
1581
1583
  },
1582
1584
  });
1583
1585
  expect(std.out).toMatchInlineSnapshot(`
1584
- "✨ Created wrangler.toml
1585
- ✨ Created package.json
1586
- ✨ Created src/index.js
1586
+ "✨ Created wrangler.toml
1587
+ ✨ Created package.json
1588
+ ✨ Created src/index.js
1587
1589
 
1588
- To start developing your Worker, run \`npm start\`
1589
- To publish your Worker to the Internet, run \`npm run deploy\`"
1590
- `);
1590
+ To start developing your Worker, run \`npm start\`
1591
+ To publish your Worker to the Internet, run \`npm run deploy\`"
1592
+ `);
1591
1593
  });
1592
1594
 
1593
1595
  it("should not overwrite package.json scripts for a non-ts project with .js extension", async () => {
@@ -1639,12 +1641,12 @@ describe("init", () => {
1639
1641
  },
1640
1642
  });
1641
1643
  expect(std.out).toMatchInlineSnapshot(`
1642
- "✨ Created wrangler.toml
1643
- ✨ Created src/index.js
1644
+ "✨ Created wrangler.toml
1645
+ ✨ Created src/index.js
1644
1646
 
1645
- To start developing your Worker, run \`npx wrangler dev\`
1646
- To publish your Worker to the Internet, run \`npx wrangler publish\`"
1647
- `);
1647
+ To start developing your Worker, run \`npx wrangler dev\`
1648
+ To publish your Worker to the Internet, run \`npx wrangler publish\`"
1649
+ `);
1648
1650
  });
1649
1651
 
1650
1652
  it("should not offer to create a worker in a non-ts project if a file already exists at the location", async () => {
@@ -1679,13 +1681,13 @@ describe("init", () => {
1679
1681
  },
1680
1682
  });
1681
1683
  expect(std).toMatchInlineSnapshot(`
1682
- Object {
1683
- "debug": "",
1684
- "err": "",
1685
- "out": "✨ Created wrangler.toml",
1686
- "warn": "",
1687
- }
1688
- `);
1684
+ Object {
1685
+ "debug": "",
1686
+ "err": "",
1687
+ "out": "✨ Created wrangler.toml",
1688
+ "warn": "",
1689
+ }
1690
+ `);
1689
1691
  });
1690
1692
 
1691
1693
  it("should not offer to create a worker in a non-ts named worker project if a file already exists at the location", async () => {
@@ -1722,13 +1724,13 @@ describe("init", () => {
1722
1724
  },
1723
1725
  });
1724
1726
  expect(std).toMatchInlineSnapshot(`
1725
- Object {
1726
- "debug": "",
1727
- "err": "",
1728
- "out": "✨ Created my-worker/wrangler.toml",
1729
- "warn": "",
1730
- }
1731
- `);
1727
+ Object {
1728
+ "debug": "",
1729
+ "err": "",
1730
+ "out": "✨ Created my-worker/wrangler.toml",
1731
+ "warn": "",
1732
+ }
1733
+ `);
1732
1734
  });
1733
1735
  });
1734
1736
 
@@ -1759,21 +1761,21 @@ describe("init", () => {
1759
1761
  },
1760
1762
  });
1761
1763
  expect(std).toMatchInlineSnapshot(`
1762
- Object {
1763
- "debug": "",
1764
- "err": "",
1765
- "out": "✨ Created wrangler.toml
1766
- ✨ Initialized git repository
1767
- ✨ Created package.json
1768
- ✨ Created tsconfig.json
1769
- ✨ Created src/index.ts
1770
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1771
-
1772
- To start developing your Worker, run \`npm start\`
1773
- To publish your Worker to the Internet, run \`npm run deploy\`",
1774
- "warn": "",
1775
- }
1776
- `);
1764
+ Object {
1765
+ "debug": "",
1766
+ "err": "",
1767
+ "out": "✨ Created wrangler.toml
1768
+ ✨ Initialized git repository
1769
+ ✨ Created package.json
1770
+ ✨ Created tsconfig.json
1771
+ ✨ Created src/index.ts
1772
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1773
+
1774
+ To start developing your Worker, run \`npm start\`
1775
+ To publish your Worker to the Internet, run \`npm run deploy\`",
1776
+ "warn": "",
1777
+ }
1778
+ `);
1777
1779
  });
1778
1780
 
1779
1781
  it('should create a worker in a nested directory if "name" is path/to/worker', async () => {
@@ -1788,21 +1790,21 @@ describe("init", () => {
1788
1790
  },
1789
1791
  });
1790
1792
  expect(std).toMatchInlineSnapshot(`
1791
- Object {
1792
- "debug": "",
1793
- "err": "",
1794
- "out": "✨ Created path/to/worker/wrangler.toml
1795
- ✨ Initialized git repository at path/to/worker
1796
- ✨ Created path/to/worker/package.json
1797
- ✨ Created path/to/worker/tsconfig.json
1798
- ✨ Created path/to/worker/src/index.ts
1799
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1800
-
1801
- To start developing your Worker, run \`cd path/to/worker && npm start\`
1802
- To publish your Worker to the Internet, run \`npm run deploy\`",
1803
- "warn": "",
1804
- }
1805
- `);
1793
+ Object {
1794
+ "debug": "",
1795
+ "err": "",
1796
+ "out": "✨ Created path/to/worker/wrangler.toml
1797
+ ✨ Initialized git repository at path/to/worker
1798
+ ✨ Created path/to/worker/package.json
1799
+ ✨ Created path/to/worker/tsconfig.json
1800
+ ✨ Created path/to/worker/src/index.ts
1801
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1802
+
1803
+ To start developing your Worker, run \`cd path/to/worker && npm start\`
1804
+ To publish your Worker to the Internet, run \`npm run deploy\`",
1805
+ "warn": "",
1806
+ }
1807
+ `);
1806
1808
  });
1807
1809
 
1808
1810
  it("should normalize characters that aren't lowercase alphanumeric, underscores, or dashes", async () => {
@@ -1817,21 +1819,21 @@ describe("init", () => {
1817
1819
  },
1818
1820
  });
1819
1821
  expect(std).toMatchInlineSnapshot(`
1820
- Object {
1821
- "debug": "",
1822
- "err": "",
1823
- "out": "✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml
1824
- ✨ Initialized git repository at WEIRD_w0rkr_N4m3.js.tsx.tar.gz
1825
- ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/package.json
1826
- ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json
1827
- ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/src/index.ts
1828
- ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1829
-
1830
- To start developing your Worker, run \`cd WEIRD_w0rkr_N4m3.js.tsx.tar.gz && npm start\`
1831
- To publish your Worker to the Internet, run \`npm run deploy\`",
1832
- "warn": "",
1833
- }
1834
- `);
1822
+ Object {
1823
+ "debug": "",
1824
+ "err": "",
1825
+ "out": "✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/wrangler.toml
1826
+ ✨ Initialized git repository at WEIRD_w0rkr_N4m3.js.tsx.tar.gz
1827
+ ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/package.json
1828
+ ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/tsconfig.json
1829
+ ✨ Created WEIRD_w0rkr_N4m3.js.tsx.tar.gz/src/index.ts
1830
+ ✨ Installed @cloudflare/workers-types and typescript into devDependencies
1831
+
1832
+ To start developing your Worker, run \`cd WEIRD_w0rkr_N4m3.js.tsx.tar.gz && npm start\`
1833
+ To publish your Worker to the Internet, run \`npm run deploy\`",
1834
+ "warn": "",
1835
+ }
1836
+ `);
1835
1837
  });
1836
1838
 
1837
1839
  it("should ignore ancestor files (such as wrangler.toml, package.json and tsconfig.json) if a name/path is given", async () => {
@@ -1900,6 +1902,182 @@ describe("init", () => {
1900
1902
  });
1901
1903
  });
1902
1904
  });
1905
+
1906
+ describe("from dashboard", () => {
1907
+ mockApiToken();
1908
+ mockAccountId({ accountId: "LCARS" });
1909
+ afterEach(() => {
1910
+ unsetAllMocks();
1911
+ });
1912
+ const mockDashboardScript = `
1913
+ export default {
1914
+ async fetch(request, env, ctx) {
1915
+ return new Response("Hello World!");
1916
+ },
1917
+ };
1918
+ `;
1919
+
1920
+ //TODO: Tests for a case when a worker name doesn't exist - JACOB & CASS
1921
+ it("should download source script from dashboard w/ positional <name> in TypeScript project", async () => {
1922
+ setMockFetchDashScript({
1923
+ accountId: "LCARS",
1924
+ fromDashScriptName: "memory-crystal",
1925
+ mockResponse: mockDashboardScript,
1926
+ });
1927
+ mockConfirm(
1928
+ {
1929
+ text: "Would you like to use git to manage this Worker?",
1930
+ result: false,
1931
+ },
1932
+ {
1933
+ text: "Would you like to use TypeScript?",
1934
+ result: true,
1935
+ },
1936
+ {
1937
+ text: "No package.json found. Would you like to create one?",
1938
+ result: true,
1939
+ },
1940
+ {
1941
+ text: "Would you like to install the type definitions for Workers into your package.json?",
1942
+ result: true,
1943
+ }
1944
+ );
1945
+
1946
+ await runWrangler(
1947
+ "init isolinear-optical-chip --from-dash memory-crystal"
1948
+ );
1949
+
1950
+ checkFiles({
1951
+ items: {
1952
+ "isolinear-optical-chip/src/index.js": false,
1953
+ "isolinear-optical-chip/src/index.ts": {
1954
+ contents: mockDashboardScript,
1955
+ },
1956
+ "isolinear-optical-chip/package.json": {
1957
+ contents: expect.objectContaining({
1958
+ name: "isolinear-optical-chip",
1959
+ }),
1960
+ },
1961
+ "isolinear-optical-chip/tsconfig.json": true,
1962
+ "isolinear-optical-chip/wrangler.toml": wranglerToml({
1963
+ ...MINIMAL_WRANGLER_TOML,
1964
+ name: "isolinear-optical-chip",
1965
+ }),
1966
+ },
1967
+ });
1968
+ });
1969
+
1970
+ it("should download source script from dashboard w/ out positional <name>", async () => {
1971
+ setMockFetchDashScript({
1972
+ accountId: "LCARS",
1973
+ fromDashScriptName: "isolinear-optical-chip",
1974
+ mockResponse: mockDashboardScript,
1975
+ });
1976
+ mockConfirm(
1977
+ {
1978
+ text: "Would you like to use git to manage this Worker?",
1979
+ result: false,
1980
+ },
1981
+ {
1982
+ text: "Would you like to use TypeScript?",
1983
+ result: true,
1984
+ },
1985
+ {
1986
+ text: "No package.json found. Would you like to create one?",
1987
+ result: true,
1988
+ },
1989
+ {
1990
+ text: "Would you like to install the type definitions for Workers into your package.json?",
1991
+ result: true,
1992
+ }
1993
+ );
1994
+
1995
+ await runWrangler("init --from-dash isolinear-optical-chip");
1996
+
1997
+ checkFiles({
1998
+ items: {
1999
+ "isolinear-optical-chip/src/index.js": false,
2000
+ "isolinear-optical-chip/src/index.ts": {
2001
+ contents: mockDashboardScript,
2002
+ },
2003
+ "isolinear-optical-chip/package.json": {
2004
+ contents: expect.objectContaining({
2005
+ name: "isolinear-optical-chip",
2006
+ }),
2007
+ },
2008
+ "isolinear-optical-chip/tsconfig.json": true,
2009
+ "isolinear-optical-chip/wrangler.toml": wranglerToml({
2010
+ ...MINIMAL_WRANGLER_TOML,
2011
+ name: "isolinear-optical-chip",
2012
+ }),
2013
+ },
2014
+ });
2015
+ });
2016
+
2017
+ it("should download source script from dashboard as plain JavaScript", async () => {
2018
+ setMockFetchDashScript({
2019
+ accountId: "LCARS",
2020
+ fromDashScriptName: "isolinear-optical-chip",
2021
+ mockResponse: mockDashboardScript,
2022
+ });
2023
+ mockConfirm(
2024
+ {
2025
+ text: "Would you like to use git to manage this Worker?",
2026
+ result: false,
2027
+ },
2028
+ {
2029
+ text: "Would you like to use TypeScript?",
2030
+ result: false,
2031
+ },
2032
+ {
2033
+ text: "No package.json found. Would you like to create one?",
2034
+ result: true,
2035
+ },
2036
+ {
2037
+ text: "Would you like to install the type definitions for Workers into your package.json?",
2038
+ result: true,
2039
+ }
2040
+ );
2041
+
2042
+ await runWrangler("init --from-dash isolinear-optical-chip");
2043
+
2044
+ checkFiles({
2045
+ items: {
2046
+ "isolinear-optical-chip/src/index.js": {
2047
+ contents: mockDashboardScript,
2048
+ },
2049
+ "isolinear-optical-chip/src/index.ts": false,
2050
+ "isolinear-optical-chip/package.json": {
2051
+ contents: expect.objectContaining({
2052
+ name: "isolinear-optical-chip",
2053
+ }),
2054
+ },
2055
+ "isolinear-optical-chip/tsconfig.json": false,
2056
+ "isolinear-optical-chip/wrangler.toml": wranglerToml({
2057
+ ...MINIMAL_WRANGLER_TOML,
2058
+ name: "isolinear-optical-chip",
2059
+ }),
2060
+ },
2061
+ });
2062
+ });
2063
+
2064
+ it("should not continue if no worker name is provided", async () => {
2065
+ await expect(
2066
+ runWrangler("init --from-dash")
2067
+ ).rejects.toMatchInlineSnapshot(
2068
+ `[YError: Not enough arguments following: from-dash]`
2069
+ );
2070
+ checkFiles({
2071
+ items: {
2072
+ "isolinear-optical-chip/src/index.js": false,
2073
+ "isolinear-optical-chip/src/index.ts": false,
2074
+ "isolinear-optical-chip/package.json": false,
2075
+ "isolinear-optical-chip/tsconfig.json": false,
2076
+ "isolinear-optical-chip/wrangler.toml": false,
2077
+ },
2078
+ });
2079
+ });
2080
+ });
1903
2081
  });
1904
2082
 
1905
2083
  /**