wrangler 0.0.0-e88a54e → 0.0.0-e95e5a0
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/README.md +25 -14
- package/bin/wrangler.js +13 -1
- package/miniflare-dist/index.mjs +4828 -21
- package/package.json +29 -24
- package/pages/functions/buildPlugin.ts +92 -0
- package/pages/functions/buildWorker.ts +80 -4
- package/pages/functions/filepath-routing.test.ts +11 -0
- package/pages/functions/filepath-routing.ts +8 -0
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +146 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +530 -201
- package/src/__tests__/dev.test.tsx +284 -18
- package/src/__tests__/guess-worker-format.test.ts +28 -1
- package/src/__tests__/helpers/mock-cfetch.ts +5 -1
- package/src/__tests__/helpers/mock-console.ts +20 -3
- package/src/__tests__/helpers/mock-dialogs.ts +26 -1
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/run-in-tmp.ts +7 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +5 -2
- package/src/__tests__/index.test.ts +27 -769
- package/src/__tests__/init.test.ts +1516 -0
- package/src/__tests__/jest.setup.ts +4 -4
- package/src/__tests__/kv.test.ts +133 -61
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +311 -26
- package/src/__tests__/publish.test.ts +2789 -618
- package/src/__tests__/r2.test.ts +26 -10
- package/src/__tests__/route.test.ts +4 -4
- package/src/__tests__/secret.test.ts +55 -34
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +14 -9
- package/src/bundle.ts +30 -3
- package/src/cfetch/internal.ts +0 -2
- package/src/cli.ts +5 -11
- package/src/config/README.md +1 -1
- package/src/config/config.ts +20 -4
- package/src/config/environment.ts +32 -4
- package/src/config/index.ts +4 -3
- package/src/config/validation-helpers.ts +96 -7
- package/src/config/validation.ts +388 -54
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +22 -13
- package/src/create-worker-upload-form.ts +32 -9
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +132 -78
- package/src/dev/local.tsx +101 -21
- package/src/dev/remote.tsx +23 -13
- package/src/dev/use-esbuild.ts +23 -5
- package/src/dialogs.tsx +16 -6
- package/src/entry.ts +83 -24
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +3 -2
- package/src/index.tsx +689 -394
- package/src/inspect.ts +17 -11
- package/src/intl-polyfill.d.ts +139 -0
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/index.ts +4 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +7 -7
- package/src/open-in-browser.ts +5 -4
- package/src/package-manager.ts +9 -8
- package/src/pages.tsx +875 -56
- package/src/parse.ts +1 -1
- package/src/proxy.ts +28 -19
- package/src/publish.ts +263 -141
- package/src/sites.tsx +27 -14
- package/src/tail/index.ts +2 -2
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +116 -41
- package/src/whoami.tsx +2 -1
- package/src/worker.ts +15 -6
- package/templates/gitignore +171 -0
- package/templates/static-asset-facade.js +1 -1
- package/wrangler-dist/cli.js +21162 -50227
- package/miniflare-dist/index.mjs.map +0 -7
- package/src/__tests__/dev2.test.tsx +0 -154
- package/src/__tests__/logout.test.ts +0 -52
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/reporting.ts +0 -131
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -6,6 +6,7 @@ type Params<P extends string = string> = Record<P, string | string[]>;
|
|
|
6
6
|
|
|
7
7
|
type EventContext<Env, P extends string, Data> = {
|
|
8
8
|
request: Request;
|
|
9
|
+
functionPath: string;
|
|
9
10
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
10
11
|
next: (input?: Request | string, init?: RequestInit) => Promise<Response>;
|
|
11
12
|
env: Env & { ASSETS: { fetch: typeof fetch } };
|
|
@@ -22,6 +23,7 @@ declare type PagesFunction<
|
|
|
22
23
|
|
|
23
24
|
type RouteHandler = {
|
|
24
25
|
routePath: string;
|
|
26
|
+
mountPath: string;
|
|
25
27
|
method?: HTTPMethod;
|
|
26
28
|
modules: PagesFunction[];
|
|
27
29
|
middlewares: PagesFunction[];
|
|
@@ -42,7 +44,7 @@ type WorkerContext = {
|
|
|
42
44
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
|
-
function* executeRequest(request: Request
|
|
47
|
+
function* executeRequest(request: Request) {
|
|
46
48
|
const requestPath = new URL(request.url).pathname;
|
|
47
49
|
|
|
48
50
|
// First, iterate through the routes (backwards) and execute "middlewares" on partial route matches
|
|
@@ -52,12 +54,15 @@ function* executeRequest(request: Request, _env: FetchEnv) {
|
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
const routeMatcher = match(route.routePath, { end: false });
|
|
57
|
+
const mountMatcher = match(route.mountPath, { end: false });
|
|
55
58
|
const matchResult = routeMatcher(requestPath);
|
|
56
|
-
|
|
59
|
+
const mountMatchResult = mountMatcher(requestPath);
|
|
60
|
+
if (matchResult && mountMatchResult) {
|
|
57
61
|
for (const handler of route.middlewares.flat()) {
|
|
58
62
|
yield {
|
|
59
63
|
handler,
|
|
60
64
|
params: matchResult.params as Params,
|
|
65
|
+
path: mountMatchResult.path,
|
|
61
66
|
};
|
|
62
67
|
}
|
|
63
68
|
}
|
|
@@ -70,12 +75,15 @@ function* executeRequest(request: Request, _env: FetchEnv) {
|
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
const routeMatcher = match(route.routePath, { end: true });
|
|
78
|
+
const mountMatcher = match(route.mountPath, { end: false });
|
|
73
79
|
const matchResult = routeMatcher(requestPath);
|
|
74
|
-
|
|
80
|
+
const mountMatchResult = mountMatcher(requestPath);
|
|
81
|
+
if (matchResult && mountMatchResult && route.modules.length) {
|
|
75
82
|
for (const handler of route.modules.flat()) {
|
|
76
83
|
yield {
|
|
77
84
|
handler,
|
|
78
85
|
params: matchResult.params as Params,
|
|
86
|
+
path: matchResult.path,
|
|
79
87
|
};
|
|
80
88
|
}
|
|
81
89
|
break;
|
|
@@ -85,19 +93,24 @@ function* executeRequest(request: Request, _env: FetchEnv) {
|
|
|
85
93
|
|
|
86
94
|
export default {
|
|
87
95
|
async fetch(request: Request, env: FetchEnv, workerContext: WorkerContext) {
|
|
88
|
-
const handlerIterator = executeRequest(request
|
|
96
|
+
const handlerIterator = executeRequest(request);
|
|
89
97
|
const data = {}; // arbitrary data the user can set between functions
|
|
90
98
|
const next = async (input?: RequestInfo, init?: RequestInit) => {
|
|
91
99
|
if (input !== undefined) {
|
|
92
|
-
|
|
100
|
+
let url = input;
|
|
101
|
+
if (typeof input === "string") {
|
|
102
|
+
url = new URL(input, request.url).toString();
|
|
103
|
+
}
|
|
104
|
+
request = new Request(url, init);
|
|
93
105
|
}
|
|
94
106
|
|
|
95
107
|
const result = handlerIterator.next();
|
|
96
108
|
// Note we can't use `!result.done` because this doesn't narrow to the correct type
|
|
97
|
-
if (result.done
|
|
98
|
-
const { handler, params } = result.value;
|
|
109
|
+
if (result.done === false) {
|
|
110
|
+
const { handler, params, path } = result.value;
|
|
99
111
|
const context = {
|
|
100
112
|
request: new Request(request.clone()),
|
|
113
|
+
functionPath: path,
|
|
101
114
|
next,
|
|
102
115
|
params,
|
|
103
116
|
data,
|
|
@@ -110,7 +123,7 @@ export default {
|
|
|
110
123
|
// https://fetch.spec.whatwg.org/#null-body-status
|
|
111
124
|
return new Response(
|
|
112
125
|
[101, 204, 205, 304].includes(response.status) ? null : response.body,
|
|
113
|
-
response
|
|
126
|
+
{ ...response, headers: new Headers(response.headers) }
|
|
114
127
|
);
|
|
115
128
|
} else if (__FALLBACK_SERVICE__) {
|
|
116
129
|
// There are no more handlers so finish with the fallback service (`env.ASSETS.fetch` in Pages' case)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getConfigCache, saveToConfigCache } from "../config-cache";
|
|
2
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
3
|
+
|
|
4
|
+
interface PagesConfigCache {
|
|
5
|
+
account_id: string;
|
|
6
|
+
pages_project_name: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe("config cache", () => {
|
|
10
|
+
runInTempDir();
|
|
11
|
+
|
|
12
|
+
const pagesConfigCacheFilename = "pages-config-cache.json";
|
|
13
|
+
|
|
14
|
+
it("should return an empty config if no file exists", () => {
|
|
15
|
+
expect(
|
|
16
|
+
getConfigCache<PagesConfigCache>(pagesConfigCacheFilename)
|
|
17
|
+
).toMatchInlineSnapshot(`Object {}`);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should read and write values without overriding old ones", () => {
|
|
21
|
+
saveToConfigCache<PagesConfigCache>(pagesConfigCacheFilename, {
|
|
22
|
+
account_id: "some-account-id",
|
|
23
|
+
pages_project_name: "foo",
|
|
24
|
+
});
|
|
25
|
+
expect(
|
|
26
|
+
getConfigCache<PagesConfigCache>(pagesConfigCacheFilename).account_id
|
|
27
|
+
).toEqual("some-account-id");
|
|
28
|
+
|
|
29
|
+
saveToConfigCache<PagesConfigCache>(pagesConfigCacheFilename, {
|
|
30
|
+
pages_project_name: "bar",
|
|
31
|
+
});
|
|
32
|
+
expect(
|
|
33
|
+
getConfigCache<PagesConfigCache>(pagesConfigCacheFilename).account_id
|
|
34
|
+
).toEqual("some-account-id");
|
|
35
|
+
});
|
|
36
|
+
});
|