wrangler 0.0.0-ece06ea → 0.0.0-ef13735

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 (63) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +35 -21
  3. package/pages/functions/buildWorker.ts +62 -0
  4. package/pages/functions/filepath-routing.test.ts +66 -0
  5. package/pages/functions/filepath-routing.ts +219 -0
  6. package/pages/functions/identifiers.ts +78 -0
  7. package/pages/functions/routes.ts +151 -0
  8. package/pages/functions/template-worker.ts +130 -0
  9. package/src/__tests__/dev.test.tsx +73 -0
  10. package/src/__tests__/guess-worker-format.test.ts +51 -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/mock-account-id.ts +30 -0
  14. package/src/__tests__/helpers/mock-bin.ts +33 -0
  15. package/src/__tests__/helpers/mock-cfetch.ts +207 -0
  16. package/src/__tests__/helpers/mock-console.ts +56 -0
  17. package/src/__tests__/helpers/mock-dialogs.ts +65 -0
  18. package/src/__tests__/helpers/mock-kv.ts +40 -0
  19. package/src/__tests__/helpers/mock-user.ts +27 -0
  20. package/src/__tests__/helpers/run-in-tmp.ts +29 -0
  21. package/src/__tests__/helpers/run-wrangler.ts +14 -0
  22. package/src/__tests__/index.test.ts +715 -119
  23. package/src/__tests__/jest.setup.ts +37 -0
  24. package/src/__tests__/kv.test.ts +1139 -0
  25. package/src/__tests__/logout.test.ts +50 -0
  26. package/src/__tests__/package-manager.test.ts +206 -0
  27. package/src/__tests__/publish.test.ts +1381 -0
  28. package/src/__tests__/secret.test.ts +210 -0
  29. package/src/__tests__/whoami.test.tsx +86 -0
  30. package/src/api/form_data.ts +93 -100
  31. package/src/api/preview.ts +29 -24
  32. package/src/api/worker.ts +55 -47
  33. package/src/cfetch/index.ts +102 -0
  34. package/src/cfetch/internal.ts +101 -0
  35. package/src/cli.ts +6 -7
  36. package/src/config.ts +641 -112
  37. package/src/dev.tsx +476 -355
  38. package/src/dialogs.tsx +6 -14
  39. package/src/guess-worker-format.ts +66 -0
  40. package/src/index.tsx +828 -496
  41. package/src/inspect.ts +596 -0
  42. package/src/kv.tsx +118 -45
  43. package/src/module-collection.ts +63 -0
  44. package/src/open-in-browser.ts +13 -0
  45. package/src/package-manager.ts +120 -0
  46. package/src/pages.tsx +915 -215
  47. package/src/paths.ts +26 -0
  48. package/src/proxy.ts +370 -0
  49. package/src/publish.ts +349 -290
  50. package/src/sites.tsx +184 -55
  51. package/src/tail.tsx +5 -3
  52. package/src/user.tsx +81 -91
  53. package/src/whoami.tsx +69 -0
  54. package/templates/new-worker.js +15 -0
  55. package/templates/new-worker.ts +15 -0
  56. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  57. package/wrangler-dist/cli.js +119231 -130682
  58. package/wrangler-dist/cli.js.map +3 -3
  59. package/src/__tests__/fixtures/init/.gitkeep +0 -0
  60. package/src/__tests__/mock-cfetch.js +0 -46
  61. package/src/api/inspect.ts +0 -441
  62. package/src/cfetch.ts +0 -72
  63. package/src/util/fetch.ts +0 -74
package/src/dialogs.tsx CHANGED
@@ -1,10 +1,10 @@
1
- import * as React from "react";
2
- import { useState } from "react";
3
1
  import { Box, Text, useInput, render } from "ink";
4
2
  import TextInput from "ink-text-input";
3
+ import * as React from "react";
4
+ import { useState } from "react";
5
5
  type ConfirmProps = {
6
6
  text: string;
7
- onConfirm: (answer: boolean) => void | Promise<void>;
7
+ onConfirm: (answer: boolean) => void;
8
8
  };
