wrangler 0.0.0-e22f9d7 → 0.0.0-e273e09

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 (154) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +27 -14
  3. package/bin/wrangler.js +48 -4
  4. package/miniflare-dist/index.mjs +4886 -0
  5. package/package.json +60 -31
  6. package/pages/functions/buildPlugin.ts +105 -0
  7. package/pages/functions/buildWorker.ts +93 -4
  8. package/pages/functions/filepath-routing.test.ts +223 -28
  9. package/pages/functions/filepath-routing.ts +100 -132
  10. package/pages/functions/routes.ts +16 -18
  11. package/pages/functions/template-plugin.ts +147 -0
  12. package/pages/functions/template-worker.ts +37 -38
  13. package/src/__tests__/config-cache.test.ts +36 -0
  14. package/src/__tests__/configuration.test.ts +3487 -0
  15. package/src/__tests__/dev.test.tsx +977 -61
  16. package/src/__tests__/guess-worker-format.test.ts +85 -0
  17. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  18. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  19. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  20. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  21. package/src/__tests__/helpers/mock-bin.ts +36 -0
  22. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +56 -16
  23. package/src/__tests__/helpers/mock-console.ts +87 -0
  24. package/src/__tests__/helpers/mock-dialogs.ts +130 -0
  25. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  26. package/src/__tests__/helpers/mock-istty.ts +27 -0
  27. package/src/__tests__/helpers/mock-kv.ts +33 -0
  28. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -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 +39 -0
  32. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  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 +179 -209
  37. package/src/__tests__/init.test.ts +1637 -0
  38. package/src/__tests__/jest.setup.ts +61 -6
  39. package/src/__tests__/kv.test.ts +842 -472
  40. package/src/__tests__/logger.test.ts +115 -0
  41. package/src/__tests__/package-manager.test.ts +353 -0
  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 +5755 -0
  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 +481 -0
  48. package/src/__tests__/tail.test.ts +690 -0
  49. package/src/__tests__/user.test.ts +131 -0
  50. package/src/__tests__/whoami.test.tsx +139 -0
  51. package/src/abort.d.ts +3 -0
  52. package/src/bundle.ts +197 -0
  53. package/src/cfetch/index.ts +40 -21
  54. package/src/cfetch/internal.ts +102 -29
  55. package/src/cli.ts +6 -2
  56. package/src/config/README.md +107 -0
  57. package/src/config/config.ts +234 -0
  58. package/src/config/diagnostics.ts +80 -0
  59. package/src/config/environment.ts +420 -0
  60. package/src/config/index.ts +225 -0
  61. package/src/config/validation-helpers.ts +584 -0
  62. package/src/config/validation.ts +1548 -0
  63. package/src/config-cache.ts +45 -0
  64. package/src/create-worker-preview.ts +185 -0
  65. package/src/create-worker-upload-form.ts +254 -0
  66. package/src/dev/dev-vars.ts +36 -0
  67. package/src/dev/dev.tsx +401 -0
  68. package/src/dev/local.tsx +326 -0
  69. package/src/dev/remote.tsx +237 -0
  70. package/src/dev/use-esbuild.ts +118 -0
  71. package/src/dialogs.tsx +66 -8
  72. package/src/durable.ts +102 -0
  73. package/src/entry.ts +322 -0
  74. package/src/environment-variables.ts +35 -0
  75. package/src/errors.ts +11 -0
  76. package/src/https-options.ts +123 -0
  77. package/src/index.tsx +1848 -976
  78. package/src/inspect.ts +156 -33
  79. package/src/intl-polyfill.d.ts +139 -0
  80. package/src/{kv.tsx → kv.ts} +199 -67
  81. package/src/logger.ts +66 -0
  82. package/src/miniflare-cli/README.md +30 -0
  83. package/src/miniflare-cli/enum-keys.ts +17 -0
  84. package/src/miniflare-cli/index.ts +41 -0
  85. package/src/miniflare-cli/request-context.ts +40 -0
  86. package/src/module-collection.ts +229 -35
  87. package/src/open-in-browser.ts +19 -0
  88. package/src/package-manager.ts +174 -0
  89. package/src/pages.tsx +1162 -100
  90. package/src/parse.ts +203 -0
  91. package/src/paths.ts +26 -0
  92. package/src/proxy.ts +227 -51
  93. package/src/publish.ts +633 -276
  94. package/src/r2.ts +50 -0
  95. package/src/selfsigned.d.ts +29 -0
  96. package/src/sites.tsx +270 -62
  97. package/src/tail/filters.ts +279 -0
  98. package/src/tail/index.ts +299 -0
  99. package/src/tail/printing.ts +67 -0
  100. package/src/update-check.ts +19 -0
  101. package/src/user.tsx +382 -195
  102. package/src/whoami.tsx +71 -0
  103. package/src/{api/worker.ts → worker.ts} +66 -40
  104. package/src/zones.ts +73 -0
  105. package/templates/gitignore +171 -0
  106. package/templates/new-worker-scheduled.js +17 -0
  107. package/templates/new-worker-scheduled.ts +32 -0
  108. package/templates/new-worker.js +15 -0
  109. package/templates/new-worker.ts +30 -0
  110. package/{static-asset-facade.js → templates/static-asset-facade.js} +1 -5
  111. package/templates/tsconfig.json +105 -0
  112. package/wrangler-dist/cli.js +106332 -103741
  113. package/src/__tests__/mock-dialogs.ts +0 -65
  114. package/src/__tests__/run-in-tmp.ts +0 -19
  115. package/src/__tests__/run-wrangler.ts +0 -32
  116. package/src/api/form_data.ts +0 -131
  117. package/src/api/preview.ts +0 -128
  118. package/src/config.ts +0 -487
  119. package/src/dev.tsx +0 -784
  120. package/src/tail.tsx +0 -73
  121. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  122. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  123. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  124. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  125. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  126. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  127. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  128. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  129. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  130. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  131. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  132. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  133. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  134. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  135. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  136. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  137. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  138. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  139. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  140. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  141. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  142. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  143. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  144. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  145. package/vendor/wrangler-mime/LICENSE +0 -21
  146. package/vendor/wrangler-mime/Mime.js +0 -97
  147. package/vendor/wrangler-mime/README.md +0 -187
  148. package/vendor/wrangler-mime/cli.js +0 -46
  149. package/vendor/wrangler-mime/index.js +0 -4
  150. package/vendor/wrangler-mime/lite.js +0 -4
  151. package/vendor/wrangler-mime/package.json +0 -52
  152. package/vendor/wrangler-mime/types/other.js +0 -1
  153. package/vendor/wrangler-mime/types/standard.js +0 -1
  154. package/wrangler-dist/cli.js.map +0 -7
