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.
- package/package.json +6 -5
- package/pages/functions/filepath-routing.test.ts +4 -4
- package/pages/functions/filepath-routing.ts +44 -87
- package/src/__tests__/configuration.test.ts +2186 -0
- package/src/__tests__/dev.test.tsx +218 -75
- package/src/__tests__/helpers/mock-account-id.ts +6 -6
- package/src/__tests__/helpers/mock-cfetch.ts +2 -2
- package/src/__tests__/helpers/mock-console.ts +17 -9
- package/src/__tests__/helpers/mock-web-socket.ts +0 -8
- package/src/__tests__/helpers/write-wrangler-toml.ts +2 -5
- package/src/__tests__/index.test.ts +150 -55
- package/src/__tests__/jest.setup.ts +24 -5
- package/src/__tests__/kv.test.ts +399 -132
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +793 -384
- package/src/__tests__/r2.test.ts +16 -24
- package/src/__tests__/secret.test.ts +176 -63
- package/src/__tests__/tail.test.ts +482 -164
- package/src/api/form_data.ts +43 -7
- package/src/api/preview.ts +34 -17
- package/src/api/worker.ts +19 -7
- package/src/bundle.ts +21 -15
- package/src/cfetch/index.ts +8 -6
- package/src/cfetch/internal.ts +41 -14
- package/src/config/README.md +107 -0
- package/src/config/config.ts +270 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +305 -0
- package/src/config/index.ts +52 -0
- package/src/config/validation-helpers.ts +370 -0
- package/src/config/validation.ts +1019 -0
- package/src/dev.tsx +124 -49
- package/src/entry.ts +57 -0
- package/src/environment-variables.ts +33 -0
- package/src/guess-worker-format.ts +1 -1
- package/src/index.tsx +657 -852
- package/src/kv.tsx +101 -44
- package/src/module-collection.ts +133 -47
- package/src/package-manager.ts +21 -15
- package/src/pages.tsx +1 -1
- package/src/parse.ts +183 -0
- package/src/proxy.ts +1 -1
- package/src/publish.ts +72 -71
- package/src/sites.tsx +5 -11
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +62 -0
- package/src/user.tsx +29 -13
- package/templates/new-worker.js +1 -1
- package/templates/new-worker.ts +1 -1
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +5323 -9418
- package/wrangler-dist/cli.js.map +3 -3
- package/src/config.ts +0 -671
- package/src/tail.tsx +0 -242
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.
|
|
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.
|
|
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: "
|
|
94
|
-
module: ["bar.ts:
|
|
93
|
+
method: "DELETE",
|
|
94
|
+
module: ["bar.ts:onRequestDelete"],
|
|
95
95
|
routePath: "/base/bar",
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
|
-
method: "
|
|
99
|
-
module: ["bar.ts:
|
|
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
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
48
|
+
const isIndexFile = basename === "index";
|
|
49
|
+
// TODO: deprecate _middleware_ in favor of _middleware
|
|
50
|
+
const isMiddlewareFile =
|
|
51
|
+
basename === "_middleware" || basename === "_middleware_";
|
|
92
52
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
53
|
+
let routePath = path
|
|
54
|
+
.relative(baseDir, filepath)
|
|
55
|
+
.slice(0, -ext.length);
|
|
96
56
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
57
|
+
if (isIndexFile || isMiddlewareFile) {
|
|
58
|
+
routePath = path.dirname(routePath);
|
|
59
|
+
}
|
|
100
60
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
61
|
+
if (routePath === ".") {
|
|
62
|
+
routePath = "";
|
|
63
|
+
}
|
|
104
64
|
|
|
105
|
-
|
|
65
|
+
routePath = `${baseURL}/${routePath}`;
|
|
106
66
|
|
|
107
|
-
|
|
108
|
-
|
|
67
|
+
routePath = routePath.replace(/\[\[(.+)]]/g, ":$1*"); // transform [[id]] => :id*
|
|
68
|
+
routePath = routePath.replace(/\[(.+)]/g, ":$1"); // transform [id] => :id
|
|
109
69
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
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 }) => {
|