wrangler 0.0.0-e09abbc → 0.0.0-e0abf917

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 (186) hide show
  1. package/README.md +24 -12
  2. package/bin/wrangler.js +26 -67
  3. package/config-schema.json +2900 -0
  4. package/package.json +224 -167
  5. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  6. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  7. package/templates/__tests__/tsconfig.json +8 -0
  8. package/templates/checked-fetch.js +19 -6
  9. package/templates/facade.d.ts +19 -0
  10. package/templates/gitignore +0 -4
  11. package/templates/init-tests/test-jest-new-worker.js +23 -0
  12. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  13. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  14. package/templates/middleware/common.ts +67 -0
  15. package/templates/middleware/loader-modules.ts +133 -0
  16. package/templates/middleware/loader-sw.ts +229 -0
  17. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  18. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  19. package/templates/middleware/middleware-pretty-error.ts +40 -0
  20. package/templates/middleware/middleware-scheduled.ts +15 -0
  21. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  22. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  23. package/templates/modules-watch-stub.js +4 -0
  24. package/templates/new-worker-scheduled.ts +1 -1
  25. package/templates/new-worker.js +1 -1
  26. package/templates/new-worker.ts +4 -1
  27. package/templates/pages-dev-pipeline.ts +32 -0
  28. package/templates/pages-dev-util.ts +55 -0
  29. package/templates/pages-shim.ts +1 -1
  30. package/templates/pages-template-plugin.ts +51 -16
  31. package/templates/pages-template-worker.ts +48 -11
  32. package/templates/startDevWorker/InspectorProxyWorker.ts +661 -0
  33. package/templates/startDevWorker/ProxyWorker.ts +331 -0
  34. package/templates/tsconfig-sanity.ts +11 -0
  35. package/templates/tsconfig.init.json +105 -0
  36. package/templates/tsconfig.json +5 -102
  37. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  38. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  39. package/wrangler-dist/ProxyWorker.js +240 -0
  40. package/wrangler-dist/ProxyWorker.js.map +6 -0
  41. package/wrangler-dist/cli.d.ts +23804 -148
  42. package/wrangler-dist/cli.js +167847 -117611
  43. package/wrangler-dist/wasm-sync.wasm +0 -0
  44. package/import_meta_url.js +0 -3
  45. package/miniflare-config-stubs/.env.empty +0 -0
  46. package/miniflare-config-stubs/package.empty.json +0 -1
  47. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  48. package/miniflare-dist/index.mjs +0 -5354
  49. package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
  50. package/src/__tests__/config-cache.test.ts +0 -42
  51. package/src/__tests__/configuration.test.ts +0 -3950
  52. package/src/__tests__/dev.test.tsx +0 -1203
  53. package/src/__tests__/guess-worker-format.test.ts +0 -85
  54. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  55. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  56. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  57. package/src/__tests__/helpers/mock-bin.ts +0 -36
  58. package/src/__tests__/helpers/mock-cfetch.ts +0 -211
  59. package/src/__tests__/helpers/mock-console.ts +0 -97
  60. package/src/__tests__/helpers/mock-dialogs.ts +0 -153
  61. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  62. package/src/__tests__/helpers/mock-istty.ts +0 -74
  63. package/src/__tests__/helpers/mock-kv.ts +0 -33
  64. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -250
  65. package/src/__tests__/helpers/mock-process.ts +0 -39
  66. package/src/__tests__/helpers/mock-stdin.ts +0 -108
  67. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  68. package/src/__tests__/helpers/run-in-tmp.ts +0 -38
  69. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  70. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  71. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  72. package/src/__tests__/https-options.test.ts +0 -163
  73. package/src/__tests__/index.test.ts +0 -262
  74. package/src/__tests__/init.test.ts +0 -1992
  75. package/src/__tests__/jest.setup.ts +0 -120
  76. package/src/__tests__/kv.test.ts +0 -1671
  77. package/src/__tests__/logger.test.ts +0 -141
  78. package/src/__tests__/metrics.test.ts +0 -445
  79. package/src/__tests__/package-manager.test.ts +0 -353
  80. package/src/__tests__/pages.test.ts +0 -1261
  81. package/src/__tests__/parse.test.ts +0 -330
  82. package/src/__tests__/publish.test.ts +0 -6671
  83. package/src/__tests__/pubsub.test.ts +0 -367
  84. package/src/__tests__/r2.test.ts +0 -233
  85. package/src/__tests__/route.test.ts +0 -45
  86. package/src/__tests__/secret.test.ts +0 -492
  87. package/src/__tests__/tail.test.ts +0 -698
  88. package/src/__tests__/test-old-node-version.js +0 -31
  89. package/src/__tests__/user.test.ts +0 -143
  90. package/src/__tests__/whoami.test.tsx +0 -230
  91. package/src/__tests__/worker-namespace.test.ts +0 -327
  92. package/src/abort.d.ts +0 -3
  93. package/src/api/dev.ts +0 -86
  94. package/src/api/index.ts +0 -1
  95. package/src/bundle-reporter.tsx +0 -29
  96. package/src/bundle.ts +0 -236
  97. package/src/cfetch/index.ts +0 -121
  98. package/src/cfetch/internal.ts +0 -149
  99. package/src/cli.ts +0 -27
  100. package/src/config/README.md +0 -107
  101. package/src/config/config.ts +0 -251
  102. package/src/config/diagnostics.ts +0 -80
  103. package/src/config/environment.ts +0 -453
  104. package/src/config/index.ts +0 -238
  105. package/src/config/validation-helpers.ts +0 -584
  106. package/src/config/validation.ts +0 -1754
  107. package/src/config-cache.ts +0 -84
  108. package/src/create-worker-preview.ts +0 -255
  109. package/src/create-worker-upload-form.ts +0 -263
  110. package/src/dev/dev-vars.ts +0 -36
  111. package/src/dev/dev.tsx +0 -452
  112. package/src/dev/local.tsx +0 -373
  113. package/src/dev/remote.tsx +0 -386
  114. package/src/dev/use-esbuild.ts +0 -150
  115. package/src/dev.tsx +0 -593
  116. package/src/dialogs.tsx +0 -135
  117. package/src/durable.ts +0 -102
  118. package/src/entry.ts +0 -328
  119. package/src/environment-variables.ts +0 -35
  120. package/src/errors.ts +0 -11
  121. package/src/faye-websocket.d.ts +0 -6
  122. package/src/generate.ts +0 -33
  123. package/src/git-client.ts +0 -42
  124. package/src/global-wrangler-config-path.ts +0 -26
  125. package/src/https-options.ts +0 -127
  126. package/src/index.tsx +0 -1971
  127. package/src/init.ts +0 -549
  128. package/src/inspect.ts +0 -662
  129. package/src/intl-polyfill.d.ts +0 -139
  130. package/src/is-interactive.ts +0 -12
  131. package/src/kv.ts +0 -430
  132. package/src/logger.ts +0 -73
  133. package/src/metrics/index.ts +0 -4
  134. package/src/metrics/is-ci.ts +0 -14
  135. package/src/metrics/metrics-config.ts +0 -239
  136. package/src/metrics/metrics-dispatcher.ts +0 -95
  137. package/src/metrics/send-event.ts +0 -92
  138. package/src/miniflare-cli/README.md +0 -30
  139. package/src/miniflare-cli/assets.ts +0 -543
  140. package/src/miniflare-cli/enum-keys.ts +0 -17
  141. package/src/miniflare-cli/index.ts +0 -85
  142. package/src/miniflare-cli/request-context.ts +0 -40
  143. package/src/module-collection.ts +0 -258
  144. package/src/open-in-browser.ts +0 -17
  145. package/src/package-manager.ts +0 -219
  146. package/src/pages/build.tsx +0 -204
  147. package/src/pages/constants.ts +0 -7
  148. package/src/pages/deployments.tsx +0 -106
  149. package/src/pages/dev.tsx +0 -401
  150. package/src/pages/functions/buildPlugin.ts +0 -105
  151. package/src/pages/functions/buildWorker.ts +0 -151
  152. package/src/pages/functions/filepath-routing.test.ts +0 -234
  153. package/src/pages/functions/filepath-routing.ts +0 -189
  154. package/src/pages/functions/identifiers.ts +0 -78
  155. package/src/pages/functions/routes.ts +0 -151
  156. package/src/pages/index.tsx +0 -84
  157. package/src/pages/projects.tsx +0 -163
  158. package/src/pages/publish.tsx +0 -338
  159. package/src/pages/types.ts +0 -40
  160. package/src/pages/upload.tsx +0 -396
  161. package/src/pages/utils.ts +0 -12
  162. package/src/parse.ts +0 -286
  163. package/src/paths.ts +0 -26
  164. package/src/preview.ts +0 -31
  165. package/src/proxy.ts +0 -476
  166. package/src/publish.ts +0 -793
  167. package/src/pubsub/index.ts +0 -286
  168. package/src/pubsub/pubsub-commands.tsx +0 -623
  169. package/src/r2.ts +0 -50
  170. package/src/selfsigned.d.ts +0 -29
  171. package/src/sites.tsx +0 -372
  172. package/src/tail/filters.ts +0 -279
  173. package/src/tail/index.ts +0 -299
  174. package/src/tail/printing.ts +0 -67
  175. package/src/update-check.ts +0 -19
  176. package/src/user/choose-account.tsx +0 -69
  177. package/src/user/env-vars.ts +0 -46
  178. package/src/user/generate-auth-url.ts +0 -33
  179. package/src/user/generate-random-state.ts +0 -16
  180. package/src/user/index.ts +0 -3
  181. package/src/user/user.tsx +0 -1171
  182. package/src/whoami.tsx +0 -91
  183. package/src/worker-namespace.ts +0 -206
  184. package/src/worker.ts +0 -191
  185. package/src/zones.ts +0 -76
  186. package/templates/static-asset-facade.js +0 -49
