wrangler 0.0.0-e2f9bb2 → 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 (103) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +3 -1
  3. package/bin/wrangler.js +36 -4
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +15 -7
  6. package/pages/functions/buildPlugin.ts +13 -0
  7. package/pages/functions/buildWorker.ts +14 -1
  8. package/pages/functions/template-plugin.ts +3 -2
  9. package/src/__tests__/configuration.test.ts +652 -229
  10. package/src/__tests__/dev.test.tsx +372 -79
  11. package/src/__tests__/helpers/mock-cfetch.ts +2 -2
  12. package/src/__tests__/helpers/mock-console.ts +11 -1
  13. package/src/__tests__/helpers/mock-dialogs.ts +75 -11
  14. package/src/__tests__/helpers/mock-process.ts +24 -0
  15. package/src/__tests__/index.test.ts +81 -72
  16. package/src/__tests__/init.test.ts +1360 -410
  17. package/src/__tests__/jest.setup.ts +38 -0
  18. package/src/__tests__/kv.test.ts +218 -152
  19. package/src/__tests__/logger.test.ts +26 -0
  20. package/src/__tests__/package-manager.test.ts +154 -7
  21. package/src/__tests__/pages.test.ts +478 -53
  22. package/src/__tests__/parse.test.ts +8 -0
  23. package/src/__tests__/publish.test.ts +1614 -333
  24. package/src/__tests__/r2.test.ts +55 -36
  25. package/src/__tests__/secret.test.ts +39 -4
  26. package/src/__tests__/user.test.ts +1 -0
  27. package/src/__tests__/whoami.test.tsx +34 -0
  28. package/src/abort.d.ts +3 -0
  29. package/src/bundle-reporter.tsx +29 -0
  30. package/src/bundle.ts +42 -7
  31. package/src/cfetch/index.ts +21 -4
  32. package/src/cfetch/internal.ts +25 -20
  33. package/src/config/config.ts +11 -2
  34. package/src/config/environment.ts +41 -15
  35. package/src/config/index.ts +162 -0
  36. package/src/config/validation-helpers.ts +10 -1
  37. package/src/config/validation.ts +234 -78
  38. package/src/create-worker-preview.ts +32 -22
  39. package/src/create-worker-upload-form.ts +22 -8
  40. package/src/dev/dev.tsx +48 -67
  41. package/src/dev/local.tsx +16 -7
  42. package/src/dev/remote.tsx +57 -21
  43. package/src/dev/use-esbuild.ts +1 -7
  44. package/src/dialogs.tsx +48 -0
  45. package/src/durable.ts +102 -0
  46. package/src/entry.ts +71 -10
  47. package/src/generate-auth-url.ts +33 -0
  48. package/src/generate-random-state.ts +16 -0
  49. package/src/git-client.ts +42 -0
  50. package/src/index.tsx +619 -338
  51. package/src/inspect.ts +39 -0
  52. package/src/kv.ts +116 -27
  53. package/src/logger.ts +8 -1
  54. package/src/open-in-browser.ts +3 -12
  55. package/src/package-manager.ts +50 -3
  56. package/src/pages.tsx +434 -207
  57. package/src/parse.ts +44 -5
  58. package/src/proxy.ts +66 -44
  59. package/src/publish.ts +407 -137
  60. package/src/sites.tsx +103 -28
  61. package/src/user.tsx +35 -26
  62. package/src/whoami.tsx +3 -2
  63. package/src/worker.ts +10 -1
  64. package/src/zones.ts +73 -0
  65. package/templates/new-worker-scheduled.js +17 -0
  66. package/templates/new-worker-scheduled.ts +32 -0
  67. package/templates/new-worker.ts +16 -1
  68. package/templates/no-op-worker.js +10 -0
  69. package/templates/static-asset-facade.js +2 -6
  70. package/wrangler-dist/cli.js +46122 -32396
  71. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  72. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  73. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  74. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  75. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  76. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  77. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  78. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  79. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  80. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  81. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  82. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  83. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  84. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  85. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  86. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  87. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  88. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  89. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  90. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  91. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  92. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  93. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  94. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  95. package/vendor/wrangler-mime/LICENSE +0 -21
  96. package/vendor/wrangler-mime/Mime.js +0 -97
  97. package/vendor/wrangler-mime/README.md +0 -187
  98. package/vendor/wrangler-mime/cli.js +0 -46
  99. package/vendor/wrangler-mime/index.js +0 -4
  100. package/vendor/wrangler-mime/lite.js +0 -4
  101. package/vendor/wrangler-mime/package.json +0 -52
  102. package/vendor/wrangler-mime/types/other.js +0 -1
  103. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -1,4 +1,5 @@
