wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9
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 +16 -2
- package/bin/wrangler.js +31 -11
- package/miniflare-dist/index.mjs +1340 -330
- package/package.json +40 -13
- package/src/__tests__/access.test.ts +25 -0
- package/src/__tests__/api-dev.test.ts +238 -0
- package/src/__tests__/api-devregistry.test.js +64 -0
- package/src/__tests__/api.test.ts +80 -0
- package/src/__tests__/configuration.test.ts +683 -470
- package/src/__tests__/d1.test.ts +123 -0
- package/src/__tests__/delete.test.ts +263 -0
- package/src/__tests__/deployments.test.ts +105 -0
- package/src/__tests__/dev.test.tsx +453 -70
- package/src/__tests__/dialogs.test.tsx +40 -0
- package/src/__tests__/generate.test.ts +235 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-cfetch.ts +92 -26
- package/src/__tests__/helpers/mock-console.ts +11 -2
- package/src/__tests__/helpers/mock-dialogs.ts +1 -1
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +1 -1
- package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
- package/src/__tests__/helpers/msw/index.ts +21 -0
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
- package/src/__tests__/index.test.ts +103 -97
- package/src/__tests__/init.test.ts +1484 -382
- package/src/__tests__/jest.setup.ts +88 -5
- package/src/__tests__/kv.test.ts +655 -540
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +95 -45
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +750 -0
- package/src/__tests__/pages-deployment-tail.test.ts +884 -0
- package/src/__tests__/pages.test.ts +1301 -119
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +2266 -1180
- package/src/__tests__/pubsub.test.ts +211 -88
- package/src/__tests__/queues.test.ts +522 -0
- package/src/__tests__/r2.test.ts +363 -203
- package/src/__tests__/secret.test.ts +261 -59
- package/src/__tests__/tail.test.ts +352 -151
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +233 -0
- package/src/__tests__/user.test.ts +59 -73
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/whoami.test.tsx +114 -66
- package/src/__tests__/worker-namespace.test.ts +154 -155
- package/src/api/dev.ts +170 -38
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +41 -2
- package/src/bundle.ts +668 -81
- package/src/cfetch/index.ts +40 -3
- package/src/cfetch/internal.ts +144 -32
- package/src/cli.ts +4 -3
- package/src/config/config.ts +27 -3
- package/src/config/environment.ts +131 -7
- package/src/config/index.ts +128 -8
- package/src/config/validation-helpers.ts +19 -6
- package/src/config/validation.ts +411 -14
- package/src/config-cache.ts +3 -2
- package/src/create-worker-preview.ts +31 -6
- package/src/create-worker-upload-form.ts +84 -22
- package/src/d1/backups.tsx +223 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +63 -0
- package/src/d1/delete.tsx +56 -0
- package/src/d1/execute.tsx +352 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +101 -0
- package/src/d1/list.tsx +48 -0
- package/src/d1/migrations/apply.tsx +196 -0
- package/src/d1/migrations/create.tsx +77 -0
- package/src/d1/migrations/helpers.ts +147 -0
- package/src/d1/migrations/index.tsx +3 -0
- package/src/d1/migrations/list.tsx +79 -0
- package/src/d1/migrations/options.ts +18 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/types.tsx +24 -0
- package/src/d1/utils.ts +48 -0
- package/src/delete.ts +108 -0
- package/src/deployments.ts +83 -0
- package/src/deprecated/index.ts +145 -0
- package/src/dev/dev-vars.ts +11 -8
- package/src/dev/dev.tsx +220 -58
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +740 -181
- package/src/dev/remote.tsx +340 -123
- package/src/dev/start-server.ts +543 -0
- package/src/dev/use-esbuild.ts +61 -7
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +201 -0
- package/src/dev.tsx +614 -258
- package/src/dialogs.tsx +41 -8
- package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +3 -2
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +300 -0
- package/src/git-client.ts +100 -7
- package/src/index.tsx +249 -1560
- package/src/init.ts +626 -150
- package/src/inspect.ts +137 -32
- package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
- package/src/is-interactive.ts +4 -0
- package/src/jest.d.ts +4 -0
- package/src/{kv.ts → kv/helpers.ts} +3 -3
- package/src/kv/index.ts +596 -0
- package/src/logger.ts +27 -8
- package/src/metrics/index.ts +1 -0
- package/src/metrics/metrics-config.ts +4 -4
- package/src/metrics/metrics-dispatcher.ts +1 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +13 -8
- package/src/miniflare-cli/assets.ts +172 -465
- package/src/miniflare-cli/index.ts +149 -24
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +12 -3
- package/src/pages/build.tsx +108 -42
- package/src/pages/constants.ts +11 -0
- package/src/pages/deployment-tails.tsx +284 -0
- package/src/pages/deployments.tsx +9 -31
- package/src/pages/dev.tsx +417 -108
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +86 -84
- package/src/pages/functions/buildWorker.ts +121 -106
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +282 -0
- package/src/pages/functions/routes-transformation.ts +115 -0
- package/src/pages/functions/routes-validation.test.ts +403 -0
- package/src/pages/functions/routes-validation.ts +202 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.tsx +82 -0
- package/src/pages/hash.tsx +13 -0
- package/src/pages/index.tsx +73 -55
- package/src/pages/projects.tsx +9 -3
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +183 -60
- package/src/pages/types.ts +1 -0
- package/src/pages/upload.tsx +107 -56
- package/src/pages/utils.ts +13 -2
- package/src/paths.ts +49 -4
- package/src/proxy.ts +375 -157
- package/src/publish/index.ts +270 -0
- package/src/{publish.ts → publish/publish.ts} +431 -188
- package/src/pubsub/pubsub-commands.tsx +4 -3
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +22 -0
- package/src/queues/cli/commands/consumer/remove.ts +38 -0
- package/src/queues/cli/commands/create.ts +25 -0
- package/src/queues/cli/commands/delete.ts +26 -0
- package/src/queues/cli/commands/index.ts +36 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +135 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +131 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +379 -0
- package/src/sites.tsx +3 -3
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +4 -6
- package/src/tail/index.ts +199 -284
- package/src/tail/printing.ts +43 -3
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -1
- package/src/user/index.ts +0 -1
- package/src/user/user.tsx +116 -49
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/whoami.tsx +80 -2
- package/src/worker.ts +69 -9
- package/src/yargs-types.ts +24 -0
- package/src/zones.ts +124 -9
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/d1-beta-facade.js +205 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +33 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +62 -0
- package/templates/middleware/loader-modules.ts +82 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/new-worker.js +1 -1
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +21 -5
- package/templates/pages-template-worker.ts +37 -9
- package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
- package/templates/service-bindings-module-facade.js +54 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +106 -0
- package/templates/tsconfig.json +5 -102
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +621 -42
- package/wrangler-dist/cli.js +144441 -102606
- package/src/environment-variables.ts +0 -35
- package/src/faye-websocket.d.ts +0 -6
- package/src/generate.ts +0 -33
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/preview.ts +0 -31
- package/src/r2.ts +0 -50
- package/src/user/env-vars.ts +0 -46
package/src/api/dev.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fetch, Request } from "undici";
|
|
2
|
+
import { startApiDev, startDev } from "../dev";
|
|
2
3
|
import { logger } from "../logger";
|
|
3
4
|
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
5
|
+
import type { Environment } from "../config";
|
|
6
|
+
import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli/types";
|
|
7
|
+
import type { RequestInit, Response, RequestInfo } from "undici";
|
|
6
8
|
|
|
7
|
-
interface
|
|
9
|
+
export interface UnstableDevOptions {
|
|
10
|
+
config?: string;
|
|
8
11
|
env?: string;
|
|
9
12
|
ip?: string;
|
|
10
13
|
port?: number;
|
|
14
|
+
bundle?: boolean;
|
|
15
|
+
inspectorPort?: number;
|
|
11
16
|
localProtocol?: "http" | "https";
|
|
12
17
|
assets?: string;
|
|
13
18
|
site?: string;
|
|
@@ -15,10 +20,12 @@ interface DevOptions {
|
|
|
15
20
|
siteExclude?: string[];
|
|
16
21
|
nodeCompat?: boolean;
|
|
17
22
|
compatibilityDate?: string;
|
|
18
|
-
|
|
23
|
+
compatibilityFlags?: string[];
|
|
24
|
+
persist?: boolean;
|
|
25
|
+
persistTo?: string;
|
|
19
26
|
liveReload?: boolean;
|
|
20
27
|
watch?: boolean;
|
|
21
|
-
vars
|
|
28
|
+
vars?: {
|
|
22
29
|
[key: string]: unknown;
|
|
23
30
|
};
|
|
24
31
|
kv?: {
|
|
@@ -32,55 +39,180 @@ interface DevOptions {
|
|
|
32
39
|
script_name?: string | undefined;
|
|
33
40
|
environment?: string | undefined;
|
|
34
41
|
}[];
|
|
42
|
+
r2?: {
|
|
43
|
+
binding: string;
|
|
44
|
+
bucket_name: string;
|
|
45
|
+
preview_bucket_name?: string;
|
|
46
|
+
}[];
|
|
47
|
+
d1Databases?: Environment["d1_databases"];
|
|
35
48
|
showInteractiveDevSession?: boolean;
|
|
36
|
-
logLevel?: "none" | "error" | "log" | "warn" | "debug";
|
|
49
|
+
logLevel?: "none" | "info" | "error" | "log" | "warn" | "debug";
|
|
37
50
|
logPrefix?: string;
|
|
38
51
|
inspect?: boolean;
|
|
52
|
+
local?: boolean;
|
|
39
53
|
forceLocal?: boolean;
|
|
40
54
|
enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
testScheduled?: boolean;
|
|
56
|
+
experimentalLocal?: boolean;
|
|
57
|
+
accountId?: string;
|
|
58
|
+
experimentalLocalRemoteKv?: boolean;
|
|
59
|
+
experimental?: {
|
|
60
|
+
testMode?: boolean;
|
|
61
|
+
disableExperimentalWarning?: boolean;
|
|
62
|
+
disableDevRegistry?: boolean;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface UnstableDevWorker {
|
|
67
|
+
port: number;
|
|
68
|
+
address: string;
|
|
69
|
+
stop: () => Promise<void>;
|
|
70
|
+
fetch: (input?: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
71
|
+
waitUntilExit: () => Promise<void>;
|
|
43
72
|
}
|
|
44
73
|
/**
|
|
45
74
|
* unstable_dev starts a wrangler dev server, and returns a promise that resolves with utility functions to interact with it.
|
|
46
|
-
* @param {string} script
|
|
47
|
-
* @param {DevOptions} options
|
|
48
75
|
*/
|
|
49
76
|
export async function unstable_dev(
|
|
50
77
|
script: string,
|
|
51
|
-
options
|
|
52
|
-
|
|
53
|
-
) {
|
|
78
|
+
options?: UnstableDevOptions,
|
|
79
|
+
apiOptions?: unknown
|
|
80
|
+
): Promise<UnstableDevWorker> {
|
|
81
|
+
const {
|
|
82
|
+
testMode = true,
|
|
83
|
+
disableExperimentalWarning = false,
|
|
84
|
+
disableDevRegistry = false,
|
|
85
|
+
} = options?.experimental ?? {};
|
|
86
|
+
if (apiOptions) {
|
|
87
|
+
logger.error(
|
|
88
|
+
"unstable_dev's third argument (apiOptions) has been deprecated in favor of an `experimental` property within the second argument (options).\nPlease update your code from:\n`await unstable_dev('...', {...}, {...});`\nto:\n`await unstable_dev('...', {..., experimental: {...}});`"
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
54
92
|
if (!disableExperimentalWarning) {
|
|
55
93
|
logger.warn(
|
|
56
94
|
`unstable_dev() is experimental\nunstable_dev()'s behaviour will likely change in future releases`
|
|
57
95
|
);
|
|
58
96
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
97
|
+
let readyPort: number;
|
|
98
|
+
let readyAddress: string;
|
|
99
|
+
//due to Pages adoption of unstable_dev, we can't *just* disable rebuilds and watching. instead, we'll have two versions of startDev, which will converge.
|
|
100
|
+
if (testMode) {
|
|
101
|
+
//in testMode, we can run multiple wranglers in parallel, but rebuilds might not work out of the box
|
|
102
|
+
return new Promise<UnstableDevWorker>((resolve) => {
|
|
103
|
+
//lmao
|
|
104
|
+
return new Promise<Awaited<ReturnType<typeof startApiDev>>>((ready) => {
|
|
105
|
+
// once the devServer is ready for requests, we resolve the inner promise
|
|
106
|
+
// (where we've named the resolve function "ready")
|
|
107
|
+
const devServer = startApiDev({
|
|
108
|
+
script: script,
|
|
109
|
+
inspect: false,
|
|
110
|
+
logLevel: "none",
|
|
111
|
+
showInteractiveDevSession: false,
|
|
112
|
+
_: [],
|
|
113
|
+
$0: "",
|
|
114
|
+
port: options?.port ?? 0,
|
|
115
|
+
local: true,
|
|
116
|
+
disableDevRegistry,
|
|
117
|
+
...options,
|
|
118
|
+
onReady: (address, port) => {
|
|
119
|
+
readyPort = port;
|
|
120
|
+
readyAddress = address;
|
|
121
|
+
ready(devServer);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}).then((devServer) => {
|
|
125
|
+
// now that the inner promise has resolved, we can resolve the outer promise
|
|
126
|
+
// with an object that lets you fetch and stop the dev server
|
|
127
|
+
resolve({
|
|
128
|
+
port: readyPort,
|
|
129
|
+
address: readyAddress,
|
|
130
|
+
stop: devServer.stop,
|
|
131
|
+
fetch: async (input?: RequestInfo, init?: RequestInit) => {
|
|
132
|
+
return await fetch(
|
|
133
|
+
...parseRequestInput(
|
|
134
|
+
readyAddress,
|
|
135
|
+
readyPort,
|
|
136
|
+
input,
|
|
137
|
+
init,
|
|
138
|
+
options?.localProtocol
|
|
139
|
+
)
|
|
140
|
+
);
|
|
141
|
+
},
|
|
142
|
+
//no-op, does nothing in tests
|
|
143
|
+
waitUntilExit: async () => {
|
|
144
|
+
return;
|
|
145
|
+
},
|
|
146
|
+
});
|
|
77
147
|
});
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
148
|
+
});
|
|
149
|
+
} else {
|
|
150
|
+
//outside of test mode, rebuilds work fine, but only one instance of wrangler will work at a time
|
|
151
|
+
|
|
152
|
+
return new Promise<UnstableDevWorker>((resolve) => {
|
|
153
|
+
//lmao
|
|
154
|
+
return new Promise<Awaited<ReturnType<typeof startDev>>>((ready) => {
|
|
155
|
+
const devServer = startDev({
|
|
156
|
+
script: script,
|
|
157
|
+
inspect: false,
|
|
158
|
+
showInteractiveDevSession: false,
|
|
159
|
+
_: [],
|
|
160
|
+
$0: "",
|
|
161
|
+
local: true,
|
|
162
|
+
...options,
|
|
163
|
+
onReady: (address, port) => {
|
|
164
|
+
readyPort = port;
|
|
165
|
+
readyAddress = address;
|
|
166
|
+
ready(devServer);
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
}).then((devServer) => {
|
|
170
|
+
resolve({
|
|
171
|
+
port: readyPort,
|
|
172
|
+
address: readyAddress,
|
|
173
|
+
stop: devServer.stop,
|
|
174
|
+
fetch: async (input?: RequestInfo, init?: RequestInit) => {
|
|
175
|
+
return await fetch(
|
|
176
|
+
...parseRequestInput(
|
|
177
|
+
readyAddress,
|
|
178
|
+
readyPort,
|
|
179
|
+
input,
|
|
180
|
+
init,
|
|
181
|
+
options?.localProtocol
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
waitUntilExit: devServer.devReactElement.waitUntilExit,
|
|
186
|
+
});
|
|
83
187
|
});
|
|
84
188
|
});
|
|
85
|
-
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function parseRequestInput(
|
|
193
|
+
readyAddress: string,
|
|
194
|
+
readyPort: number,
|
|
195
|
+
input?: RequestInfo,
|
|
196
|
+
init?: RequestInit,
|
|
197
|
+
protocol: "http" | "https" = "http"
|
|
198
|
+
): [RequestInfo, RequestInit | undefined] {
|
|
199
|
+
if (input instanceof Request) {
|
|
200
|
+
return [input, undefined];
|
|
201
|
+
} else if (input instanceof URL) {
|
|
202
|
+
input = `${protocol}://${readyAddress}:${readyPort}${input.pathname}`;
|
|
203
|
+
} else if (typeof input === "string") {
|
|
204
|
+
try {
|
|
205
|
+
// Want to strip the URL to only get the pathname, but the user could pass in only the pathname
|
|
206
|
+
// Will error if we try and pass "/something" into new URL("/something")
|
|
207
|
+
input = `${protocol}://${readyAddress}:${readyPort}${
|
|
208
|
+
new URL(input).pathname
|
|
209
|
+
}`;
|
|
210
|
+
} catch {
|
|
211
|
+
input = `${protocol}://${readyAddress}:${readyPort}${input}`;
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
input = `${protocol}://${readyAddress}:${readyPort}`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return [input, init];
|
|
86
218
|
}
|
package/src/api/index.ts
CHANGED
package/src/bundle-reporter.tsx
CHANGED
|
@@ -2,6 +2,10 @@ import { Blob } from "node:buffer";
|
|
|
2
2
|
import { gzipSync } from "node:zlib";
|
|
3
3
|
import { logger } from "./logger";
|
|
4
4
|
import type { CfModule } from "./worker";
|
|
5
|
+
import type { Metafile } from "esbuild";
|
|
6
|
+
|
|
7
|
+
const ONE_KIB_BYTES = 1024;
|
|
8
|
+
const ONE_MIB_BYTES = ONE_KIB_BYTES * 1024;
|
|
5
9
|
|
|
6
10
|
async function getSize(modules: CfModule[]) {
|
|
7
11
|
const gzipSize = gzipSync(
|
|
@@ -21,9 +25,44 @@ export async function printBundleSize(
|
|
|
21
25
|
) {
|
|
22
26
|
const { size, gzipSize } = await getSize([...modules, main]);
|
|
23
27
|
|
|
24
|
-
const bundleReport = `${(size /
|
|
25
|
-
gzipSize /
|
|
28
|
+
const bundleReport = `${(size / ONE_KIB_BYTES).toFixed(2)} KiB / gzip: ${(
|
|
29
|
+
gzipSize / ONE_KIB_BYTES
|
|
26
30
|
).toFixed(2)} KiB`;
|
|
27
31
|
|
|
28
32
|
logger.log(`Total Upload: ${bundleReport}`);
|
|
33
|
+
|
|
34
|
+
if (gzipSize > ONE_MIB_BYTES && !process.env.NO_SCRIPT_SIZE_WARNING) {
|
|
35
|
+
logger.warn(
|
|
36
|
+
"We recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding past this can affect cold start time"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function printOffendingDependencies(
|
|
42
|
+
dependencies: Metafile["outputs"][string]["inputs"]
|
|
43
|
+
) {
|
|
44
|
+
const warning: string[] = [];
|
|
45
|
+
|
|
46
|
+
const dependenciesSorted = Object.entries(dependencies);
|
|
47
|
+
dependenciesSorted.sort(
|
|
48
|
+
([_adep, aData], [_bdep, bData]) =>
|
|
49
|
+
bData.bytesInOutput - aData.bytesInOutput
|
|
50
|
+
);
|
|
51
|
+
const topLargest = dependenciesSorted.slice(0, 5);
|
|
52
|
+
|
|
53
|
+
if (topLargest.length > 0) {
|
|
54
|
+
warning.push(
|
|
55
|
+
`Here are the ${topLargest.length} largest dependencies included in your script:`
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
for (const [dep, data] of topLargest) {
|
|
59
|
+
warning.push(
|
|
60
|
+
`- ${dep} - ${(data.bytesInOutput / ONE_KIB_BYTES).toFixed(2)} KiB`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
warning.push("If these are unnecessary, consider removing them");
|
|
65
|
+
|
|
66
|
+
logger.warn(warning.join("\n"));
|
|
67
|
+
}
|
|
29
68
|
}
|