wrangler 0.0.0-e1c615f → 0.0.0-e1d2fd668

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 (121) hide show
  1. package/README.md +50 -15
  2. package/bin/wrangler.js +94 -31
  3. package/config-schema.json +3126 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +155 -82
  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 +19 -0
  11. package/templates/gitignore +170 -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 +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  21. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  22. package/templates/middleware/middleware-pretty-error.ts +40 -0
  23. package/templates/middleware/middleware-scheduled.ts +29 -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 +32 -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 +664 -0
  38. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  39. package/templates/tsconfig-sanity.ts +11 -0
  40. package/templates/tsconfig.init.json +22 -0
  41. package/templates/tsconfig.json +8 -0
  42. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  43. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  44. package/wrangler-dist/ProxyWorker.js +241 -0
  45. package/wrangler-dist/ProxyWorker.js.map +6 -0
  46. package/wrangler-dist/cli.d.ts +26506 -0
  47. package/wrangler-dist/cli.js +211253 -116921
  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 -57
  54. package/pages/functions/filepath-routing.test.ts +0 -39
  55. package/pages/functions/filepath-routing.ts +0 -221
  56. package/pages/functions/identifiers.ts +0 -78
  57. package/pages/functions/routes.ts +0 -158
  58. package/pages/functions/template-worker.ts +0 -137
  59. package/src/__tests__/clipboardy-mock.js +0 -4
  60. package/src/__tests__/dev.test.tsx +0 -66
  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 -1098
  64. package/src/__tests__/mock-cfetch.ts +0 -171
  65. package/src/__tests__/mock-dialogs.ts +0 -65
  66. package/src/__tests__/run-in-tmp.ts +0 -19
  67. package/src/__tests__/run-wrangler.ts +0 -32
  68. package/src/api/form_data.ts +0 -131
  69. package/src/api/inspect.ts +0 -430
  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 -131
  76. package/src/dev.tsx +0 -874
  77. package/src/dialogs.tsx +0 -77
  78. package/src/index.tsx +0 -1929
  79. package/src/kv.tsx +0 -267
  80. package/src/module-collection.ts +0 -64
  81. package/src/pages.tsx +0 -968
  82. package/src/proxy.ts +0 -103
  83. package/src/publish.ts +0 -350
  84. package/src/sites.tsx +0 -114
  85. package/src/tail.tsx +0 -73
  86. package/src/user.tsx +0 -1022
  87. package/static-asset-facade.js +0 -47
  88. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  89. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  90. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  91. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  92. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  93. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  94. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  95. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  96. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  97. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  98. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  99. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  100. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  101. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  102. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  103. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  104. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  105. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  106. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  107. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  108. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  109. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  110. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  111. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  112. package/vendor/wrangler-mime/LICENSE +0 -21
  113. package/vendor/wrangler-mime/Mime.js +0 -97
  114. package/vendor/wrangler-mime/README.md +0 -187
  115. package/vendor/wrangler-mime/cli.js +0 -46
  116. package/vendor/wrangler-mime/index.js +0 -4
  117. package/vendor/wrangler-mime/lite.js +0 -4
  118. package/vendor/wrangler-mime/package.json +0 -52
  119. package/vendor/wrangler-mime/types/other.js +0 -1
  120. package/vendor/wrangler-mime/types/standard.js +0 -1
  121. package/wrangler-dist/cli.js.map +0 -7
