wrangler 2.0.23 → 2.0.26

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 (80) hide show
  1. package/README.md +20 -2
  2. package/bin/wrangler.js +1 -1
  3. package/miniflare-dist/index.mjs +235 -47
  4. package/package.json +11 -6
  5. package/src/__tests__/configuration.test.ts +89 -17
  6. package/src/__tests__/dev.test.tsx +29 -4
  7. package/src/__tests__/generate.test.ts +93 -0
  8. package/src/__tests__/helpers/mock-cfetch.ts +87 -2
  9. package/src/__tests__/index.test.ts +10 -27
  10. package/src/__tests__/init.test.ts +537 -359
  11. package/src/__tests__/jest.setup.ts +34 -1
  12. package/src/__tests__/kv.test.ts +2 -2
  13. package/src/__tests__/metrics.test.ts +5 -0
  14. package/src/__tests__/pages.test.ts +14 -0
  15. package/src/__tests__/publish.test.ts +497 -254
  16. package/src/__tests__/r2.test.ts +173 -71
  17. package/src/__tests__/tail.test.ts +112 -42
  18. package/src/__tests__/user.test.ts +1 -0
  19. package/src/__tests__/validate-dev-props.test.ts +56 -0
  20. package/src/__tests__/whoami.test.tsx +60 -1
  21. package/src/api/dev.ts +7 -0
  22. package/src/bundle.ts +279 -44
  23. package/src/cfetch/internal.ts +73 -2
  24. package/src/config/config.ts +8 -3
  25. package/src/config/environment.ts +40 -8
  26. package/src/config/index.ts +13 -0
  27. package/src/config/validation.ts +102 -8
  28. package/src/create-worker-upload-form.ts +25 -0
  29. package/src/dev/dev.tsx +121 -28
  30. package/src/dev/local.tsx +88 -14
  31. package/src/dev/remote.tsx +39 -8
  32. package/src/dev/use-esbuild.ts +28 -0
  33. package/src/dev/validate-dev-props.ts +31 -0
  34. package/src/dev-registry.tsx +160 -0
  35. package/src/dev.tsx +107 -80
  36. package/src/generate.ts +112 -14
  37. package/src/index.tsx +212 -4
  38. package/src/init.ts +111 -38
  39. package/src/inspect.ts +90 -5
  40. package/src/metrics/index.ts +1 -0
  41. package/src/metrics/metrics-dispatcher.ts +1 -0
  42. package/src/metrics/metrics-usage-headers.ts +24 -0
  43. package/src/metrics/send-event.ts +2 -2
  44. package/src/miniflare-cli/assets.ts +27 -16
  45. package/src/miniflare-cli/index.ts +124 -2
  46. package/src/module-collection.ts +3 -3
  47. package/src/pages/build.tsx +75 -41
  48. package/src/pages/constants.ts +5 -0
  49. package/src/pages/deployments.tsx +10 -10
  50. package/src/pages/dev.tsx +177 -52
  51. package/src/pages/errors.ts +22 -0
  52. package/src/pages/functions/buildPlugin.ts +4 -0
  53. package/src/pages/functions/buildWorker.ts +4 -0
  54. package/src/pages/functions/routes-consolidation.test.ts +250 -0
  55. package/src/pages/functions/routes-consolidation.ts +73 -0
  56. package/src/pages/functions/routes-transformation.test.ts +271 -0
  57. package/src/pages/functions/routes-transformation.ts +122 -0
  58. package/src/pages/functions.tsx +96 -0
  59. package/src/pages/index.tsx +65 -55
  60. package/src/pages/projects.tsx +9 -3
  61. package/src/pages/publish.tsx +76 -23
  62. package/src/pages/types.ts +9 -0
  63. package/src/pages/upload.tsx +38 -21
  64. package/src/publish.ts +126 -112
  65. package/src/r2.ts +81 -0
  66. package/src/tail/filters.ts +3 -1
  67. package/src/tail/index.ts +15 -2
  68. package/src/tail/printing.ts +43 -3
  69. package/src/user/user.tsx +20 -2
  70. package/src/whoami.tsx +79 -1
  71. package/src/worker.ts +12 -0
  72. package/templates/first-party-worker-module-facade.ts +18 -0
  73. package/templates/format-dev-errors.ts +32 -0
  74. package/templates/pages-template-plugin.ts +16 -4
  75. package/templates/pages-template-worker.ts +16 -5
  76. package/templates/{static-asset-facade.js → serve-static-assets.ts} +21 -7
  77. package/templates/service-bindings-module-facade.js +54 -0
  78. package/templates/service-bindings-sw-facade.js +42 -0
  79. package/wrangler-dist/cli.d.ts +7 -0
  80. package/wrangler-dist/cli.js +40851 -15332
@@ -1,11 +1,18 @@
1
1
  import fetchMock from "jest-fetch-mock";
