wrangler 0.0.0-e1c615f → 0.0.0-e2234bbc

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 (115) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +47 -16
  3. package/bin/wrangler.js +117 -31
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +194 -123
  6. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  7. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  8. package/templates/__tests__/tsconfig.json +8 -0
  9. package/templates/checked-fetch.js +30 -0
  10. package/templates/facade.d.ts +17 -0
  11. package/templates/gitignore +172 -0
  12. package/templates/init-tests/test-jest-new-worker.js +23 -0
  13. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  14. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  15. package/templates/middleware/common.ts +67 -0
  16. package/templates/middleware/loader-modules.ts +137 -0
  17. package/templates/middleware/loader-sw.ts +228 -0
  18. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  19. package/templates/middleware/middleware-d1-beta.ts +244 -0
  20. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  21. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  22. package/templates/middleware/middleware-multiworker-dev.ts +59 -0
  23. package/templates/middleware/middleware-pretty-error.ts +40 -0
  24. package/templates/middleware/middleware-scheduled.ts +15 -0
  25. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  26. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  27. package/templates/new-worker-scheduled.js +17 -0
  28. package/templates/new-worker-scheduled.ts +32 -0
  29. package/templates/new-worker.js +15 -0
  30. package/templates/new-worker.ts +33 -0
  31. package/templates/no-op-worker.js +10 -0
  32. package/templates/pages-dev-pipeline.ts +31 -0
  33. package/templates/pages-dev-util.ts +55 -0
  34. package/templates/pages-shim.ts +9 -0
  35. package/templates/pages-template-plugin.ts +190 -0
  36. package/templates/pages-template-worker.ts +198 -0
  37. package/templates/tsconfig-sanity.ts +11 -0
  38. package/templates/tsconfig.init.json +105 -0
  39. package/templates/tsconfig.json +8 -0
  40. package/wrangler-dist/cli.d.ts +1726 -0
  41. package/wrangler-dist/cli.js +143067 -117031
  42. package/wrangler-dist/wasm-sync.wasm +0 -0
  43. package/import_meta_url.js +0 -3
  44. package/miniflare-config-stubs/.env.empty +0 -0
  45. package/miniflare-config-stubs/package.empty.json +0 -1
  46. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  47. package/pages/functions/buildWorker.ts +0 -57
  48. package/pages/functions/filepath-routing.test.ts +0 -39
  49. package/pages/functions/filepath-routing.ts +0 -221
  50. package/pages/functions/identifiers.ts +0 -78
  51. package/pages/functions/routes.ts +0 -158
  52. package/pages/functions/template-worker.ts +0 -137
  53. package/src/__tests__/clipboardy-mock.js +0 -4
  54. package/src/__tests__/dev.test.tsx +0 -66
  55. package/src/__tests__/index.test.ts +0 -287
  56. package/src/__tests__/jest.setup.ts +0 -22
  57. package/src/__tests__/kv.test.ts +0 -1098
  58. package/src/__tests__/mock-cfetch.ts +0 -171
  59. package/src/__tests__/mock-dialogs.ts +0 -65
  60. package/src/__tests__/run-in-tmp.ts +0 -19
  61. package/src/__tests__/run-wrangler.ts +0 -32
  62. package/src/api/form_data.ts +0 -131
  63. package/src/api/inspect.ts +0 -430
  64. package/src/api/preview.ts +0 -128
  65. package/src/api/worker.ts +0 -155
  66. package/src/cfetch/index.ts +0 -102
  67. package/src/cfetch/internal.ts +0 -69
  68. package/src/cli.ts +0 -9
  69. package/src/config.ts +0 -131
  70. package/src/dev.tsx +0 -874
  71. package/src/dialogs.tsx +0 -77
  72. package/src/index.tsx +0 -1929
  73. package/src/kv.tsx +0 -267
  74. package/src/module-collection.ts +0 -64
  75. package/src/pages.tsx +0 -968
  76. package/src/proxy.ts +0 -103
  77. package/src/publish.ts +0 -350
  78. package/src/sites.tsx +0 -114
  79. package/src/tail.tsx +0 -73
  80. package/src/user.tsx +0 -1022
  81. package/static-asset-facade.js +0 -47
  82. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  83. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  84. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  85. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  86. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  87. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  88. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  89. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  90. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  91. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  92. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  93. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  94. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  95. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  96. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  97. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  98. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  99. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  100. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  101. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  102. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  103. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  104. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  105. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  106. package/vendor/wrangler-mime/LICENSE +0 -21
  107. package/vendor/wrangler-mime/Mime.js +0 -97
  108. package/vendor/wrangler-mime/README.md +0 -187
  109. package/vendor/wrangler-mime/cli.js +0 -46
  110. package/vendor/wrangler-mime/index.js +0 -4
  111. package/vendor/wrangler-mime/lite.js +0 -4
  112. package/vendor/wrangler-mime/package.json +0 -52
  113. package/vendor/wrangler-mime/types/other.js +0 -1
  114. package/vendor/wrangler-mime/types/standard.js +0 -1
  115. package/wrangler-dist/cli.js.map +0 -7
