wrangler 0.0.0-e9a1820 → 0.0.0-e9c2b04a
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.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +47 -16
- package/bin/wrangler.js +122 -31
- package/kv-asset-handler.js +1 -0
- package/package.json +168 -74
- 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 +17 -0
- package/templates/gitignore +172 -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 +137 -0
- package/templates/middleware/loader-sw.ts +228 -0
- package/templates/middleware/middleware-d1-beta.d.ts +3 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +33 -0
- package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
- package/templates/middleware/middleware-multiworker-dev.ts +68 -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 +31 -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 +652 -0
- package/templates/startDevWorker/ProxyWorker.ts +252 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +8 -0
- package/wrangler-dist/InspectorProxyWorker.js +460 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +186 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +23507 -0
- package/wrangler-dist/cli.js +153110 -109544
- 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/src/__tests__/clipboardy-mock.js +0 -4
- package/src/__tests__/index.test.ts +0 -287
- package/src/__tests__/jest.setup.ts +0 -18
- package/src/__tests__/kv.test.ts +0 -322
- package/src/__tests__/mock-cfetch.ts +0 -63
- 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/inspect.ts +0 -430
- package/src/api/preview.ts +0 -128
- package/src/api/worker.ts +0 -155
- package/src/cfetch.ts +0 -72
- package/src/cli.ts +0 -9
- package/src/config.ts +0 -131
- package/src/dev.tsx +0 -879
- package/src/dialogs.tsx +0 -77
- package/src/index.tsx +0 -1902
- package/src/kv.tsx +0 -257
- package/src/module-collection.ts +0 -64
- package/src/pages.tsx +0 -851
- package/src/proxy.ts +0 -103
- package/src/publish.ts +0 -350
- package/src/sites.tsx +0 -115
- package/src/tail.tsx +0 -71
- package/src/user.tsx +0 -1022
- 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
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// This file mocks ../cfetch.ts
|
|
2
|
-
// so we can insert whatever responses we want from it
|
|
3
|
-
import { pathToRegexp } from "path-to-regexp";
|
|
4
|
-
|
|
5
|
-
// Sadly we cannot give use the correct `RequestInit` type from node-fetch.
|
|
6
|
-
// Jest needs to transform the code as part of the module mocking, and it doesn't know how to cope with such types.
|
|
7
|
-
type RequestInit = { method: string; body: string };
|
|
8
|
-
type MockHandler = (uri: RegExpExecArray, init?: RequestInit) => unknown;
|
|
9
|
-
type MockFetch = {
|
|
10
|
-
regexp: RegExp;
|
|
11
|
-
method: string | undefined;
|
|
12
|
-
handler: MockHandler;
|
|
13
|
-
};
|
|
14
|
-
type RemoveMockFn = () => void;
|
|
15
|
-
|
|
16
|
-
let mocks: MockFetch[] = [];
|
|
17
|
-
|
|
18
|
-
export default function mockCfetch(
|
|
19
|
-
resource: string,
|
|
20
|
-
init: RequestInit
|
|
21
|
-
): unknown {
|
|
22
|
-
for (const { regexp, method, handler } of mocks) {
|
|
23
|
-
const uri = regexp.exec(resource);
|
|
24
|
-
// Do the resource path and (if specified) the HTTP method match?
|
|
25
|
-
if (uri !== null && (!method || method === init.method)) {
|
|
26
|
-
// The `resource` regular expression will extract the labelled groups from the URL.
|
|
27
|
-
// These are passed through to the `handler` call, to allow it to do additional checks or behaviour.
|
|
28
|
-
return handler(uri, init); // TODO: should we have some kind of fallthrough system? we'll see.
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
throw new Error(`no mocks found for ${resource}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Specify an expected resource path that is to be handled.
|
|
36
|
-
*/
|
|
37
|
-
export function setMock(
|
|
38
|
-
resource: string,
|
|
39
|
-
method: string,
|
|
40
|
-
handler: MockHandler
|
|
41
|
-
): RemoveMockFn;
|
|
42
|
-
export function setMock(resource: string, handler: MockHandler): RemoveMockFn;
|
|
43
|
-
export function setMock(resource: string, ...args: unknown[]): RemoveMockFn {
|
|
44
|
-
const handler = args.pop() as MockHandler;
|
|
45
|
-
const method = args.pop() as string;
|
|
46
|
-
const mock = {
|
|
47
|
-
resource,
|
|
48
|
-
method,
|
|
49
|
-
handler,
|
|
50
|
-
regexp: pathToRegexp(resource),
|
|
51
|
-
};
|
|
52
|
-
mocks.push(mock);
|
|
53
|
-
return () => {
|
|
54
|
-
mocks = mocks.filter((x) => x !== mock);
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function unsetAllMocks() {
|
|
59
|
-
mocks = [];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const CF_API_BASE_URL =
|
|
63
|
-
process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { confirm, prompt } from "../dialogs";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The expected values for a confirmation request.
|
|
5
|
-
*/
|
|
6
|
-
export interface ConfirmExpectation {
|
|
7
|
-
/** The text expected to be seen in the confirmation dialog. */
|
|
8
|
-
text: string;
|
|
9
|
-
/** The mock response send back from the confirmation dialog. */
|
|
10
|
-
result: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Mock the implementation of `confirm()` that will respond with configured results
|
|
15
|
-
* for configured confirmation text messages.
|
|
16
|
-
*
|
|
17
|
-
* If there is a call to `confirm()` that does not match any of the expectations
|
|
18
|
-
* then an error is thrown.
|
|
19
|
-
*/
|
|
20
|
-
export function mockConfirm(...expectations: ConfirmExpectation[]) {
|
|
21
|
-
(confirm as jest.Mock).mockImplementation((text: string) => {
|
|
22
|
-
for (const { text: expectedText, result } of expectations) {
|
|
23
|
-
if (text === expectedText) {
|
|
24
|
-
return Promise.resolve(result);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
throw new Error(`Unexpected confirmation message: ${text}`);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The expected values for a prompt request.
|
|
33
|
-
*/
|
|
34
|
-
export interface PromptExpectation {
|
|
35
|
-
/** The text expected to be seen in the prompt dialog. */
|
|
36
|
-
text: string;
|
|
37
|
-
/** The type of the prompt. */
|
|
38
|
-
type: "text" | "password";
|
|
39
|
-
/** The mock response send back from the prompt dialog. */
|
|
40
|
-
result: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Mock the implementation of `prompt()` that will respond with configured results
|
|
45
|
-
* for configured prompt text messages.
|
|
46
|
-
*
|
|
47
|
-
* If there is a call to `prompt()` that does not match any of the expectations
|
|
48
|
-
* then an error is thrown.
|
|
49
|
-
*/
|
|
50
|
-
export function mockPrompt(...expectations: PromptExpectation[]) {
|
|
51
|
-
(prompt as jest.Mock).mockImplementation(
|
|
52
|
-
(text: string, type: "text" | "password") => {
|
|
53
|
-
for (const {
|
|
54
|
-
text: expectedText,
|
|
55
|
-
type: expectedType,
|
|
56
|
-
result,
|
|
57
|
-
} of expectations) {
|
|
58
|
-
if (text === expectedText && type == expectedType) {
|
|
59
|
-
return Promise.resolve(result);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
throw new Error(`Unexpected confirmation message: ${text}`);
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as os from "node:os";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
|
|
5
|
-
const originalCwd = process.cwd();
|
|
6
|
-
|
|
7
|
-
export function runInTempDir() {
|
|
8
|
-
let tmpDir: string;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"));
|
|
12
|
-
process.chdir(tmpDir);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
process.chdir(originalCwd);
|
|
17
|
-
fs.rmSync(tmpDir, { recursive: true });
|
|
18
|
-
});
|
|
19
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { main } from "../index";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Run the wrangler CLI tool in tests, capturing the logging output.
|
|
5
|
-
*/
|
|
6
|
-
export async function runWrangler(cmd?: string) {
|
|
7
|
-
const logSpy = jest.spyOn(console, "log").mockImplementation();
|
|
8
|
-
const errorSpy = jest.spyOn(console, "error").mockImplementation();
|
|
9
|
-
const warnSpy = jest.spyOn(console, "warn").mockImplementation();
|
|
10
|
-
try {
|
|
11
|
-
let error: unknown = undefined;
|
|
12
|
-
try {
|
|
13
|
-
await main(cmd?.split(" ") ?? []);
|
|
14
|
-
} catch (e) {
|
|
15
|
-
error = e;
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
error,
|
|
19
|
-
stdout: captureCalls(logSpy),
|
|
20
|
-
stderr: captureCalls(errorSpy),
|
|
21
|
-
warnings: captureCalls(warnSpy),
|
|
22
|
-
};
|
|
23
|
-
} finally {
|
|
24
|
-
logSpy.mockRestore();
|
|
25
|
-
errorSpy.mockRestore();
|
|
26
|
-
warnSpy.mockRestore();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function captureCalls(spy: jest.SpyInstance): string {
|
|
31
|
-
return spy.mock.calls.flat(2).join("\n");
|
|
32
|
-
}
|
package/src/api/form_data.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
CfWorkerInit,
|
|
3
|
-
CfModuleType,
|
|
4
|
-
CfModule,
|
|
5
|
-
CfDurableObjectMigrations,
|
|
6
|
-
} from "./worker.js";
|
|
7
|
-
import { FormData, Blob } from "formdata-node";
|
|
8
|
-
|
|
9
|
-
export function toMimeType(type: CfModuleType): string {
|
|
10
|
-
switch (type) {
|
|
11
|
-
case "esm":
|
|
12
|
-
return "application/javascript+module";
|
|
13
|
-
case "commonjs":
|
|
14
|
-
return "application/javascript";
|
|
15
|
-
case "compiled-wasm":
|
|
16
|
-
return "application/wasm";
|
|
17
|
-
case "buffer":
|
|
18
|
-
return "application/octet-stream";
|
|
19
|
-
case "text":
|
|
20
|
-
return "text/plain";
|
|
21
|
-
default:
|
|
22
|
-
throw new TypeError("Unsupported module: " + type);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function toModule(module: CfModule, entryType?: CfModuleType): Blob {
|
|
27
|
-
const { type: moduleType, content } = module;
|
|
28
|
-
const type = toMimeType(moduleType ?? entryType);
|
|
29
|
-
|
|
30
|
-
return new Blob([content], { type });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface WorkerMetadata {
|
|
34
|
-
compatibility_date?: string;
|
|
35
|
-
compatibility_flags?: string[];
|
|
36
|
-
usage_model?: "bundled" | "unbound";
|
|
37
|
-
migrations?: CfDurableObjectMigrations;
|
|
38
|
-
bindings: (
|
|
39
|
-
| { type: "kv_namespace"; name: string; namespace_id: string }
|
|
40
|
-
| { type: "plain_text"; name: string; text: string }
|
|
41
|
-
| {
|
|
42
|
-
type: "durable_object_namespace";
|
|
43
|
-
name: string;
|
|
44
|
-
class_name: string;
|
|
45
|
-
script_name?: string;
|
|
46
|
-
}
|
|
47
|
-
| {
|
|
48
|
-
type: "service";
|
|
49
|
-
name: string;
|
|
50
|
-
service: string;
|
|
51
|
-
environment: string;
|
|
52
|
-
}
|
|
53
|
-
)[];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Creates a `FormData` upload from a `CfWorkerInit`.
|
|
58
|
-
*/
|
|
59
|
-
export function toFormData(worker: CfWorkerInit): FormData {
|
|
60
|
-
const formData = new FormData();
|
|
61
|
-
const {
|
|
62
|
-
main,
|
|
63
|
-
modules,
|
|
64
|
-
bindings,
|
|
65
|
-
migrations,
|
|
66
|
-
usage_model,
|
|
67
|
-
compatibility_date,
|
|
68
|
-
compatibility_flags,
|
|
69
|
-
} = worker;
|
|
70
|
-
|
|
71
|
-
const metadataBindings: WorkerMetadata["bindings"] = [];
|
|
72
|
-
|
|
73
|
-
bindings.kv_namespaces?.forEach(({ id, binding }) => {
|
|
74
|
-
metadataBindings.push({
|
|
75
|
-
name: binding,
|
|
76
|
-
type: "kv_namespace",
|
|
77
|
-
namespace_id: id,
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
bindings.durable_objects?.bindings.forEach(
|
|
82
|
-
({ name, class_name, script_name }) => {
|
|
83
|
-
metadataBindings.push({
|
|
84
|
-
name,
|
|
85
|
-
type: "durable_object_namespace",
|
|
86
|
-
class_name: class_name,
|
|
87
|
-
...(script_name && { script_name }),
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
Object.entries(bindings.vars || {})?.forEach(([key, value]) => {
|
|
93
|
-
metadataBindings.push({ name: key, type: "plain_text", text: value });
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
bindings.services?.forEach(({ name, service, environment }) => {
|
|
97
|
-
metadataBindings.push({
|
|
98
|
-
name,
|
|
99
|
-
type: "service",
|
|
100
|
-
service,
|
|
101
|
-
environment,
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const metadata: WorkerMetadata = {
|
|
106
|
-
...(main.type !== "commonjs"
|
|
107
|
-
? { main_module: main.name }
|
|
108
|
-
: { body_part: main.name }),
|
|
109
|
-
bindings: metadataBindings,
|
|
110
|
-
...(compatibility_date && { compatibility_date }),
|
|
111
|
-
...(compatibility_flags && { compatibility_flags }),
|
|
112
|
-
...(usage_model && { usage_model }),
|
|
113
|
-
...(migrations && { migrations }),
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
formData.set("metadata", JSON.stringify(metadata));
|
|
117
|
-
|
|
118
|
-
if (main.type === "commonjs" && modules && modules.length > 0) {
|
|
119
|
-
throw new TypeError(
|
|
120
|
-
"More than one module can only be specified when type = 'esm'"
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
for (const module of [main].concat(modules || [])) {
|
|
125
|
-
const { name } = module;
|
|
126
|
-
const blob = toModule(module, main.type ?? "esm");
|
|
127
|
-
formData.set(name, blob, name);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return formData;
|
|
131
|
-
}
|