wrangler 0.0.0-e043479 → 0.0.0-e09abbc
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/Cloudflare_CA.pem +18 -0
- package/README.md +33 -14
- package/bin/wrangler.js +160 -28
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +5354 -0
- package/package.json +166 -136
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +42 -0
- package/src/__tests__/configuration.test.ts +3942 -2178
- package/src/__tests__/dev.test.tsx +1191 -235
- package/src/__tests__/guess-worker-format.test.ts +76 -57
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/mock-account-id.ts +26 -22
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +96 -92
- package/src/__tests__/helpers/mock-console.ts +59 -32
- package/src/__tests__/helpers/mock-dialogs.ts +121 -33
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +74 -0
- package/src/__tests__/helpers/mock-kv.ts +28 -35
- package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +29 -20
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +163 -0
- package/src/__tests__/index.test.ts +246 -850
- package/src/__tests__/init.test.ts +1992 -0
- package/src/__tests__/jest.setup.ts +85 -34
- package/src/__tests__/kv.test.ts +1402 -1139
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/metrics.test.ts +445 -0
- package/src/__tests__/package-manager.test.ts +312 -165
- package/src/__tests__/pages.test.ts +1261 -0
- package/src/__tests__/parse.test.ts +253 -245
- package/src/__tests__/publish.test.ts +6611 -2079
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +184 -149
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +474 -407
- package/src/__tests__/tail.test.ts +565 -431
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/user.test.ts +143 -0
- package/src/__tests__/whoami.test.tsx +219 -75
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +3 -0
- package/src/api/dev.ts +86 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +196 -93
- package/src/cfetch/index.ts +83 -66
- package/src/cfetch/internal.ts +100 -84
- package/src/cli.ts +22 -14
- package/src/config/README.md +7 -7
- package/src/config/config.ts +223 -242
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +404 -256
- package/src/config/index.ts +218 -32
- package/src/config/validation-helpers.ts +436 -222
- package/src/config/validation.ts +1642 -907
- package/src/config-cache.ts +84 -0
- package/src/create-worker-preview.ts +255 -0
- package/src/create-worker-upload-form.ts +263 -0
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +452 -0
- package/src/dev/local.tsx +373 -0
- package/src/dev/remote.tsx +386 -0
- package/src/dev/use-esbuild.ts +150 -0
- package/src/dev.tsx +576 -943
- package/src/dialogs.tsx +115 -57
- package/src/durable.ts +102 -0
- package/src/entry.ts +308 -37
- package/src/environment-variables.ts +25 -23
- package/src/errors.ts +11 -0
- package/src/faye-websocket.d.ts +6 -0
- package/src/generate.ts +33 -0
- package/src/git-client.ts +42 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +127 -0
- package/src/index.tsx +1910 -2241
- package/src/init.ts +549 -0
- package/src/inspect.ts +603 -550
- package/src/intl-polyfill.d.ts +139 -0
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +430 -0
- package/src/logger.ts +73 -0
- package/src/metrics/index.ts +4 -0
- package/src/metrics/is-ci.ts +14 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +95 -0
- package/src/metrics/send-event.ts +92 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/assets.ts +543 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +85 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +234 -146
- package/src/open-in-browser.ts +10 -6
- package/src/package-manager.ts +183 -90
- package/src/pages/build.tsx +204 -0
- package/src/pages/constants.ts +7 -0
- package/src/pages/deployments.tsx +106 -0
- package/src/pages/dev.tsx +401 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/src/pages/functions/filepath-routing.test.ts +234 -0
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +163 -0
- package/src/pages/publish.tsx +338 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +396 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +224 -121
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +413 -313
- package/src/publish.ts +773 -343
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +623 -0
- package/src/r2.ts +19 -19
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +285 -151
- package/src/tail/filters.ts +108 -108
- package/src/tail/index.ts +217 -217
- package/src/tail/printing.ts +51 -46
- package/src/update-check.ts +19 -0
- package/src/user/choose-account.tsx +69 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1171 -0
- package/src/whoami.tsx +63 -41
- package/src/worker-namespace.ts +206 -0
- package/src/worker.ts +191 -0
- package/src/zones.ts +76 -0
- package/templates/checked-fetch.js +17 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +18 -3
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/static-asset-facade.js +38 -36
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.d.ts +327 -0
- package/wrangler-dist/cli.js +94947 -111199
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -123
- package/pages/functions/filepath-routing.ts +0 -178
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -151
- package/pages/functions/template-worker.ts +0 -130
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/api/form_data.ts +0 -217
- package/src/api/preview.ts +0 -147
- package/src/api/worker.ts +0 -186
- package/src/guess-worker-format.ts +0 -68
- package/src/kv.tsx +0 -339
- package/src/pages.tsx +0 -1045
- package/src/reporting.ts +0 -115
- package/src/user.tsx +0 -1063
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
package/src/api/preview.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { URL } from "node:url";
|
|
2
|
-
import { fetch } from "undici";
|
|
3
|
-
import { fetchResult } from "../cfetch";
|
|
4
|
-
import { toFormData } from "./form_data";
|
|
5
|
-
import type { CfAccount, CfWorkerContext, CfWorkerInit } from "./worker";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A preview mode.
|
|
9
|
-
*
|
|
10
|
-
* * If true, then using a `workers.dev` subdomain.
|
|
11
|
-
* * Otherwise, a list of routes under a single zone.
|
|
12
|
-
*/
|
|
13
|
-
type CfPreviewMode = { workers_dev: boolean } | { routes: string[] };
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A preview token.
|
|
17
|
-
*/
|
|
18
|
-
export interface CfPreviewToken {
|
|
19
|
-
/**
|
|
20
|
-
* The header value required to trigger a preview.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const headers = { 'cf-workers-preview-token': value }
|
|
24
|
-
* const response = await fetch('https://' + host, { headers })
|
|
25
|
-
*/
|
|
26
|
-
value: string;
|
|
27
|
-
/**
|
|
28
|
-
* The host where the preview is available.
|
|
29
|
-
*/
|
|
30
|
-
host: string;
|
|
31
|
-
/**
|
|
32
|
-
* A websocket url to a DevTools inspector.
|
|
33
|
-
*
|
|
34
|
-
* Workers does not have a fully-featured implementation
|
|
35
|
-
* of the Chrome DevTools protocol, but supports the following:
|
|
36
|
-
* * `console.log()` output.
|
|
37
|
-
* * `Error` stack traces.
|
|
38
|
-
* * `fetch()` events.
|
|
39
|
-
*
|
|
40
|
-
* There is no support for breakpoints, but we want to implement
|
|
41
|
-
* this eventually.
|
|
42
|
-
*
|
|
43
|
-
* @link https://chromedevtools.github.io/devtools-protocol/
|
|
44
|
-
*/
|
|
45
|
-
inspectorUrl: URL;
|
|
46
|
-
/**
|
|
47
|
-
* A url to prewarm the preview session.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* fetch(prewarmUrl, { method: 'POST' })
|
|
51
|
-
*/
|
|
52
|
-
prewarmUrl: URL;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Generates a preview session token.
|
|
57
|
-
*/
|
|
58
|
-
async function sessionToken(
|
|
59
|
-
account: CfAccount,
|
|
60
|
-
ctx: CfWorkerContext
|
|
61
|
-
): Promise<CfPreviewToken> {
|
|
62
|
-
const { accountId } = account;
|
|
63
|
-
const initUrl = ctx.zone
|
|
64
|
-
? `/zones/${ctx.zone.id}/workers/edge-preview`
|
|
65
|
-
: `/accounts/${accountId}/workers/subdomain/edge-preview`;
|
|
66
|
-
|
|
67
|
-
const { exchange_url } = await fetchResult<{ exchange_url: string }>(initUrl);
|
|
68
|
-
const { inspector_websocket, token } = (await (
|
|
69
|
-
await fetch(exchange_url)
|
|
70
|
-
).json()) as { inspector_websocket: string; token: string };
|
|
71
|
-
const { host } = new URL(inspector_websocket);
|
|
72
|
-
const query = `cf_workers_preview_token=${token}`;
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
value: token,
|
|
76
|
-
host,
|
|
77
|
-
inspectorUrl: new URL(`${inspector_websocket}?${query}`),
|
|
78
|
-
prewarmUrl: new URL(
|
|
79
|
-
`https://${host}/cdn-cgi/workers/preview/prewarm?${query}`
|
|
80
|
-
),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Credit: https://stackoverflow.com/a/2117523
|
|
85
|
-
function randomId(): string {
|
|
86
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
87
|
-
const r = (Math.random() * 16) | 0,
|
|
88
|
-
v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
89
|
-
return v.toString(16);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Creates a preview token.
|
|
95
|
-
*/
|
|
96
|
-
export async function previewToken(
|
|
97
|
-
account: CfAccount,
|
|
98
|
-
worker: CfWorkerInit,
|
|
99
|
-
ctx: CfWorkerContext
|
|
100
|
-
): Promise<CfPreviewToken> {
|
|
101
|
-
const { value, host, inspectorUrl, prewarmUrl } = await sessionToken(
|
|
102
|
-
account,
|
|
103
|
-
ctx
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const { accountId } = account;
|
|
107
|
-
const scriptId = ctx.zone ? randomId() : worker.name || host.split(".")[0];
|
|
108
|
-
const url =
|
|
109
|
-
ctx.env && !ctx.legacyEnv
|
|
110
|
-
? `/accounts/${accountId}/workers/services/${scriptId}/environments/${ctx.env}/edge-preview`
|
|
111
|
-
: `/accounts/${accountId}/workers/scripts/${scriptId}/edge-preview`;
|
|
112
|
-
|
|
113
|
-
const mode: CfPreviewMode = ctx.zone
|
|
114
|
-
? { routes: ["*/*"] } // TODO: should we support routes here? how?
|
|
115
|
-
: { workers_dev: true };
|
|
116
|
-
|
|
117
|
-
const formData = toFormData(worker);
|
|
118
|
-
formData.set("wrangler-session-config", JSON.stringify(mode));
|
|
119
|
-
|
|
120
|
-
const { preview_token } = await fetchResult<{ preview_token: string }>(url, {
|
|
121
|
-
method: "POST",
|
|
122
|
-
body: formData,
|
|
123
|
-
headers: {
|
|
124
|
-
"cf-preview-upload-config-token": value,
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
value: preview_token,
|
|
130
|
-
host: ctx.zone
|
|
131
|
-
? ctx.zone.host
|
|
132
|
-
: worker.name
|
|
133
|
-
? `${
|
|
134
|
-
worker.name
|
|
135
|
-
// TODO: this should also probably have the env prefix
|
|
136
|
-
// but it doesn't appear to work yet, instead giving us the
|
|
137
|
-
// "There is nothing here yet" screen
|
|
138
|
-
// ctx.env && !ctx.legacyEnv
|
|
139
|
-
// ? `${ctx.env}.${worker.name}`
|
|
140
|
-
// : worker.name
|
|
141
|
-
}.${host.split(".").slice(1).join(".")}`
|
|
142
|
-
: host,
|
|
143
|
-
|
|
144
|
-
inspectorUrl,
|
|
145
|
-
prewarmUrl,
|
|
146
|
-
};
|
|
147
|
-
}
|
package/src/api/worker.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { fetch } from "undici";
|
|
2
|
-
import { previewToken } from "./preview";
|
|
3
|
-
import type { CfPreviewToken } from "./preview";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A Cloudflare account.
|
|
7
|
-
*/
|
|
8
|
-
export interface CfAccount {
|
|
9
|
-
/**
|
|
10
|
-
* An API token.
|
|
11
|
-
*
|
|
12
|
-
* @link https://api.cloudflare.com/#user-api-tokens-properties
|
|
13
|
-
*/
|
|
14
|
-
apiToken: string;
|
|
15
|
-
/**
|
|
16
|
-
* An account ID.
|
|
17
|
-
*/
|
|
18
|
-
accountId: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The type of Worker
|
|
23
|
-
*/
|
|
24
|
-
export type CfScriptFormat = "modules" | "service-worker";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A module type.
|
|
28
|
-
*/
|
|
29
|
-
export type CfModuleType =
|
|
30
|
-
| "esm"
|
|
31
|
-
| "commonjs"
|
|
32
|
-
| "compiled-wasm"
|
|
33
|
-
| "text"
|
|
34
|
-
| "buffer";
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* An imported module.
|
|
38
|
-
*/
|
|
39
|
-
export interface CfModule {
|
|
40
|
-
/**
|
|
41
|
-
* The module name.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* './src/index.js'
|
|
45
|
-
*/
|
|
46
|
-
name: string;
|
|
47
|
-
/**
|
|
48
|
-
* The module content, usually JavaScript or WASM code.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* export default {
|
|
52
|
-
* async fetch(request) {
|
|
53
|
-
* return new Response('Ok')
|
|
54
|
-
* }
|
|
55
|
-
* }
|
|
56
|
-
*/
|
|
57
|
-
content: string | Buffer;
|
|
58
|
-
/**
|
|
59
|
-
* The module type.
|
|
60
|
-
*
|
|
61
|
-
* If absent, will default to the main module's type.
|
|
62
|
-
*/
|
|
63
|
-
type?: CfModuleType;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* A map of variable names to values.
|
|
68
|
-
*/
|
|
69
|
-
interface CfVars {
|
|
70
|
-
[key: string]: unknown;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A KV namespace.
|
|
75
|
-
*/
|
|
76
|
-
interface CfKvNamespace {
|
|
77
|
-
binding: string;
|
|
78
|
-
id: string;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* A binding to a wasm module (in service worker format)
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
interface CfWasmModuleBindings {
|
|
86
|
-
[key: string]: string;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* A binding to a text blob (in service worker format)
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
interface CfTextBlobBindings {
|
|
94
|
-
[key: string]: string;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* A Durable Object.
|
|
99
|
-
*/
|
|
100
|
-
interface CfDurableObject {
|
|
101
|
-
name: string;
|
|
102
|
-
class_name: string;
|
|
103
|
-
script_name?: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
interface CfR2Bucket {
|
|
107
|
-
binding: string;
|
|
108
|
-
bucket_name: string;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
interface CfUnsafeBinding {
|
|
112
|
-
name: string;
|
|
113
|
-
type: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface CfDurableObjectMigrations {
|
|
117
|
-
old_tag?: string;
|
|
118
|
-
new_tag: string;
|
|
119
|
-
steps: {
|
|
120
|
-
new_classes?: string[];
|
|
121
|
-
renamed_classes?: {
|
|
122
|
-
from: string;
|
|
123
|
-
to: string;
|
|
124
|
-
}[];
|
|
125
|
-
deleted_classes?: string[];
|
|
126
|
-
}[];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Options for creating a `CfWorker`.
|
|
131
|
-
*/
|
|
132
|
-
export interface CfWorkerInit {
|
|
133
|
-
/**
|
|
134
|
-
* The name of the worker.
|
|
135
|
-
*/
|
|
136
|
-
name: string | undefined;
|
|
137
|
-
/**
|
|
138
|
-
* The entrypoint module.
|
|
139
|
-
*/
|
|
140
|
-
main: CfModule;
|
|
141
|
-
/**
|
|
142
|
-
* The list of additional modules.
|
|
143
|
-
*/
|
|
144
|
-
modules: undefined | CfModule[];
|
|
145
|
-
/**
|
|
146
|
-
* All the bindings
|
|
147
|
-
*/
|
|
148
|
-
bindings: {
|
|
149
|
-
vars: CfVars | undefined;
|
|
150
|
-
kv_namespaces: CfKvNamespace[] | undefined;
|
|
151
|
-
wasm_modules: CfWasmModuleBindings | undefined;
|
|
152
|
-
text_blobs: CfTextBlobBindings | undefined;
|
|
153
|
-
durable_objects: { bindings: CfDurableObject[] } | undefined;
|
|
154
|
-
r2_buckets: CfR2Bucket[] | undefined;
|
|
155
|
-
unsafe: CfUnsafeBinding[] | undefined;
|
|
156
|
-
};
|
|
157
|
-
migrations: undefined | CfDurableObjectMigrations;
|
|
158
|
-
compatibility_date: string | undefined;
|
|
159
|
-
compatibility_flags: undefined | string[];
|
|
160
|
-
usage_model: undefined | "bundled" | "unbound";
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export interface CfWorkerContext {
|
|
164
|
-
env: string | undefined;
|
|
165
|
-
legacyEnv: boolean | undefined;
|
|
166
|
-
zone: { id: string; host: string } | undefined;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* A stub to create a Cloudflare Worker preview.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* const {value, host} = await createWorker(init, acct);
|
|
174
|
-
*/
|
|
175
|
-
export async function createWorker(
|
|
176
|
-
init: CfWorkerInit,
|
|
177
|
-
account: CfAccount,
|
|
178
|
-
ctx: CfWorkerContext
|
|
179
|
-
): Promise<CfPreviewToken> {
|
|
180
|
-
const token = await previewToken(account, init, ctx);
|
|
181
|
-
const response = await fetch(token.prewarmUrl.href, { method: "POST" });
|
|
182
|
-
if (!response.ok) {
|
|
183
|
-
// console.error("worker failed to prewarm: ", response.statusText);
|
|
184
|
-
}
|
|
185
|
-
return token;
|
|
186
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import assert from "node:assert";
|
|
2
|
-
import { build } from "esbuild";
|
|
3
|
-
import type { CfScriptFormat } from "./api/worker";
|
|
4
|
-
import type { Entry } from "./entry";
|
|
5
|
-
import type { Metafile } from "esbuild";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A function to "guess" the type of worker.
|
|
9
|
-
* We do this by running a lightweight build of the actual script,
|
|
10
|
-
* and looking at the metafile generated by esbuild. If it has a default
|
|
11
|
-
* export (or really, any exports), that means it's a "modules" worker.
|
|
12
|
-
* Else, it's a "service-worker" worker. This seems hacky, but works remarkably
|
|
13
|
-
* well in practice.
|
|
14
|
-
*/
|
|
15
|
-
export default async function guessWorkerFormat(
|
|
16
|
-
entry: Entry,
|
|
17
|
-
hint: CfScriptFormat | undefined
|
|
18
|
-
): Promise<CfScriptFormat> {
|
|
19
|
-
const result = await build({
|
|
20
|
-
entryPoints: [entry.file],
|
|
21
|
-
absWorkingDir: entry.directory,
|
|
22
|
-
metafile: true,
|
|
23
|
-
bundle: false,
|
|
24
|
-
format: "esm",
|
|
25
|
-
write: false,
|
|
26
|
-
});
|
|
27
|
-
// result.metafile is defined because of the `metafile: true` option above.
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
29
|
-
const metafile = result.metafile!;
|
|
30
|
-
const entryPoints = Object.entries(metafile.outputs).filter(
|
|
31
|
-
([_path, output]) => output.entryPoint !== undefined
|
|
32
|
-
);
|
|
33
|
-
assert(
|
|
34
|
-
entryPoints.length > 0,
|
|
35
|
-
`Cannot find entry-point "${entry.file}" in generated bundle.` +
|
|
36
|
-
listEntryPoints(entryPoints)
|
|
37
|
-
);
|
|
38
|
-
assert(
|
|
39
|
-
entryPoints.length < 2,
|
|
40
|
-
"More than one entry-point found for generated bundle." +
|
|
41
|
-
listEntryPoints(entryPoints)
|
|
42
|
-
);
|
|
43
|
-
const guessedWorkerFormat =
|
|
44
|
-
entryPoints[0][1].exports.length > 0 ? "modules" : "service-worker";
|
|
45
|
-
|
|
46
|
-
if (hint) {
|
|
47
|
-
if (hint !== guessedWorkerFormat) {
|
|
48
|
-
if (hint === "service-worker") {
|
|
49
|
-
throw new Error(
|
|
50
|
-
"You configured this worker to be a 'service-worker', but the file you are trying to build appears to have ES module exports. Please pass `--format modules`, or simply remove the configuration."
|
|
51
|
-
);
|
|
52
|
-
} else {
|
|
53
|
-
throw new Error(
|
|
54
|
-
"You configured this worker to be 'modules', but the file you are trying to build doesn't export a handler. Please pass `--format service-worker`, or simply remove the configuration."
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return guessedWorkerFormat;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function listEntryPoints(
|
|
63
|
-
outputs: [string, ValueOf<Metafile["outputs"]>][]
|
|
64
|
-
): string {
|
|
65
|
-
return outputs.map(([_input, output]) => output.entryPoint).join("\n");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type ValueOf<T> = T[keyof T];
|