wrangler 0.0.0-e95e5a0 → 0.0.0-e978986
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 +3 -1
- package/bin/wrangler.js +36 -4
- package/package.json +11 -7
- package/pages/functions/buildPlugin.ts +13 -0
- package/pages/functions/buildWorker.ts +14 -1
- package/pages/functions/template-plugin.ts +3 -2
- package/src/__tests__/configuration.test.ts +336 -87
- package/src/__tests__/dev.test.tsx +243 -25
- package/src/__tests__/helpers/mock-dialogs.ts +41 -1
- package/src/__tests__/index.test.ts +79 -72
- package/src/__tests__/init.test.ts +182 -131
- package/src/__tests__/jest.setup.ts +8 -0
- package/src/__tests__/kv.test.ts +173 -146
- package/src/__tests__/package-manager.test.ts +154 -7
- package/src/__tests__/pages.test.ts +381 -53
- package/src/__tests__/parse.test.ts +8 -0
- package/src/__tests__/publish.test.ts +682 -89
- package/src/__tests__/r2.test.ts +55 -36
- package/src/__tests__/secret.test.ts +39 -4
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +33 -2
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +17 -9
- package/src/config/config.ts +1 -1
- package/src/config/environment.ts +40 -14
- package/src/config/index.ts +162 -0
- package/src/config/validation.ts +180 -65
- package/src/create-worker-preview.ts +17 -7
- package/src/create-worker-upload-form.ts +22 -8
- package/src/dev/dev.tsx +7 -6
- package/src/dev/local.tsx +6 -0
- package/src/dev/remote.tsx +15 -1
- package/src/dialogs.tsx +48 -0
- package/src/durable.ts +102 -0
- package/src/entry.ts +64 -9
- package/src/index.tsx +357 -177
- package/src/inspect.ts +39 -0
- package/src/kv.ts +114 -25
- package/src/open-in-browser.ts +5 -12
- package/src/package-manager.ts +50 -3
- package/src/pages.tsx +271 -110
- package/src/parse.ts +23 -4
- package/src/proxy.ts +38 -22
- package/src/publish.ts +227 -113
- package/src/sites.tsx +19 -17
- package/src/user.tsx +11 -1
- package/src/worker.ts +8 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.ts +16 -1
- package/wrangler-dist/cli.js +36017 -22687
package/src/sites.tsx
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
1
2
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
2
3
|
import * as path from "node:path";
|
|
3
4
|
import ignore from "ignore";
|
|
4
5
|
import xxhash from "xxhash-wasm";
|
|
5
6
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
createKVNamespace,
|
|
8
|
+
listKVNamespaceKeys,
|
|
9
|
+
listKVNamespaces,
|
|
10
|
+
putKVBulkKeyValue,
|
|
11
|
+
deleteKVBulkKeyValue,
|
|
11
12
|
} from "./kv";
|
|
12
13
|
import { logger } from "./logger";
|
|
13
14
|
import type { Config } from "./config";
|
|
@@ -75,14 +76,14 @@ async function createKVNamespaceIfNotAlreadyExisting(
|
|
|
75
76
|
) {
|
|
76
77
|
// check if it already exists
|
|
77
78
|
// TODO: this is super inefficient, should be made better
|
|
78
|
-
const namespaces = await
|
|
79
|
+
const namespaces = await listKVNamespaces(accountId);
|
|
79
80
|
const found = namespaces.find((x) => x.title === title);
|
|
80
81
|
if (found) {
|
|
81
82
|
return { created: false, id: found.id };
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
// else we make the namespace
|
|
85
|
-
const id = await
|
|
86
|
+
const id = await createKVNamespace(accountId, title);
|
|
86
87
|
logger.log(`🌀 Created namespace for Workers Site "${title}"`);
|
|
87
88
|
|
|
88
89
|
return {
|
|
@@ -103,7 +104,7 @@ async function createKVNamespaceIfNotAlreadyExisting(
|
|
|
103
104
|
* asset in the KV namespace.
|
|
104
105
|
*/
|
|
105
106
|
export async function syncAssets(
|
|
106
|
-
accountId: string,
|
|
107
|
+
accountId: string | undefined,
|
|
107
108
|
scriptName: string,
|
|
108
109
|
siteAssets: AssetPaths | undefined,
|
|
109
110
|
preview: boolean,
|
|
@@ -120,6 +121,7 @@ export async function syncAssets(
|
|
|
120
121
|
logger.log("(Note: doing a dry run, not uploading or deleting anything.)");
|
|
121
122
|
return { manifest: undefined, namespace: undefined };
|
|
122
123
|
}
|
|
124
|
+
assert(accountId, "Missing accountId");
|
|
123
125
|
|
|
124
126
|
const title = `__${scriptName}-workers_sites_assets${
|
|
125
127
|
preview ? "_preview" : ""
|
|
@@ -131,7 +133,7 @@ export async function syncAssets(
|
|
|
131
133
|
);
|
|
132
134
|
|
|
133
135
|
// let's get all the keys in this namespace
|
|
134
|
-
const namespaceKeysResponse = await
|
|
136
|
+
const namespaceKeysResponse = await listKVNamespaceKeys(accountId, namespace);
|
|
135
137
|
const namespaceKeys = new Set(namespaceKeysResponse.map((x) => x.name));
|
|
136
138
|
|
|
137
139
|
const manifest: Record<string, string> = {};
|
|
@@ -175,7 +177,12 @@ export async function syncAssets(
|
|
|
175
177
|
|
|
176
178
|
// remove the key from the set so we know what we've already uploaded
|
|
177
179
|
namespaceKeys.delete(assetKey);
|
|
178
|
-
|
|
180
|
+
|
|
181
|
+
// prevent causing different manifest keys on windows
|
|
182
|
+
const maifestKey = urlSafe(
|
|
183
|
+
path.relative(siteAssets.assetDirectory, absAssetFile)
|
|
184
|
+
);
|
|
185
|
+
manifest[maifestKey] = assetKey;
|
|
179
186
|
}
|
|
180
187
|
|
|
181
188
|
// keys now contains all the files we're deleting
|
|
@@ -185,14 +192,9 @@ export async function syncAssets(
|
|
|
185
192
|
|
|
186
193
|
await Promise.all([
|
|
187
194
|
// upload all the new assets
|
|
188
|
-
|
|
195
|
+
putKVBulkKeyValue(accountId, namespace, toUpload),
|
|
189
196
|
// delete all the unused assets
|
|
190
|
-
|
|
191
|
-
accountId,
|
|
192
|
-
namespace,
|
|
193
|
-
Array.from(namespaceKeys),
|
|
194
|
-
() => {}
|
|
195
|
-
),
|
|
197
|
+
deleteKVBulkKeyValue(accountId, namespace, Array.from(namespaceKeys)),
|
|
196
198
|
]);
|
|
197
199
|
|
|
198
200
|
logger.log("↗️ Done syncing assets");
|
package/src/user.tsx
CHANGED
|
@@ -214,6 +214,7 @@ import path from "node:path";
|
|
|
214
214
|
import url from "node:url";
|
|
215
215
|
import { TextEncoder } from "node:util";
|
|
216
216
|
import TOML from "@iarna/toml";
|
|
217
|
+
import { HostURL } from "@webcontainer/env";
|
|
217
218
|
import { render, Text } from "ink";
|
|
218
219
|
import SelectInput from "ink-select-input";
|
|
219
220
|
import Table from "ink-table";
|
|
@@ -339,9 +340,18 @@ export function validateScopeKeys(
|
|
|
339
340
|
const CLIENT_ID = "54d11594-84e4-41aa-b438-e81b8fa78ee7";
|
|
340
341
|
const AUTH_URL = "https://dash.cloudflare.com/oauth2/auth";
|
|
341
342
|
const TOKEN_URL = "https://dash.cloudflare.com/oauth2/token";
|
|
342
|
-
const CALLBACK_URL = "http://localhost:8976/oauth/callback";
|
|
343
343
|
const REVOKE_URL = "https://dash.cloudflare.com/oauth2/revoke";
|
|
344
344
|
|
|
345
|
+
/**
|
|
346
|
+
* To allow OAuth callbacks in environments such as WebContainer we need to
|
|
347
|
+
* create a host URL which only resolves `localhost` to a WebContainer
|
|
348
|
+
* hostname if the process is running in a WebContainer. On local this will
|
|
349
|
+
* be a no-op and it leaves the URL unmodified.
|
|
350
|
+
*
|
|
351
|
+
* @see https://www.npmjs.com/package/@webcontainer/env
|
|
352
|
+
*/
|
|
353
|
+
const CALLBACK_URL = HostURL.parse("http://localhost:8976/oauth/callback").href;
|
|
354
|
+
|
|
345
355
|
let LocalState: State = getAuthTokens();
|
|
346
356
|
|
|
347
357
|
/**
|
package/src/worker.ts
CHANGED
|
@@ -105,6 +105,7 @@ interface CfDurableObject {
|
|
|
105
105
|
name: string;
|
|
106
106
|
class_name: string;
|
|
107
107
|
script_name?: string;
|
|
108
|
+
environment?: string;
|
|
108
109
|
}
|
|
109
110
|
|
|
110
111
|
interface CfR2Bucket {
|
|
@@ -112,6 +113,12 @@ interface CfR2Bucket {
|
|
|
112
113
|
bucket_name: string;
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
interface CfService {
|
|
117
|
+
binding: string;
|
|
118
|
+
service: string;
|
|
119
|
+
environment?: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
115
122
|
interface CfUnsafeBinding {
|
|
116
123
|
name: string;
|
|
117
124
|
type: string;
|
|
@@ -157,6 +164,7 @@ export interface CfWorkerInit {
|
|
|
157
164
|
data_blobs: CfDataBlobBindings | undefined;
|
|
158
165
|
durable_objects: { bindings: CfDurableObject[] } | undefined;
|
|
159
166
|
r2_buckets: CfR2Bucket[] | undefined;
|
|
167
|
+
services: CfService[] | undefined;
|
|
160
168
|
unsafe: CfUnsafeBinding[] | undefined;
|
|
161
169
|
};
|
|
162
170
|
migrations: CfDurableObjectMigrations | undefined;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Welcome to Cloudflare Workers! This is your first scheduled worker.
|
|
3
|
+
*
|
|
4
|
+
* - Run `wrangler dev --local` in your terminal to start a development server
|
|
5
|
+
* - Run `curl "http://localhost:8787/cdn-cgi/mf/scheduled"` to trigger the scheduled event
|
|
6
|
+
* - Go back to the console to see what your worker has logged
|
|
7
|
+
* - Add a Cron trigger to wrangler.toml (see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers)
|
|
8
|
+
* - Run `wrangler publish --name my-worker` to publish your worker
|
|
9
|
+
*
|
|
10
|
+
* Learn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
async scheduled(controller, env, ctx) {
|
|
15
|
+
console.log(`Hello World!`);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Welcome to Cloudflare Workers! This is your first scheduled worker.
|
|
3
|
+
*
|
|
4
|
+
* - Run `wrangler dev --local` in your terminal to start a development server
|
|
5
|
+
* - Run `curl "http://localhost:8787/cdn-cgi/mf/scheduled"` to trigger the scheduled event
|
|
6
|
+
* - Go back to the console to see what your worker has logged
|
|
7
|
+
* - Add a Cron trigger to wrangler.toml (see https://developers.cloudflare.com/workers/wrangler/configuration/#triggers)
|
|
8
|
+
* - Run `wrangler publish --name my-worker` to publish your worker
|
|
9
|
+
*
|
|
10
|
+
* Learn more at https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export interface Env {
|
|
14
|
+
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
|
|
15
|
+
// MY_KV_NAMESPACE: KVNamespace;
|
|
16
|
+
//
|
|
17
|
+
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
|
|
18
|
+
// MY_DURABLE_OBJECT: DurableObjectNamespace;
|
|
19
|
+
//
|
|
20
|
+
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
|
|
21
|
+
// MY_BUCKET: R2Bucket;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
async scheduled(
|
|
26
|
+
controller: ScheduledController,
|
|
27
|
+
env: Env,
|
|
28
|
+
ctx: ExecutionContext
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
console.log(`Hello World!`);
|
|
31
|
+
},
|
|
32
|
+
};
|
package/templates/new-worker.ts
CHANGED
|
@@ -8,8 +8,23 @@
|
|
|
8
8
|
* Learn more at https://developers.cloudflare.com/workers/
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
export interface Env {
|
|
12
|
+
// Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
|
|
13
|
+
// MY_KV_NAMESPACE: KVNamespace;
|
|
14
|
+
//
|
|
15
|
+
// Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
|
|
16
|
+
// MY_DURABLE_OBJECT: DurableObjectNamespace;
|
|
17
|
+
//
|
|
18
|
+
// Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
|
|
19
|
+
// MY_BUCKET: R2Bucket;
|
|
20
|
+
}
|
|
21
|
+
|
|
11
22
|
export default {
|
|
12
|
-
async fetch(
|
|
23
|
+
async fetch(
|
|
24
|
+
request: Request,
|
|
25
|
+
env: Env,
|
|
26
|
+
ctx: ExecutionContext
|
|
27
|
+
): Promise<Response> {
|
|
13
28
|
return new Response("Hello World!");
|
|
14
29
|
},
|
|
15
30
|
};
|