wrangler 0.0.0-e3cab74 → 0.0.0-e3ce82b
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/Cloudflare_CA.pem +18 -0
- package/README.md +27 -14
- package/bin/wrangler.js +49 -5
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +43 -28
- package/pages/functions/buildPlugin.ts +105 -0
- package/pages/functions/buildWorker.ts +93 -4
- package/pages/functions/filepath-routing.test.ts +136 -25
- package/pages/functions/filepath-routing.ts +14 -3
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +147 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +1713 -411
- package/src/__tests__/dev.test.tsx +954 -84
- package/src/__tests__/guess-worker-format.test.ts +37 -18
- package/src/__tests__/helpers/mock-account-id.ts +22 -4
- package/src/__tests__/helpers/mock-cfetch.ts +8 -4
- package/src/__tests__/helpers/mock-console.ts +35 -10
- package/src/__tests__/helpers/mock-dialogs.ts +67 -2
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +130 -0
- package/src/__tests__/index.test.ts +138 -747
- package/src/__tests__/init.test.ts +1637 -0
- package/src/__tests__/jest.setup.ts +28 -8
- package/src/__tests__/kv.test.ts +598 -258
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/package-manager.test.ts +154 -7
- package/src/__tests__/pages.test.ts +754 -0
- package/src/__tests__/parse.test.ts +8 -0
- package/src/__tests__/publish.test.ts +4374 -1025
- package/src/__tests__/r2.test.ts +69 -34
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +228 -73
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +60 -7
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +75 -11
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +29 -20
- package/src/cli.ts +5 -11
- package/src/config/README.md +7 -7
- package/src/config/config.ts +69 -100
- package/src/config/environment.ts +119 -4
- package/src/config/index.ts +177 -4
- package/src/config/validation-helpers.ts +237 -23
- package/src/config/validation.ts +722 -191
- package/src/config-cache.ts +45 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +65 -27
- package/src/{api/form_data.ts → create-worker-upload-form.ts} +55 -18
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +401 -0
- package/src/dev/local.tsx +322 -0
- package/src/dev/remote.tsx +237 -0
- package/src/dev/use-esbuild.ts +118 -0
- package/src/dialogs.tsx +64 -6
- package/src/durable.ts +102 -0
- package/src/entry.ts +279 -14
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +123 -0
- package/src/index.tsx +1386 -867
- package/src/inspect.ts +64 -11
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +195 -62
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +94 -6
- package/src/open-in-browser.ts +9 -3
- package/src/package-manager.ts +59 -11
- package/src/pages.tsx +1123 -75
- package/src/parse.ts +26 -6
- package/src/proxy.ts +159 -57
- package/src/publish.ts +581 -228
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +130 -45
- package/src/tail/index.ts +2 -2
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +275 -110
- package/src/whoami.tsx +5 -3
- package/src/{api/worker.ts → worker.ts} +24 -29
- package/src/zones.ts +73 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.ts +16 -1
- package/templates/static-asset-facade.js +1 -5
- package/wrangler-dist/cli.js +104803 -118375
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/dev.tsx +0 -961
- package/src/guess-worker-format.ts +0 -68
- package/src/reporting.ts +0 -115
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as fsp from "node:fs/promises";
|
|
3
|
-
import * as TOML from "@iarna/toml";
|
|
4
|
-
import { parseConfigFileTextToJson } from "typescript";
|
|
5
|
-
import { version as wranglerVersion } from "../../package.json";
|
|
6
1
|
import { getPackageManager } from "../package-manager";
|
|
7
2
|
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
8
|
-
import { mockConfirm } from "./helpers/mock-dialogs";
|
|
9
3
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
10
4
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
5
|
+
import { writeWorkerSource } from "./helpers/write-worker-source";
|
|
6
|
+
import writeWranglerToml from "./helpers/write-wrangler-toml";
|
|
11
7
|
import type { PackageManager } from "../package-manager";
|
|
12
8
|
|
|
13
9
|
describe("wrangler", () => {
|
|
@@ -36,7 +32,6 @@ describe("wrangler", () => {
|
|
|
36
32
|
|
|
37
33
|
Commands:
|
|
38
34
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
39
|
-
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
40
35
|
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
41
36
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
42
37
|
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
@@ -46,12 +41,14 @@ describe("wrangler", () => {
|
|
|
46
41
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
47
42
|
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
48
43
|
wrangler r2 📦 Interact with an R2 store
|
|
44
|
+
wrangler login 🔓 Login to Cloudflare
|
|
45
|
+
wrangler logout 🚪 Logout from Cloudflare
|
|
46
|
+
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
49
47
|
|
|
50
48
|
Flags:
|
|
51
|
-
-c, --config
|
|
52
|
-
-h, --help
|
|
53
|
-
-v, --version
|
|
54
|
-
--legacy-env Use legacy environments [boolean]"
|
|
49
|
+
-c, --config Path to .toml configuration file [string]
|
|
50
|
+
-h, --help Show help [boolean]
|
|
51
|
+
-v, --version Show version number [boolean]"
|
|
55
52
|
`);
|
|
56
53
|
|
|
57
54
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
@@ -63,16 +60,15 @@ describe("wrangler", () => {
|
|
|
63
60
|
await expect(
|
|
64
61
|
runWrangler("invalid-command")
|
|
65
62
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
66
|
-
`"Unknown
|
|
63
|
+
`"Unknown argument: invalid-command"`
|
|
67
64
|
);
|
|
68
65
|
|
|
69
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
67
|
+
"
|
|
68
|
+
wrangler
|
|
72
69
|
|
|
73
70
|
Commands:
|
|
74
71
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
75
|
-
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
76
72
|
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
77
73
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
78
74
|
wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
|
|
@@ -82,785 +78,180 @@ describe("wrangler", () => {
|
|
|
82
78
|
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
|
|
83
79
|
wrangler pages ⚡️ Configure Cloudflare Pages
|
|
84
80
|
wrangler r2 📦 Interact with an R2 store
|
|
81
|
+
wrangler login 🔓 Login to Cloudflare
|
|
82
|
+
wrangler logout 🚪 Logout from Cloudflare
|
|
83
|
+
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
85
84
|
|
|
86
85
|
Flags:
|
|
87
|
-
-c, --config
|
|
88
|
-
-h, --help
|
|
89
|
-
-v, --version
|
|
90
|
-
|
|
86
|
+
-c, --config Path to .toml configuration file [string]
|
|
87
|
+
-h, --help Show help [boolean]
|
|
88
|
+
-v, --version Show version number [boolean]"
|
|
89
|
+
`);
|
|
90
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
91
|
+
"[31mX [41;31m[[41;97mERROR[41;31m][0m [1mUnknown argument: invalid-command[0m
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
"
|
|
93
94
|
`);
|
|
94
95
|
});
|
|
95
96
|
});
|
|
96
97
|
|
|
97
|
-
describe("
|
|
98
|
-
it("should
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
expect(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
text: "No package.json found. Would you like to create one?",
|
|
114
|
-
result: false,
|
|
115
|
-
});
|
|
116
|
-
await runWrangler("init my-worker");
|
|
117
|
-
const parsed = TOML.parse(
|
|
118
|
-
await fsp.readFile("./my-worker/wrangler.toml", "utf-8")
|
|
119
|
-
);
|
|
120
|
-
expect(typeof parsed.compatibility_date).toBe("string");
|
|
121
|
-
expect(parsed.name).toBe("my-worker");
|
|
122
|
-
expect(fs.existsSync("./my-worker/package.json")).toBe(false);
|
|
123
|
-
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
|
|
127
|
-
fs.writeFileSync(
|
|
128
|
-
"./wrangler.toml",
|
|
129
|
-
'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
|
|
130
|
-
"utf-8"
|
|
131
|
-
);
|
|
132
|
-
mockConfirm({
|
|
133
|
-
text: "Do you want to continue initializing this project?",
|
|
134
|
-
result: false,
|
|
135
|
-
});
|
|
136
|
-
await runWrangler("init");
|
|
137
|
-
expect(std.warn).toContain("wrangler.toml file already exists!");
|
|
138
|
-
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
139
|
-
expect(parsed.compatibility_date).toBe("something-else");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should not overwrite an existing wrangler.toml, after agreeing to other prompts", async () => {
|
|
143
|
-
fs.writeFileSync(
|
|
144
|
-
"./wrangler.toml",
|
|
145
|
-
'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
|
|
146
|
-
"utf-8"
|
|
147
|
-
);
|
|
148
|
-
mockConfirm(
|
|
149
|
-
{
|
|
150
|
-
text: "Do you want to continue initializing this project?",
|
|
151
|
-
result: true,
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
text: "No package.json found. Would you like to create one?",
|
|
155
|
-
result: true,
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
text: "Would you like to use TypeScript?",
|
|
159
|
-
result: true,
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
163
|
-
result: true,
|
|
164
|
-
}
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
await runWrangler("init");
|
|
168
|
-
expect(fs.readFileSync("./wrangler.toml", "utf-8")).toMatchInlineSnapshot(
|
|
169
|
-
`"compatibility_date=\\"something-else\\""`
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
|
|
174
|
-
fs.writeFileSync(
|
|
175
|
-
"./wrangler.toml",
|
|
176
|
-
`compatibility_date="something-else"`,
|
|
177
|
-
"utf-8"
|
|
178
|
-
);
|
|
179
|
-
mockConfirm(
|
|
180
|
-
{
|
|
181
|
-
text: "Do you want to continue initializing this project?",
|
|
182
|
-
result: true,
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
text: "No package.json found. Would you like to create one?",
|
|
186
|
-
result: false,
|
|
187
|
-
}
|
|
188
|
-
);
|
|
189
|
-
await runWrangler("init");
|
|
190
|
-
expect(std.warn).toContain("wrangler.toml file already exists!");
|
|
191
|
-
const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
|
|
192
|
-
expect(parsed.compatibility_date).toBe("something-else");
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("should create a package.json if none is found and user confirms", async () => {
|
|
196
|
-
mockConfirm(
|
|
197
|
-
{
|
|
198
|
-
text: "No package.json found. Would you like to create one?",
|
|
199
|
-
result: true,
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
text: "Would you like to use TypeScript?",
|
|
203
|
-
result: false,
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
207
|
-
result: false,
|
|
208
|
-
}
|
|
209
|
-
);
|
|
210
|
-
await runWrangler("init");
|
|
211
|
-
expect(fs.existsSync("./package.json")).toBe(true);
|
|
212
|
-
const packageJson = JSON.parse(
|
|
213
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
214
|
-
);
|
|
215
|
-
expect(packageJson.name).toContain("wrangler-tests");
|
|
216
|
-
expect(packageJson.version).toEqual("0.0.0");
|
|
217
|
-
expect(packageJson.devDependencies).toEqual({
|
|
218
|
-
wrangler: expect.any(String),
|
|
219
|
-
});
|
|
220
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(false);
|
|
221
|
-
expect(mockPackageManager.install).toHaveBeenCalled();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it("should create a package.json, with the specified name, if none is found and user confirms", async () => {
|
|
225
|
-
mockConfirm(
|
|
226
|
-
{
|
|
227
|
-
text: "No package.json found. Would you like to create one?",
|
|
228
|
-
result: true,
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
text: "Would you like to use TypeScript?",
|
|
232
|
-
result: false,
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
236
|
-
result: false,
|
|
237
|
-
}
|
|
238
|
-
);
|
|
239
|
-
await runWrangler("init my-worker");
|
|
240
|
-
const packageJson = JSON.parse(
|
|
241
|
-
fs.readFileSync("./my-worker/package.json", "utf-8")
|
|
242
|
-
);
|
|
243
|
-
expect(packageJson.name).toBe("my-worker");
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("should not touch an existing package.json in the same directory", async () => {
|
|
247
|
-
mockConfirm(
|
|
248
|
-
{
|
|
249
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
250
|
-
result: false,
|
|
251
|
-
},
|
|
252
|
-
{
|
|
253
|
-
text: "Would you like to use TypeScript?",
|
|
254
|
-
result: false,
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
258
|
-
result: false,
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
fs.writeFileSync(
|
|
263
|
-
"./package.json",
|
|
264
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
265
|
-
"utf-8"
|
|
266
|
-
);
|
|
267
|
-
|
|
268
|
-
await runWrangler("init");
|
|
269
|
-
const packageJson = JSON.parse(
|
|
270
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
271
|
-
);
|
|
272
|
-
expect(packageJson.name).toEqual("test");
|
|
273
|
-
expect(packageJson.version).toEqual("1.0.0");
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("should offer to install wrangler into an existing package.json", async () => {
|
|
277
|
-
mockConfirm(
|
|
278
|
-
{
|
|
279
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
280
|
-
result: true,
|
|
281
|
-
},
|
|
282
|
-
{
|
|
283
|
-
text: "Would you like to use TypeScript?",
|
|
284
|
-
result: false,
|
|
285
|
-
},
|
|
286
|
-
{
|
|
287
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
288
|
-
result: false,
|
|
289
|
-
}
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
fs.writeFileSync(
|
|
293
|
-
"./package.json",
|
|
294
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
295
|
-
"utf-8"
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
await runWrangler("init");
|
|
299
|
-
const packageJson = JSON.parse(
|
|
300
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
301
|
-
);
|
|
302
|
-
expect(packageJson.name).toEqual("test");
|
|
303
|
-
expect(packageJson.version).toEqual("1.0.0");
|
|
304
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
305
|
-
`wrangler@${wranglerVersion}`
|
|
306
|
-
);
|
|
98
|
+
describe("preview", () => {
|
|
99
|
+
it("should throw an error if the deprecated command is used with positional arguments", async () => {
|
|
100
|
+
await expect(runWrangler("preview GET")).rejects
|
|
101
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
102
|
+
"Deprecation:
|
|
103
|
+
The \`wrangler preview\` command has been deprecated.
|
|
104
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
105
|
+
"
|
|
106
|
+
`);
|
|
107
|
+
await expect(runWrangler(`preview GET "SomeBody"`)).rejects
|
|
108
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
109
|
+
"Deprecation:
|
|
110
|
+
The \`wrangler preview\` command has been deprecated.
|
|
111
|
+
Try using \`wrangler dev\` to to try out a worker during development.
|
|
112
|
+
"
|
|
113
|
+
`);
|
|
307
114
|
});
|
|
115
|
+
});
|
|
308
116
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
{
|
|
316
|
-
text: "Would you like to use TypeScript?",
|
|
317
|
-
result: false,
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
321
|
-
result: false,
|
|
322
|
-
}
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
fs.writeFileSync(
|
|
326
|
-
"./package.json",
|
|
327
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
328
|
-
"utf-8"
|
|
329
|
-
);
|
|
117
|
+
describe("subcommand implicit help ran on incomplete command execution", () => {
|
|
118
|
+
it("no subcommand for 'secret' should display a list of available subcommands", async () => {
|
|
119
|
+
await runWrangler("secret");
|
|
120
|
+
await endEventLoop();
|
|
121
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
122
|
+
"wrangler secret
|
|
330
123
|
|
|
331
|
-
|
|
332
|
-
process.chdir("./sub-1/sub-2");
|
|
124
|
+
🤫 Generate a secret that can be referenced in the worker script
|
|
333
125
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
126
|
+
Commands:
|
|
127
|
+
wrangler secret put <key> Create or update a secret variable for a script
|
|
128
|
+
wrangler secret delete <key> Delete a secret variable from a script
|
|
129
|
+
wrangler secret list List all secrets for a script
|
|
337
130
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
Object {
|
|
343
|
-
"name": "test",
|
|
344
|
-
"version": "1.0.0",
|
|
345
|
-
}
|
|
131
|
+
Flags:
|
|
132
|
+
-c, --config Path to .toml configuration file [string]
|
|
133
|
+
-h, --help Show help [boolean]
|
|
134
|
+
-v, --version Show version number [boolean]"
|
|
346
135
|
`);
|
|
347
136
|
});
|
|
348
137
|
|
|
349
|
-
it("
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
353
|
-
result: false,
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
text: "Would you like to use TypeScript?",
|
|
357
|
-
result: false,
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
361
|
-
result: true,
|
|
362
|
-
}
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
fs.writeFileSync(
|
|
366
|
-
"./package.json",
|
|
367
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
368
|
-
"utf-8"
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
await runWrangler("init");
|
|
372
|
-
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
373
|
-
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
it("should offer to create a worker in a typescript project", async () => {
|
|
377
|
-
mockConfirm(
|
|
378
|
-
{
|
|
379
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
380
|
-
result: false,
|
|
381
|
-
},
|
|
382
|
-
{
|
|
383
|
-
text: "Would you like to use TypeScript?",
|
|
384
|
-
result: true,
|
|
385
|
-
},
|
|
386
|
-
{
|
|
387
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
388
|
-
result: true,
|
|
389
|
-
}
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
fs.writeFileSync(
|
|
393
|
-
"./package.json",
|
|
394
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
395
|
-
"utf-8"
|
|
396
|
-
);
|
|
397
|
-
|
|
398
|
-
await runWrangler("init");
|
|
399
|
-
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
400
|
-
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
it("should add scripts for a typescript project with .ts extension", async () => {
|
|
404
|
-
mockConfirm(
|
|
405
|
-
{
|
|
406
|
-
text: "No package.json found. Would you like to create one?",
|
|
407
|
-
result: true,
|
|
408
|
-
},
|
|
409
|
-
{
|
|
410
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
411
|
-
result: false,
|
|
412
|
-
},
|
|
413
|
-
{
|
|
414
|
-
text: "Would you like to use TypeScript?",
|
|
415
|
-
result: true,
|
|
416
|
-
},
|
|
417
|
-
{
|
|
418
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
419
|
-
result: true,
|
|
420
|
-
}
|
|
421
|
-
);
|
|
422
|
-
await runWrangler("init");
|
|
423
|
-
|
|
424
|
-
expect(fs.existsSync("./package.json")).toBe(true);
|
|
425
|
-
const packageJson = JSON.parse(
|
|
426
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
427
|
-
);
|
|
428
|
-
|
|
429
|
-
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
430
|
-
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
431
|
-
|
|
432
|
-
expect(packageJson.scripts.start).toBe("wrangler dev");
|
|
433
|
-
expect(packageJson.scripts.publish).toBe("wrangler publish");
|
|
434
|
-
expect(packageJson.name).toContain("wrangler-tests");
|
|
435
|
-
expect(packageJson.version).toEqual("0.0.0");
|
|
138
|
+
it("no subcommand 'kv:namespace' should display a list of available subcommands", async () => {
|
|
139
|
+
await runWrangler("kv:namespace");
|
|
140
|
+
await endEventLoop();
|
|
436
141
|
expect(std.out).toMatchInlineSnapshot(`
|
|
437
|
-
"
|
|
438
|
-
✨ Created package.json
|
|
439
|
-
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
440
|
-
✨ Created src/index.ts
|
|
441
|
-
|
|
442
|
-
To start developing your Worker, run \`npm start\`
|
|
443
|
-
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
444
|
-
`);
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
it("should not overwrite package.json scripts for a typescript project", async () => {
|
|
448
|
-
mockConfirm(
|
|
449
|
-
{
|
|
450
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
451
|
-
result: false,
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
text: "Would you like to use TypeScript?",
|
|
455
|
-
result: true,
|
|
456
|
-
},
|
|
457
|
-
{
|
|
458
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
459
|
-
result: true,
|
|
460
|
-
}
|
|
461
|
-
);
|
|
462
|
-
await fsp.writeFile(
|
|
463
|
-
"./package.json",
|
|
464
|
-
JSON.stringify({
|
|
465
|
-
scripts: {
|
|
466
|
-
start: "test-start",
|
|
467
|
-
publish: "test-publish",
|
|
468
|
-
},
|
|
469
|
-
})
|
|
470
|
-
);
|
|
471
|
-
const packageJson = JSON.parse(
|
|
472
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
473
|
-
);
|
|
474
|
-
await runWrangler("init");
|
|
142
|
+
"wrangler kv:namespace
|
|
475
143
|
|
|
476
|
-
|
|
477
|
-
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
144
|
+
🗂️ Interact with your Workers KV Namespaces
|
|
478
145
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
484
|
-
✨ Created src/index.ts
|
|
146
|
+
Commands:
|
|
147
|
+
wrangler kv:namespace create <namespace> Create a new namespace
|
|
148
|
+
wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
|
|
149
|
+
wrangler kv:namespace delete Deletes a given namespace.
|
|
485
150
|
|
|
486
|
-
|
|
487
|
-
|
|
151
|
+
Flags:
|
|
152
|
+
-c, --config Path to .toml configuration file [string]
|
|
153
|
+
-h, --help Show help [boolean]
|
|
154
|
+
-v, --version Show version number [boolean]"
|
|
488
155
|
`);
|
|
489
156
|
});
|
|
490
157
|
|
|
491
|
-
it("
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
text: "No package.json found. Would you like to create one?",
|
|
495
|
-
result: true,
|
|
496
|
-
},
|
|
497
|
-
{
|
|
498
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
499
|
-
result: false,
|
|
500
|
-
},
|
|
501
|
-
{
|
|
502
|
-
text: "Would you like to use TypeScript?",
|
|
503
|
-
result: false,
|
|
504
|
-
},
|
|
505
|
-
{
|
|
506
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
507
|
-
result: true,
|
|
508
|
-
}
|
|
509
|
-
);
|
|
510
|
-
await runWrangler("init");
|
|
511
|
-
|
|
512
|
-
expect(fs.existsSync("./package.json")).toBe(true);
|
|
513
|
-
const packageJson = JSON.parse(
|
|
514
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
515
|
-
);
|
|
516
|
-
|
|
517
|
-
expect(fs.existsSync("./src/index.js")).toBe(true);
|
|
518
|
-
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
519
|
-
|
|
520
|
-
expect(packageJson.scripts.start).toBe("wrangler dev");
|
|
521
|
-
expect(packageJson.scripts.publish).toBe("wrangler publish");
|
|
522
|
-
expect(packageJson.name).toContain("wrangler-tests");
|
|
523
|
-
expect(packageJson.version).toEqual("0.0.0");
|
|
158
|
+
it("no subcommand 'kv:key' should display a list of available subcommands", async () => {
|
|
159
|
+
await runWrangler("kv:key");
|
|
160
|
+
await endEventLoop();
|
|
524
161
|
expect(std.out).toMatchInlineSnapshot(`
|
|
525
|
-
"
|
|
526
|
-
✨ Created package.json
|
|
527
|
-
✨ Created src/index.js
|
|
162
|
+
"wrangler kv:key
|
|
528
163
|
|
|
529
|
-
|
|
530
|
-
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
531
|
-
`);
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
it("should not overwrite package.json scripts for a non-ts project with .js extension", async () => {
|
|
535
|
-
mockConfirm(
|
|
536
|
-
{
|
|
537
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
538
|
-
result: false,
|
|
539
|
-
},
|
|
540
|
-
{
|
|
541
|
-
text: "Would you like to use TypeScript?",
|
|
542
|
-
result: false,
|
|
543
|
-
},
|
|
544
|
-
{
|
|
545
|
-
text: "Would you like to create a Worker at src/index.js?",
|
|
546
|
-
result: true,
|
|
547
|
-
}
|
|
548
|
-
);
|
|
549
|
-
await fsp.writeFile(
|
|
550
|
-
"./package.json",
|
|
551
|
-
JSON.stringify({
|
|
552
|
-
scripts: {
|
|
553
|
-
start: "test-start",
|
|
554
|
-
publish: "test-publish",
|
|
555
|
-
},
|
|
556
|
-
})
|
|
557
|
-
);
|
|
558
|
-
const packageJson = JSON.parse(
|
|
559
|
-
fs.readFileSync("./package.json", "utf-8")
|
|
560
|
-
);
|
|
561
|
-
await runWrangler("init");
|
|
164
|
+
🔑 Individually manage Workers KV key-value pairs
|
|
562
165
|
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
569
|
-
"✨ Successfully created wrangler.toml
|
|
570
|
-
✨ Created src/index.js
|
|
166
|
+
Commands:
|
|
167
|
+
wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
|
|
168
|
+
wrangler kv:key list Outputs a list of all keys in a given namespace.
|
|
169
|
+
wrangler kv:key get <key> Reads a single value by key from the given namespace.
|
|
170
|
+
wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
|
|
571
171
|
|
|
572
|
-
|
|
573
|
-
|
|
172
|
+
Flags:
|
|
173
|
+
-c, --config Path to .toml configuration file [string]
|
|
174
|
+
-h, --help Show help [boolean]
|
|
175
|
+
-v, --version Show version number [boolean]"
|
|
574
176
|
`);
|
|
575
177
|
});
|
|
576
178
|
|
|
577
|
-
it("
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
},
|
|
583
|
-
{
|
|
584
|
-
text: "Would you like to use TypeScript?",
|
|
585
|
-
result: false,
|
|
586
|
-
}
|
|
587
|
-
);
|
|
588
|
-
|
|
589
|
-
fs.writeFileSync(
|
|
590
|
-
"./package.json",
|
|
591
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
592
|
-
"utf-8"
|
|
593
|
-
);
|
|
594
|
-
fs.mkdirSync("./src", { recursive: true });
|
|
595
|
-
const PLACEHOLDER = "/* placeholder text */";
|
|
596
|
-
fs.writeFileSync("./src/index.js", PLACEHOLDER, "utf-8");
|
|
597
|
-
|
|
598
|
-
await runWrangler("init");
|
|
599
|
-
expect(fs.readFileSync("./src/index.js", "utf-8")).toBe(PLACEHOLDER);
|
|
600
|
-
expect(fs.existsSync("./src/index.ts")).toBe(false);
|
|
601
|
-
});
|
|
602
|
-
|
|
603
|
-
it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
|
|
604
|
-
mockConfirm(
|
|
605
|
-
{
|
|
606
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
607
|
-
result: false,
|
|
608
|
-
},
|
|
609
|
-
{
|
|
610
|
-
text: "Would you like to use TypeScript?",
|
|
611
|
-
result: true,
|
|
612
|
-
}
|
|
613
|
-
);
|
|
614
|
-
|
|
615
|
-
fs.writeFileSync(
|
|
616
|
-
"./package.json",
|
|
617
|
-
JSON.stringify({ name: "test", version: "1.0.0" }),
|
|
618
|
-
"utf-8"
|
|
619
|
-
);
|
|
620
|
-
fs.mkdirSync("./src", { recursive: true });
|
|
621
|
-
const PLACEHOLDER = "/* placeholder text */";
|
|
622
|
-
fs.writeFileSync("./src/index.ts", PLACEHOLDER, "utf-8");
|
|
623
|
-
|
|
624
|
-
await runWrangler("init");
|
|
625
|
-
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
626
|
-
expect(fs.readFileSync("./src/index.ts", "utf-8")).toBe(PLACEHOLDER);
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
|
|
630
|
-
mockConfirm(
|
|
631
|
-
{
|
|
632
|
-
text: "No package.json found. Would you like to create one?",
|
|
633
|
-
result: true,
|
|
634
|
-
},
|
|
635
|
-
{
|
|
636
|
-
text: "Would you like to use TypeScript?",
|
|
637
|
-
result: true,
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
641
|
-
result: false,
|
|
642
|
-
}
|
|
643
|
-
);
|
|
644
|
-
await runWrangler("init");
|
|
645
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
646
|
-
const { config: tsconfigJson, error: tsConfigParseError } =
|
|
647
|
-
parseConfigFileTextToJson(
|
|
648
|
-
"./tsconfig.json",
|
|
649
|
-
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
650
|
-
);
|
|
651
|
-
expect(tsConfigParseError).toBeUndefined();
|
|
652
|
-
expect(tsconfigJson.compilerOptions.types).toEqual([
|
|
653
|
-
"@cloudflare/workers-types",
|
|
654
|
-
]);
|
|
655
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
656
|
-
"@cloudflare/workers-types",
|
|
657
|
-
"typescript"
|
|
658
|
-
);
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
it("should not touch an existing tsconfig.json in the same directory", async () => {
|
|
662
|
-
fs.writeFileSync(
|
|
663
|
-
"./package.json",
|
|
664
|
-
JSON.stringify({
|
|
665
|
-
name: "test",
|
|
666
|
-
version: "1.0.0",
|
|
667
|
-
devDependencies: {
|
|
668
|
-
wrangler: "0.0.0",
|
|
669
|
-
"@cloudflare/workers-types": "0.0.0",
|
|
670
|
-
},
|
|
671
|
-
}),
|
|
672
|
-
"utf-8"
|
|
673
|
-
);
|
|
674
|
-
fs.writeFileSync(
|
|
675
|
-
"./tsconfig.json",
|
|
676
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
677
|
-
"utf-8"
|
|
678
|
-
);
|
|
679
|
-
|
|
680
|
-
await runWrangler("init");
|
|
681
|
-
const tsconfigJson = JSON.parse(
|
|
682
|
-
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
683
|
-
);
|
|
684
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
685
|
-
});
|
|
686
|
-
|
|
687
|
-
it("should offer to install type definitions in an existing typescript project", async () => {
|
|
688
|
-
mockConfirm(
|
|
689
|
-
{
|
|
690
|
-
text: "Would you like to install wrangler into your package.json?",
|
|
691
|
-
result: false,
|
|
692
|
-
},
|
|
693
|
-
{
|
|
694
|
-
text: "Would you like to install the type definitions for Workers into your package.json?",
|
|
695
|
-
result: true,
|
|
696
|
-
},
|
|
697
|
-
{
|
|
698
|
-
text: "Would you like to create a Worker at src/index.ts?",
|
|
699
|
-
result: false,
|
|
700
|
-
}
|
|
701
|
-
);
|
|
702
|
-
fs.writeFileSync(
|
|
703
|
-
"./package.json",
|
|
704
|
-
JSON.stringify({
|
|
705
|
-
name: "test",
|
|
706
|
-
version: "1.0.0",
|
|
707
|
-
}),
|
|
708
|
-
"utf-8"
|
|
709
|
-
);
|
|
710
|
-
fs.writeFileSync(
|
|
711
|
-
"./tsconfig.json",
|
|
712
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
713
|
-
"utf-8"
|
|
714
|
-
);
|
|
715
|
-
|
|
716
|
-
await runWrangler("init");
|
|
717
|
-
const tsconfigJson = JSON.parse(
|
|
718
|
-
fs.readFileSync("./tsconfig.json", "utf-8")
|
|
719
|
-
);
|
|
720
|
-
// unchanged tsconfig
|
|
721
|
-
expect(tsconfigJson.compilerOptions).toEqual({});
|
|
722
|
-
expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
|
|
723
|
-
"@cloudflare/workers-types"
|
|
724
|
-
);
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
|
|
728
|
-
fs.writeFileSync(
|
|
729
|
-
"./package.json",
|
|
730
|
-
JSON.stringify({
|
|
731
|
-
name: "test",
|
|
732
|
-
version: "1.0.0",
|
|
733
|
-
devDependencies: {
|
|
734
|
-
wrangler: "0.0.0",
|
|
735
|
-
"@cloudflare/workers-types": "0.0.0",
|
|
736
|
-
},
|
|
737
|
-
}),
|
|
738
|
-
"utf-8"
|
|
739
|
-
);
|
|
740
|
-
fs.writeFileSync(
|
|
741
|
-
"./tsconfig.json",
|
|
742
|
-
JSON.stringify({ compilerOptions: {} }),
|
|
743
|
-
"utf-8"
|
|
744
|
-
);
|
|
179
|
+
it("no subcommand 'kv:bulk' should display a list of available subcommands", async () => {
|
|
180
|
+
await runWrangler("kv:bulk");
|
|
181
|
+
await endEventLoop();
|
|
182
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
183
|
+
"wrangler kv:bulk
|
|
745
184
|
|
|
746
|
-
|
|
747
|
-
process.chdir("./sub-1/sub-2");
|
|
185
|
+
💪 Interact with multiple Workers KV key-value pairs at once
|
|
748
186
|
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
187
|
+
Commands:
|
|
188
|
+
wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
|
|
189
|
+
wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
|
|
752
190
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
191
|
+
Flags:
|
|
192
|
+
-c, --config Path to .toml configuration file [string]
|
|
193
|
+
-h, --help Show help [boolean]
|
|
194
|
+
-v, --version Show version number [boolean]"
|
|
195
|
+
`);
|
|
757
196
|
});
|
|
758
197
|
|
|
759
|
-
it("
|
|
760
|
-
await runWrangler("
|
|
761
|
-
|
|
762
|
-
expect(fs.existsSync("./src/index.js")).toBe(false);
|
|
763
|
-
expect(fs.existsSync("./src/index.ts")).toBe(true);
|
|
764
|
-
expect(fs.existsSync("./tsconfig.json")).toBe(true);
|
|
765
|
-
expect(fs.existsSync("./package.json")).toBe(true);
|
|
766
|
-
expect(fs.existsSync("./wrangler.toml")).toBe(true);
|
|
198
|
+
it("no subcommand 'r2' should display a list of available subcommands", async () => {
|
|
199
|
+
await runWrangler("r2");
|
|
200
|
+
await endEventLoop();
|
|
767
201
|
expect(std.out).toMatchInlineSnapshot(`
|
|
768
|
-
"
|
|
769
|
-
✨ Created package.json
|
|
770
|
-
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
771
|
-
✨ Created src/index.ts
|
|
202
|
+
"wrangler r2
|
|
772
203
|
|
|
773
|
-
|
|
774
|
-
To publish your Worker to the Internet, run \`npm run publish\`"
|
|
775
|
-
`);
|
|
776
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
777
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
778
|
-
});
|
|
204
|
+
📦 Interact with an R2 store
|
|
779
205
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
expect(fs.existsSync("./my-worker/src/index.js")).toBe(false);
|
|
784
|
-
expect(fs.existsSync("./my-worker/src/index.ts")).toBe(true);
|
|
785
|
-
expect(fs.existsSync("./my-worker/tsconfig.json")).toBe(true);
|
|
786
|
-
expect(fs.existsSync("./my-worker/package.json")).toBe(true);
|
|
787
|
-
expect(fs.existsSync("./my-worker/wrangler.toml")).toBe(true);
|
|
788
|
-
const parsedWranglerToml = TOML.parse(
|
|
789
|
-
fs.readFileSync("./my-worker/wrangler.toml", "utf-8")
|
|
790
|
-
);
|
|
791
|
-
expect(parsedWranglerToml.main).toEqual("src/index.ts");
|
|
792
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
793
|
-
"✨ Successfully created wrangler.toml
|
|
794
|
-
✨ Created package.json
|
|
795
|
-
✨ Created tsconfig.json, installed @cloudflare/workers-types into devDependencies
|
|
796
|
-
✨ Created src/index.ts
|
|
206
|
+
Commands:
|
|
207
|
+
wrangler r2 bucket Manage R2 buckets
|
|
797
208
|
|
|
798
|
-
|
|
799
|
-
|
|
209
|
+
Flags:
|
|
210
|
+
-c, --config Path to .toml configuration file [string]
|
|
211
|
+
-h, --help Show help [boolean]
|
|
212
|
+
-v, --version Show version number [boolean]"
|
|
800
213
|
`);
|
|
801
|
-
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
802
|
-
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
803
214
|
});
|
|
215
|
+
});
|
|
804
216
|
|
|
805
|
-
|
|
806
|
-
|
|
217
|
+
describe("Deprecated commands", () => {
|
|
218
|
+
it("should print a deprecation message for 'generate'", async () => {
|
|
219
|
+
await runWrangler("generate").catch((err) => {
|
|
220
|
+
expect(err.message).toMatchInlineSnapshot(`
|
|
221
|
+
"Deprecation:
|
|
222
|
+
\`wrangler generate\` has been deprecated.
|
|
223
|
+
Try running \`wrangler init\` to generate a basic Worker, or cloning the template repository instead:
|
|
807
224
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
expect(fs.existsSync("./package.json")).toBe(true);
|
|
812
|
-
expect(fs.existsSync("./wrangler.toml")).toBe(true);
|
|
813
|
-
});
|
|
225
|
+
\`\`\`
|
|
226
|
+
git clone https://github.com/cloudflare/worker-template
|
|
227
|
+
\`\`\`
|
|
814
228
|
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
819
|
-
`"The --type option is no longer supported."`
|
|
820
|
-
);
|
|
229
|
+
Please refer to https://developers.cloudflare.com/workers/wrangler/deprecations/#generate for more information."
|
|
230
|
+
`);
|
|
231
|
+
});
|
|
821
232
|
});
|
|
233
|
+
});
|
|
822
234
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
827
|
-
`"The --type option is no longer supported."`
|
|
828
|
-
);
|
|
235
|
+
it("should print a deprecation message for 'build' and then try to run `publish --dry-run --outdir`", async () => {
|
|
236
|
+
writeWranglerToml({
|
|
237
|
+
main: "index.js",
|
|
829
238
|
});
|
|
239
|
+
writeWorkerSource();
|
|
240
|
+
await runWrangler("build");
|
|
241
|
+
await endEventLoop();
|
|
242
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
243
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mDeprecation: \`wrangler build\` has been deprecated.[0m
|
|
830
244
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
835
|
-
`"The --type option is no longer supported."`
|
|
836
|
-
);
|
|
837
|
-
});
|
|
245
|
+
Please refer to [4mhttps://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build[0m
|
|
246
|
+
for more information.
|
|
247
|
+
Attempting to run \`wrangler publish --dry-run --outdir=dist\` for you instead:
|
|
838
248
|
|
|
839
|
-
it("should error if `--type webpack` is used", async () => {
|
|
840
|
-
await expect(runWrangler("init --type webpack")).rejects
|
|
841
|
-
.toThrowErrorMatchingInlineSnapshot(`
|
|
842
|
-
"The --type option is no longer supported.
|
|
843
|
-
If you wish to use webpack then you will need to create a custom build."
|
|
844
|
-
`);
|
|
845
|
-
});
|
|
846
|
-
});
|
|
847
249
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
await expect(runWrangler("preview GET")).rejects
|
|
851
|
-
.toThrowErrorMatchingInlineSnapshot(`
|
|
852
|
-
"DEPRECATION WARNING:
|
|
853
|
-
The \`wrangler preview\` command has been deprecated.
|
|
854
|
-
Try using \`wrangler dev\` to to try out a worker during development.
|
|
855
|
-
"
|
|
856
|
-
`);
|
|
857
|
-
await expect(runWrangler("preview GET 'Some Body'")).rejects
|
|
858
|
-
.toThrowErrorMatchingInlineSnapshot(`
|
|
859
|
-
"DEPRECATION WARNING:
|
|
860
|
-
The \`wrangler preview\` command has been deprecated.
|
|
861
|
-
Try using \`wrangler dev\` to to try out a worker during development.
|
|
862
|
-
"
|
|
863
|
-
`);
|
|
864
|
-
});
|
|
250
|
+
--dry-run: exiting now."
|
|
251
|
+
`);
|
|
865
252
|
});
|
|
866
253
|
});
|
|
254
|
+
|
|
255
|
+
function endEventLoop() {
|
|
256
|
+
return new Promise((resolve) => setImmediate(resolve));
|
|
257
|
+
}
|