@@ -1,287 +1,257 @@
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 * 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";
7
8
 
8
9
  describe("wrangler", () => {
10
+ let mockPackageManager: PackageManager;
9
11
  runInTempDir();
10
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
+
24
+ const std = mockConsoleMethods();
25
+
11
26
  describe("no command", () => {
12
27
  it("should display a list of available commands", async () => {
13
- const { stdout, stderr } = await runWrangler();
28
+ await runWrangler();
14
29
 
15
- expect(stdout).toMatchInlineSnapshot(`
30
+ expect(std.out).toMatchInlineSnapshot(`
16
31
  "wrangler
17
32
 
18
33
  Commands:
19
34
  wrangler init [name] 📥 Create a wrangler.toml configuration file
20
- wrangler dev <filename> 👂 Start a local server for developing your worker
35
+ wrangler dev [script] 👂 Start a local server for developing your worker
21
36
  wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
22
- 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.
23
38
  wrangler secret 🤫 Generate a secret that can be referenced in the worker script
24
39
  wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
25
40
  wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
26
41
  wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
27
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
28
47
 
29
48
  Flags:
30
49
  -c, --config Path to .toml configuration file [string]
31
50
  -h, --help Show help [boolean]
32
- -v, --version Show version number [boolean]
33
-
34
- Options:
35
- -l, --local Run on my machine [boolean] [default: false]"
51
+ -v, --version Show version number [boolean]"
36
52
  `);
37
53
 
38
- expect(stderr).toMatchInlineSnapshot(`""`);
54
+ expect(std.err).toMatchInlineSnapshot(`""`);
39
55
  });
40
56
  });
41
57
 
42
58
  describe("invalid command", () => {
43
59
  it("should display an error", async () => {
44
- const { error, stdout, stderr } = await runWrangler("invalid-command");
60
+ await expect(
61
+ runWrangler("invalid-command")
62
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
63
+ `"Unknown argument: invalid-command"`
64
+ );
45
65
 
46
- expect(stdout).toMatchInlineSnapshot(`""`);
47
- expect(stderr).toMatchInlineSnapshot(`
48
- "wrangler
66
+ expect(std.out).toMatchInlineSnapshot(`
67
+ "
68
+ wrangler
49
69
 
50
70
  Commands:
51
71
  wrangler init [name] 📥 Create a wrangler.toml configuration file
52
- wrangler dev <filename> 👂 Start a local server for developing your worker
72
+ wrangler dev [script] 👂 Start a local server for developing your worker
53
73
  wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
54
- 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.
55
75
  wrangler secret 🤫 Generate a secret that can be referenced in the worker script
56
76
  wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
57
77
  wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
58
78
  wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
59
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
60
84
 
61
85
  Flags:
62
86
  -c, --config Path to .toml configuration file [string]
63
87
  -h, --help Show help [boolean]
64
- -v, --version Show version number [boolean]
65
-
66
- Options:
67
- -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
68
92
 
69
- Unknown command: invalid-command."
93
+ "
70
94
  `);
71
- expect(error).toMatchInlineSnapshot(
72
- `[Error: Unknown command: invalid-command.]`
73
- );
74
95
  });
75
96
  });
76
97
 
77
- describe("init", () => {
78
- it("should create a wrangler.toml", async () => {
79
- mockConfirm({
80
- text: "No package.json found. Would you like to create one?",
81
- result: false,
82
- });
83
- await runWrangler("init");
84
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
85
- expect(typeof parsed.compatibility_date).toBe("string");
86
- expect(fs.existsSync("./package.json")).toBe(false);
87
- 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
+ `);
88
114
  });
115
+ });
89
116
 
90
- it("should display warning when wrangler.toml already exists, and exit if user does not want to carry on", async () => {
91
- fs.writeFileSync("./wrangler.toml", "", "utf-8");
92
- mockConfirm({
93
- text: "Do you want to continue initializing this project?",
94
- result: false,
95
- });
96
- const { warnings } = await runWrangler("init");
97
- expect(warnings).toContain("wrangler.toml file already exists!");
98
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
99
- expect(typeof parsed.compatibility_date).toBe("undefined");
100
- });
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
101
123
 
102
- it("should display warning when wrangler.toml already exists, but continue if user does want to carry on", async () => {
103
- fs.writeFileSync("./wrangler.toml", "", "utf-8");
104
- mockConfirm(
105
- {
106
- text: "Do you want to continue initializing this project?",
107
- result: true,
108
- },
109
- {
110
- text: "No package.json found. Would you like to create one?",
111
- result: false,
112
- }
113
- );
114
- const { warnings } = await runWrangler("init");
115
- expect(warnings).toContain("wrangler.toml file already exists!");
116
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
117
- expect(typeof parsed.compatibility_date).toBe("string");
118
- });
124
+ 🤫 Generate a secret that can be referenced in the worker script
119
125
 
120
- it("should create a package.json if none is found and user confirms", async () => {
121
- mockConfirm(
122
- {
123
- text: "No package.json found. Would you like to create one?",
124
- result: true,
125
- },
126
- {
127
- text: "Would you like to use typescript?",
128
- result: false,
129
- }
130
- );
131
- await runWrangler("init");
132
- expect(fs.existsSync("./package.json")).toBe(true);
133
- const packageJson = JSON.parse(
134
- fs.readFileSync("./package.json", "utf-8")
135
- );
136
- expect(packageJson.name).toEqual("worker"); // TODO: should we infer the name from the directory?
137
- expect(packageJson.version).toEqual("0.0.1");
138
- 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
+ `);
139
136
  });
140
137
 
141
- it("should not touch an existing package.json in the same directory", async () => {
142
- mockConfirm({
143
- text: "Would you like to use typescript?",
144
- result: false,
145
- });
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
146
143
 
147
- fs.writeFileSync(
148
- "./package.json",
149
- JSON.stringify({ name: "test", version: "1.0.0" }),
150
- "utf-8"
151
- );
144
+ 🗂️ Interact with your Workers KV Namespaces
152
145
 
153
- await runWrangler("init");
154
- const packageJson = JSON.parse(
155
- fs.readFileSync("./package.json", "utf-8")
156
- );
157
- expect(packageJson.name).toEqual("test");
158
- expect(packageJson.version).toEqual("1.0.0");
159
- });
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.
160
150
 
161
- it("should not touch an existing package.json in an ancestor directory", async () => {
162
- mockConfirm({
163
- text: "Would you like to use typescript?",
164
- result: false,
165
- });
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
+ `);
156
+ });
166
157
 
167
- fs.writeFileSync(
168
- "./package.json",
169
- JSON.stringify({ name: "test", version: "1.0.0" }),
170
- "utf-8"
171
- );
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
172
163
 
173
- fs.mkdirSync("./sub-1/sub-2", { recursive: true });
174
- process.chdir("./sub-1/sub-2");
164
+ 🔑 Individually manage Workers KV key-value pairs
175
165
 
176
- await runWrangler("init");
177
- expect(fs.existsSync("./package.json")).toBe(false);
178
- expect(fs.existsSync("../../package.json")).toBe(true);
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.
179
171
 
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");
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
+ `);
185
177
  });
186
178
 
187
- it("should create a tsconfig.json and install `workers-types` if none is found and user confirms", async () => {
188
- mockConfirm(
189
- {
190
- text: "No package.json found. Would you like to create one?",
191
- result: true,
192
- },
193
- {
194
- text: "Would you like to use typescript?",
195
- result: true,
196
- }
197
- );
198
- await runWrangler("init");
199
- expect(fs.existsSync("./tsconfig.json")).toBe(true);
200
- const tsconfigJson = JSON.parse(
201
- fs.readFileSync("./tsconfig.json", "utf-8")
202
- );
203
- expect(tsconfigJson.compilerOptions.types).toEqual([
204
- "@cloudflare/workers-types",
205
- ]);
206
- const packageJson = JSON.parse(
207
- fs.readFileSync("./package.json", "utf-8")
208
- );
209
- expect(packageJson.devDependencies).toEqual({
210
- "@cloudflare/workers-types": expect.any(String),
211
- });
212
- });
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
213
184
 
214
- it("should not touch an existing tsconfig.json in the same directory", async () => {
215
- fs.writeFileSync(
216
- "./package.json",
217
- JSON.stringify({ name: "test", version: "1.0.0" }),
218
- "utf-8"
219
- );
220
- fs.writeFileSync(
221
- "./tsconfig.json",
222
- JSON.stringify({ compilerOptions: {} }),
223
- "utf-8"
224
- );
185
+ 💪 Interact with multiple Workers KV key-value pairs at once
225
186
 
226
- await runWrangler("init");
227
- const tsconfigJson = JSON.parse(
228
- fs.readFileSync("./tsconfig.json", "utf-8")
229
- );
230
- expect(tsconfigJson.compilerOptions).toEqual({});
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
190
+
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
+ `);
231
196
  });
232
197
 
233
- it("should not touch an existing package.json in an ancestor directory", async () => {
234
- fs.writeFileSync(
235
- "./package.json",
236
- JSON.stringify({ name: "test", version: "1.0.0" }),
237
- "utf-8"
238
- );
239
- fs.writeFileSync(
240
- "./tsconfig.json",
241
- JSON.stringify({ compilerOptions: {} }),
242
- "utf-8"
243
- );
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
244
203
 
245
- fs.mkdirSync("./sub-1/sub-2", { recursive: true });
246
- process.chdir("./sub-1/sub-2");
204
+ 📦 Interact with an R2 store
247
205
 
248
- await runWrangler("init");
249
- expect(fs.existsSync("./tsconfig.json")).toBe(false);
250
- expect(fs.existsSync("../../tsconfig.json")).toBe(true);
206
+ Commands:
207
+ wrangler r2 bucket Manage R2 buckets
251
208
 
252
- const tsconfigJson = JSON.parse(
253
- fs.readFileSync("../../tsconfig.json", "utf-8")
254
- );
255
- expect(tsconfigJson.compilerOptions).toEqual({});
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
+ `);
256
214
  });
215
+ });
257
216
 
