wrangler 0.0.0-e0d2f35 → 0.0.0-e11e1691

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 (130) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +47 -16
  3. package/bin/wrangler.js +122 -31
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +176 -80
  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 +17 -0
  11. package/templates/gitignore +167 -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 +136 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  19. package/templates/middleware/middleware-ensure-req-body-drained.ts +19 -0
  20. package/templates/middleware/middleware-miniflare3-json-error.ts +33 -0
  21. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  22. package/templates/middleware/middleware-multiworker-dev.ts +68 -0
  23. package/templates/middleware/middleware-pretty-error.ts +40 -0
  24. package/templates/middleware/middleware-scheduled.ts +15 -0
  25. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  26. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  27. package/templates/modules-watch-stub.js +4 -0
  28. package/templates/new-worker-scheduled.js +17 -0
  29. package/templates/new-worker-scheduled.ts +32 -0
  30. package/templates/new-worker.js +15 -0
  31. package/templates/new-worker.ts +33 -0
  32. package/templates/no-op-worker.js +10 -0
  33. package/templates/pages-dev-pipeline.ts +32 -0
  34. package/templates/pages-dev-util.ts +55 -0
  35. package/templates/pages-shim.ts +9 -0
  36. package/templates/pages-template-plugin.ts +190 -0
  37. package/templates/pages-template-worker.ts +198 -0
  38. package/templates/startDevWorker/InspectorProxyWorker.ts +661 -0
  39. package/templates/startDevWorker/ProxyWorker.ts +326 -0
  40. package/templates/tsconfig-sanity.ts +11 -0
  41. package/templates/tsconfig.init.json +105 -0
  42. package/templates/tsconfig.json +8 -0
  43. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  44. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  45. package/wrangler-dist/ProxyWorker.js +237 -0
  46. package/wrangler-dist/ProxyWorker.js.map +6 -0
  47. package/wrangler-dist/cli.d.ts +23937 -0
  48. package/wrangler-dist/cli.js +164283 -116933
  49. package/wrangler-dist/wasm-sync.wasm +0 -0
  50. package/import_meta_url.js +0 -3
  51. package/miniflare-config-stubs/.env.empty +0 -0
  52. package/miniflare-config-stubs/package.empty.json +0 -1
  53. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  54. package/pages/functions/buildWorker.ts +0 -62
  55. package/pages/functions/filepath-routing.test.ts +0 -39
  56. package/pages/functions/filepath-routing.ts +0 -228
  57. package/pages/functions/identifiers.ts +0 -78
  58. package/pages/functions/routes.ts +0 -158
  59. package/pages/functions/template-worker.ts +0 -136
  60. package/src/__tests__/clipboardy-mock.js +0 -4
  61. package/src/__tests__/dev.test.tsx +0 -71
  62. package/src/__tests__/index.test.ts +0 -424
  63. package/src/__tests__/jest.setup.ts +0 -29
  64. package/src/__tests__/kv.test.ts +0 -1224
  65. package/src/__tests__/logout.test.ts +0 -64
  66. package/src/__tests__/mock-cfetch.ts +0 -173
  67. package/src/__tests__/mock-console.ts +0 -34
  68. package/src/__tests__/mock-dialogs.ts +0 -65
  69. package/src/__tests__/mock-kv.ts +0 -40
  70. package/src/__tests__/mock-user.ts +0 -27
  71. package/src/__tests__/publish.test.ts +0 -1206
  72. package/src/__tests__/run-in-tmp.ts +0 -29
  73. package/src/__tests__/run-wrangler.ts +0 -8
  74. package/src/__tests__/secret.test.ts +0 -206
  75. package/src/__tests__/whoami.test.tsx +0 -101
  76. package/src/api/form_data.ts +0 -135
  77. package/src/api/preview.ts +0 -128
  78. package/src/api/worker.ts +0 -155
  79. package/src/cfetch/index.ts +0 -111
  80. package/src/cfetch/internal.ts +0 -71
  81. package/src/cli.ts +0 -9
  82. package/src/config.ts +0 -641
  83. package/src/dev.tsx +0 -830
  84. package/src/dialogs.tsx +0 -77
  85. package/src/index.tsx +0 -2078
  86. package/src/inspect.ts +0 -595
  87. package/src/kv.tsx +0 -276
  88. package/src/module-collection.ts +0 -63
  89. package/src/pages.tsx +0 -1043
  90. package/src/proxy.ts +0 -370
  91. package/src/publish.ts +0 -410
  92. package/src/sites.tsx +0 -240
  93. package/src/tail.tsx +0 -73
  94. package/src/user.tsx +0 -1019
  95. package/src/whoami.tsx +0 -69
  96. package/static-asset-facade.js +0 -47
  97. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  98. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  99. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  100. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  101. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  102. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  103. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  104. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  105. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  106. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  107. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  108. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  109. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  110. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  111. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  112. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  113. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  114. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  115. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  116. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  117. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  118. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  119. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  120. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  121. package/vendor/wrangler-mime/LICENSE +0 -21
  122. package/vendor/wrangler-mime/Mime.js +0 -97
  123. package/vendor/wrangler-mime/README.md +0 -187
  124. package/vendor/wrangler-mime/cli.js +0 -46
  125. package/vendor/wrangler-mime/index.js +0 -4
  126. package/vendor/wrangler-mime/lite.js +0 -4
  127. package/vendor/wrangler-mime/package.json +0 -52
  128. package/vendor/wrangler-mime/types/other.js +0 -1
  129. package/vendor/wrangler-mime/types/standard.js +0 -1
  130. package/wrangler-dist/cli.js.map +0 -7