9
9
  function Confirm(props: ConfirmProps) {
10
10
  useInput((input: string) => {
@@ -43,7 +43,7 @@ type PromptProps = {
43
43
  onSubmit: (text: string) => void;
44
44
  };
45
45
 
46
- export function Prompt(props: PromptProps) {
46
+ function Prompt(props: PromptProps) {
47
47
  const [value, setValue] = useState("");
48
48
 
49
49
  return (
@@ -67,19 +67,11 @@ export async function prompt(text: string, type: "text" | "password" = "text") {
67
67
  <Prompt
68
68
  text={text}
69
69
  type={type}
70
- onSubmit={(text) => {
70
+ onSubmit={(inputText) => {
71
71
  unmount();
72
- resolve(text);
72
+ resolve(inputText);
73
73
  }}
74
74
  />
75
75
  );
76
76
  });
77
77
  }
78
-
79
- // this one feels a little non "standard"
80
- // export async function select(
81
- // title: string,
82
- // choices: { label: string; value: string }[]
83
- // ): Promise<{ label: string; value: string }>{
84
-
85
- // }
@@ -0,0 +1,66 @@
1
+ import assert from "node:assert";
2
+ import { build } from "esbuild";
3
+ import type { CfScriptFormat } from "./api/worker";
4
+ import type { Metafile } from "esbuild";
5
+
6
+ /**
7
+ * A function to "guess" the type of worker.
8
+ * We do this by running a lightweight build of the actual script,
9
+ * and looking at the metafile generated by esbuild. If it has a default
10
+ * export (or really, any exports), that means it's a "modules" worker.
11
+ * Else, it's a "service-worker" worker. This seems hacky, but works remarkably
12
+ * well in practice.
13
+ */
14
+ export default async function guessWorkerFormat(
15
+ filePath: string,
16
+ hint: CfScriptFormat | undefined
17
+ ): Promise<CfScriptFormat> {
18
+ const result = await build({
19
+ entryPoints: [filePath],
20
+ metafile: true,
21
+ bundle: false,
22
+ format: "esm",
23
+ write: false,
24
+ });
25
+ // result.metafile is defined because of the `metafile: true` option above.
26
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
27
+ const metafile = result.metafile!;
28
+ const entryPoints = Object.entries(metafile.outputs).filter(
29
+ ([_path, output]) => output.entryPoint !== undefined
30
+ );
31
+ assert(
32
+ entryPoints.length > 0,
33
+ `Cannot find entry-point "${filePath}" in generated bundle.` +
34
+ listEntryPoints(entryPoints)
35
+ );
36
+ assert(
37
+ entryPoints.length < 2,
38
+ "More than one entry-point found for generated bundle." +
39
+ listEntryPoints(entryPoints)
40
+ );
41
+ const guessedWorkerFormat =
42
+ entryPoints[0][1].exports.length > 0 ? "modules" : "service-worker";
43
+
44
+ if (hint) {
45
+ if (hint !== guessedWorkerFormat) {
46
+ if (hint === "service-worker") {
47
+ throw new Error(
48
+ "You configured this worker to be a 'service-worker', but the file you are trying to build appears to have es module exports. Please pass `--format modules`, or simply remove the configuration."
49
+ );
50
+ } else {
51
+ throw new Error(
52
+ "You configured this worker to be 'modules', but the file you are trying to build doesn't export a handler. Please pass `--format service-worker`, or simply remove the configuration."
53
+ );
54
+ }
55
+ }
56
+ }
57
+ return guessedWorkerFormat;
58
+ }
59
+
60
+ function listEntryPoints(
61
+ outputs: [string, ValueOf<Metafile["outputs"]>][]
62
+ ): string {
63
+ return outputs.map(([_input, output]) => output.entryPoint).join("\n");
64
+ }
65
+
66
+ type ValueOf<T> = T[keyof T];