2
2
  import {
3
+ fetchDashboardScript,
3
4
  fetchInternal,
4
5
  fetchKVGetValue,
6
+ fetchR2Objects,
5
7
  getCloudflareAPIBaseURL,
6
8
  } from "../cfetch/internal";
7
9
  import { confirm, prompt } from "../dialogs";
8
- import { mockFetchInternal, mockFetchKVGetValue } from "./helpers/mock-cfetch";
10
+ import {
11
+ mockFetchDashScript,
12
+ mockFetchInternal,
13
+ mockFetchKVGetValue,
14
+ mockFetchR2Objects,
15
+ } from "./helpers/mock-cfetch";
9
16
  import { MockWebSocket } from "./helpers/mock-web-socket";
10
17
 
11
18
  // Mock out getPort since we don't actually care about what ports are open in unit tests.
@@ -43,6 +50,8 @@ jest.mock("../cfetch/internal");
43
50
  (getCloudflareAPIBaseURL as jest.Mock).mockReturnValue(
44
51
  "https://api.cloudflare.com/client/v4"
45
52
  );
53
+ (fetchR2Objects as jest.Mock).mockImplementation(mockFetchR2Objects);
54
+ (fetchDashboardScript as jest.Mock).mockImplementation(mockFetchDashScript);
46
55
 
47
56
  jest.mock("../dialogs");
48
57
 
@@ -118,3 +127,27 @@ jest.mock("xdg-app-paths", () => {
118
127
  }),
119
128
  };
120
129
  });
130
+
131
+ jest.mock("create-cloudflare");
132
+
133
+ jest.mock("../metrics/metrics-config", () => {
134
+ const realModule = jest.requireActual("../metrics/metrics-config");
135
+ const fakeModule = {
136
+ ...realModule,
137
+ // Although we mock out the getMetricsConfig() function in most tests,
138
+ // we need a way to reinstate it for the metrics specific tests.
139
+ // This is what `useOriginal` is for.
140
+ useOriginal: false,
141
+ getMetricsConfig: (...args: unknown[]) =>
142
+ fakeModule.useOriginal
143
+ ? realModule.getMetricsConfig(...args)
144
+ : async () => {
145
+ return {
146
+ enabled: false,
147
+ deviceId: "mock-device",
148
+ userId: undefined,
149
+ };
150
+ },
151
+ };
152
+ return fakeModule;
153
+ });
@@ -4,7 +4,7 @@ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
4
4
  import {
5
5
  setMockResponse,
6
6
  unsetAllMocks,
7
- unsetMockFetchKVGetValues,
7
+ unsetSpecialMockFns,
8
8
  setMockFetchKVGetValue,
9
9
  setMockRawResponse,
10
10
  createFetchResult,
@@ -924,7 +924,7 @@ describe("wrangler", () => {
924
924
 
925
925
  describe("get", () => {
926
926
  afterEach(() => {
927
- unsetMockFetchKVGetValues();
927
+ unsetSpecialMockFns();
928
928
  });
929
929
 
930
930
  it("should get a key in a given namespace specified by namespace-id", async () => {
@@ -26,6 +26,9 @@ describe("metrics", () => {
26
26
  runInTempDir();
27
27
 
28
28
  beforeEach(() => {
29
+ // Tell jest to use the original version of the `getMetricsConfig()` function in these tests.
30
+ const mockMetricsConfig = jest.requireMock("../metrics/metrics-config");
31
+ mockMetricsConfig.useOriginal = true;
29
32
  global.SPARROW_SOURCE_KEY = "MOCK_KEY";
30
33
  logger.loggerLevel = "debug";
31
34
  // Create a node_modules directory to store config-cache files
@@ -65,6 +68,7 @@ describe("metrics", () => {
65
68
  properties: {
66
69
  category: "Workers",
67
70
  wranglerVersion,
71
+ os: process.platform + ":" + process.arch,
68
72
  a: 1,
69
73
  b: 2,
70
74
  },
@@ -139,6 +143,7 @@ describe("metrics", () => {
139
143
  properties: {
140
144
  category: "Workers",
141
145
  wranglerVersion,
146
+ os: process.platform + ":" + process.arch,
142
147
  a: 1,
143
148
  b: 2,
144
149
  },
@@ -97,6 +97,20 @@ describe("pages", () => {
97
97
  expect(std.out).toMatchInlineSnapshot(`
98
98
  "🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
99
99
 
100
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
101
+ `);
102
+ });
103
+
104
+ it("should display for pages:functions:optimize-routes", async () => {
105
+ await expect(
106
+ runWrangler(
107
+ 'pages functions optimize-routes --routes-path="/build/_routes.json" --output-routes-path="/build/_optimized-routes.json"'
108
+ )
109
+ ).rejects.toThrowError();
110
+
111
+ expect(std.out).toMatchInlineSnapshot(`
112
+ "🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
113
+
100
114
  If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
101
115
  `);
102
116
  });