wrangler 0.0.17 → 0.0.18

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 (55) hide show
  1. package/package.json +6 -5
  2. package/pages/functions/filepath-routing.test.ts +4 -4
  3. package/pages/functions/filepath-routing.ts +44 -87
  4. package/src/__tests__/configuration.test.ts +2186 -0
  5. package/src/__tests__/dev.test.tsx +218 -75
  6. package/src/__tests__/helpers/mock-account-id.ts +6 -6
  7. package/src/__tests__/helpers/mock-cfetch.ts +2 -2
  8. package/src/__tests__/helpers/mock-console.ts +17 -9
  9. package/src/__tests__/helpers/mock-web-socket.ts +0 -8
  10. package/src/__tests__/helpers/write-wrangler-toml.ts +2 -5
  11. package/src/__tests__/index.test.ts +150 -55
  12. package/src/__tests__/jest.setup.ts +24 -5
  13. package/src/__tests__/kv.test.ts +399 -132
  14. package/src/__tests__/parse.test.ts +322 -0
  15. package/src/__tests__/publish.test.ts +793 -384
  16. package/src/__tests__/r2.test.ts +16 -24
  17. package/src/__tests__/secret.test.ts +176 -63
  18. package/src/__tests__/tail.test.ts +482 -164
  19. package/src/api/form_data.ts +43 -7
  20. package/src/api/preview.ts +34 -17
  21. package/src/api/worker.ts +19 -7
  22. package/src/bundle.ts +21 -15
  23. package/src/cfetch/index.ts +8 -6
  24. package/src/cfetch/internal.ts +41 -14
  25. package/src/config/README.md +107 -0
  26. package/src/config/config.ts +270 -0
  27. package/src/config/diagnostics.ts +80 -0
  28. package/src/config/environment.ts +305 -0
  29. package/src/config/index.ts +52 -0
  30. package/src/config/validation-helpers.ts +370 -0
  31. package/src/config/validation.ts +1019 -0
  32. package/src/dev.tsx +124 -49
  33. package/src/entry.ts +57 -0
  34. package/src/environment-variables.ts +33 -0
  35. package/src/guess-worker-format.ts +1 -1
  36. package/src/index.tsx +657 -852
  37. package/src/kv.tsx +101 -44
  38. package/src/module-collection.ts +133 -47
  39. package/src/package-manager.ts +21 -15
  40. package/src/pages.tsx +1 -1
  41. package/src/parse.ts +183 -0
  42. package/src/proxy.ts +1 -1
  43. package/src/publish.ts +72 -71
  44. package/src/sites.tsx +5 -11
  45. package/src/tail/filters.ts +279 -0
  46. package/src/tail/index.ts +299 -0
  47. package/src/tail/printing.ts +62 -0
  48. package/src/user.tsx +29 -13
  49. package/templates/new-worker.js +1 -1
  50. package/templates/new-worker.ts +1 -1
  51. package/templates/tsconfig.json +105 -0
  52. package/wrangler-dist/cli.js +5323 -9418
  53. package/wrangler-dist/cli.js.map +3 -3
  54. package/src/config.ts +0 -671
  55. package/src/tail.tsx +0 -242
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -36,7 +36,7 @@
36
36
  "cli"
37
37
  ],
38
38
  "dependencies": {
39
- "esbuild": "0.14.14",
39
+ "esbuild": "0.14.23",
40
40
  "miniflare": "2.3.0",
41
41
  "path-to-regexp": "^6.2.0",
42
42
  "semiver": "^1.1.0",
@@ -53,6 +53,7 @@
53
53
  "@sentry/node": "^6.17.6",
54
54
  "@types/command-exists": "^1.2.0",
55
55
  "@types/estree": "^0.0.50",
56
+ "@types/glob-to-regexp": "0.4.1",
56
57
  "@types/mime": "^2.0.3",
57
58
  "@types/prompts": "^2.0.14",
58
59
  "@types/react": "^17.0.37",
@@ -60,8 +61,6 @@
60
61
  "@types/signal-exit": "^3.0.1",
61
62
  "@types/ws": "^8.2.1",
62
63
  "@types/yargs": "^17.0.7",
63
- "acorn": "^8.6.0",
64
- "acorn-walk": "^8.2.0",
65
64
  "chokidar": "^3.5.2",
66
65
  "clipboardy": "^3.0.0",
67
66
  "cmd-shim": "^4.1.0",
@@ -71,6 +70,8 @@
71
70
  "faye-websocket": "^0.11.4",
72
71
  "finalhandler": "^1.1.2",
73
72
  "find-up": "^6.2.0",
73
+ "get-port": "^6.1.2",
74
+ "glob-to-regexp": "0.4.1",
74
75
  "ignore": "^5.2.0",
75
76
  "ink": "^3.2.0",
76
77
  "ink-select-input": "^4.2.1",
@@ -119,7 +120,7 @@
119
120
  "testTimeout": 30000,
120
121
  "testRegex": ".*.(test|spec)\\.[jt]sx?$",
121
122
  "transformIgnorePatterns": [
122
- "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)"
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)"
123
124
  ],