package/src/kv.tsx DELETED
@@ -1,276 +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 = ""
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
- let searchParams: URLSearchParams | undefined;
102
- if (args) {
103
- searchParams = new URLSearchParams();
104
- if (args.expiration) {
105
- searchParams.set("expiration", `${args.expiration}`);
106
- }
107
- if (args.expiration_ttl) {
108
- searchParams.set("expiration_ttl", `${args.expiration_ttl}`);
109
- }
110
- }
111
- return await fetchResult(
112
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`,
113
- { method: "PUT", body: value },
114
- searchParams
115
- );
116
- }
117
-
118
- export async function putBulkKeyValue(
119
- accountId: string,
120
- namespaceId: string,
121
- keyvalueStr: string
122
- ) {
123
- return await fetchResult(
124
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
125
- {
126
- method: "PUT",
127
- body: keyvalueStr,
128
- headers: { "Content-Type": "application/json" },
129
- }
130
- );
131
- }
132
-
133
- export async function deleteBulkKeyValue(
134
- accountId: string,
135
- namespaceId: string,
136
- keyStr: string
137
- ) {
138
- return await fetchResult(
139
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
140
- {
141
- method: "DELETE",
142
- body: keyStr,
143
- headers: { "Content-Type": "application/json" },
144
- }
145
- );
146
- }
147
-
148
- export function getNamespaceId({
149
- preview,
150
- binding,
151
- config,
152
- "namespace-id": namespaceId,
153
- env,
154
- }: KvArgs): string {
155
- // nice
156
- if (namespaceId) {
157
- return namespaceId;
158
- }
159
-
160
- // begin pre-flight checks
161
-
162
- // `--binding` is only valid if there's a wrangler configuration file.
163
- if (binding && !config) {
164
- throw new Error("--binding specified, but no config file was found.");
165
- }
166
-
167
- // there's no config. abort here
168
- if (!config) {
169
- throw new Error(
170
- "Failed to find a config file.\n" +
171
- "Either use --namespace-id to upload directly or create a configuration file with a binding."
172
- );
173
- }
174
-
175
- // they want to use an environment, actually
176
- if (env) {
177
- if (!config.env || !config.env[env]) {
178
- throw new Error(
179
- `Failed to find environment "${env}" in configuration file!`
180
- );
181
- }
182
-
183
- // TODO: either a bespoke arg type for this function to avoid `undefined`s or an `EnvOrConfig` type
184
- return getNamespaceId({
185
- binding,
186
- "namespace-id": namespaceId,
187
- env: undefined,
188
- preview,
189
- config: {
190
- env: undefined,
191
- build: undefined,
192
- name: undefined,
193
- account_id: undefined,
194
- ...config.env[env],
195
- },
196
- });
197
- }
198
-
199
- // there's no KV namespaces
200
- if (!config.kv_namespaces || config.kv_namespaces.length === 0) {
201
- throw new Error(
202
- "No KV Namespaces configured! Either use --namespace-id to upload directly or add a KV namespace to your wrangler config file."
203
- );
204
- }
205
-
206
- const namespace = config.kv_namespaces.find((ns) => ns.binding === binding);
207
-
208
- // we couldn't find a namespace with that binding
209
- if (!namespace) {
210
- throw new Error(
211
- `A namespace with binding name "${binding}" was not found in the configured "kv_namespaces".`
212
- );
213
- }
214
-
215
- // end pre-flight checks
216
-
217
- // we're in preview mode, `--preview true` or `--preview` was passed
218
- if (preview && namespace.preview_id) {
219
- namespaceId = namespace.preview_id;
220
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we will get errors!
221
- return namespaceId;
222
- } else if (preview) {
223
- throw new Error(
224
- `No preview ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
225
- );
226
- }
227
-
228
- // either `--preview false`, or preview wasn't passed
229
- // TODO: should we care? or should we just treat false and undefined the same
230
- const previewIsDefined = typeof preview !== "undefined";
231
-
232
- // --preview false was passed
233
- if (previewIsDefined && namespace.id) {
234
- namespaceId = namespace.id;
235
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we can get error!
236
- return namespaceId;
237
- } else if (previewIsDefined) {
238
- throw new Error(
239
- `No namespace ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
240
- );
241
- }
242
-
243
- // `--preview` wasn't passed
244
- const bindingHasOnlyOneId =
245
- (namespace.id && !namespace.preview_id) ||
246
- (!namespace.id && namespace.preview_id);
247
- if (bindingHasOnlyOneId) {
248
- namespaceId = namespace.id || namespace.preview_id;
249
- } else {
250
- throw new Error(
251
- `${binding} has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.`
252
- );
253
- }
254
-
255
- // shouldn't happen. we should be able to prove this with strong typing.
256
- // TODO: when we add strongly typed commands, rewrite these checks so they're exhaustive
257
- if (!namespaceId) {
258
- throw Error(
259
- "Something went wrong trying to determine which namespace to upload to.\n" +
260
- "Please create a github issue with the command you just ran along with your wrangler configuration."
261
- );
262
- }
263
-
264
- return namespaceId;
265
- }
266
-
267
- /**
268
- * KV namespace binding names must be valid JS identifiers.
269
- */
270
- export function isValidNamespaceBinding(
271
- binding: string | undefined
272
- ): binding is string {
273
- return (
274
- typeof binding === "string" && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding)
275
- );
276
- }
@@ -1,63 +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: /.*\.(wasm)$/ },
34
- async (args: esbuild.OnResolveArgs) => {
35
- // take the file and massage it to a
36
- // transportable/manageable format
37
- const filePath = path.join(args.resolveDir, args.path);
38
- const fileContent = await readFile(filePath);
39
- const fileHash = crypto
40
- .createHash("sha1")
41
- .update(fileContent)
42
- .digest("hex");
43
- const fileName = `${fileHash}-${path.basename(args.path)}`;
44
-
45
- // add the module to the array
46
- modules.push({
47
- name: fileName,
48
- content: fileContent,
49
- type: "compiled-wasm",
50
- });
51
-
52
- return {
53
- path: fileName, // change the reference to the changed module
54
- external: true, // mark it as external in the bundle
55
- namespace: "wrangler-module-collector-ns", // just a tag, this isn't strictly necessary
56
- watchFiles: [filePath], // we also add the file to esbuild's watch list
57
- };
58
- }
59
- );
60
- },
61
- },
62
- };
63
- }