wrangler 2.0.23 → 2.0.24
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 +20 -2
- package/bin/wrangler.js +1 -1
- package/miniflare-dist/index.mjs +96 -34
- package/package.json +9 -4
- package/src/__tests__/configuration.test.ts +88 -16
- package/src/__tests__/dev.test.tsx +3 -0
- package/src/__tests__/generate.test.ts +93 -0
- package/src/__tests__/helpers/mock-cfetch.ts +54 -2
- package/src/__tests__/index.test.ts +10 -27
- package/src/__tests__/jest.setup.ts +31 -1
- package/src/__tests__/kv.test.ts +2 -2
- package/src/__tests__/metrics.test.ts +5 -0
- package/src/__tests__/publish.test.ts +497 -254
- package/src/__tests__/r2.test.ts +155 -71
- package/src/__tests__/user.test.ts +1 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/whoami.test.tsx +60 -1
- package/src/bundle.ts +278 -44
- package/src/cfetch/internal.ts +34 -2
- package/src/config/config.ts +7 -2
- package/src/config/environment.ts +40 -8
- package/src/config/index.ts +13 -0
- package/src/config/validation.ts +101 -7
- package/src/create-worker-upload-form.ts +25 -0
- package/src/dev/dev.tsx +107 -28
- package/src/dev/local.tsx +20 -10
- package/src/dev/remote.tsx +39 -8
- package/src/dev/use-esbuild.ts +25 -0
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +157 -0
- package/src/dev.tsx +93 -75
- package/src/generate.ts +112 -14
- package/src/index.tsx +182 -4
- package/src/inspect.ts +93 -5
- package/src/metrics/index.ts +1 -0
- package/src/metrics/metrics-dispatcher.ts +1 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +2 -2
- package/src/module-collection.ts +3 -3
- package/src/pages/constants.ts +1 -0
- package/src/pages/deployments.tsx +1 -1
- package/src/pages/dev.tsx +6 -1
- package/src/pages/publish.tsx +1 -1
- package/src/pages/upload.tsx +32 -13
- package/src/publish.ts +126 -112
- package/src/r2.ts +68 -0
- package/src/user/user.tsx +20 -2
- package/src/whoami.tsx +79 -1
- package/src/worker.ts +12 -0
- package/templates/first-party-worker-module-facade.ts +18 -0
- package/templates/format-dev-errors.ts +32 -0
- package/templates/{static-asset-facade.js → serve-static-assets.ts} +21 -7
- package/templates/service-bindings-module-facade.js +51 -0
- package/templates/service-bindings-sw-facade.js +39 -0
- package/wrangler-dist/cli.js +40192 -15265
|
@@ -1,25 +1,40 @@
|
|
|
1
|
-
//
|
|
1
|
+
// @ts-expect-error
|
|
2
2
|
import worker from "__ENTRY_POINT__";
|
|
3
3
|
import {
|
|
4
4
|
getAssetFromKV,
|
|
5
5
|
NotFoundError,
|
|
6
6
|
MethodNotAllowedError,
|
|
7
|
+
// @ts-expect-error
|
|
7
8
|
} from "__KV_ASSET_HANDLER__";
|
|
9
|
+
// @ts-expect-error
|
|
8
10
|
import manifest from "__STATIC_CONTENT_MANIFEST";
|
|
11
|
+
import type * as kvAssetHandler from "@cloudflare/kv-asset-handler";
|
|
12
|
+
|
|
9
13
|
const ASSET_MANIFEST = JSON.parse(manifest);
|
|
10
14
|
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
export * from "__ENTRY_POINT__";
|
|
17
|
+
|
|
11
18
|
export default {
|
|
12
|
-
async fetch(
|
|
19
|
+
async fetch(
|
|
20
|
+
request: Request,
|
|
21
|
+
env: { __STATIC_CONTENT: string },
|
|
22
|
+
ctx: ExecutionContext
|
|
23
|
+
) {
|
|
13
24
|
let options = {
|
|
14
25
|
ASSET_MANIFEST,
|
|
15
26
|
ASSET_NAMESPACE: env.__STATIC_CONTENT,
|
|
27
|
+
cacheControl: __CACHE_CONTROL_OPTIONS__,
|
|
28
|
+
serveSinglePageApp: __SERVE_SINGLE_PAGE_APP__,
|
|
16
29
|
};
|
|
17
30
|
|
|
18
31
|
try {
|
|
19
|
-
const page = await
|
|
32
|
+
const page = await (
|
|
33
|
+
getAssetFromKV as typeof kvAssetHandler.getAssetFromKV
|
|
34
|
+
)(
|
|
20
35
|
{
|
|
21
36
|
request,
|
|
22
|
-
waitUntil(promise) {
|
|
37
|
+
waitUntil(promise: Promise<unknown>) {
|
|
23
38
|
return ctx.waitUntil(promise);
|
|
24
39
|
},
|
|
25
40
|
},
|
|
@@ -39,11 +54,10 @@ export default {
|
|
|
39
54
|
} catch (e) {
|
|
40
55
|
if (e instanceof NotFoundError || e instanceof MethodNotAllowedError) {
|
|
41
56
|
// if a known error is thrown then serve from actual worker
|
|
42
|
-
return worker.fetch(request, env, ctx);
|
|
57
|
+
return await worker.fetch(request, env, ctx);
|
|
43
58
|
}
|
|
44
59
|
// otherwise it's a real error, so throw it
|
|
45
|
-
|
|
46
|
-
return new Response(e.message, { status: 500 });
|
|
60
|
+
throw e;
|
|
47
61
|
}
|
|
48
62
|
},
|
|
49
63
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import worker from "__ENTRY_POINT__";
|
|
2
|
+
const Workers = __WORKERS__;
|
|
3
|
+
|
|
4
|
+
export * from "__ENTRY_POINT__";
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
async fetch(req, env, ctx) {
|
|
8
|
+
const facadeEnv = { ...env };
|
|
9
|
+
// For every Worker definition that's available,
|
|
10
|
+
// create a fetcher for it on the facade env.
|
|
11
|
+
// for const [name, binding] of env
|
|
12
|
+
// if Workers[name]
|
|
13
|
+
// const details = Workers[name];
|
|
14
|
+
|
|
15
|
+
for (const [name, details] of Object.entries(Workers)) {
|
|
16
|
+
if (details) {
|
|
17
|
+
facadeEnv[name] = {
|
|
18
|
+
async fetch(...reqArgs) {
|
|
19
|
+
if (details.headers) {
|
|
20
|
+
const req = new Request(...reqArgs);
|
|
21
|
+
for (const [key, value] of Object.entries(details.headers)) {
|
|
22
|
+
// In remote mode, you need to add a couple of headers
|
|
23
|
+
// to make sure it's talking to the 'dev' preview session
|
|
24
|
+
// (much like wrangler dev already does via proxy.ts)
|
|
25
|
+
req.headers.set(key, value);
|
|
26
|
+
}
|
|
27
|
+
return env[name].fetch(req);
|
|
28
|
+
}
|
|
29
|
+
const url = `${details.protocol}://${details.host}${
|
|
30
|
+
details.port ? `:${details.port}` : ""
|
|
31
|
+
}`;
|
|
32
|
+
const request = new Request(url, ...reqArgs);
|
|
33
|
+
return fetch(request);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
// This means there's no dev binding available.
|
|
38
|
+
// Let's use whatever's available, or put a shim with a message.
|
|
39
|
+
facadeEnv[name] = facadeEnv[name] || {
|
|
40
|
+
async fetch() {
|
|
41
|
+
return new Response(
|
|
42
|
+
`You should start up wrangler dev --local on the ${name} worker`,
|
|
43
|
+
{ status: 404 }
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return worker.fetch(req, facadeEnv, ctx);
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "__ENTRY_POINT__";
|
|
2
|
+
const Workers = __WORKERS__;
|
|
3
|
+
|
|
4
|
+
// For every Worker definition that's available,
|
|
5
|
+
// create a fetcher for it on the facade env.
|
|
6
|
+
for (const [name, details] of Object.entries(Workers)) {
|
|
7
|
+
if (details) {
|
|
8
|
+
globalThis[name] = {
|
|
9
|
+
async fetch(...reqArgs) {
|
|
10
|
+
if (details.headers) {
|
|
11
|
+
const req = new Request(...reqArgs);
|
|
12
|
+
for (const [key, value] of Object.entries(details.headers)) {
|
|
13
|
+
// In remote mode, you need to add a couple of headers
|
|
14
|
+
// to make sure it's talking to the 'dev' preview session
|
|
15
|
+
// (much like wrangler dev already does via proxy.ts)
|
|
16
|
+
req.headers.set(key, value);
|
|
17
|
+
}
|
|
18
|
+
return env[name].fetch(req);
|
|
19
|
+
}
|
|
20
|
+
const url = `${details.protocol}://${details.host}${
|
|
21
|
+
details.port ? `:${details.port}` : ""
|
|
22
|
+
}`;
|
|
23
|
+
const request = new Request(url, ...reqArgs);
|
|
24
|
+
return fetch(request);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
} else {
|
|
28
|
+
// This means it's a local mode binding
|
|
29
|
+
// but hasn't started up locally yet.
|
|
30
|
+
globalThis[name] = {
|
|
31
|
+
async fetch() {
|
|
32
|
+
return new Response(
|
|
33
|
+
`You should start up wrangler dev --local on the ${name} worker`,
|
|
34
|
+
{ status: 404 }
|
|
35
|
+
);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|