wrangler 0.0.0-ece06ea → 0.0.0-ecef68635

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 (108) hide show
  1. package/README.md +50 -15
  2. package/bin/wrangler.js +94 -31
  3. package/config-schema.json +3074 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +155 -75
  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-mock-analytics-engine.d.ts +3 -0
  21. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  22. package/templates/middleware/middleware-pretty-error.ts +40 -0
  23. package/templates/middleware/middleware-scheduled.ts +29 -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/modules-watch-stub.js +4 -0
  27. package/templates/new-worker-scheduled.js +17 -0
  28. package/templates/new-worker-scheduled.ts +32 -0
  29. package/templates/new-worker.js +15 -0
  30. package/templates/new-worker.ts +33 -0
  31. package/templates/no-op-worker.js +10 -0
  32. package/templates/pages-dev-pipeline.ts +32 -0
  33. package/templates/pages-dev-util.ts +55 -0
  34. package/templates/pages-shim.ts +9 -0
  35. package/templates/pages-template-plugin.ts +190 -0
  36. package/templates/pages-template-worker.ts +198 -0
  37. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  38. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  39. package/templates/tsconfig-sanity.ts +11 -0
  40. package/templates/tsconfig.init.json +22 -0
  41. package/templates/tsconfig.json +8 -0
  42. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  43. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  44. package/wrangler-dist/ProxyWorker.js +241 -0
  45. package/wrangler-dist/ProxyWorker.js.map +6 -0
  46. package/wrangler-dist/cli.d.ts +26463 -0
  47. package/wrangler-dist/cli.js +206335 -125492
  48. package/wrangler-dist/wasm-sync.wasm +0 -0
  49. package/import_meta_url.js +0 -3
  50. package/miniflare-config-stubs/.env.empty +0 -0
  51. package/miniflare-config-stubs/package.empty.json +0 -1
  52. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  53. package/src/__tests__/clipboardy-mock.js +0 -4
  54. package/src/__tests__/fixtures/init/.gitkeep +0 -0
  55. package/src/__tests__/index.test.ts +0 -153
  56. package/src/__tests__/mock-cfetch.js +0 -46
  57. package/src/api/form_data.ts +0 -158
  58. package/src/api/inspect.ts +0 -441
  59. package/src/api/preview.ts +0 -123
  60. package/src/api/worker.ts +0 -161
  61. package/src/cfetch.ts +0 -72
  62. package/src/cli.ts +0 -10
  63. package/src/config.ts +0 -124
  64. package/src/dev.tsx +0 -736
  65. package/src/dialogs.tsx +0 -85
  66. package/src/index.tsx +0 -1845
  67. package/src/kv.tsx +0 -211
  68. package/src/pages.tsx +0 -344
  69. package/src/publish.ts +0 -354
  70. package/src/sites.tsx +0 -115
  71. package/src/tail.tsx +0 -71
  72. package/src/user.tsx +0 -1029
  73. package/src/util/fetch.ts +0 -74
  74. package/static-asset-facade.js +0 -47
  75. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  76. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  77. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  78. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  79. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  80. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  81. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  82. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  83. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  84. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  85. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  86. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  87. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  88. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  89. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  90. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  91. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  92. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  93. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  94. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  95. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  96. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  97. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  98. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  99. package/vendor/wrangler-mime/LICENSE +0 -21
  100. package/vendor/wrangler-mime/Mime.js +0 -97
  101. package/vendor/wrangler-mime/README.md +0 -187
  102. package/vendor/wrangler-mime/cli.js +0 -46
  103. package/vendor/wrangler-mime/index.js +0 -4
  104. package/vendor/wrangler-mime/lite.js +0 -4
  105. package/vendor/wrangler-mime/package.json +0 -52
  106. package/vendor/wrangler-mime/types/other.js +0 -1
  107. package/vendor/wrangler-mime/types/standard.js +0 -1
  108. package/wrangler-dist/cli.js.map +0 -7
