wrangler 0.0.0-e043479 → 0.0.0-e0b9366

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 (51) hide show
  1. package/package.json +10 -4
  2. package/pages/functions/filepath-routing.test.ts +125 -25
  3. package/pages/functions/filepath-routing.ts +6 -3
  4. package/src/__tests__/configuration.test.ts +479 -114
  5. package/src/__tests__/dev.test.tsx +162 -8
  6. package/src/__tests__/dev2.test.tsx +152 -0
  7. package/src/__tests__/guess-worker-format.test.ts +9 -17
  8. package/src/__tests__/helpers/mock-account-id.ts +4 -0
  9. package/src/__tests__/helpers/mock-cfetch.ts +3 -3
  10. package/src/__tests__/helpers/mock-kv.ts +9 -16
  11. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  12. package/src/__tests__/https-options.test.ts +127 -0
  13. package/src/__tests__/index.test.ts +125 -0
  14. package/src/__tests__/jest.setup.ts +1 -1
  15. package/src/__tests__/kv.test.ts +27 -53
  16. package/src/__tests__/logout.test.ts +15 -13
  17. package/src/__tests__/pages.test.ts +44 -0
  18. package/src/__tests__/publish.test.ts +504 -32
  19. package/src/__tests__/route.test.ts +45 -0
  20. package/src/__tests__/whoami.test.tsx +21 -7
  21. package/src/bundle.ts +20 -11
  22. package/src/cfetch/internal.ts +11 -5
  23. package/src/config/config.ts +53 -44
  24. package/src/config/validation-helpers.ts +110 -12
  25. package/src/config/validation.ts +59 -41
  26. package/src/{api/preview.ts → create-worker-preview.ts} +23 -4
  27. package/src/{api/form_data.ts → create-worker-upload-form.ts} +1 -1
  28. package/src/dev/dev.tsx +357 -0
  29. package/src/dev/local.tsx +241 -0
  30. package/src/dev/remote.tsx +201 -0
  31. package/src/dev/use-esbuild.ts +100 -0
  32. package/src/entry.ts +111 -9
  33. package/src/https-options.ts +122 -0
  34. package/src/index.tsx +171 -109
  35. package/src/inspect.ts +9 -1
  36. package/src/{kv.tsx → kv.ts} +0 -0
  37. package/src/module-collection.ts +85 -2
  38. package/src/open-in-browser.ts +14 -2
  39. package/src/pages.tsx +1 -1
  40. package/src/proxy.ts +102 -40
  41. package/src/publish.ts +41 -50
  42. package/src/reporting.ts +25 -9
  43. package/src/selfsigned.d.ts +29 -0
  44. package/src/sites.tsx +51 -16
  45. package/src/user.tsx +132 -77
  46. package/src/{api/worker.ts → worker.ts} +0 -23
  47. package/wrangler-dist/cli.js +5012 -3107
  48. package/wrangler-dist/cli.js.map +3 -3
  49. package/src/__tests__/helpers/mock-user.ts +0 -27
  50. package/src/dev.tsx +0 -960
  51. package/src/guess-worker-format.ts +0 -68
@@ -1,68 +0,0 @@
1
- import assert from "node:assert";
2
- import { build } from "esbuild";
3
- import type { CfScriptFormat } from "./api/worker";
4
- import type { Entry } from "./entry";
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];