wrangler 0.0.0-e2a26a0 → 0.0.0-e322475

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.
Files changed (157) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +27 -14
  3. package/bin/wrangler.js +49 -5
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +4886 -0
  6. package/package.json +54 -27
  7. package/pages/functions/buildPlugin.ts +105 -0
  8. package/pages/functions/buildWorker.ts +93 -4
  9. package/pages/functions/filepath-routing.test.ts +223 -36
  10. package/pages/functions/filepath-routing.ts +78 -120
  11. package/pages/functions/routes.ts +13 -17
  12. package/pages/functions/template-plugin.ts +147 -0
  13. package/pages/functions/template-worker.ts +24 -17
  14. package/src/__tests__/config-cache.test.ts +36 -0
  15. package/src/__tests__/configuration.test.ts +3548 -0
  16. package/src/__tests__/dev.test.tsx +1049 -65
  17. package/src/__tests__/guess-worker-format.test.ts +85 -0
  18. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  19. package/src/__tests__/helpers/mock-account-id.ts +26 -8
  20. package/src/__tests__/helpers/mock-bin.ts +4 -1
  21. package/src/__tests__/helpers/mock-cfetch.ts +12 -8
  22. package/src/__tests__/helpers/mock-console.ts +49 -8
  23. package/src/__tests__/helpers/mock-dialogs.ts +99 -11
  24. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  25. package/src/__tests__/helpers/mock-istty.ts +27 -0
  26. package/src/__tests__/helpers/mock-kv.ts +9 -16
  27. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  28. package/src/__tests__/helpers/mock-process.ts +24 -0
  29. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  30. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  31. package/src/__tests__/helpers/run-in-tmp.ts +10 -0
  32. package/src/__tests__/helpers/run-wrangler.ts +5 -3
  33. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  34. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  35. package/src/__tests__/https-options.test.ts +130 -0
  36. package/src/__tests__/index.test.ts +150 -435
  37. package/src/__tests__/init.test.ts +1992 -0
  38. package/src/__tests__/jest.setup.ts +75 -5
  39. package/src/__tests__/kv.test.ts +634 -253
  40. package/src/__tests__/logger.test.ts +141 -0
  41. package/src/__tests__/package-manager.test.ts +156 -9
  42. package/src/__tests__/pages.test.ts +754 -0
  43. package/src/__tests__/parse.test.ts +330 -0
  44. package/src/__tests__/publish.test.ts +5895 -961
  45. package/src/__tests__/r2.test.ts +233 -0
  46. package/src/__tests__/route.test.ts +45 -0
  47. package/src/__tests__/secret.test.ts +362 -91
  48. package/src/__tests__/tail.test.ts +690 -0
  49. package/src/__tests__/user.test.ts +132 -0
  50. package/src/__tests__/whoami.test.tsx +60 -7
  51. package/src/abort.d.ts +3 -0
  52. package/src/bundle-reporter.tsx +29 -0
  53. package/src/bundle.ts +204 -0
  54. package/src/cfetch/index.ts +27 -8
  55. package/src/cfetch/internal.ts +75 -34
  56. package/src/cli.ts +6 -2
  57. package/src/config/README.md +107 -0
  58. package/src/config/config.ts +243 -0
  59. package/src/config/diagnostics.ts +80 -0
  60. package/src/config/environment.ts +420 -0
  61. package/src/config/index.ts +225 -0
  62. package/src/config/validation-helpers.ts +584 -0
  63. package/src/config/validation.ts +1580 -0
  64. package/src/config-cache.ts +45 -0
  65. package/src/create-worker-preview.ts +185 -0
  66. package/src/create-worker-upload-form.ts +254 -0
  67. package/src/dev/dev-vars.ts +36 -0
  68. package/src/dev/dev.tsx +399 -0
  69. package/src/dev/local.tsx +321 -0
  70. package/src/dev/remote.tsx +249 -0
  71. package/src/dev/use-esbuild.ts +112 -0
  72. package/src/dialogs.tsx +64 -6
  73. package/src/durable.ts +102 -0
  74. package/src/entry.ts +328 -0
  75. package/src/environment-variables.ts +35 -0
  76. package/src/errors.ts +11 -0
  77. package/src/generate-auth-url.ts +33 -0
  78. package/src/generate-random-state.ts +16 -0
  79. package/src/git-client.ts +42 -0
  80. package/src/https-options.ts +123 -0
  81. package/src/index.tsx +1804 -1009
  82. package/src/inspect.ts +80 -14
  83. package/src/intl-polyfill.d.ts +139 -0
  84. package/src/{kv.tsx → kv.ts} +193 -69
  85. package/src/logger.ts +73 -0
  86. package/src/miniflare-cli/README.md +30 -0
  87. package/src/miniflare-cli/enum-keys.ts +17 -0
  88. package/src/miniflare-cli/index.ts +41 -0
  89. package/src/miniflare-cli/request-context.ts +40 -0
  90. package/src/module-collection.ts +226 -31
  91. package/src/open-in-browser.ts +17 -0
  92. package/src/package-manager.ts +79 -25
  93. package/src/pages.tsx +1131 -84
  94. package/src/parse.ts +222 -0
  95. package/src/proxy.ts +176 -70
  96. package/src/publish.ts +637 -308
  97. package/src/r2.ts +50 -0
  98. package/src/selfsigned.d.ts +29 -0
  99. package/src/sites.tsx +185 -57
  100. package/src/tail/filters.ts +279 -0
  101. package/src/tail/index.ts +299 -0
  102. package/src/tail/printing.ts +67 -0
  103. package/src/update-check.ts +19 -0
  104. package/src/user.tsx +349 -166
  105. package/src/whoami.tsx +5 -3
  106. package/src/{api/worker.ts → worker.ts} +65 -39
  107. package/src/zones.ts +73 -0
  108. package/templates/gitignore +171 -0
  109. package/templates/new-worker-scheduled.js +17 -0
  110. package/templates/new-worker-scheduled.ts +32 -0
  111. package/templates/new-worker.js +1 -1
  112. package/templates/new-worker.ts +17 -2
  113. package/templates/no-op-worker.js +10 -0
  114. package/templates/static-asset-facade.js +3 -7
  115. package/templates/tsconfig.json +105 -0
  116. package/wrangler-dist/cli.js +77463 -75999
  117. package/src/__tests__/helpers/mock-user.ts +0 -27
  118. package/src/__tests__/logout.test.ts +0 -50
  119. package/src/api/form_data.ts +0 -134
  120. package/src/api/preview.ts +0 -128
  121. package/src/config.ts +0 -641
  122. package/src/dev.tsx +0 -834
  123. package/src/tail.tsx +0 -73
  124. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  125. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  126. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  127. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  128. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  129. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  130. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  131. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  132. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  133. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  134. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  135. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  136. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  137. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  138. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  139. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  140. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  141. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  142. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  143. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  144. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  145. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  146. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  147. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  148. package/vendor/wrangler-mime/LICENSE +0 -21
  149. package/vendor/wrangler-mime/Mime.js +0 -97
  150. package/vendor/wrangler-mime/README.md +0 -187
  151. package/vendor/wrangler-mime/cli.js +0 -46
  152. package/vendor/wrangler-mime/index.js +0 -4
  153. package/vendor/wrangler-mime/lite.js +0 -4
  154. package/vendor/wrangler-mime/package.json +0 -52
  155. package/vendor/wrangler-mime/types/other.js +0 -1
  156. package/vendor/wrangler-mime/types/standard.js +0 -1
  157. package/wrangler-dist/cli.js.map +0 -7