package/src/dev/local.tsx DELETED
@@ -1,373 +0,0 @@
1
- import { fork } from "node:child_process";
2
- import { realpathSync } from "node:fs";
3
- import { writeFile } from "node:fs/promises";
4
- import path from "node:path";
5
- import { useState, useEffect, useRef } from "react";
6
- import onExit from "signal-exit";
7
- import useInspector from "../inspect";
8
- import { logger } from "../logger";
9
- import { DEFAULT_MODULE_RULES } from "../module-collection";
10
- import { waitForPortToBeAvailable } from "../proxy";
11
- import type { Config } from "../config";
12
- import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli";
13
- import type { AssetPaths } from "../sites";
14
- import type { CfWorkerInit, CfScriptFormat } from "../worker";
15
- import type { EsbuildBundle } from "./use-esbuild";
16
- import type { MiniflareOptions } from "miniflare";
17
- import type { ChildProcess } from "node:child_process";
18
- interface LocalProps {
19
- name: string | undefined;
20
- bundle: EsbuildBundle | undefined;
21
- format: CfScriptFormat | undefined;
22
- compatibilityDate: string;
23
- compatibilityFlags: string[] | undefined;
24
- bindings: CfWorkerInit["bindings"];
25
- assetPaths: AssetPaths | undefined;
26
- isWorkersSite: boolean;
27
- port: number;
28
- ip: string;
29
- rules: Config["rules"];
30
- inspectorPort: number;
31
- enableLocalPersistence: boolean;
32
- liveReload: boolean;
33
- crons: Config["triggers"]["crons"];
34
- localProtocol: "http" | "https";
35
- localUpstream: string | undefined;
36
- inspect: boolean;
37
- onReady: (() => void) | undefined;
38
- logLevel: "none" | "error" | "log" | "warn" | "debug" | undefined;
39
- logPrefix?: string;
40
- enablePagesAssetsServiceBinding?: EnablePagesAssetsServiceBindingOptions;
41
- }
42
-
43
- export function Local(props: LocalProps) {
44
- const { inspectorUrl } = useLocalWorker(props);
45
- useInspector({
46
- inspectorUrl,
47
- port: props.inspectorPort,
48
- logToTerminal: false,
49
- });
50
- return null;
51
- }
52
-
53
- function useLocalWorker({
54
- name: workerName,
55
- bundle,
56
- format,
57
- compatibilityDate,
58
- compatibilityFlags,
59
- bindings,
60
- assetPaths,
61
- isWorkersSite,
62
- port,
63
- rules,
64
- enableLocalPersistence,
65
- liveReload,
66
- ip,
67
- crons,
68
- localProtocol,
69
- localUpstream,
70
- inspect,
71
- onReady,
72
- logLevel,
73
- logPrefix,
74
- enablePagesAssetsServiceBinding,
75
- }: LocalProps) {
76
- // TODO: pass vars via command line
77
- const local = useRef<ChildProcess>();
78
- const removeSignalExitListener = useRef<() => void>();
79
- const [inspectorUrl, setInspectorUrl] = useState<string | undefined>();
80
- // if we're using local persistence for data, we should use the cwd
81
- // as an explicit path, or else it'll use the temp dir
82
- // which disappears when dev ends
83
- const localPersistencePath = enableLocalPersistence
84
- ? // Maybe we could make the path configurable as well?
85
- path.join(process.cwd(), "wrangler-local-state")
86
- : // We otherwise choose null, but choose true later
87
- // so that it's persisted in the temp dir across a dev session
88
- // even when we change source and reload
89
- null;
90
- useEffect(() => {
91
- const abortController = new AbortController();
92
- async function startLocalWorker() {
93
- if (!bundle || !format) return;
94
-
95
- // port for the worker
96
- await waitForPortToBeAvailable(port, {
97
- retryPeriod: 200,
98
- timeout: 2000,
99
- abortSignal: abortController.signal,
100
- });
101
-
102
- if (bindings.services && bindings.services.length > 0) {
103
- throw new Error(
104
- "⎔ Service bindings are not yet supported in local mode."
105
- );
106
- }
107
-
108
- // In local mode, we want to copy all referenced modules into
109
- // the output bundle directory before starting up
110
- for (const module of bundle.modules) {
111
- await writeFile(
112
- path.join(path.dirname(bundle.path), module.name),
113
- module.content
114
- );
115
- }
116
-
117
- const scriptPath = realpathSync(bundle.path);
118
-
119
- // the wasm_modules/text_blobs/data_blobs bindings are
120
- // relative to process.cwd(), but the actual worker bundle
121
- // is in the temp output directory; so we rewrite the paths to be absolute,
122
- // letting miniflare resolve them correctly
123
-
124
- // wasm
125
- const wasmBindings: Record<string, string> = {};
126
- for (const [name, filePath] of Object.entries(
127
- bindings.wasm_modules || {}
128
- )) {
129
- wasmBindings[name] = path.join(process.cwd(), filePath);
130
- }
131
-
132
- // text
133
- const textBlobBindings: Record<string, string> = {};
134
- for (const [name, filePath] of Object.entries(
135
- bindings.text_blobs || {}
136
- )) {
137
- textBlobBindings[name] = path.join(process.cwd(), filePath);
138
- }
139
-
140
- // data
141
- const dataBlobBindings: Record<string, string> = {};
142
- for (const [name, filePath] of Object.entries(
143
- bindings.data_blobs || {}
144
- )) {
145
- dataBlobBindings[name] = path.join(process.cwd(), filePath);
146
- }
147
-
148
- if (format === "service-worker") {
149
- for (const { type, name } of bundle.modules) {
150
- if (type === "compiled-wasm") {
151
- // In service-worker format, .wasm modules are referenced by global identifiers,
152
- // so we convert it here.
153
- // This identifier has to be a valid JS identifier, so we replace all non alphanumeric
154
- // characters with an underscore.
155
- const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
156
- wasmBindings[identifier] = name;
157
- } else if (type === "text") {
158
- // In service-worker format, text modules are referenced by global identifiers,
159
- // so we convert it here.
160
- // This identifier has to be a valid JS identifier, so we replace all non alphanumeric
161
- // characters with an underscore.
162
- const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
163
- textBlobBindings[identifier] = name;
164
- } else if (type === "buffer") {
165
- // In service-worker format, data blobs are referenced by global identifiers,
166
- // so we convert it here.
167
- // This identifier has to be a valid JS identifier, so we replace all non alphanumeric
168
- // characters with an underscore.
169
- const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
170
- dataBlobBindings[identifier] = name;
171
- }
172
- }
173
- }
174
-
175
- const upstream =
176
- typeof localUpstream === "string"
177
- ? `${localProtocol}://${localUpstream}`
178
- : undefined;
179
-
180
- const options: MiniflareOptions = {
181
- name: workerName,
182
- port,
183
- scriptPath,
184
- https: localProtocol === "https",
185
- host: ip,
186
- modules: format === "modules",
187
- modulesRules: (rules || [])
188
- .concat(DEFAULT_MODULE_RULES)
189
- .map(({ type, globs: include, fallthrough }) => ({
190
- type,
191
- include,
192
- fallthrough,
193
- })),
194
- compatibilityDate,
195
- compatibilityFlags,
196
- kvNamespaces: bindings.kv_namespaces?.map((kv) => kv.binding),
197
- r2Buckets: bindings.r2_buckets?.map((r2) => r2.binding),
198
- durableObjects: Object.fromEntries(
199
- (bindings.durable_objects?.bindings ?? []).map<[string, string]>(
200
- (value) => [value.name, value.class_name]
201
- )
202
- ),
203
- ...(localPersistencePath
204
- ? {
205
- cachePersist: path.join(localPersistencePath, "cache"),
206
- durableObjectsPersist: path.join(localPersistencePath, "do"),
207
- kvPersist: path.join(localPersistencePath, "kv"),
208
- r2Persist: path.join(localPersistencePath, "r2"),
209
- }
210
- : {
211
- // We mark these as true, so that they'll
212
- // persist in the temp directory.
213
- // This means they'll persist across a dev session,
214
- // even if we change source and reload,
215
- // and be deleted when the dev session ends
216
- cachePersist: true,
217
- durableObjectsPersist: true,
218
- kvPersist: true,
219
- r2Persist: true,
220
- }),
221
-
222
- liveReload,
223
- sitePath: assetPaths?.assetDirectory
224
- ? path.join(assetPaths.baseDirectory, assetPaths.assetDirectory)
225
- : undefined,
226
- siteInclude: assetPaths?.includePatterns.length
227
- ? assetPaths?.includePatterns
228
- : undefined,
229
- siteExclude: assetPaths?.excludePatterns.length
230
- ? assetPaths.excludePatterns
231
- : undefined,
232
- bindings: bindings.vars,
233
- wasmBindings,
234
- textBlobBindings,
235
- dataBlobBindings,
236
- sourceMap: true,
237
- logUnhandledRejections: true,
238
- crons,
239
- upstream,
240
- disableLogs: logLevel === "none",
241
- logOptions: logPrefix ? { prefix: logPrefix } : undefined,
242
- };
243
-
244
- // The path to the Miniflare CLI assumes that this file is being run from
245
- // `wrangler-dist` and that the CLI is found in `miniflare-dist`.
246
- // If either of those paths change this line needs updating.
247
- const miniflareCLIPath = path.resolve(
248
- __dirname,
249
- "../miniflare-dist/index.mjs"
250
- );
251
- const miniflareOptions = JSON.stringify(options, null);
252
-
253
- logger.log("⎔ Starting a local server...");
254
- const nodeOptions = [
255
- "--experimental-vm-modules", // ensures that Miniflare can run ESM Workers
256
- "--no-warnings", // hide annoying Node warnings
257
- // "--log=VERBOSE", // uncomment this to Miniflare to log "everything"!
258
- ];
259
- if (inspect) {
260
- nodeOptions.push("--inspect"); // start Miniflare listening for a debugger to attach
261
- }
262
-
263
- const forkOptions = [miniflareOptions];
264
-
265
- if (enablePagesAssetsServiceBinding) {
266
- forkOptions.push(JSON.stringify(enablePagesAssetsServiceBinding));
267
- }
268
-
269
- const child = (local.current = fork(miniflareCLIPath, forkOptions, {
270
- cwd: path.dirname(scriptPath),
271
- execArgv: nodeOptions,
272
- stdio: "pipe",
273
- }));
274
-
275
- child.on("message", (message) => {
276
- if (message === "ready") {
277
- onReady?.();
278
- }
279
- });
280
-
281
- child.on("close", (code) => {
282
- if (code) {
283
- logger.log(`Miniflare process exited with code ${code}`);
284
- }
285
- });
286
-
287
- child.stdout?.on("data", (data: Buffer) => {
288
- process.stdout.write(data);
289
- });
290
-
291
- // parse the node inspector url (which may be received in chunks) from stderr
292
- let stderrData = "";
293
- let inspectorUrlFound = false;
294
- child.stderr?.on("data", (data: Buffer) => {
295
- if (!inspectorUrlFound) {
296
- stderrData += data.toString();
297
- const matches =
298
- /Debugger listening on (ws:\/\/127\.0\.0\.1:\d+\/[A-Za-z0-9-]+)[\r|\n]/.exec(
299
- stderrData
300
- );
301
- if (matches) {
302
- inspectorUrlFound = true;
303
- setInspectorUrl(matches[1]);
304
- }
305
- }
306
-
307
- process.stderr.write(data);
308
- });
309
-
310
- child.on("exit", (code) => {
311
- if (code) {
312
- logger.error(`Miniflare process exited with code ${code}`);
313
- }
314
- });
315
-
316
- child.on("error", (error: Error) => {
317
- logger.error(`Miniflare process failed to spawn`);
318
- logger.error(error);
319
- });
320
-
321
- removeSignalExitListener.current = onExit((_code, _signal) => {
322
- logger.log("⎔ Shutting down local server.");
323
- child.kill();
324
- local.current = undefined;
325
- });
326
- }
327
-
328
- startLocalWorker().catch((err) => {
329
- logger.error("local worker:", err);
330
- });
331
-
332
- return () => {
333
- abortController.abort();
334
- if (local.current) {
335
- logger.log("⎔ Shutting down local server.");
336
- local.current?.kill();
337
- local.current = undefined;
338
- removeSignalExitListener.current && removeSignalExitListener.current();
339
- removeSignalExitListener.current = undefined;
340
- }
341
- };
342
- }, [
343
- bundle,
344
- workerName,
345
- format,
346
- port,
347
- ip,
348
- bindings.durable_objects?.bindings,
349
- bindings.kv_namespaces,
350
- bindings.r2_buckets,
351
- bindings.vars,
352
- bindings.services,
353
- compatibilityDate,
354
- compatibilityFlags,
355
- localPersistencePath,
356
- liveReload,
357
- assetPaths,
358
- isWorkersSite,
359
- rules,
360
- bindings.wasm_modules,
361
- bindings.text_blobs,
362
- bindings.data_blobs,
363
- crons,
364
- localProtocol,
365
- localUpstream,
366
- inspect,
367
- logLevel,
368
- logPrefix,
369
- onReady,
370
- enablePagesAssetsServiceBinding,
371
- ]);
372
- return { inspectorUrl };
373
- }