wrangler 0.0.0-e928f94 → 0.0.0-e95bea2

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 (100) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +46 -18
  3. package/pages/functions/buildWorker.ts +62 -0
  4. package/pages/functions/filepath-routing.test.ts +123 -0
  5. package/pages/functions/filepath-routing.ts +178 -0
  6. package/pages/functions/identifiers.ts +78 -0
  7. package/pages/functions/routes.ts +151 -0
  8. package/pages/functions/template-worker.ts +130 -0
  9. package/src/__tests__/configuration.test.ts +2217 -0
  10. package/src/__tests__/dev.test.tsx +405 -0
  11. package/src/__tests__/dev2.test.tsx +152 -0
  12. package/src/__tests__/guess-worker-format.test.ts +58 -0
  13. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  14. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  15. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  16. package/src/__tests__/helpers/mock-account-id.ts +44 -0
  17. package/src/__tests__/helpers/mock-bin.ts +36 -0
  18. package/src/__tests__/helpers/mock-cfetch.ts +207 -0
  19. package/src/__tests__/helpers/mock-console.ts +70 -0
  20. package/src/__tests__/helpers/mock-dialogs.ts +65 -0
  21. package/src/__tests__/helpers/mock-kv.ts +40 -0
  22. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  23. package/src/__tests__/helpers/mock-user.ts +27 -0
  24. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  25. package/src/__tests__/helpers/run-in-tmp.ts +29 -0
  26. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  27. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  28. package/src/__tests__/https-options.test.ts +127 -0
  29. package/src/__tests__/index.test.ts +957 -119
  30. package/src/__tests__/jest.setup.ts +69 -0
  31. package/src/__tests__/kv.test.ts +1408 -0
  32. package/src/__tests__/logout.test.ts +50 -0
  33. package/src/__tests__/package-manager.test.ts +206 -0
  34. package/src/__tests__/pages.test.ts +44 -0
  35. package/src/__tests__/parse.test.ts +322 -0
  36. package/src/__tests__/publish.test.ts +2453 -0
  37. package/src/__tests__/r2.test.ts +198 -0
  38. package/src/__tests__/route.test.ts +45 -0
  39. package/src/__tests__/secret.test.ts +425 -0
  40. package/src/__tests__/sentry.test.ts +146 -0
  41. package/src/__tests__/tail.test.ts +564 -0
  42. package/src/__tests__/whoami.test.tsx +86 -0
  43. package/src/bundle.ts +142 -0
  44. package/src/cfetch/index.ts +104 -0
  45. package/src/cfetch/internal.ts +135 -0
  46. package/src/cli.ts +16 -7
  47. package/src/config/README.md +107 -0
  48. package/src/config/config.ts +279 -0
  49. package/src/config/diagnostics.ts +80 -0
  50. package/src/config/environment.ts +305 -0
  51. package/src/config/index.ts +52 -0
  52. package/src/config/validation-helpers.ts +388 -0
  53. package/src/config/validation.ts +1027 -0
  54. package/src/{api/preview.ts → create-worker-preview.ts} +63 -25
  55. package/src/create-worker-upload-form.ts +217 -0
  56. package/src/dev/dev.tsx +357 -0
  57. package/src/dev/local.tsx +241 -0
  58. package/src/dev/remote.tsx +201 -0
  59. package/src/dev/use-esbuild.ts +100 -0
  60. package/src/dialogs.tsx +5 -13
  61. package/src/entry.ts +159 -0
  62. package/src/environment-variables.ts +33 -0
  63. package/src/https-options.ts +122 -0
  64. package/src/index.tsx +1374 -903
  65. package/src/inspect.ts +617 -0
  66. package/src/kv/index.tsx +339 -0
  67. package/src/module-collection.ts +215 -26
  68. package/src/open-in-browser.ts +25 -0
  69. package/src/package-manager.ts +126 -0
  70. package/src/pages.tsx +452 -250
  71. package/src/parse.ts +183 -0
  72. package/src/paths.ts +26 -0
  73. package/src/proxy.ts +438 -0
  74. package/src/publish.ts +300 -292
  75. package/src/r2.ts +50 -0
  76. package/src/reporting.ts +131 -0
  77. package/src/selfsigned.d.ts +29 -0
  78. package/src/sites.tsx +181 -58
  79. package/src/tail/filters.ts +279 -0
  80. package/src/tail/index.ts +299 -0
  81. package/src/tail/printing.ts +62 -0
  82. package/src/user.tsx +166 -130
  83. package/src/whoami.tsx +69 -0
  84. package/src/worker.ts +163 -0
  85. package/templates/new-worker.js +15 -0
  86. package/templates/new-worker.ts +15 -0
  87. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  88. package/templates/tsconfig.json +105 -0
  89. package/wrangler-dist/cli.js +131958 -115793
  90. package/wrangler-dist/cli.js.map +3 -3
  91. package/src/__tests__/fixtures/init/.gitkeep +0 -0
  92. package/src/__tests__/mock-cfetch.js +0 -46
  93. package/src/api/form_data.ts +0 -141
  94. package/src/api/inspect.ts +0 -441
  95. package/src/api/worker.ts +0 -161
  96. package/src/cfetch.ts +0 -72
  97. package/src/config.ts +0 -122
  98. package/src/dev.tsx +0 -724
  99. package/src/kv.tsx +0 -211
  100. package/src/tail.tsx +0 -71
