wrangler 0.0.0-e22f9d7 → 0.0.0-e452a04

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 (95) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +31 -15
  3. package/pages/functions/buildWorker.ts +1 -1
  4. package/pages/functions/filepath-routing.test.ts +112 -28
  5. package/pages/functions/filepath-routing.ts +88 -131
  6. package/pages/functions/routes.ts +11 -18
  7. package/pages/functions/template-worker.ts +19 -33
  8. package/src/__tests__/configuration.test.ts +2217 -0
  9. package/src/__tests__/dev.test.tsx +397 -59
  10. package/src/__tests__/dev2.test.tsx +152 -0
  11. package/src/__tests__/guess-worker-format.test.ts +58 -0
  12. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  13. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  14. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  15. package/src/__tests__/helpers/mock-account-id.ts +44 -0
  16. package/src/__tests__/helpers/mock-bin.ts +36 -0
  17. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +52 -16
  18. package/src/__tests__/helpers/mock-console.ts +70 -0
  19. package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
  20. package/src/__tests__/helpers/mock-kv.ts +40 -0
  21. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  22. package/src/__tests__/helpers/mock-user.ts +27 -0
  23. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  24. package/src/__tests__/helpers/run-in-tmp.ts +29 -0
  25. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  26. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  27. package/src/__tests__/https-options.test.ts +127 -0
  28. package/src/__tests__/index.test.ts +779 -75
  29. package/src/__tests__/jest.setup.ts +53 -6
  30. package/src/__tests__/kv.test.ts +734 -437
  31. package/src/__tests__/logout.test.ts +50 -0
  32. package/src/__tests__/package-manager.test.ts +206 -0
  33. package/src/__tests__/pages.test.ts +44 -0
  34. package/src/__tests__/parse.test.ts +322 -0
  35. package/src/__tests__/publish.test.ts +2252 -0
  36. package/src/__tests__/r2.test.ts +198 -0
  37. package/src/__tests__/route.test.ts +45 -0
  38. package/src/__tests__/secret.test.ts +425 -0
  39. package/src/__tests__/sentry.test.ts +146 -0
  40. package/src/__tests__/tail.test.ts +564 -0
  41. package/src/__tests__/whoami.test.tsx +86 -0
  42. package/src/bundle.ts +142 -0
  43. package/src/cfetch/index.ts +21 -19
  44. package/src/cfetch/internal.ts +84 -18
  45. package/src/cli.ts +10 -0
  46. package/src/config/README.md +107 -0
  47. package/src/config/config.ts +279 -0
  48. package/src/config/diagnostics.ts +80 -0
  49. package/src/config/environment.ts +305 -0
  50. package/src/config/index.ts +52 -0
  51. package/src/config/validation-helpers.ts +388 -0
  52. package/src/config/validation.ts +1027 -0
  53. package/src/{api/preview.ts → create-worker-preview.ts} +61 -23
  54. package/src/create-worker-upload-form.ts +217 -0
  55. package/src/dev/dev.tsx +357 -0
  56. package/src/dev/local.tsx +241 -0
  57. package/src/dev/remote.tsx +201 -0
  58. package/src/dev/use-esbuild.ts +100 -0
  59. package/src/dialogs.tsx +2 -2
  60. package/src/entry.ts +159 -0
  61. package/src/environment-variables.ts +33 -0
  62. package/src/https-options.ts +122 -0
  63. package/src/index.tsx +1145 -790
  64. package/src/inspect.ts +103 -25
  65. package/src/{kv.tsx → kv/index.tsx} +119 -56
  66. package/src/module-collection.ts +215 -26
  67. package/src/open-in-browser.ts +25 -0
  68. package/src/package-manager.ts +126 -0
  69. package/src/pages.tsx +49 -35
  70. package/src/parse.ts +183 -0
  71. package/src/paths.ts +26 -0
  72. package/src/proxy.ts +175 -39
  73. package/src/publish.ts +288 -300
  74. package/src/r2.ts +50 -0
  75. package/src/reporting.ts +131 -0
  76. package/src/selfsigned.d.ts +29 -0
  77. package/src/sites.tsx +181 -61
  78. package/src/tail/filters.ts +279 -0
  79. package/src/tail/index.ts +299 -0
  80. package/src/tail/printing.ts +62 -0
  81. package/src/user.tsx +141 -103
  82. package/src/whoami.tsx +69 -0
  83. package/src/{api/worker.ts → worker.ts} +45 -37
  84. package/templates/new-worker.js +15 -0
  85. package/templates/new-worker.ts +15 -0
  86. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  87. package/templates/tsconfig.json +105 -0
  88. package/wrangler-dist/cli.js +128965 -112680
  89. package/wrangler-dist/cli.js.map +3 -3
  90. package/src/__tests__/run-in-tmp.ts +0 -19
  91. package/src/__tests__/run-wrangler.ts +0 -32
  92. package/src/api/form_data.ts +0 -131
  93. package/src/config.ts +0 -487
  94. package/src/dev.tsx +0 -784
  95. package/src/tail.tsx +0 -73