Binary file
@@ -1,3 +0,0 @@
1
- // as per https://github.com/evanw/esbuild/issues/1492
2
- // to make some libs work
3
- export const import_meta_url = require("url").pathToFileURL(__filename);
File without changes
@@ -1 +0,0 @@
1
- {}
File without changes
@@ -1,4 +0,0 @@
1
- // We use this mock during tests because we're having trouble
2
- // properly compiling clipboardy for jest
3
- // We can revisit this if and when we write tests that test
4
- // the copying part of `dev`
File without changes
@@ -1,153 +0,0 @@
1
- import * as fs from "node:fs";
2
- import * as fsp from "node:fs/promises";
3
- import * as path from "node:path";
4
- import * as TOML from "@iarna/toml";
5
- import { main } from "../index";
6
- // @ts-expect-error we're mocking cfetch, so of course setMock isn't a thing
7
- import { setMock, unsetAllMocks } from "../cfetch";
8
-
9
- jest.mock("../cfetch", () => {
10
- return jest.requireActual("./mock-cfetch");
11
- });
12
-
13
- async function w(cmd: void | string, options?: { tap: boolean }) {
14
- const tapped = options?.tap ? tap() : undefined;
15
- await main([...(cmd ? cmd.split(" ") : [])]);
16
- tapped?.off();
17
- return { stdout: tapped?.out, stderr: tapped?.err };
18
- }
19
-
20
- function tap() {
21
- const oldLog = console.log;
22
- const oldError = console.error;
23
-
24
- const toReturn = {
25
- off: () => {
26
- console.log = oldLog;
27
- console.error = oldError;
28
- },
29
- out: "",
30
- err: "",
31
- };
32
-
33
- console.log = (...args) => {
34
- toReturn.out += args.join("");
35
- oldLog.apply(console, args);
36
- // console.trace(...args); // use this if you want to find the true source of your console.log
37
- };
38
- console.error = (...args) => {
39
- toReturn.err += args.join("");
40
- oldError.apply(console, args);
41
- };
42
-
43
- return toReturn;
44
- }
45
-
46
- describe("wrangler", () => {
47
- it("should run", async () => {
48
- const { stdout } = await w(undefined, { tap: true });
49
-
50
- expect(stdout).toMatchInlineSnapshot(`
51
- "wrangler
52
-
53
- Commands:
54
- wrangler init [name] 📥 Create a wrangler.toml configuration file
55
- wrangler dev <filename> 👂 Start a local server for developing your worker
56
- wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
57
- wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
58
- wrangler secret 🤫 Generate a secret that can be referenced in the worker script
59
- wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
60
- wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
61
- wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
62
- wrangler pages ⚡️ Configure Cloudflare Pages
63
-
64
- Flags:
65
- --config Path to .toml configuration file [string]
66
- --help Show help [boolean]
67
- --version Show version number [boolean]
68
-
69
- Options:
70
- --local Run on my machine [boolean] [default: false]"
71
- `);
72
- });
73
-
74
- describe("init", () => {
75
- const ogcwd = process.cwd();
76
-
77
- beforeEach(() => {
78
- process.chdir(path.join(__dirname, "fixtures", "init"));
79
- });
80
-
81
- afterEach(async () => {
82
- await fsp.rm("./wrangler.toml");
83
- process.chdir(ogcwd);
84
- });
85
-
86
- it("should create a wrangler.toml", async () => {
87
- await w("init");
88
- const parsed = TOML.parse(await fsp.readFile("./wrangler.toml", "utf-8"));
89
- expect(typeof parsed.compatibility_date).toBe("string");
90
- });
91
-
92
- it("should error when wrangler.toml already exists", async () => {
93
- fs.closeSync(fs.openSync("./wrangler.toml", "w"));
94
- const { stderr } = await w("init", { tap: true });
95
- expect(stderr.endsWith("wrangler.toml already exists.")).toBe(true);
96
- });
97
- });
98
-
99
- describe("kv:namespace", () => {
100
- afterAll(() => {
101
- unsetAllMocks();
102
- });
103
- let KVNamespaces: { title: string; id: string }[] = [];
104
- it("can create a namespace", async () => {
105
- setMock("/accounts/:accountId/storage/kv/namespaces", (uri, init) => {
106
- expect(init.method === "POST");
107
- const body = JSON.parse(init.body);
108
- expect(body.title).toBe("worker-UnitTestNamespace");
109
- KVNamespaces.push({ title: body.title, id: "some-namespace-id" });
110
- return { id: "some-namespace-id" };
111
- });
112
-
113
- await w("kv:namespace create UnitTestNamespace");
114
- expect(
115
- KVNamespaces.find((ns) => ns.title === `worker-UnitTestNamespace`)
116
- ).toBeTruthy();
117
- });
118
-
119
- let createdNamespace: { id: string; title: string };
120
- it("can list namespaces", async () => {
121
- setMock(
122
- "/accounts/:accountId/storage/kv/namespaces\\?:qs",
123
- (uri, init) => {
124
- expect(init).toBe(undefined);
125
- return KVNamespaces;
126
- }
127
- );
128
- const { stdout } = await w("kv:namespace list", { tap: true });
129
- const namespaces = JSON.parse(stdout);
130
- createdNamespace = namespaces.find(
131
- (ns) => ns.title === "worker-UnitTestNamespace"
132
- );
133
- expect(createdNamespace.title).toBe("worker-UnitTestNamespace");
134
- });
135
-
136
- it("can delete a namespace", async () => {
137
- const namespaceIdToDelete = createdNamespace.id;
138
- setMock(
139
- "/accounts/:accountId/storage/kv/namespaces/:namespaceId",
140
- (uri, init) => {
141
- expect(init.method).toBe("DELETE");
142
- KVNamespaces = KVNamespaces.filter(
143
- (ns) => ns.id !== namespaceIdToDelete
144
- );
145
- }
146
- );
147
- await w(`kv:namespace delete --namespace-id ${namespaceIdToDelete}`);
148
- expect(KVNamespaces.find((ns) => ns.id === namespaceIdToDelete)).toBe(
149
- undefined
150
- );
151
- });
152
- });
153
- });
@@ -1,46 +0,0 @@
1
- // This file mocks ../cfetch.ts
2
- // so we can insert whatever responses we want from it
3
-
4
- const pathToRegexp = require("path-to-regexp");
5
- // TODO: add jsdoc style types here
6
-
7
- // type MockHandler = (resource: string, init?: RequestInit) => any; // TODO: use a generic here
8
-
9
- let mocks = [];
10
-
11
- function mockCfetch(resource, init) {
12
- for (const { regexp, handler } of mocks) {
13
- if (regexp.test(resource)) {
14
- return handler(resource, init); // should we have some kind of fallthrough system? we'll see.
15
- }
16
- }
17
- throw new Error(`no mocks found for ${resource}`);
18
- }
19
-
20
- function setMock(resource, handler) {
21
- const mock = {
22
- resource,
23
- handler,
24
- regexp: pathToRegexp(resource),
25
- };
26
- mocks.push(mock);
27
- return () => {
28
- mocks = mocks.filter((x) => x !== mock);
29
- };
30
- }
31
-
32
- function unsetAllMocks() {
33
- mocks = [];
34
- }
35
-
36
- const CF_API_BASE_URL =
37
- process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
38
-
39
- Object.assign(module.exports, {
40
- __esModule: true,
41
- default: mockCfetch,
42
- mockCfetch,
43
- setMock,
44
- unsetAllMocks,
45
- CF_API_BASE_URL,
46
- });
@@ -1,158 +0,0 @@
1
- import type {
2
- CfWorkerInit,
3
- CfModuleType,
4
- CfVariable,
5
- CfModule,
6
- } from "./worker.js";
7
- import { FormData, Blob } from "formdata-node";
8
-
9
- // Credit: https://stackoverflow.com/a/9458996
10
- function toBase64(source: BufferSource): string {
11
- let result = "";
12
- const buffer = source instanceof ArrayBuffer ? source : source.buffer;
13
- const bytes = new Uint8Array(buffer);
14
- for (let i = 0; i < bytes.byteLength; i++) {
15
- result += String.fromCharCode(bytes[i]);
16
- }
17
- return btoa(result);
18
- }
19
-
20
- function toBinding(
21
- name: string,
22
- variable: CfVariable
23
- ): Record<string, unknown> {
24
- if (typeof variable === "string") {
25
- return { name, type: "plain_text", text: variable };
26
- }
27
-
28
- if ("namespaceId" in variable) {
29
- return {
30
- name,
31
- type: "kv_namespace",
32
- namespace_id: variable.namespaceId,
33
- };
34
- }
35
-
36
- if ("class_name" in variable) {
37
- return {
38
- name,
39
- type: "durable_object_namespace",
40
- class_name: variable.class_name,
41
- ...(variable.script_name && {
42
- script_name: variable.script_name,
43
- }),
44
- };
45
- }
46
-
47
- const { format, algorithm, usages, data } = variable;
48
- if (format) {
49
- let key_base64;
50
- let key_jwk;
51
- if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) {
52
- key_base64 = toBase64(data);
53
- } else {
54
- key_jwk = data;
55
- }
56
- return {
57
- name,
58
- type: "secret_key",
59
- format,
60
- algorithm,
61
- usages,
62
- key_base64,
63
- key_jwk,
64
- };
65
- }
66
-
67
- throw new TypeError("Unsupported variable: " + variable);
68
- }
69
-
70
- export function toMimeType(type: CfModuleType): string {
71
- switch (type) {
72
- case "esm":
73
- return "application/javascript+module";
74
- case "commonjs":
75
- return "application/javascript";
76
- case "compiled-wasm":
77
- return "application/wasm";
78
- case "buffer":
79
- return "application/octet-stream";
80
- case "text":
81
- return "text/plain";
82
- default:
83
- throw new TypeError("Unsupported module: " + type);
84
- }
85
- }
86
-
87
- function toModule(module: CfModule, entryType?: CfModuleType): Blob {
88
- const { type: moduleType, content } = module;
89
- const type = toMimeType(moduleType ?? entryType);
90
-
91
- return new Blob([content], { type });
92
- }
93
-
94
- /**
95
- * Creates a `FormData` upload from a `CfWorkerInit`.
96
- */
97
- export function toFormData(worker: CfWorkerInit): FormData {
98
- const formData = new FormData();
99
- const {
100
- main,
101
- modules,
102
- variables,
103
- migrations,
104
- usage_model,
105
- compatibility_date,
106
- compatibility_flags,
107
- } = worker;
108
- const { name, type: mainType } = main;
109
-
110
- const bindings = [];
111
- for (const [name, variable] of Object.entries(variables ?? {})) {
112
- const binding = toBinding(name, variable);
113
- bindings.push(binding);
114
- }
115
-
116
- const metadata =
117
- mainType !== "commonjs"
118
- ? {
119
- main_module: name,
120
- bindings,
121
- }
122
- : {
123
- body_part: name,
124
- bindings,
125
- };
126
- if (compatibility_date) {
127
- // @ts-expect-error - we should type metadata
128
- metadata.compatibility_date = compatibility_date;
129
- }
130
- if (compatibility_flags) {
131
- // @ts-expect-error - we should type metadata
132
- metadata.compatibility_flags = compatibility_flags;
133
- }
134
- if (usage_model) {
135
- // @ts-expect-error - we should type metadata
136
- metadata.usage_model = usage_model;
137
- }
138
- if (migrations) {
139
- // @ts-expect-error - we should type metadata
140
- metadata.migrations = migrations;
141
- }
142
-
143
- formData.set("metadata", JSON.stringify(metadata));
144
-
145
- if (mainType === "commonjs" && modules && modules.length > 0) {
146
- throw new TypeError(
147
- "More than one module can only be specified when type = 'esm'"
148
- );
149
- }
150
-
151
- for (const module of [main].concat(modules || [])) {
152
- const { name } = module;
153
- const blob = toModule(module, mainType ?? "esm");
154
- formData.set(name, blob, name);
155
- }
156
-
157
- return formData;
158
- }