wrangler 0.0.0-fe5dcfd → 0.0.0-ff53f4e

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 (94) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +28 -15
  3. package/pages/functions/buildWorker.ts +1 -1
  4. package/pages/functions/filepath-routing.test.ts +212 -28
  5. package/pages/functions/filepath-routing.ts +83 -130
  6. package/pages/functions/routes.ts +11 -18
  7. package/pages/functions/template-worker.ts +3 -9
  8. package/src/__tests__/configuration.test.ts +2237 -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} +46 -12
  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 +33 -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 +777 -75
  29. package/src/__tests__/jest.setup.ts +53 -6
  30. package/src/__tests__/kv.test.ts +662 -480
  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 +2218 -338
  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 +7 -51
  42. package/src/bundle.ts +142 -0
  43. package/src/cfetch/index.ts +13 -19
  44. package/src/cfetch/internal.ts +88 -20
  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 +1122 -768
  64. package/src/inspect.ts +95 -21
  65. package/src/{kv.tsx → kv.ts} +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 +30 -25
  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 +282 -310
  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 +77 -48
  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 +106 -60
  82. package/src/{api/worker.ts → worker.ts} +45 -37
  83. package/templates/new-worker.js +15 -0
  84. package/templates/new-worker.ts +15 -0
  85. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  86. package/templates/tsconfig.json +105 -0
  87. package/wrangler-dist/cli.js +128970 -113025
  88. package/wrangler-dist/cli.js.map +3 -3
  89. package/src/__tests__/run-in-tmp.ts +0 -19
  90. package/src/__tests__/run-wrangler.ts +0 -32
  91. package/src/api/form_data.ts +0 -131
  92. package/src/config.ts +0 -646
  93. package/src/dev.tsx +0 -779
  94. package/src/tail.tsx +0 -73
@@ -1,6 +1,7 @@
1
- import path from "path";
2
- import fs from "fs/promises";
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
3
  import { isValidIdentifier, normalizeIdentifier } from "./identifiers";
4
+ import type { UrlPath } from "../../src/paths";
4
5
 
5
6
  export const HTTP_METHODS = [
6
7
  "HEAD",
@@ -19,22 +20,20 @@ export function isHTTPMethod(
19
20
  }
20
21
 
21
22
  export type RoutesCollection = Array<{
22
- routePath: string;
23
- methods: HTTPMethod[];
23
+ routePath: UrlPath;
24
+ method?: HTTPMethod;
24
25
  modules: string[];
25
26
  middlewares: string[];
26
27
  }>;
27
28
 
28
29
  export type Config = {
29
- routes?: RoutesConfig;
30
+ routes?: RouteConfig[];
30
31
  schedules?: unknown;
31
32
  };
32
33
 
33
- export type RoutesConfig = {
34
- [route: string]: RouteConfig;
35
- };
36
-
37
34
  export type RouteConfig = {
35
+ routePath: UrlPath;
36
+ method?: HTTPMethod;
38
37
  middleware?: string | string[];
39
38
  module?: string | string[];
40
39
  };
@@ -114,16 +113,10 @@ export function parseConfig(config: Config, baseDir: string) {
114
113
  });
115
114
  }
116
115
 
117
- for (const [route, props] of Object.entries(config.routes ?? {})) {
118
- let [_methods, routePath] = route.split(" ");
119
- if (!routePath) {
120
- routePath = _methods;
121
- _methods = "";
122
- }
123
-
116
+ for (const { routePath, method, ...props } of config.routes ?? []) {
124
117
  routes.push({
125
118
  routePath,
126
- methods: _methods.split("|").filter(isHTTPMethod),
119
+ method,
127
120
  middlewares: parseModuleIdentifiers(props.middleware),
128
121
  modules: parseModuleIdentifiers(props.module),
129
122
  });
@@ -148,7 +141,7 @@ export const routes = [
148
141
  .map(
149
142
  (route) => ` {
150
143
  routePath: "${route.routePath}",
151
- methods: ${JSON.stringify(route.methods)},
144
+ method: "${route.method}",
152
145
  middlewares: [${route.middlewares.join(", ")}],
153
146
  modules: [${route.modules.join(", ")}],
154
147
  },`
@@ -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
  };
@@ -47,10 +47,7 @@ function* executeRequest(request: Request, _env: FetchEnv) {
47
47
 
48
48
  // First, iterate through the routes (backwards) and execute "middlewares" on partial route matches
49
49
  for (const route of [...routes].reverse()) {
50
- if (
51
- route.methods.length &&
52
- !route.methods.includes(request.method as HTTPMethod)
53
- ) {
50
+ if (route.method && route.method !== request.method) {
54
51
  continue;
55
52
  }
56
53
 
@@ -68,10 +65,7 @@ function* executeRequest(request: Request, _env: FetchEnv) {
68
65
 
69
66
  // Then look for the first exact route match and execute its "modules"
70
67
  for (const route of routes) {
71
- if (
72
- route.methods.length &&
73
- !route.methods.includes(request.method as HTTPMethod)
74
- ) {
68
+ if (route.method && route.method !== request.method) {
75
69
  continue;
76
70
  }
77
71