wrangler 0.0.0-e9ab55a → 0.0.0-e9c2b04a

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 (122) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +47 -16
  3. package/bin/wrangler.js +122 -31
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +165 -78
  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-miniflare3-json-error.ts +33 -0
  20. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  21. package/templates/middleware/middleware-multiworker-dev.ts +68 -0
  22. package/templates/middleware/middleware-pretty-error.ts +40 -0
  23. package/templates/middleware/middleware-scheduled.ts +15 -0
  24. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  25. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  26. package/templates/modules-watch-stub.js +4 -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/startDevWorker/InspectorProxyWorker.ts +652 -0
  38. package/templates/startDevWorker/ProxyWorker.ts +252 -0
  39. package/templates/tsconfig-sanity.ts +11 -0
  40. package/templates/tsconfig.init.json +105 -0
  41. package/templates/tsconfig.json +8 -0
  42. package/wrangler-dist/InspectorProxyWorker.js +460 -0
  43. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  44. package/wrangler-dist/ProxyWorker.js +186 -0
  45. package/wrangler-dist/ProxyWorker.js.map +6 -0
  46. package/wrangler-dist/cli.d.ts +23507 -0
  47. package/wrangler-dist/cli.js +152216 -114779
  48. package/wrangler-dist/wasm-sync.wasm +0 -0
  49. package/import_meta_url.js +0 -3
  50. package/miniflare-config-stubs/.env.empty +0 -0
  51. package/miniflare-config-stubs/package.empty.json +0 -1
  52. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  53. package/pages/functions/buildWorker.ts +0 -62
  54. package/pages/functions/filepath-routing.test.ts +0 -39
  55. package/pages/functions/filepath-routing.ts +0 -228
  56. package/pages/functions/identifiers.ts +0 -78
  57. package/pages/functions/routes.ts +0 -158
  58. package/pages/functions/template-worker.ts +0 -136
  59. package/src/__tests__/clipboardy-mock.js +0 -4
  60. package/src/__tests__/dev.test.tsx +0 -67
  61. package/src/__tests__/index.test.ts +0 -287
  62. package/src/__tests__/jest.setup.ts +0 -22
  63. package/src/__tests__/kv.test.ts +0 -1126
  64. package/src/__tests__/mock-cfetch.ts +0 -171
  65. package/src/__tests__/mock-dialogs.ts +0 -65
  66. package/src/__tests__/publish.test.ts +0 -102
  67. package/src/__tests__/run-in-tmp.ts +0 -19
  68. package/src/__tests__/run-wrangler.ts +0 -32
  69. package/src/api/form_data.ts +0 -131
  70. package/src/api/preview.ts +0 -128
  71. package/src/api/worker.ts +0 -155
  72. package/src/cfetch/index.ts +0 -102
  73. package/src/cfetch/internal.ts +0 -69
  74. package/src/cli.ts +0 -9
  75. package/src/config.ts +0 -646
  76. package/src/dev.tsx +0 -784
  77. package/src/dialogs.tsx +0 -77
  78. package/src/index.tsx +0 -1928
  79. package/src/inspect.ts +0 -543
  80. package/src/kv.tsx +0 -276
  81. package/src/module-collection.ts +0 -64
  82. package/src/pages.tsx +0 -1040
  83. package/src/proxy.ts +0 -302
  84. package/src/publish.ts +0 -382
  85. package/src/sites.tsx +0 -118
  86. package/src/tail.tsx +0 -73
  87. package/src/user.tsx +0 -1027
  88. package/static-asset-facade.js +0 -47
  89. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  90. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  91. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  92. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  93. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  94. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  95. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  96. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  97. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  98. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  99. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  100. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  101. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  102. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  103. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  104. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  105. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  106. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  107. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  108. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  109. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  110. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  111. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  112. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  113. package/vendor/wrangler-mime/LICENSE +0 -21
  114. package/vendor/wrangler-mime/Mime.js +0 -97
  115. package/vendor/wrangler-mime/README.md +0 -187
  116. package/vendor/wrangler-mime/cli.js +0 -46
  117. package/vendor/wrangler-mime/index.js +0 -4
  118. package/vendor/wrangler-mime/lite.js +0 -4
  119. package/vendor/wrangler-mime/package.json +0 -52
  120. package/vendor/wrangler-mime/types/other.js +0 -1
  121. package/vendor/wrangler-mime/types/standard.js +0 -1
  122. package/wrangler-dist/cli.js.map +0 -7
