wrangler 0.0.0-e7a0cd5b ā 0.0.0-e7cf0caa
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 +3 -3
- package/bin/wrangler.js +30 -10
- package/miniflare-dist/index.mjs +126 -74
- package/package.json +27 -19
- package/src/__tests__/api-dev.test.ts +65 -36
- package/src/__tests__/api-devregistry.test.ts +121 -0
- package/src/__tests__/api.test.ts +27 -5
- package/src/__tests__/configuration.test.ts +567 -86
- package/src/__tests__/d1/d1.test.ts +82 -0
- package/src/__tests__/d1/execute.test.ts +66 -0
- package/src/__tests__/d1/migrate.test.ts +157 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +91 -49
- package/src/__tests__/deployments.test.ts +330 -56
- package/src/__tests__/dev.test.tsx +198 -90
- package/src/__tests__/generate.test.ts +12 -10
- package/src/__tests__/guess-worker-format.test.ts +35 -0
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-console.ts +6 -0
- package/src/__tests__/helpers/mock-dialogs.ts +71 -85
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -5
- package/src/__tests__/helpers/mock-known-routes.ts +7 -2
- package/src/__tests__/helpers/mock-kv.ts +29 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +103 -92
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +128 -27
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +18 -41
- package/src/__tests__/helpers/msw/handlers/oauth.ts +13 -18
- package/src/__tests__/helpers/msw/handlers/r2.ts +14 -34
- package/src/__tests__/helpers/msw/handlers/script.ts +9 -28
- package/src/__tests__/helpers/msw/handlers/user.ts +13 -24
- package/src/__tests__/helpers/msw/handlers/zones.ts +6 -8
- package/src/__tests__/helpers/msw/index.ts +32 -1
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +4 -1
- package/src/__tests__/index.test.ts +90 -72
- package/src/__tests__/init.test.ts +927 -631
- package/src/__tests__/jest.setup.ts +19 -42
- package/src/__tests__/kv.test.ts +355 -231
- package/src/__tests__/logger.test.ts +68 -2
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +94 -51
- package/src/__tests__/middleware.scheduled.test.ts +42 -32
- package/src/__tests__/middleware.test.ts +212 -122
- package/src/__tests__/mtls-certificates.test.ts +588 -0
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +452 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +110 -0
- package/src/__tests__/pages/project-upload.test.ts +500 -0
- package/src/__tests__/pages/publish.test.ts +2864 -0
- package/src/__tests__/pages-deployment-tail.test.ts +955 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +1615 -852
- package/src/__tests__/pubsub.test.ts +226 -100
- package/src/__tests__/queues.test.ts +238 -77
- package/src/__tests__/r2.test.ts +55 -57
- package/src/__tests__/secret.test.ts +179 -130
- package/src/__tests__/tail.test.ts +267 -109
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/traverse-module-graph.test.ts +220 -0
- 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 +43 -26
- package/src/__tests__/user.test.ts +35 -72
- package/src/__tests__/whoami.test.tsx +8 -114
- package/src/__tests__/worker-namespace.test.ts +83 -69
- package/src/api/dev.ts +168 -60
- package/src/api/index.ts +10 -1
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +76 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +355 -0
- package/src/bundle.ts +263 -140
- package/src/cfetch/index.ts +0 -2
- package/src/cfetch/internal.ts +16 -21
- package/src/cli.ts +4 -4
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +79 -24
- package/src/config/index.ts +99 -38
- package/src/config/validation-helpers.ts +1 -1
- package/src/config/validation.ts +248 -19
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +60 -22
- package/src/d1/backups.tsx +43 -42
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +44 -30
- package/src/d1/{delete.tsx ā delete.ts} +11 -14
- package/src/d1/execute.tsx +209 -151
- package/src/d1/index.ts +31 -7
- package/src/d1/list.tsx +22 -10
- package/src/d1/migrations/apply.tsx +212 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +172 -0
- package/src/d1/migrations/index.ts +3 -0
- package/src/d1/migrations/list.tsx +95 -0
- package/src/d1/migrations/options.ts +23 -0
- package/src/d1/options.ts +12 -2
- package/src/d1/splitter.ts +161 -0
- package/src/d1/{types.tsx ā types.ts} +11 -0
- package/src/d1/utils.ts +12 -2
- package/src/delete.ts +8 -16
- package/src/deployments.ts +340 -46
- package/src/deprecated/index.ts +8 -302
- package/src/dev/dev.tsx +57 -44
- package/src/dev/local.tsx +294 -91
- package/src/dev/remote.tsx +32 -3
- package/src/dev/start-server.ts +89 -68
- package/src/dev/use-esbuild.ts +17 -18
- package/src/dev/validate-dev-props.ts +9 -0
- package/src/{dev-registry.tsx ā dev-registry.ts} +2 -1
- package/src/dev.tsx +178 -118
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +21 -17
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +19 -11
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +298 -0
- package/src/git-client.ts +15 -4
- package/src/{index.tsx ā index.ts} +137 -63
- package/src/init.ts +249 -187
- package/src/inspect.ts +16 -1
- package/src/jest.d.ts +4 -0
- package/src/kv/index.ts +15 -17
- package/src/logger.ts +32 -5
- package/src/metrics/metrics-config.ts +3 -3
- package/src/metrics/send-event.ts +6 -1
- package/src/miniflare-cli/assets.ts +64 -28
- package/src/miniflare-cli/index.ts +4 -7
- 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 +91 -25
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +410 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/deployment-tails.ts +281 -0
- package/src/pages/deployments.tsx +11 -33
- package/src/pages/{dev.tsx ā dev.ts} +147 -124
- package/src/pages/errors.ts +1 -0
- package/src/pages/functions/buildPlugin.ts +72 -69
- package/src/pages/functions/buildWorker.ts +249 -114
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/{functions.tsx ā functions.ts} +8 -4
- package/src/pages/{index.tsx ā index.ts} +11 -3
- package/src/pages/projects.tsx +12 -22
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +45 -214
- package/src/pages/types.ts +6 -9
- package/src/pages/upload.tsx +58 -14
- package/src/pages/utils.ts +14 -3
- package/src/parse.ts +23 -1
- package/src/paths.ts +1 -1
- package/src/proxy.ts +5 -0
- package/src/publish/index.ts +20 -16
- package/src/publish/publish.ts +72 -47
- package/src/pubsub/{pubsub-commands.tsx ā pubsub-commands.ts} +19 -20
- package/src/queues/cli/commands/consumer/add.ts +24 -24
- package/src/queues/cli/commands/consumer/index.ts +3 -6
- package/src/queues/cli/commands/consumer/remove.ts +11 -18
- package/src/queues/cli/commands/create.ts +8 -8
- package/src/queues/cli/commands/delete.ts +8 -8
- package/src/queues/cli/commands/index.ts +6 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/queues/client.ts +1 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +40 -28
- package/src/secret/index.ts +14 -17
- package/src/{sites.tsx ā sites.ts} +1 -1
- package/src/tail/createTail.ts +94 -3
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +8 -11
- package/src/tail/printing.ts +15 -0
- package/src/traverse-module-graph.ts +53 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +79 -57
- package/src/user/access.ts +0 -1
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -31
- package/src/user/index.ts +0 -1
- package/src/user/{user.tsx ā user.ts} +123 -82
- package/src/utils/render.ts +93 -0
- package/src/{whoami.tsx ā whoami.ts} +37 -71
- package/src/worker.ts +35 -3
- package/src/yargs-types.ts +22 -5
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/checked-fetch.js +9 -3
- package/templates/d1-beta-facade.js +95 -25
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +4 -3
- package/templates/format-dev-errors.ts +8 -6
- package/templates/gitignore +1 -0
- package/templates/init-tests/test-jest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/loader-modules.ts +2 -2
- package/templates/middleware/loader-sw.ts +51 -31
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/new-worker.ts +3 -0
- package/templates/pages-dev-pipeline.ts +4 -1
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +19 -10
- package/templates/serve-static-assets.ts +17 -14
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +5 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +826 -77
- package/wrangler-dist/cli.js +130734 -140838
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/src/__tests__/api-devregistry.test.js +0 -57
- package/src/__tests__/d1.test.ts +0 -72
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/pages.test.ts +0 -2223
- package/src/dialogs.tsx +0 -163
- package/src/environment-variables.ts +0 -50
- package/src/pages/build.tsx +0 -238
- package/src/user/env-vars.ts +0 -46
- package/templates/experimental-local-cache-stubs.js +0 -27
- /package/src/{bundle-reporter.tsx ā bundle-reporter.ts} +0 -0
- /package/src/dev/{get-local-persistence-path.tsx ā get-local-persistence-path.ts} +0 -0
- /package/src/pages/{hash.tsx ā hash.ts} +0 -0
package/src/dev.tsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import chalk from "chalk";
|
|
2
3
|
import { watch } from "chokidar";
|
|
3
4
|
import getPort from "get-port";
|
|
4
5
|
import { render } from "ink";
|
|
@@ -13,12 +14,11 @@ import { getEntry } from "./entry";
|
|
|
13
14
|
import { logger } from "./logger";
|
|
14
15
|
import * as metrics from "./metrics";
|
|
15
16
|
import { getAssetPaths, getSiteAssetPaths } from "./sites";
|
|
16
|
-
import { getAccountFromCache } from "./user";
|
|
17
|
+
import { getAccountFromCache, loginOrRefreshIfRequired } from "./user";
|
|
17
18
|
import { collectKeyValues } from "./utils/collectKeyValues";
|
|
18
19
|
import { identifyD1BindingsAsBeta } from "./worker";
|
|
19
20
|
import { getHostFromRoute, getZoneForRoute, getZoneIdFromHost } from "./zones";
|
|
20
21
|
import {
|
|
21
|
-
type ConfigPath,
|
|
22
22
|
DEFAULT_INSPECTOR_PORT,
|
|
23
23
|
DEFAULT_LOCAL_PORT,
|
|
24
24
|
getDevCompatibilityDate,
|
|
@@ -29,58 +29,15 @@ import {
|
|
|
29
29
|
} from "./index";
|
|
30
30
|
import type { Config, Environment } from "./config";
|
|
31
31
|
import type { Route } from "./config/environment";
|
|
32
|
-
import type {
|
|
32
|
+
import type { LoggerLevel } from "./logger";
|
|
33
|
+
import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types";
|
|
33
34
|
import type { CfWorkerInit } from "./worker";
|
|
34
|
-
import type {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
config?: string;
|
|
39
|
-
script?: string;
|
|
40
|
-
name?: string;
|
|
41
|
-
bundle?: boolean;
|
|
42
|
-
build?: boolean;
|
|
43
|
-
format?: string;
|
|
44
|
-
env?: string;
|
|
45
|
-
"compatibility-date"?: string;
|
|
46
|
-
"compatibility-flags"?: string[];
|
|
47
|
-
latest?: boolean;
|
|
48
|
-
ip?: string;
|
|
49
|
-
inspect?: boolean;
|
|
50
|
-
port?: number;
|
|
51
|
-
"inspector-port"?: number;
|
|
52
|
-
routes?: string[];
|
|
53
|
-
host?: string;
|
|
54
|
-
"local-protocol"?: "http" | "https";
|
|
55
|
-
"local-upstream"?: string | undefined;
|
|
56
|
-
"experimental-public"?: string;
|
|
57
|
-
public?: string;
|
|
58
|
-
assets?: string;
|
|
59
|
-
site?: string;
|
|
60
|
-
"site-include"?: string[];
|
|
61
|
-
"site-exclude"?: string[];
|
|
62
|
-
"upstream-protocol"?: "http" | "https";
|
|
63
|
-
"jsx-factory"?: string;
|
|
64
|
-
"jsx-fragment"?: string;
|
|
65
|
-
tsconfig?: string;
|
|
66
|
-
local?: boolean;
|
|
67
|
-
"experimental-local"?: boolean;
|
|
68
|
-
minify?: boolean;
|
|
69
|
-
var?: string[];
|
|
70
|
-
define?: string[];
|
|
71
|
-
"node-compat"?: boolean;
|
|
72
|
-
"experimental-enable-local-persistence"?: boolean;
|
|
73
|
-
persist?: boolean;
|
|
74
|
-
"persist-to"?: string;
|
|
75
|
-
"live-reload"?: boolean;
|
|
76
|
-
onReady?: (ip: string, port: number) => void;
|
|
77
|
-
logLevel?: "none" | "info" | "error" | "log" | "warn" | "debug";
|
|
78
|
-
logPrefix?: string;
|
|
79
|
-
showInteractiveDevSession?: boolean;
|
|
80
|
-
"test-scheduled"?: boolean;
|
|
81
|
-
}
|
|
35
|
+
import type {
|
|
36
|
+
CommonYargsArgv,
|
|
37
|
+
StrictYargsOptionsToInterface,
|
|
38
|
+
} from "./yargs-types";
|
|
82
39
|
|
|
83
|
-
export function devOptions(yargs:
|
|
40
|
+
export function devOptions(yargs: CommonYargsArgv) {
|
|
84
41
|
return (
|
|
85
42
|
yargs
|
|
86
43
|
.positional("script", {
|
|
@@ -175,6 +132,13 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
|
|
|
175
132
|
type: "string",
|
|
176
133
|
requiresArg: true,
|
|
177
134
|
})
|
|
135
|
+
.option("public", {
|
|
136
|
+
describe: "(Deprecated) Static assets to be served",
|
|
137
|
+
type: "string",
|
|
138
|
+
requiresArg: true,
|
|
139
|
+
deprecated: true,
|
|
140
|
+
hidden: true,
|
|
141
|
+
})
|
|
178
142
|
.option("site", {
|
|
179
143
|
describe: "Root folder of static assets for Workers Sites",
|
|
180
144
|
type: "string",
|
|
@@ -237,11 +201,25 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
|
|
|
237
201
|
type: "boolean",
|
|
238
202
|
default: false,
|
|
239
203
|
})
|
|
204
|
+
.option("experimental-local-remote-kv", {
|
|
205
|
+
describe:
|
|
206
|
+
"Read/write KV data from/to real namespaces on the Cloudflare network",
|
|
207
|
+
type: "boolean",
|
|
208
|
+
default: false,
|
|
209
|
+
})
|
|
240
210
|
.check((argv) => {
|
|
241
211
|
if (argv.local && argv["experimental-local"]) {
|
|
242
212
|
throw new Error(
|
|
243
213
|
"--local and --experimental-local are mutually exclusive. " +
|
|
244
|
-
"Please
|
|
214
|
+
"Please enable one or the other."
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
if (
|
|
218
|
+
argv["experimental-local-remote-kv"] &&
|
|
219
|
+
!argv["experimental-local"]
|
|
220
|
+
) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
"--experimental-local-remote-kv requires --experimental-local to be enabled."
|
|
245
223
|
);
|
|
246
224
|
}
|
|
247
225
|
return true;
|
|
@@ -251,7 +229,7 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
|
|
|
251
229
|
type: "boolean",
|
|
252
230
|
})
|
|
253
231
|
.option("node-compat", {
|
|
254
|
-
describe: "Enable
|
|
232
|
+
describe: "Enable Node.js compatibility",
|
|
255
233
|
type: "boolean",
|
|
256
234
|
})
|
|
257
235
|
.option("experimental-enable-local-persistence", {
|
|
@@ -273,11 +251,20 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
|
|
|
273
251
|
requiresArg: true,
|
|
274
252
|
})
|
|
275
253
|
.option("live-reload", {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
// describe: "Auto reload HTML pages when change is detected",
|
|
254
|
+
describe:
|
|
255
|
+
"Auto reload HTML pages when change is detected in local mode",
|
|
279
256
|
type: "boolean",
|
|
280
257
|
})
|
|
258
|
+
.check((argv) => {
|
|
259
|
+
const local = argv["local"] || argv["experimental-local"];
|
|
260
|
+
if (argv["live-reload"] && !local) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
"--live-reload is only supported in local mode. " +
|
|
263
|
+
"Please enable either --local or --experimental-local."
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return true;
|
|
267
|
+
})
|
|
281
268
|
.option("inspect", {
|
|
282
269
|
describe: "Enable dev tools",
|
|
283
270
|
type: "boolean",
|
|
@@ -297,12 +284,24 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
|
|
|
297
284
|
.option("log-level", {
|
|
298
285
|
choices: ["debug", "info", "log", "warn", "error", "none"] as const,
|
|
299
286
|
describe: "Specify logging level",
|
|
300
|
-
|
|
287
|
+
// Yargs requires this to type log-level properly
|
|
288
|
+
default: "log" as LoggerLevel,
|
|
301
289
|
})
|
|
302
290
|
);
|
|
303
291
|
}
|
|
304
292
|
|
|
305
|
-
|
|
293
|
+
type DevArguments = StrictYargsOptionsToInterface<typeof devOptions>;
|
|
294
|
+
|
|
295
|
+
export async function devHandler(args: DevArguments) {
|
|
296
|
+
if (!(args.local || args.experimentalLocal)) {
|
|
297
|
+
const isLoggedIn = await loginOrRefreshIfRequired();
|
|
298
|
+
if (!isLoggedIn) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
"You must be logged in to use wrangler dev in remote mode. Try logging in, or run wrangler dev --local."
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
306
305
|
let watcher;
|
|
307
306
|
try {
|
|
308
307
|
const devInstance = await startDev(args);
|
|
@@ -337,12 +336,15 @@ export type AdditionalDevProps = {
|
|
|
337
336
|
d1Databases?: Environment["d1_databases"];
|
|
338
337
|
};
|
|
339
338
|
|
|
340
|
-
type StartDevOptions =
|
|
339
|
+
type StartDevOptions = DevArguments &
|
|
341
340
|
// These options can be passed in directly when called with the `wrangler.dev()` API.
|
|
342
341
|
// They aren't exposed as CLI arguments.
|
|
343
342
|
AdditionalDevProps & {
|
|
344
343
|
forceLocal?: boolean;
|
|
344
|
+
disableDevRegistry?: boolean;
|
|
345
345
|
enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
|
|
346
|
+
onReady?: (ip: string, port: number) => void;
|
|
347
|
+
showInteractiveDevSession?: boolean;
|
|
346
348
|
};
|
|
347
349
|
|
|
348
350
|
export async function startDev(args: StartDevOptions) {
|
|
@@ -354,10 +356,19 @@ export async function startDev(args: StartDevOptions) {
|
|
|
354
356
|
}
|
|
355
357
|
await printWranglerBanner();
|
|
356
358
|
|
|
359
|
+
if (args.local && process.platform !== "win32") {
|
|
360
|
+
logger.info(
|
|
361
|
+
chalk.magenta(
|
|
362
|
+
`Want to try out the next version of local mode using the open-source Workers runtime?\nSwitch out --local for ${chalk.bold(
|
|
363
|
+
"--experimental-local"
|
|
364
|
+
)} and let us know what you think at https://discord.gg/cloudflaredev !`
|
|
365
|
+
)
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
357
369
|
const configPath =
|
|
358
|
-
|
|
359
|
-
(
|
|
360
|
-
findWranglerToml(path.dirname(args.script))) as ConfigPath);
|
|
370
|
+
args.config ||
|
|
371
|
+
(args.script && findWranglerToml(path.dirname(args.script)));
|
|
361
372
|
let config = readConfig(configPath, args);
|
|
362
373
|
|
|
363
374
|
if (config.configPath) {
|
|
@@ -376,7 +387,8 @@ export async function startDev(args: StartDevOptions) {
|
|
|
376
387
|
|
|
377
388
|
const {
|
|
378
389
|
entry,
|
|
379
|
-
|
|
390
|
+
legacyNodeCompat,
|
|
391
|
+
nodejsCompat,
|
|
380
392
|
upstreamProtocol,
|
|
381
393
|
zoneId,
|
|
382
394
|
host,
|
|
@@ -398,7 +410,7 @@ export async function startDev(args: StartDevOptions) {
|
|
|
398
410
|
|
|
399
411
|
// eslint-disable-next-line no-inner-declarations
|
|
400
412
|
async function getDevReactElement(configParam: Config) {
|
|
401
|
-
const { assetPaths, bindings } =
|
|
413
|
+
const { assetPaths, bindings } = getBindingsAndAssetPaths(
|
|
402
414
|
args,
|
|
403
415
|
configParam
|
|
404
416
|
);
|
|
@@ -415,28 +427,31 @@ export async function startDev(args: StartDevOptions) {
|
|
|
415
427
|
rules={getRules(configParam)}
|
|
416
428
|
legacyEnv={isLegacyEnv(configParam)}
|
|
417
429
|
minify={args.minify ?? configParam.minify}
|
|
418
|
-
|
|
430
|
+
legacyNodeCompat={legacyNodeCompat}
|
|
431
|
+
nodejsCompat={nodejsCompat}
|
|
419
432
|
build={configParam.build || {}}
|
|
420
433
|
define={{ ...configParam.define, ...cliDefines }}
|
|
421
434
|
initialMode={
|
|
422
435
|
args.local || args.experimentalLocal ? "local" : "remote"
|
|
423
436
|
}
|
|
424
|
-
jsxFactory={args
|
|
425
|
-
jsxFragment={args
|
|
437
|
+
jsxFactory={args.jsxFactory || configParam.jsx_factory}
|
|
438
|
+
jsxFragment={args.jsxFragment || configParam.jsx_fragment}
|
|
426
439
|
tsconfig={args.tsconfig ?? configParam.tsconfig}
|
|
427
440
|
upstreamProtocol={upstreamProtocol}
|
|
428
441
|
localProtocol={args.localProtocol || configParam.dev.local_protocol}
|
|
429
|
-
localUpstream={args
|
|
442
|
+
localUpstream={args.localUpstream ?? host}
|
|
430
443
|
localPersistencePath={localPersistencePath}
|
|
431
444
|
liveReload={args.liveReload || false}
|
|
432
445
|
accountId={configParam.account_id || getAccountFromCache()?.id}
|
|
433
446
|
assetPaths={assetPaths}
|
|
434
447
|
assetsConfig={configParam.assets}
|
|
435
|
-
|
|
436
|
-
|
|
448
|
+
initialPort={
|
|
449
|
+
args.port ?? configParam.dev.port ?? (await getLocalPort())
|
|
450
|
+
}
|
|
451
|
+
initialIp={args.ip || configParam.dev.ip}
|
|
437
452
|
inspectorPort={
|
|
438
|
-
args.inspectorPort
|
|
439
|
-
configParam.dev.inspector_port
|
|
453
|
+
args.inspectorPort ??
|
|
454
|
+
configParam.dev.inspector_port ??
|
|
440
455
|
(await getInspectorPort())
|
|
441
456
|
}
|
|
442
457
|
isWorkersSite={Boolean(args.site || configParam.site)}
|
|
@@ -451,7 +466,6 @@ export async function startDev(args: StartDevOptions) {
|
|
|
451
466
|
bindings={bindings}
|
|
452
467
|
crons={configParam.triggers.crons}
|
|
453
468
|
queueConsumers={configParam.queues.consumers}
|
|
454
|
-
logPrefix={args.logPrefix}
|
|
455
469
|
onReady={args.onReady}
|
|
456
470
|
inspect={args.inspect ?? true}
|
|
457
471
|
showInteractiveDevSession={args.showInteractiveDevSession}
|
|
@@ -459,17 +473,35 @@ export async function startDev(args: StartDevOptions) {
|
|
|
459
473
|
enablePagesAssetsServiceBinding={args.enablePagesAssetsServiceBinding}
|
|
460
474
|
firstPartyWorker={configParam.first_party_worker}
|
|
461
475
|
sendMetrics={configParam.send_metrics}
|
|
462
|
-
testScheduled={args
|
|
476
|
+
testScheduled={args.testScheduled}
|
|
463
477
|
experimentalLocal={args.experimentalLocal}
|
|
478
|
+
experimentalLocalRemoteKv={args.experimentalLocalRemoteKv}
|
|
464
479
|
/>
|
|
465
480
|
);
|
|
466
481
|
}
|
|
467
482
|
const devReactElement = render(await getDevReactElement(config));
|
|
483
|
+
|
|
484
|
+
// In the bootstrapper script `bin/wrangler.js`, we open an IPC channel, so
|
|
485
|
+
// IPC messages from this process are propagated through the bootstrapper.
|
|
486
|
+
// Normally, Node's SIGINT handler would close this for us, but interactive
|
|
487
|
+
// mode enables raw mode on stdin which disables the built-in handler. The
|
|
488
|
+
// following line disconnects from the IPC channel when we press `x` or
|
|
489
|
+
// CTRL-C in interactive mode, ensuring no open handles, and allowing for a
|
|
490
|
+
// clean exit. Note, if we called `stop()` using the dev API, we don't want
|
|
491
|
+
// to disconnect here, as the user may still need IPC. We also don't want
|
|
492
|
+
// to disconnect if this file was imported in Jest (not the case with E2E
|
|
493
|
+
// tests), as that would stop communication with the test runner.
|
|
494
|
+
let apiStopped = false;
|
|
495
|
+
void devReactElement.waitUntilExit().then(() => {
|
|
496
|
+
if (!apiStopped && typeof jest === "undefined") process.disconnect?.();
|
|
497
|
+
});
|
|
498
|
+
|
|
468
499
|
rerender = devReactElement.rerender;
|
|
469
500
|
return {
|
|
470
501
|
devReactElement,
|
|
471
502
|
watcher,
|
|
472
503
|
stop: async () => {
|
|
504
|
+
apiStopped = true;
|
|
473
505
|
devReactElement.unmount();
|
|
474
506
|
await watcher?.close();
|
|
475
507
|
},
|
|
@@ -486,14 +518,13 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
486
518
|
await printWranglerBanner();
|
|
487
519
|
|
|
488
520
|
const configPath =
|
|
489
|
-
|
|
490
|
-
((args.script &&
|
|
491
|
-
findWranglerToml(path.dirname(args.script))) as ConfigPath);
|
|
521
|
+
args.config || (args.script && findWranglerToml(path.dirname(args.script)));
|
|
492
522
|
const config = readConfig(configPath, args);
|
|
493
523
|
|
|
494
524
|
const {
|
|
495
525
|
entry,
|
|
496
|
-
|
|
526
|
+
legacyNodeCompat,
|
|
527
|
+
nodejsCompat,
|
|
497
528
|
upstreamProtocol,
|
|
498
529
|
zoneId,
|
|
499
530
|
host,
|
|
@@ -512,7 +543,7 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
512
543
|
|
|
513
544
|
// eslint-disable-next-line no-inner-declarations
|
|
514
545
|
async function getDevServer(configParam: Config) {
|
|
515
|
-
const { assetPaths, bindings } =
|
|
546
|
+
const { assetPaths, bindings } = getBindingsAndAssetPaths(
|
|
516
547
|
args,
|
|
517
548
|
configParam
|
|
518
549
|
);
|
|
@@ -532,46 +563,41 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
532
563
|
rules: getRules(configParam),
|
|
533
564
|
legacyEnv: isLegacyEnv(configParam),
|
|
534
565
|
minify: args.minify ?? configParam.minify,
|
|
535
|
-
|
|
566
|
+
legacyNodeCompat,
|
|
567
|
+
nodejsCompat,
|
|
536
568
|
build: configParam.build || {},
|
|
537
569
|
define: { ...config.define, ...cliDefines },
|
|
538
570
|
initialMode: args.local ? "local" : "remote",
|
|
539
|
-
jsxFactory: args
|
|
540
|
-
jsxFragment: args
|
|
571
|
+
jsxFactory: args.jsxFactory ?? configParam.jsx_factory,
|
|
572
|
+
jsxFragment: args.jsxFragment ?? configParam.jsx_fragment,
|
|
541
573
|
tsconfig: args.tsconfig ?? configParam.tsconfig,
|
|
542
574
|
upstreamProtocol: upstreamProtocol,
|
|
543
|
-
localProtocol: args.localProtocol
|
|
544
|
-
localUpstream: args
|
|
575
|
+
localProtocol: args.localProtocol ?? configParam.dev.local_protocol,
|
|
576
|
+
localUpstream: args.localUpstream ?? host,
|
|
545
577
|
localPersistencePath,
|
|
546
|
-
liveReload: args.liveReload
|
|
547
|
-
accountId: configParam.account_id
|
|
578
|
+
liveReload: args.liveReload ?? false,
|
|
579
|
+
accountId: configParam.account_id ?? getAccountFromCache()?.id,
|
|
548
580
|
assetPaths: assetPaths,
|
|
549
581
|
assetsConfig: configParam.assets,
|
|
550
582
|
//port can be 0, which means to use a random port
|
|
551
|
-
port
|
|
552
|
-
|
|
553
|
-
? args.port
|
|
554
|
-
: args.port || configParam.dev.port || (await getLocalPort()),
|
|
555
|
-
ip: args.ip || configParam.dev.ip,
|
|
583
|
+
initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()),
|
|
584
|
+
initialIp: args.ip ?? configParam.dev.ip,
|
|
556
585
|
inspectorPort:
|
|
557
|
-
args
|
|
558
|
-
configParam.dev.inspector_port
|
|
586
|
+
args.inspectorPort ??
|
|
587
|
+
configParam.dev.inspector_port ??
|
|
559
588
|
(await getInspectorPort()),
|
|
560
589
|
isWorkersSite: Boolean(args.site || configParam.site),
|
|
561
590
|
compatibilityDate: getDevCompatibilityDate(
|
|
562
591
|
config,
|
|
563
592
|
// Only `compatibilityDate` will be set when using `unstable_dev`
|
|
564
|
-
args
|
|
593
|
+
args.compatibilityDate
|
|
565
594
|
),
|
|
566
595
|
compatibilityFlags:
|
|
567
|
-
args
|
|
568
|
-
args.compatibilityFlags ??
|
|
569
|
-
configParam.compatibility_flags,
|
|
596
|
+
args.compatibilityFlags ?? configParam.compatibility_flags,
|
|
570
597
|
usageModel: configParam.usage_model,
|
|
571
598
|
bindings: bindings,
|
|
572
599
|
crons: configParam.triggers.crons,
|
|
573
600
|
queueConsumers: configParam.queues.consumers,
|
|
574
|
-
logPrefix: args.logPrefix,
|
|
575
601
|
onReady: args.onReady,
|
|
576
602
|
inspect: args.inspect ?? true,
|
|
577
603
|
showInteractiveDevSession: args.showInteractiveDevSession,
|
|
@@ -582,6 +608,8 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
582
608
|
sendMetrics: configParam.send_metrics,
|
|
583
609
|
testScheduled: args.testScheduled,
|
|
584
610
|
experimentalLocal: args.experimentalLocal,
|
|
611
|
+
experimentalLocalRemoteKv: args.experimentalLocalRemoteKv,
|
|
612
|
+
disableDevRegistry: args.disableDevRegistry ?? false,
|
|
585
613
|
});
|
|
586
614
|
}
|
|
587
615
|
|
|
@@ -687,8 +715,7 @@ async function validateDevServerSettings(
|
|
|
687
715
|
"Passing --inspect is unnecessary, now you can always connect to devtools."
|
|
688
716
|
);
|
|
689
717
|
}
|
|
690
|
-
|
|
691
|
-
if (args["experimental-public"]) {
|
|
718
|
+
if (args.experimentalPublic) {
|
|
692
719
|
throw new Error(
|
|
693
720
|
"The --experimental-public field has been renamed to --assets"
|
|
694
721
|
);
|
|
@@ -698,7 +725,7 @@ async function validateDevServerSettings(
|
|
|
698
725
|
throw new Error("The --public field has been renamed to --assets");
|
|
699
726
|
}
|
|
700
727
|
|
|
701
|
-
if ((args.assets
|
|
728
|
+
if ((args.assets ?? config.assets) && (args.site ?? config.site)) {
|
|
702
729
|
throw new Error("Cannot use Assets and Workers Sites in the same Worker.");
|
|
703
730
|
}
|
|
704
731
|
|
|
@@ -708,18 +735,27 @@ async function validateDevServerSettings(
|
|
|
708
735
|
);
|
|
709
736
|
}
|
|
710
737
|
const upstreamProtocol =
|
|
711
|
-
args
|
|
738
|
+
args.upstreamProtocol ?? config.dev.upstream_protocol;
|
|
712
739
|
if (upstreamProtocol === "http") {
|
|
713
740
|
logger.warn(
|
|
714
741
|
"Setting upstream-protocol to http is not currently implemented.\n" +
|
|
715
742
|
"If this is required in your project, please add your use case to the following issue:\n" +
|
|
716
|
-
"https://github.com/cloudflare/
|
|
743
|
+
"https://github.com/cloudflare/workers-sdk/issues/583."
|
|
717
744
|
);
|
|
718
745
|
}
|
|
719
|
-
const
|
|
720
|
-
if (
|
|
746
|
+
const legacyNodeCompat = args.nodeCompat ?? config.node_compat;
|
|
747
|
+
if (legacyNodeCompat) {
|
|
721
748
|
logger.warn(
|
|
722
|
-
"Enabling
|
|
749
|
+
"Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details."
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
const compatibilityFlags =
|
|
754
|
+
args.compatibilityFlags ?? config.compatibility_flags;
|
|
755
|
+
const nodejsCompat = compatibilityFlags?.includes("nodejs_compat");
|
|
756
|
+
if (legacyNodeCompat && nodejsCompat) {
|
|
757
|
+
throw new Error(
|
|
758
|
+
"The `nodejs_compat` compatibility flag cannot be used in conjunction with the legacy `--node-compat` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the `--node-compat` argument from your CLI command or `node_compat = true` from your config file."
|
|
723
759
|
);
|
|
724
760
|
}
|
|
725
761
|
|
|
@@ -742,7 +778,8 @@ async function validateDevServerSettings(
|
|
|
742
778
|
return {
|
|
743
779
|
entry,
|
|
744
780
|
upstreamProtocol,
|
|
745
|
-
|
|
781
|
+
legacyNodeCompat,
|
|
782
|
+
nodejsCompat,
|
|
746
783
|
getLocalPort,
|
|
747
784
|
getInspectorPort,
|
|
748
785
|
zoneId,
|
|
@@ -753,14 +790,11 @@ async function validateDevServerSettings(
|
|
|
753
790
|
};
|
|
754
791
|
}
|
|
755
792
|
|
|
756
|
-
|
|
757
|
-
args: StartDevOptions,
|
|
758
|
-
configParam: Config
|
|
759
|
-
) {
|
|
793
|
+
function getBindingsAndAssetPaths(args: StartDevOptions, configParam: Config) {
|
|
760
794
|
const cliVars = collectKeyValues(args.var);
|
|
761
795
|
|
|
762
796
|
// now log all available bindings into the terminal
|
|
763
|
-
const bindings =
|
|
797
|
+
const bindings = getBindings(configParam, args.env, args.local ?? false, {
|
|
764
798
|
kv: args.kv,
|
|
765
799
|
vars: { ...args.vars, ...cliVars },
|
|
766
800
|
durableObjects: args.durableObjects,
|
|
@@ -787,11 +821,12 @@ async function getBindingsAndAssetPaths(
|
|
|
787
821
|
return { assetPaths, bindings };
|
|
788
822
|
}
|
|
789
823
|
|
|
790
|
-
|
|
824
|
+
function getBindings(
|
|
791
825
|
configParam: Config,
|
|
792
826
|
env: string | undefined,
|
|
827
|
+
local: boolean,
|
|
793
828
|
args: AdditionalDevProps
|
|
794
|
-
):
|
|
829
|
+
): CfWorkerInit["bindings"] {
|
|
795
830
|
const bindings = {
|
|
796
831
|
kv_namespaces: [
|
|
797
832
|
...(configParam.kv_namespaces || []).map(
|
|
@@ -817,12 +852,12 @@ async function getBindings(
|
|
|
817
852
|
),
|
|
818
853
|
...(args.kv || []),
|
|
819
854
|
],
|
|
855
|
+
send_email: configParam.send_email,
|
|
820
856
|
// Use a copy of combinedVars since we're modifying it later
|
|
821
857
|
vars: {
|
|
822
858
|
...getVarsForDev(configParam, env),
|
|
823
859
|
...args.vars,
|
|
824
860
|
},
|
|
825
|
-
metadata_binding: configParam.metadata_binding,
|
|
826
861
|
wasm_modules: configParam.wasm_modules,
|
|
827
862
|
text_blobs: configParam.text_blobs,
|
|
828
863
|
data_blobs: configParam.data_blobs,
|
|
@@ -856,11 +891,36 @@ async function getBindings(
|
|
|
856
891
|
...(args.r2 || []),
|
|
857
892
|
],
|
|
858
893
|
dispatch_namespaces: configParam.dispatch_namespaces,
|
|
894
|
+
mtls_certificates: configParam.mtls_certificates,
|
|
859
895
|
services: configParam.services,
|
|
860
|
-
|
|
896
|
+
analytics_engine_datasets: configParam.analytics_engine_datasets,
|
|
897
|
+
unsafe: {
|
|
898
|
+
bindings: configParam.unsafe.bindings,
|
|
899
|
+
metadata: configParam.unsafe.metadata,
|
|
900
|
+
},
|
|
861
901
|
logfwdr: configParam.logfwdr,
|
|
862
902
|
d1_databases: identifyD1BindingsAsBeta([
|
|
863
|
-
...configParam.d1_databases
|
|
903
|
+
...(configParam.d1_databases ?? []).map((d1Db) => {
|
|
904
|
+
//in local dev, bindings don't matter
|
|
905
|
+
if (local) {
|
|
906
|
+
return {
|
|
907
|
+
...d1Db,
|
|
908
|
+
database_id: "local",
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
// if you have a preview_database_id, we'll use it, but we shouldn't force people to use it.
|
|
912
|
+
if (!d1Db.preview_database_id && !process.env.NO_D1_WARNING) {
|
|
913
|
+
logger.log(
|
|
914
|
+
`--------------------\nš” Recommendation: for development, use a preview D1 database rather than the one you'd use in production.\nš” Create a new D1 database with "wrangler d1 create <name>" and add its id as preview_database_id to the d1_database "${d1Db.binding}" in your wrangler.toml\n--------------------\n`
|
|
915
|
+
);
|
|
916
|
+
}
|
|
917
|
+
return {
|
|
918
|
+
...d1Db,
|
|
919
|
+
database_id: d1Db.preview_database_id
|
|
920
|
+
? d1Db.preview_database_id
|
|
921
|
+
: d1Db.database_id,
|
|
922
|
+
};
|
|
923
|
+
}),
|
|
864
924
|
...(args.d1Databases || []),
|
|
865
925
|
]),
|
|
866
926
|
};
|