wrangler 0.0.0-e043479 → 0.0.0-e0b9366

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 (51) hide show
  1. package/package.json +10 -4
  2. package/pages/functions/filepath-routing.test.ts +125 -25
  3. package/pages/functions/filepath-routing.ts +6 -3
  4. package/src/__tests__/configuration.test.ts +479 -114
  5. package/src/__tests__/dev.test.tsx +162 -8
  6. package/src/__tests__/dev2.test.tsx +152 -0
  7. package/src/__tests__/guess-worker-format.test.ts +9 -17
  8. package/src/__tests__/helpers/mock-account-id.ts +4 -0
  9. package/src/__tests__/helpers/mock-cfetch.ts +3 -3
  10. package/src/__tests__/helpers/mock-kv.ts +9 -16
  11. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  12. package/src/__tests__/https-options.test.ts +127 -0
  13. package/src/__tests__/index.test.ts +125 -0
  14. package/src/__tests__/jest.setup.ts +1 -1
  15. package/src/__tests__/kv.test.ts +27 -53
  16. package/src/__tests__/logout.test.ts +15 -13
  17. package/src/__tests__/pages.test.ts +44 -0
  18. package/src/__tests__/publish.test.ts +504 -32
  19. package/src/__tests__/route.test.ts +45 -0
  20. package/src/__tests__/whoami.test.tsx +21 -7
  21. package/src/bundle.ts +20 -11
  22. package/src/cfetch/internal.ts +11 -5
  23. package/src/config/config.ts +53 -44
  24. package/src/config/validation-helpers.ts +110 -12
  25. package/src/config/validation.ts +59 -41
  26. package/src/{api/preview.ts → create-worker-preview.ts} +23 -4
  27. package/src/{api/form_data.ts → create-worker-upload-form.ts} +1 -1
  28. package/src/dev/dev.tsx +357 -0
  29. package/src/dev/local.tsx +241 -0
  30. package/src/dev/remote.tsx +201 -0
  31. package/src/dev/use-esbuild.ts +100 -0
  32. package/src/entry.ts +111 -9
  33. package/src/https-options.ts +122 -0
  34. package/src/index.tsx +171 -109
  35. package/src/inspect.ts +9 -1
  36. package/src/{kv.tsx → kv.ts} +0 -0
  37. package/src/module-collection.ts +85 -2
  38. package/src/open-in-browser.ts +14 -2
  39. package/src/pages.tsx +1 -1
  40. package/src/proxy.ts +102 -40
  41. package/src/publish.ts +41 -50
  42. package/src/reporting.ts +25 -9
  43. package/src/selfsigned.d.ts +29 -0
  44. package/src/sites.tsx +51 -16
  45. package/src/user.tsx +132 -77
  46. package/src/{api/worker.ts → worker.ts} +0 -23
  47. package/wrangler-dist/cli.js +5012 -3107
  48. package/wrangler-dist/cli.js.map +3 -3
  49. package/src/__tests__/helpers/mock-user.ts +0 -27
  50. package/src/dev.tsx +0 -960
  51. package/src/guess-worker-format.ts +0 -68
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-e043479",
3
+ "version": "0.0.0-e0b9366",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -39,6 +39,7 @@
39
39
  "esbuild": "0.14.23",
40
40
  "miniflare": "2.3.0",
41
41
  "path-to-regexp": "^6.2.0",
42
+ "selfsigned": "^2.0.0",
42
43
  "semiver": "^1.1.0",
43
44
  "xxhash-wasm": "^1.0.1"
44
45
  },
@@ -55,8 +56,10 @@
55
56
  "@types/mime": "^2.0.3",
56
57
  "@types/prompts": "^2.0.14",
57
58
  "@types/react": "^17.0.37",
59
+ "@types/react-test-renderer": "^17.0.1",
58
60
  "@types/serve-static": "^1.13.10",
59
61
  "@types/signal-exit": "^3.0.1",
