wrangler 0.0.13 → 0.0.17

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 (67) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +20 -11
  3. package/pages/functions/buildWorker.ts +1 -1
  4. package/pages/functions/filepath-routing.test.ts +112 -28
  5. package/pages/functions/filepath-routing.ts +44 -51
  6. package/pages/functions/routes.ts +11 -18
  7. package/pages/functions/template-worker.ts +3 -9
  8. package/src/__tests__/dev.test.tsx +42 -5
  9. package/src/__tests__/guess-worker-format.test.ts +66 -0
  10. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  11. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  12. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  13. package/src/__tests__/helpers/mock-account-id.ts +30 -0
  14. package/src/__tests__/helpers/mock-bin.ts +36 -0
  15. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +43 -9
  16. package/src/__tests__/helpers/mock-console.ts +62 -0
  17. package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
  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/mock-web-socket.ts +37 -0
  21. package/src/__tests__/{run-in-tmp.ts → helpers/run-in-tmp.ts} +1 -1
  22. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  23. package/src/__tests__/helpers/write-wrangler-toml.ts +20 -0
  24. package/src/__tests__/index.test.ts +418 -71
  25. package/src/__tests__/jest.setup.ts +30 -2
  26. package/src/__tests__/kv.test.ts +147 -252
  27. package/src/__tests__/logout.test.ts +50 -0
  28. package/src/__tests__/package-manager.test.ts +206 -0
  29. package/src/__tests__/publish.test.ts +1136 -291
  30. package/src/__tests__/r2.test.ts +206 -0
  31. package/src/__tests__/secret.test.ts +210 -0
  32. package/src/__tests__/sentry.test.ts +146 -0
  33. package/src/__tests__/tail.test.ts +246 -0
  34. package/src/__tests__/whoami.test.tsx +6 -47
  35. package/src/api/form_data.ts +75 -25
  36. package/src/api/preview.ts +2 -2
  37. package/src/api/worker.ts +34 -15
  38. package/src/bundle.ts +127 -0
  39. package/src/cfetch/index.ts +7 -15
  40. package/src/cfetch/internal.ts +41 -6
  41. package/src/cli.ts +10 -0
  42. package/src/config.ts +125 -95
  43. package/src/dev.tsx +300 -193
  44. package/src/dialogs.tsx +2 -2
  45. package/src/guess-worker-format.ts +68 -0
  46. package/src/index.tsx +578 -192
  47. package/src/inspect.ts +29 -10
  48. package/src/kv.tsx +23 -17
  49. package/src/module-collection.ts +32 -12
  50. package/src/open-in-browser.ts +13 -0
  51. package/src/package-manager.ts +120 -0
  52. package/src/pages.tsx +28 -23
  53. package/src/paths.ts +26 -0
  54. package/src/proxy.ts +88 -14
  55. package/src/publish.ts +260 -297
  56. package/src/r2.ts +50 -0
  57. package/src/reporting.ts +115 -0
  58. package/src/sites.tsx +28 -27
  59. package/src/tail.tsx +178 -9
  60. package/src/user.tsx +58 -44
  61. package/templates/new-worker.js +15 -0
  62. package/templates/new-worker.ts +15 -0
  63. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  64. package/wrangler-dist/cli.js +124315 -104677
  65. package/wrangler-dist/cli.js.map +3 -3
  66. package/src/__tests__/mock-console.ts +0 -34
  67. package/src/__tests__/run-wrangler.ts +0 -8
package/src/dialogs.tsx CHANGED
@@ -1,7 +1,7 @@
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
7
  onConfirm: (answer: boolean) => void;
@@ -0,0 +1,68 @@
1
+ import assert from "node:assert";
2
+ import { build } from "esbuild";
3
+ import type { CfScriptFormat } from "./api/worker";
4
+ import type { Entry } from "./bundle";
5
+ import type { Metafile } from "esbuild";
6
+
7
+ /**
8
+ * A function to "guess" the type of worker.
9
+ * We do this by running a lightweight build of the actual script,
10
+ * and looking at the metafile generated by esbuild. If it has a default
11
+ * export (or really, any exports), that means it's a "modules" worker.
12
+ * Else, it's a "service-worker" worker. This seems hacky, but works remarkably
13
+ * well in practice.
14
+ */
15
+ export default async function guessWorkerFormat(
16
+ entry: Entry,
17
+ hint: CfScriptFormat | undefined
18
+ ): Promise<CfScriptFormat> {
19
+ const result = await build({
20
+ entryPoints: [entry.file],
21
+ absWorkingDir: entry.directory,
22
+ metafile: true,
23
+ bundle: false,
24
+ format: "esm",
25
+ write: false,
26
+ });
27
+ // result.metafile is defined because of the `metafile: true` option above.
28
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
29
+ const metafile = result.metafile!;
30
+ const entryPoints = Object.entries(metafile.outputs).filter(
31
+ ([_path, output]) => output.entryPoint !== undefined
32
+ );
33
+ assert(
34
+ entryPoints.length > 0,
35
+ `Cannot find entry-point "${entry.file}" in generated bundle.` +
36
+ listEntryPoints(entryPoints)
37
+ );
38
+ assert(
39
+ entryPoints.length < 2,
40
+ "More than one entry-point found for generated bundle." +
41
+ listEntryPoints(entryPoints)
42
+ );
43
+ const guessedWorkerFormat =
44
+ entryPoints[0][1].exports.length > 0 ? "modules" : "service-worker";
45
+
46
+ if (hint) {
47
+ if (hint !== guessedWorkerFormat) {
48
+ if (hint === "service-worker") {
49
+ throw new Error(
50
+ "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."
51
+ );
52
+ } else {
53
+ throw new Error(
54
+ "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."
55
+ );
56
+ }
57
+ }
58
+ }
59
+ return guessedWorkerFormat;
60
+ }
61
+
62
+ function listEntryPoints(
63
+ outputs: [string, ValueOf<Metafile["outputs"]>][]
64
+ ): string {
65
+ return outputs.map(([_input, output]) => output.entryPoint).join("\n");
66
+ }
67
+
68
+ type ValueOf<T> = T[keyof T];