124
125
  "moduleNameMapper": {
125
126
  "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js"
@@ -90,13 +90,13 @@ describe("filepath-routing", () => {
90
90
  expect(entries).toEqual({
91
91
  routes: [
92
92
  {
93
- method: "PUT",
94
- module: ["bar.ts:onRequestPut"],
93
+ method: "DELETE",
94
+ module: ["bar.ts:onRequestDelete"],
95
95
  routePath: "/base/bar",
96
96
  },
97
97
  {
98
- method: "DELETE",
99
- module: ["bar.ts:onRequestDelete"],
98
+ method: "PUT",
99
+ module: ["bar.ts:onRequestPut"],
100
100
  routePath: "/base/bar",
101
101
  },
102
102
  {
@@ -1,12 +1,9 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
- import * as acorn from "acorn";
4
- import * as acornWalk from "acorn-walk";
5
- import { transform } from "esbuild";
3
+ import { build } from "esbuild";
6
4
  import { toUrlPath } from "../../src/paths";
7
5
  import type { UrlPath } from "../../src/paths";
8
6
  import type { HTTPMethod, RouteConfig } from "./routes";
9
- import type { ExportNamedDeclaration, Identifier } from "estree";
10
7
 
11
8
  export async function generateConfigFromFileTree({
12
9
  baseDir,
@@ -28,101 +25,61 @@ export async function generateConfigFromFileTree({
28
25
  await forEachFile(baseDir, async (filepath) => {
29
26
  const ext = path.extname(filepath);
30
27
  if (/^\.(mjs|js|ts|tsx|jsx)$/.test(ext)) {
31
- // transform the code to ensure we're working with vanilla JS + ESM
32
- const { code } = await transform(await fs.readFile(filepath, "utf-8"), {
33
- loader: ext === ".ts" ? "ts" : "js",
28
+ const { metafile } = await build({
29
+ metafile: true,
30
+ write: false,
31
+ bundle: false,
32
+ entryPoints: [path.resolve(filepath)],
34
33
  });
34
+ const exportNames: string[] = [];
35
+ if (metafile) {
36
+ for (const output in metafile?.outputs) {
37
+ exportNames.push(...metafile.outputs[output].exports);
38
+ }
39
+ }
40
+ for (const exportName of exportNames) {
41
+ const [match, method = ""] = (exportName.match(
42
+ /^onRequest(Get|Post|Put|Patch|Delete|Options|Head)?$/
43
+ ) ?? []) as (string | undefined)[];
35
44
 
36
- // parse each file into an AST and search for module exports that match "onRequest" and friends
37
- const ast = acorn.parse(code, {
38
- ecmaVersion: "latest",
39
- sourceType: "module",
40
- });
41
- acornWalk.simple(ast, {
42
- ExportNamedDeclaration(_node: unknown) {
43
- // This dynamic cast assumes that the AST generated by acornWalk will generate nodes that
44
- // are compatible with the eslint AST nodes.
45
- const node = _node as ExportNamedDeclaration;
46
-
47
- // this is an array because multiple things can be exported from a single statement
48
- // i.e. `export {foo, bar}` or `export const foo = "f", bar = "b"`
49
- const exportNames: string[] = [];
50
-
51
- if (node.declaration) {
52
- const declaration = node.declaration;
53
-
54
- // `export async function onRequest() {...}`
55
- if (declaration.type === "FunctionDeclaration" && declaration.id) {
56
- exportNames.push(declaration.id.name);
57
- }
58
-
59
- // `export const onRequestGet = () => {}, onRequestPost = () => {}`
60
- if (declaration.type === "VariableDeclaration") {
61
- exportNames.push(
62
- ...declaration.declarations.map(
63
- (variableDeclarator) =>
64
- (variableDeclarator.id as unknown as Identifier).name
65
- )
66
- );
67
- }
68
- }
69
-
70
- // `export {foo, bar}`
71
- if (node.specifiers.length) {
72
- exportNames.push(
73
- ...node.specifiers.map(
74
- (exportSpecifier) =>
75
- (exportSpecifier.exported as unknown as Identifier).name
76
- )
77
- );
78
- }
79
-
80
- for (const exportName of exportNames) {
81
- const [match, method = ""] = (exportName.match(
82
- /^onRequest(Get|Post|Put|Patch|Delete|Options|Head)?$/
83
- ) ?? []) as (string | undefined)[];
84
-
85
- if (match) {
86
- const basename = path.basename(filepath).slice(0, -ext.length);
45
+ if (match) {
46
+ const basename = path.basename(filepath).slice(0, -ext.length);
87
47
 
88
- const isIndexFile = basename === "index";
89
- // TODO: deprecate _middleware_ in favor of _middleware
90
- const isMiddlewareFile =
91
- basename === "_middleware" || basename === "_middleware_";
48
+ const isIndexFile = basename === "index";
49
+ // TODO: deprecate _middleware_ in favor of _middleware
50
+ const isMiddlewareFile =
51
+ basename === "_middleware" || basename === "_middleware_";
92
52
 
93
- let routePath = path
94
- .relative(baseDir, filepath)
95
- .slice(0, -ext.length);
53
+ let routePath = path
54
+ .relative(baseDir, filepath)
55
+ .slice(0, -ext.length);
96
56
 
97
- if (isIndexFile || isMiddlewareFile) {
98
- routePath = path.dirname(routePath);
99
- }
57
+ if (isIndexFile || isMiddlewareFile) {
58
+ routePath = path.dirname(routePath);
59
+ }
100
60
 
101
- if (routePath === ".") {
102
- routePath = "";
103
- }
61
+ if (routePath === ".") {
62
+ routePath = "";
63
+ }
104
64
 
105
- routePath = `${baseURL}/${routePath}`;
65
+ routePath = `${baseURL}/${routePath}`;
106
66
 
107
- routePath = routePath.replace(/\[\[(.+)]]/g, ":$1*"); // transform [[id]] => :id*
108
- routePath = routePath.replace(/\[(.+)]/g, ":$1"); // transform [id] => :id
67
+ routePath = routePath.replace(/\[\[(.+)]]/g, ":$1*"); // transform [[id]] => :id*
68
+ routePath = routePath.replace(/\[(.+)]/g, ":$1"); // transform [id] => :id
109
69
 
110
- const routeEntry: RouteConfig = {
111
- routePath: toUrlPath(routePath),
112
- method: method.toUpperCase() as HTTPMethod,
113
- [isMiddlewareFile ? "middleware" : "module"]: [
114
- `${path.relative(baseDir, filepath)}:${exportName}`,
115
- ],
116
- };
70
+ const routeEntry: RouteConfig = {
71
+ routePath: toUrlPath(routePath),
72
+ method: method.toUpperCase() as HTTPMethod,
73
+ [isMiddlewareFile ? "middleware" : "module"]: [
74
+ `${path.relative(baseDir, filepath)}:${exportName}`,
75
+ ],
76
+ };
117
77
 
118
- routeEntries.push(routeEntry);
119
- }
120
- }
121
- },
122
- });
78
+ routeEntries.push(routeEntry);
79
+ }
80
+ }
123
81
  }
124
82
  });
125
-
126
83
  // Combine together any routes (index routes) which contain both a module and a middleware
127
84
  routeEntries = routeEntries.reduce(
128
85
  (acc: typeof routeEntries, { routePath, ...rest }) => {