wrangler 0.0.0-e3cab74 → 0.0.0-e3e3243

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 (66) hide show
  1. package/README.md +1 -1
  2. package/bin/wrangler.js +10 -1
  3. package/miniflare-dist/index.mjs +79 -0
  4. package/miniflare-dist/index.mjs.map +7 -0
  5. package/package.json +10 -7
  6. package/pages/functions/filepath-routing.test.ts +125 -25
  7. package/pages/functions/filepath-routing.ts +6 -3
  8. package/src/__tests__/configuration.test.ts +959 -324
  9. package/src/__tests__/dev.test.tsx +512 -84
  10. package/src/__tests__/guess-worker-format.test.ts +19 -17
  11. package/src/__tests__/helpers/mock-account-id.ts +22 -4
  12. package/src/__tests__/helpers/mock-cfetch.ts +3 -3
  13. package/src/__tests__/helpers/mock-console.ts +17 -9
  14. package/src/__tests__/helpers/mock-kv.ts +9 -16
  15. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  16. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  17. package/src/__tests__/https-options.test.ts +127 -0
  18. package/src/__tests__/index.test.ts +128 -11
  19. package/src/__tests__/jest.setup.ts +16 -4
  20. package/src/__tests__/kv.test.ts +364 -125
  21. package/src/__tests__/logout.test.ts +15 -13
  22. package/src/__tests__/pages.test.ts +82 -0
  23. package/src/__tests__/publish.test.ts +1838 -735
  24. package/src/__tests__/r2.test.ts +4 -4
  25. package/src/__tests__/route.test.ts +45 -0
  26. package/src/__tests__/secret.test.ts +167 -68
  27. package/src/__tests__/tail.test.ts +2 -4
  28. package/src/__tests__/whoami.test.tsx +21 -7
  29. package/src/bundle.ts +27 -5
  30. package/src/cfetch/internal.ts +11 -5
  31. package/src/config/README.md +6 -6
  32. package/src/config/config.ts +54 -101
  33. package/src/config/environment.ts +67 -1
  34. package/src/config/index.ts +13 -3
  35. package/src/config/validation-helpers.ts +207 -23
  36. package/src/config/validation.ts +344 -129
  37. package/src/{api/preview.ts → create-worker-preview.ts} +39 -20
  38. package/src/{api/form_data.ts → create-worker-upload-form.ts} +1 -1
  39. package/src/dev/dev.tsx +392 -0
  40. package/src/dev/local.tsx +232 -0
  41. package/src/dev/remote.tsx +203 -0
  42. package/src/dev/use-esbuild.ts +104 -0
  43. package/src/entry.ts +192 -9
  44. package/src/https-options.ts +122 -0
  45. package/src/index.tsx +577 -515
  46. package/src/inspect.ts +9 -1
  47. package/src/intl-polyfill.d.ts +139 -0
  48. package/src/{kv.tsx → kv.ts} +97 -53
  49. package/src/miniflare-cli/README.md +30 -0
  50. package/src/miniflare-cli/enum-keys.ts +17 -0
  51. package/src/miniflare-cli/index.ts +37 -0
  52. package/src/module-collection.ts +90 -2
  53. package/src/open-in-browser.ts +14 -2
  54. package/src/pages.tsx +26 -10
  55. package/src/proxy.ts +104 -40
  56. package/src/publish.ts +53 -71
  57. package/src/reporting.ts +25 -9
  58. package/src/selfsigned.d.ts +29 -0
  59. package/src/sites.tsx +68 -29
  60. package/src/user.tsx +163 -85
  61. package/src/{api/worker.ts → worker.ts} +1 -24
  62. package/wrangler-dist/cli.js +5933 -3842
  63. package/wrangler-dist/cli.js.map +3 -3
  64. package/src/__tests__/helpers/mock-user.ts +0 -27
  65. package/src/dev.tsx +0 -961
  66. 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-e3cab74",
3
+ "version": "0.0.0-e3e3243",
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
  },
@@ -46,19 +47,18 @@
46
47
  "fsevents": "~2.3.2"
47
48
  },
48
49
  "devDependencies": {
49
- "@babel/types": "^7.16.0",
50
50
  "@iarna/toml": "^2.2.5",
51
51
  "@sentry/cli": "^1.71.0",
52
52
  "@sentry/integrations": "^6.17.6",
53
53
  "@sentry/node": "^6.17.6",
54
54
  "@types/command-exists": "^1.2.0",
55
- "@types/estree": "^0.0.50",
56
55
  "@types/glob-to-regexp": "0.4.1",
57
56
  "@types/mime": "^2.0.3",
58
57
  "@types/prompts": "^2.0.14",
59
58
  "@types/react": "^17.0.37",
60
59
  "@types/serve-static": "^1.13.10",
61
60
  "@types/signal-exit": "^3.0.1",
61
+ "@types/supports-color": "^8.1.1",
62
62
  "@types/ws": "^8.2.1",
63
63
  "@types/yargs": "^17.0.7",
64
64
  "chokidar": "^3.5.2",
@@ -87,8 +87,9 @@
87
87
  "react-error-boundary": "^3.1.4",
88
88
  "serve-static": "^1.14.1",
89
89
  "signal-exit": "^3.0.6",
90
+ "supports-color": "^9.2.1",
90
91
  "tmp-promise": "^3.0.3",
91
- "undici": "4.13.0",
92
+ "undici": "^4.15.1",
92
93
  "ws": "^8.3.0",
93
94
  "yargs": "^17.3.0"
94
95
  },
@@ -97,13 +98,14 @@
97
98
  "bin",
98
99
  "pages",
99
100
  "miniflare-config-stubs",
101
+ "miniflare-dist",
100
102
  "wrangler-dist",
101
103
  "templates",
102
104
  "vendor",
103
105
  "import_meta_url.js"
104
106
  ],
105
107
  "scripts": {
106
- "clean": "rm -rf wrangler-dist",
108
+ "clean": "rm -rf wrangler-dist miniflare-dist",
107
109
  "check:type": "tsc",
108
110
  "bundle": "node -r esbuild-register scripts/bundle.ts",
109
111
  "build": "npm run clean && npm run bundle",
@@ -120,10 +122,11 @@
120
122
  "testTimeout": 30000,
121
123
  "testRegex": ".*.(test|spec)\\.[jt]sx?$",
122
124
  "transformIgnorePatterns": [
123
- "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)"
125
+ "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)"
124
126
  ],
125
127
  "moduleNameMapper": {
126
- "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js"
128
+ "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
129
+ "miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
127
130
  },
128
131
  "transform": {
129
132
  "^.+\\.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