wrangler 0.0.0-e9ab55a → 0.0.0-e9fae558

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 -125
  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 +59 -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/new-worker-scheduled.js +17 -0
  27. package/templates/new-worker-scheduled.ts +32 -0
  28. package/templates/new-worker.js +15 -0
  29. package/templates/new-worker.ts +33 -0
  30. package/templates/no-op-worker.js +10 -0
  31. package/templates/pages-dev-pipeline.ts +31 -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/tsconfig-sanity.ts +11 -0
  37. package/templates/tsconfig.init.json +105 -0
  38. package/templates/tsconfig.json +8 -0
  39. package/wrangler-dist/cli.d.ts +1732 -0
  40. package/wrangler-dist/cli.js +141470 -110893
  41. package/wrangler-dist/wasm-sync.wasm +0 -0
  42. package/import_meta_url.js +0 -3
  43. package/miniflare-config-stubs/.env.empty +0 -0
  44. package/miniflare-config-stubs/package.empty.json +0 -1
  45. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  46. package/pages/functions/buildWorker.ts +0 -62
  47. package/pages/functions/filepath-routing.test.ts +0 -39
  48. package/pages/functions/filepath-routing.ts +0 -228
  49. package/pages/functions/identifiers.ts +0 -78
  50. package/pages/functions/routes.ts +0 -158
  51. package/pages/functions/template-worker.ts +0 -136
  52. package/src/__tests__/clipboardy-mock.js +0 -4
  53. package/src/__tests__/dev.test.tsx +0 -67
  54. package/src/__tests__/index.test.ts +0 -287
  55. package/src/__tests__/jest.setup.ts +0 -22
  56. package/src/__tests__/kv.test.ts +0 -1126
  57. package/src/__tests__/mock-cfetch.ts +0 -171
  58. package/src/__tests__/mock-dialogs.ts +0 -65
  59. package/src/__tests__/publish.test.ts +0 -102
  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/preview.ts +0 -128
  64. package/src/api/worker.ts +0 -155
  65. package/src/cfetch/index.ts +0 -102
  66. package/src/cfetch/internal.ts +0 -69
  67. package/src/cli.ts +0 -9
  68. package/src/config.ts +0 -646
  69. package/src/dev.tsx +0 -784
  70. package/src/dialogs.tsx +0 -77
  71. package/src/index.tsx +0 -1928
  72. package/src/inspect.ts +0 -543
  73. package/src/kv.tsx +0 -276
  74. package/src/module-collection.ts +0 -64
  75. package/src/pages.tsx +0 -1040
  76. package/src/proxy.ts +0 -302
  77. package/src/publish.ts +0 -382
  78. package/src/sites.tsx +0 -118
  79. package/src/tail.tsx +0 -73
  80. package/src/user.tsx +0 -1027
  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
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
- };