@@ -1,12 +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 { version as wranglerVersion } from "../../package.json";
5
1
  import { getPackageManager } from "../package-manager";
6
2
  import { mockConsoleMethods } from "./helpers/mock-console";
7
- import { mockConfirm } from "./helpers/mock-dialogs";
8
3
  import { runInTempDir } from "./helpers/run-in-tmp";
9
4
  import { runWrangler } from "./helpers/run-wrangler";
5
+ import { writeWorkerSource } from "./helpers/write-worker-source";
6
+ import writeWranglerToml from "./helpers/write-wrangler-toml";
10
7
  import type { PackageManager } from "../package-manager";
11
8
 
12
9
  describe("wrangler", () => {
@@ -15,6 +12,9 @@ describe("wrangler", () => {
15
12
 
16
13
  beforeEach(() => {
17
14
  mockPackageManager = {
15
+ cwd: process.cwd(),
16
+ // @ts-expect-error we're making a fake package manager here
17
+ type: "mockpm",
18
18
  addDevDeps: jest.fn(),
19
19
  install: jest.fn(),
20
20
  };
@@ -32,23 +32,23 @@ describe("wrangler", () => {
32
32
 
33
33
  Commands:
34
34
  wrangler init [name] 📥 Create a wrangler.toml configuration file
35
- wrangler whoami 🕵️ Retrieve your user info and test your auth config
36
- wrangler dev <filename> 👂 Start a local server for developing your worker
35
+ wrangler dev [script] 👂 Start a local server for developing your worker
37
36
  wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
38
- wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
37
+ wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
39
38
  wrangler secret 🤫 Generate a secret that can be referenced in the worker script
40
39
  wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
41
40
  wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
42
41
  wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
43
42
  wrangler pages ⚡️ Configure Cloudflare Pages
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
44
47
 
45
48
  Flags:
46
49
  -c, --config Path to .toml configuration file [string]
47
50
  -h, --help Show help [boolean]
48
- -v, --version Show version number [boolean]
49
-
50
- Options:
51
- -l, --local Run on my machine [boolean] [default: false]"
51
+ -v, --version Show version number [boolean]"
52
52
  `);
53
53
 
54
54
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -60,484 +60,199 @@ describe("wrangler", () => {
60
60
  await expect(
61
61
  runWrangler("invalid-command")
62
62
  ).rejects.toThrowErrorMatchingInlineSnapshot(
63
- `"Unknown command: invalid-command."`
63
+ `"Unknown argument: invalid-command"`
64
64
  );
65
65
 
66
- expect(std.out).toMatchInlineSnapshot(`""`);
67
- expect(std.err).toMatchInlineSnapshot(`
68
- "wrangler
66
+ expect(std.out).toMatchInlineSnapshot(`
67
+ "
68
+ wrangler
69
69
 
70
70
  Commands:
71
71
  wrangler init [name] 📥 Create a wrangler.toml configuration file
72
- wrangler whoami 🕵️ Retrieve your user info and test your auth config
73
- wrangler dev <filename> 👂 Start a local server for developing your worker
72
+ wrangler dev [script] 👂 Start a local server for developing your worker
74
73
  wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
75
- wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
74
+ wrangler tail [name] 🦚 Starts a log tailing session for a published Worker.
76
75
  wrangler secret 🤫 Generate a secret that can be referenced in the worker script
77
76
  wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
78
77
  wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
79
78
  wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
80
79
  wrangler pages ⚡️ Configure Cloudflare Pages
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
81
84
 
82
85
  Flags:
83
86
  -c, --config Path to .toml configuration file [string]
84
87
  -h, --help Show help [boolean]
85
- -v, --version Show version number [boolean]
86
-
87
- Options:
88
- -l, --local Run on my machine [boolean] [default: false]
88
+ -v, --version Show version number [boolean]"
89
+ `);
90
+ expect(std.err).toMatchInlineSnapshot(`
91
+ "X [ERROR] Unknown argument: invalid-command
89
92
 
90
- Unknown command: invalid-command."
93
+ "
91
94
  `);
92
95
  });
93
96
  });
94
97
 
95
- describe("init", () => {
96
- it("should create a wrangler.toml", async () => {
97
- mockConfirm({
98
- text: "No package.json found. Would you like to create one?",
99
- result: false,
100
- });
101
- await runWrangler("init");
102
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
103
- expect(typeof parsed.compatibility_date).toBe("string");
104
- expect(fs.existsSync("./package.json")).toBe(false);
105
- expect(fs.existsSync("./tsconfig.json")).toBe(false);
106
- });
107
-
108
- it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
109
- fs.writeFileSync(
110
- "./wrangler.toml",
111
- 'compatibility_date="something-else"', // use a fake value to make sure the file is not overwritten
112
- "utf-8"
113
- );
114
- mockConfirm({
115
- text: "Do you want to continue initializing this project?",
116
- result: false,
117
- });
118
- await runWrangler("init");
119
- expect(std.warn).toContain("wrangler.toml file already exists!");
120
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
121
- expect(parsed.compatibility_date).toBe("something-else");
122
- });
123
-
124
- it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
125
- fs.writeFileSync(
126
- "./wrangler.toml",
127
- `compatibility_date="something-else"`,
128
- "utf-8"
129
- );
130
- mockConfirm(
131
- {
132
- text: "Do you want to continue initializing this project?",
133
- result: true,
134
- },
135
- {
136
- text: "No package.json found. Would you like to create one?",
137
- result: false,
138
- }
139
- );
140
- await runWrangler("init");
141
- expect(std.warn).toContain("wrangler.toml file already exists!");
142
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
143
- expect(parsed.compatibility_date).toBe("something-else");
144
- });
145
-
146
- it("should create a package.json if none is found and user confirms", async () => {
147
- mockConfirm(
148
- {
149
- text: "No package.json found. Would you like to create one?",
150
- result: true,
151
- },
152
- {
153
- text: "Would you like to use TypeScript?",
154
- result: false,
155
- },
156
- {
157
- text: "Would you like to create a Worker at src/index.js?",
158
- result: false,
159
- }
160
- );
161
- await runWrangler("init");
162
- expect(fs.existsSync("./package.json")).toBe(true);
163
- const packageJson = JSON.parse(
164
- fs.readFileSync("./package.json", "utf-8")
165
- );
166
- expect(packageJson.name).toEqual("worker"); // TODO: should we infer the name from the directory?
167
- expect(packageJson.version).toEqual("0.0.0");
168
- expect(packageJson.devDependencies).toEqual({
169
- wrangler: expect.any(String),
170
- });
171
- expect(fs.existsSync("./tsconfig.json")).toBe(false);
172
- expect(mockPackageManager.install).toHaveBeenCalled();
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
+ `);
173
114
  });
115
+ });
174
116
 
175
- it("should not touch an existing package.json in the same directory", async () => {
176
- mockConfirm(
177
- {
178
- text: "Would you like to install wrangler into your package.json?",
179
- result: false,
180
- },
181
- {
182
- text: "Would you like to use TypeScript?",
183
- result: false,
184
- },
185
- {
186
- text: "Would you like to create a Worker at src/index.js?",
187
- result: false,
188
- }
189
- );
190
-
191
- fs.writeFileSync(
192
- "./package.json",
193
- JSON.stringify({ name: "test", version: "1.0.0" }),
194
- "utf-8"
195
- );
196
-
197
- await runWrangler("init");
198
- const packageJson = JSON.parse(
199
- fs.readFileSync("./package.json", "utf-8")
200
- );
201
- expect(packageJson.name).toEqual("test");
202
- expect(packageJson.version).toEqual("1.0.0");
203
- });
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
204
123
 
205
- it("should offer to install wrangler into an existing package.json", async () => {
206
- mockConfirm(
207
- {
208
- text: "Would you like to install wrangler into your package.json?",
209
- result: true,
210
- },
211
- {
212
- text: "Would you like to use TypeScript?",
213
- result: false,
214
- },
215
- {
216
- text: "Would you like to create a Worker at src/index.js?",
217
- result: false,
218
- }
219
- );
124
+ 🤫 Generate a secret that can be referenced in the worker script
220
125
 
221
- fs.writeFileSync(
222
- "./package.json",
223
- JSON.stringify({ name: "test", version: "1.0.0" }),
224
- "utf-8"
225
- );
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
226
130
 
227
- await runWrangler("init");
228
- const packageJson = JSON.parse(
229
- fs.readFileSync("./package.json", "utf-8")
230
- );
231
- expect(packageJson.name).toEqual("test");
232
- expect(packageJson.version).toEqual("1.0.0");
233
- expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
234
- `wrangler@${wranglerVersion}`
235
- );
131
+ Flags:
132
+ -c, --config Path to .toml configuration file [string]
133
+ -h, --help Show help [boolean]
134
+ -v, --version Show version number [boolean]"
135
+ `);
236
136
  });
237
137
 
238
- it("should not touch an existing package.json in an ancestor directory", async () => {
239
- mockConfirm(
240
- {
241
- text: "Would you like to install wrangler into your package.json?",
242
- result: false,
243
- },
244
- {
245
- text: "Would you like to use TypeScript?",
246
- result: false,
247
- },
248
- {
249
- text: "Would you like to create a Worker at src/index.js?",
250
- result: false,
251
- }
252
- );
253
-
254
- fs.writeFileSync(
255
- "./package.json",
256
- JSON.stringify({ name: "test", version: "1.0.0" }),
257
- "utf-8"
258
- );
138
+ it("no subcommand 'kv:namespace' should display a list of available subcommands", async () => {
139
+ await runWrangler("kv:namespace");
140
+ await endEventLoop();
141
+ expect(std.out).toMatchInlineSnapshot(`
142
+ "wrangler kv:namespace
259
143
 
260
- fs.mkdirSync("./sub-1/sub-2", { recursive: true });
261
- process.chdir("./sub-1/sub-2");
144
+ 🗂️ Interact with your Workers KV Namespaces
262
145
 
263
- await runWrangler("init");
264
- expect(fs.existsSync("./package.json")).toBe(false);
265
- expect(fs.existsSync("../../package.json")).toBe(true);
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.
266
150
 
267
- const packageJson = JSON.parse(
268
- fs.readFileSync("../../package.json", "utf-8")
269
- );
270
- expect(packageJson).toMatchInlineSnapshot(`
271
- Object {
272
- "name": "test",
273
- "version": "1.0.0",
274
- }
151
+ Flags:
152
+ -c, --config Path to .toml configuration file [string]
153
+ -h, --help Show help [boolean]
154
+ -v, --version Show version number [boolean]"
275
155
  `);
276
156
  });
277
157
 
278
- it("should offer to create a worker in a non-typescript project", async () => {
279
- mockConfirm(
280
- {
281
- text: "Would you like to install wrangler into your package.json?",
282
- result: false,
283
- },
284
- {
285
- text: "Would you like to use TypeScript?",
286
- result: false,
287
- },
288
- {
289
- text: "Would you like to create a Worker at src/index.js?",
290
- result: true,
291
- }
292
- );
293
-
294
- fs.writeFileSync(
295
- "./package.json",
296
- JSON.stringify({ name: "test", version: "1.0.0" }),
297
- "utf-8"
298
- );
299
-
300
- await runWrangler("init");
301
- expect(fs.existsSync("./src/index.js")).toBe(true);
302
- expect(fs.existsSync("./src/index.ts")).toBe(false);
303
- });
304
-
305
- it("should offer to create a worker in a typescript project", async () => {
306
- mockConfirm(
307
- {
308
- text: "Would you like to install wrangler into your package.json?",
309
- result: false,
310
- },
311
- {
312
- text: "Would you like to use TypeScript?",
313
- result: true,
314
- },
315
- {
316
- text: "Would you like to create a Worker at src/index.ts?",
317
- result: true,
318
- }
319
- );
320
-
321
- fs.writeFileSync(
322
- "./package.json",
323
- JSON.stringify({ name: "test", version: "1.0.0" }),
324
- "utf-8"
325
- );
326
-
327
- await runWrangler("init");
328
- expect(fs.existsSync("./src/index.js")).toBe(false);
329
- expect(fs.existsSync("./src/index.ts")).toBe(true);
330
- });
158
+ it("no subcommand 'kv:key' should display a list of available subcommands", async () => {
159
+ await runWrangler("kv:key");
160
+ await endEventLoop();
161
+ expect(std.out).toMatchInlineSnapshot(`
162
+ "wrangler kv:key
331
163
 
332
- it("should not offer to create a worker in a non-ts project if a file already exists at the location", async () => {
333
- mockConfirm(
334
- {
335
- text: "Would you like to install wrangler into your package.json?",
336
- result: false,
337
- },
338
- {
339
- text: "Would you like to use TypeScript?",
340
- result: false,
341
- }
342
- );
164
+ 🔑 Individually manage Workers KV key-value pairs
343
165
 
344
- fs.writeFileSync(
345
- "./package.json",
346
- JSON.stringify({ name: "test", version: "1.0.0" }),
347
- "utf-8"
348
- );
349
- fs.mkdirSync("./src", { recursive: true });
350
- const PLACEHOLDER = "/* placeholder text */";
351
- fs.writeFileSync("./src/index.js", PLACEHOLDER, "utf-8");
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.
352
171
 
353
- await runWrangler("init");
354
- expect(fs.readFileSync("./src/index.js", "utf-8")).toBe(PLACEHOLDER);
355
- expect(fs.existsSync("./src/index.ts")).toBe(false);
172
+ Flags:
173
+ -c, --config Path to .toml configuration file [string]
174
+ -h, --help Show help [boolean]
175
+ -v, --version Show version number [boolean]"
176
+ `);
356
177
  });
357
178
 
358
- it("should not offer to create a worker in a ts project if a file already exists at the location", async () => {
359
- mockConfirm(
360
- {
361
- text: "Would you like to install wrangler into your package.json?",
362
- result: false,
363
- },
364
- {
365
- text: "Would you like to use TypeScript?",
366
- result: true,
367
- }
368
- );
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
369
184
 
370
- fs.writeFileSync(
371
- "./package.json",
372
- JSON.stringify({ name: "test", version: "1.0.0" }),
373
- "utf-8"
374
- );
375
- fs.mkdirSync("./src", { recursive: true });
376
- const PLACEHOLDER = "/* placeholder text */";
377
- fs.writeFileSync("./src/index.ts", PLACEHOLDER, "utf-8");
185
+ 💪 Interact with multiple Workers KV key-value pairs at once
378
186
 
379
- await runWrangler("init");
380
- expect(fs.existsSync("./src/index.js")).toBe(false);
381
- expect(fs.readFileSync("./src/index.ts", "utf-8")).toBe(PLACEHOLDER);
382
- });
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
383
190
 
384
- it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
385
- mockConfirm(
386
- {
387
- text: "No package.json found. Would you like to create one?",
388
- result: true,
389
- },
390
- {
391
- text: "Would you like to use TypeScript?",
392
- result: true,
393
- },
394
- {
395
- text: "Would you like to create a Worker at src/index.ts?",
396
- result: false,
397
- }
398
- );
399
- await runWrangler("init");
400
- expect(fs.existsSync("./tsconfig.json")).toBe(true);
401
- const tsconfigJson = JSON.parse(
402
- fs.readFileSync("./tsconfig.json", "utf-8")
403
- );
404
- expect(tsconfigJson.compilerOptions.types).toEqual([
405
- "@cloudflare/workers-types",
406
- ]);
407
- expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
408
- "@cloudflare/workers-types",
409
- "typescript"
410
- );
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
+ `);
411
196
  });
412
197
 
413
- it("should not touch an existing tsconfig.json in the same directory", async () => {
414
- fs.writeFileSync(
415
- "./package.json",
416
- JSON.stringify({
417
- name: "test",
418
- version: "1.0.0",
419
- devDependencies: {
420
- wrangler: "0.0.0",
421
- "@cloudflare/workers-types": "0.0.0",
422
- },
423
- }),
424
- "utf-8"
425
- );
426
- fs.writeFileSync(
427
- "./tsconfig.json",
428
- JSON.stringify({ compilerOptions: {} }),
429
- "utf-8"
430
- );
198
+ it("no subcommand 'r2' should display a list of available subcommands", async () => {
199
+ await runWrangler("r2");
200
+ await endEventLoop();
201
+ expect(std.out).toMatchInlineSnapshot(`
202
+ "wrangler r2
431
203
 
432
- await runWrangler("init");
433
- const tsconfigJson = JSON.parse(
434
- fs.readFileSync("./tsconfig.json", "utf-8")
435
- );
436
- expect(tsconfigJson.compilerOptions).toEqual({});
437
- });
204
+ 📦 Interact with an R2 store
438
205
 
439
- it("should offer to install type definitions in an existing typescript project", async () => {
440
- mockConfirm(
441
- {
442
- text: "Would you like to install wrangler into your package.json?",
443
- result: false,
444
- },
445
- {
446
- text: "Would you like to install the type definitions for Workers into your package.json?",
447
- result: true,
448
- },
449
- {
450
- text: "Would you like to create a Worker at src/index.ts?",
451
- result: false,
452
- }
453
- );
454
- fs.writeFileSync(
455
- "./package.json",
456
- JSON.stringify({
457
- name: "test",
458
- version: "1.0.0",
459
- }),
460
- "utf-8"
461
- );
462
- fs.writeFileSync(
463
- "./tsconfig.json",
464
- JSON.stringify({ compilerOptions: {} }),
465
- "utf-8"
466
- );
206
+ Commands:
207
+ wrangler r2 bucket Manage R2 buckets
467
208
 
468
- await runWrangler("init");
469
- const tsconfigJson = JSON.parse(
470
- fs.readFileSync("./tsconfig.json", "utf-8")
471
- );
472
- // unchanged tsconfig
473
- expect(tsconfigJson.compilerOptions).toEqual({});
474
- expect(mockPackageManager.addDevDeps).toHaveBeenCalledWith(
475
- "@cloudflare/workers-types"
476
- );
209
+ Flags:
210
+ -c, --config Path to .toml configuration file [string]
211
+ -h, --help Show help [boolean]
212
+ -v, --version Show version number [boolean]"
213
+ `);
477
214
  });
215
+ });
478
216
 
479
- it("should not touch an existing tsconfig.json in an ancestor directory", async () => {
480
- fs.writeFileSync(
481
- "./package.json",
482
- JSON.stringify({
483
- name: "test",
484
- version: "1.0.0",
485
- devDependencies: {
486
- wrangler: "0.0.0",
487
- "@cloudflare/workers-types": "0.0.0",
488
- },
489
- }),
490
- "utf-8"
491
- );
492
- fs.writeFileSync(
493
- "./tsconfig.json",
494
- JSON.stringify({ compilerOptions: {} }),
495
- "utf-8"
496
- );
497
-
498
- fs.mkdirSync("./sub-1/sub-2", { recursive: true });
499
- process.chdir("./sub-1/sub-2");
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:
500
224
 
501
- await runWrangler("init");
502
- expect(fs.existsSync("./tsconfig.json")).toBe(false);
503
- expect(fs.existsSync("../../tsconfig.json")).toBe(true);
225
+ \`\`\`
226
+ git clone https://github.com/cloudflare/worker-template
227
+ \`\`\`
504
228
 
505
- const tsconfigJson = JSON.parse(
506
- fs.readFileSync("../../tsconfig.json", "utf-8")
507
- );
508
- expect(tsconfigJson.compilerOptions).toEqual({});
229
+ Please refer to https://developers.cloudflare.com/workers/wrangler/deprecations/#generate for more information."
230
+ `);
231
+ });
509
232
  });
233
+ });
510
234
 
