wrangler 0.0.0-bfbb0be → 0.0.0-bfbe49d0

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 (161) hide show
  1. package/README.md +29 -11
  2. package/bin/wrangler.js +99 -114
  3. package/package.json +194 -155
  4. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  5. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  6. package/templates/__tests__/tsconfig.json +8 -0
  7. package/templates/checked-fetch.js +30 -0
  8. package/templates/facade.d.ts +17 -0
  9. package/templates/gitignore +1 -0
  10. package/templates/init-tests/test-jest-new-worker.js +23 -0
  11. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  12. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  13. package/templates/middleware/common.ts +67 -0
  14. package/templates/middleware/loader-modules.ts +137 -0
  15. package/templates/middleware/loader-sw.ts +228 -0
  16. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  17. package/templates/middleware/middleware-d1-beta.ts +244 -0
  18. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  19. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  20. package/templates/middleware/middleware-multiworker-dev.ts +59 -0
  21. package/templates/middleware/middleware-pretty-error.ts +40 -0
  22. package/templates/middleware/middleware-scheduled.ts +15 -0
  23. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  24. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  25. package/templates/new-worker-scheduled.js +3 -3
  26. package/templates/new-worker-scheduled.ts +16 -16
  27. package/templates/new-worker.js +3 -3
  28. package/templates/new-worker.ts +19 -16
  29. package/templates/no-op-worker.js +8 -8
  30. package/templates/pages-dev-pipeline.ts +31 -0
  31. package/templates/pages-dev-util.ts +55 -0
  32. package/templates/pages-shim.ts +9 -0
  33. package/templates/pages-template-plugin.ts +159 -124
  34. package/templates/pages-template-worker.ts +161 -124
  35. package/templates/tsconfig-sanity.ts +11 -0
  36. package/templates/tsconfig.init.json +105 -0
  37. package/templates/tsconfig.json +6 -103
  38. package/wrangler-dist/cli.d.ts +1732 -0
  39. package/wrangler-dist/cli.js +112895 -89619
  40. package/wrangler-dist/wasm-sync.wasm +0 -0
  41. package/import_meta_url.js +0 -3
  42. package/miniflare-config-stubs/.env.empty +0 -0
  43. package/miniflare-config-stubs/package.empty.json +0 -1
  44. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  45. package/miniflare-dist/index.mjs +0 -4886
  46. package/src/__tests__/config-cache.test.ts +0 -36
  47. package/src/__tests__/configuration.test.ts +0 -3548
  48. package/src/__tests__/dev.test.tsx +0 -1055
  49. package/src/__tests__/guess-worker-format.test.ts +0 -85
  50. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  51. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  52. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  53. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  54. package/src/__tests__/helpers/mock-bin.ts +0 -36
  55. package/src/__tests__/helpers/mock-cfetch.ts +0 -211
  56. package/src/__tests__/helpers/mock-console.ts +0 -97
  57. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  58. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  59. package/src/__tests__/helpers/mock-istty.ts +0 -32
  60. package/src/__tests__/helpers/mock-kv.ts +0 -33
  61. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -250
  62. package/src/__tests__/helpers/mock-process.ts +0 -39
  63. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  64. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  65. package/src/__tests__/helpers/run-in-tmp.ts +0 -39
  66. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  67. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  68. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  69. package/src/__tests__/https-options.test.ts +0 -130
  70. package/src/__tests__/index.test.ts +0 -258
  71. package/src/__tests__/init.test.ts +0 -1992
  72. package/src/__tests__/jest.setup.ts +0 -107
  73. package/src/__tests__/kv.test.ts +0 -1619
  74. package/src/__tests__/logger.test.ts +0 -141
  75. package/src/__tests__/package-manager.test.ts +0 -353
  76. package/src/__tests__/pages.test.ts +0 -1242
  77. package/src/__tests__/parse.test.ts +0 -330
  78. package/src/__tests__/publish.test.ts +0 -6188
  79. package/src/__tests__/r2.test.ts +0 -233
  80. package/src/__tests__/route.test.ts +0 -45
  81. package/src/__tests__/secret.test.ts +0 -486
  82. package/src/__tests__/tail.test.ts +0 -690
  83. package/src/__tests__/user.test.ts +0 -132
  84. package/src/__tests__/whoami.test.tsx +0 -139
  85. package/src/abort.d.ts +0 -3
  86. package/src/bundle-reporter.tsx +0 -29
  87. package/src/bundle.ts +0 -204
  88. package/src/cfetch/index.ts +0 -121
  89. package/src/cfetch/internal.ts +0 -142
  90. package/src/cli.ts +0 -13
  91. package/src/config/README.md +0 -107
  92. package/src/config/config.ts +0 -243
  93. package/src/config/diagnostics.ts +0 -80
  94. package/src/config/environment.ts +0 -420
  95. package/src/config/index.ts +0 -225
  96. package/src/config/validation-helpers.ts +0 -584
  97. package/src/config/validation.ts +0 -1580
  98. package/src/config-cache.ts +0 -44
  99. package/src/create-worker-preview.ts +0 -185
  100. package/src/create-worker-upload-form.ts +0 -254
  101. package/src/dev/dev-vars.ts +0 -36
  102. package/src/dev/dev.tsx +0 -399
  103. package/src/dev/local.tsx +0 -321
  104. package/src/dev/remote.tsx +0 -282
  105. package/src/dev/use-esbuild.ts +0 -112
  106. package/src/dialogs.tsx +0 -135
  107. package/src/durable.ts +0 -102
  108. package/src/entry.ts +0 -328
  109. package/src/environment-variables.ts +0 -35
  110. package/src/errors.ts +0 -11
  111. package/src/git-client.ts +0 -42
  112. package/src/https-options.ts +0 -123
  113. package/src/index.tsx +0 -2908
  114. package/src/inspect.ts +0 -662
  115. package/src/intl-polyfill.d.ts +0 -139
  116. package/src/kv.ts +0 -408
  117. package/src/logger.ts +0 -73
  118. package/src/miniflare-cli/README.md +0 -30
  119. package/src/miniflare-cli/enum-keys.ts +0 -17
  120. package/src/miniflare-cli/index.ts +0 -41
  121. package/src/miniflare-cli/request-context.ts +0 -40
  122. package/src/module-collection.ts +0 -258
  123. package/src/open-in-browser.ts +0 -17
  124. package/src/package-manager.ts +0 -174
  125. package/src/pages/build.tsx +0 -202
  126. package/src/pages/constants.ts +0 -7
  127. package/src/pages/deployments.tsx +0 -101
  128. package/src/pages/dev.tsx +0 -948
  129. package/src/pages/functions/buildPlugin.ts +0 -105
  130. package/src/pages/functions/buildWorker.ts +0 -151
  131. package/src/pages/functions/filepath-routing.test.ts +0 -234
  132. package/src/pages/functions/filepath-routing.ts +0 -189
  133. package/src/pages/functions/identifiers.ts +0 -78
  134. package/src/pages/functions/routes.ts +0 -151
  135. package/src/pages/index.tsx +0 -84
  136. package/src/pages/projects.tsx +0 -157
  137. package/src/pages/publish.tsx +0 -325
  138. package/src/pages/types.ts +0 -40
  139. package/src/pages/upload.tsx +0 -363
  140. package/src/pages/utils.ts +0 -12
  141. package/src/parse.ts +0 -222
  142. package/src/paths.ts +0 -26
  143. package/src/proxy.ts +0 -476
  144. package/src/publish.ts +0 -739
  145. package/src/r2.ts +0 -50
  146. package/src/selfsigned.d.ts +0 -29
  147. package/src/sites.tsx +0 -372
  148. package/src/tail/filters.ts +0 -279
  149. package/src/tail/index.ts +0 -299
  150. package/src/tail/printing.ts +0 -67
  151. package/src/update-check.ts +0 -19
  152. package/src/user/choose-account.tsx +0 -60
  153. package/src/user/env-vars.ts +0 -17
  154. package/src/user/generate-auth-url.ts +0 -33
  155. package/src/user/generate-random-state.ts +0 -16
  156. package/src/user/index.ts +0 -3
  157. package/src/user/user.tsx +0 -1133
  158. package/src/whoami.tsx +0 -71
  159. package/src/worker.ts +0 -181
  160. package/src/zones.ts +0 -73
  161. package/templates/static-asset-facade.js +0 -43
@@ -1,325 +0,0 @@
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
- };
@@ -1,40 +0,0 @@
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
- }