1
- import { confirm, prompt } from "../../dialogs";
1
+ import { confirm, prompt, select } from "../../dialogs";
2
+ import { normalizeSlashes } from "./mock-console";
2
3
 
3
4
  /**
4
5
  * The expected values for a confirmation request.
@@ -19,13 +20,22 @@ export interface ConfirmExpectation {
19
20
  */
20
21
  export function mockConfirm(...expectations: ConfirmExpectation[]) {
21
22
  (confirm as jest.Mock).mockImplementation((text: string) => {
22
- for (const { text: expectedText, result } of expectations) {
23
- if (text === expectedText) {
24
- return Promise.resolve(result);
23
+ for (const expectation of expectations) {
24
+ if (normalizeSlashes(text) === normalizeSlashes(expectation.text)) {
25
+ expectations = expectations.filter((e) => e !== expectation);
26
+ return Promise.resolve(expectation.result);
25
27
  }
26
28
  }
27
29
  throw new Error(`Unexpected confirmation message: ${text}`);
28
30
  });
31
+ return () => {
32
+ if (expectations.length > 0) {
33
+ throw new Error(
34
+ "The following expected confirmation dialogs were not used:\n" +
35
+ expectations.map((e) => `- "${e.text}"`).join("\n")
36
+ );
37
+ }
38
+ };
29
39
  }
30
40
 
31
41
  export function clearConfirmMocks() {
@@ -62,18 +72,23 @@ export interface PromptExpectation {
62
72
  export function mockPrompt(...expectations: PromptExpectation[]) {
63
73
  (prompt as jest.Mock).mockImplementation(
64
74
  (text: string, type: "text" | "password") => {
65
- for (const {
66
- text: expectedText,
67
- type: expectedType,
68
- result,
69
- } of expectations) {
70
- if (text === expectedText && type == expectedType) {
71
- return Promise.resolve(result);
75
+ for (const expectation of expectations) {
76
+ if (text === expectation.text && type == expectation.type) {
77
+ expectations = expectations.filter((e) => e !== expectation);
78
+ return Promise.resolve(expectation.result);
72
79
  }
73
80
  }
74
81
  throw new Error(`Unexpected confirmation message: ${text}`);
75
82
  }
76
83
  );
84
+ return () => {
85
+ if (expectations.length > 0) {
86
+ throw new Error(
87
+ "The following expected prompt dialogs were not used:\n" +
88
+ expectations.map((e) => `- "${e.text}"`).join("\n")
89
+ );
90
+ }
91
+ };
77
92
  }
78
93
 
79
94
  export function clearPromptMocks() {
@@ -87,3 +102,52 @@ export function clearPromptMocks() {
87
102
  );
88
103
  });
89
104
  }
105
+
106
+ /**
107
+ * The expected values for a select request.
108
+ */
109
+ export interface SelectExpectation {
110
+ /** The text expected to be seen in the select dialog. */
111
+ text: string;
112
+ /** The mock response send back from the select dialog. */
113
+ result: string;
114
+ }
115
+
116
+ /**
117
+ * Mock the implementation of `select()` that will respond with configured results
118
+ * for configured select text messages.
119
+ *
120
+ * If there is a call to `select()` that does not match any of the expectations
121
+ * then an error is thrown.
122
+ */
123
+ export function mockSelect(...expectations: SelectExpectation[]) {
124
+ (select as jest.Mock).mockImplementation((text: string) => {
125
+ for (const expectation of expectations) {
126
+ if (normalizeSlashes(text) === normalizeSlashes(expectation.text)) {
127
+ expectations = expectations.filter((e) => e !== expectation);
128
+ return Promise.resolve(expectation.result);
129
+ }
130
+ }
131
+ throw new Error(`Unexpected select message: ${text}`);
132
+ });
133
+ return () => {
134
+ if (expectations.length > 0) {
135
+ throw new Error(
136
+ "The following expected select dialogs were not used:\n" +
137
+ expectations.map((e) => `- "${e.text}"`).join("\n")
138
+ );
139
+ }
140
+ };
141
+ }
142
+
143
+ export function clearSelectMocks() {
144
+ (select as jest.Mock).mockReset();
145
+ // Because select was originally a spy, calling mockReset will simply reset
146
+ // it as a function with no return value (!), so we need to additionally reset
147
+ // the mock implementation to the one that throws (from jest.setup.js).
148
+ (select as jest.Mock).mockImplementation((text: string) => {
149
+ throw new Error(
150
+ `Unexpected call to \`select("${text}")\`.\nYou should use \`mockSelect()\` to mock calls to \`select()\` with expectations. Search the codebase for \`mockSelect\` to learn more.`
151
+ );
152
+ });
153
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * We use this module to mock process methods (write only for now),
3
+ * and optionally assert on the values they're called with in our tests.
4
+ */
5
+
6
+ let writeSpy: jest.SpyInstance;
7
+
8
+ function captureWriteCall(spy: jest.SpyInstance): Buffer {
9
+ return spy.mock.calls[0]?.[0] ?? Buffer.alloc(0);
10
+ }
11
+
12
+ export function mockProcess() {
13
+ beforeEach(() => {
14
+ writeSpy = jest.spyOn(process.stdout, "write").mockImplementation();
15
+ });
16
+ afterEach(() => {
17
+ writeSpy.mockRestore();
18
+ });
19
+ return {
20
+ get write() {
21
+ return captureWriteCall(writeSpy);
22
+ },
23
+ };
24
+ }
@@ -2,6 +2,8 @@ import { getPackageManager } from "../package-manager";
2
2
  import { mockConsoleMethods } from "./helpers/mock-console";
3
3
  import { runInTempDir } from "./helpers/run-in-tmp";
4
4
  import { runWrangler } from "./helpers/run-wrangler";
5
+ import { writeWorkerSource } from "./helpers/write-worker-source";
6
+ import writeWranglerToml from "./helpers/write-wrangler-toml";
5
7
  import type { PackageManager } from "../package-manager";
6
8
 
7
9
  describe("wrangler", () => {
@@ -44,10 +46,9 @@ describe("wrangler", () => {
44
46
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
45
47
 
46
48
  Flags:
47
- -c, --config Path to .toml configuration file [string]
48
- -h, --help Show help [boolean]
49
- -v, --version Show version number [boolean]
50
- --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]"
51
52
  `);
52
53
 
53
54
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -64,10 +65,7 @@ describe("wrangler", () => {
64
65
 
65
66
  expect(std.out).toMatchInlineSnapshot(`
66
67
  "
67
- "
68
- `);
69
- expect(std.err).toMatchInlineSnapshot(`
70
- "wrangler
68
+ wrangler
71
69
 
72
70
  Commands:
73
71
  wrangler init [name] 📥 Create a wrangler.toml configuration file
@@ -85,11 +83,12 @@ describe("wrangler", () => {
85
83
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
86
84
 
87
85
  Flags:
88
- -c, --config Path to .toml configuration file [string]
89
- -h, --help Show help [boolean]
90
- -v, --version Show version number [boolean]
91
- --legacy-env Use legacy environments [boolean]
92
- X [ERROR] Unknown argument: invalid-command
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
+ "X [ERROR] Unknown argument: invalid-command
93
92
 
94
93
  "
95
94
  `);
@@ -116,9 +115,6 @@ describe("wrangler", () => {
116
115
  });
117
116
 
118
117
  describe("subcommand implicit help ran on incomplete command execution", () => {
119
- function endEventLoop() {
120
- return new Promise((resolve) => setImmediate(resolve));
121
- }
122
118
  it("no subcommand for 'secret' should display a list of available subcommands", async () => {
123
119
  await runWrangler("secret");
124
120
  await endEventLoop();
@@ -133,10 +129,9 @@ describe("wrangler", () => {
133
129
  wrangler secret list List all secrets for a script
134
130
 
135
131
  Flags:
136
- -c, --config Path to .toml configuration file [string]
137
- -h, --help Show help [boolean]
138
- -v, --version Show version number [boolean]
139
- --legacy-env Use legacy environments [boolean]"
132
+ -c, --config Path to .toml configuration file [string]
133
+ -h, --help Show help [boolean]
134
+ -v, --version Show version number [boolean]"
140
135
  `);
141
136
  });
142
137
 
@@ -144,20 +139,19 @@ describe("wrangler", () => {
144
139
  await runWrangler("kv:namespace");
145
140
  await endEventLoop();
146
141
  expect(std.out).toMatchInlineSnapshot(`
147
- "wrangler kv:namespace
142
+ "wrangler kv:namespace
148
143
 
149
- 🗂️ Interact with your Workers KV Namespaces
144
+ 🗂️ Interact with your Workers KV Namespaces
150
145
 
151
- Commands:
152
- wrangler kv:namespace create <namespace> Create a new namespace
153
- wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
154
- wrangler kv:namespace delete Deletes a given namespace.
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.
155
150
 
156
- Flags:
157
- -c, --config Path to .toml configuration file [string]
158
- -h, --help Show help [boolean]
159
- -v, --version Show version number [boolean]
160
- --legacy-env Use legacy environments [boolean]"
151
+ Flags:
152
+ -c, --config Path to .toml configuration file [string]
153
+ -h, --help Show help [boolean]
154
+ -v, --version Show version number [boolean]"
161
155
  `);
162
156
  });
163
157
 
@@ -165,62 +159,61 @@ describe("wrangler", () => {
165
159
  await runWrangler("kv:key");
166
160
  await endEventLoop();
167
161
  expect(std.out).toMatchInlineSnapshot(`
168
- "wrangler kv:key
162
+ "wrangler kv:key
169
163
 
170
- 🔑 Individually manage Workers KV key-value pairs
164
+ 🔑 Individually manage Workers KV key-value pairs
171
165
 
172
- Commands:
173
- wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
174
- wrangler kv:key list Outputs a list of all keys in a given namespace.
175
- wrangler kv:key get <key> Reads a single value by key from the given namespace.
176
- wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
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.
177
171
 
178
- Flags:
179
- -c, --config Path to .toml configuration file [string]
180
- -h, --help Show help [boolean]
181
- -v, --version Show version number [boolean]
182
- --legacy-env Use legacy environments [boolean]"
183
- `);
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
+ `);
184
177
  });
185
178
 
186
179
  it("no subcommand 'kv:bulk' should display a list of available subcommands", async () => {
187
180
  await runWrangler("kv:bulk");
188
181
  await endEventLoop();
189
182
  expect(std.out).toMatchInlineSnapshot(`
190
- "wrangler kv:bulk
183
+ "wrangler kv:bulk
191
184
 
192
- 💪 Interact with multiple Workers KV key-value pairs at once
185
+ 💪 Interact with multiple Workers KV key-value pairs at once
193
186
 
194
- Commands:
195
- wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
196
- wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
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
197
190
 
198
- Flags:
199
- -c, --config Path to .toml configuration file [string]
200
- -h, --help Show help [boolean]
201
- -v, --version Show version number [boolean]
202
- --legacy-env Use legacy environments [boolean]"
203
- `);
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
+ `);
204
196
  });
197
+
205
198
  it("no subcommand 'r2' should display a list of available subcommands", async () => {
206
199
  await runWrangler("r2");
207
200
  await endEventLoop();
208
201
  expect(std.out).toMatchInlineSnapshot(`
209
- "wrangler r2
202
+ "wrangler r2
210
203
 
211
- 📦 Interact with an R2 store
204
+ 📦 Interact with an R2 store
212
205
 
213
- Commands:
214
- wrangler r2 bucket Manage R2 buckets
206
+ Commands:
207
+ wrangler r2 bucket Manage R2 buckets
215
208
 
216
- Flags:
217
- -c, --config Path to .toml configuration file [string]
218
- -h, --help Show help [boolean]
219
- -v, --version Show version number [boolean]
220
- --legacy-env Use legacy environments [boolean]"
221
- `);
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
+ `);
222
214
  });
223
215
  });
216
+
224
217
  describe("Deprecated commands", () => {
225
218
  it("should print a deprecation message for 'generate'", async () => {
226
219
  await runWrangler("generate").catch((err) => {
@@ -237,13 +230,29 @@ describe("wrangler", () => {
237
230
  `);
238
231
  });
239
232
  });
240
- it("should print a deprecation message for 'build'", async () => {
241
- await runWrangler("build").catch((err) => {
242
- expect(err.message).toMatchInlineSnapshot(`
243
- "Deprecation:
244
- \`wrangler build\` has been deprecated, please refer to https://github.com/cloudflare/wrangler2/blob/main/docs/deprecations.md#build for alternatives"
245
- `);
246
- });
233
+ });
234
+
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",
247
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
+ Total Upload: 0xx KiB / gzip: 0xx KiB"
252
+ `);
248
253
  });
249
254
  });
255
+
256
+ function endEventLoop() {
257
+ return new Promise((resolve) => setImmediate(resolve));
258
+ }