wrangler 0.0.0-e22f9d7 → 0.0.0-e2472f152

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 +49 -26
  2. package/bin/wrangler.js +88 -31
  3. package/config-schema.json +2290 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +146 -89
  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-patch-console-prefix.d.ts +3 -0
  23. package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
  24. package/templates/middleware/middleware-pretty-error.ts +40 -0
  25. package/templates/middleware/middleware-scheduled.ts +29 -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 +33 -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 +15 -0
  42. package/templates/tsconfig.tsbuildinfo +1 -0
  43. package/wrangler-dist/InspectorProxyWorker.js +460 -0
  44. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  45. package/wrangler-dist/ProxyWorker.js +238 -0
  46. package/wrangler-dist/ProxyWorker.js.map +6 -0
  47. package/wrangler-dist/cli.d.ts +26699 -0
  48. package/wrangler-dist/cli.js +147915 -118486
  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 -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 -144
  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 -1111
  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/preview.ts +0 -128
  70. package/src/api/worker.ts +0 -155
  71. package/src/cfetch/index.ts +0 -102
  72. package/src/cfetch/internal.ts +0 -69
  73. package/src/cli.ts +0 -9
  74. package/src/config.ts +0 -487
  75. package/src/dev.tsx +0 -784
  76. package/src/dialogs.tsx +0 -77
  77. package/src/index.tsx +0 -1974
  78. package/src/inspect.ts +0 -539
  79. package/src/kv.tsx +0 -276
  80. package/src/module-collection.ts +0 -64
  81. package/src/pages.tsx +0 -1031
  82. package/src/proxy.ts +0 -302
  83. package/src/publish.ts +0 -364
  84. package/src/sites.tsx +0 -118
  85. package/src/tail.tsx +0 -73
  86. package/src/user.tsx +0 -1027
  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
