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/kv.tsx
DELETED
@@ -1,267 +0,0 @@
|
|
1
|
-
import { URLSearchParams } from "node:url";
|
2
|
-
import type { Config } from "./config";
|
3
|
-
import { fetchListResult, fetchResult } from "./cfetch";
|
4
|
-
|
5
|
-
type KvArgs = {
|
6
|
-
binding?: string;
|
7
|
-
"namespace-id"?: string;
|
8
|
-
env?: string;
|
9
|
-
preview?: boolean;
|
10
|
-
config?: Config;
|
11
|
-
};
|
12
|
-
|
13
|
-
/**
|
14
|
-
* Create a new namespace under the given `accountId` with the given `title`.
|
15
|
-
*
|
16
|
-
* @returns the generated id of the created namespace.
|
17
|
-
*/
|
18
|
-
export async function createNamespace(
|
19
|
-
accountId: string,
|
20
|
-
title: string
|
21
|
-
): Promise<string> {
|
22
|
-
const response = await fetchResult<{ id: string }>(
|
23
|
-
`/accounts/${accountId}/storage/kv/namespaces`,
|
24
|
-
{
|
25
|
-
method: "POST",
|
26
|
-
headers: {
|
27
|
-
"Content-Type": "application/json",
|
28
|
-
},
|
29
|
-
body: JSON.stringify({
|
30
|
-
title,
|
31
|
-
}),
|
32
|
-
}
|
33
|
-
);
|
34
|
-
|
35
|
-
return response.id;
|
36
|
-
}
|
37
|
-
|
38
|
-
/**
|
39
|
-
* The information about a namespace that is returned from `listNamespaces()`.
|
40
|
-
*/
|
41
|
-
export interface KVNamespaceInfo {
|
42
|
-
id: string;
|
43
|
-
title: string;
|
44
|
-
supports_url_encoding?: boolean;
|
45
|
-
}
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Fetch a list of all the namespaces under the given `accountId`.
|
49
|
-
*/
|
50
|
-
export async function listNamespaces(
|
51
|
-
accountId: string
|
52
|
-
): Promise<KVNamespaceInfo[]> {
|
53
|
-
const pageSize = 100;
|
54
|
-
let page = 1;
|
55
|
-
const results: KVNamespaceInfo[] = [];
|
56
|
-
while (results.length % pageSize === 0) {
|
57
|
-
const json = await fetchResult<KVNamespaceInfo[]>(
|
58
|
-
`/accounts/${accountId}/storage/kv/namespaces`,
|
59
|
-
{},
|
60
|
-
new URLSearchParams({
|
61
|
-
per_page: pageSize.toString(),
|
62
|
-
order: "title",
|
63
|
-
direction: "asc",
|
64
|
-
page: page.toString(),
|
65
|
-
})
|
66
|
-
);
|
67
|
-
page++;
|
68
|
-
results.push(...json);
|
69
|
-
if (json.length < pageSize) {
|
70
|
-
break;
|
71
|
-
}
|
72
|
-
}
|
73
|
-
return results;
|
74
|
-
}
|
75
|
-
|
76
|
-
export interface NamespaceKeyInfo {
|
77
|
-
name: string;
|
78
|
-
expiration?: number;
|
79
|
-
metadata?: { [key: string]: unknown };
|
80
|
-
}
|
81
|
-
|
82
|
-
export async function listNamespaceKeys(
|
83
|
-
accountId: string,
|
84
|
-
namespaceId: string,
|
85
|
-
prefix?: string
|
86
|
-
) {
|
87
|
-
return await fetchListResult<NamespaceKeyInfo>(
|
88
|
-
`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/keys`,
|
89
|
-
{},
|
90
|
-
new URLSearchParams({ prefix })
|
91
|
-
);
|
92
|
-
}
|
93
|
-
|
94
|
-
export async function putKeyValue(
|
95
|
-
accountId: string,
|
96
|
-
namespaceId: string,
|
97
|
-
key: string,
|
98
|
-
value: string,
|
99
|
-
args?: { expiration?: number; expiration_ttl?: number }
|
100
|
-
) {
|
101
|
-
return await fetchResult(
|
102
|
-
`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`,
|
103
|
-
{ method: "PUT", body: value },
|
104
|
-
args
|
105
|
-
? new URLSearchParams({
|
106
|
-
expiration: args.expiration?.toString(),
|
107
|
-
expiration_ttl: args.expiration_ttl?.toString(),
|
108
|
-
})
|
109
|
-
: undefined
|
110
|
-
);
|
111
|
-
}
|
112
|
-
|
113
|
-
export async function putBulkKeyValue(
|
114
|
-
accountId: string,
|
115
|
-
namespaceId: string,
|
116
|
-
keyvalueStr: string
|
117
|
-
) {
|
118
|
-
return await fetchResult(
|
119
|
-
`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
|
120
|
-
{
|
121
|
-
method: "PUT",
|
122
|
-
body: keyvalueStr,
|
123
|
-
headers: { "Content-Type": "application/json" },
|
124
|
-
}
|
125
|
-
);
|
126
|
-
}
|
127
|
-
|
128
|
-
export async function deleteBulkKeyValue(
|
129
|
-
accountId: string,
|
130
|
-
namespaceId: string,
|
131
|
-
keyStr: string
|
132
|
-
) {
|
133
|
-
return await fetchResult(
|
134
|
-
`/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
|
135
|
-
{
|
136
|
-
method: "DELETE",
|
137
|
-
body: keyStr,
|
138
|
-
headers: { "Content-Type": "application/json" },
|
139
|
-
}
|
140
|
-
);
|
141
|
-
}
|
142
|
-
|
143
|
-
export function getNamespaceId({
|
144
|
-
preview,
|
145
|
-
binding,
|
146
|
-
config,
|
147
|
-
"namespace-id": namespaceId,
|
148
|
-
env,
|
149
|
-
}: KvArgs): string {
|
150
|
-
// nice
|
151
|
-
if (namespaceId) {
|
152
|
-
return namespaceId;
|
153
|
-
}
|
154
|
-
|
155
|
-
// begin pre-flight checks
|
156
|
-
|
157
|
-
// `--binding` is only valid if there's a wrangler configuration file.
|
158
|
-
if (binding && !config) {
|
159
|
-
throw new Error("--binding specified, but no config file was found.");
|
160
|
-
}
|
161
|
-
|
162
|
-
// there's no config. abort here
|
163
|
-
if (!config) {
|
164
|
-
throw new Error(
|
165
|
-
"Failed to find a config file.\n" +
|
166
|
-
"Either use --namespace-id to upload directly or create a configuration file with a binding."
|
167
|
-
);
|
168
|
-
}
|
169
|
-
|
170
|
-
// they want to use an environment, actually
|
171
|
-
if (env) {
|
172
|
-
if (!config.env || !config.env[env]) {
|
173
|
-
throw new Error(
|
174
|
-
`Failed to find environment "${env}" in configuration file!`
|
175
|
-
);
|
176
|
-
}
|
177
|
-
|
178
|
-
// TODO: either a bespoke arg type for this function to avoid `undefined`s or an `EnvOrConfig` type
|
179
|
-
return getNamespaceId({
|
180
|
-
binding,
|
181
|
-
"namespace-id": namespaceId,
|
182
|
-
env: undefined,
|
183
|
-
preview,
|
184
|
-
config: {
|
185
|
-
env: undefined,
|
186
|
-
build: undefined,
|
187
|
-
name: undefined,
|
188
|
-
account_id: undefined,
|
189
|
-
...config.env[env],
|
190
|
-
},
|
191
|
-
});
|
192
|
-
}
|
193
|
-
|
194
|
-
// there's no KV namespaces
|
195
|
-
if (!config.kv_namespaces || config.kv_namespaces.length === 0) {
|
196
|
-
throw new Error(
|
197
|
-
"No KV Namespaces configured! Either use --namespace-id to upload directly or add a KV namespace to your wrangler config file."
|
198
|
-
);
|
199
|
-
}
|
200
|
-
|
201
|
-
const namespace = config.kv_namespaces.find((ns) => ns.binding === binding);
|
202
|
-
|
203
|
-
// we couldn't find a namespace with that binding
|
204
|
-
if (!namespace) {
|
205
|
-
throw new Error(
|
206
|
-
`A namespace with binding name "${binding}" was not found in the configured "kv_namespaces".`
|
207
|
-
);
|
208
|
-
}
|
209
|
-
|
210
|
-
// end pre-flight checks
|
211
|
-
|
212
|
-
// we're in preview mode, `--preview true` or `--preview` was passed
|
213
|
-
if (preview && namespace.preview_id) {
|
214
|
-
namespaceId = namespace.preview_id;
|
215
|
-
// We don't want to execute code below if preview is set to true, so we just return. Otherwise we will get errors!
|
216
|
-
return namespaceId;
|
217
|
-
} else if (preview) {
|
218
|
-
throw new Error(
|
219
|
-
`No preview ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
|
220
|
-
);
|
221
|
-
}
|
222
|
-
|
223
|
-
// either `--preview false`, or preview wasn't passed
|
224
|
-
// TODO: should we care? or should we just treat false and undefined the same
|
225
|
-
const previewIsDefined = typeof preview !== "undefined";
|
226
|
-
|
227
|
-
// --preview false was passed
|
228
|
-
if (previewIsDefined && namespace.id) {
|
229
|
-
namespaceId = namespace.id;
|
230
|
-
// We don't want to execute code below if preview is set to true, so we just return. Otherwise we can get error!
|
231
|
-
return namespaceId;
|
232
|
-
} else if (previewIsDefined) {
|
233
|
-
throw new Error(
|
234
|
-
`No namespace ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
|
235
|
-
);
|
236
|
-
}
|
237
|
-
|
238
|
-
// `--preview` wasn't passed
|
239
|
-
const bindingHasOnlyOneId =
|
240
|
-
(namespace.id && !namespace.preview_id) ||
|
241
|
-
(!namespace.id && namespace.preview_id);
|
242
|
-
if (bindingHasOnlyOneId) {
|
243
|
-
namespaceId = namespace.id || namespace.preview_id;
|
244
|
-
} else {
|
245
|
-
throw new Error(
|
246
|
-
`${binding} has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.`
|
247
|
-
);
|
248
|
-
}
|
249
|
-
|
250
|
-
// shouldn't happen. we should be able to prove this with strong typing.
|
251
|
-
// TODO: when we add strongly typed commands, rewrite these checks so they're exhaustive
|
252
|
-
if (!namespaceId) {
|
253
|
-
throw Error(
|
254
|
-
"Something went wrong trying to determine which namespace to upload to.\n" +
|
255
|
-
"Please create a github issue with the command you just ran along with your wrangler configuration."
|
256
|
-
);
|
257
|
-
}
|
258
|
-
|
259
|
-
return namespaceId;
|
260
|
-
}
|
261
|
-
|
262
|
-
/**
|
263
|
-
* KV namespace binding names must be valid JS identifiers.
|
264
|
-
*/
|
265
|
-
export function isValidNamespaceBinding(binding: string): boolean {
|
266
|
-
return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding);
|
267
|
-
}
|
package/src/module-collection.ts
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
import type { CfModule } from "./api/worker";
|
2
|
-
import type esbuild from "esbuild";
|
3
|
-
import path from "node:path";
|
4
|
-
import { readFile } from "node:fs/promises";
|
5
|
-
import crypto from "node:crypto";
|
6
|
-
|
7
|
-
// This is a combination of an esbuild plugin and a mutable array
|
8
|
-
// that we use to collect module references from source code.
|
9
|
-
// There will be modules that _shouldn't_ be inlined directly into
|
10
|
-
// the bundle. (eg. wasm modules, some text files, etc). We can include
|
11
|
-
// those files as modules in the multi part forker form upload. This
|
12
|
-
// plugin+array is used to collect references to these modules, reference
|
13
|
-
// them correctly in the bundle, and add them to the form upload.
|
14
|
-
|
15
|
-
export default function makeModuleCollector(): {
|
16
|
-
modules: CfModule[];
|
17
|
-
plugin: esbuild.Plugin;
|
18
|
-
} {
|
19
|
-
const modules: CfModule[] = [];
|
20
|
-
return {
|
21
|
-
modules,
|
22
|
-
plugin: {
|
23
|
-
name: "wrangler-module-collector",
|
24
|
-
setup(build) {
|
25
|
-
build.onStart(() => {
|
26
|
-
// reset the moduels collection
|
27
|
-
modules.splice(0);
|
28
|
-
});
|
29
|
-
|
30
|
-
build.onResolve(
|
31
|
-
// filter on "known" file types,
|
32
|
-
// we can expand this list later
|
33
|
-
{ filter: /.*\.(pem|txt|html|wasm)$/ },
|
34
|
-
async (args: esbuild.OnResolveArgs) => {
|
35
|
-
// take the file and massage it to a
|
36
|
-
// transportable/manageable format
|
37
|
-
const fileExt = path.extname(args.path);
|
38
|
-
const filePath = path.join(args.resolveDir, args.path);
|
39
|
-
const fileContent = await readFile(filePath);
|
40
|
-
const fileHash = crypto
|
41
|
-
.createHash("sha1")
|
42
|
-
.update(fileContent)
|
43
|
-
.digest("hex");
|
44
|
-
const fileName = `${fileHash}-${path.basename(args.path)}`;
|
45
|
-
|
46
|
-
// add the module to the array
|
47
|
-
modules.push({
|
48
|
-
name: fileName,
|
49
|
-
content: fileContent,
|
50
|
-
type: fileExt === ".wasm" ? "compiled-wasm" : "text",
|
51
|
-
});
|
52
|
-
|
53
|
-
return {
|
54
|
-
path: fileName, // change the reference to the changed module
|
55
|
-
external: true, // mark it as external in the bundle
|
56
|
-
namespace: "wrangler-module-collector-ns", // just a tag, this isn't strictly necessary
|
57
|
-
watchFiles: [filePath], // we also add the file to esbuild's watch list
|
58
|
-
};
|
59
|
-
}
|
60
|
-
);
|
61
|
-
},
|
62
|
-
},
|
63
|
-
};
|
64
|
-
}
|