package/src/api/worker.ts DELETED
@@ -1,155 +0,0 @@
1
- import type { CfPreviewToken } from "./preview";
2
- import { previewToken } from "./preview";
3
- import fetch from "node-fetch";
4
-
5
- /**
6
- * A Cloudflare account.
7
- */
8
- export interface CfAccount {
9
- /**
10
- * An API token.
11
- *
12
- * @link https://api.cloudflare.com/#user-api-tokens-properties
13
- */
14
- apiToken: string;
15
- /**
16
- * An account ID.
17
- */
18
- accountId: string;
19
- /**
20
- * A zone ID, only required if not using `workers.dev`.
21
- */
22
- zoneId?: string;
23
- }
24
-
25
- /**
26
- * A module type.
27
- */
28
- export type CfModuleType =
29
- | "esm"
30
- | "commonjs"
31
- | "compiled-wasm"
32
- | "text"
33
- | "buffer";
34
-
35
- /**
36
- * An imported module.
37
- */
38
- export interface CfModule {
39
- /**
40
- * The module name.
41
- *
42
- * @example
43
- * './src/index.js'
44
- */
45
- name: string;
46
- /**
47
- * The module content, usually JavaScript or WASM code.
48
- *
49
- * @example
50
- * export default {
51
- * async fetch(request) {
52
- * return new Response('Ok')
53
- * }
54
- * }
55
- */
56
- content: string | BufferSource;
57
- /**
58
- * The module type.
59
- *
60
- * If absent, will default to the main module's type.
61
- */
62
- type?: CfModuleType;
63
- }
64
-
65
- /**
66
- * A map of variable names to values.
67
- */
68
- interface CfVars {
69
- [key: string]: string;
70
- }
71
-
72
- /**
73
- * A KV namespace.
74
- */
75
- interface CfKvNamespace {
76
- binding: string;
77
- id: string;
78
- }
79
-
80
- /**
81
- * A Durable Object.
82
- */
83
- interface CfDurableObject {
84
- name: string;
85
- class_name: string;
86
- script_name?: string;
87
- }
88
-
89
- /**
90
- * A Service.
91
- */
92
- interface CfService {
93
- name: string;
94
- service: string;
95
- environment: string;
96
- }
97
-
98
- export interface CfDurableObjectMigrations {
99
- old_tag?: string;
100
- new_tag: string;
101
- steps: {
102
- new_classes?: string[];
103
- renamed_classes?: string[];
104
- deleted_classes?: string[];
105
- }[];
106
- }
107
-
108
- /**
109
- * Options for creating a `CfWorker`.
110
- */
111
- export interface CfWorkerInit {
112
- /**
113
- * The name of the worker.
114
- */
115
- name: string | undefined;
116
- /**
117
- * The entrypoint module.
118
- */
119
- main: CfModule;
120
- /**
121
- * The list of additional modules.
122
- */
123
- modules: undefined | CfModule[];
124
- /**
125
- * All the bindings
126
- */
127
- bindings: {
128
- kv_namespaces?: CfKvNamespace[];
129
- durable_objects?: { bindings: CfDurableObject[] };
130
- vars?: CfVars;
131
- services?: CfService[];
132
- };
133
- migrations: undefined | CfDurableObjectMigrations;
134
- compatibility_date: string | undefined;
135
- compatibility_flags: undefined | string[];
136
- usage_model: undefined | "bundled" | "unbound";
137
- }
138
-
139
- /**
140
- * A stub to create a Cloudflare Worker preview.
141
- *
142
- * @example
143
- * const {value, host} = await createWorker(init, acct);
144
- */
145
- export async function createWorker(
146
- init: CfWorkerInit,
147
- account: CfAccount
148
- ): Promise<CfPreviewToken> {
149
- const token = await previewToken(account, init);
150
- const response = await fetch(token.prewarmUrl.href, { method: "POST" });
151
- if (!response.ok) {
152
- // console.error("worker failed to prewarm: ", response.statusText);
153
- }
154
- return token;
155
- }
@@ -1,102 +0,0 @@
1
- import type { RequestInit } from "node-fetch";
2
- import { URLSearchParams } from "url";
3
- import { fetchInternal } from "./internal";
4
-
5
- // Check out https://api.cloudflare.com/ for API docs.
6
-
7
- export { CF_API_BASE_URL } from "./internal";
8
-
9
- export interface FetchError {
10
- code: number;
11
- message: string;
12
- }
13
- export interface FetchResult<ResponseType = unknown> {
14
- success: boolean;
15
- result: ResponseType;
16
- errors: FetchError[];
17
- messages: string[];
18
- result_info?: unknown;
19
- }
20
-
21
- /**
22
- * Make a fetch request for a raw JSON value.
23
- */
24
- export async function fetchRaw<ResponseType>(
25
- resource: string,
26
- init: RequestInit = {},
27
- queryParams?: URLSearchParams
28
- ): Promise<ResponseType> {
29
- return fetchInternal<ResponseType>(resource, init, queryParams);
30
- }
31
-
32
- /**
33
- * Make a fetch request, and extract the `result` from the JSON response.
34
- */
35
- export async function fetchResult<ResponseType>(
36
- resource: string,
37
- init: RequestInit = {},
38
- queryParams?: URLSearchParams
39
- ): Promise<ResponseType> {
40
- const json = await fetchInternal<FetchResult<ResponseType>>(
41
- resource,
42
- init,
43
- queryParams
44
- );
45
- if (json.success) {
46
- return json.result;
47
- } else {
48
- throwFetchError(resource, json);
49
- }
50
- }
51
-
52
- /**
53
- * Make a fetch request for a list of values,
54
- * extracting the `result` from the JSON response,
55
- * and repeating the request if the results are paginated.
56
- */
57
- export async function fetchListResult<ResponseType>(
58
- resource: string,
59
- init: RequestInit = {},
60
- queryParams?: URLSearchParams
61
- ): Promise<ResponseType[]> {
62
- const results: ResponseType[] = [];
63
- let getMoreResults = true;
64
- let cursor: string | undefined;
65
- while (getMoreResults) {
66
- if (cursor) {
67
- queryParams = new URLSearchParams(queryParams);
68
- queryParams.set("cursor", cursor);
69
- }
70
- const json = await fetchInternal<FetchResult<ResponseType[]>>(
71
- resource,
72
- init,
73
- queryParams
74
- );
75
- if (json.success) {
76
- results.push(...json.result);
77
- if (hasCursor(json.result_info)) {
78
- cursor = json.result_info?.cursor;
79
- } else {
80
- getMoreResults = false;
81
- }
82
- } else {
83
- throwFetchError(resource, json);
84
- }
85
- }
86
- return results;
87
- }
88
-
89
- function throwFetchError(
90
- resource: string,
91
- response: FetchResult<unknown>
92
- ): never {
93
- response.messages.forEach((message) => console.warn(message));
94
- const errors = response.errors
95
- .map((error) => `${error.code}: ${error.message}`)
96
- .join("\n");
97
- throw new Error(`Failed to fetch ${resource} - ${errors}`);
98
- }
99
-
100
- function hasCursor(result_info: unknown): result_info is { cursor: string } {
101
- return (result_info as { cursor } | undefined)?.cursor !== undefined;
102
- }
@@ -1,69 +0,0 @@
1
- import fetch from "node-fetch";
2
- import type { RequestInit, HeadersInit } from "node-fetch";
3
- import { getAPIToken, loginOrRefreshIfRequired } from "../user";
4
-
5
- export const CF_API_BASE_URL =
6
- process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
7
-
8
- /**
9
- * Make a fetch request to the Cloudflare API.
10
- *
11
- * This function handles acquiring the API token and logging the caller in, as necessary.
12
- *
13
- * Check out https://api.cloudflare.com/ for API docs.
14
- *
15
- * This function should not be used directly, instead use the functions in `cfetch/index.ts`.
16
- */
17
- export async function fetchInternal<ResponseType>(
18
- resource: string,
19
- init: RequestInit = {},
20
- queryParams?: URLSearchParams
21
- ): Promise<ResponseType> {
22
- await requireLoggedIn();
23
- const apiToken = requireApiToken();
24
- const headers = cloneHeaders(init.headers);
25
- addAuthorizationHeader(headers, apiToken);
26
-
27
- const queryString = queryParams ? `?${queryParams.toString()}` : "";
28
- const response = await fetch(`${CF_API_BASE_URL}${resource}${queryString}`, {
29
- method: "GET",
30
- ...init,
31
- headers,
32
- });
33
-
34
- if (response.ok) {
35
- return (await response.json()) as ResponseType;
36
- } else {
37
- throw new Error(
38
- `Failed to fetch ${resource} - ${response.status}: ${response.statusText}`
39
- );
40
- }
41
- }
42
-
43
- function cloneHeaders(headers: HeadersInit | undefined): HeadersInit {
44
- return { ...headers };
45
- }
46
-
47
- async function requireLoggedIn(): Promise<void> {
48
- const loggedIn = await loginOrRefreshIfRequired();
49
- if (!loggedIn) {
50
- throw new Error("Not logged in.");
51
- }
52
- }
53
-
54
- function requireApiToken(): string {
55
- const apiToken = getAPIToken();
56
- if (!apiToken) {
57
- throw new Error("No API token found.");
58
- }
59
- return apiToken;
60
- }
61
-
62
- function addAuthorizationHeader(headers: HeadersInit, apiToken: string): void {
63
- if (headers["Authorization"]) {
64
- throw new Error(
65
- "The request already specifies an authorisation header - cannot add a new one."
66
- );
67
- }
68
- headers["Authorization"] = `Bearer ${apiToken}`;
69
- }
package/src/cli.ts DELETED
@@ -1,9 +0,0 @@
1
- import { hideBin } from "yargs/helpers";
2
- import { main } from ".";
3
-
4
- main(hideBin(process.argv)).catch(() => {
5
- // The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
6
- // Here we just want to ensure that the process exits with a non-zero code.
7
- // We don't want to do this inside the `main()` function, since that would kill the process when running our tests.
8
- process.exit(1);
9
- });