package/src/sites.tsx DELETED
@@ -1,118 +0,0 @@
1
- import crypto from "node:crypto";
2
- import { createReadStream } from "node:fs";
3
- import * as path from "node:path";
4
- import { readdir, readFile } from "node:fs/promises";
5
- import { fetchResult } from "./cfetch";
6
- import { listNamespaceKeys, listNamespaces, putBulkKeyValue } from "./kv";
7
-
8
- async function* getFilesInFolder(dirPath: string): AsyncIterable<string> {
9
- const files = await readdir(dirPath, { withFileTypes: true });
10
- for (const file of files) {
11
- if (file.isDirectory()) {
12
- yield* await getFilesInFolder(path.join(dirPath, file.name));
13
- } else {
14
- yield path.join(dirPath, file.name);
15
- }
16
- }
17
- }
18
-
19
- async function hashFileContent(filePath: string): Promise<string> {
20
- return new Promise((resolve, reject) => {
21
- const hash = crypto.createHash("sha1");
22
- const rs = createReadStream(filePath);
23
- rs.on("error", reject);
24
- rs.on("data", (chunk) => hash.update(chunk));
25
- rs.on("end", () => resolve(hash.digest("hex")));
26
- });
27
- }
28
-
29
- async function hashFile(filePath: string): Promise<{
30
- filePath: string;
31
- hash: string;
32
- }> {
33
- const extName = path.extname(filePath);
34
- const baseName = path.basename(filePath, extName);
35
- const hash = await hashFileContent(filePath);
36
- return {
37
- filePath: `${baseName}.${hash}${extName || ""}`,
38
- hash,
39
- };
40
- }
41
-
42
- async function createKVNamespaceIfNotAlreadyExisting(
43
- title: string,
44
- accountId: string
45
- ) {
46
- // check if it already exists
47
- // TODO: this is super inefficient, should be made better
48
- const namespaces = await listNamespaces(accountId);
49
- const found = namespaces.find((x) => x.title === title);
50
- if (found) {
51
- return { created: false, id: found.id };
52
- }
53
-
54
- // else we make the namespace
55
- // TODO: use an export from ./kv
56
- const json = await fetchResult<{ id: string }>(
57
- `/accounts/${accountId}/storage/kv/namespaces`,
58
- {
59
- method: "POST",
60
- headers: {
61
- "Content-Type": "application/json",
62
- },
63
- body: JSON.stringify({ title }),
64
- }
65
- );
66
-
67
- return {
68
- created: true,
69
- id: json.id,
70
- };
71
- }
72
-
73
- export async function syncAssets(
74
- accountId: string,
75
- scriptName: string,
76
- dirPath: string,
77
- preview: boolean,
78
- _env?: string
79
- ) {
80
- const title = `__${scriptName}_sites_assets${preview ? "_preview" : ""}`;
81
- const { id: namespace } = await createKVNamespaceIfNotAlreadyExisting(
82
- title,
83
- accountId
84
- );
85
-
86
- // let's get all the keys in this namespace
87
- const keys = new Set(
88
- (await listNamespaceKeys(accountId, namespace)).map((x) => x.name)
89
- );
90
-
91
- const manifest = {};
92
- const upload: {
93
- key: string;
94
- value: string;
95
- base64: boolean;
96
- }[] = [];
97
- // TODO: this can be more efficient by parallelising
98
- for await (const file of getFilesInFolder(dirPath)) {
99
- // TODO: "exclude:" config
100
- const { filePath } = await hashFile(file);
101
- // now put each of the files into kv
102
- if (!keys.has(filePath)) {
103
- console.log(`uploading ${file}...`);
104
- const content = await readFile(file, "base64");
105
- if (content.length > 25 * 1024 * 1024) {
106
- throw new Error(`File ${file} is too big, it should be under 25 mb.`);
107
- }
108
- upload.push({
109
- key: filePath,
110
- value: content,
111
- base64: true,
112
- });
113
- }
114
- manifest[path.relative(dirPath, file)] = filePath;
115
- }
116
- await putBulkKeyValue(accountId, namespace, JSON.stringify(upload));
117
- return { manifest, namespace };
118
- }
package/src/tail.tsx DELETED
@@ -1,73 +0,0 @@
1
- import WebSocket from "ws";
2
- import { version as packageVersion } from "../package.json";
3
- import { fetchResult } from "./cfetch";
4
-
5
- export type TailApiResponse = {
6
- id: string;
7
- url: string;
8
- expires_at: Date;
9
- };
10
-
11
- function makeCreateTailUrl(accountId: string, workerName: string): string {
12
- return `/accounts/${accountId}/workers/scripts/${workerName}/tails`;
13
- }
14
-
15
- function makeDeleteTailUrl(
16
- accountId: string,
17
- workerName: string,
18
- tailId: string
19
- ): string {
20
- return `/accounts/${accountId}/workers/scripts/${workerName}/tails/${tailId}`;
21
- }
22
-
23
- /// Creates a tail, but doesn't connect to it.
24
- async function createTailButDontConnect(
25
- accountId: string,
26
- workerName: string
27
- ): Promise<TailApiResponse> {
28
- const createTailUrl = makeCreateTailUrl(accountId, workerName);
29
- /// https://api.cloudflare.com/#worker-tail-logs-start-tail
30
- return await fetchResult<TailApiResponse>(createTailUrl, {
31
- method: "POST",
32
- });
33
- }
34
-
35
- export async function createTail(
36
- accountId: string,
37
- workerName: string,
38
- _filters: Filters
39
- ): Promise<{
40
- tail: WebSocket;
41
- expiration: Date;
42
- deleteTail: () => Promise<void>;
43
- }> {
44
- const {
45
- id: tailId,
46
- url: websocketUrl,
47
- expires_at: expiration,
48
- } = await createTailButDontConnect(accountId, workerName);
49
- const deleteUrl = makeDeleteTailUrl(accountId, workerName, tailId);
50
-
51
- // deletes the tail
52
- async function deleteTail() {
53
- await fetchResult(deleteUrl, { method: "DELETE" });
54
- }
55
-
56
- const tail = new WebSocket(websocketUrl, "trace-v1", {
57
- headers: {
58
- "Sec-WebSocket-Protocol": "trace-v1", // needs to be `trace-v1` to be accepted
59
- "User-Agent": `wrangler-js/${packageVersion}`,
60
- },
61
- });
62
-
63
- // TODO: send filters as well
64
- return { tail, expiration, deleteTail };
65
- }
66
-
67
- export type Filters = {
68
- status?: "ok" | "error" | "canceled";
69
- header?: string;
70
- method?: string;
71
- "sampling-rate"?: number;
72
- search?: string;
73
- };