wrangler 0.0.0-e5d3690 → 0.0.0-e60a675d

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 (123) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +47 -16
  3. package/bin/wrangler.js +122 -31
  4. package/config-schema.json +2900 -0
  5. package/kv-asset-handler.js +1 -0
  6. package/package.json +175 -79
  7. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  8. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  9. package/templates/__tests__/tsconfig.json +8 -0
  10. package/templates/checked-fetch.js +30 -0
  11. package/templates/facade.d.ts +19 -0
  12. package/templates/gitignore +167 -0
  13. package/templates/init-tests/test-jest-new-worker.js +23 -0
  14. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  15. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  16. package/templates/middleware/common.ts +67 -0
  17. package/templates/middleware/loader-modules.ts +133 -0
  18. package/templates/middleware/loader-sw.ts +229 -0
  19. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  20. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  21. package/templates/middleware/middleware-pretty-error.ts +40 -0
  22. package/templates/middleware/middleware-scheduled.ts +15 -0
  23. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  24. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  25. package/templates/modules-watch-stub.js +4 -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 +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 +661 -0
  37. package/templates/startDevWorker/ProxyWorker.ts +331 -0
  38. package/templates/tsconfig-sanity.ts +11 -0
  39. package/templates/tsconfig.init.json +105 -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 +240 -0
  44. package/wrangler-dist/ProxyWorker.js.map +6 -0
  45. package/wrangler-dist/cli.d.ts +23983 -0
  46. package/wrangler-dist/cli.js +166972 -117326
  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 -228
  55. package/pages/functions/identifiers.ts +0 -78
  56. package/pages/functions/routes.ts +0 -158
  57. package/pages/functions/template-worker.ts +0 -136
  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 -289
  61. package/src/__tests__/jest.setup.ts +0 -22
  62. package/src/__tests__/kv.test.ts +0 -1199
  63. package/src/__tests__/mock-cfetch.ts +0 -173
  64. package/src/__tests__/mock-dialogs.ts +0 -65
  65. package/src/__tests__/publish.test.ts +0 -672
  66. package/src/__tests__/run-in-tmp.ts +0 -19
  67. package/src/__tests__/run-wrangler.ts +0 -32
  68. package/src/__tests__/whoami.test.tsx +0 -130
  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 -110
  73. package/src/cfetch/internal.ts +0 -71
  74. package/src/cli.ts +0 -9
  75. package/src/config.ts +0 -646
  76. package/src/dev.tsx +0 -779
  77. package/src/dialogs.tsx +0 -77
  78. package/src/index.tsx +0 -1975
  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 -243
  86. package/src/tail.tsx +0 -73
  87. package/src/user.tsx +0 -1019
  88. package/src/whoami.tsx +0 -69
  89. package/static-asset-facade.js +0 -47
  90. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  91. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  92. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  93. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  94. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  95. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  96. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  97. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  98. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  99. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  100. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  101. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  102. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  103. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  104. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  105. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  106. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  107. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  108. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  109. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  110. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  111. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  112. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  113. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  114. package/vendor/wrangler-mime/LICENSE +0 -21
  115. package/vendor/wrangler-mime/Mime.js +0 -97
  116. package/vendor/wrangler-mime/README.md +0 -187
  117. package/vendor/wrangler-mime/cli.js +0 -46
  118. package/vendor/wrangler-mime/index.js +0 -4
  119. package/vendor/wrangler-mime/lite.js +0 -4
  120. package/vendor/wrangler-mime/package.json +0 -52
  121. package/vendor/wrangler-mime/types/other.js +0 -1
  122. package/vendor/wrangler-mime/types/standard.js +0 -1
  123. package/wrangler-dist/cli.js.map +0 -7
