wrangler 0.0.0-e2a26a0 → 0.0.0-e3e3243

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 (91) hide show
  1. package/README.md +1 -1
  2. package/bin/wrangler.js +10 -1
  3. package/miniflare-dist/index.mjs +79 -0
  4. package/miniflare-dist/index.mjs.map +7 -0
  5. package/package.json +24 -12
  6. package/pages/functions/filepath-routing.test.ts +212 -36
  7. package/pages/functions/filepath-routing.ts +69 -119
  8. package/pages/functions/routes.ts +8 -17
  9. package/pages/functions/template-worker.ts +3 -9
  10. package/src/__tests__/configuration.test.ts +2820 -0
  11. package/src/__tests__/dev.test.tsx +535 -65
  12. package/src/__tests__/guess-worker-format.test.ts +68 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +26 -8
  15. package/src/__tests__/helpers/mock-bin.ts +4 -1
  16. package/src/__tests__/helpers/mock-cfetch.ts +5 -5
  17. package/src/__tests__/helpers/mock-console.ts +21 -7
  18. package/src/__tests__/helpers/mock-kv.ts +9 -16
  19. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  20. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  21. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  22. package/src/__tests__/helpers/run-wrangler.ts +5 -3
  23. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  24. package/src/__tests__/https-options.test.ts +127 -0
  25. package/src/__tests__/index.test.ts +467 -27
  26. package/src/__tests__/jest.setup.ts +37 -5
  27. package/src/__tests__/kv.test.ts +442 -201
  28. package/src/__tests__/logout.test.ts +15 -13
  29. package/src/__tests__/package-manager.test.ts +2 -2
  30. package/src/__tests__/pages.test.ts +82 -0
  31. package/src/__tests__/parse.test.ts +322 -0
  32. package/src/__tests__/publish.test.ts +2717 -430
  33. package/src/__tests__/r2.test.ts +198 -0
  34. package/src/__tests__/route.test.ts +45 -0
  35. package/src/__tests__/secret.test.ts +301 -86
  36. package/src/__tests__/sentry.test.ts +146 -0
  37. package/src/__tests__/tail.test.ts +562 -0
  38. package/src/__tests__/whoami.test.tsx +21 -7
  39. package/src/bundle.ts +155 -0
  40. package/src/cfetch/index.ts +8 -6
  41. package/src/cfetch/internal.ts +60 -22
  42. package/src/cli.ts +10 -0
  43. package/src/config/README.md +107 -0
  44. package/src/config/config.ts +218 -0
  45. package/src/config/diagnostics.ts +80 -0
  46. package/src/config/environment.ts +371 -0
  47. package/src/config/index.ts +62 -0
  48. package/src/config/validation-helpers.ts +554 -0
  49. package/src/config/validation.ts +1232 -0
  50. package/src/{api/preview.ts → create-worker-preview.ts} +59 -21
  51. package/src/create-worker-upload-form.ts +217 -0
  52. package/src/dev/dev.tsx +392 -0
  53. package/src/dev/local.tsx +232 -0
  54. package/src/dev/remote.tsx +203 -0
  55. package/src/dev/use-esbuild.ts +104 -0
  56. package/src/entry.ts +240 -0
  57. package/src/environment-variables.ts +33 -0
  58. package/src/https-options.ts +122 -0
  59. package/src/index.tsx +1067 -779
  60. package/src/inspect.ts +25 -4
  61. package/src/intl-polyfill.d.ts +139 -0
  62. package/src/{kv.tsx → kv.ts} +95 -60
  63. package/src/miniflare-cli/README.md +30 -0
  64. package/src/miniflare-cli/enum-keys.ts +17 -0
  65. package/src/miniflare-cli/index.ts +37 -0
  66. package/src/module-collection.ts +226 -31
  67. package/src/open-in-browser.ts +25 -0
  68. package/src/package-manager.ts +21 -15
  69. package/src/pages.tsx +35 -20
  70. package/src/parse.ts +183 -0
  71. package/src/proxy.ts +115 -45
  72. package/src/publish.ts +268 -328
  73. package/src/r2.ts +50 -0
  74. package/src/reporting.ts +131 -0
  75. package/src/selfsigned.d.ts +29 -0
  76. package/src/sites.tsx +83 -43
  77. package/src/tail/filters.ts +279 -0
  78. package/src/tail/index.ts +299 -0
  79. package/src/tail/printing.ts +62 -0
  80. package/src/user.tsx +234 -126
  81. package/src/{api/worker.ts → worker.ts} +44 -36
  82. package/templates/new-worker.js +1 -1
  83. package/templates/new-worker.ts +1 -1
  84. package/templates/tsconfig.json +105 -0
  85. package/wrangler-dist/cli.js +131201 -114242
  86. package/wrangler-dist/cli.js.map +3 -3
  87. package/src/__tests__/helpers/mock-user.ts +0 -27
  88. package/src/api/form_data.ts +0 -134
  89. package/src/config.ts +0 -641
  90. package/src/dev.tsx +0 -834
  91. 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
- }