wrangler 0.0.0-bf67bf2 → 0.0.0-bfbb0be

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 (179) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +27 -14
  3. package/bin/wrangler.js +106 -5
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +4886 -0
  6. package/package.json +76 -36
  7. package/src/__tests__/config-cache.test.ts +36 -0
  8. package/src/__tests__/configuration.test.ts +3548 -0
  9. package/src/__tests__/dev.test.tsx +1055 -0
  10. package/src/__tests__/guess-worker-format.test.ts +85 -0
  11. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  12. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  15. package/src/__tests__/helpers/mock-bin.ts +36 -0
  16. package/src/__tests__/helpers/mock-cfetch.ts +211 -0
  17. package/src/__tests__/helpers/mock-console.ts +97 -0
  18. package/src/__tests__/helpers/mock-dialogs.ts +153 -0
  19. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  20. package/src/__tests__/helpers/mock-istty.ts +32 -0
  21. package/src/__tests__/helpers/mock-kv.ts +33 -0
  22. package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
  23. package/src/__tests__/helpers/mock-process.ts +39 -0
  24. package/src/__tests__/helpers/mock-stdin.ts +108 -0
  25. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  26. package/src/__tests__/helpers/run-in-tmp.ts +39 -0
  27. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  28. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  29. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  30. package/src/__tests__/https-options.test.ts +130 -0
  31. package/src/__tests__/index.test.ts +235 -130
  32. package/src/__tests__/init.test.ts +1992 -0
  33. package/src/__tests__/jest.setup.ts +107 -0
  34. package/src/__tests__/kv.test.ts +1619 -0
  35. package/src/__tests__/logger.test.ts +141 -0
  36. package/src/__tests__/package-manager.test.ts +353 -0
  37. package/src/__tests__/pages.test.ts +1242 -0
  38. package/src/__tests__/parse.test.ts +330 -0
  39. package/src/__tests__/publish.test.ts +6188 -0
  40. package/src/__tests__/r2.test.ts +233 -0
  41. package/src/__tests__/route.test.ts +45 -0
  42. package/src/__tests__/secret.test.ts +486 -0
  43. package/src/__tests__/tail.test.ts +690 -0
  44. package/src/__tests__/user.test.ts +132 -0
  45. package/src/__tests__/whoami.test.tsx +139 -0
  46. package/src/abort.d.ts +3 -0
  47. package/src/bundle-reporter.tsx +29 -0
  48. package/src/bundle.ts +204 -0
  49. package/src/cfetch/index.ts +121 -0
  50. package/src/cfetch/internal.ts +142 -0
  51. package/src/cli.ts +10 -7
  52. package/src/config/README.md +107 -0
  53. package/src/config/config.ts +243 -0
  54. package/src/config/diagnostics.ts +80 -0
  55. package/src/config/environment.ts +420 -0
  56. package/src/config/index.ts +225 -0
  57. package/src/config/validation-helpers.ts +584 -0
  58. package/src/config/validation.ts +1580 -0
  59. package/src/config-cache.ts +44 -0
  60. package/src/create-worker-preview.ts +185 -0
  61. package/src/create-worker-upload-form.ts +254 -0
  62. package/src/dev/dev-vars.ts +36 -0
  63. package/src/dev/dev.tsx +399 -0
  64. package/src/dev/local.tsx +321 -0
  65. package/src/dev/remote.tsx +282 -0
  66. package/src/dev/use-esbuild.ts +112 -0
  67. package/src/dialogs.tsx +68 -18
  68. package/src/durable.ts +102 -0
  69. package/src/entry.ts +328 -0
  70. package/src/environment-variables.ts +35 -0
  71. package/src/errors.ts +11 -0
  72. package/src/git-client.ts +42 -0
  73. package/src/https-options.ts +123 -0
  74. package/src/index.tsx +2092 -1029
  75. package/src/inspect.ts +662 -0
  76. package/src/intl-polyfill.d.ts +139 -0
  77. package/src/kv.ts +408 -0
  78. package/src/logger.ts +73 -0
  79. package/src/miniflare-cli/README.md +30 -0
  80. package/src/miniflare-cli/enum-keys.ts +17 -0
  81. package/src/miniflare-cli/index.ts +41 -0
  82. package/src/miniflare-cli/request-context.ts +40 -0
  83. package/src/module-collection.ts +258 -0
  84. package/src/open-in-browser.ts +17 -0
  85. package/src/package-manager.ts +174 -0
  86. package/src/pages/build.tsx +202 -0
  87. package/src/pages/constants.ts +7 -0
  88. package/src/pages/deployments.tsx +101 -0
  89. package/src/pages/dev.tsx +948 -0
  90. package/src/pages/functions/buildPlugin.ts +105 -0
  91. package/src/pages/functions/buildWorker.ts +151 -0
  92. package/src/pages/functions/filepath-routing.test.ts +234 -0
  93. package/src/pages/functions/filepath-routing.ts +189 -0
  94. package/src/pages/functions/identifiers.ts +78 -0
  95. package/src/pages/functions/routes.ts +151 -0
  96. package/src/pages/index.tsx +84 -0
  97. package/src/pages/projects.tsx +157 -0
  98. package/src/pages/publish.tsx +325 -0
  99. package/src/pages/types.ts +40 -0
  100. package/src/pages/upload.tsx +363 -0
  101. package/src/pages/utils.ts +12 -0
  102. package/src/parse.ts +222 -0
  103. package/src/paths.ts +26 -0
  104. package/src/proxy.ts +476 -0
  105. package/src/publish.ts +661 -272
  106. package/src/r2.ts +50 -0
  107. package/src/selfsigned.d.ts +29 -0
  108. package/src/sites.tsx +316 -59
  109. package/src/tail/filters.ts +279 -0
  110. package/src/tail/index.ts +299 -0
  111. package/src/tail/printing.ts +67 -0
  112. package/src/update-check.ts +19 -0
  113. package/src/user/choose-account.tsx +60 -0
  114. package/src/user/env-vars.ts +17 -0
  115. package/src/user/generate-auth-url.ts +33 -0
  116. package/src/user/generate-random-state.ts +16 -0
  117. package/src/user/index.ts +3 -0
  118. package/src/{user.tsx → user/user.tsx} +380 -276
  119. package/src/whoami.tsx +71 -0
  120. package/src/worker.ts +181 -0
  121. package/src/zones.ts +73 -0
  122. package/templates/gitignore +171 -0
  123. package/templates/new-worker-scheduled.js +17 -0
  124. package/templates/new-worker-scheduled.ts +32 -0
  125. package/templates/new-worker.js +15 -0
  126. package/templates/new-worker.ts +30 -0
  127. package/templates/no-op-worker.js +10 -0
  128. package/templates/pages-template-plugin.ts +155 -0
  129. package/templates/pages-template-worker.ts +161 -0
  130. package/{static-asset-facade.js → templates/static-asset-facade.js} +3 -7
  131. package/templates/tsconfig.json +105 -0
  132. package/wrangler-dist/cli.js +100313 -110298
  133. package/src/__tests__/fixtures/init/.gitkeep +0 -0
  134. package/src/__tests__/mock-cfetch.js +0 -46
  135. package/src/api/form_data.ts +0 -158
  136. package/src/api/inspect.ts +0 -441
  137. package/src/api/preview.ts +0 -123
  138. package/src/api/worker.ts +0 -157
  139. package/src/cfetch.ts +0 -72
  140. package/src/config.ts +0 -124
  141. package/src/dev.tsx +0 -736
  142. package/src/kv.tsx +0 -211
  143. package/src/pages.tsx +0 -340
  144. package/src/tail.tsx +0 -71
  145. package/src/util/fetch.ts +0 -74
  146. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  147. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  148. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  149. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  150. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  151. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  152. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  153. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  154. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  155. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  156. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  157. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  158. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  159. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  160. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  161. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  162. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  163. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  164. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  165. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  166. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  167. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  168. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  169. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  170. package/vendor/wrangler-mime/LICENSE +0 -21
  171. package/vendor/wrangler-mime/Mime.js +0 -97
  172. package/vendor/wrangler-mime/README.md +0 -187
  173. package/vendor/wrangler-mime/cli.js +0 -46
  174. package/vendor/wrangler-mime/index.js +0 -4
  175. package/vendor/wrangler-mime/lite.js +0 -4
  176. package/vendor/wrangler-mime/package.json +0 -52
  177. package/vendor/wrangler-mime/types/other.js +0 -1
  178. package/vendor/wrangler-mime/types/standard.js +0 -1
  179. package/wrangler-dist/cli.js.map +0 -7
