wrangler 0.0.0-e0d2f35 → 0.0.0-e1b8ac4

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