@@ -0,0 +1,241 @@
1
+ import { spawn } 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 { DEFAULT_MODULE_RULES } from "../module-collection";
9
+ import { waitForPortToBeAvailable } from "../proxy";
10
+ import type { Config } from "../config";
11
+ import type { AssetPaths } from "../sites";
12
+ import type { CfWorkerInit, CfScriptFormat } from "../worker";
13
+ import type { EsbuildBundle } from "./use-esbuild";
14
+
15
+ export function Local(props: {
16
+ name: undefined | string;
17
+ bundle: EsbuildBundle | undefined;
18
+ format: CfScriptFormat | undefined;
19
+ bindings: CfWorkerInit["bindings"];
20
+ assetPaths: undefined | AssetPaths;
21
+ public: undefined | string;
22
+ port: number;
23
+ rules: Config["rules"];
24
+ inspectorPort: number;
25
+ enableLocalPersistence: boolean;
26
+ }) {
27
+ const { inspectorUrl } = useLocalWorker({
28
+ name: props.name,
29
+ bundle: props.bundle,
30
+ format: props.format,
31
+ bindings: props.bindings,
32
+ assetPaths: props.assetPaths,
33
+ public: props.public,
34
+ port: props.port,
35
+ rules: props.rules,
36
+ enableLocalPersistence: props.enableLocalPersistence,
37
+ });
38
+ useInspector({
39
+ inspectorUrl,
40
+ port: props.inspectorPort,
41
+ logToTerminal: false,
42
+ });
43
+ return null;
44
+ }
45
+
46
+ function useLocalWorker(props: {
47
+ name: undefined | string;
48
+ bundle: EsbuildBundle | undefined;
49
+ rules: Config["rules"];
50
+ format: CfScriptFormat | undefined;
51
+ bindings: CfWorkerInit["bindings"];
52
+ assetPaths: undefined | AssetPaths;
53
+ public: undefined | string;
54
+ port: number;
55
+ enableLocalPersistence: boolean;
56
+ }) {
57
+ // TODO: pass vars via command line
58
+ const { bundle, format, bindings, port, assetPaths } = props;
59
+ const local = useRef<ReturnType<typeof spawn>>();
60
+ const removeSignalExitListener = useRef<() => void>();
61
+ const [inspectorUrl, setInspectorUrl] = useState<string | undefined>();
62
+ useEffect(() => {
63
+ async function startLocalWorker() {
64
+ if (!bundle || !format) return;
65
+
66
+ // port for the worker
67
+ await waitForPortToBeAvailable(port, { retryPeriod: 200, timeout: 2000 });
68
+
69
+ if (props.public) {
70
+ throw new Error(
71
+ '⎔ A "public" folder is not yet supported in local mode.'
72
+ );
73
+ }
74
+
75
+ // In local mode, we want to copy all referenced modules into
76
+ // the output bundle directory before starting up
77
+ for (const module of bundle.modules) {
78
+ await writeFile(
79
+ path.join(path.dirname(bundle.path), module.name),
80
+ module.content
81
+ );
82
+ }
83
+
84
+ console.log("⎔ Starting a local server...");
85
+ // TODO: just use execa for this
86
+ local.current = spawn(
87
+ "node",
88
+ [
89
+ "--experimental-vm-modules",
90
+ "--inspect",
91
+ require.resolve("miniflare/cli"),
92
+ realpathSync(bundle.path),
93
+ "--watch",
94
+ "--wrangler-config",
95
+ path.join(__dirname, "../miniflare-config-stubs/wrangler.empty.toml"),
96
+ "--env",
97
+ path.join(__dirname, "../miniflare-config-stubs/.env.empty"),
98
+ "--package",
99
+ path.join(__dirname, "../miniflare-config-stubs/package.empty.json"),
100
+ "--port",
101
+ port.toString(),
102
+ ...(assetPaths
103
+ ? [
104
+ "--site",
105
+ path.join(process.cwd(), assetPaths.baseDirectory),
106
+ ...assetPaths.includePatterns.map((pattern) => [
107
+ "--site-include",
108
+ pattern,
109
+ ]),
110
+ ...assetPaths.excludePatterns.map((pattern) => [
111
+ "--site-exclude",
112
+ pattern,
113
+ ]),
114
+ ].flatMap((x) => x)
115
+ : []),
116
+ ...(props.enableLocalPersistence
117
+ ? ["--kv-persist", "--cache-persist", "--do-persist"]
118
+ : []),
119
+ ...Object.entries(bindings.vars || {}).flatMap(([key, value]) => {
120
+ return ["--binding", `${key}=${value}`];
121
+ }),
122
+ ...(bindings.kv_namespaces || []).flatMap(({ binding }) => {
123
+ return ["--kv", binding];
124
+ }),
125
+ ...(bindings.durable_objects?.bindings || []).flatMap(
126
+ ({ name, class_name }) => {
127
+ return ["--do", `${name}=${class_name}`];
128
+ }
129
+ ),
130
+ ...Object.entries(bindings.wasm_modules || {}).flatMap(
131
+ ([name, filePath]) => {
132
+ return [
133
+ "--wasm",
134
+ `${name}=${path.join(process.cwd(), filePath)}`,
135
+ ];
136
+ }
137
+ ),
138
+ ...bundle.modules.reduce<string[]>((cmd, { name, type }) => {
139
+ if (format === "service-worker") {
140
+ if (type === "compiled-wasm") {
141
+ // In service-worker format, .wasm modules are referenced
142
+ // by global identifiers, so we convert it here.
143
+ // This identifier has to be a valid JS identifier,
144
+ // so we replace all non alphanumeric characters
145
+ // with an underscore.
146
+ const identifier = name.replace(/[^a-zA-Z0-9_$]/g, "_");
147
+ return cmd.concat([`--wasm`, `${identifier}=${name}`]);
148
+ } else {
149
+ // TODO: we should actually support this
150
+ throw new Error(
151
+ `⎔ Unsupported module type ${type} for file ${name} in service-worker format`
152
+ );
153
+ }
154
+ }
155
+ return cmd;
156
+ }, []),
157
+ "--modules",
158
+ String(format === "modules"),
159
+ ...(props.rules || [])
160
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
161
+ .concat(DEFAULT_MODULE_RULES!)
162
+ .flatMap((rule) =>
163
+ rule.globs.flatMap((glob) => [
164
+ "--modules-rule",
165
+ `${rule.type}=${glob}`,
166
+ ])
167
+ ),
168
+ ],
169
+ {
170
+ cwd: path.dirname(realpathSync(bundle.path)),
171
+ }
172
+ );
173
+ console.log(`⬣ Listening at http://localhost:${port}`);
174
+
175
+ local.current.on("close", (code) => {
176
+ if (code) {
177
+ console.log(`miniflare process exited with code ${code}`);
178
+ }
179
+ });
180
+
181
+ local.current.stdout?.on("data", (data: Buffer) => {
182
+ console.log(`${data.toString()}`);
183
+ });
184
+
185
+ local.current.stderr?.on("data", (data: Buffer) => {
186
+ console.error(`${data.toString()}`);
187
+ const matches =
188
+ /Debugger listening on (ws:\/\/127\.0\.0\.1:\d+\/[A-Za-z0-9-]+)/.exec(
189
+ data.toString()
190
+ );
191
+ if (matches) {
192
+ setInspectorUrl(matches[1]);
193
+ }
194
+ });
195
+
196
+ local.current.on("exit", (code) => {
197
+ if (code) {
198
+ console.error(`miniflare process exited with code ${code}`);
199
+ }
200
+ });
201
+
202
+ local.current.on("error", (error: Error) => {
203
+ console.error(`miniflare process failed to spawn`);
204
+ console.error(error);
205
+ });
206
+
207
+ removeSignalExitListener.current = onExit((_code, _signal) => {
208
+ console.log("⎔ Shutting down local server.");
209
+ local.current?.kill();
210
+ local.current = undefined;
211
+ });
212
+ }
213
+
214
+ startLocalWorker().catch((err) => {
215
+ console.error("local worker:", err);
216
+ });
217
+
218
+ return () => {
219
+ if (local.current) {
220
+ console.log("⎔ Shutting down local server.");
221
+ local.current?.kill();
222
+ local.current = undefined;
223
+ removeSignalExitListener.current && removeSignalExitListener.current();
224
+ removeSignalExitListener.current = undefined;
225
+ }
226
+ };
227
+ }, [
228
+ bundle,
229
+ format,
230
+ port,
231
+ bindings.durable_objects?.bindings,
232
+ bindings.kv_namespaces,
233
+ bindings.vars,
234
+ props.enableLocalPersistence,
235
+ assetPaths,
236
+ props.public,
237
+ props.rules,
238
+ bindings.wasm_modules,
239
+ ]);
240
+ return { inspectorUrl };
241
+ }
@@ -0,0 +1,201 @@
1
+ import assert from "node:assert";
2
+ import { readFile } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { useState, useEffect, useRef } from "react";
5
+ import { createWorkerPreview } from "../create-worker-preview";
6
+ import useInspector from "../inspect";
7
+ import { usePreviewServer } from "../proxy";
8
+ import { syncAssets } from "../sites";
9
+ import type { CfPreviewToken } from "../create-worker-preview";
10
+ import type { AssetPaths } from "../sites";
11
+ import type { CfModule, CfWorkerInit, CfScriptFormat } from "../worker";
12
+ import type { EsbuildBundle } from "./use-esbuild";
13
+
14
+ export function Remote(props: {
15
+ name: string | undefined;
16
+ bundle: EsbuildBundle | undefined;
17
+ format: CfScriptFormat | undefined;
18
+ public: undefined | string;
19
+ assetPaths: undefined | AssetPaths;
20
+ port: number;
21
+ localProtocol: "https" | "http";
22
+ inspectorPort: number;
23
+ accountId: undefined | string;
24
+ apiToken: undefined | string;
25
+ bindings: CfWorkerInit["bindings"];
26
+ compatibilityDate: string | undefined;
27
+ compatibilityFlags: undefined | string[];
28
+ usageModel: undefined | "bundled" | "unbound";
29
+ env: string | undefined;
30
+ legacyEnv: boolean | undefined;
31
+ zone: { id: string; host: string } | undefined;
32
+ }) {
33
+ assert(props.accountId, "accountId is required");
34
+ assert(props.apiToken, "apiToken is required");
35
+ const previewToken = useWorker({
36
+ name: props.name,
37
+ bundle: props.bundle,
38
+ format: props.format,
39
+ modules: props.bundle ? props.bundle.modules : [],
40
+ accountId: props.accountId,
41
+ apiToken: props.apiToken,
42
+ bindings: props.bindings,
43
+ assetPaths: props.assetPaths,
44
+ port: props.port,
45
+ compatibilityDate: props.compatibilityDate,
46
+ compatibilityFlags: props.compatibilityFlags,
47
+ usageModel: props.usageModel,
48
+ env: props.env,
49
+ legacyEnv: props.legacyEnv,
50
+ zone: props.zone,
51
+ });
52
+
53
+ usePreviewServer({
54
+ previewToken,
55
+ publicRoot: props.public,
56
+ localProtocol: props.localProtocol,
57
+ localPort: props.port,
58
+ });
59
+
60
+ useInspector({
61
+ inspectorUrl: previewToken ? previewToken.inspectorUrl.href : undefined,
62
+ port: props.inspectorPort,
63
+ logToTerminal: true,
64
+ });
65
+ return null;
66
+ }
67
+
68
+ export function useWorker(props: {
69
+ name: string | undefined;
70
+ bundle: EsbuildBundle | undefined;
71
+ format: CfScriptFormat | undefined;
72
+ modules: CfModule[];
73
+ accountId: string;
74
+ apiToken: string;
75
+ bindings: CfWorkerInit["bindings"];
76
+ assetPaths: undefined | AssetPaths;
77
+ port: number;
78
+ compatibilityDate: string | undefined;
79
+ compatibilityFlags: string[] | undefined;
80
+ usageModel: undefined | "bundled" | "unbound";
81
+ env: string | undefined;
82
+ legacyEnv: boolean | undefined;
83
+ zone: { id: string; host: string } | undefined;
84
+ }): CfPreviewToken | undefined {
85
+ const {
86
+ name,
87
+ bundle,
88
+ format,
89
+ modules,
90
+ accountId,
91
+ apiToken,
92
+ bindings,
93
+ assetPaths,
94
+ compatibilityDate,
95
+ compatibilityFlags,
96
+ usageModel,
97
+ port,
98
+ } = props;
99
+ const [token, setToken] = useState<CfPreviewToken | undefined>();
100
+
101
+ // This is the most reliable way to detect whether
102
+ // something's "happened" in our system; We make a ref and
103
+ // mark it once we log our initial message. Refs are vars!
104
+ const startedRef = useRef(false);
105
+
106
+ useEffect(() => {
107
+ async function start() {
108
+ setToken(undefined); // reset token in case we're re-running
109
+
110
+ if (!bundle || !format) return;
111
+
112
+ if (!startedRef.current) {
113
+ startedRef.current = true;
114
+ } else {
115
+ console.log("⎔ Detected changes, restarted server.");
116
+ }
117
+
118
+ const assets = await syncAssets(
119
+ accountId,
120
+ // When we're using the newer service environments, we wouldn't
121
+ // have added the env name on to the script name. However, we must
122
+ // include it in the kv namespace name regardless (since there's no
123
+ // concept of service environments for kv namespaces yet).
124
+ name + (!props.legacyEnv && props.env ? `-${props.env}` : ""),
125
+ assetPaths,
126
+ true
127
+ ); // TODO: cancellable?
128
+
129
+ const content = await readFile(bundle.path, "utf-8");
130
+
131
+ const init: CfWorkerInit = {
132
+ name,
133
+ main: {
134
+ name: path.basename(bundle.path),
135
+ type: format === "modules" ? "esm" : "commonjs",
136
+ content,
137
+ },
138
+ modules: modules.concat(
139
+ assets.manifest
140
+ ? {
141
+ name: "__STATIC_CONTENT_MANIFEST",
142
+ content: JSON.stringify(assets.manifest),
143
+ type: "text",
144
+ }
145
+ : []
146
+ ),
147
+ bindings: {
148
+ ...bindings,
149
+ kv_namespaces: (bindings.kv_namespaces || []).concat(
150
+ assets.namespace
151
+ ? { binding: "__STATIC_CONTENT", id: assets.namespace }
152
+ : []
153
+ ),
154
+ text_blobs: {
155
+ ...bindings.text_blobs,
156
+ ...(assets.manifest &&
157
+ format === "service-worker" && {
158
+ __STATIC_CONTENT_MANIFEST: "__STATIC_CONTENT_MANIFEST",
159
+ }),
160
+ },
161
+ },
162
+ migrations: undefined, // no migrations in dev
163
+ compatibility_date: compatibilityDate,
164
+ compatibility_flags: compatibilityFlags,
165
+ usage_model: usageModel,
166
+ };
167
+ setToken(
168
+ await createWorkerPreview(
169
+ init,
170
+ {
171
+ accountId,
172
+ apiToken,
173
+ },
174
+ { env: props.env, legacyEnv: props.legacyEnv, zone: props.zone }
175
+ )
176
+ );
177
+ }
178
+ start().catch((err) => {
179
+ // we want to log the error, but not end the process
180
+ // since it could recover after the developer fixes whatever's wrong
181
+ console.error("remote worker:", err);
182
+ });
183
+ }, [
184
+ name,
185
+ bundle,
186
+ format,
187
+ accountId,
188
+ apiToken,
189
+ port,
190
+ assetPaths,
191
+ compatibilityDate,
192
+ compatibilityFlags,
193
+ usageModel,
194
+ bindings,
195
+ modules,
196
+ props.env,
197
+ props.legacyEnv,
198
+ props.zone,
199
+ ]);
200
+ return token;
201
+ }
@@ -0,0 +1,100 @@
1
+ import assert from "node:assert";
2
+ import { useState, useEffect } from "react";
3
+ import { bundleWorker } from "../bundle";
4
+ import type { Config } from "../config";
5
+ import type { Entry } from "../entry";
6
+ import type { CfModule } from "../worker";
7
+ import type { WatchMode } from "esbuild";
8
+
9
+ export type EsbuildBundle = {
10
+ id: number;
11
+ path: string;
12
+ entry: Entry;
13
+ type: "esm" | "commonjs";
14
+ modules: CfModule[];
15
+ serveAssetsFromWorker: boolean;
16
+ };
17
+
18
+ export function useEsbuild({
19
+ entry,
20
+ destination,
21
+ staticRoot,
22
+ jsxFactory,
23
+ jsxFragment,
24
+ rules,
25
+ serveAssetsFromWorker,
26
+ }: {
27
+ entry: Entry;
28
+ destination: string | undefined;
29
+ staticRoot: undefined | string;
30
+ jsxFactory: string | undefined;
31
+ jsxFragment: string | undefined;
32
+ rules: Config["rules"];
33
+ serveAssetsFromWorker: boolean;
34
+ }): EsbuildBundle | undefined {
35
+ const [bundle, setBundle] = useState<EsbuildBundle>();
36
+ useEffect(() => {
37
+ let stopWatching: (() => void) | undefined = undefined;
38
+
39
+ const watchMode: WatchMode = {
40
+ async onRebuild(error) {
41
+ if (error) console.error("watch build failed:", error);
42
+ else {
43
+ // nothing really changes here, so let's increment the id
44
+ // to change the return object's identity
45
+ setBundle((previousBundle) => {
46
+ assert(
47
+ previousBundle,
48
+ "Rebuild triggered with no previous build available"
49
+ );
50
+ return { ...previousBundle, id: previousBundle.id + 1 };
51
+ });
52
+ }
53
+ },
54
+ };
55
+
56
+ async function build() {
57
+ if (!destination) return;
58
+
59
+ const { resolvedEntryPointPath, bundleType, modules, stop } =
60
+ await bundleWorker(entry, destination, {
61
+ // In dev, we serve assets from the local proxy before we send the request to the worker.
62
+ serveAssetsFromWorker: false,
63
+ jsxFactory,
64
+ jsxFragment,
65
+ rules,
66
+ watch: watchMode,
67
+ });
68
+
69
+ // Capture the `stop()` method to use as the `useEffect()` destructor.
70
+ stopWatching = stop;
71
+
72
+ setBundle({
73
+ id: 0,
74
+ entry,
75
+ path: resolvedEntryPointPath,
76
+ type: bundleType,
77
+ modules,
78
+ serveAssetsFromWorker,
79
+ });
80
+ }
81
+
82
+ build().catch(() => {
83
+ // esbuild already logs errors to stderr and we don't want to end the process
84
+ // on build errors anyway so this is a no-op error handler
85
+ });
86
+
87
+ return () => {
88
+ stopWatching?.();
89
+ };
90
+ }, [
91
+ entry,
92
+ destination,
93
+ staticRoot,
94
+ jsxFactory,
95
+ jsxFragment,
96
+ serveAssetsFromWorker,
97
+ rules,
98
+ ]);
99
+ return bundle;
100
+ }
package/src/dialogs.tsx CHANGED
@@ -1,10 +1,10 @@
1
- import * as React from "react";
2
- import { useState } from "react";
3
1
  import { Box, Text, useInput, render } from "ink";
4
2
  import TextInput from "ink-text-input";
3
+ import * as React from "react";
4
+ import { useState } from "react";
5
5
  type ConfirmProps = {
6
6
  text: string;
7
- onConfirm: (answer: boolean) => void | Promise<void>;
7
+ onConfirm: (answer: boolean) => void;
8
8
  };
9
9
  function Confirm(props: ConfirmProps) {
10
10
  useInput((input: string) => {
@@ -67,19 +67,11 @@ export async function prompt(text: string, type: "text" | "password" = "text") {
67
67
  <Prompt
68
68
  text={text}
69
69
  type={type}
70
- onSubmit={(text) => {
70
+ onSubmit={(inputText) => {
71
71
  unmount();
72
- resolve(text);
72
+ resolve(inputText);
73
73
  }}
74
74
  />
75
75
  );
76
76
  });
77
77
  }
78
-
79
- // this one feels a little non "standard"
80
- // export async function select(
81
- // title: string,
82
- // choices: { label: string; value: string }[]
83
- // ): Promise<{ label: string; value: string }>{
84
-
85
- // }