@@ -1,171 +0,0 @@
1
- import type { RequestInit } from "node-fetch";
2
- import type { URLSearchParams } from "node:url";
3
- import { pathToRegexp } from "path-to-regexp";
4
- import { CF_API_BASE_URL } from "../cfetch";
5
- import type { FetchResult } from "../cfetch";
6
-
7
- /**
8
- * The signature of the function that will handle a mock request.
9
- */
10
- export type MockHandler<ResponseType> = (
11
- uri: RegExpExecArray,
12
- init?: RequestInit,
13
- queryParams?: URLSearchParams
14
- ) => ResponseType;
15
-
16
- type RemoveMockFn = () => void;
17
-
18
- interface MockFetch<ResponseType> {
19
- regexp: RegExp;
20
- method: string | undefined;
21
- handler: MockHandler<ResponseType>;
22
- }
23
- const mocks: MockFetch<unknown>[] = [];
24
-
25
- /**
26
- * The mock implementation of `cfApi.fetch()`.
27
- *
28
- * This function will attempt to match the given request to one of the mock handlers configured by calls to `setMock`.
29
- *
30
- * Once found the handler will be used to generate a mock response.
31
- */
32
- export async function mockFetchInternal(
33
- resource: string,
34
- init: RequestInit = {},
35
- queryParams?: URLSearchParams
36
- ) {
37
- for (const { regexp, method, handler } of mocks) {
38
- const resourcePath = new URL(resource, CF_API_BASE_URL).pathname;
39
- const uri = regexp.exec(resourcePath);
40
- // Do the resource path and (if specified) the HTTP method match?
41
- if (uri !== null && (!method || method === init.method)) {
42
- // The `resource` regular expression will extract the labelled groups from the URL.
43
- // These are passed through to the `handler` call, to allow it to do additional checks or behaviour.
44
- return handler(uri, init, queryParams); // TODO: should we have some kind of fallthrough system? we'll see.
45
- }
46
- }
47
- throw new Error(`no mocks found for ${init.method}: ${resource}`);
48
- }
49
-
50
- /**
51
- * Specify an expected resource path that is to be handled, resulting in a raw JSON response.
52
- *
53
- * @param resource The path of the resource to be matched.
54
- * This can include wildcards whose value will be passed to the `handler`.
55
- * @param handler The function that will generate the mock response for this request.
56
- */
57
- export function setMockRawResponse<ResponseType>(
58
- resource: string,
59
- handler: MockHandler<ResponseType>
60
- ): RemoveMockFn;
61
- /**
62
- * Specify an expected resource path that is to be handled, resulting in a raw JSON response.
63
- *
64
- * @param resource The path of the resource to be matched.
65
- * This can include wildcards whose value will be passed to the `handler`.
66
- * @param method The HTTP method (e.g. GET, POST, etc) that the request must have to match this mock handler.
67
- * @param handler The function that will generate the mock response for this request.
68
- */
69
- export function setMockRawResponse<ResponseType>(
70
- resource: string,
71
- method: string,
72
- handler: MockHandler<ResponseType>
73
- ): RemoveMockFn;
74
- /**
75
- * Specify an expected resource path that is to be handled, resulting in a raw JSON response.
76
- */
77
- export function setMockRawResponse<ResponseType>(
78
- resource: string,
79
- ...args: [string, MockHandler<ResponseType>] | [MockHandler<ResponseType>]
80
- ): RemoveMockFn {
81
- const handler = args.pop() as MockHandler<ResponseType>;
82
- const method = args.pop() as string;
83
- const mock = {
84
- resource,
85
- method,
86
- handler,
87
- regexp: pathToRegexp(resource),
88
- };
89
- mocks.push(mock);
90
- return () => {
91
- const mockIndex = mocks.indexOf(mock);
92
- if (mockIndex !== -1) {
93
- mocks.splice(mockIndex, 1);
94
- }
95
- };
96
- }
97
-
98
- /**
99
- * Specify an expected resource path that is to be handled, resulting in a `FetchRequest`.
100
- *
101
- * The mock `handler` should return the `result`, which will then be wrapped in a `FetchRequest` object.
102
- *
103
- * @param resource The path of the resource to be matched.
104
- * This can include wildcards whose value will be passed to the `handler`.
105
- * @param handler The function that will generate the mock response for this request.
106
- */
107
- export function setMockResponse<ResponseType>(
108
- resource: string,
109
- handler: MockHandler<ResponseType>
110
- ): RemoveMockFn;
111
- /**
112
- * Specify an expected resource path that is to be handled, resulting in a FetchRequest..
113
- *
114
- * @param resource The path of the resource to be matched.
115
- * This can include wildcards whose value will be passed to the `handler`.
116
- * @param method The HTTP method (e.g. GET, POST, etc) that the request must have to match this mock handler.
117
- * @param handler The function that will generate the mock response for this request.
118
- */
119
- export function setMockResponse<ResponseType>(
120
- resource: string,
121
- method: string,
122
- handler: MockHandler<ResponseType>
123
- ): RemoveMockFn;
124
- /**
125
- * Specify an expected resource path that is to be handled, resulting in a FetchRequest.
126
- */
127
- export function setMockResponse<ResponseType>(
128
- resource: string,
129
- ...args: [string, MockHandler<ResponseType>] | [MockHandler<ResponseType>]
130
- ): RemoveMockFn {
131
- const handler = args.pop() as MockHandler<ResponseType>;
132
- const method = args.pop() as string;
133
- return setMockRawResponse(resource, method, (...handlerArgs) =>
134
- createFetchResult(handler(...handlerArgs))
135
- );
136
- }
137
-
138
- /**
139
- * A helper to make it easier to create `FetchResult` objects in tests.
140
- */
141
- export function createFetchResult<ResponseType>(
142
- result: ResponseType,
143
- success = true,
144
- errors = [],
145
- messages = [],
146
- result_info?: unknown
147
- ): FetchResult<ResponseType> {
148
- return result_info
149
- ? {
150
- result,
151
- success,
152
- errors,
153
- messages,
154
- result_info,
155
- }
156
- : {
157
- result,
158
- success,
159
- errors,
160
- messages,
161
- };
162
- }
163
-
164
- /**
165
- * Remove all the configured mock handlers.
166
- *
167
- * This should be called in an `afterEach()` block to ensure that mock handlers do not leak between tests.
168
- */
169
- export function unsetAllMocks() {
170
- mocks.length = 0;
171
- }
@@ -1,65 +0,0 @@
1
- import { confirm, prompt } from "../dialogs";
2
-
3
- /**
4
- * The expected values for a confirmation request.
5
- */
6
- export interface ConfirmExpectation {
7
- /** The text expected to be seen in the confirmation dialog. */
8
- text: string;
9
- /** The mock response send back from the confirmation dialog. */
10
- result: boolean;
11
- }
12
-
13
- /**
14
- * Mock the implementation of `confirm()` that will respond with configured results
15
- * for configured confirmation text messages.
16
- *
17
- * If there is a call to `confirm()` that does not match any of the expectations
18
- * then an error is thrown.
19
- */
20
- export function mockConfirm(...expectations: ConfirmExpectation[]) {
21
- (confirm as jest.Mock).mockImplementation((text: string) => {
22
- for (const { text: expectedText, result } of expectations) {
23
- if (text === expectedText) {
24
- return Promise.resolve(result);
25
- }
26
- }
27
- throw new Error(`Unexpected confirmation message: ${text}`);
28
- });
29
- }
30
-
31
- /**
32
- * The expected values for a prompt request.
33
- */
34
- export interface PromptExpectation {
35
- /** The text expected to be seen in the prompt dialog. */
36
- text: string;
37
- /** The type of the prompt. */
38
- type: "text" | "password";
39
- /** The mock response send back from the prompt dialog. */
40
- result: string;
41
- }
42
-
43
- /**
44
- * Mock the implementation of `prompt()` that will respond with configured results
45
- * for configured prompt text messages.
46
- *
47
- * If there is a call to `prompt()` that does not match any of the expectations
48
- * then an error is thrown.
49
- */
50
- export function mockPrompt(...expectations: PromptExpectation[]) {
51
- (prompt as jest.Mock).mockImplementation(
52
- (text: string, type: "text" | "password") => {
53
- for (const {
54
- text: expectedText,
55
- type: expectedType,
56
- result,
57
- } of expectations) {
58
- if (text === expectedText && type == expectedType) {
59
- return Promise.resolve(result);
60
- }
61
- }
62
- throw new Error(`Unexpected confirmation message: ${text}`);
63
- }
64
- );
65
- }
@@ -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
- }