package/src/sites.tsx DELETED
@@ -1,243 +0,0 @@
1
- import * as path from "node:path";
2
- import { readdir, readFile, stat } from "node:fs/promises";
3
- import ignore from "ignore";
4
- import { XXHash64 } from "xxhash-addon";
5
- import { fetchResult } from "./cfetch";
6
- import type { Config } from "./config";
7
- import { listNamespaceKeys, listNamespaces, putBulkKeyValue } from "./kv";
8
-
9
- /** Paths to always ignore. */
10
- const ALWAYS_IGNORE = ["node_modules"];
11
- const HIDDEN_FILES_TO_INCLUDE = [
12
- ".well-known", // See https://datatracker.ietf.org/doc/html/rfc8615
13
- ];
14
-
15
- async function* getFilesInFolder(dirPath: string): AsyncIterable<string> {
16
- const files = await readdir(dirPath, { withFileTypes: true });
17
- for (const file of files) {
18
- // Skip files that we never want to process.
19
- if (ALWAYS_IGNORE.some((p) => file.name === p)) {
20
- continue;
21
- }
22
- // Skip hidden files (starting with .) except for some special ones
23
- if (
24
- file.name.startsWith(".") &&
25
- !HIDDEN_FILES_TO_INCLUDE.some((p) => file.name === p)
26
- ) {
27
- continue;
28
- }
29
- // TODO: follow symlinks??
30
- if (file.isDirectory()) {
31
- yield* await getFilesInFolder(path.join(dirPath, file.name));
32
- } else {
33
- yield path.join(dirPath, file.name);
34
- }
35
- }
36
- }
37
-
38
- /**
39
- * Create a hash key for the given content using the xxhash algorithm.
40
- *
41
- * Note we only return the first 10 characters, since we will also include the file name in the asset manifest key
42
- * the most important thing here is to detect changes of a single file to invalidate the cache and
43
- * it's impossible to serve two different files with the same name
44
- */
45
- function hashFileContent(content: string): string {
46
- const hasher = new XXHash64();
47
- hasher.update(Buffer.from(content));
48
- const hash = hasher.digest();
49
- return hash.toString("hex").substring(0, 10);
50
- }
51
-
52
- /**
53
- * Create a hashed asset key for the given asset.
54
- *
55
- * The key will change if the file path or content of the asset changes.
56
- * The algorithm used here matches that of Wrangler 1.
57
- */
58
- function hashAsset(filePath: string, content: string): string {
59
- const extName = path.extname(filePath) || "";
60
- const baseName = path.basename(filePath, extName);
61
- const directory = path.dirname(filePath);
62
- const hash = hashFileContent(content);
63
- return urlSafe(path.join(directory, `${baseName}.${hash}${extName}`));
64
- }
65
-
66
- async function createKVNamespaceIfNotAlreadyExisting(
67
- title: string,
68
- accountId: string
69
- ) {
70
- // check if it already exists
71
- // TODO: this is super inefficient, should be made better
72
- const namespaces = await listNamespaces(accountId);
73
- const found = namespaces.find((x) => x.title === title);
74
- if (found) {
75
- return { created: false, id: found.id };
76
- }
77
-
78
- // else we make the namespace
79
- // TODO: use an export from ./kv
80
- const json = await fetchResult<{ id: string }>(
81
- `/accounts/${accountId}/storage/kv/namespaces`,
82
- {
83
- method: "POST",
84
- headers: {
85
- "Content-Type": "application/json",
86
- },
87
- body: JSON.stringify({ title }),
88
- }
89
- );
90
-
91
- return {
92
- created: true,
93
- id: json.id,
94
- };
95
- }
96
-
97
- /**
98
- * Upload the assets found within the `dirPath` directory to the sites assets KV namespace for
99
- * the worker given by `scriptName`.
100
- *
101
- * @param accountId the account to upload to.
102
- * @param scriptName the name of the worker whose assets we are uploading.
103
- * @param siteAssets an objects describing what assets to upload, or undefined if there are no assets to upload.
104
- * @param preview if true then upload to a "preview" KV namespace.
105
- * @param _env (not implemented).
106
- * @returns a promise for an object mapping the relative paths of the assets to the key of that
107
- * asset in the KV namespace.
108
- */
109
- export async function syncAssets(
110
- accountId: string,
111
- scriptName: string,
112
- siteAssets: AssetPaths | undefined,
113
- preview: boolean,
114
- _env?: string
115
- ): Promise<{
116
- manifest: { [filePath: string]: string } | undefined;
117
- namespace: string | undefined;
118
- }> {
119
- if (siteAssets === undefined) {
120
- return { manifest: undefined, namespace: undefined };
121
- }
122
-
123
- const title = `__${scriptName}_sites_assets${preview ? "_preview" : ""}`;
124
- const { id: namespace } = await createKVNamespaceIfNotAlreadyExisting(
125
- title,
126
- accountId
127
- );
128
-
129
- // let's get all the keys in this namespace
130
- const result = await listNamespaceKeys(accountId, namespace);
131
- const keys = new Set(result.map((x) => x.name));
132
-
133
- const manifest = {};
134
- const upload: {
135
- key: string;
136
- value: string;
137
- base64: boolean;
138
- }[] = [];
139
-
140
- const include = createPatternMatcher(siteAssets.includePatterns, false);
141
- const exclude = createPatternMatcher(siteAssets.excludePatterns, true);
142
- // TODO: this can be more efficient by parallelising
143
- for await (const file of getFilesInFolder(siteAssets.baseDirectory)) {
144
- if (!include(file)) {
145
- continue;
146
- }
147
- if (exclude(file)) {
148
- continue;
149
- }
150
-
151
- await validateAssetSize(file);
152
- console.log(`reading ${file}...`);
153
- const content = await readFile(file, "base64");
154
-
155
- const assetKey = hashAsset(file, content);
156
- validateAssetKey(assetKey);
157
-
158
- // now put each of the files into kv
159
- if (!keys.has(assetKey)) {
160
- console.log(`uploading as ${assetKey}...`);
161
- upload.push({
162
- key: assetKey,
163
- value: content,
164
- base64: true,
165
- });
166
- } else {
167
- console.log(`skipping - already uploaded`);
168
- }
169
- manifest[path.relative(siteAssets.baseDirectory, file)] = assetKey;
170
- }
171
- await putBulkKeyValue(accountId, namespace, JSON.stringify(upload));
172
- return { manifest, namespace };
173
- }
174
-
175
- function createPatternMatcher(
176
- patterns: string[],
177
- exclude: boolean
178
- ): (filePath: string) => boolean {
179
- if (patterns.length === 0) {
180
- return (_filePath) => !exclude;
181
- } else {
182
- const ignorer = ignore().add(patterns);
183
- return (filePath) => ignorer.test(filePath).ignored;
184
- }
185
- }
186
-
187
- async function validateAssetSize(filePath: string) {
188
- const { size } = await stat(filePath);
189
- if (size > 25 * 1024 * 1024) {
190
- throw new Error(
191
- `File ${filePath} is too big, it should be under 25 MiB. See https://developers.cloudflare.com/workers/platform/limits#kv-limits`
192
- );
193
- }
194
- }
195
-
196
- function validateAssetKey(assetKey: string) {
197
- if (assetKey.length > 512) {
198
- throw new Error(
199
- `The asset path key "${assetKey}" exceeds the maximum key size limit of 512. See https://developers.cloudflare.com/workers/platform/limits#kv-limits",`
200
- );
201
- }
202
- }
203
-
204
- /**
205
- * Convert a filePath to be safe to use as a relative URL.
206
- *
207
- * Primarily this involves converting Windows backslashes to forward slashes.
208
- */
209
- function urlSafe(filePath: string): string {
210
- return filePath.replace(/\\/g, "/");
211
- }
212
-
213
- /**
214
- * Information about the assets that should be uploaded
215
- */
216
- export interface AssetPaths {
217
- baseDirectory: string;
218
- includePatterns: string[];
219
- excludePatterns: string[];
220
- }
221
-
222
- /**
223
- * Get an object that describes what assets to upload, if any.
224
- *
225
- * Uses the args (passed from the command line) if available,
226
- * falling back to those defined in the config.
227
- *
228
- * // TODO: Support for environments
229
- */
230
- export function getAssetPaths(
231
- config: Config,
232
- baseDirectory = config.site?.bucket,
233
- includePatterns = config.site?.include ?? [],
234
- excludePatterns = config.site?.exclude ?? []
235
- ): undefined | AssetPaths {
236
- return baseDirectory
237
- ? {
238
- baseDirectory,
239
- includePatterns,
240
- excludePatterns,
241
- }
242
- : undefined;
243
- }
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
- };