62
+ "@types/supports-color": "^8.1.1",
60
63
  "@types/ws": "^8.2.1",
61
64
  "@types/yargs": "^17.0.7",
62
65
  "chokidar": "^3.5.2",
@@ -83,10 +86,12 @@
83
86
  "prompts": "^2.4.2",
84
87
  "react": "^17.0.2",
85
88
  "react-error-boundary": "^3.1.4",
89
+ "react-test-renderer": "^17.0.2",
86
90
  "serve-static": "^1.14.1",
87
91
  "signal-exit": "^3.0.6",
92
+ "supports-color": "^9.2.1",
88
93
  "tmp-promise": "^3.0.3",
89
- "undici": "4.13.0",
94
+ "undici": "^4.15.1",
90
95
  "ws": "^8.3.0",
91
96
  "yargs": "^17.3.0"
92
97
  },
@@ -118,10 +123,11 @@
118
123
  "testTimeout": 30000,
119
124
  "testRegex": ".*.(test|spec)\\.[jt]sx?$",
120
125
  "transformIgnorePatterns": [
121
- "node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port)"
126
+ "node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color)"
122
127
  ],
123
128
  "moduleNameMapper": {
124
- "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js"
129
+ "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
130
+ "miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
125
131
  },
126
132
  "transform": {
127
133
  "^.+\\.c?(t|j)sx?$": [
@@ -1,4 +1,4 @@
1
- import { writeFileSync } from "fs";
1
+ import { writeFileSync, mkdirSync } from "fs";
2
2
  import { runInTempDir } from "../../src/__tests__/helpers/run-in-tmp";
3
3
  import { toUrlPath } from "../../src/paths";
4
4
  import { compareRoutes, generateConfigFromFileTree } from "./filepath-routing";
@@ -83,34 +83,134 @@ describe("filepath-routing", () => {
83
83
  `
84
84
  );
85
85
 
86
+ mkdirSync("todos");
87
+
88
+ writeFileSync(
89
+ "todos/[id].ts",
90
+ `
91
+ export function onRequestPost() {}
92
+ export function onRequestDelete() {}
93
+ `
94
+ );
95
+
96
+ mkdirSync("authors");
97
+ mkdirSync("authors/[authorId]");
98
+ mkdirSync("authors/[authorId]/todos");
99
+
100
+ writeFileSync(
101
+ "authors/[authorId]/todos/[todoId].ts",
102
+ `
103
+ export function onRequestPost() {}
104
+ `
105
+ );
106
+
107
+ mkdirSync("books");
108
+
109
+ writeFileSync(
110
+ "books/[[title]].ts",
111
+ `
112
+ export function onRequestPost() {}
113
+ `
114
+ );
115
+
116
+ mkdirSync("cats");
117
+ mkdirSync("cats/[[breed]]");
118
+
119
+ writeFileSync(
120
+ "cats/[[breed]]/blah.ts",
121
+ `
122
+ export function onRequestPost() {}
123
+ `
124
+ );
125
+
126
+ // This won't actually work at runtime.
127
+ writeFileSync(
128
+ "cats/[[breed]]/[[name]].ts",
129
+ `
130
+ export function onRequestPost() {}
131
+ `
132
+ );
133
+
86
134
  const entries = await generateConfigFromFileTree({
87
135
  baseDir: ".",
88
136
  baseURL: "/base" as UrlPath,
89
137
  });
90
- expect(entries).toEqual({
91
- routes: [
92
- {
93
- method: "DELETE",
94
- module: ["bar.ts:onRequestDelete"],
95
- routePath: "/base/bar",
96
- },
97
- {
98
- method: "PUT",
99
- module: ["bar.ts:onRequestPut"],
100
- routePath: "/base/bar",
101
- },
102
- {
103
- method: "GET",
104
- module: ["foo.ts:onRequestGet"],
105
- routePath: "/base/foo",
106
- },
107
- {
108
- method: "POST",
109
- module: ["foo.ts:onRequestPost"],
110
- routePath: "/base/foo",
111
- },
112
- ],
113
- });
138
+ expect(entries).toMatchInlineSnapshot(`
139
+ Object {
140
+ "routes": Array [
141
+ Object {
142
+ "method": "POST",
143
+ "module": Array [
144
+ "authors/[authorId]/todos/[todoId].ts:onRequestPost",
145
+ ],
146
+ "routePath": "/base/authors/:authorId/todos/:todoId",
147
+ },
148
+ Object {
149
+ "method": "POST",
150
+ "module": Array [
151
+ "cats/[[breed]]/blah.ts:onRequestPost",
152
+ ],
153
+ "routePath": "/base/cats/:breed*/blah",
154
+ },
155
+ Object {
156
+ "method": "POST",
157
+ "module": Array [
158
+ "cats/[[breed]]/[[name]].ts:onRequestPost",
159
+ ],
160
+ "routePath": "/base/cats/:breed*/:name*",
161
+ },
162
+ Object {
163
+ "method": "DELETE",
164
+ "module": Array [
165
+ "todos/[id].ts:onRequestDelete",
166
+ ],
167
+ "routePath": "/base/todos/:id",
168
+ },
169
+ Object {
170
+ "method": "POST",
171
+ "module": Array [
172
+ "todos/[id].ts:onRequestPost",
173
+ ],
174
+ "routePath": "/base/todos/:id",
175
+ },
176
+ Object {
177
+ "method": "POST",
178
+ "module": Array [
179
+ "books/[[title]].ts:onRequestPost",
180
+ ],
181
+ "routePath": "/base/books/:title*",
182
+ },
183
+ Object {
184
+ "method": "DELETE",
185
+ "module": Array [
186
+ "bar.ts:onRequestDelete",
187
+ ],
188
+ "routePath": "/base/bar",
189
+ },
190
+ Object {
191
+ "method": "PUT",
192
+ "module": Array [
193
+ "bar.ts:onRequestPut",
194
+ ],
195
+ "routePath": "/base/bar",
196
+ },
197
+ Object {
198
+ "method": "GET",
199
+ "module": Array [
200
+ "foo.ts:onRequestGet",
201
+ ],
202
+ "routePath": "/base/foo",
203
+ },
204
+ Object {
205
+ "method": "POST",
206
+ "module": Array [
207
+ "foo.ts:onRequestPost",
208
+ ],
209
+ "routePath": "/base/foo",
210
+ },
211
+ ],
212
+ }
213
+ `);
114
214
  });
115
215
  });
116
216
  });
@@ -64,14 +64,17 @@ export async function generateConfigFromFileTree({
64
64
 
65
65
  routePath = `${baseURL}/${routePath}`;
66
66
 
67
- routePath = routePath.replace(/\[\[(.+)]]/g, ":$1*"); // transform [[id]] => :id*
68
- routePath = routePath.replace(/\[(.+)]/g, ":$1"); // transform [id] => :id
67
+ routePath = routePath.replace(/\[\[([^\]]+)\]\]/g, ":$1*"); // transform [[id]] => :id*
68
+ routePath = routePath.replaceAll(/\[([^\]]+)\]/g, ":$1"); // transform [id] => :id
69
+
70
+ // These are used as module specifiers so UrlPaths are okay to use even on Windows
71
+ const modulePath = toUrlPath(path.relative(baseDir, filepath));
69
72
 
70
73
  const routeEntry: RouteConfig = {
71
74
  routePath: toUrlPath(routePath),
72
75
  method: method.toUpperCase() as HTTPMethod,
73
76
  [isMiddlewareFile ? "middleware" : "module"]: [
74
- `${path.relative(baseDir, filepath)}:${exportName}`,
77
+ `${modulePath}:${exportName}`,
75
78
  ],
76
79
  };
77
80