511
- it("should error if `--type` is used", async () => {
512
- await expect(
513
- runWrangler("init --type")
514
- ).rejects.toThrowErrorMatchingInlineSnapshot(
515
- `"The --type option is no longer supported."`
516
- );
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",
517
238
  });
239
+ writeWorkerSource();
240
+ await runWrangler("build");
241
+ await endEventLoop();
242
+ expect(std.out).toMatchInlineSnapshot(`
243
+ "▲ [WARNING] Deprecation: \`wrangler build\` has been deprecated.
518
244
 
519
- it("should error if `--type javascript` is used", async () => {
520
- await expect(
521
- runWrangler("init --type javascript")
522
- ).rejects.toThrowErrorMatchingInlineSnapshot(
523
- `"The --type option is no longer supported."`
524
- );
525
- });
245
+ Please refer to https://developers.cloudflare.com/workers/wrangler/migration/deprecations/#build
246
+ for more information.
247
+ Attempting to run \`wrangler publish --dry-run --outdir=dist\` for you instead:
526
248
 
527
- it("should error if `--type rust` is used", async () => {
528
- await expect(
529
- runWrangler("init --type rust")
530
- ).rejects.toThrowErrorMatchingInlineSnapshot(
531
- `"The --type option is no longer supported."`
532
- );
533
- });
534
249
 
535
- it("should error if `--type webpack` is used", async () => {
536
- await expect(runWrangler("init --type webpack")).rejects
537
- .toThrowErrorMatchingInlineSnapshot(`
538
- "The --type option is no longer supported.
539
- If you wish to use webpack then you will need to create a custom build."
540
- `);
541
- });
250
+ --dry-run: exiting now.
251
+ Total Upload: 0xx KiB / gzip: 0xx KiB"
252
+ `);
542
253
  });
543
254
  });
255
+
256
+ function endEventLoop() {
257
+ return new Promise((resolve) => setImmediate(resolve));
258
+ }