258
- it("should error if `--type` is used", async () => {
259
- const { error } = await runWrangler("init --type");
260
- expect(error).toMatchInlineSnapshot(
261
- `[Error: The --type option is no longer supported.]`
262
- );
263
- });
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:
264
224
 
265
- it("should error if `--type javascript` is used", async () => {
266
- const { error } = await runWrangler("init --type javascript");
267
- expect(error).toMatchInlineSnapshot(
268
- `[Error: The --type option is no longer supported.]`
269
- );
270
- });
225
+ \`\`\`
226
+ git clone https://github.com/cloudflare/worker-template
227
+ \`\`\`
271
228
 
272
- it("should error if `--type rust` is used", async () => {
273
- const { error } = await runWrangler("init --type rust");
274
- expect(error).toMatchInlineSnapshot(
275
- `[Error: The --type option is no longer supported.]`
276
- );
229
+ Please refer to https://developers.cloudflare.com/workers/wrangler/deprecations/#generate for more information."
230
+ `);
231
+ });
277
232
  });
233
+ });
278
234
 
279
- it("should error if `--type webpack` is used", async () => {
280
- const { error } = await runWrangler("init --type webpack");
281
- expect(error).toMatchInlineSnapshot(`
282
- [Error: The --type option is no longer supported.
283
- If you wish to use webpack then you will need to create a custom build.]
284
- `);
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",
285
238
  });
239
+ writeWorkerSource();
240
+ await runWrangler("build");
241
+ await endEventLoop();
242
+ expect(std.out).toMatchInlineSnapshot(`
243
+ "▲ [WARNING] Deprecation: \`wrangler build\` has been deprecated.
244
+
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:
248
+
249
+
250
+ --dry-run: exiting now."
251
+ `);
286
252
  });
287
253
  });
254
+
255
+ function endEventLoop() {
256
+ return new Promise((resolve) => setImmediate(resolve));
257
+ }