@@ -22,7 +22,7 @@ declare type PagesFunction<
22
22
 
23
23
  type RouteHandler = {
24
24
  routePath: string;
25
- methods: HTTPMethod[];
25
+ method?: HTTPMethod;
26
26
  modules: PagesFunction[];
27
27
  middlewares: PagesFunction[];
28
28
  };
@@ -33,25 +33,21 @@ declare const routes: RouteHandler[];
33
33
  declare const __FALLBACK_SERVICE__: string;
34
34
 
35
35
  // expect an ASSETS fetcher binding pointing to the asset-server stage
36
- type Env = {
37
- [name: string]: unknown;
38
- ASSETS: { fetch(url: string, init: RequestInit): Promise<Response> };
36
+ type FetchEnv = {
37
+ [name: string]: { fetch: typeof fetch };
38
+ ASSETS: { fetch: typeof fetch };
39
39
  };
40
40
 
41
41
  type WorkerContext = {
42
42
  waitUntil: (promise: Promise<unknown>) => void;
43
43
  };
44
44
 
45
- // eslint-disable-next-line @typescript-eslint/no-unused-vars -- `env` can be used by __FALLBACK_SERVICE_FETCH__
46
- function* executeRequest(request: Request, env: Env) {
45
+ function* executeRequest(request: Request, _env: FetchEnv) {
47
46
  const requestPath = new URL(request.url).pathname;
48
47
 
49
48
  // First, iterate through the routes (backwards) and execute "middlewares" on partial route matches
50
49
  for (const route of [...routes].reverse()) {
51
- if (
52
- route.methods.length &&
53
- !route.methods.includes(request.method as HTTPMethod)
54
- ) {
50
+ if (route.method && route.method !== request.method) {
55
51
  continue;
56
52
  }
57
53
 
@@ -69,10 +65,7 @@ function* executeRequest(request: Request, env: Env) {
69
65
 
70
66
  // Then look for the first exact route match and execute its "modules"
71
67
  for (const route of routes) {
72
- if (
73
- route.methods.length &&
74
- !route.methods.includes(request.method as HTTPMethod)
75
- ) {
68
+ if (route.method && route.method !== request.method) {
76
69
  continue;
77
70
  }
78
71
 
@@ -88,20 +81,10 @@ function* executeRequest(request: Request, env: Env) {
88
81
  break;
89
82
  }
90
83
  }
91
-
92
- // Finally, yield to the fallback service (`env.ASSETS.fetch` in Pages' case)
93
- return {
94
- handler: () =>
95
- __FALLBACK_SERVICE__
96
- ? // @ts-expect-error expecting __FALLBACK_SERVICE__ to be the name of a service binding, so fetch should be defined
97
- env[__FALLBACK_SERVICE__].fetch(request)
98
- : fetch(request),
99
- params: {} as Params,
100
- };
101
84
  }
102
85
 
103
86
  export default {
104
- async fetch(request: Request, env: Env, workerContext: WorkerContext) {
87
+ async fetch(request: Request, env: FetchEnv, workerContext: WorkerContext) {
105
88
  const handlerIterator = executeRequest(request, env);
106
89
  const data = {}; // arbitrary data the user can set between functions
107
90
  const next = async (input?: RequestInfo, init?: RequestInit) => {
@@ -109,14 +92,11 @@ export default {
109
92
  request = new Request(input, init);
110
93
  }
111
94
 
112
- const { value } = handlerIterator.next();
113
- if (value) {
114
- const { handler, params } = value;
115
- const context: EventContext<
116
- unknown,
117
- string,
118
- Record<string, unknown>
119
- > = {
95
+ const result = handlerIterator.next();
96
+ // Note we can't use `!result.done` because this doesn't narrow to the correct type
97
+ if (result.done == false) {
98
+ const { handler, params } = result.value;
99
+ const context = {
120
100
  request: new Request(request.clone()),
121
101
  next,
122
102
  params,
@@ -132,6 +112,12 @@ export default {
132
112
  [101, 204, 205, 304].includes(response.status) ? null : response.body,
133
113
  response
134
114
  );
115
+ } else if (__FALLBACK_SERVICE__) {
116
+ // There are no more handlers so finish with the fallback service (`env.ASSETS.fetch` in Pages' case)
117
+ return env[__FALLBACK_SERVICE__].fetch(request);
118
+ } else {
119
+ // There was not fallback service so actually make the request to the origin.
120
+ return fetch(request);
135
121
  }
136
122
  };
137
123