wrangler 0.0.0-e14e589 → 0.0.0-e1c615f
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 +51 -0
- package/package.json +39 -26
- package/pages/functions/buildWorker.ts +57 -0
- package/pages/functions/filepath-routing.test.ts +39 -0
- package/pages/functions/filepath-routing.ts +221 -0
- package/pages/functions/identifiers.ts +78 -0
- package/pages/functions/routes.ts +158 -0
- package/pages/functions/template-worker.ts +137 -0
- package/src/__tests__/dev.test.tsx +66 -0
- package/src/__tests__/index.test.ts +254 -120
- package/src/__tests__/jest.setup.ts +22 -0
- package/src/__tests__/kv.test.ts +1098 -0
- package/src/__tests__/mock-cfetch.ts +171 -0
- package/src/__tests__/mock-dialogs.ts +65 -0
- package/src/__tests__/run-in-tmp.ts +19 -0
- package/src/__tests__/run-wrangler.ts +32 -0
- package/src/api/form_data.ts +78 -72
- package/src/api/inspect.ts +0 -11
- package/src/api/preview.ts +29 -24
- package/src/api/worker.ts +46 -31
- package/src/cfetch/index.ts +102 -0
- package/src/cfetch/internal.ts +69 -0
- package/src/cli.ts +6 -7
- package/src/config.ts +39 -4
- package/src/dev.tsx +332 -128
- package/src/dialogs.tsx +4 -12
- package/src/index.tsx +397 -222
- package/src/kv.tsx +101 -45
- package/src/module-collection.ts +64 -0
- package/src/pages.tsx +839 -211
- package/src/proxy.ts +103 -0
- package/src/publish.ts +117 -45
- package/src/sites.tsx +6 -7
- package/src/tail.tsx +6 -4
- package/src/user.tsx +9 -16
- package/wrangler-dist/cli.js +123794 -528
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/mock-cfetch.js +0 -46
- package/src/cfetch.ts +0 -72
- package/src/util/fetch.ts +0 -74
package/src/index.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render } from "ink";
|
|
3
|
-
import
|
|
3
|
+
import Dev from "./dev";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import makeCLI from "yargs";
|
|
6
|
-
import
|
|
7
|
-
import type yargs from "yargs";
|
|
6
|
+
import type Yargs from "yargs";
|
|
8
7
|
import { findUp } from "find-up";
|
|
9
8
|
import TOML from "@iarna/toml";
|
|
10
9
|
import type { Config } from "./config";
|
|
@@ -25,11 +24,13 @@ import {
|
|
|
25
24
|
putKeyValue,
|
|
26
25
|
putBulkKeyValue,
|
|
27
26
|
deleteBulkKeyValue,
|
|
27
|
+
createNamespace,
|
|
28
|
+
isValidNamespaceBinding,
|
|
28
29
|
} from "./kv";
|
|
29
30
|
|
|
30
31
|
import { pages } from "./pages";
|
|
31
32
|
|
|
32
|
-
import
|
|
33
|
+
import { fetchResult, fetchRaw } from "./cfetch";
|
|
33
34
|
|
|
34
35
|
import publish from "./publish";
|
|
35
36
|
import path from "path/posix";
|
|
@@ -40,26 +41,75 @@ import { createTail } from "./tail";
|
|
|
40
41
|
import onExit from "signal-exit";
|
|
41
42
|
import { setTimeout } from "node:timers/promises";
|
|
42
43
|
import * as fs from "node:fs";
|
|
43
|
-
import execa from "execa";
|
|
44
|
+
import { execa } from "execa";
|
|
44
45
|
|
|
45
|
-
async function readConfig(
|
|
46
|
+
async function readConfig(configPath?: string): Promise<Config> {
|
|
46
47
|
const config: Config = {};
|
|
47
|
-
if (!
|
|
48
|
-
|
|
48
|
+
if (!configPath) {
|
|
49
|
+
configPath = await findUp("wrangler.toml");
|
|
49
50
|
// TODO - terminate this early instead of going all the way to the root
|
|
50
51
|
}
|
|
51
52
|
|
|
52
|
-
if (
|
|
53
|
-
const tml: string = await readFile(
|
|
53
|
+
if (configPath) {
|
|
54
|
+
const tml: string = await readFile(configPath, "utf-8");
|
|
54
55
|
const parsed = TOML.parse(tml) as Config;
|
|
55
56
|
Object.assign(config, parsed);
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
const inheritedFields = [
|
|
60
|
+
"name",
|
|
61
|
+
"account_id",
|
|
62
|
+
"workers_dev",
|
|
63
|
+
"compatibility_date",
|
|
64
|
+
"compatibility_flags",
|
|
65
|
+
"zone_id",
|
|
66
|
+
"routes",
|
|
67
|
+
"route",
|
|
68
|
+
"jsx_factory",
|
|
69
|
+
"jsx_fragment",
|
|
70
|
+
"site",
|
|
71
|
+
"triggers",
|
|
72
|
+
"usage_model",
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
Object.keys(config.env || {}).forEach((env) => {
|
|
76
|
+
inheritedFields.forEach((field) => {
|
|
77
|
+
if (config[field] !== undefined && config.env[env][field] === undefined) {
|
|
78
|
+
config.env[env][field] = config[field]; // TODO: - shallow copy?
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const mirroredFields = [
|
|
84
|
+
"vars",
|
|
85
|
+
"kv_namespaces",
|
|
86
|
+
"durable_objects",
|
|
87
|
+
"experimental_services",
|
|
88
|
+
];
|
|
89
|
+
Object.keys(config.env || {}).forEach((env) => {
|
|
90
|
+
mirroredFields.forEach((field) => {
|
|
91
|
+
// if it exists on top level, it should exist on env definitions
|
|
92
|
+
Object.keys(config[field] || {}).forEach((fieldKey) => {
|
|
93
|
+
if (!(fieldKey in config.env[env][field])) {
|
|
94
|
+
console.warn(
|
|
95
|
+
`In your configuration, "${field}.${fieldKey}" exists at a top level, but not on "env.${env}". This is not what you probably want, since the field "${field}" is not inherited by environments. Please add "${field}.${fieldKey}" to "env.${env}".`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if ("experimental_services" in config) {
|
|
103
|
+
console.warn(
|
|
104
|
+
"The experimental_services field is only for cloudflare internal usage right now, and is subject to change. Please do not use this on production projects"
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
58
108
|
// todo: validate, add defaults
|
|
59
109
|
// let's just do some basics for now
|
|
60
110
|
|
|
61
111
|
// @ts-expect-error we're being sneaky here for now
|
|
62
|
-
config.__path__ =
|
|
112
|
+
config.__path__ = configPath;
|
|
63
113
|
|
|
64
114
|
return config;
|
|
65
115
|
}
|
|
@@ -67,18 +117,18 @@ async function readConfig(path?: string): Promise<Config> {
|
|
|
67
117
|
// a helper to demand one of a set of options
|
|
68
118
|
// via https://github.com/yargs/yargs/issues/1093#issuecomment-491299261
|
|
69
119
|
function demandOneOfOption(...options: string[]) {
|
|
70
|
-
return function (argv:
|
|
120
|
+
return function (argv: Yargs.Arguments) {
|
|
71
121
|
const count = options.filter((option) => argv[option]).length;
|
|
72
122
|
const lastOption = options.pop();
|
|
73
123
|
|
|
74
124
|
if (count === 0) {
|
|
75
|
-
throw new
|
|
125
|
+
throw new CommandLineArgsError(
|
|
76
126
|
`Exactly one of the arguments ${options.join(
|
|
77
127
|
", "
|
|
78
128
|
)} and ${lastOption} is required`
|
|
79
129
|
);
|
|
80
130
|
} else if (count > 1) {
|
|
81
|
-
throw new
|
|
131
|
+
throw new CommandLineArgsError(
|
|
82
132
|
`Arguments ${options.join(
|
|
83
133
|
", "
|
|
84
134
|
)} and ${lastOption} are mutually exclusive`
|
|
@@ -89,30 +139,49 @@ function demandOneOfOption(...options: string[]) {
|
|
|
89
139
|
};
|
|
90
140
|
}
|
|
91
141
|
|
|
142
|
+
class CommandLineArgsError extends Error {}
|
|
143
|
+
class DeprecationError extends Error {}
|
|
144
|
+
class NotImplementedError extends Error {}
|
|
145
|
+
|
|
92
146
|
export async function main(argv: string[]): Promise<void> {
|
|
93
|
-
const
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
()
|
|
100
|
-
yargs
|
|
147
|
+
const wrangler = makeCLI(argv)
|
|
148
|
+
// We handle errors ourselves in a try-catch around `yargs.parse`.
|
|
149
|
+
// If you want the "help info" to be displayed then throw an instance of `CommandLineArgsError`.
|
|
150
|
+
// Otherwise we just log the error that was thrown without any "help info".
|
|
151
|
+
.showHelpOnFail(false)
|
|
152
|
+
.fail((msg, error) => {
|
|
153
|
+
if (!error) {
|
|
154
|
+
// If there is only a `msg` then this came from yargs own validation, so wrap in a `CommandLineArgsError`.
|
|
155
|
+
error = new CommandLineArgsError(msg);
|
|
101
156
|
}
|
|
102
|
-
|
|
157
|
+
throw error;
|
|
158
|
+
})
|
|
103
159
|
.scriptName("wrangler")
|
|
104
160
|
.wrap(null);
|
|
105
161
|
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
162
|
+
// the default is to simply print the help menu
|
|
163
|
+
wrangler.command(
|
|
164
|
+
["*"],
|
|
165
|
+
false,
|
|
166
|
+
() => {},
|
|
167
|
+
(args) => {
|
|
168
|
+
if (args._.length > 0) {
|
|
169
|
+
throw new CommandLineArgsError(`Unknown command: ${args._}.`);
|
|
170
|
+
} else {
|
|
171
|
+
wrangler.showHelp("log");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
);
|
|
111
175
|
|
|
112
|
-
//
|
|
176
|
+
// You will note that we use the form for all commands where we use the builder function
|
|
177
|
+
// to define options and subcommands.
|
|
178
|
+
// Further we return the result of this builder even though it's not completely necessary.
|
|
179
|
+
// The reason is that it's required for type inference of the args in the handle function.
|
|
180
|
+
// I wish we could enforce this pattern, but this comment will have to do for now.
|
|
181
|
+
// (It's also annoying that choices[] doesn't get inferred as an enum. 🤷♂.)
|
|
113
182
|
|
|
114
183
|
// [DEPRECATED] generate
|
|
115
|
-
|
|
184
|
+
wrangler.command(
|
|
116
185
|
// we definitely want to move away from us cloning github templates
|
|
117
186
|
// we can do something better here, let's see
|
|
118
187
|
"generate [name] [template]",
|
|
@@ -130,14 +199,14 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
130
199
|
},
|
|
131
200
|
() => {
|
|
132
201
|
// "👯 [DEPRECATED]. Scaffold a Cloudflare Workers project from a public GitHub repository.",
|
|
133
|
-
|
|
202
|
+
throw new DeprecationError(
|
|
134
203
|
"`wrangler generate` has been deprecated, please refer to TODO://some/path for alternatives"
|
|
135
204
|
);
|
|
136
205
|
}
|
|
137
206
|
);
|
|
138
207
|
|
|
139
208
|
// init
|
|
140
|
-
|
|
209
|
+
wrangler.command(
|
|
141
210
|
"init [name]",
|
|
142
211
|
"📥 Create a wrangler.toml configuration file",
|
|
143
212
|
(yargs) => {
|
|
@@ -146,27 +215,42 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
146
215
|
type: "string",
|
|
147
216
|
});
|
|
148
217
|
},
|
|
149
|
-
async () => {
|
|
218
|
+
async (args) => {
|
|
219
|
+
if ("type" in args) {
|
|
220
|
+
let message = "The --type option is no longer supported.";
|
|
221
|
+
if (args.type === "webpack") {
|
|
222
|
+
message +=
|
|
223
|
+
"\nIf you wish to use webpack then you will need to create a custom build.";
|
|
224
|
+
// TODO: Add a link to docs
|
|
225
|
+
}
|
|
226
|
+
throw new CommandLineArgsError(message);
|
|
227
|
+
}
|
|
228
|
+
|
|
150
229
|
const destination = path.join(process.cwd(), "wrangler.toml");
|
|
151
230
|
if (fs.existsSync(destination)) {
|
|
152
|
-
console.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
`compatibility_date = "${compatibilityDate}"
|
|
159
|
-
`
|
|
160
|
-
);
|
|
161
|
-
console.log(`✨ Succesfully created wrangler.toml`);
|
|
162
|
-
// TODO: suggest next steps?
|
|
163
|
-
} catch (err) {
|
|
164
|
-
console.error(`Failed to create wrangler.toml`);
|
|
165
|
-
console.error(err);
|
|
166
|
-
throw err;
|
|
231
|
+
console.warn(`${destination} file already exists!`);
|
|
232
|
+
const result = await confirm(
|
|
233
|
+
"Do you want to continue initializing this project?"
|
|
234
|
+
);
|
|
235
|
+
if (!result) {
|
|
236
|
+
return;
|
|
167
237
|
}
|
|
168
238
|
}
|
|
169
239
|
|
|
240
|
+
const compatibilityDate = new Date().toISOString().substring(0, 10);
|
|
241
|
+
try {
|
|
242
|
+
await writeFile(
|
|
243
|
+
destination,
|
|
244
|
+
`compatibility_date = "${compatibilityDate}"` + "\n"
|
|
245
|
+
);
|
|
246
|
+
console.log(`✨ Successfully created wrangler.toml`);
|
|
247
|
+
// TODO: suggest next steps?
|
|
248
|
+
} catch (err) {
|
|
249
|
+
throw new Error(
|
|
250
|
+
`Failed to create wrangler.toml.\n${err.message ?? err}`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
170
254
|
// if no package.json, ask, and if yes, create one
|
|
171
255
|
let pathToPackageJson = await findUp("package.json");
|
|
172
256
|
|
|
@@ -203,9 +287,17 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
203
287
|
JSON.stringify(
|
|
204
288
|
{
|
|
205
289
|
compilerOptions: {
|
|
206
|
-
target: "
|
|
207
|
-
module: "
|
|
208
|
-
|
|
290
|
+
target: "esnext",
|
|
291
|
+
module: "esnext",
|
|
292
|
+
moduleResolution: "node",
|
|
293
|
+
esModuleInterop: true,
|
|
294
|
+
allowJs: true,
|
|
295
|
+
allowSyntheticDefaultImports: true,
|
|
296
|
+
isolatedModules: true,
|
|
297
|
+
noEmit: true,
|
|
298
|
+
lib: ["esnext"],
|
|
299
|
+
jsx: "react",
|
|
300
|
+
resolveJsonModule: true,
|
|
209
301
|
types: ["@cloudflare/workers-types"],
|
|
210
302
|
},
|
|
211
303
|
},
|
|
@@ -228,7 +320,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
228
320
|
);
|
|
229
321
|
|
|
230
322
|
// build
|
|
231
|
-
|
|
323
|
+
wrangler.command(
|
|
232
324
|
"build",
|
|
233
325
|
false,
|
|
234
326
|
(yargs) => {
|
|
@@ -238,14 +330,14 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
238
330
|
},
|
|
239
331
|
() => {
|
|
240
332
|
// "[DEPRECATED] 🦀 Build your project (if applicable)",
|
|
241
|
-
|
|
333
|
+
throw new DeprecationError(
|
|
242
334
|
"`wrangler build` has been deprecated, please refer to TODO://some/path for alternatives"
|
|
243
335
|
);
|
|
244
336
|
}
|
|
245
337
|
);
|
|
246
338
|
|
|
247
339
|
// login
|
|
248
|
-
|
|
340
|
+
wrangler.command(
|
|
249
341
|
// this needs scopes as an option?
|
|
250
342
|
"login",
|
|
251
343
|
false, // we don't need to show this in the menu
|
|
@@ -282,13 +374,13 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
282
374
|
await login();
|
|
283
375
|
|
|
284
376
|
// TODO: would be nice if it optionally saved login
|
|
285
|
-
//
|
|
377
|
+
// credentials inside node_modules/.cache or something
|
|
286
378
|
// this way you could have multiple users on a single machine
|
|
287
379
|
}
|
|
288
380
|
);
|
|
289
381
|
|
|
290
382
|
// logout
|
|
291
|
-
|
|
383
|
+
wrangler.command(
|
|
292
384
|
// this needs scopes as an option?
|
|
293
385
|
"logout",
|
|
294
386
|
false, // we don't need to show this in the menu
|
|
@@ -300,7 +392,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
300
392
|
);
|
|
301
393
|
|
|
302
394
|
// whoami
|
|
303
|
-
|
|
395
|
+
wrangler.command(
|
|
304
396
|
"whoami",
|
|
305
397
|
false, // we don't need to show this the menu
|
|
306
398
|
// "🕵️ Retrieve your user info and test your auth config",
|
|
@@ -311,20 +403,20 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
311
403
|
);
|
|
312
404
|
|
|
313
405
|
// config
|
|
314
|
-
|
|
406
|
+
wrangler.command(
|
|
315
407
|
"config",
|
|
316
408
|
false,
|
|
317
409
|
() => {},
|
|
318
410
|
() => {
|
|
319
411
|
// "🕵️ Authenticate Wrangler with a Cloudflare API Token",
|
|
320
|
-
|
|
412
|
+
throw new DeprecationError(
|
|
321
413
|
"`wrangler config` has been deprecated, please refer to TODO://some/path for alternatives"
|
|
322
414
|
);
|
|
323
415
|
}
|
|
324
416
|
);
|
|
325
417
|
|
|
326
418
|
// dev
|
|
327
|
-
|
|
419
|
+
wrangler.command(
|
|
328
420
|
"dev <filename>",
|
|
329
421
|
"👂 Start a local server for developing your worker",
|
|
330
422
|
(yargs) => {
|
|
@@ -356,14 +448,14 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
356
448
|
.option("host", {
|
|
357
449
|
type: "string",
|
|
358
450
|
describe:
|
|
359
|
-
"Host to forward requests to, defaults to the zone of project
|
|
451
|
+
"Host to forward requests to, defaults to the zone of project",
|
|
360
452
|
})
|
|
361
453
|
.option("local-protocol", {
|
|
362
454
|
default: "http",
|
|
363
455
|
describe: "Protocol to listen to requests on, defaults to http.",
|
|
364
456
|
choices: ["http", "https"],
|
|
365
457
|
})
|
|
366
|
-
.option("public", {
|
|
458
|
+
.option("experimental-public", {
|
|
367
459
|
describe: "Static assets to be served",
|
|
368
460
|
type: "string",
|
|
369
461
|
})
|
|
@@ -376,12 +468,32 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
376
468
|
describe:
|
|
377
469
|
"Protocol to forward requests to host on, defaults to https.",
|
|
378
470
|
choices: ["http", "https"],
|
|
471
|
+
})
|
|
472
|
+
.option("jsx-factory", {
|
|
473
|
+
describe: "The function that is called for each JSX element",
|
|
474
|
+
type: "string",
|
|
475
|
+
})
|
|
476
|
+
.option("jsx-fragment", {
|
|
477
|
+
describe: "The function that is called for each JSX fragment",
|
|
478
|
+
type: "string",
|
|
379
479
|
});
|
|
380
480
|
},
|
|
381
481
|
async (args) => {
|
|
382
482
|
const { filename, format } = args;
|
|
383
483
|
const config = args.config as Config;
|
|
384
484
|
|
|
485
|
+
if (args["experimental-public"]) {
|
|
486
|
+
console.warn(
|
|
487
|
+
"🚨 The --experimental-public field is experimental and will change in the future."
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (args.public) {
|
|
492
|
+
throw new Error(
|
|
493
|
+
"🚨 The --public field has been renamed to --experimental-public, and will change behaviour in the future."
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
|
|
385
497
|
// -- snip, extract --
|
|
386
498
|
|
|
387
499
|
if (!args.local) {
|
|
@@ -394,49 +506,76 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
394
506
|
if (!config.account_id) {
|
|
395
507
|
config.account_id = await getAccountId();
|
|
396
508
|
if (!config.account_id) {
|
|
397
|
-
|
|
398
|
-
return;
|
|
509
|
+
throw new Error("No account id found, quitting...");
|
|
399
510
|
}
|
|
400
511
|
}
|
|
401
512
|
}
|
|
402
513
|
|
|
403
514
|
// -- snip, end --
|
|
404
515
|
|
|
405
|
-
const envRootObj = args.env ? config[
|
|
516
|
+
const envRootObj = args.env ? config.env[args.env] || {} : config;
|
|
517
|
+
|
|
518
|
+
// TODO: this error shouldn't actually happen,
|
|
519
|
+
// but we haven't fixed it internally yet
|
|
520
|
+
if ("durable_objects" in envRootObj) {
|
|
521
|
+
if (!(args.name || config.name)) {
|
|
522
|
+
console.warn(
|
|
523
|
+
'A worker with durable objects need to be named, or it may not work as expected. Add a "name" into wrangler.toml, or pass it in the command line with --name.'
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
// TODO: if not already published, publish a draft worker
|
|
527
|
+
}
|
|
406
528
|
|
|
407
|
-
render(
|
|
529
|
+
const { waitUntilExit } = render(
|
|
408
530
|
<Dev
|
|
409
531
|
name={args.name || config.name}
|
|
410
|
-
entry={filename}
|
|
532
|
+
entry={path.relative(process.cwd(), filename)}
|
|
533
|
+
buildCommand={config.build || {}}
|
|
411
534
|
format={format}
|
|
412
535
|
initialMode={args.local ? "local" : "remote"}
|
|
536
|
+
jsxFactory={args["jsx-factory"] || envRootObj?.jsx_factory}
|
|
537
|
+
jsxFragment={args["jsx-fragment"] || envRootObj?.jsx_fragment}
|
|
413
538
|
accountId={config.account_id}
|
|
414
539
|
site={args.site || config.site?.bucket}
|
|
415
540
|
port={args.port || config.dev?.port}
|
|
416
|
-
public={args
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
541
|
+
public={args["experimental-public"]}
|
|
542
|
+
compatibilityDate={config.compatibility_date}
|
|
543
|
+
compatibilityFlags={config.compatibility_flags}
|
|
544
|
+
usageModel={config.usage_model}
|
|
545
|
+
bindings={{
|
|
546
|
+
kv_namespaces: envRootObj.kv_namespaces?.map(
|
|
547
|
+
({ binding, preview_id, id: _id }) => {
|
|
548
|
+
// In `dev`, we make folks use a separate kv namespace called
|
|
549
|
+
// `preview_id` instead of `id` so that they don't
|
|
550
|
+
// break production data. So here we check that a `preview_id`
|
|
551
|
+
// has actually been configured.
|
|
552
|
+
// This whole block of code will be obsoleted in the future
|
|
553
|
+
// when we have copy-on-write for previews on edge workers.
|
|
421
554
|
if (!preview_id) {
|
|
422
555
|
// TODO: This error has to be a _lot_ better, ideally just asking
|
|
423
556
|
// to create a preview namespace for the user automatically
|
|
424
557
|
throw new Error(
|
|
425
|
-
|
|
426
|
-
);
|
|
558
|
+
`In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "${binding}" in your wrangler.toml`
|
|
559
|
+
); // Ugh, I really don't like this message very much
|
|
427
560
|
}
|
|
428
|
-
return {
|
|
429
|
-
|
|
430
|
-
|
|
561
|
+
return {
|
|
562
|
+
binding,
|
|
563
|
+
id: preview_id,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
431
566
|
),
|
|
567
|
+
vars: envRootObj.vars,
|
|
568
|
+
durable_objects: envRootObj.durable_objects,
|
|
569
|
+
services: envRootObj.experimental_services,
|
|
432
570
|
}}
|
|
433
571
|
/>
|
|
434
572
|
);
|
|
573
|
+
await waitUntilExit();
|
|
435
574
|
}
|
|
436
575
|
);
|
|
437
576
|
|
|
438
577
|
// publish
|
|
439
|
-
|
|
578
|
+
wrangler.command(
|
|
440
579
|
"publish [script]",
|
|
441
580
|
"🆙 Publish your Worker to Cloudflare.",
|
|
442
581
|
(yargs) => {
|
|
@@ -453,7 +592,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
453
592
|
describe: "name to use when uploading",
|
|
454
593
|
type: "string",
|
|
455
594
|
})
|
|
456
|
-
.option("public", {
|
|
595
|
+
.option("experimental-public", {
|
|
457
596
|
describe: "Static assets to be served",
|
|
458
597
|
type: "string",
|
|
459
598
|
})
|
|
@@ -476,13 +615,34 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
476
615
|
type: "boolean",
|
|
477
616
|
default: "false",
|
|
478
617
|
hidden: true,
|
|
618
|
+
})
|
|
619
|
+
.option("jsx-factory", {
|
|
620
|
+
describe: "The function that is called for each JSX element",
|
|
621
|
+
type: "string",
|
|
622
|
+
})
|
|
623
|
+
.option("jsx-fragment", {
|
|
624
|
+
describe: "The function that is called for each JSX fragment",
|
|
625
|
+
type: "string",
|
|
479
626
|
});
|
|
480
627
|
},
|
|
481
628
|
async (args) => {
|
|
482
629
|
if (args.local) {
|
|
483
|
-
|
|
484
|
-
|
|
630
|
+
throw new NotImplementedError(
|
|
631
|
+
"🚫 Local publishing is not yet supported"
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
if (args["experimental-public"]) {
|
|
636
|
+
console.warn(
|
|
637
|
+
"🚨 The --experimental-public field is experimental and will change in the future."
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
if (args.public) {
|
|
641
|
+
throw new Error(
|
|
642
|
+
"🚨 The --public field has been renamed to --experimental-public, and will change behaviour in the future."
|
|
643
|
+
);
|
|
485
644
|
}
|
|
645
|
+
|
|
486
646
|
const config = args.config as Config;
|
|
487
647
|
|
|
488
648
|
// -- snip, extract --
|
|
@@ -496,8 +656,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
496
656
|
if (!config.account_id) {
|
|
497
657
|
config.account_id = await getAccountId();
|
|
498
658
|
if (!config.account_id) {
|
|
499
|
-
|
|
500
|
-
return;
|
|
659
|
+
throw new Error("No account id found, quitting...");
|
|
501
660
|
}
|
|
502
661
|
}
|
|
503
662
|
}
|
|
@@ -510,15 +669,17 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
510
669
|
script: args.script,
|
|
511
670
|
env: args.env,
|
|
512
671
|
triggers: args.triggers,
|
|
672
|
+
jsxFactory: args["jsx-factory"],
|
|
673
|
+
jsxFragment: args["jsx-fragment"],
|
|
513
674
|
routes: args.routes,
|
|
514
|
-
public: args
|
|
675
|
+
public: args["experimental-public"],
|
|
515
676
|
site: args.site,
|
|
516
677
|
});
|
|
517
678
|
}
|
|
518
679
|
);
|
|
519
680
|
|
|
520
681
|
// tail
|
|
521
|
-
|
|
682
|
+
wrangler.command(
|
|
522
683
|
"tail [name]",
|
|
523
684
|
"🦚 Starts a log tailing session for a deployed Worker.",
|
|
524
685
|
(yargs) => {
|
|
@@ -565,8 +726,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
565
726
|
const config = args.config as Config;
|
|
566
727
|
|
|
567
728
|
if (!(args.name || config.name)) {
|
|
568
|
-
|
|
569
|
-
return;
|
|
729
|
+
throw new Error("Missing script name");
|
|
570
730
|
}
|
|
571
731
|
const scriptName = `${args.name || config.name}${
|
|
572
732
|
args.env ? `-${args.env}` : ""
|
|
@@ -584,8 +744,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
584
744
|
if (!config.account_id) {
|
|
585
745
|
config.account_id = await getAccountId();
|
|
586
746
|
if (!config.account_id) {
|
|
587
|
-
|
|
588
|
-
return;
|
|
747
|
+
throw new Error("No account id found, quitting...");
|
|
589
748
|
}
|
|
590
749
|
}
|
|
591
750
|
}
|
|
@@ -609,9 +768,9 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
609
768
|
`successfully created tail, expires at ${expiration.toLocaleString()}`
|
|
610
769
|
);
|
|
611
770
|
|
|
612
|
-
onExit(() => {
|
|
771
|
+
onExit(async () => {
|
|
613
772
|
tail.terminate();
|
|
614
|
-
deleteTail();
|
|
773
|
+
await deleteTail();
|
|
615
774
|
});
|
|
616
775
|
|
|
617
776
|
tail.on("message", (data) => {
|
|
@@ -636,7 +795,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
636
795
|
);
|
|
637
796
|
|
|
638
797
|
// preview
|
|
639
|
-
|
|
798
|
+
wrangler.command(
|
|
640
799
|
"preview [method] [body]",
|
|
641
800
|
false,
|
|
642
801
|
(yargs) => {
|
|
@@ -662,20 +821,20 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
662
821
|
});
|
|
663
822
|
},
|
|
664
823
|
() => {
|
|
665
|
-
// "🔬 [DEPRECATED] Preview your code temporarily on cloudflareworkers.com"
|
|
666
|
-
|
|
824
|
+
// "🔬 [DEPRECATED] Preview your code temporarily on https://cloudflareworkers.com"
|
|
825
|
+
throw new DeprecationError(
|
|
667
826
|
"`wrangler preview` has been deprecated, please refer to TODO://some/path for alternatives"
|
|
668
827
|
);
|
|
669
828
|
}
|
|
670
829
|
);
|
|
671
830
|
|
|
672
831
|
// route
|
|
673
|
-
|
|
832
|
+
wrangler.command(
|
|
674
833
|
"route",
|
|
675
834
|
false, // I think we want to hide this command
|
|
676
835
|
// "➡️ List or delete worker routes",
|
|
677
|
-
(
|
|
678
|
-
return
|
|
836
|
+
(routeYargs) => {
|
|
837
|
+
return routeYargs
|
|
679
838
|
.command(
|
|
680
839
|
"list",
|
|
681
840
|
"List a route associated with a zone",
|
|
@@ -699,11 +858,10 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
699
858
|
// TODO: use environment (current wrangler doesn't do so?)
|
|
700
859
|
const zone = args.zone || (args.config as Config).zone_id;
|
|
701
860
|
if (!zone) {
|
|
702
|
-
|
|
703
|
-
return;
|
|
861
|
+
throw new Error("missing zone id");
|
|
704
862
|
}
|
|
705
863
|
|
|
706
|
-
console.log(await
|
|
864
|
+
console.log(await fetchResult(`/zones/${zone}/workers/routes`));
|
|
707
865
|
}
|
|
708
866
|
)
|
|
709
867
|
.command(
|
|
@@ -733,7 +891,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
733
891
|
}
|
|
734
892
|
|
|
735
893
|
console.log(
|
|
736
|
-
await
|
|
894
|
+
await fetchResult(`/zones/${zone}/workers/routes/${args.id}`, {
|
|
737
895
|
method: "DELETE",
|
|
738
896
|
})
|
|
739
897
|
);
|
|
@@ -743,7 +901,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
743
901
|
);
|
|
744
902
|
|
|
745
903
|
// subdomain
|
|
746
|
-
|
|
904
|
+
wrangler.command(
|
|
747
905
|
"subdomain [name]",
|
|
748
906
|
false,
|
|
749
907
|
// "👷 Create or change your workers.dev subdomain.",
|
|
@@ -751,18 +909,18 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
751
909
|
return yargs.positional("name", { type: "string" });
|
|
752
910
|
},
|
|
753
911
|
() => {
|
|
754
|
-
|
|
912
|
+
throw new DeprecationError(
|
|
755
913
|
"`wrangler subdomain` has been deprecated, please refer to TODO://some/path for alternatives"
|
|
756
914
|
);
|
|
757
915
|
}
|
|
758
916
|
);
|
|
759
917
|
|
|
760
918
|
// secret
|
|
761
|
-
|
|
919
|
+
wrangler.command(
|
|
762
920
|
"secret",
|
|
763
921
|
"🤫 Generate a secret that can be referenced in the worker script",
|
|
764
|
-
(
|
|
765
|
-
return
|
|
922
|
+
(secretYargs) => {
|
|
923
|
+
return secretYargs
|
|
766
924
|
.command(
|
|
767
925
|
"put <key>",
|
|
768
926
|
"Create or update a secret variable for a script",
|
|
@@ -784,16 +942,16 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
784
942
|
},
|
|
785
943
|
async (args) => {
|
|
786
944
|
if (args.local) {
|
|
787
|
-
|
|
788
|
-
|
|
945
|
+
throw new NotImplementedError(
|
|
946
|
+
"--local not implemented for this command yet"
|
|
947
|
+
);
|
|
789
948
|
}
|
|
790
949
|
const config = args.config as Config;
|
|
791
950
|
|
|
792
951
|
// TODO: use environment (how does current wrangler do it?)
|
|
793
952
|
const scriptName = args.name || config.name;
|
|
794
953
|
if (!scriptName) {
|
|
795
|
-
|
|
796
|
-
return;
|
|
954
|
+
throw new Error("Missing script name");
|
|
797
955
|
}
|
|
798
956
|
|
|
799
957
|
// -- snip, extract --
|
|
@@ -808,8 +966,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
808
966
|
if (!config.account_id) {
|
|
809
967
|
config.account_id = await getAccountId();
|
|
810
968
|
if (!config.account_id) {
|
|
811
|
-
|
|
812
|
-
return;
|
|
969
|
+
throw new Error("No account id found, quitting...");
|
|
813
970
|
}
|
|
814
971
|
}
|
|
815
972
|
}
|
|
@@ -821,7 +978,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
821
978
|
"password"
|
|
822
979
|
);
|
|
823
980
|
async function submitSecret() {
|
|
824
|
-
return await
|
|
981
|
+
return await fetchResult(
|
|
825
982
|
`/accounts/${config.account_id}/workers/scripts/${scriptName}/secrets/`,
|
|
826
983
|
{
|
|
827
984
|
method: "PUT",
|
|
@@ -840,7 +997,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
840
997
|
} catch (e) {
|
|
841
998
|
if (e.code === 10007) {
|
|
842
999
|
// upload a draft worker
|
|
843
|
-
await
|
|
1000
|
+
await fetchResult(
|
|
844
1001
|
`/accounts/${config.account_id}/workers/scripts/${scriptName}`,
|
|
845
1002
|
{
|
|
846
1003
|
method: "PUT",
|
|
@@ -851,7 +1008,11 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
851
1008
|
content: `export default { fetch() {} }`,
|
|
852
1009
|
type: "esm",
|
|
853
1010
|
},
|
|
854
|
-
|
|
1011
|
+
bindings: {
|
|
1012
|
+
kv_namespaces: [],
|
|
1013
|
+
vars: {},
|
|
1014
|
+
durable_objects: { bindings: [] },
|
|
1015
|
+
},
|
|
855
1016
|
modules: [],
|
|
856
1017
|
}),
|
|
857
1018
|
}
|
|
@@ -885,8 +1046,9 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
885
1046
|
},
|
|
886
1047
|
async (args) => {
|
|
887
1048
|
if (args.local) {
|
|
888
|
-
|
|
889
|
-
|
|
1049
|
+
throw new NotImplementedError(
|
|
1050
|
+
"--local not implemented for this command yet"
|
|
1051
|
+
);
|
|
890
1052
|
}
|
|
891
1053
|
const config = args.config as Config;
|
|
892
1054
|
|
|
@@ -908,8 +1070,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
908
1070
|
if (!config.account_id) {
|
|
909
1071
|
config.account_id = await getAccountId();
|
|
910
1072
|
if (!config.account_id) {
|
|
911
|
-
|
|
912
|
-
return;
|
|
1073
|
+
throw new Error("No account id found, quitting...");
|
|
913
1074
|
}
|
|
914
1075
|
}
|
|
915
1076
|
}
|
|
@@ -922,7 +1083,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
922
1083
|
);
|
|
923
1084
|
|
|
924
1085
|
console.log(
|
|
925
|
-
await
|
|
1086
|
+
await fetchResult(
|
|
926
1087
|
`/accounts/${config.account_id}/workers/scripts/${scriptName}/secrets/${args.key}`,
|
|
927
1088
|
{ method: "DELETE" }
|
|
928
1089
|
)
|
|
@@ -947,16 +1108,16 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
947
1108
|
},
|
|
948
1109
|
async (args) => {
|
|
949
1110
|
if (args.local) {
|
|
950
|
-
|
|
951
|
-
|
|
1111
|
+
throw new NotImplementedError(
|
|
1112
|
+
"--local not implemented for this command yet"
|
|
1113
|
+
);
|
|
952
1114
|
}
|
|
953
1115
|
const config = args.config as Config;
|
|
954
1116
|
|
|
955
1117
|
// TODO: use environment (how does current wrangler do it?)
|
|
956
1118
|
const scriptName = args.name || config.name;
|
|
957
1119
|
if (!scriptName) {
|
|
958
|
-
|
|
959
|
-
return;
|
|
1120
|
+
throw new Error("Missing script name");
|
|
960
1121
|
}
|
|
961
1122
|
|
|
962
1123
|
// -- snip, extract --
|
|
@@ -971,8 +1132,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
971
1132
|
if (!config.account_id) {
|
|
972
1133
|
config.account_id = await getAccountId();
|
|
973
1134
|
if (!config.account_id) {
|
|
974
|
-
|
|
975
|
-
return;
|
|
1135
|
+
throw new Error("No account id found, quitting...");
|
|
976
1136
|
}
|
|
977
1137
|
}
|
|
978
1138
|
}
|
|
@@ -980,7 +1140,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
980
1140
|
// -- snip, end --
|
|
981
1141
|
|
|
982
1142
|
console.log(
|
|
983
|
-
await
|
|
1143
|
+
await fetchResult(
|
|
984
1144
|
`/accounts/${config.account_id}/workers/scripts/${scriptName}/secrets`
|
|
985
1145
|
)
|
|
986
1146
|
);
|
|
@@ -991,11 +1151,11 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
991
1151
|
|
|
992
1152
|
// kv
|
|
993
1153
|
// :namespace
|
|
994
|
-
|
|
1154
|
+
wrangler.command(
|
|
995
1155
|
"kv:namespace",
|
|
996
1156
|
"🗂️ Interact with your Workers KV Namespaces",
|
|
997
|
-
(
|
|
998
|
-
return
|
|
1157
|
+
(namespaceYargs) => {
|
|
1158
|
+
return namespaceYargs
|
|
999
1159
|
.command(
|
|
1000
1160
|
"create <namespace>",
|
|
1001
1161
|
"Create a new namespace",
|
|
@@ -1015,13 +1175,19 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1015
1175
|
});
|
|
1016
1176
|
},
|
|
1017
1177
|
async (args) => {
|
|
1018
|
-
if (args._.length
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
} ${args._.slice(2).join(" ")}"?`
|
|
1178
|
+
if (args._.length > 2) {
|
|
1179
|
+
const extraArgs = args._.slice(2).join(" ");
|
|
1180
|
+
throw new CommandLineArgsError(
|
|
1181
|
+
`Unexpected additional positional arguments "${extraArgs}".`
|
|
1023
1182
|
);
|
|
1024
1183
|
}
|
|
1184
|
+
|
|
1185
|
+
if (!isValidNamespaceBinding(args.namespace)) {
|
|
1186
|
+
throw new CommandLineArgsError(
|
|
1187
|
+
`The namespace binding name "${args.namespace}" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.`
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1025
1191
|
const config = args.config as Config;
|
|
1026
1192
|
if (!config.name) {
|
|
1027
1193
|
console.warn(
|
|
@@ -1029,13 +1195,10 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1029
1195
|
);
|
|
1030
1196
|
}
|
|
1031
1197
|
|
|
1032
|
-
const
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
if (/[\W]+/.test(args.namespace)) {
|
|
1037
|
-
throw new Error("invalid binding name, needs to be js friendly");
|
|
1038
|
-
}
|
|
1198
|
+
const name = config.name || "worker";
|
|
1199
|
+
const environment = args.env ? `-${args.env}` : "";
|
|
1200
|
+
const preview = args.preview ? "_preview" : "";
|
|
1201
|
+
const title = `${name}${environment}-${args.namespace}${preview}`;
|
|
1039
1202
|
|
|
1040
1203
|
if (args.local) {
|
|
1041
1204
|
const { Miniflare } = await import("miniflare");
|
|
@@ -1044,7 +1207,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1044
1207
|
// TODO: these options shouldn't be required
|
|
1045
1208
|
script: ` `, // has to be a string with at least one char
|
|
1046
1209
|
});
|
|
1047
|
-
mf.getKVNamespace(title); // this should "create" the namespace
|
|
1210
|
+
await mf.getKVNamespace(title); // this should "create" the namespace
|
|
1048
1211
|
console.log(`✨ Success! Created KV namespace ${title}`);
|
|
1049
1212
|
return;
|
|
1050
1213
|
}
|
|
@@ -1061,8 +1224,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1061
1224
|
if (!config.account_id) {
|
|
1062
1225
|
config.account_id = await getAccountId();
|
|
1063
1226
|
if (!config.account_id) {
|
|
1064
|
-
|
|
1065
|
-
return;
|
|
1227
|
+
throw new Error("No account id found, quitting...");
|
|
1066
1228
|
}
|
|
1067
1229
|
}
|
|
1068
1230
|
}
|
|
@@ -1072,31 +1234,19 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1072
1234
|
// TODO: generate a binding name stripping non alphanumeric chars
|
|
1073
1235
|
|
|
1074
1236
|
console.log(`🌀 Creating namespace with title "${title}"`);
|
|
1075
|
-
|
|
1076
|
-
const response = await cfetch<{ id: string }>(
|
|
1077
|
-
`/accounts/${config.account_id}/storage/kv/namespaces`,
|
|
1078
|
-
{
|
|
1079
|
-
method: "POST",
|
|
1080
|
-
headers: {
|
|
1081
|
-
"Content-Type": "application/json",
|
|
1082
|
-
},
|
|
1083
|
-
body: JSON.stringify({
|
|
1084
|
-
title,
|
|
1085
|
-
}),
|
|
1086
|
-
}
|
|
1087
|
-
);
|
|
1237
|
+
const namespaceId = await createNamespace(config.account_id, title);
|
|
1088
1238
|
|
|
1089
1239
|
console.log("✨ Success!");
|
|
1240
|
+
const envString = args.env ? ` under [env.${args.env}]` : "";
|
|
1241
|
+
const previewString = args.preview ? "preview_" : "";
|
|
1090
1242
|
console.log(
|
|
1091
|
-
`Add the following to your configuration file in your kv_namespaces array${
|
|
1092
|
-
args.env ? ` under [env.${args.env}]` : ""
|
|
1093
|
-
}:`
|
|
1243
|
+
`Add the following to your configuration file in your kv_namespaces array${envString}:`
|
|
1094
1244
|
);
|
|
1095
1245
|
console.log(
|
|
1096
|
-
`{ binding = "${args.namespace}", ${
|
|
1097
|
-
args.preview ? "preview_" : ""
|
|
1098
|
-
}id = ${response.id} }`
|
|
1246
|
+
`{ binding = "${args.namespace}", ${previewString}id = "${namespaceId}" }`
|
|
1099
1247
|
);
|
|
1248
|
+
|
|
1249
|
+
// TODO: automatically write this block to the wrangler.toml config file??
|
|
1100
1250
|
}
|
|
1101
1251
|
)
|
|
1102
1252
|
.command(
|
|
@@ -1105,8 +1255,9 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1105
1255
|
{},
|
|
1106
1256
|
async (args) => {
|
|
1107
1257
|
if (args.local) {
|
|
1108
|
-
|
|
1109
|
-
|
|
1258
|
+
throw new NotImplementedError(
|
|
1259
|
+
`local mode is not yet supported for this command`
|
|
1260
|
+
);
|
|
1110
1261
|
}
|
|
1111
1262
|
|
|
1112
1263
|
const config = args.config as Config;
|
|
@@ -1123,8 +1274,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1123
1274
|
if (!config.account_id) {
|
|
1124
1275
|
config.account_id = await getAccountId();
|
|
1125
1276
|
if (!config.account_id) {
|
|
1126
|
-
|
|
1127
|
-
return;
|
|
1277
|
+
throw new Error("No account id found, quitting...");
|
|
1128
1278
|
}
|
|
1129
1279
|
}
|
|
1130
1280
|
}
|
|
@@ -1167,21 +1317,19 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1167
1317
|
},
|
|
1168
1318
|
async (args) => {
|
|
1169
1319
|
if (args.local) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1320
|
+
throw new NotImplementedError(
|
|
1321
|
+
`local mode is not yet supported for this command`
|
|
1322
|
+
);
|
|
1172
1323
|
}
|
|
1173
1324
|
const config = args.config as Config;
|
|
1174
1325
|
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
(args
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
)[args.preview ? "preview_id" : "id"];
|
|
1183
|
-
if (!id) {
|
|
1184
|
-
throw new Error("Are you sure? id not found");
|
|
1326
|
+
let id;
|
|
1327
|
+
try {
|
|
1328
|
+
id = getNamespaceId(args);
|
|
1329
|
+
} catch (e) {
|
|
1330
|
+
throw new CommandLineArgsError(
|
|
1331
|
+
"Not able to delete namespace.\n" + e.message
|
|
1332
|
+
);
|
|
1185
1333
|
}
|
|
1186
1334
|
|
|
1187
1335
|
// -- snip, extract --
|
|
@@ -1197,15 +1345,14 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1197
1345
|
if (!config.account_id) {
|
|
1198
1346
|
config.account_id = await getAccountId();
|
|
1199
1347
|
if (!config.account_id) {
|
|
1200
|
-
|
|
1201
|
-
return;
|
|
1348
|
+
throw new Error("No account id found, quitting...");
|
|
1202
1349
|
}
|
|
1203
1350
|
}
|
|
1204
1351
|
}
|
|
1205
1352
|
|
|
1206
1353
|
// -- snip, end --
|
|
1207
1354
|
|
|
1208
|
-
await
|
|
1355
|
+
await fetchResult<{ id: string }>(
|
|
1209
1356
|
`/accounts/${config.account_id}/storage/kv/namespaces/${id}`,
|
|
1210
1357
|
{ method: "DELETE" }
|
|
1211
1358
|
);
|
|
@@ -1233,13 +1380,13 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1233
1380
|
);
|
|
1234
1381
|
|
|
1235
1382
|
// :key
|
|
1236
|
-
|
|
1383
|
+
wrangler.command(
|
|
1237
1384
|
"kv:key",
|
|
1238
1385
|
"🔑 Individually manage Workers KV key-value pairs",
|
|
1239
|
-
(
|
|
1240
|
-
return
|
|
1386
|
+
(kvKeyYargs) => {
|
|
1387
|
+
return kvKeyYargs
|
|
1241
1388
|
.command(
|
|
1242
|
-
"put <key>
|
|
1389
|
+
"put <key> [value]",
|
|
1243
1390
|
"Writes a single key/value pair to the given namespace.",
|
|
1244
1391
|
(yargs) => {
|
|
1245
1392
|
return yargs
|
|
@@ -1280,7 +1427,8 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1280
1427
|
.option("path", {
|
|
1281
1428
|
type: "string",
|
|
1282
1429
|
describe: "Read value from the file at a given path.",
|
|
1283
|
-
})
|
|
1430
|
+
})
|
|
1431
|
+
.check(demandOneOfOption("value", "path"));
|
|
1284
1432
|
},
|
|
1285
1433
|
async ({ key, ttl, expiration, ...args }) => {
|
|
1286
1434
|
const namespaceId = getNamespaceId(args);
|
|
@@ -1289,7 +1437,16 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1289
1437
|
: args.value;
|
|
1290
1438
|
const config = args.config as Config;
|
|
1291
1439
|
|
|
1292
|
-
|
|
1440
|
+
if (args.path) {
|
|
1441
|
+
console.log(
|
|
1442
|
+
`writing the contents of ${args.path} to the key "${key}" on namespace ${namespaceId}`
|
|
1443
|
+
);
|
|
1444
|
+
} else {
|
|
1445
|
+
console.log(
|
|
1446
|
+
`writing the value "${value}" to key "${key}" on namespace ${namespaceId}`
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1293
1450
|
if (args.local) {
|
|
1294
1451
|
const { Miniflare } = await import("miniflare");
|
|
1295
1452
|
const mf = new Miniflare({
|
|
@@ -1314,8 +1471,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1314
1471
|
if (!config.account_id) {
|
|
1315
1472
|
config.account_id = await getAccountId();
|
|
1316
1473
|
if (!config.account_id) {
|
|
1317
|
-
|
|
1318
|
-
return;
|
|
1474
|
+
throw new Error("No account id found, quitting...");
|
|
1319
1475
|
}
|
|
1320
1476
|
}
|
|
1321
1477
|
}
|
|
@@ -1346,6 +1502,12 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1346
1502
|
type: "string",
|
|
1347
1503
|
describe: "Perform on a specific environment",
|
|
1348
1504
|
})
|
|
1505
|
+
.option("preview", {
|
|
1506
|
+
type: "boolean",
|
|
1507
|
+
// In the case of listing keys we will default to non-preview mode
|
|
1508
|
+
default: false,
|
|
1509
|
+
describe: "Interact with a preview namespace",
|
|
1510
|
+
})
|
|
1349
1511
|
.option("prefix", {
|
|
1350
1512
|
type: "string",
|
|
1351
1513
|
describe: "A prefix to filter listed keys",
|
|
@@ -1383,8 +1545,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1383
1545
|
if (!config.account_id) {
|
|
1384
1546
|
config.account_id = await getAccountId();
|
|
1385
1547
|
if (!config.account_id) {
|
|
1386
|
-
|
|
1387
|
-
return;
|
|
1548
|
+
throw new Error("No account id found, quitting...");
|
|
1388
1549
|
}
|
|
1389
1550
|
}
|
|
1390
1551
|
}
|
|
@@ -1421,6 +1582,12 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1421
1582
|
.option("preview", {
|
|
1422
1583
|
type: "boolean",
|
|
1423
1584
|
describe: "Interact with a preview namespace",
|
|
1585
|
+
})
|
|
1586
|
+
.option("preview", {
|
|
1587
|
+
type: "boolean",
|
|
1588
|
+
// In the case of getting key values we will default to non-preview mode
|
|
1589
|
+
default: false,
|
|
1590
|
+
describe: "Interact with a preview namespace",
|
|
1424
1591
|
});
|
|
1425
1592
|
},
|
|
1426
1593
|
async ({ key, ...args }) => {
|
|
@@ -1452,20 +1619,15 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1452
1619
|
if (!config.account_id) {
|
|
1453
1620
|
config.account_id = await getAccountId();
|
|
1454
1621
|
if (!config.account_id) {
|
|
1455
|
-
|
|
1456
|
-
return;
|
|
1622
|
+
throw new Error("No account id found, quitting...");
|
|
1457
1623
|
}
|
|
1458
1624
|
}
|
|
1459
1625
|
}
|
|
1460
1626
|
|
|
1461
1627
|
// -- snip, end --
|
|
1462
1628
|
|
|
1463
|
-
// annoyingly, the API for this one doesn't return the
|
|
1464
|
-
// data in the 'standard' format. goddamit.
|
|
1465
|
-
// That's why we have the fallthrough response in cfetch.
|
|
1466
|
-
// Oh well.
|
|
1467
1629
|
console.log(
|
|
1468
|
-
await
|
|
1630
|
+
await fetchRaw(
|
|
1469
1631
|
`/accounts/${config.account_id}/storage/kv/namespaces/${namespaceId}/values/${key}`
|
|
1470
1632
|
)
|
|
1471
1633
|
);
|
|
@@ -1501,6 +1663,10 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1501
1663
|
async ({ key, ...args }) => {
|
|
1502
1664
|
const namespaceId = getNamespaceId(args);
|
|
1503
1665
|
|
|
1666
|
+
console.log(
|
|
1667
|
+
`deleting the key "${key}" on namespace ${namespaceId}`
|
|
1668
|
+
);
|
|
1669
|
+
|
|
1504
1670
|
if (args.local) {
|
|
1505
1671
|
const { Miniflare } = await import("miniflare");
|
|
1506
1672
|
const mf = new Miniflare({
|
|
@@ -1528,15 +1694,14 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1528
1694
|
if (!config.account_id) {
|
|
1529
1695
|
config.account_id = await getAccountId();
|
|
1530
1696
|
if (!config.account_id) {
|
|
1531
|
-
|
|
1532
|
-
return;
|
|
1697
|
+
throw new Error("No account id found, quitting...");
|
|
1533
1698
|
}
|
|
1534
1699
|
}
|
|
1535
1700
|
}
|
|
1536
1701
|
|
|
1537
1702
|
// -- snip, end --
|
|
1538
1703
|
|
|
1539
|
-
await
|
|
1704
|
+
await fetchResult(
|
|
1540
1705
|
`/accounts/${config.account_id}/storage/kv/namespaces/${namespaceId}/values/${key}`,
|
|
1541
1706
|
{ method: "DELETE" }
|
|
1542
1707
|
);
|
|
@@ -1546,11 +1711,11 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1546
1711
|
);
|
|
1547
1712
|
|
|
1548
1713
|
// :bulk
|
|
1549
|
-
|
|
1714
|
+
wrangler.command(
|
|
1550
1715
|
"kv:bulk",
|
|
1551
1716
|
"💪 Interact with multiple Workers KV key-value pairs at once",
|
|
1552
|
-
(
|
|
1553
|
-
return
|
|
1717
|
+
(kvBulkYargs) => {
|
|
1718
|
+
return kvBulkYargs
|
|
1554
1719
|
.command(
|
|
1555
1720
|
"put <filename>",
|
|
1556
1721
|
"Upload multiple key-value pairs to a namespace",
|
|
@@ -1590,8 +1755,9 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1590
1755
|
try {
|
|
1591
1756
|
parsedContent = JSON.parse(content);
|
|
1592
1757
|
} catch (err) {
|
|
1593
|
-
|
|
1594
|
-
|
|
1758
|
+
throw new Error(
|
|
1759
|
+
`Could not parse json from ${filename}.\n${err.message ?? err}`
|
|
1760
|
+
);
|
|
1595
1761
|
}
|
|
1596
1762
|
|
|
1597
1763
|
if (args.local) {
|
|
@@ -1630,8 +1796,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1630
1796
|
if (!config.account_id) {
|
|
1631
1797
|
config.account_id = await getAccountId();
|
|
1632
1798
|
if (!config.account_id) {
|
|
1633
|
-
|
|
1634
|
-
return;
|
|
1799
|
+
throw new Error("No account id found, quitting...");
|
|
1635
1800
|
}
|
|
1636
1801
|
}
|
|
1637
1802
|
}
|
|
@@ -1678,8 +1843,9 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1678
1843
|
try {
|
|
1679
1844
|
parsedContent = JSON.parse(content);
|
|
1680
1845
|
} catch (err) {
|
|
1681
|
-
|
|
1682
|
-
|
|
1846
|
+
throw new Error(
|
|
1847
|
+
`Could not parse json from ${filename}.\n${err.message ?? err}`
|
|
1848
|
+
);
|
|
1683
1849
|
}
|
|
1684
1850
|
|
|
1685
1851
|
if (args.local) {
|
|
@@ -1710,8 +1876,7 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1710
1876
|
if (!config.account_id) {
|
|
1711
1877
|
config.account_id = await getAccountId();
|
|
1712
1878
|
if (!config.account_id) {
|
|
1713
|
-
|
|
1714
|
-
return;
|
|
1879
|
+
throw new Error("No account id found, quitting...");
|
|
1715
1880
|
}
|
|
1716
1881
|
}
|
|
1717
1882
|
}
|
|
@@ -1726,10 +1891,11 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1726
1891
|
}
|
|
1727
1892
|
);
|
|
1728
1893
|
|
|
1729
|
-
|
|
1894
|
+
wrangler.command("pages", "⚡️ Configure Cloudflare Pages", pages);
|
|
1730
1895
|
|
|
1731
|
-
|
|
1896
|
+
wrangler
|
|
1732
1897
|
.option("config", {
|
|
1898
|
+
alias: "c",
|
|
1733
1899
|
describe: "Path to .toml configuration file",
|
|
1734
1900
|
type: "string",
|
|
1735
1901
|
async coerce(arg) {
|
|
@@ -1737,18 +1903,27 @@ export async function main(argv: string[]): Promise<void> {
|
|
|
1737
1903
|
},
|
|
1738
1904
|
})
|
|
1739
1905
|
.option("local", {
|
|
1906
|
+
alias: "l",
|
|
1740
1907
|
describe: "Run on my machine",
|
|
1741
1908
|
type: "boolean",
|
|
1742
1909
|
default: false, // I bet this will a point of contention. We'll revisit it.
|
|
1743
1910
|
});
|
|
1744
1911
|
|
|
1745
|
-
|
|
1912
|
+
wrangler.group(["config", "help", "version"], "Flags:");
|
|
1913
|
+
wrangler.help().alias("h", "help");
|
|
1914
|
+
wrangler.version(wranglerVersion).alias("v", "version");
|
|
1915
|
+
wrangler.exitProcess(false);
|
|
1746
1916
|
|
|
1747
1917
|
await initialiseUserConfig();
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1918
|
+
|
|
1919
|
+
try {
|
|
1920
|
+
await wrangler.parse();
|
|
1921
|
+
} catch (e) {
|
|
1922
|
+
if (e instanceof CommandLineArgsError) {
|
|
1923
|
+
wrangler.showHelp("error");
|
|
1924
|
+
console.error(""); // Just adds a bit of space
|
|
1751
1925
|
}
|
|
1752
|
-
|
|
1753
|
-
|
|
1926
|
+
console.error(e.message);
|
|
1927
|
+
throw e;
|
|
1928
|
+
}
|
|
1754
1929
|
}
|