wrangler 0.0.0-e2a26a0 → 0.0.0-e3a458e

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 (84) hide show
  1. package/package.json +24 -11
  2. package/pages/functions/filepath-routing.test.ts +212 -36
  3. package/pages/functions/filepath-routing.ts +69 -119
  4. package/pages/functions/routes.ts +8 -17
  5. package/pages/functions/template-worker.ts +3 -9
  6. package/src/__tests__/configuration.test.ts +2598 -0
  7. package/src/__tests__/dev.test.tsx +437 -63
  8. package/src/__tests__/dev2.test.tsx +154 -0
  9. package/src/__tests__/guess-worker-format.test.ts +58 -0
  10. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  11. package/src/__tests__/helpers/mock-account-id.ts +26 -8
  12. package/src/__tests__/helpers/mock-bin.ts +4 -1
  13. package/src/__tests__/helpers/mock-cfetch.ts +5 -5
  14. package/src/__tests__/helpers/mock-console.ts +21 -7
  15. package/src/__tests__/helpers/mock-kv.ts +9 -16
  16. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  17. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  18. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  19. package/src/__tests__/helpers/run-wrangler.ts +5 -3
  20. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  21. package/src/__tests__/https-options.test.ts +127 -0
  22. package/src/__tests__/index.test.ts +468 -20
  23. package/src/__tests__/jest.setup.ts +37 -5
  24. package/src/__tests__/kv.test.ts +426 -183
  25. package/src/__tests__/logout.test.ts +15 -13
  26. package/src/__tests__/package-manager.test.ts +2 -2
  27. package/src/__tests__/pages.test.ts +44 -0
  28. package/src/__tests__/parse.test.ts +322 -0
  29. package/src/__tests__/publish.test.ts +1733 -344
  30. package/src/__tests__/r2.test.ts +198 -0
  31. package/src/__tests__/route.test.ts +45 -0
  32. package/src/__tests__/secret.test.ts +301 -86
  33. package/src/__tests__/sentry.test.ts +146 -0
  34. package/src/__tests__/tail.test.ts +564 -0
  35. package/src/__tests__/whoami.test.tsx +21 -7
  36. package/src/bundle.ts +142 -0
  37. package/src/cfetch/index.ts +8 -6
  38. package/src/cfetch/internal.ts +60 -22
  39. package/src/cli.ts +10 -0
  40. package/src/config/README.md +107 -0
  41. package/src/config/config.ts +279 -0
  42. package/src/config/diagnostics.ts +80 -0
  43. package/src/config/environment.ts +305 -0
  44. package/src/config/index.ts +52 -0
  45. package/src/config/validation-helpers.ts +468 -0
  46. package/src/config/validation.ts +1057 -0
  47. package/src/{api/preview.ts → create-worker-preview.ts} +59 -21
  48. package/src/create-worker-upload-form.ts +217 -0
  49. package/src/dev/dev.tsx +362 -0
  50. package/src/dev/local.tsx +247 -0
  51. package/src/dev/remote.tsx +203 -0
  52. package/src/dev/use-esbuild.ts +100 -0
  53. package/src/entry.ts +159 -0
  54. package/src/environment-variables.ts +33 -0
  55. package/src/https-options.ts +122 -0
  56. package/src/index.tsx +1030 -766
  57. package/src/inspect.ts +25 -4
  58. package/src/{kv.tsx → kv.ts} +110 -55
  59. package/src/module-collection.ts +212 -22
  60. package/src/open-in-browser.ts +25 -0
  61. package/src/package-manager.ts +21 -15
  62. package/src/pages.tsx +10 -11
  63. package/src/parse.ts +183 -0
  64. package/src/proxy.ts +115 -45
  65. package/src/publish.ts +273 -329
  66. package/src/r2.ts +50 -0
  67. package/src/reporting.ts +131 -0
  68. package/src/selfsigned.d.ts +29 -0
  69. package/src/sites.tsx +66 -33
  70. package/src/tail/filters.ts +279 -0
  71. package/src/tail/index.ts +299 -0
  72. package/src/tail/printing.ts +62 -0
  73. package/src/user.tsx +223 -124
  74. package/src/{api/worker.ts → worker.ts} +44 -36
  75. package/templates/new-worker.js +1 -1
  76. package/templates/new-worker.ts +1 -1
  77. package/templates/tsconfig.json +105 -0
  78. package/wrangler-dist/cli.js +129900 -113128
  79. package/wrangler-dist/cli.js.map +3 -3
  80. package/src/__tests__/helpers/mock-user.ts +0 -27
  81. package/src/api/form_data.ts +0 -134
  82. package/src/config.ts +0 -641
  83. package/src/dev.tsx +0 -834
  84. package/src/tail.tsx +0 -73
