wrangler 0.0.0-e22f9d7 → 0.0.0-e24939c53

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 (120) hide show
  1. package/README.md +47 -16
  2. package/bin/wrangler.js +94 -31
  3. package/config-schema.json +3058 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +154 -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-pretty-error.ts +40 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -0
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.js +17 -0
  26. package/templates/new-worker-scheduled.ts +32 -0
  27. package/templates/new-worker.js +15 -0
  28. package/templates/new-worker.ts +33 -0
  29. package/templates/no-op-assets-worker.ts +33 -0
  30. package/templates/no-op-worker.js +10 -0
  31. package/templates/pages-dev-pipeline.ts +32 -0
  32. package/templates/pages-dev-util.ts +55 -0
  33. package/templates/pages-shim.ts +9 -0
  34. package/templates/pages-template-plugin.ts +190 -0
  35. package/templates/pages-template-worker.ts +198 -0
  36. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  37. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  38. package/templates/tsconfig-sanity.ts +11 -0
  39. package/templates/tsconfig.init.json +22 -0
  40. package/templates/tsconfig.json +8 -0
  41. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  42. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  43. package/wrangler-dist/ProxyWorker.js +242 -0
  44. package/wrangler-dist/ProxyWorker.js.map +6 -0
  45. package/wrangler-dist/cli.d.ts +26389 -0
  46. package/wrangler-dist/cli.js +205466 -116944
  47. package/wrangler-dist/wasm-sync.wasm +0 -0
  48. package/import_meta_url.js +0 -3
  49. package/miniflare-config-stubs/.env.empty +0 -0
  50. package/miniflare-config-stubs/package.empty.json +0 -1
  51. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  52. package/pages/functions/buildWorker.ts +0 -62
  53. package/pages/functions/filepath-routing.test.ts +0 -39
  54. package/pages/functions/filepath-routing.ts +0 -221
  55. package/pages/functions/identifiers.ts +0 -78
  56. package/pages/functions/routes.ts +0 -158
  57. package/pages/functions/template-worker.ts +0 -144
  58. package/src/__tests__/clipboardy-mock.js +0 -4
  59. package/src/__tests__/dev.test.tsx +0 -67
  60. package/src/__tests__/index.test.ts +0 -287
  61. package/src/__tests__/jest.setup.ts +0 -22
  62. package/src/__tests__/kv.test.ts +0 -1111
  63. package/src/__tests__/mock-cfetch.ts +0 -171
  64. package/src/__tests__/mock-dialogs.ts +0 -65
  65. package/src/__tests__/run-in-tmp.ts +0 -19
  66. package/src/__tests__/run-wrangler.ts +0 -32
  67. package/src/api/form_data.ts +0 -131
  68. package/src/api/preview.ts +0 -128
  69. package/src/api/worker.ts +0 -155
  70. package/src/cfetch/index.ts +0 -102
  71. package/src/cfetch/internal.ts +0 -69
  72. package/src/cli.ts +0 -9
  73. package/src/config.ts +0 -487
  74. package/src/dev.tsx +0 -784
  75. package/src/dialogs.tsx +0 -77
  76. package/src/index.tsx +0 -1974
  77. package/src/inspect.ts +0 -539
  78. package/src/kv.tsx +0 -276
  79. package/src/module-collection.ts +0 -64
  80. package/src/pages.tsx +0 -1031
  81. package/src/proxy.ts +0 -302
  82. package/src/publish.ts +0 -364
  83. package/src/sites.tsx +0 -118
  84. package/src/tail.tsx +0 -73
  85. package/src/user.tsx +0 -1027
  86. package/static-asset-facade.js +0 -47
  87. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  88. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  89. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  90. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  91. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  92. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  93. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  94. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  95. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  96. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  97. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  98. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  99. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  100. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  101. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  102. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  103. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  104. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  105. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  106. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  107. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  108. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  109. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  110. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  111. package/vendor/wrangler-mime/LICENSE +0 -21
  112. package/vendor/wrangler-mime/Mime.js +0 -97
  113. package/vendor/wrangler-mime/README.md +0 -187
  114. package/vendor/wrangler-mime/cli.js +0 -46
  115. package/vendor/wrangler-mime/index.js +0 -4
  116. package/vendor/wrangler-mime/lite.js +0 -4
  117. package/vendor/wrangler-mime/package.json +0 -52
  118. package/vendor/wrangler-mime/types/other.js +0 -1
  119. package/vendor/wrangler-mime/types/standard.js +0 -1
  120. 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
- };