Skip to content

Commit 7f2386e

Browse files
Add option to make newly created resources remote (#10710)
* Add commented out remote bindings to newly created resources * Create silly-toes-swim.md * Make interactive * fix type * Update .changeset/silly-toes-swim.md Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com> * Add CLI prompts * fix lint --------- Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
1 parent 21a0bef commit 7f2386e

File tree

14 files changed

+400
-198
lines changed

14 files changed

+400
-198
lines changed

.changeset/silly-toes-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Add prompt to resource creation flow allowing for newly created resources to be remote.

packages/wrangler/src/__tests__/__snapshots__/kv.test.ts.snap

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To access your new KV Namespace in your Worker, add the following snippet to you
88
{
99
\\"kv_namespaces\\": [
1010
{
11-
\\"binding\\": \\"UnitTestNamespace\\",
11+
\\"binding\\": \\"MY_NS\\",
1212
\\"id\\": \\"some-namespace-id\\"
1313
}
1414
]
@@ -21,7 +21,7 @@ exports[`wrangler > kv namespace > create > wrangler.json > should create a name
2121
\\"name\\": \\"worker\\",
2222
\\"kv_namespaces\\": [
2323
{
24-
\\"binding\\": \\"UnitTestNamespace\\",
24+
\\"binding\\": \\"MY_NS\\",
2525
\\"id\\": \\"some-namespace-id\\"
2626
}
2727
]
@@ -52,8 +52,9 @@ exports[`wrangler > kv namespace > create > wrangler.json > should create a name
5252
\\"name\\": \\"worker\\",
5353
\\"kv_namespaces\\": [
5454
{
55-
\\"binding\\": \\"UnitTestNamespace\\",
56-
\\"id\\": \\"some-namespace-id\\"
55+
\\"binding\\": \\"HELLO\\",
56+
\\"id\\": \\"some-namespace-id\\",
57+
\\"remote\\": true
5758
}
5859
]
5960
}
@@ -70,7 +71,8 @@ To access your new KV Namespace in your Worker, add the following snippet to you
7071
\\"kv_namespaces\\": [
7172
{
7273
\\"binding\\": \\"UnitTestNamespace\\",
73-
\\"id\\": \\"some-namespace-id\\"
74+
\\"id\\": \\"some-namespace-id\\",
75+
\\"remote\\": true
7476
}
7577
]
7678
}"
@@ -82,8 +84,9 @@ exports[`wrangler > kv namespace > create > wrangler.json > should create a name
8284
\\"name\\": \\"other-worker\\",
8385
\\"kv_namespaces\\": [
8486
{
85-
\\"binding\\": \\"UnitTestNamespace\\",
86-
\\"id\\": \\"some-namespace-id\\"
87+
\\"binding\\": \\"HELLO\\",
88+
\\"id\\": \\"some-namespace-id\\",
89+
\\"remote\\": true
8790
}
8891
]
8992
}"
@@ -111,7 +114,8 @@ exports[`wrangler > kv namespace > create > wrangler.json > should create a name
111114
\\"kv_namespaces\\": [
112115
{
113116
\\"binding\\": \\"HELLO\\",
114-
\\"id\\": \\"some-namespace-id\\"
117+
\\"id\\": \\"some-namespace-id\\",
118+
\\"remote\\": true
115119
}
116120
]
117121
}"
@@ -138,7 +142,7 @@ exports[`wrangler > kv namespace > create > wrangler.toml > should create a name
138142
✨ Success!
139143
To access your new KV Namespace in your Worker, add the following snippet to your configuration file:
140144
[[kv_namespaces]]
141-
binding = \\"UnitTestNamespace\\"
145+
binding = \\"MY_NS\\"
142146
id = \\"some-namespace-id\\"
143147
"
144148
`;
@@ -177,6 +181,7 @@ To access your new KV Namespace in your Worker, add the following snippet to you
177181
[[kv_namespaces]]
178182
binding = \\"UnitTestNamespace\\"
179183
id = \\"some-namespace-id\\"
184+
remote = true
180185
"
181186
`;
182187

packages/wrangler/src/__tests__/__snapshots__/r2.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ To access your new R2 Bucket in your Worker, add the following snippet to your c
1313
]
1414
}
1515
? Would you like Wrangler to add it on your behalf?
16-
🤖 Using fallback value in non-interactive context: No"
16+
🤖 Using fallback value in non-interactive context: no"
1717
`;
1818

1919
exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected default storage class 1`] = `
@@ -29,7 +29,7 @@ To access your new R2 Bucket in your Worker, add the following snippet to your c
2929
]
3030
}
3131
? Would you like Wrangler to add it on your behalf?
32-
🤖 Using fallback value in non-interactive context: No"
32+
🤖 Using fallback value in non-interactive context: no"
3333
`;
3434

3535
exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected jurisdiction 1`] = `
@@ -45,7 +45,7 @@ To access your new R2 Bucket in your Worker, add the following snippet to your c
4545
]
4646
}
4747
? Would you like Wrangler to add it on your behalf?
48-
🤖 Using fallback value in non-interactive context: No"
48+
🤖 Using fallback value in non-interactive context: no"
4949
`;
5050

