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.
Files changed (113) 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 +168 -74
  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 +172 -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 +137 -0
  17. package/templates/middleware/loader-sw.ts +228 -0
  18. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +33 -0
  20. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  21. package/templates/middleware/middleware-multiworker-dev.ts +68 -0
  22. package/templates/middleware/middleware-pretty-error.ts +40 -0
  23. package/templates/middleware/middleware-scheduled.ts +15 -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 +31 -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 +652 -0
  38. package/templates/startDevWorker/ProxyWorker.ts +252 -0
  39. package/templates/tsconfig-sanity.ts +11 -0
  40. package/templates/tsconfig.init.json +105 -0
  41. package/templates/tsconfig.json +8 -0
  42. package/wrangler-dist/InspectorProxyWorker.js +460 -0
  43. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  44. package/wrangler-dist/ProxyWorker.js +186 -0
  45. package/wrangler-dist/ProxyWorker.js.map +6 -0
  46. package/wrangler-dist/cli.d.ts +23507 -0
  47. package/wrangler-dist/cli.js +153110 -109544
  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__/index.test.ts +0 -287
  55. package/src/__tests__/jest.setup.ts +0 -18
  56. package/src/__tests__/kv.test.ts +0 -322
  57. package/src/__tests__/mock-cfetch.ts +0 -63
  58. package/src/__tests__/mock-dialogs.ts +0 -65
  59. package/src/__tests__/run-in-tmp.ts +0 -19
  60. package/src/__tests__/run-wrangler.ts +0 -32
  61. package/src/api/form_data.ts +0 -131
  62. package/src/api/inspect.ts +0 -430
  63. package/src/api/preview.ts +0 -128
  64. package/src/api/worker.ts +0 -155
  65. package/src/cfetch.ts +0 -72
  66. package/src/cli.ts +0 -9
  67. package/src/config.ts +0 -131
  68. package/src/dev.tsx +0 -879
  69. package/src/dialogs.tsx +0 -77
  70. package/src/index.tsx +0 -1902
  71. package/src/kv.tsx +0 -257
  72. package/src/module-collection.ts +0 -64
  73. package/src/pages.tsx +0 -851
  74. package/src/proxy.ts +0 -103
  75. package/src/publish.ts +0 -350
  76. package/src/sites.tsx +0 -115
  77. package/src/tail.tsx +0 -71
  78. package/src/user.tsx +0 -1022
  79. package/static-asset-facade.js +0 -47
  80. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  81. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  82. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  83. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  84. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  85. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  86. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  87. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  88. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  89. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  90. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  91. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  92. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  93. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  94. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  95. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  96. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  97. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  98. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  99. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  100. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  101. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  102. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  103. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  104. package/vendor/wrangler-mime/LICENSE +0 -21
  105. package/vendor/wrangler-mime/Mime.js +0 -97
  106. package/vendor/wrangler-mime/README.md +0 -187
  107. package/vendor/wrangler-mime/cli.js +0 -46
  108. package/vendor/wrangler-mime/index.js +0 -4
  109. package/vendor/wrangler-mime/lite.js +0 -4
  110. package/vendor/wrangler-mime/package.json +0 -52
  111. package/vendor/wrangler-mime/types/other.js +0 -1
  112. package/vendor/wrangler-mime/types/standard.js +0 -1
  113. package/wrangler-dist/cli.js.map +0 -7
