@cdwr/fly-node 0.1.0 → 0.2.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 0.2.1 (2025-02-07)
2
+
3
+ ### 🐞 Bug Fixes
4
+
5
+ - **web:** remove dependency to payload and related packages ([0a7a63e](https://github.com/codeware-sthlm/codeware/commit/0a7a63e))
6
+
7
+ ## 0.2.0 (2025-01-30)
8
+
9
+ ### ✨ Features
10
+
11
+ - **fly-node:** optional opt out depot builder on deploy ([5bd15a0e1](https://github.com/codeware-sthlm/codeware/commit/5bd15a0e1))
12
+
13
+ ### 🐞 Bug Fixes
14
+
15
+ - **fly-node:** fix fly deploy command typo ([fa79f4daf](https://github.com/codeware-sthlm/codeware/commit/fa79f4daf))
16
+ - **fly-node:** use spawn pty for interactive prompts ([3998bc606](https://github.com/codeware-sthlm/codeware/commit/3998bc606))
17
+ - **fly-node:** detach postgres must handle interactive prompt ([6e2c79036](https://github.com/codeware-sthlm/codeware/commit/6e2c79036))
18
+
1
19
  ## 0.1.0 (2025-01-12)
2
20
 
3
21
  ### ✨ Features
package/README.md CHANGED
@@ -207,7 +207,14 @@ const response = await fly.deploy({
207
207
  postgres: 'db-app'
208
208
  });
209
209
 
210
- // With all options, could be a pull request preview deployment
210
+ // Opt out of the default depot builder
211
+ const response = await fly.deploy({
212
+ app: 'pr-19-foo-app',
213
+ config: 'apps/foo-app/fly.toml',
214
+ optOutDepotBuilder: true
215
+ });
216
+
217
+ // With options that could be a pull request preview deployment
211
218
  const response = await fly.deploy({
212
219
  app: 'pr-19-foo-app',
213
220
  config: 'apps/foo-app/fly.toml',
package/index.cjs CHANGED
@@ -65,14 +65,78 @@ var import_child_process2 = require("child_process");
65
65
  var import_util3 = require("util");
66
66
  var exec = (0, import_util3.promisify)(import_child_process2.exec);
67
67
 
68
+ // packages/core/src/lib/utils/promisified-spawn.ts
69
+ var import_child_process3 = require("child_process");
70
+ function spawn(command, args, options) {
71
+ return new Promise((resolve, reject) => {
72
+ const process2 = (0, import_child_process3.spawn)(command, args, {
73
+ ...options,
74
+ stdio: "pipe"
75
+ });
76
+ const stdoutChunks = [];
77
+ const stderrChunks = [];
78
+ process2.stdout.on("data", (data) => {
79
+ stdoutChunks.push(Buffer.from(data));
80
+ });
81
+ process2.stderr.on("data", (data) => {
82
+ stderrChunks.push(Buffer.from(data));
83
+ });
84
+ process2.on("close", (code) => {
85
+ const stdout = Buffer.concat(stdoutChunks).toString();
86
+ const stderr = Buffer.concat(stderrChunks).toString();
87
+ if (code === 0) {
88
+ resolve({ stdout, stderr });
89
+ } else {
90
+ reject(new Error(`Process exited with code ${code}
91
+ Error: ${stderr}`));
92
+ }
93
+ });
94
+ process2.on("error", reject);
95
+ });
96
+ }
97
+
68
98
  // packages/core/src/lib/utils/run-command.ts
69
99
  var import_testing = require("@nx/plugin/testing");
70
100
 
101
+ // packages/core/src/lib/utils/spawn-pty.ts
102
+ var import_node_pty_prebuilt_multiarch = require("@homebridge/node-pty-prebuilt-multiarch");
103
+ function spawnPty(command, args, options) {
104
+ return new Promise((resolve, reject) => {
105
+ const ptyData = [];
106
+ const ptyProcess = (0, import_node_pty_prebuilt_multiarch.spawn)(command, args, {
107
+ cwd: process.cwd(),
108
+ encoding: "utf-8",
109
+ env: process.env
110
+ });
111
+ ptyProcess.onData((data) => {
112
+ ptyData.push(data);
113
+ if (options?.prompt) {
114
+ const answer = options.prompt(data);
115
+ if (answer) {
116
+ ptyProcess.write(`${answer}
117
+ `);
118
+ }
119
+ }
120
+ });
121
+ ptyProcess.onExit(({ exitCode }) => {
122
+ const output = ptyData.join("");
123
+ if (exitCode === 0) {
124
+ resolve(output);
125
+ } else {
126
+ reject(
127
+ new Error(`Process exited with code ${exitCode}
128
+ Output: ${output}`)
129
+ );
130
+ }
131
+ });
132
+ });
133
+ }
134
+
71
135
  // packages/core/src/lib/utils/whoami.ts
72
136
  var import_npm_whoami = __toESM(require("npm-whoami"), 1);
73
137
 
74
138
  // packages/fly-node/src/lib/fly.class.ts
75
- var import_zod29 = require("zod");
139
+ var import_zod28 = require("zod");
76
140
 
77
141
  // packages/core/src/lib/zod/json.schema.ts
78
142
  var import_zod = require("zod");
@@ -140,43 +204,40 @@ var withCamelCase = (schema, options = {}) => {
140
204
  );
141
205
  };
142
206
 
143
- // packages/core/src/lib/zod/with-env-vars.preprocess.ts
144
- var import_zod3 = require("zod");
145
-
146
207
  // packages/core/src/lib/zod/with-replace-all.preprocess.ts
147
- var import_zod4 = require("zod");
208
+ var import_zod3 = require("zod");
148
209
 
149
210
  // packages/fly-node/src/lib/schemas/apps-create.schema.ts
150
- var import_zod6 = require("zod");
211
+ var import_zod5 = require("zod");
151
212
  var AppsCreateTransformedResponseSchema = withCamelCase(
152
- import_zod6.z.object({
153
- id: import_zod6.z.string(),
154
- name: import_zod6.z.string(),
155
- organization: import_zod6.z.object({
156
- id: import_zod6.z.string(),
157
- name: import_zod6.z.string()
213
+ import_zod5.z.object({
214
+ id: import_zod5.z.string(),
215
+ name: import_zod5.z.string(),
216
+ organization: import_zod5.z.object({
217
+ id: import_zod5.z.string(),
218
+ name: import_zod5.z.string()
158
219
  })
159
220
  })
160
221
  );
161
222
 
162
223
  // packages/fly-node/src/lib/schemas/apps-list.schema.ts
163
- var import_zod8 = require("zod");
164
- var AppsListTransformedResponseSchema = import_zod8.z.array(
224
+ var import_zod7 = require("zod");
225
+ var AppsListTransformedResponseSchema = import_zod7.z.array(
165
226
  withCamelCase(
166
- import_zod8.z.object({
167
- id: import_zod8.z.string(),
168
- name: import_zod8.z.string(),
169
- status: import_zod8.z.string(),
170
- deployed: import_zod8.z.boolean(),
171
- hostname: import_zod8.z.string(),
172
- organization: import_zod8.z.object({
173
- name: import_zod8.z.string(),
174
- slug: import_zod8.z.string()
227
+ import_zod7.z.object({
228
+ id: import_zod7.z.string(),
229
+ name: import_zod7.z.string(),
230
+ status: import_zod7.z.string(),
231
+ deployed: import_zod7.z.boolean(),
232
+ hostname: import_zod7.z.string(),
233
+ organization: import_zod7.z.object({
234
+ name: import_zod7.z.string(),
235
+ slug: import_zod7.z.string()
175
236
  }),
176
- currentRelease: import_zod8.z.nullable(
177
- import_zod8.z.object({
178
- status: import_zod8.z.string(),
179
- createdAt: import_zod8.z.string().datetime()
237
+ currentRelease: import_zod7.z.nullable(
238
+ import_zod7.z.object({
239
+ status: import_zod7.z.string(),
240
+ createdAt: import_zod7.z.string().datetime()
180
241
  })
181
242
  )
182
243
  })
@@ -184,46 +245,46 @@ var AppsListTransformedResponseSchema = import_zod8.z.array(
184
245
  );
185
246
 
186
247
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
187
- var import_zod12 = require("zod");
248
+ var import_zod11 = require("zod");
188
249
 
189
250
  // packages/fly-node/src/lib/schemas/certs-list.schema.ts
190
- var import_zod10 = require("zod");
191
- var CertsListFlyResponseElementSchema = import_zod10.z.object({
192
- createdAt: import_zod10.z.string().datetime(),
193
- hostname: import_zod10.z.string(),
194
- clientStatus: import_zod10.z.string()
251
+ var import_zod9 = require("zod");
252
+ var CertsListFlyResponseElementSchema = import_zod9.z.object({
253
+ createdAt: import_zod9.z.string().datetime(),
254
+ hostname: import_zod9.z.string(),
255
+ clientStatus: import_zod9.z.string()
195
256
  });
196
- var CertsListTransformedResponseSchema = import_zod10.z.array(
257
+ var CertsListTransformedResponseSchema = import_zod9.z.array(
197
258
  withCamelCase(CertsListFlyResponseElementSchema)
198
259
  );
199
260
 
200
261
  // packages/fly-node/src/lib/schemas/certs-list-with-app.schema.ts
201
- var CertsListWithAppTransformedResponseSchema = import_zod12.z.array(
262
+ var CertsListWithAppTransformedResponseSchema = import_zod11.z.array(
202
263
  withCamelCase(
203
264
  CertsListFlyResponseElementSchema.extend({
204
- app: import_zod12.z.string()
265
+ app: import_zod11.z.string()
205
266
  })
206
267
  )
207
268
  );
208
269
 
209
270
  // packages/fly-node/src/lib/schemas/config-show.schema.ts
210
- var import_zod14 = require("zod");
271
+ var import_zod13 = require("zod");
211
272
  var ConfigShowResponseSchema = withCamelCase(
212
- import_zod14.z.object({
213
- app: import_zod14.z.string(),
214
- primaryRegion: import_zod14.z.string().optional(),
215
- build: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()).optional().or(
216
- import_zod14.z.object({
217
- args: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.string()).optional(),
218
- dockerfile: import_zod14.z.string().optional(),
219
- image: import_zod14.z.string().optional()
273
+ import_zod13.z.object({
274
+ app: import_zod13.z.string(),
275
+ primaryRegion: import_zod13.z.string().optional(),
276
+ build: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any()).optional().or(
277
+ import_zod13.z.object({
278
+ args: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.string()).optional(),
279
+ dockerfile: import_zod13.z.string().optional(),
280
+ image: import_zod13.z.string().optional()
220
281
  })
221
282
  ),
222
- deploy: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()).optional().or(import_zod14.z.object({ strategy: import_zod14.z.string().optional() })),
223
- env: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.string()).optional(),
224
- httpService: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()).optional(),
225
- mounts: import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any()).optional(),
226
- services: import_zod14.z.array(import_zod14.z.record(import_zod14.z.string(), import_zod14.z.any())).optional()
283
+ deploy: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any()).optional().or(import_zod13.z.object({ strategy: import_zod13.z.string().optional() })),
284
+ env: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.string()).optional(),
285
+ httpService: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any()).optional(),
286
+ mounts: import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any()).optional(),
287
+ services: import_zod13.z.array(import_zod13.z.record(import_zod13.z.string(), import_zod13.z.any())).optional()
227
288
  }),
228
289
  {
229
290
  preserve: ["build.args", "env"]
@@ -231,115 +292,115 @@ var ConfigShowResponseSchema = withCamelCase(
231
292
  );
232
293
 
233
294
  // packages/fly-node/src/lib/schemas/deploy.schema.ts
234
- var import_zod15 = require("zod");
235
- var DeployResponseSchema = import_zod15.z.object({
236
- app: import_zod15.z.string(),
237
- hostname: import_zod15.z.string(),
238
- url: import_zod15.z.string().url()
295
+ var import_zod14 = require("zod");
296
+ var DeployResponseSchema = import_zod14.z.object({
297
+ app: import_zod14.z.string(),
298
+ hostname: import_zod14.z.string(),
299
+ url: import_zod14.z.string().url()
239
300
  });
240
301
 
241
302
  // packages/fly-node/src/lib/schemas/helper-schemas.ts
242
- var import_zod16 = require("zod");
243
- var AllowEmptyUrlSchema = import_zod16.z.string().url().or(import_zod16.z.literal(""));
244
- var NameSchema = import_zod16.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
303
+ var import_zod15 = require("zod");
304
+ var AllowEmptyUrlSchema = import_zod15.z.string().url().or(import_zod15.z.literal(""));
305
+ var NameSchema = import_zod15.z.string({ message: "App name must be a valid slug" }).regex(/^[a-z0-9-]+$/);
245
306
 
246
307
  // packages/fly-node/src/lib/schemas/postgres-list.ts
247
- var import_zod18 = require("zod");
248
- var PostgresListTransformedResponseSchema = import_zod18.z.array(
308
+ var import_zod17 = require("zod");
309
+ var PostgresListTransformedResponseSchema = import_zod17.z.array(
249
310
  withCamelCase(
250
- import_zod18.z.object({
251
- deployed: import_zod18.z.boolean(),
252
- hostname: import_zod18.z.string(),
253
- id: import_zod18.z.string(),
254
- name: import_zod18.z.string(),
255
- organization: import_zod18.z.object({ id: import_zod18.z.string(), slug: import_zod18.z.string() }),
256
- status: import_zod18.z.string(),
257
- version: import_zod18.z.number()
311
+ import_zod17.z.object({
312
+ deployed: import_zod17.z.boolean(),
313
+ hostname: import_zod17.z.string(),
314
+ id: import_zod17.z.string(),
315
+ name: import_zod17.z.string(),
316
+ organization: import_zod17.z.object({ id: import_zod17.z.string(), slug: import_zod17.z.string() }),
317
+ status: import_zod17.z.string(),
318
+ version: import_zod17.z.number()
258
319
  })
259
320
  )
260
321
  );
261
322
 
262
323
  // packages/fly-node/src/lib/schemas/postgres-users-list.ts
263
- var import_zod20 = require("zod");
264
- var PostgresUsersListTransformedResponseSchema = import_zod20.z.array(
324
+ var import_zod19 = require("zod");
325
+ var PostgresUsersListTransformedResponseSchema = import_zod19.z.array(
265
326
  withCamelCase(
266
- import_zod20.z.object({
267
- username: import_zod20.z.string(),
268
- superuser: import_zod20.z.boolean(),
269
- databases: import_zod20.z.array(import_zod20.z.string())
327
+ import_zod19.z.object({
328
+ username: import_zod19.z.string(),
329
+ superuser: import_zod19.z.boolean(),
330
+ databases: import_zod19.z.array(import_zod19.z.string())
270
331
  })
271
332
  )
272
333
  );
273
334
 
274
335
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
275
- var import_zod24 = require("zod");
336
+ var import_zod23 = require("zod");
276
337
 
277
338
  // packages/fly-node/src/lib/schemas/secrets-list.schema.ts
278
- var import_zod22 = require("zod");
279
- var SecretsListFlyResponseElementSchema = import_zod22.z.object({
280
- name: import_zod22.z.string(),
281
- digest: import_zod22.z.string(),
282
- createdAt: import_zod22.z.string().datetime()
339
+ var import_zod21 = require("zod");
340
+ var SecretsListFlyResponseElementSchema = import_zod21.z.object({
341
+ name: import_zod21.z.string(),
342
+ digest: import_zod21.z.string(),
343
+ createdAt: import_zod21.z.string().datetime()
283
344
  });
284
- var SecretsListTransformedResponseSchema = import_zod22.z.array(
345
+ var SecretsListTransformedResponseSchema = import_zod21.z.array(
285
346
  withCamelCase(SecretsListFlyResponseElementSchema)
286
347
  );
287
348
 
288
349
  // packages/fly-node/src/lib/schemas/secrets-list-with-app.schema.ts
289
- var SecretsListWithAppTransformedResponseSchema = import_zod24.z.array(
350
+ var SecretsListWithAppTransformedResponseSchema = import_zod23.z.array(
290
351
  withCamelCase(
291
352
  SecretsListFlyResponseElementSchema.extend({
292
- app: import_zod24.z.string()
353
+ app: import_zod23.z.string()
293
354
  })
294
355
  )
295
356
  );
296
357
 
297
358
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
298
- var import_zod28 = require("zod");
359
+ var import_zod27 = require("zod");
299
360
 
300
361
  // packages/fly-node/src/lib/schemas/status.schema.ts
301
- var import_zod26 = require("zod");
302
- var statusFlyResponseSchema = import_zod26.z.object({
303
- deployed: import_zod26.z.boolean(),
304
- hostname: import_zod26.z.string(),
305
- id: import_zod26.z.string(),
306
- machines: import_zod26.z.array(
307
- import_zod26.z.object({
308
- id: import_zod26.z.string(),
309
- name: import_zod26.z.string(),
310
- state: import_zod26.z.string(),
311
- region: import_zod26.z.string(),
312
- createdAt: import_zod26.z.string().datetime(),
313
- updatedAt: import_zod26.z.string().datetime(),
314
- config: import_zod26.z.object({
315
- env: import_zod26.z.record(import_zod26.z.string()),
316
- metadata: import_zod26.z.record(import_zod26.z.string())
362
+ var import_zod25 = require("zod");
363
+ var statusFlyResponseSchema = import_zod25.z.object({
364
+ deployed: import_zod25.z.boolean(),
365
+ hostname: import_zod25.z.string(),
366
+ id: import_zod25.z.string(),
367
+ machines: import_zod25.z.array(
368
+ import_zod25.z.object({
369
+ id: import_zod25.z.string(),
370
+ name: import_zod25.z.string(),
371
+ state: import_zod25.z.string(),
372
+ region: import_zod25.z.string(),
373
+ createdAt: import_zod25.z.string().datetime(),
374
+ updatedAt: import_zod25.z.string().datetime(),
375
+ config: import_zod25.z.object({
376
+ env: import_zod25.z.record(import_zod25.z.string()),
377
+ metadata: import_zod25.z.record(import_zod25.z.string())
317
378
  }),
318
- events: import_zod26.z.array(
319
- import_zod26.z.object({
320
- type: import_zod26.z.string(),
321
- status: import_zod26.z.string(),
322
- timestamp: import_zod26.z.number()
379
+ events: import_zod25.z.array(
380
+ import_zod25.z.object({
381
+ type: import_zod25.z.string(),
382
+ status: import_zod25.z.string(),
383
+ timestamp: import_zod25.z.number()
323
384
  })
324
385
  ),
325
- checks: import_zod26.z.array(
326
- import_zod26.z.object({
327
- name: import_zod26.z.string(),
328
- status: import_zod26.z.string(),
329
- output: import_zod26.z.string(),
330
- updatedAt: import_zod26.z.string().datetime()
386
+ checks: import_zod25.z.array(
387
+ import_zod25.z.object({
388
+ name: import_zod25.z.string(),
389
+ status: import_zod25.z.string(),
390
+ output: import_zod25.z.string(),
391
+ updatedAt: import_zod25.z.string().datetime()
331
392
  })
332
393
  ).optional(),
333
- hostStatus: import_zod26.z.string()
394
+ hostStatus: import_zod25.z.string()
334
395
  })
335
396
  ),
336
- name: import_zod26.z.string(),
337
- organization: import_zod26.z.object({
338
- id: import_zod26.z.string(),
339
- slug: import_zod26.z.string()
397
+ name: import_zod25.z.string(),
398
+ organization: import_zod25.z.object({
399
+ id: import_zod25.z.string(),
400
+ slug: import_zod25.z.string()
340
401
  }),
341
- status: import_zod26.z.string(),
342
- version: import_zod26.z.number()
402
+ status: import_zod25.z.string(),
403
+ version: import_zod25.z.number()
343
404
  });
344
405
  var StatusTransformedResponseSchema = withCamelCase(
345
406
  statusFlyResponseSchema,
@@ -352,8 +413,8 @@ var StatusTransformedResponseSchema = withCamelCase(
352
413
  // packages/fly-node/src/lib/schemas/status-extended.schema.ts
353
414
  var StatusExtendedTransformedResponseSchema = withCamelCase(
354
415
  statusFlyResponseSchema.extend({
355
- domains: import_zod28.z.array(import_zod28.z.object({ hostname: import_zod28.z.string() })),
356
- secrets: import_zod28.z.array(import_zod28.z.object({ name: import_zod28.z.string() }))
416
+ domains: import_zod27.z.array(import_zod27.z.object({ hostname: import_zod27.z.string() })),
417
+ secrets: import_zod27.z.array(import_zod27.z.object({ name: import_zod27.z.string() }))
357
418
  }),
358
419
  {
359
420
  preserve: ["machines.config.env", "machines.config.metadata"]
@@ -477,7 +538,8 @@ ${error}`
477
538
  this.logger.info(
478
539
  `Detaching Postgres cluster '${cluster}' from application '${app}'`
479
540
  );
480
- await this.detachPostgres(cluster, app);
541
+ const output = await this.detachPostgres(cluster, app);
542
+ this.logger.info(output);
481
543
  }
482
544
  await this.destroyApp(app, options?.force);
483
545
  this.logger.info(`Application '${app}' was destroyed`);
@@ -624,6 +686,11 @@ ${error}`
624
686
  );
625
687
  }
626
688
  };
689
+ postgres = {
690
+ detach: async (cluster, app) => {
691
+ await this.detachPostgres(cluster, app);
692
+ }
693
+ };
627
694
  /**
628
695
  * Manage application secrets
629
696
  */
@@ -866,6 +933,9 @@ ${error}`);
866
933
  for (const [key, value] of Object.entries(options?.env || {})) {
867
934
  args.push("--env", `${key}=${this.safeArg(value)}`);
868
935
  }
936
+ if (options?.optOutDepotBuilder) {
937
+ args.push("--depot=false");
938
+ }
869
939
  args.push("--yes");
870
940
  this.logger.info(`Deploying '${appName}'...`);
871
941
  await this.execFly(args);
@@ -891,11 +961,19 @@ ${error}`);
891
961
  }
892
962
  /**
893
963
  * @private
964
+ * @returns Log output from the detach process
894
965
  * @throws An error if the Postgres database cannot be detached from an app
895
966
  */
896
967
  async detachPostgres(postgres, app) {
897
968
  const args = ["postgres", "detach", postgres, "--app", app];
898
- await this.execFly(args);
969
+ return await this.execFly(args, {
970
+ prompt: (output) => {
971
+ if (output.match(/select .* detach/i)) {
972
+ return app.replace(/-/g, "_");
973
+ }
974
+ return;
975
+ }
976
+ });
899
977
  }
900
978
  /**
901
979
  * @private
@@ -1032,7 +1110,7 @@ ${error}`);
1032
1110
  if (onError === "throwOnError") {
1033
1111
  throw error;
1034
1112
  }
1035
- if (error instanceof import_zod29.ZodError) {
1113
+ if (error instanceof import_zod28.ZodError) {
1036
1114
  this.logger.info(`Failed to parse response:
1037
1115
  ${error.message}`);
1038
1116
  this.logger.info(`Raw response:
@@ -1119,6 +1197,7 @@ ${JSON.stringify(response, null, 2)}`);
1119
1197
  this.logger.info("Authenticating with Fly.io...");
1120
1198
  let user = await this.execFly(
1121
1199
  ["auth", "whoami"],
1200
+ void 0,
1122
1201
  "nullOnError",
1123
1202
  true
1124
1203
  // won't use token
@@ -1136,34 +1215,43 @@ ${JSON.stringify(response, null, 2)}`);
1136
1215
  throw error;
1137
1216
  }
1138
1217
  }
1139
- async execFly(command, onError = "throwOnError", skipToken) {
1140
- const cmdArr = Array.isArray(command) ? command : [command];
1218
+ async execFly(command, options, onError = "throwOnError", skipToken) {
1219
+ const args = Array.isArray(command) ? command : command.split(" ");
1141
1220
  if (!skipToken && !this.authByLogin && this._config.token) {
1142
- cmdArr.push("--access-token", this._config.token);
1221
+ args.push("--access-token", this._config.token);
1143
1222
  }
1144
- const flyCmd = `flyctl ${cmdArr.filter(Boolean).join(" ")}`;
1145
- let stdout = "";
1223
+ const flyCmd = "flyctl";
1224
+ const toLogCmd = `${flyCmd} ${args.join(" ")}`;
1225
+ let output = "";
1146
1226
  try {
1147
- this.traceCLI("CALL", flyCmd);
1148
- const result = await exec(flyCmd);
1149
- stdout = result.stdout.trim();
1150
- this.traceCLI("RESULT", stdout);
1227
+ this.traceCLI("CALL", toLogCmd);
1228
+ if (options?.prompt) {
1229
+ output = await spawnPty(flyCmd, args, { prompt: options.prompt });
1230
+ this.traceCLI("RESULT", output);
1231
+ } else {
1232
+ const result = await spawn(flyCmd, args, options);
1233
+ output = result.stdout.trim();
1234
+ const stderr = result.stderr.trim();
1235
+ this.traceCLI("RESULT", `${output}${stderr ? `
1236
+ ${stderr}` : ""}`);
1237
+ }
1151
1238
  } catch (error) {
1152
- this.traceCLI("RESULT", error);
1239
+ const errorMsg = error.message;
1240
+ this.traceCLI("RESULT", errorMsg);
1153
1241
  if (onError === "throwOnError") {
1154
- throw new Error(`Command failed: ${flyCmd}
1155
- ${error}`);
1242
+ throw new Error(`Command failed: ${toLogCmd}
1243
+ ${errorMsg}`);
1156
1244
  }
1157
1245
  return null;
1158
1246
  }
1159
1247
  try {
1160
- return JSON.parse(stdout);
1248
+ return JSON.parse(output);
1161
1249
  } catch {
1162
- if (stdout) {
1250
+ if (output) {
1163
1251
  if (this.logger.traceCLI) {
1164
1252
  this.logger.info(`Failed to parse as JSON, returning raw output`);
1165
1253
  }
1166
- return stdout;
1254
+ return output;
1167
1255
  }
1168
1256
  }
1169
1257
  return void 0;
@@ -1233,7 +1321,7 @@ ${error}`);
1233
1321
  * @returns `true` if the Fly CLI is installed, `false` otherwise
1234
1322
  */
1235
1323
  async isInstalled() {
1236
- return await this.execFly("version", "nullOnError") !== null;
1324
+ return await this.execFly("version", void 0, "nullOnError") !== null;
1237
1325
  }
1238
1326
  /**
1239
1327
  * @private