5151
exports[`r2 > bucket > create > wrangler.json > should create a bucket with the expected location hint 1`] = `
@@ -61,7 +61,7 @@ To access your new R2 Bucket in your Worker, add the following snippet to your c
6161
]
6262
}
6363
? Would you like Wrangler to add it on your behalf?
64-
🤖 Using fallback value in non-interactive context: No"
64+
🤖 Using fallback value in non-interactive context: no"
6565
`;
6666

6767
exports[`r2 > bucket > create > wrangler.toml > should create a bucket & check request inputs 1`] = `

packages/wrangler/src/__tests__/d1/create.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("create", () => {
6262
});
6363
})
6464
);
65-
await runWrangler("d1 create test --location oc");
65+
await runWrangler("d1 create test --location oc --binding MY_TEST_DB");
6666
expect(std.out).toMatchInlineSnapshot(`
6767
"✅ Successfully created DB 'test' in region OC
6868
Created your new D1 database.
@@ -71,14 +71,12 @@ describe("create", () => {
7171
{
7272
\\"d1_databases\\": [
7373
{
74-
\\"binding\\": \\"test\\",
74+
\\"binding\\": \\"MY_TEST_DB\\",
7575
\\"database_name\\": \\"test\\",
7676
\\"database_id\\": \\"51e7c314-456e-4167-b6c3-869ad188fc23\\"
7777
}
7878
]
79-
}
80-
? Would you like Wrangler to add it on your behalf?
81-
🤖 Using fallback value in non-interactive context: No"
79+
}"
8280
`);
8381
});
8482
});

packages/wrangler/src/__tests__/kv.test.ts

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import { BATCH_MAX_ERRORS_WARNINGS } from "../kv/helpers";
55
import { endEventLoop } from "./helpers/end-event-loop";
66
import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
77
import { mockConsoleMethods } from "./helpers/mock-console";
8-
import {
9-
clearDialogs,
10-
mockConfirm,
11-
mockPrompt,
12-
mockSelect,
13-
} from "./helpers/mock-dialogs";
8+
import { clearDialogs, mockConfirm, mockPrompt } from "./helpers/mock-dialogs";
149
import { useMockIsTTY } from "./helpers/mock-istty";
1510
import { mockProcess } from "./helpers/mock-process";
1611
import { msw } from "./helpers/msw";
@@ -161,7 +156,10 @@ describe("wrangler", () => {
161156
-v, --version Show version number [boolean]
162157
163158
OPTIONS
164-
--preview Interact with a preview namespace [boolean]"
159+
--preview Interact with a preview namespace [boolean]
160+
--use-remote Use a remote binding when adding the newly created resource to your config [boolean]
161+
--update-config Automatically update your config file with the newly added resource [boolean]
162+
--binding The binding name of this resource in your Worker [string]"
165163
`);
166164
expect(std.err).toMatchInlineSnapshot(`
167165
"X [ERROR] Not enough non-option arguments: got 0, need at least 1
@@ -194,7 +192,10 @@ describe("wrangler", () => {
194192
-v, --version Show version number [boolean]
195193
196194
OPTIONS
197-
--preview Interact with a preview namespace [boolean]"
195+
--preview Interact with a preview namespace [boolean]
196+
--use-remote Use a remote binding when adding the newly created resource to your config [boolean]
197+
--update-config Automatically update your config file with the newly added resource [boolean]
198+
--binding The binding name of this resource in your Worker [string]"
198199
`);
199200
expect(std.err).toMatchInlineSnapshot(`
200201
"X [ERROR] Unknown arguments: def, ghi
@@ -207,13 +208,10 @@ describe("wrangler", () => {
207208
it("should create a namespace", async () => {
208209
writeWranglerConfig({ name: "worker" }, configPath);
209210
mockCreateRequest("UnitTestNamespace");
210-
if (configPath === "wrangler.json") {
211-
mockSelect({
212-
text: "Would you like Wrangler to add it on your behalf?",
213-
result: "yes",
214-
});
215-
}
216-
await runWrangler("kv namespace create UnitTestNamespace");
211+
212+
await runWrangler(
213+
"kv namespace create UnitTestNamespace --binding MY_NS"
214+
);
217215
expect(std.out).toMatchSnapshot();
218216
expect(await readFile(configPath, "utf8")).toMatchSnapshot();
219217
});
@@ -222,14 +220,18 @@ describe("wrangler", () => {
222220
writeWranglerConfig({ name: "worker" }, configPath);
223221
mockCreateRequest("UnitTestNamespace");
224222
if (configPath === "wrangler.json") {
225-
mockSelect({
223+
mockConfirm({
226224
text: "Would you like Wrangler to add it on your behalf?",
227-
result: "yes-but",
225+
result: true,
228226
});
229227
mockPrompt({
230228
text: "What binding name would you like to use?",
231229
result: "HELLO",
232230
});
231+
mockConfirm({
232+
text: "For local dev, do you want to connect to the remote resource instead of a local resource?",
233+
result: true,
234+
});
233235
}
234236
await runWrangler("kv namespace create UnitTestNamespace");
235237
expect(std.out).toMatchSnapshot();
@@ -249,12 +251,18 @@ describe("wrangler", () => {
249251

250252
mockCreateRequest("UnitTestNamespace");
251253
if (configPath === "wrangler.json") {
252-
mockSelect({
254+
mockConfirm({
253255
text: "Would you like Wrangler to add it on your behalf?",
254-
result: "yes",
256+
result: true,
257+
});
258+
mockPrompt({
259+
text: "What binding name would you like to use?",
260+
result: "HELLO",
255261
});
256262
}
257-
await runWrangler("kv namespace create UnitTestNamespace");
263+
await runWrangler(
264+
"kv namespace create UnitTestNamespace --use-remote"
265+
);
258266
expect(std.out).toMatchSnapshot();
259267
expect(await readFile(configPath, "utf8")).toMatchSnapshot();
260268
});
@@ -274,9 +282,17 @@ describe("wrangler", () => {
274282

275283
mockCreateRequest("customEnv-UnitTestNamespace");
276284
if (configPath === "wrangler.json") {
277-
mockSelect({
285+
mockConfirm({
278286
text: "Would you like Wrangler to add it on your behalf?",
279-
result: "yes",
287+
result: true,
288+
});
289+
mockPrompt({
290+
text: "What binding name would you like to use?",
291+
result: "HELLO",
292+
});
293+
mockConfirm({
294+
text: "For local dev, do you want to connect to the remote resource instead of a local resource?",
295+
result: true,
280296
});
281297
}
282298
await runWrangler(

packages/wrangler/src/__tests__/r2.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ describe("r2", () => {
331331
OPTIONS
332332
--location The optional location hint that determines geographic placement of the R2 bucket [string] [choices: \\"weur\\", \\"eeur\\", \\"apac\\", \\"wnam\\", \\"enam\\", \\"oc\\"]
333333
-s, --storage-class The default storage class for objects uploaded to this bucket [string]
334-
-J, --jurisdiction The jurisdiction where the new bucket will be created [string]"
334+
-J, --jurisdiction The jurisdiction where the new bucket will be created [string]
335+
--use-remote Use a remote binding when adding the newly created resource to your config [boolean]
336+
--update-config Automatically update your config file with the newly added resource [boolean]
337+
--binding The binding name of this resource in your Worker [string]"
335338
`);
336339
expect(std.err).toMatchInlineSnapshot(`
337340
"X [ERROR] Not enough non-option arguments: got 0, need at least 1
@@ -366,7 +369,10 @@ describe("r2", () => {
366369
OPTIONS
367370
--location The optional location hint that determines geographic placement of the R2 bucket [string] [choices: \\"weur\\", \\"eeur\\", \\"apac\\", \\"wnam\\", \\"enam\\", \\"oc\\"]
368371
-s, --storage-class The default storage class for objects uploaded to this bucket [string]
369-
-J, --jurisdiction The jurisdiction where the new bucket will be created [string]"
372+
-J, --jurisdiction The jurisdiction where the new bucket will be created [string]
373+
--use-remote Use a remote binding when adding the newly created resource to your config [boolean]
374+
--update-config Automatically update your config file with the newly added resource [boolean]
375+
--binding The binding name of this resource in your Worker [string]"
370376
`);
371377
expect(std.err).toMatchInlineSnapshot(`
372378
"X [ERROR] Unknown arguments: def, ghi

0 commit comments

Comments
 (0)