wrangler 0.0.0-e9ab55a → 0.0.0-ed4f2ef

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 (102) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +12 -3
  3. package/miniflare-dist/index.mjs +79 -0
  4. package/miniflare-dist/index.mjs.map +7 -0
  5. package/package.json +33 -16
  6. package/pages/functions/buildWorker.ts +1 -1
  7. package/pages/functions/filepath-routing.test.ts +212 -28
  8. package/pages/functions/filepath-routing.ts +83 -130
  9. package/pages/functions/routes.ts +11 -18
  10. package/pages/functions/template-worker.ts +3 -9
  11. package/src/__tests__/configuration.test.ts +2874 -0
  12. package/src/__tests__/dev.test.tsx +582 -61
  13. package/src/__tests__/guess-worker-format.test.ts +83 -0
  14. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  15. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  16. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  17. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  18. package/src/__tests__/helpers/mock-bin.ts +36 -0
  19. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +52 -16
  20. package/src/__tests__/helpers/mock-console.ts +70 -0
  21. package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
  22. package/src/__tests__/helpers/mock-kv.ts +33 -0
  23. package/src/__tests__/helpers/mock-oauth-flow.ts +178 -0
  24. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  25. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  26. package/src/__tests__/helpers/run-in-tmp.ts +32 -0
  27. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  28. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  29. package/src/__tests__/https-options.test.ts +127 -0
  30. package/src/__tests__/index.test.ts +777 -77
  31. package/src/__tests__/jest.setup.ts +58 -6
  32. package/src/__tests__/kv.test.ts +716 -462
  33. package/src/__tests__/package-manager.test.ts +206 -0
  34. package/src/__tests__/pages.test.ts +180 -0
  35. package/src/__tests__/parse.test.ts +322 -0
  36. package/src/__tests__/publish.test.ts +3915 -71
  37. package/src/__tests__/r2.test.ts +198 -0
  38. package/src/__tests__/route.test.ts +45 -0
  39. package/src/__tests__/secret.test.ts +425 -0
  40. package/src/__tests__/sentry.test.ts +146 -0
  41. package/src/__tests__/tail.test.ts +638 -0
  42. package/src/__tests__/user.test.ts +83 -0
  43. package/src/__tests__/whoami.test.tsx +95 -0
  44. package/src/bundle.ts +155 -0
  45. package/src/cfetch/index.ts +21 -19
  46. package/src/cfetch/internal.ts +92 -22
  47. package/src/cli.ts +14 -2
  48. package/src/config/README.md +107 -0
  49. package/src/config/config.ts +229 -0
  50. package/src/config/diagnostics.ts +80 -0
  51. package/src/config/environment.ts +371 -0
  52. package/src/config/index.ts +62 -0
  53. package/src/config/validation-helpers.ts +557 -0
  54. package/src/config/validation.ts +1240 -0
  55. package/src/{api/preview.ts → create-worker-preview.ts} +69 -24
  56. package/src/create-worker-upload-form.ts +240 -0
  57. package/src/dev/dev.tsx +413 -0
  58. package/src/dev/local.tsx +287 -0
  59. package/src/dev/remote.tsx +209 -0
  60. package/src/dev/use-esbuild.ts +109 -0
  61. package/src/dialogs.tsx +2 -2
  62. package/src/entry.ts +256 -0
  63. package/src/environment-variables.ts +33 -0
  64. package/src/errors.ts +11 -0
  65. package/src/https-options.ts +122 -0
  66. package/src/index.tsx +1310 -849
  67. package/src/inspect.ts +102 -21
  68. package/src/intl-polyfill.d.ts +139 -0
  69. package/src/{kv.tsx → kv.ts} +104 -61
  70. package/src/miniflare-cli/README.md +30 -0
  71. package/src/miniflare-cli/enum-keys.ts +17 -0
  72. package/src/miniflare-cli/index.ts +38 -0
  73. package/src/module-collection.ts +228 -35
  74. package/src/open-in-browser.ts +25 -0
  75. package/src/package-manager.ts +126 -0
  76. package/src/pages.tsx +214 -48
  77. package/src/parse.ts +183 -0
  78. package/src/paths.ts +26 -0
  79. package/src/proxy.ts +192 -39
  80. package/src/publish.ts +321 -318
  81. package/src/r2.ts +50 -0
  82. package/src/reporting.ts +131 -0
  83. package/src/selfsigned.d.ts +29 -0
  84. package/src/sites.tsx +224 -62
  85. package/src/tail/filters.ts +279 -0
  86. package/src/tail/index.ts +299 -0
  87. package/src/tail/printing.ts +62 -0
  88. package/src/user.tsx +317 -178
  89. package/src/whoami.tsx +69 -0
  90. package/src/{api/worker.ts → worker.ts} +54 -37
  91. package/templates/new-worker.js +15 -0
  92. package/templates/new-worker.ts +15 -0
  93. package/{static-asset-facade.js → templates/static-asset-facade.js} +1 -1
  94. package/templates/tsconfig.json +105 -0
  95. package/wrangler-dist/cli.js +131262 -112648
  96. package/wrangler-dist/cli.js.map +3 -3
  97. package/src/__tests__/run-in-tmp.ts +0 -19
  98. package/src/__tests__/run-wrangler.ts +0 -32
  99. package/src/api/form_data.ts +0 -131
  100. package/src/config.ts +0 -646
  101. package/src/dev.tsx +0 -784
  102. package/src/tail.tsx +0 -73
