wrangler 0.0.0-e6733a3 → 0.0.0-e6ada079
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.
Potentially problematic release.
This version of wrangler might be problematic. Click here for more details.
- package/README.md +47 -16
- package/bin/wrangler.js +94 -31
- package/config-schema.json +3100 -0
- package/kv-asset-handler.js +1 -0
- package/package.json +154 -82
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/checked-fetch.js +30 -0
- package/templates/facade.d.ts +19 -0
- package/templates/gitignore +170 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +67 -0
- package/templates/middleware/loader-modules.ts +134 -0
- package/templates/middleware/loader-sw.ts +229 -0
- package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -0
- package/templates/modules-watch-stub.js +4 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +33 -0
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +32 -0
- package/templates/pages-dev-util.ts +55 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +190 -0
- package/templates/pages-template-worker.ts +198 -0
- package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
- package/templates/startDevWorker/ProxyWorker.ts +334 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +22 -0
- package/templates/tsconfig.json +8 -0
- package/wrangler-dist/InspectorProxyWorker.js +464 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +240 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +26391 -0
- package/wrangler-dist/cli.js +204293 -116652
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/import_meta_url.js +0 -3
- package/miniflare-config-stubs/.env.empty +0 -0
- package/miniflare-config-stubs/package.empty.json +0 -1
- package/miniflare-config-stubs/wrangler.empty.toml +0 -0
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -39
- package/pages/functions/filepath-routing.ts +0 -221
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -158
- package/pages/functions/template-worker.ts +0 -144
- package/src/__tests__/clipboardy-mock.js +0 -4
- package/src/__tests__/dev.test.tsx +0 -66
- package/src/__tests__/index.test.ts +0 -287
- package/src/__tests__/jest.setup.ts +0 -22
- package/src/__tests__/kv.test.ts +0 -1098
- package/src/__tests__/mock-cfetch.ts +0 -171
- package/src/__tests__/mock-dialogs.ts +0 -65
- package/src/__tests__/run-in-tmp.ts +0 -19
- package/src/__tests__/run-wrangler.ts +0 -32
- package/src/api/form_data.ts +0 -131
- package/src/api/preview.ts +0 -128
- package/src/api/worker.ts +0 -155
- package/src/cfetch/index.ts +0 -102
- package/src/cfetch/internal.ts +0 -69
- package/src/cli.ts +0 -9
- package/src/config.ts +0 -487
- package/src/dev.tsx +0 -771
- package/src/dialogs.tsx +0 -77
- package/src/index.tsx +0 -1974
- package/src/inspect.ts +0 -524
- package/src/kv.tsx +0 -267
- package/src/module-collection.ts +0 -64
- package/src/pages.tsx +0 -1031
- package/src/proxy.ts +0 -294
- package/src/publish.ts +0 -358
- package/src/sites.tsx +0 -114
- package/src/tail.tsx +0 -73
- package/src/user.tsx +0 -1025
- package/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
package/src/sites.tsx
DELETED
@@ -1,114 +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
|
-
// TODO: this can be more efficient by parallelising
|
94
|
-
for await (const file of getFilesInFolder(dirPath)) {
|
95
|
-
// TODO: "exclude:" config
|
96
|
-
const { filePath } = await hashFile(file);
|
97
|
-
// now put each of the files into kv
|
98
|
-
if (!keys.has(filePath)) {
|
99
|
-
console.log(`uploading ${file}...`);
|
100
|
-
const content = await readFile(file, "base64");
|
101
|
-
if (content.length > 25 * 1024 * 1024) {
|
102
|
-
throw new Error(`File ${file} is too big, it should be under 25 mb.`);
|
103
|
-
}
|
104
|
-
upload.push({
|
105
|
-
key: filePath,
|
106
|
-
value: content,
|
107
|
-
base64: true,
|
108
|
-
});
|
109
|
-
}
|
110
|
-
manifest[path.relative(dirPath, file)] = filePath;
|
111
|
-
}
|
112
|
-
await putBulkKeyValue(accountId, namespace, JSON.stringify(upload));
|
113
|
-
return { manifest, namespace };
|
114
|
-
}
|
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
|
-
};
|