wrangler 0.0.0-e6c9c5c0 → 0.0.0-e6e1daba
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/miniflare-dist/index.mjs +22 -18
- package/package.json +12 -12
- package/src/__tests__/configuration.test.ts +70 -0
- package/src/__tests__/d1/d1.test.ts +13 -58
- package/src/__tests__/d1/execute.test.ts +64 -0
- package/src/__tests__/d1/migrate.test.ts +155 -0
- package/src/__tests__/deployments.test.ts +40 -16
- package/src/__tests__/dev.test.tsx +8 -7
- package/src/__tests__/generate.test.ts +1 -1
- 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-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +40 -16
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
- package/src/__tests__/index.test.ts +38 -32
- package/src/__tests__/init.test.ts +1 -1
- package/src/__tests__/kv.test.ts +63 -52
- package/src/__tests__/middleware.test.ts +65 -0
- package/src/__tests__/mtls-certificates.test.ts +585 -0
- package/src/__tests__/pages/deployment-list.test.ts +78 -0
- package/src/__tests__/pages/functions-build.test.ts +402 -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 +108 -0
- package/src/__tests__/pages/project-upload.test.ts +481 -0
- package/src/__tests__/pages/publish.test.ts +2745 -0
- package/src/__tests__/parse.test.ts +106 -0
- package/src/__tests__/publish.test.ts +80 -30
- package/src/__tests__/pubsub.test.ts +15 -12
- package/src/__tests__/queues.test.ts +37 -30
- package/src/__tests__/r2.test.ts +25 -20
- package/src/__tests__/secret.test.ts +4 -4
- package/src/__tests__/tsconfig.tsbuildinfo +1 -1
- package/src/__tests__/user.test.ts +1 -1
- package/src/__tests__/whoami.test.tsx +1 -1
- package/src/__tests__/worker-namespace.test.ts +26 -21
- package/src/api/dev.ts +80 -11
- package/src/api/index.ts +8 -0
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +75 -0
- package/src/api/pages/publish.tsx +59 -12
- package/src/bundle.ts +9 -7
- package/src/config/config.ts +14 -7
- package/src/config/environment.ts +9 -2
- package/src/config/index.ts +37 -20
- package/src/config/validation.ts +50 -3
- package/src/create-worker-preview.ts +19 -8
- package/src/create-worker-upload-form.ts +9 -0
- package/src/d1/backups.tsx +20 -24
- package/src/d1/create.tsx +6 -5
- package/src/d1/delete.ts +7 -10
- package/src/d1/execute.tsx +174 -143
- package/src/d1/index.ts +5 -6
- package/src/d1/list.tsx +21 -9
- package/src/d1/migrations/apply.tsx +42 -33
- package/src/d1/migrations/create.tsx +16 -17
- package/src/d1/migrations/helpers.ts +63 -38
- package/src/d1/migrations/list.tsx +37 -24
- package/src/d1/migrations/options.ts +7 -2
- package/src/d1/options.ts +3 -3
- package/src/d1/types.ts +1 -0
- package/src/d1/utils.ts +2 -1
- package/src/delete.ts +5 -8
- package/src/deployments.ts +62 -39
- package/src/deprecated/index.ts +7 -8
- package/src/dev/dev.tsx +1 -15
- package/src/dev/local.tsx +5 -6
- package/src/dev/remote.tsx +2 -2
- package/src/dev.tsx +51 -86
- package/src/dispatch-namespace.ts +20 -16
- package/src/docs/index.ts +7 -8
- package/src/entry.ts +1 -2
- package/src/generate/index.ts +6 -8
- package/src/index.ts +37 -26
- package/src/init.ts +5 -7
- package/src/inspect.ts +16 -1
- package/src/kv/index.ts +15 -17
- package/src/miniflare-cli/assets.ts +9 -8
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/pages/build.ts +109 -27
- package/src/pages/buildFunctions.ts +32 -31
- package/src/pages/deployment-tails.ts +7 -10
- package/src/pages/deployments.tsx +6 -4
- package/src/pages/dev.ts +19 -19
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
- package/src/pages/functions.ts +8 -4
- package/src/pages/index.ts +3 -3
- package/src/pages/projects.tsx +7 -12
- package/src/pages/publish.tsx +18 -5
- package/src/pages/types.ts +5 -0
- package/src/pages/upload.tsx +6 -4
- package/src/pages/utils.ts +1 -1
- package/src/parse.ts +23 -1
- package/src/publish/index.ts +19 -15
- package/src/publish/publish.ts +5 -4
- package/src/pubsub/pubsub-commands.ts +18 -19
- package/src/queues/cli/commands/consumer/add.ts +18 -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 +3 -4
- package/src/queues/cli/commands/list.ts +8 -8
- package/src/r2/helpers.ts +1 -0
- package/src/r2/index.ts +28 -28
- package/src/secret/index.ts +10 -14
- package/src/sites.ts +1 -1
- package/src/tail/filters.ts +1 -1
- package/src/tail/index.ts +6 -8
- package/src/user/user.ts +4 -3
- package/src/worker.ts +6 -0
- package/src/yargs-types.ts +18 -5
- package/templates/checked-fetch.js +9 -1
- package/templates/format-dev-errors.ts +1 -0
- package/templates/new-worker.ts +3 -0
- package/templates/pages-template-plugin.ts +7 -3
- package/templates/serve-static-assets.ts +1 -0
- package/templates/service-bindings-module-facade.js +1 -0
- package/templates/tsconfig.init.json +1 -1
- package/templates/tsconfig.tsbuildinfo +1 -1
- package/wrangler-dist/cli.d.ts +596 -3
- package/wrangler-dist/cli.js +14276 -6748
- package/src/__tests__/pages.test.ts +0 -2898
package/src/dev.tsx
CHANGED
|
@@ -19,7 +19,6 @@ import { collectKeyValues } from "./utils/collectKeyValues";
|
|
|
19
19
|
import { identifyD1BindingsAsBeta } from "./worker";
|
|
20
20
|
import { getHostFromRoute, getZoneForRoute, getZoneIdFromHost } from "./zones";
|
|
21
21
|
import {
|
|
22
|
-
type ConfigPath,
|
|
23
22
|
DEFAULT_INSPECTOR_PORT,
|
|
24
23
|
DEFAULT_LOCAL_PORT,
|
|
25
24
|
getDevCompatibilityDate,
|
|
@@ -30,59 +29,15 @@ import {
|
|
|
30
29
|
} from "./index";
|
|
31
30
|
import type { Config, Environment } from "./config";
|
|
32
31
|
import type { Route } from "./config/environment";
|
|
32
|
+
import type { LoggerLevel } from "./logger";
|
|
33
33
|
import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types";
|
|
34
34
|
import type { CfWorkerInit } from "./worker";
|
|
35
|
-
import type {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
config?: string;
|
|
40
|
-
script?: string;
|
|
41
|
-
name?: string;
|
|
42
|
-
bundle?: boolean;
|
|
43
|
-
build?: boolean;
|
|
44
|
-
format?: string;
|
|
45
|
-
env?: string;
|
|
46
|
-
"compatibility-date"?: string;
|
|
47
|
-
"compatibility-flags"?: string[];
|
|
48
|
-
latest?: boolean;
|
|
49
|
-
ip?: string;
|
|
50
|
-
inspect?: boolean;
|
|
51
|
-
port?: number;
|
|
52
|
-
"inspector-port"?: number;
|
|
53
|
-
routes?: string[];
|
|
54
|
-
host?: string;
|
|
55
|
-
"local-protocol"?: "http" | "https";
|
|
56
|
-
"local-upstream"?: string | undefined;
|
|
57
|
-
"experimental-public"?: string;
|
|
58
|
-
public?: string;
|
|
59
|
-
assets?: string;
|
|
60
|
-
site?: string;
|
|
61
|
-
"site-include"?: string[];
|
|
62
|
-
"site-exclude"?: string[];
|
|
63
|
-
"upstream-protocol"?: "http" | "https";
|
|
64
|
-
"jsx-factory"?: string;
|
|
65
|
-
"jsx-fragment"?: string;
|
|
66
|
-
tsconfig?: string;
|
|
67
|
-
local?: boolean;
|
|
68
|
-
"experimental-local"?: boolean;
|
|
69
|
-
"experimental-local-remote-kv"?: boolean;
|
|
70
|
-
minify?: boolean;
|
|
71
|
-
var?: string[];
|
|
72
|
-
define?: string[];
|
|
73
|
-
"node-compat"?: boolean;
|
|
74
|
-
"experimental-enable-local-persistence"?: boolean;
|
|
75
|
-
persist?: boolean;
|
|
76
|
-
"persist-to"?: string;
|
|
77
|
-
"live-reload"?: boolean;
|
|
78
|
-
onReady?: (ip: string, port: number) => void;
|
|
79
|
-
logLevel?: "none" | "info" | "error" | "log" | "warn" | "debug";
|
|
80
|
-
logPrefix?: string;
|
|
81
|
-
showInteractiveDevSession?: boolean;
|
|
82
|
-
"test-scheduled"?: boolean;
|
|
83
|
-
}
|
|
35
|
+
import type {
|
|
36
|
+
CommonYargsArgv,
|
|
37
|
+
StrictYargsOptionsToInterface,
|
|
38
|
+
} from "./yargs-types";
|
|
84
39
|
|
|
85
|
-
export function devOptions(yargs:
|
|
40
|
+
export function devOptions(yargs: CommonYargsArgv) {
|
|
86
41
|
return (
|
|
87
42
|
yargs
|
|
88
43
|
.positional("script", {
|
|
@@ -177,6 +132,13 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
|
|
|
177
132
|
type: "string",
|
|
178
133
|
requiresArg: true,
|
|
179
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
|
+
})
|
|
180
142
|
.option("site", {
|
|
181
143
|
describe: "Root folder of static assets for Workers Sites",
|
|
182
144
|
type: "string",
|
|
@@ -322,12 +284,15 @@ export function devOptions(yargs: Argv<CommonYargsOptions>): Argv<DevArgs> {
|
|
|
322
284
|
.option("log-level", {
|
|
323
285
|
choices: ["debug", "info", "log", "warn", "error", "none"] as const,
|
|
324
286
|
describe: "Specify logging level",
|
|
325
|
-
|
|
287
|
+
// Yargs requires this to type log-level properly
|
|
288
|
+
default: "log" as LoggerLevel,
|
|
326
289
|
})
|
|
327
290
|
);
|
|
328
291
|
}
|
|
329
292
|
|
|
330
|
-
|
|
293
|
+
type DevArguments = StrictYargsOptionsToInterface<typeof devOptions>;
|
|
294
|
+
|
|
295
|
+
export async function devHandler(args: DevArguments) {
|
|
331
296
|
if (!(args.local || args.experimentalLocal)) {
|
|
332
297
|
const isLoggedIn = await loginOrRefreshIfRequired();
|
|
333
298
|
if (!isLoggedIn) {
|
|
@@ -371,13 +336,16 @@ export type AdditionalDevProps = {
|
|
|
371
336
|
d1Databases?: Environment["d1_databases"];
|
|
372
337
|
};
|
|
373
338
|
|
|
374
|
-
type StartDevOptions =
|
|
339
|
+
type StartDevOptions = DevArguments &
|
|
375
340
|
// These options can be passed in directly when called with the `wrangler.dev()` API.
|
|
376
341
|
// They aren't exposed as CLI arguments.
|
|
377
342
|
AdditionalDevProps & {
|
|
378
343
|
forceLocal?: boolean;
|
|
379
344
|
disableDevRegistry?: boolean;
|
|
380
345
|
enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
|
|
346
|
+
onReady?: (ip: string, port: number) => void;
|
|
347
|
+
logPrefix?: string;
|
|
348
|
+
showInteractiveDevSession?: boolean;
|
|
381
349
|
};
|
|
382
350
|
|
|
383
351
|
export async function startDev(args: StartDevOptions) {
|
|
@@ -400,9 +368,8 @@ export async function startDev(args: StartDevOptions) {
|
|
|
400
368
|
}
|
|
401
369
|
|
|
402
370
|
const configPath =
|
|
403
|
-
|
|
404
|
-
(
|
|
405
|
-
findWranglerToml(path.dirname(args.script))) as ConfigPath);
|
|
371
|
+
args.config ||
|
|
372
|
+
(args.script && findWranglerToml(path.dirname(args.script)));
|
|
406
373
|
let config = readConfig(configPath, args);
|
|
407
374
|
|
|
408
375
|
if (config.configPath) {
|
|
@@ -466,12 +433,12 @@ export async function startDev(args: StartDevOptions) {
|
|
|
466
433
|
initialMode={
|
|
467
434
|
args.local || args.experimentalLocal ? "local" : "remote"
|
|
468
435
|
}
|
|
469
|
-
jsxFactory={args
|
|
470
|
-
jsxFragment={args
|
|
436
|
+
jsxFactory={args.jsxFactory || configParam.jsx_factory}
|
|
437
|
+
jsxFragment={args.jsxFragment || configParam.jsx_fragment}
|
|
471
438
|
tsconfig={args.tsconfig ?? configParam.tsconfig}
|
|
472
439
|
upstreamProtocol={upstreamProtocol}
|
|
473
440
|
localProtocol={args.localProtocol || configParam.dev.local_protocol}
|
|
474
|
-
localUpstream={args
|
|
441
|
+
localUpstream={args.localUpstream ?? host}
|
|
475
442
|
localPersistencePath={localPersistencePath}
|
|
476
443
|
liveReload={args.liveReload || false}
|
|
477
444
|
accountId={configParam.account_id || getAccountFromCache()?.id}
|
|
@@ -506,7 +473,7 @@ export async function startDev(args: StartDevOptions) {
|
|
|
506
473
|
enablePagesAssetsServiceBinding={args.enablePagesAssetsServiceBinding}
|
|
507
474
|
firstPartyWorker={configParam.first_party_worker}
|
|
508
475
|
sendMetrics={configParam.send_metrics}
|
|
509
|
-
testScheduled={args
|
|
476
|
+
testScheduled={args.testScheduled}
|
|
510
477
|
experimentalLocal={args.experimentalLocal}
|
|
511
478
|
experimentalLocalRemoteKv={args.experimentalLocalRemoteKv}
|
|
512
479
|
/>
|
|
@@ -551,9 +518,7 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
551
518
|
await printWranglerBanner();
|
|
552
519
|
|
|
553
520
|
const configPath =
|
|
554
|
-
|
|
555
|
-
((args.script &&
|
|
556
|
-
findWranglerToml(path.dirname(args.script))) as ConfigPath);
|
|
521
|
+
args.config || (args.script && findWranglerToml(path.dirname(args.script)));
|
|
557
522
|
const config = readConfig(configPath, args);
|
|
558
523
|
|
|
559
524
|
const {
|
|
@@ -601,34 +566,32 @@ export async function startApiDev(args: StartDevOptions) {
|
|
|
601
566
|
build: configParam.build || {},
|
|
602
567
|
define: { ...config.define, ...cliDefines },
|
|
603
568
|
initialMode: args.local ? "local" : "remote",
|
|
604
|
-
jsxFactory: args
|
|
605
|
-
jsxFragment: args
|
|
569
|
+
jsxFactory: args.jsxFactory ?? configParam.jsx_factory,
|
|
570
|
+
jsxFragment: args.jsxFragment ?? configParam.jsx_fragment,
|
|
606
571
|
tsconfig: args.tsconfig ?? configParam.tsconfig,
|
|
607
572
|
upstreamProtocol: upstreamProtocol,
|
|
608
|
-
localProtocol: args.localProtocol
|
|
609
|
-
localUpstream: args
|
|
573
|
+
localProtocol: args.localProtocol ?? configParam.dev.local_protocol,
|
|
574
|
+
localUpstream: args.localUpstream ?? host,
|
|
610
575
|
localPersistencePath,
|
|
611
|
-
liveReload: args.liveReload
|
|
612
|
-
accountId: configParam.account_id
|
|
576
|
+
liveReload: args.liveReload ?? false,
|
|
577
|
+
accountId: configParam.account_id ?? getAccountFromCache()?.id,
|
|
613
578
|
assetPaths: assetPaths,
|
|
614
579
|
assetsConfig: configParam.assets,
|
|
615
580
|
//port can be 0, which means to use a random port
|
|
616
581
|
initialPort: args.port ?? configParam.dev.port ?? (await getLocalPort()),
|
|
617
|
-
initialIp: args.ip
|
|
582
|
+
initialIp: args.ip ?? configParam.dev.ip,
|
|
618
583
|
inspectorPort:
|
|
619
|
-
args
|
|
584
|
+
args.inspectorPort ??
|
|
620
585
|
configParam.dev.inspector_port ??
|
|
621
586
|
(await getInspectorPort()),
|
|
622
587
|
isWorkersSite: Boolean(args.site || configParam.site),
|
|
623
588
|
compatibilityDate: getDevCompatibilityDate(
|
|
624
589
|
config,
|
|
625
590
|
// Only `compatibilityDate` will be set when using `unstable_dev`
|
|
626
|
-
args
|
|
591
|
+
args.compatibilityDate
|
|
627
592
|
),
|
|
628
593
|
compatibilityFlags:
|
|
629
|
-
args
|
|
630
|
-
args.compatibilityFlags ??
|
|
631
|
-
configParam.compatibility_flags,
|
|
594
|
+
args.compatibilityFlags ?? configParam.compatibility_flags,
|
|
632
595
|
usageModel: configParam.usage_model,
|
|
633
596
|
bindings: bindings,
|
|
634
597
|
crons: configParam.triggers.crons,
|
|
@@ -751,8 +714,7 @@ async function validateDevServerSettings(
|
|
|
751
714
|
"Passing --inspect is unnecessary, now you can always connect to devtools."
|
|
752
715
|
);
|
|
753
716
|
}
|
|
754
|
-
|
|
755
|
-
if (args["experimental-public"]) {
|
|
717
|
+
if (args.experimentalPublic) {
|
|
756
718
|
throw new Error(
|
|
757
719
|
"The --experimental-public field has been renamed to --assets"
|
|
758
720
|
);
|
|
@@ -762,7 +724,7 @@ async function validateDevServerSettings(
|
|
|
762
724
|
throw new Error("The --public field has been renamed to --assets");
|
|
763
725
|
}
|
|
764
726
|
|
|
765
|
-
if ((args.assets
|
|
727
|
+
if ((args.assets ?? config.assets) && (args.site ?? config.site)) {
|
|
766
728
|
throw new Error("Cannot use Assets and Workers Sites in the same Worker.");
|
|
767
729
|
}
|
|
768
730
|
|
|
@@ -772,12 +734,12 @@ async function validateDevServerSettings(
|
|
|
772
734
|
);
|
|
773
735
|
}
|
|
774
736
|
const upstreamProtocol =
|
|
775
|
-
args
|
|
737
|
+
args.upstreamProtocol ?? config.dev.upstream_protocol;
|
|
776
738
|
if (upstreamProtocol === "http") {
|
|
777
739
|
logger.warn(
|
|
778
740
|
"Setting upstream-protocol to http is not currently implemented.\n" +
|
|
779
741
|
"If this is required in your project, please add your use case to the following issue:\n" +
|
|
780
|
-
"https://github.com/cloudflare/
|
|
742
|
+
"https://github.com/cloudflare/workers-sdk/issues/583."
|
|
781
743
|
);
|
|
782
744
|
}
|
|
783
745
|
const nodeCompat = args.nodeCompat ?? config.node_compat;
|
|
@@ -917,6 +879,7 @@ function getBindings(
|
|
|
917
879
|
...(args.r2 || []),
|
|
918
880
|
],
|
|
919
881
|
dispatch_namespaces: configParam.dispatch_namespaces,
|
|
882
|
+
mtls_certificates: configParam.mtls_certificates,
|
|
920
883
|
services: configParam.services,
|
|
921
884
|
analytics_engine_datasets: configParam.analytics_engine_datasets,
|
|
922
885
|
unsafe: configParam.unsafe?.bindings,
|
|
@@ -930,15 +893,17 @@ function getBindings(
|
|
|
930
893
|
database_id: "local",
|
|
931
894
|
};
|
|
932
895
|
}
|
|
933
|
-
if
|
|
934
|
-
|
|
935
|
-
|
|
896
|
+
// if you have a preview_database_id, we'll use it, but we shouldn't force people to use it.
|
|
897
|
+
if (!d1Db.preview_database_id && !process.env.NO_D1_WARNING) {
|
|
898
|
+
logger.log(
|
|
899
|
+
`--------------------\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`
|
|
936
900
|
);
|
|
937
901
|
}
|
|
938
|
-
|
|
939
902
|
return {
|
|
940
903
|
...d1Db,
|
|
941
|
-
database_id: d1Db.preview_database_id
|
|
904
|
+
database_id: d1Db.preview_database_id
|
|
905
|
+
? d1Db.preview_database_id
|
|
906
|
+
: d1Db.database_id,
|
|
942
907
|
};
|
|
943
908
|
}),
|
|
944
909
|
...(args.d1Databases || []),
|
|
@@ -4,9 +4,8 @@ import { logger } from "./logger";
|
|
|
4
4
|
import * as metrics from "./metrics";
|
|
5
5
|
import { requireAuth } from "./user";
|
|
6
6
|
import { printWranglerBanner } from ".";
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { Argv, CommandModule } from "yargs";
|
|
7
|
+
import type { CommonYargsArgv, CommonYargsOptions } from "./yargs-types";
|
|
8
|
+
import type { CommandModule } from "yargs";
|
|
10
9
|
|
|
11
10
|
type Namespace = {
|
|
12
11
|
namespace_id: string;
|
|
@@ -106,19 +105,24 @@ async function renameWorkerNamespace(
|
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
export function workerNamespaceCommands(
|
|
109
|
-
workerNamespaceYargs:
|
|
108
|
+
workerNamespaceYargs: CommonYargsArgv,
|
|
110
109
|
subHelp: CommandModule<CommonYargsOptions, CommonYargsOptions>
|
|
111
110
|
) {
|
|
112
111
|
return workerNamespaceYargs
|
|
113
112
|
.command(subHelp)
|
|
114
|
-
.command(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
.command(
|
|
114
|
+
"list",
|
|
115
|
+
"List all dispatch namespaces",
|
|
116
|
+
(args) => args,
|
|
117
|
+
async (args) => {
|
|
118
|
+
const config = readConfig(args.config, args);
|
|
119
|
+
const accountId = await requireAuth(config);
|
|
120
|
+
await listWorkerNamespaces(accountId);
|
|
121
|
+
await metrics.sendMetricsEvent("list dispatch namespaces", {
|
|
122
|
+
sendMetrics: config.send_metrics,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
)
|
|
122
126
|
.command(
|
|
123
127
|
"get <name>",
|
|
124
128
|
"Get information about a dispatch namespace",
|
|
@@ -130,7 +134,7 @@ export function workerNamespaceCommands(
|
|
|
130
134
|
});
|
|
131
135
|
},
|
|
132
136
|
async (args) => {
|
|
133
|
-
const config = readConfig(args.config
|
|
137
|
+
const config = readConfig(args.config, args);
|
|
134
138
|
const accountId = await requireAuth(config);
|
|
135
139
|
await getWorkerNamespaceInfo(accountId, args.name);
|
|
136
140
|
await metrics.sendMetricsEvent("view dispatch namespace", {
|
|
@@ -150,7 +154,7 @@ export function workerNamespaceCommands(
|
|
|
150
154
|
},
|
|
151
155
|
async (args) => {
|
|
152
156
|
await printWranglerBanner();
|
|
153
|
-
const config = readConfig(args.config
|
|
157
|
+
const config = readConfig(args.config, args);
|
|
154
158
|
const accountId = await requireAuth(config);
|
|
155
159
|
await createWorkerNamespace(accountId, args.name);
|
|
156
160
|
await metrics.sendMetricsEvent("create dispatch namespace", {
|
|
@@ -170,7 +174,7 @@ export function workerNamespaceCommands(
|
|
|
170
174
|
},
|
|
171
175
|
async (args) => {
|
|
172
176
|
await printWranglerBanner();
|
|
173
|
-
const config = readConfig(args.config
|
|
177
|
+
const config = readConfig(args.config, args);
|
|
174
178
|
const accountId = await requireAuth(config);
|
|
175
179
|
await deleteWorkerNamespace(accountId, args.name);
|
|
176
180
|
await metrics.sendMetricsEvent("delete dispatch namespace", {
|
|
@@ -196,7 +200,7 @@ export function workerNamespaceCommands(
|
|
|
196
200
|
},
|
|
197
201
|
async (args) => {
|
|
198
202
|
await printWranglerBanner();
|
|
199
|
-
const config = readConfig(args.config
|
|
203
|
+
const config = readConfig(args.config, args);
|
|
200
204
|
const accountId = await requireAuth(config);
|
|
201
205
|
await renameWorkerNamespace(accountId, args.oldName, args.newName);
|
|
202
206
|
await metrics.sendMetricsEvent("rename dispatch namespace", {
|
package/src/docs/index.ts
CHANGED
|
@@ -5,10 +5,9 @@ import * as metrics from "../metrics";
|
|
|
5
5
|
import openInBrowser from "../open-in-browser";
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
CommonYargsArgv,
|
|
9
|
+
StrictYargsOptionsToInterface,
|
|
10
10
|
} from "../yargs-types";
|
|
11
|
-
import type { ArgumentsCamelCase, Argv } from "yargs";
|
|
12
11
|
|
|
13
12
|
const argToUrlHash = {
|
|
14
13
|
d1: "d1",
|
|
@@ -34,7 +33,7 @@ const argToUrlHash = {
|
|
|
34
33
|
deployments: "deployments",
|
|
35
34
|
};
|
|
36
35
|
|
|
37
|
-
export function docsOptions(yargs:
|
|
36
|
+
export function docsOptions(yargs: CommonYargsArgv) {
|
|
38
37
|
return yargs.positional("command", {
|
|
39
38
|
describe: "Enter the wrangler command you want to know more about",
|
|
40
39
|
type: "string",
|
|
@@ -69,13 +68,13 @@ export function docsOptions(yargs: Argv<CommonYargsOptions>) {
|
|
|
69
68
|
});
|
|
70
69
|
}
|
|
71
70
|
|
|
72
|
-
type DocsArgs = YargsOptionsToInterface<typeof docsOptions>;
|
|
73
|
-
|
|
74
71
|
function isValidParam(k: string): k is keyof typeof argToUrlHash {
|
|
75
72
|
return k in argToUrlHash;
|
|
76
73
|
}
|
|
77
74
|
|
|
78
|
-
export async function docsHandler(
|
|
75
|
+
export async function docsHandler(
|
|
76
|
+
args: StrictYargsOptionsToInterface<typeof docsOptions>
|
|
77
|
+
) {
|
|
79
78
|
let urlToOpen =
|
|
80
79
|
"https://developers.cloudflare.com/workers/wrangler/commands/";
|
|
81
80
|
|
|
@@ -91,7 +90,7 @@ export async function docsHandler(args: ArgumentsCamelCase<DocsArgs>) {
|
|
|
91
90
|
|
|
92
91
|
logger.log(`Opening a link in your default browser: ${urlToOpen}`);
|
|
93
92
|
await openInBrowser(urlToOpen);
|
|
94
|
-
const config = readConfig(undefined,
|
|
93
|
+
const config = readConfig(undefined, args);
|
|
95
94
|
await metrics.sendMetricsEvent("view docs", {
|
|
96
95
|
sendMetrics: config.send_metrics,
|
|
97
96
|
});
|
package/src/entry.ts
CHANGED
package/src/generate/index.ts
CHANGED
|
@@ -5,12 +5,11 @@ import { CommandLineArgsError, printWranglerBanner } from "../index";
|
|
|
5
5
|
import { initHandler } from "../init";
|
|
6
6
|
import { logger } from "../logger";
|
|
7
7
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
CommonYargsArgv,
|
|
9
|
+
StrictYargsOptionsToInterface,
|
|
10
10
|
} from "../yargs-types";
|
|
11
|
-
import type { Argv } from "yargs";
|
|
12
11
|
|
|
13
|
-
export function generateOptions(yargs:
|
|
12
|
+
export function generateOptions(yargs: CommonYargsArgv) {
|
|
14
13
|
return yargs
|
|
15
14
|
.positional("name", {
|
|
16
15
|
describe: "Name of the Workers project",
|
|
@@ -34,9 +33,9 @@ export function generateOptions(yargs: Argv<CommonYargsOptions>) {
|
|
|
34
33
|
deprecated: true,
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
type GenerateArgs =
|
|
36
|
+
type GenerateArgs = StrictYargsOptionsToInterface<typeof generateOptions>;
|
|
38
37
|
|
|
39
|
-
// Originally, generate was a rust function: https://github.com/cloudflare/wrangler/blob/master/src/cli/mod.rs#L106-L123
|
|
38
|
+
// Originally, generate was a rust function: https://github.com/cloudflare/wrangler-legacy/blob/master/src/cli/mod.rs#L106-L123
|
|
40
39
|
export async function generateHandler(args: GenerateArgs) {
|
|
41
40
|
// somehow, `init` marks name as required but then also runs fine
|
|
42
41
|
// with the name omitted, and then substitutes it at runtime with ""
|
|
@@ -44,17 +43,16 @@ export async function generateHandler(args: GenerateArgs) {
|
|
|
44
43
|
if (args.template === undefined) {
|
|
45
44
|
return initHandler({
|
|
46
45
|
name: args.name,
|
|
47
|
-
template: undefined,
|
|
48
46
|
site: undefined,
|
|
49
47
|
yes: undefined,
|
|
50
48
|
fromDash: undefined,
|
|
51
|
-
"from-dash": undefined,
|
|
52
49
|
v: undefined,
|
|
53
50
|
config: undefined,
|
|
54
51
|
env: undefined,
|
|
55
52
|
type: undefined,
|
|
56
53
|
_: args._,
|
|
57
54
|
$0: args.$0,
|
|
55
|
+
experimentalJsonConfig: false,
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
58
|
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ import { initHandler, initOptions } from "./init";
|
|
|
30
30
|
import { kvNamespace, kvKey, kvBulk } from "./kv";
|
|
31
31
|
import { logBuildFailure, logger } from "./logger";
|
|
32
32
|
import * as metrics from "./metrics";
|
|
33
|
+
import { mTlsCertificateCommands } from "./mtls-certificate/cli";
|
|
33
34
|
import { pages } from "./pages";
|
|
34
35
|
import { formatMessage, ParseError } from "./parse";
|
|
35
36
|
import { publishOptions, publishHandler } from "./publish";
|
|
@@ -50,12 +51,9 @@ import {
|
|
|
50
51
|
import { whoami } from "./whoami";
|
|
51
52
|
|
|
52
53
|
import type { Config } from "./config";
|
|
53
|
-
import type { CommonYargsOptions } from "./yargs-types";
|
|
54
|
-
import type { ArgumentsCamelCase } from "yargs";
|
|
54
|
+
import type { CommonYargsArgv, CommonYargsOptions } from "./yargs-types";
|
|
55
55
|
import type Yargs from "yargs";
|
|
56
56
|
|
|
57
|
-
export type ConfigPath = string | undefined;
|
|
58
|
-
|
|
59
57
|
const resetColor = "\x1b[0m";
|
|
60
58
|
const fgGreenColor = "\x1b[32m";
|
|
61
59
|
export const DEFAULT_LOCAL_PORT = 8787;
|
|
@@ -113,7 +111,7 @@ export async function printWranglerBanner() {
|
|
|
113
111
|
|
|
114
112
|
export function isLegacyEnv(config: Config): boolean {
|
|
115
113
|
// We only read from config here, because we've already accounted for
|
|
116
|
-
// args["legacy-env"] in https://github.com/cloudflare/
|
|
114
|
+
// args["legacy-env"] in https://github.com/cloudflare/workers-sdk/blob/b24aeb5722370c2e04bce97a84a1fa1e55725d79/packages/wrangler/src/config/validation.ts#L94-L98
|
|
117
115
|
return config.legacy_env;
|
|
118
116
|
}
|
|
119
117
|
|
|
@@ -135,7 +133,7 @@ export function getScriptName(
|
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
/**
|
|
138
|
-
* Alternative to the getScriptName() because special Legacy cases allowed "name", and "env" together in
|
|
136
|
+
* Alternative to the getScriptName() because special Legacy cases allowed "name", and "env" together in Wrangler v1
|
|
139
137
|
*/
|
|
140
138
|
export function getLegacyScriptName(
|
|
141
139
|
args: { name: string | undefined; env: string | undefined },
|
|
@@ -176,7 +174,7 @@ export class CommandLineArgsError extends Error {}
|
|
|
176
174
|
export function createCLIParser(argv: string[]) {
|
|
177
175
|
// Type check result against CommonYargsOptions to make sure we've included
|
|
178
176
|
// all common options
|
|
179
|
-
const wrangler:
|
|
177
|
+
const wrangler: CommonYargsArgv = makeCLI(argv)
|
|
180
178
|
.strict()
|
|
181
179
|
// We handle errors ourselves in a try-catch around `yargs.parse`.
|
|
182
180
|
// If you want the "help info" to be displayed then throw an instance of `CommandLineArgsError`.
|
|
@@ -212,6 +210,11 @@ export function createCLIParser(argv: string[]) {
|
|
|
212
210
|
type: "string",
|
|
213
211
|
requiresArg: true,
|
|
214
212
|
})
|
|
213
|
+
.option("experimental-json-config", {
|
|
214
|
+
alias: "j",
|
|
215
|
+
describe: `Experimental: Support wrangler.json`,
|
|
216
|
+
type: "boolean",
|
|
217
|
+
})
|
|
215
218
|
.check((args) => {
|
|
216
219
|
// Grab locally specified env params from `.env` file
|
|
217
220
|
const loaded = loadDotEnv(".env", args.env);
|
|
@@ -221,7 +224,10 @@ export function createCLIParser(argv: string[]) {
|
|
|
221
224
|
return true;
|
|
222
225
|
});
|
|
223
226
|
|
|
224
|
-
wrangler.group(
|
|
227
|
+
wrangler.group(
|
|
228
|
+
["experimental-json-config", "config", "env", "help", "version"],
|
|
229
|
+
"Flags:"
|
|
230
|
+
);
|
|
225
231
|
wrangler.help().alias("h", "help");
|
|
226
232
|
|
|
227
233
|
// Default help command that supports the subcommands
|
|
@@ -435,6 +441,15 @@ export function createCLIParser(argv: string[]) {
|
|
|
435
441
|
}
|
|
436
442
|
);
|
|
437
443
|
|
|
444
|
+
// mtls-certificate
|
|
445
|
+
wrangler.command(
|
|
446
|
+
"mtls-certificate",
|
|
447
|
+
"🪪 Manage certificates used for mTLS connections",
|
|
448
|
+
(mtlsYargs) => {
|
|
449
|
+
return mTlsCertificateCommands(mtlsYargs.command(subHelp));
|
|
450
|
+
}
|
|
451
|
+
);
|
|
452
|
+
|
|
438
453
|
/**
|
|
439
454
|
* User Group: login, logout, and whoami
|
|
440
455
|
* TODO: group commands into User group similar to .group() for flags in yargs
|
|
@@ -486,7 +501,7 @@ export function createCLIParser(argv: string[]) {
|
|
|
486
501
|
return;
|
|
487
502
|
}
|
|
488
503
|
await login({ browser: args.browser });
|
|
489
|
-
const config = readConfig(args.config
|
|
504
|
+
const config = readConfig(args.config, args);
|
|
490
505
|
await metrics.sendMetricsEvent("login user", {
|
|
491
506
|
sendMetrics: config.send_metrics,
|
|
492
507
|
});
|
|
@@ -503,10 +518,10 @@ export function createCLIParser(argv: string[]) {
|
|
|
503
518
|
"logout",
|
|
504
519
|
"🚪 Logout from Cloudflare",
|
|
505
520
|
() => {},
|
|
506
|
-
async () => {
|
|
521
|
+
async (args) => {
|
|
507
522
|
await printWranglerBanner();
|
|
508
523
|
await logout();
|
|
509
|
-
const config = readConfig(undefined,
|
|
524
|
+
const config = readConfig(undefined, args);
|
|
510
525
|
await metrics.sendMetricsEvent("logout user", {
|
|
511
526
|
sendMetrics: config.send_metrics,
|
|
512
527
|
});
|
|
@@ -518,10 +533,10 @@ export function createCLIParser(argv: string[]) {
|
|
|
518
533
|
"whoami",
|
|
519
534
|
"🕵️ Retrieve your user info and test your auth config",
|
|
520
535
|
() => {},
|
|
521
|
-
async () => {
|
|
536
|
+
async (args) => {
|
|
522
537
|
await printWranglerBanner();
|
|
523
538
|
await whoami();
|
|
524
|
-
const config = readConfig(undefined,
|
|
539
|
+
const config = readConfig(undefined, args);
|
|
525
540
|
await metrics.sendMetricsEvent("view accounts", {
|
|
526
541
|
sendMetrics: config.send_metrics,
|
|
527
542
|
});
|
|
@@ -533,9 +548,9 @@ export function createCLIParser(argv: string[]) {
|
|
|
533
548
|
"types",
|
|
534
549
|
"📝 Generate types from bindings & module rules in config",
|
|
535
550
|
() => {},
|
|
536
|
-
async () => {
|
|
551
|
+
async (args) => {
|
|
537
552
|
await printWranglerBanner();
|
|
538
|
-
const config = readConfig(undefined,
|
|
553
|
+
const config = readConfig(undefined, args);
|
|
539
554
|
|
|
540
555
|
const configBindings: Partial<Config> = {
|
|
541
556
|
kv_namespaces: config.kv_namespaces ?? [],
|
|
@@ -563,24 +578,20 @@ export function createCLIParser(argv: string[]) {
|
|
|
563
578
|
|
|
564
579
|
//deployments
|
|
565
580
|
const deploymentsWarning =
|
|
566
|
-
"🚧`wrangler deployments` is a beta command. Please report any issues to https://github.com/cloudflare/
|
|
581
|
+
"🚧`wrangler deployments` is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose";
|
|
567
582
|
wrangler.command(
|
|
568
583
|
"deployments",
|
|
569
584
|
"🚢 Displays the 10 most recent deployments for a worker",
|
|
570
|
-
(yargs) =>
|
|
585
|
+
(yargs) =>
|
|
571
586
|
yargs
|
|
572
587
|
.option("name", {
|
|
573
588
|
describe: "The name of your worker",
|
|
574
589
|
type: "string",
|
|
575
590
|
})
|
|
576
|
-
.epilogue(deploymentsWarning)
|
|
577
|
-
|
|
578
|
-
async (deploymentsYargs: ArgumentsCamelCase<{ name: string }>) => {
|
|
591
|
+
.epilogue(deploymentsWarning),
|
|
592
|
+
async (deploymentsYargs) => {
|
|
579
593
|
await printWranglerBanner();
|
|
580
|
-
const config = readConfig(
|
|
581
|
-
deploymentsYargs.config as ConfigPath,
|
|
582
|
-
deploymentsYargs
|
|
583
|
-
);
|
|
594
|
+
const config = readConfig(deploymentsYargs.config, deploymentsYargs);
|
|
584
595
|
const accountId = await requireAuth(config);
|
|
585
596
|
const scriptName = getScriptName(
|
|
586
597
|
{ name: deploymentsYargs.name, env: undefined },
|
|
@@ -628,7 +639,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
628
639
|
await createCLIParser([...argv, "--help"]).parse();
|
|
629
640
|
} else if (e instanceof ParseError) {
|
|
630
641
|
e.notes.push({
|
|
631
|
-
text: "\nIf you think this is a bug, please open an issue at: https://github.com/cloudflare/
|
|
642
|
+
text: "\nIf you think this is a bug, please open an issue at: https://github.com/cloudflare/workers-sdk/issues/new/choose",
|
|
632
643
|
});
|
|
633
644
|
logger.log(formatMessage(e));
|
|
634
645
|
} else if (
|
|
@@ -664,7 +675,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
664
675
|
logger.error(e instanceof Error ? e.message : e);
|
|
665
676
|
logger.log(
|
|
666
677
|
`${fgGreenColor}%s${resetColor}`,
|
|
667
|
-
"If you think this is a bug then please create an issue at https://github.com/cloudflare/
|
|
678
|
+
"If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
|
|
668
679
|
);
|
|
669
680
|
}
|
|
670
681
|
throw e;
|