@@ -1,19 +0,0 @@
1
- import * as os from "node:os";
2
- import * as path from "node:path";
3
- import * as fs from "fs";
4
-
5
- const originalCwd = process.cwd();
6
-
7
- export function runInTempDir() {
8
- let tmpDir: string;
9
-
10
- beforeEach(() => {
11
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"));
12
- process.chdir(tmpDir);
13
- });
14
-
15
- afterEach(() => {
16
- process.chdir(originalCwd);
17
- fs.rmSync(tmpDir, { recursive: true });
18
- });
19
- }
@@ -1,32 +0,0 @@
1
- import { main } from "../index";
2
-
3
- /**
4
- * Run the wrangler CLI tool in tests, capturing the logging output.
5
- */
6
- export async function runWrangler(cmd?: string) {
7
- const logSpy = jest.spyOn(console, "log").mockImplementation();
8
- const errorSpy = jest.spyOn(console, "error").mockImplementation();
9
- const warnSpy = jest.spyOn(console, "warn").mockImplementation();
10
- try {
11
- let error: unknown = undefined;
12
- try {
13
- await main(cmd?.split(" ") ?? []);
14
- } catch (e) {
15
- error = e;
16
- }
17
- return {
18
- error,
19
- stdout: captureCalls(logSpy),
20
- stderr: captureCalls(errorSpy),
21
- warnings: captureCalls(warnSpy),
22
- };
23
- } finally {
24
- logSpy.mockRestore();
25
- errorSpy.mockRestore();
26
- warnSpy.mockRestore();
27
- }
28
- }
29
-
30
- function captureCalls(spy: jest.SpyInstance): string {
31
- return spy.mock.calls.flat(2).join("\n");
32
- }
@@ -1,131 +0,0 @@
1
- import type {
2
- CfWorkerInit,
3
- CfModuleType,
4
- CfModule,
5
- CfDurableObjectMigrations,
6
- } from "./worker.js";
7
- import { FormData, Blob } from "formdata-node";
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): Blob {
27
- const { type: moduleType, content } = module;
28
- const type = toMimeType(moduleType ?? entryType);
29
-
30
- return new Blob([content], { type });
31
- }
32
-
33
- interface WorkerMetadata {
34
- compatibility_date?: string;
35
- compatibility_flags?: string[];
36
- usage_model?: "bundled" | "unbound";
37
- migrations?: CfDurableObjectMigrations;
38
- bindings: (
39
- | { type: "kv_namespace"; name: string; namespace_id: string }
40
- | { type: "plain_text"; name: string; text: string }
41
- | {
42
- type: "durable_object_namespace";
43
- name: string;
44
- class_name: string;
45
- script_name?: string;
46
- }
47
- | {
48
- type: "service";
49
- name: string;
50
- service: string;
51
- environment: string;
52
- }
53
- )[];
54
- }
55
-
56
- /**
57
- * Creates a `FormData` upload from a `CfWorkerInit`.
58
- */
59
- export function toFormData(worker: CfWorkerInit): FormData {
60
- const formData = new FormData();
61
- const {
62
- main,
63
- modules,
64
- bindings,
65
- migrations,
66
- usage_model,
67
- compatibility_date,
68
- compatibility_flags,
69
- } = worker;
70
-
71
- const metadataBindings: WorkerMetadata["bindings"] = [];
72
-
73
- bindings.kv_namespaces?.forEach(({ id, binding }) => {
74
- metadataBindings.push({
75
- name: binding,
76
- type: "kv_namespace",
77
- namespace_id: id,
78
- });
79
- });
80
-
81
- bindings.durable_objects?.bindings.forEach(
82
- ({ name, class_name, script_name }) => {
83
- metadataBindings.push({
84
- name,
85
- type: "durable_object_namespace",
86
- class_name: class_name,
87
- ...(script_name && { script_name }),
88
- });
89
- }
90
- );
91
-
92
- Object.entries(bindings.vars || {})?.forEach(([key, value]) => {
93
- metadataBindings.push({ name: key, type: "plain_text", text: value });
94
- });
95
-
96
- bindings.services?.forEach(({ name, service, environment }) => {
97
- metadataBindings.push({
98
- name,
99
- type: "service",
100
- service,
101
- environment,
102
- });
103
- });
104
-
105
- const metadata: WorkerMetadata = {
106
- ...(main.type !== "commonjs"
107
- ? { main_module: main.name }
108
- : { body_part: main.name }),
109
- bindings: metadataBindings,
110
- ...(compatibility_date && { compatibility_date }),
111
- ...(compatibility_flags && { compatibility_flags }),
112
- ...(usage_model && { usage_model }),
113
- ...(migrations && { migrations }),
114
- };
115
-
116
- formData.set("metadata", JSON.stringify(metadata));
117
-
118
- if (main.type === "commonjs" && modules && modules.length > 0) {
119
- throw new TypeError(
120
- "More than one module can only be specified when type = 'esm'"
121
- );
122
- }
123
-
124
- for (const module of [main].concat(modules || [])) {
125
- const { name } = module;
126
- const blob = toModule(module, main.type ?? "esm");
127
- formData.set(name, blob, name);
128
- }
129
-
130
- return formData;
131
- }