package/src/kv.tsx DELETED
@@ -1,257 +0,0 @@
1
- import type { Config } from "./config";
2
- import cfetch from "./cfetch";
3
- import qs from "node:querystring";
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 cfetch<{ 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 cfetch<KVNamespaceInfo[]>(
58
- `/accounts/${accountId}/storage/kv/namespaces?per_page=${pageSize}&order=title&direction=asc&page=${page}`
59
- );
60
- page++;
61
- results.push(...json);
62
- if (json.length < pageSize) {
63
- break;
64
- }
65
- }
66
- return results;
67
- }
68
-
69
- export async function listNamespaceKeys(
70
- accountId: string,
71
- namespaceId: string,
72
- prefix?: string,
73
- limit?: number
74
- ) {
75
- // TODO: this doesn't appear to do pagination
76
- return await cfetch<
77
- { name: string; expiration: number; metadata: { [key: string]: unknown } }[]
78
- >(
79
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/keys?${qs.stringify(
80
- { prefix, limit }
81
- )}`
82
- );
83
- }
84
-
85
- export async function putKeyValue(
86
- accountId: string,
87
- namespaceId: string,
88
- key: string,
89
- value: string,
90
- args?: { expiration?: number; expiration_ttl?: number }
91
- ) {
92
- return await cfetch(
93
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}?${
94
- args
95
- ? qs.stringify({
96
- expiration: args.expiration,
97
- expiration_ttl: args.expiration_ttl,
98
- })
99
- : ""
100
- }`,
101
- { method: "PUT", body: value }
102
- );
103
- }
104
-
105
- export async function putBulkKeyValue(
106
- accountId: string,
107
- namespaceId: string,
108
- keyvalueStr: string
109
- ) {
110
- return await cfetch(
111
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
112
- {
113
- method: "PUT",
114
- body: keyvalueStr,
115
- headers: { "Content-Type": "application/json" },
116
- }
117
- );
118
- }
119
-
120
- export async function deleteBulkKeyValue(
121
- accountId: string,
122
- namespaceId: string,
123
- keyStr: string
124
- ) {
125
- return await cfetch(
126
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
127
- {
128
- method: "DELETE",
129
- body: keyStr,
130
- headers: { "Content-Type": "application/json" },
131
- }
132
- );
133
- }
134
-
135
- export function getNamespaceId({
136
- preview,
137
- binding,
138
- config,
139
- "namespace-id": namespaceId,
140
- env,
141
- }: KvArgs): string {
142
- // nice
143
- if (namespaceId) {
144
- return namespaceId;
145
- }
146
-
147
- // begin pre-flight checks
148
-
149
- // `--binding` is only valid if there's a wrangler configuration file.
150
- if (binding && !config) {
151
- throw new Error("--binding specified, but no config file was found.");
152
- }
153
-
154
- // there's no config. abort here
155
- if (!config) {
156
- throw new Error(
157
- "Failed to find a config file.\n" +
158
- "Either use --namespace-id to upload directly or create a configuration file with a binding."
159
- );
160
- }
161
-
162
- // they want to use an environment, actually
163
- if (env) {
164
- if (!config.env || !config.env[env]) {
165
- throw new Error(
166
- `Failed to find environment "${env}" in configuration file!`
167
- );
168
- }
169
-
170
- // TODO: either a bespoke arg type for this function to avoid `undefined`s or an `EnvOrConfig` type
171
- return getNamespaceId({
172
- binding,
173
- "namespace-id": namespaceId,
174
- env: undefined,
175
- preview,
176
- config: {
177
- env: undefined,
178
- build: undefined,
179
- name: undefined,
180
- account_id: undefined,
181
- ...config.env[env],
182
- },
183
- });
184
- }
185
-
186
- // there's no KV namespaces
187
- if (!config.kv_namespaces || config.kv_namespaces.length === 0) {
188
- throw new Error(
189
- "No KV Namespace to upload to! Either use --namespace-id to upload directly or add a KV namespace to your wrangler config file."
190
- );
191
- }
192
-
193
- const namespace = config.kv_namespaces.find((ns) => ns.binding === binding);
194
-
195
- // we couldn't find a namespace with that binding
196
- if (!namespace) {
197
- throw new Error(`No KV Namespaces found with binding ${binding}!`);
198
- }
199
-
200
- // end pre-flight checks
201
-
202
- // we're in preview mode, `--preview true` or `--preview` was passed
203
- if (preview && namespace.preview_id) {
204
- namespaceId = namespace.preview_id;
205
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we will get errors!
206
- return namespaceId;
207
- } else if (preview) {
208
- throw new Error(
209
- `No preview ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
210
- );
211
- }
212
-
213
- // either `--preview false`, or preview wasn't passed
214
- // TODO: should we care? or should we just treat false and undefined the same
215
- const previewIsDefined = typeof preview !== "undefined";
216
-
217
- // --preview false was passed
218
- if (previewIsDefined && namespace.id) {
219
- namespaceId = namespace.id;
220
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we can get error!
221
- return namespaceId;
222
- } else if (previewIsDefined) {
223
- throw new Error(
224
- `No namespace ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
225
- );
226
- }
227
-
228
- // `--preview` wasn't passed
229
- const bindingHasOnlyOneId =
230
- (namespace.id && !namespace.preview_id) ||
231
- (!namespace.id && namespace.preview_id);
232
- if (bindingHasOnlyOneId) {
233
- namespaceId = namespace.id || namespace.preview_id;
234
- } else {
235
- throw new Error(
236
- `${binding} has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.`
237
- );
238
- }
239
-
240
- // shouldn't happen. we should be able to prove this with strong typing.
241
- // TODO: when we add strongly typed commands, rewrite these checks so they're exhaustive
242
- if (!namespaceId) {
243
- throw Error(
244
- "Something went wrong trying to determine which namespace to upload to.\n" +
245
- "Please create a github issue with the command you just ran along with your wrangler configuration."
246
- );
247
- }
248
-
249
- return namespaceId;
250
- }
251
-
252
- /**
253
- * KV namespace binding names must be valid JS identifiers.
254
- */
255
- export function isValidNamespaceBinding(binding: string): boolean {
256
- return /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding);
257
- }
@@ -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
- }