@@ -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
- async function requireLoggedIn(): Promise<void> {
44
- const loggedIn = await loginOrRefreshIfRequired();
45
- if (!loggedIn) {
46
- throw new Error("Not logged in.");
47
- }
48
- }
49
-
50
- function requireApiToken(): string {
51
- const apiToken = getAPIToken();
52
- if (!apiToken) {
53
- throw new Error("No API token found.");
54
- }
55
- return apiToken;
56
- }
57
-
58
- function cloneHeaders(headers: HeadersInit): HeadersInit {
59
- return { ...headers };
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
- });
package/src/config.ts DELETED
@@ -1,131 +0,0 @@
1
- // we're going to manually write both the type definition AND
2
- // the validator for the config, so that we can give better error messages
3
-
4
- type DurableObjectMigration = {
5
- tag: string;
6
- new_classes?: string[];
7
- renamed_classes?: string[];
8
- deleted_classes?: string[];
9
- };
10
-
11
- type Project = "webpack" | "javascript" | "rust";
12
-
13
- type Site = {
14
- // inherited
15
- bucket: string;
16
- "entry-point": string;
17
- include?: string[];
18
- exclude?: string[];
19
- };
20
-
21
- type Dev = {
22
- ip?: string;
23
- port?: number;
24
- local_protocol?: string;
25
- upstream_protocol?: string;
26
- };
27
-
28
- export type Vars = { [key: string]: string };
29
-
30
- type Cron = string; // TODO: we should be able to parse a cron pattern with ts
31
-
32
- type KVNamespace = {
33
- binding: string;
34
- preview_id?: string;
35
- id: string;
36
- };
37
-
38
- type DurableObject = {
39
- name: string;
40
- class_name: string;
41
- script_name?: string;
42
- };
43
-
44
- type Service = {
45
- name: string;
46
- service: string;
47
- environment: string;
48
- };
49
-
50
- type Build = {
51
- command?: string;
52
- cwd?: string;
53
- watch_dir?: string;
54
- } & (
55
- | {
56
- upload?: {
57
- format: "service-worker";
58
- main: string;
59
- };
60
- }
61
- | {
62
- upload?: {
63
- format: "modules";
64
- dir?: string;
65
- main?: string;
66
- rules?: {
67
- type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm";
68
- globs: string[]; // can we use typescript for these patterns?
69
- fallthrough?: boolean;
70
- };
71
- };
72
- }
73
- );
74
-
75
- type UsageModel = "bundled" | "unbound";
76
-
77
- type Env = {
78
- name?: string; // inherited
79
- account_id?: string; // inherited
80
- workers_dev?: boolean; // inherited
81
- compatibility_date?: string; // inherited
82
- compatibility_flags?: string[]; // inherited
83
- zone_id?: string; // inherited
84
- routes?: string[]; // inherited
85
- route?: string; // inherited
86
- webpack_config?: string; // inherited
87
- site?: Site;
88
- jsx_factory?: string; // inherited
89
- jsx_fragment?: string; // inherited
90
- // we should use typescript to parse cron patterns
91
- triggers?: { crons: Cron[] }; // inherited
92
- vars?: Vars;
93
- durable_objects?: { bindings: DurableObject[] };
94
- kv_namespaces?: KVNamespace[];
95
- experimental_services?: Service[];
96
- migrations?: DurableObjectMigration[];
97
- usage_model?: UsageModel; // inherited
98
- };
99
-
100
- export type Config = {
101
- name?: string; // inherited
102
- account_id?: string; // inherited
103
- // @deprecated Don't use this
104
- type?: Project; // top level
105
- compatibility_date?: string; // inherited
106
- compatibility_flags?: string[]; // inherited
107
- // -- there's some mutually exclusive logic for this next block,
108
- // but I didn't bother for now
109
- workers_dev?: boolean; // inherited
110
- zone_id?: string; // inherited
111
- routes?: string[]; // inherited
112
- route?: string; // inherited
113
- // -- end mutually exclusive stuff
114
- // @deprecated Don't use this
115
- webpack_config?: string; // inherited
116
- jsx_factory?: string; // inherited
117
- jsx_fragment?: string; // inherited
118
- vars?: Vars;
119
- durable_objects?: { bindings: DurableObject[] };
120
- kv_namespaces?: KVNamespace[];
121
- experimental_services?: Service[];
122
- migrations?: DurableObjectMigration[];
123
- site?: Site; // inherited
124
- // we should use typescript to parse cron patterns
125
- triggers?: { crons: Cron[] }; // inherited
126
- dev?: Dev;
127
- usage_model?: UsageModel; // inherited
128
- // top level
129
- build?: Build;
130
- env?: { [envName: string]: void | Env };
131
- };