@@ -0,0 +1,325 @@
1
+ import { execSync } from "node:child_process";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { dirname, join } from "node:path";
5
+ import { cwd } from "node:process";
6
+ import { render, Text } from "ink";
7
+ import SelectInput from "ink-select-input";
8
+ import React from "react";
9
+ import { File, FormData } from "undici";
10
+ import { fetchResult } from "../cfetch";
11
+ import { getConfigCache, saveToConfigCache } from "../config-cache";
12
+ import { prompt } from "../dialogs";
13
+ import { FatalError } from "../errors";
14
+ import { logger } from "../logger";
15
+ import { requireAuth } from "../user";
16
+ import { buildFunctions } from "./build";
17
+ import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
18
+ import { listProjects } from "./projects";
19
+ import { upload } from "./upload";
20
+ import { pagesBetaWarning } from "./utils";
21
+ import type { Deployment, PagesConfigCache, Project } from "./types";
22
+ import type { ArgumentsCamelCase, Argv } from "yargs";
23
+
24
+ type PublishArgs = {
25
+ directory: string;
26
+ "project-name"?: string;
27
+ branch?: string;
28
+ "commit-hash"?: string;
29
+ "commit-message"?: string;
30
+ "commit-dirty"?: boolean;
31
+ };
32
+
33
+ export function Options(yargs: Argv): Argv<PublishArgs> {
34
+ return yargs
35
+ .positional("directory", {
36
+ type: "string",
37
+ demandOption: true,
38
+ description: "The directory of static files to upload",
39
+ })
40
+ .options({
41
+ "project-name": {
42
+ type: "string",
43
+ description: "The name of the project you want to deploy to",
44
+ },
45
+ branch: {
46
+ type: "string",
47
+ description: "The name of the branch you want to deploy to",
48
+ },
49
+ "commit-hash": {
50
+ type: "string",
51
+ description: "The SHA to attach to this deployment",
52
+ },
53
+ "commit-message": {
54
+ type: "string",
55
+ description: "The commit message to attach to this deployment",
56
+ },
57
+ "commit-dirty": {
58
+ type: "boolean",
59
+ description:
60
+ "Whether or not the workspace should be considered dirty for this deployment",
61
+ },
62
+ })
63
+ .epilogue(pagesBetaWarning);
64
+ }
65
+
66
+ export const Handler = async ({
67
+ directory,
68
+ projectName,
69
+ branch,
70
+ commitHash,
71
+ commitMessage,
72
+ commitDirty,
73
+ }: ArgumentsCamelCase<PublishArgs>) => {
74
+ if (!directory) {
75
+ throw new FatalError("Must specify a directory.", 1);
76
+ }
77
+
78
+ const config = getConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME);
79
+ const accountId = await requireAuth(config);
80
+
81
+ projectName ??= config.project_name;
82
+
83
+ const isInteractive = process.stdin.isTTY;
84
+ if (!projectName && isInteractive) {
85
+ const projects = (await listProjects({ accountId })).filter(
86
+ (project) => !project.source
87
+ );
88
+
89
+ let existingOrNew: "existing" | "new" = "new";
90
+
91
+ if (projects.length > 0) {
92
+ existingOrNew = await new Promise<"new" | "existing">((resolve) => {
93
+ const { unmount } = render(
94
+ <>
95
+ <Text>
96
+ No project selected. Would you like to create one or use an
97
+ existing project?
98
+ </Text>
99
+ <SelectInput
100
+ items={[
101
+ {
102
+ key: "new",
103
+ label: "Create a new project",
104
+ value: "new",
105
+ },
106
+ {
107
+ key: "existing",
108
+ label: "Use an existing project",
109
+ value: "existing",
110
+ },
111
+ ]}
112
+ onSelect={async (selected) => {
113
+ resolve(selected.value as "new" | "existing");
114
+ unmount();
115
+ }}
116
+ />
117
+ </>
118
+ );
119
+ });
120
+ }
121
+
122
+ switch (existingOrNew) {
123
+ case "existing": {
124
+ projectName = await new Promise((resolve) => {
125
+ const { unmount } = render(
126
+ <>
127
+ <Text>Select a project:</Text>
128
+ <SelectInput
129
+ items={projects.map((project) => ({
130
+ key: project.name,
131
+ label: project.name,
132
+ value: project,
133
+ }))}
134
+ onSelect={async (selected) => {
135
+ resolve(selected.value.name);
136
+ unmount();
137
+ }}
138
+ />
139
+ </>
140
+ );
141
+ });
142
+ break;
143
+ }
144
+ case "new": {
145
+ projectName = await prompt("Enter the name of your new project:");
146
+
147
+ if (!projectName) {
148
+ throw new FatalError("Must specify a project name.", 1);
149
+ }
150
+
151
+ let isGitDir = true;
152
+ try {
153
+ execSync(`git rev-parse --is-inside-work-tree`, {
154
+ stdio: "ignore",
155
+ });
156
+ } catch (err) {
157
+ isGitDir = false;
158
+ }
159
+
160
+ const productionBranch = await prompt(
161
+ "Enter the production branch name:",
162
+ "text",
163
+ isGitDir
164
+ ? execSync(`git rev-parse --abbrev-ref HEAD`).toString().trim()
165
+ : "production"
166
+ );
167
+
168
+ if (!productionBranch) {
169
+ throw new FatalError("Must specify a production branch.", 1);
170
+ }
171
+
172
+ await fetchResult<Project>(`/accounts/${accountId}/pages/projects`, {
173
+ method: "POST",
174
+ body: JSON.stringify({
175
+ name: projectName,
176
+ production_branch: productionBranch,
177
+ }),
178
+ });
179
+
180
+ saveToConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME, {
181
+ account_id: accountId,
182
+ project_name: projectName,
183
+ });
184
+
185
+ logger.log(`✨ Successfully created the '${projectName}' project.`);
186
+ break;
187
+ }
188
+ }
189
+ }
190
+
191
+ if (!projectName) {
192
+ throw new FatalError("Must specify a project name.", 1);
193
+ }
194
+
195
+ // We infer git info by default is not passed in
196
+
197
+ let isGitDir = true;
198
+ try {
199
+ execSync(`git rev-parse --is-inside-work-tree`, {
200
+ stdio: "ignore",
201
+ });
202
+ } catch (err) {
203
+ isGitDir = false;
204
+ }
205
+
206
+ let isGitDirty = false;
207
+
208
+ if (isGitDir) {
209
+ try {
210
+ isGitDirty = Boolean(
211
+ execSync(`git status --porcelain`).toString().length
212
+ );
213
+
214
+ if (!branch) {
215
+ branch = execSync(`git rev-parse --abbrev-ref HEAD`).toString().trim();
216
+ }
217
+
218
+ if (!commitHash) {
219
+ commitHash = execSync(`git rev-parse HEAD`).toString().trim();
220
+ }
221
+
222
+ if (!commitMessage) {
223
+ commitMessage = execSync(`git show -s --format=%B ${commitHash}`)
224
+ .toString()
225
+ .trim();
226
+ }
227
+ } catch (err) {}
228
+
229
+ if (isGitDirty && !commitDirty) {
230
+ logger.warn(
231
+ `Warning: Your working directory is a git repo and has uncommitted changes\nTo silence this warning, pass in --commit-dirty=true`
232
+ );
233
+ }
234
+
235
+ if (commitDirty === undefined) {
236
+ commitDirty = isGitDirty;
237
+ }
238
+ }
239
+
240
+ let builtFunctions: string | undefined = undefined;
241
+ const functionsDirectory = join(cwd(), "functions");
242
+ if (existsSync(functionsDirectory)) {
243
+ const outfile = join(tmpdir(), `./functionsWorker-${Math.random()}.js`);
244
+
245
+ await new Promise((resolve) =>
246
+ buildFunctions({
247
+ outfile,
248
+ functionsDirectory,
249
+ onEnd: () => resolve(null),
250
+ buildOutputDirectory: dirname(outfile),
251
+ })
252
+ );
253
+
254
+ builtFunctions = readFileSync(outfile, "utf-8");
255
+ }
256
+
257
+ const manifest = await upload({ directory, accountId, projectName });
258
+
259
+ const formData = new FormData();
260
+
261
+ formData.append("manifest", JSON.stringify(manifest));
262
+
263
+ if (branch) {
264
+ formData.append("branch", branch);
265
+ }
266
+
267
+ if (commitMessage) {
268
+ formData.append("commit_message", commitMessage);
269
+ }
270
+
271
+ if (commitHash) {
272
+ formData.append("commit_hash", commitHash);
273
+ }
274
+
275
+ if (commitDirty !== undefined) {
276
+ formData.append("commit_dirty", commitDirty);
277
+ }
278
+
279
+ let _headers: string | undefined,
280
+ _redirects: string | undefined,
281
+ _workerJS: string | undefined;
282
+
283
+ try {
284
+ _headers = readFileSync(join(directory, "_headers"), "utf-8");
285
+ } catch {}
286
+
287
+ try {
288
+ _redirects = readFileSync(join(directory, "_redirects"), "utf-8");
289
+ } catch {}
290
+
291
+ try {
292
+ _workerJS = readFileSync(join(directory, "_worker.js"), "utf-8");
293
+ } catch {}
294
+
295
+ if (_headers) {
296
+ formData.append("_headers", new File([_headers], "_headers"));
297
+ }
298
+
299
+ if (_redirects) {
300
+ formData.append("_redirects", new File([_redirects], "_redirects"));
301
+ }
302
+
303
+ if (builtFunctions) {
304
+ formData.append("_worker.js", new File([builtFunctions], "_worker.js"));
305
+ } else if (_workerJS) {
306
+ formData.append("_worker.js", new File([_workerJS], "_worker.js"));
307
+ }
308
+
309
+ const deploymentResponse = await fetchResult<Deployment>(
310
+ `/accounts/${accountId}/pages/projects/${projectName}/deployments`,
311
+ {
312
+ method: "POST",
313
+ body: formData,
314
+ }
315
+ );
316
+
317
+ saveToConfigCache<PagesConfigCache>(PAGES_CONFIG_CACHE_FILENAME, {
318
+ account_id: accountId,
319
+ project_name: projectName,
320
+ });
321
+
322
+ logger.log(
323
+ `✨ Deployment complete! Take a peek over at ${deploymentResponse.url}`
324
+ );
325
+ };
@@ -0,0 +1,40 @@
1
+ export type Project = {
2
+ name: string;
3
+ subdomain: string;
4
+ domains: Array<string>;
5
+ source?: {
6
+ type: string;
7
+ };
8
+ latest_deployment?: {
9
+ modified_on: string;
10
+ };
11
+ created_on: string;
12
+ production_branch: string;
13
+ };
14
+ export type Deployment = {
15
+ id: string;
16
+ environment: string;
17
+ deployment_trigger: {
18
+ metadata: {
19
+ commit_hash: string;
20
+ branch: string;
21
+ };
22
+ };
23
+ url: string;
24
+ latest_stage: {
25
+ status: string;
26
+ ended_on: string;
27
+ };
28
+ project_name: string;
29
+ };
30
+ export type UploadPayloadFile = {
31
+ key: string;
32
+ value: string;
33
+ metadata: { contentType: string };
34
+ base64: boolean;
35
+ };
36
+
37
+ export interface PagesConfigCache {
38
+ account_id?: string;
39
+ project_name?: string;
40
+ }