@@ -1,27 +0,0 @@
1
- import { mkdirSync, writeFileSync } from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
-
5
- export function writeUserConfig(
6
- oauth_token?: string,
7
- refresh_token?: string,
8
- expiration_time?: string
9
- ) {
10
- const lines: string[] = [];
11
- if (oauth_token) {
12
- lines.push(`oauth_token = "${oauth_token}"`);
13
- }
14
- if (refresh_token) {
15
- lines.push(`refresh_token = "${refresh_token}"`);
16
- }
17
- if (expiration_time) {
18
- lines.push(`expiration_time = "${expiration_time}"`);
19
- }
20
- const configPath = path.join(os.homedir(), ".wrangler/config");
21
- mkdirSync(configPath, { recursive: true });
22
- writeFileSync(
23
- path.join(configPath, "default.toml"),
24
- lines.join("\n"),
25
- "utf-8"
26
- );
27
- }
@@ -1,134 +0,0 @@
1
- import { FormData, File } from "undici";
2
- import type {
3
- CfWorkerInit,
4
- CfModuleType,
5
- CfModule,
6
- CfDurableObjectMigrations,
7
- } from "./worker.js";
8
-
9
- export function toMimeType(type: CfModuleType): string {
10
- switch (type) {
11
- case "esm":
12
- return "application/javascript+module";
13
- case "commonjs":
14
- return "application/javascript";
15
- case "compiled-wasm":
16
- return "application/wasm";
17
- case "buffer":
18
- return "application/octet-stream";
19
- case "text":
20
- return "text/plain";
21
- default:
22
- throw new TypeError("Unsupported module: " + type);
23
- }
24
- }
25
-
26
- function toModule(module: CfModule, entryType: CfModuleType): File {
27
- const { type: moduleType, content } = module;
28
- const type = toMimeType(moduleType ?? entryType);
29
- return new File([content], module.name, { type });
30
- }
31
-
32
- export interface WorkerMetadata {
33
- /** The name of the entry point module. Only exists when the worker is in the ES module format */
34
- main_module?: string;
35
- /** The name of the entry point module. Only exists when the worker is in the Service Worker format */
36
- body_part?: string;
37
- compatibility_date?: string;
38
- compatibility_flags?: string[];
39
- usage_model?: "bundled" | "unbound";
40
- migrations?: CfDurableObjectMigrations;
41
- bindings: (
42
- | { type: "kv_namespace"; name: string; namespace_id: string }
43
- | { type: "plain_text"; name: string; text: string }
44
- | {
45
- type: "durable_object_namespace";
46
- name: string;
47
- class_name: string;
48
- script_name?: string;
49
- }
50
- | {
51
- type: "service";
52
- name: string;
53
- service: string;
54
- environment: string;
55
- }
56
- )[];
57
- }
58
-
59
- /**
60
- * Creates a `FormData` upload from a `CfWorkerInit`.
61
- */
62
- export function toFormData(worker: CfWorkerInit): FormData {
63
- const formData = new FormData();
64
- const {
65
- main,
66
- modules,
67
- bindings,
68
- migrations,
69
- usage_model,
70
- compatibility_date,
71
- compatibility_flags,
72
- } = worker;
73
-
74
- const metadataBindings: WorkerMetadata["bindings"] = [];
75
-
76
- bindings.kv_namespaces?.forEach(({ id, binding }) => {
77
- metadataBindings.push({
78
- name: binding,
79
- type: "kv_namespace",
80
- namespace_id: id,
81
- });
82
- });
83
-
84
- bindings.durable_objects?.bindings.forEach(
85
- ({ name, class_name, script_name }) => {
86
- metadataBindings.push({
87
- name,
88
- type: "durable_object_namespace",
89
- class_name: class_name,
90
- ...(script_name && { script_name }),
91
- });
92
- }
93
- );
94
-
95
- Object.entries(bindings.vars || {})?.forEach(([key, value]) => {
96
- metadataBindings.push({ name: key, type: "plain_text", text: value });
97
- });
98
-
99
- bindings.services?.forEach(({ name, service, environment }) => {
100
- metadataBindings.push({
101
- name,
102
- type: "service",
103
- service,
104
- environment,
105
- });
106
- });
107
-
108
- const metadata: WorkerMetadata = {
109
- ...(main.type !== "commonjs"
110
- ? { main_module: main.name }
111
- : { body_part: main.name }),
112
- bindings: metadataBindings,
113
- ...(compatibility_date && { compatibility_date }),
114
- ...(compatibility_flags && { compatibility_flags }),
115
- ...(usage_model && { usage_model }),
116
- ...(migrations && { migrations }),
117
- };
118
-
119
- formData.set("metadata", JSON.stringify(metadata));
120
-
121
- if (main.type === "commonjs" && modules && modules.length > 0) {
122
- throw new TypeError(
123
- "More than one module can only be specified when type = 'esm'"
124
- );
125
- }
126
-
127
- for (const module of [main].concat(modules || [])) {
128
- const { name } = module;
129
- const file = toModule(module, main.type ?? "esm");
130
- formData.set(name, file);
131
- }
132
-
133
- return formData;
134
- }