flypod 0.16.1 → 0.17.0

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.
@@ -2,18 +2,43 @@
2
2
  import {
3
3
  BUILD_DIR_CANDIDATES,
4
4
  DeployError,
5
+ FIRST_RUN_NOTICE,
6
+ HOSTED_UPLOAD_LIMITS,
7
+ NOT_SIGNED_IN,
8
+ NO_SITE,
9
+ PLAIN,
5
10
  atomicWriteFile,
11
+ classifyResponse,
6
12
  clearSession,
7
13
  collectFiles,
8
14
  createClient,
9
- deploySite,
15
+ emitError,
16
+ errorEnvelope,
17
+ exitCodeFor,
18
+ fail,
19
+ failure,
20
+ field,
21
+ flushFailureReports,
22
+ headline,
23
+ hero,
24
+ installId,
10
25
  installSkill,
26
+ networkError,
27
+ noBuildDir,
28
+ notice,
11
29
  packDeploy,
12
30
  projectsFilePath,
31
+ reportFailure,
13
32
  resolveCredentials,
14
33
  resolveDeployDir,
15
- saveSession
16
- } from "../cli-8h0vc7g2.js";
34
+ saveSession,
35
+ setCliVersion,
36
+ shortVersion,
37
+ startFailureReports,
38
+ storedZipBytes,
39
+ unexpectedError,
40
+ uploadLimitsFor
41
+ } from "../cli-z3p9tds1.js";
17
42
 
18
43
  // bin/deploy.ts
19
44
  import { readFile as readFile2, stat } from "node:fs/promises";
@@ -21,280 +46,9 @@ import { homedir } from "node:os";
21
46
  import { relative } from "node:path";
22
47
  import { fileURLToPath } from "node:url";
23
48
 
24
- // src/upload-limits.ts
25
- var HOSTED_UPLOAD_LIMITS = {
26
- maxFiles: 200,
27
- maxTotalBytes: 10 * 1024 * 1024,
28
- maxZipBytes: 12 * 1024 * 1024
29
- };
30
- function uploadLimitsFor(baseUrl) {
31
- try {
32
- const host = new URL(baseUrl).hostname;
33
- return host === "flypod.dev" || host.endsWith(".flypod.dev") ? HOSTED_UPLOAD_LIMITS : null;
34
- } catch {
35
- return null;
36
- }
37
- }
38
- function storedZipBytes(files) {
39
- const encoder = new TextEncoder;
40
- let total = 22;
41
- for (const [name, bytes] of Object.entries(files)) {
42
- total += 76 + 2 * encoder.encode(name).byteLength + bytes.byteLength;
43
- }
44
- return total;
45
- }
46
-
47
- // src/cli/screen.ts
48
- var WIDTH = 66;
49
- var GUTTER = 10;
50
- var id = (s) => s;
51
- var PLAIN = {
52
- dim: id,
53
- bold: id,
54
- muted: id,
55
- accent: id,
56
- ok: id,
57
- err: id,
58
- warn: id
59
- };
60
- function wrap(text, width) {
61
- const lines = [];
62
- for (const paragraph of text.split(`
63
- `)) {
64
- let line = "";
65
- for (const word of paragraph.split(/\s+/).filter(Boolean)) {
66
- if (line && line.length + 1 + word.length > width) {
67
- lines.push(line);
68
- line = word;
69
- } else {
70
- line = line ? `${line} ${word}` : word;
71
- }
72
- }
73
- lines.push(line);
74
- }
75
- return lines;
76
- }
77
- function headline(text, detail, s) {
78
- return ` ${s.ok("✓")} ${text}${detail ? s.dim(` · ${detail}`) : ""}`;
79
- }
80
- function hero(url, s) {
81
- return ` ${s.bold(s.accent(url))}`;
82
- }
83
- function field(label, value, hint, s) {
84
- return ` ${s.muted(label.padEnd(GUTTER))}${value}${hint ? ` ${s.dim(hint)}` : ""}`;
85
- }
86
- function notice(title, body, s) {
87
- return [
88
- ` ${(s.warn ?? id)("!")} ${s.bold(title)}`,
89
- ...wrap(body, WIDTH - 4).map((line) => ` ${s.dim(line)}`),
90
- ""
91
- ];
92
- }
93
- function failure(error, fix, s) {
94
- const [first = "", ...rest] = wrap(error, WIDTH - 4);
95
- return [
96
- ` ${(s.err ?? id)("✗")} ${first}`,
97
- ...rest.map((line) => ` ${line}`),
98
- ...fix ? wrap(fix, WIDTH - 4).map((line) => ` ${s.dim(line)}`) : []
99
- ];
100
- }
101
- function shortVersion(versionId) {
102
- return versionId.slice(0, 8);
103
- }
104
-
105
- // src/cli/errors.ts
106
- var USAGE_CODES = new Set([
107
- "usage",
108
- "unknown_command",
109
- "unknown_flag",
110
- "interactive_login_required"
111
- ]);
112
- var AUTH_CODES = new Set([
113
- "not_signed_in",
114
- "unauthorized",
115
- "token_rejected",
116
- "no_token",
117
- "login_denied"
118
- ]);
119
- var RETRY_CODES = new Set([
120
- "rate_limited",
121
- "server_error",
122
- "network",
123
- "authorization_pending",
124
- "login_timeout"
125
- ]);
126
- function exitCodeFor(code) {
127
- if (USAGE_CODES.has(code))
128
- return 2;
129
- if (AUTH_CODES.has(code))
130
- return 3;
131
- if (RETRY_CODES.has(code))
132
- return 4;
133
- return 1;
134
- }
135
- function errorEnvelope(err) {
136
- return {
137
- ok: false,
138
- code: err.code,
139
- error: err.error,
140
- ...err.fix ? { fix: err.fix } : {},
141
- ...err.status !== undefined ? { status: err.status } : {},
142
- ...err.extra ?? {}
143
- };
144
- }
145
- function emitError(err, args, io, _opts = {}) {
146
- if (args.json) {
147
- io.out(JSON.stringify(errorEnvelope(err)));
148
- } else {
149
- for (const line of failure(err.error, err.fix, io.style ?? PLAIN))
150
- io.err(line);
151
- }
152
- return exitCodeFor(err.code);
153
- }
154
- function fail(code, error, args, io, opts = {}) {
155
- return emitError({ code, error, fix: opts.fix, status: opts.status, extra: opts.extra }, args, io, { prefix: opts.prefix });
156
- }
157
- async function readServerMessage(res) {
158
- const text = await res.text().catch(() => "");
159
- if (!text)
160
- return { message: `HTTP ${res.status}` };
161
- try {
162
- const body = JSON.parse(text);
163
- const message = typeof body.error === "string" ? body.error : typeof body.message === "string" ? body.message : text;
164
- return { message, code: typeof body.code === "string" ? body.code : undefined, json: true };
165
- } catch {
166
- return { message: text.length > 200 ? `${text.slice(0, 200)}…` : text };
167
- }
168
- }
169
- async function classifyResponse(res, ctx) {
170
- const { message, code: serverCode, json } = await readServerMessage(res);
171
- const status = res.status;
172
- const site = ctx.siteId ? ` ${ctx.siteId}` : "";
173
- const base = { status, error: message };
174
- if (serverCode === "token_rejected") {
175
- return {
176
- ...base,
177
- code: "token_rejected",
178
- error: "The credential you sent was not accepted, so nothing was deployed.",
179
- fix: "Run `flypod login` again, or set a valid FLYPOD_TOKEN (unset it to deploy anonymously)."
180
- };
181
- }
182
- if (serverCode === "challenge_required" || /challenge required/i.test(message)) {
183
- return {
184
- ...base,
185
- code: "challenge_required",
186
- error: "The server wants a human challenge for this deploy.",
187
- fix: "Run `flypod login` and deploy again: signed-in deploys skip the challenge."
188
- };
189
- }
190
- switch (status) {
191
- case 401:
192
- case 403:
193
- if (!json && message !== `HTTP ${status}`) {
194
- return {
195
- ...base,
196
- code: "network",
197
- error: `Something between this machine and the server refused the request (HTTP ${status}): ${message}`,
198
- fix: "Check the proxy or firewall settings (and DEPLOY_URL, if set), then retry."
199
- };
200
- }
201
- if (serverCode === "blocked") {
202
- return {
203
- ...base,
204
- code: "blocked",
205
- error: `Deploy refused: ${message}`,
206
- fix: "The content tripped the abuse guard. Remove the flagged files and try again."
207
- };
208
- }
209
- return {
210
- ...base,
211
- code: "unauthorized",
212
- error: `Not authorized for site${site}.`,
213
- fix: "Run `flypod login`, or pass --token <manage_token> for a site this machine does not remember."
214
- };
215
- case 404:
216
- return ctx.siteScoped ? {
217
- ...base,
218
- code: "site_gone",
219
- error: `Site${site} is gone (expired or deleted).`,
220
- fix: "Run `flypod` to create a new site."
221
- } : { ...base, code: "not_found", error: message };
222
- case 409:
223
- return {
224
- ...base,
225
- code: "already_claimed",
226
- error: `Site${site} already belongs to another account.`
227
- };
228
- case 400:
229
- return { ...base, code: "invalid_upload", error: `Rejected: ${message}` };
230
- case 413:
231
- return {
232
- ...base,
233
- code: "too_large",
234
- error: /^upload too large\.?$/i.test(message) ? "The upload is larger than the server accepts." : `The server refused the upload: ${message}.`,
235
- fix: "Shrink the build (fewer files, smaller assets) or split it. See flypod.dev/limits."
236
- };
237
- case 429:
238
- return {
239
- ...base,
240
- code: "rate_limited",
241
- error: "Too many requests from this network right now.",
242
- fix: "Wait a minute and retry the same command.",
243
- extra: retryAfter(res)
244
- };
245
- default:
246
- if (status >= 500) {
247
- return {
248
- ...base,
249
- code: "server_error",
250
- error: `${ctx.verb}: the server returned ${status}.`,
251
- fix: "Retry in a moment; if it keeps failing, check https://flypod.dev/status."
252
- };
253
- }
254
- return { ...base, code: "bad_request", error: `${ctx.verb}: ${message}` };
255
- }
256
- }
257
- function retryAfter(res) {
258
- const raw = res.headers.get("retry-after");
259
- const seconds = raw ? Number(raw) : Number.NaN;
260
- return Number.isFinite(seconds) ? { retry_after_s: seconds } : {};
261
- }
262
- function noBuildDir(message) {
263
- const cut = message.indexOf(". ");
264
- if (cut === -1)
265
- return { code: "no_build_dir", error: message };
266
- return { code: "no_build_dir", error: message.slice(0, cut + 1), fix: message.slice(cut + 2) };
267
- }
268
- function networkError(e, baseUrl) {
269
- const reason = e instanceof Error ? e.message : String(e);
270
- const host = baseUrl ? ` ${safeHost(baseUrl)}` : "";
271
- return {
272
- code: "network",
273
- error: `Could not reach the flypod server${host}: ${reason}`,
274
- fix: "Check your connection (and DEPLOY_URL, if set), then retry."
275
- };
276
- }
277
- function safeHost(url) {
278
- try {
279
- return new URL(url).host;
280
- } catch {
281
- return url;
282
- }
283
- }
284
- var NO_SITE = {
285
- code: "no_site",
286
- error: "No flypod site is linked to this folder.",
287
- fix: "Run `flypod` here to create one, or pass --site <id>."
288
- };
289
- var NOT_SIGNED_IN = {
290
- code: "not_signed_in",
291
- error: "Not signed in.",
292
- fix: "Run `flypod login`, or set FLYPOD_TOKEN."
293
- };
294
- function unexpectedError(e) {
295
- const reason = e instanceof Error ? e.message : String(e);
296
- return { code: "unexpected", error: `unexpected error: ${reason}` };
297
- }
49
+ // src/cli/limits.ts
50
+ import { readdir } from "node:fs/promises";
51
+ import { basename, dirname, resolve } from "node:path";
298
52
 
299
53
  // src/ui.ts
300
54
  var ESC = "\x1B[";
@@ -315,8 +69,8 @@ function paint(open, s) {
315
69
  }
316
70
  function makeStyle(enabled) {
317
71
  if (!enabled) {
318
- const id2 = (s) => s;
319
- return { dim: id2, bold: id2, accent: id2, ok: id2, err: id2, warn: id2, muted: id2 };
72
+ const id = (s) => s;
73
+ return { dim: id, bold: id, accent: id, ok: id, err: id, warn: id, muted: id };
320
74
  }
321
75
  return {
322
76
  dim: (s) => paint("2", s),
@@ -402,18 +156,217 @@ function fmtCount(n, singular) {
402
156
  return `${n} ${singular}${n === 1 ? "" : "s"}`;
403
157
  }
404
158
 
159
+ // src/upload-shape.ts
160
+ var BYTE_KINDS = [
161
+ "html",
162
+ "script",
163
+ "style",
164
+ "image",
165
+ "media",
166
+ "font",
167
+ "source_map",
168
+ "data",
169
+ "archive",
170
+ "other"
171
+ ];
172
+ var EXT_KIND = {
173
+ html: "html",
174
+ htm: "html",
175
+ md: "html",
176
+ markdown: "html",
177
+ js: "script",
178
+ mjs: "script",
179
+ cjs: "script",
180
+ ts: "script",
181
+ tsx: "script",
182
+ jsx: "script",
183
+ wasm: "script",
184
+ css: "style",
185
+ scss: "style",
186
+ less: "style",
187
+ png: "image",
188
+ jpg: "image",
189
+ jpeg: "image",
190
+ gif: "image",
191
+ webp: "image",
192
+ avif: "image",
193
+ svg: "image",
194
+ ico: "image",
195
+ bmp: "image",
196
+ tif: "image",
197
+ tiff: "image",
198
+ heic: "image",
199
+ psd: "image",
200
+ mp4: "media",
201
+ webm: "media",
202
+ mov: "media",
203
+ m4v: "media",
204
+ avi: "media",
205
+ mkv: "media",
206
+ mp3: "media",
207
+ wav: "media",
208
+ ogg: "media",
209
+ m4a: "media",
210
+ flac: "media",
211
+ aac: "media",
212
+ woff: "font",
213
+ woff2: "font",
214
+ ttf: "font",
215
+ otf: "font",
216
+ eot: "font",
217
+ map: "source_map",
218
+ json: "data",
219
+ csv: "data",
220
+ xml: "data",
221
+ txt: "data",
222
+ pdf: "data",
223
+ yaml: "data",
224
+ yml: "data",
225
+ glb: "data",
226
+ gltf: "data",
227
+ zip: "archive",
228
+ gz: "archive",
229
+ tgz: "archive",
230
+ tar: "archive",
231
+ rar: "archive",
232
+ "7z": "archive"
233
+ };
234
+ function kindOf(path) {
235
+ const base = path.split("/").pop() ?? path;
236
+ const dot = base.lastIndexOf(".");
237
+ if (dot <= 0)
238
+ return "other";
239
+ return EXT_KIND[base.slice(dot + 1).toLowerCase()] ?? "other";
240
+ }
241
+ var kb = (bytes) => Math.round(bytes / 1024);
242
+ function uploadShape(files) {
243
+ const bytesByKind = new Map;
244
+ let total = 0;
245
+ let largest = { kind: null, bytes: -1 };
246
+ for (const [name, data] of Object.entries(files)) {
247
+ const kind = kindOf(name);
248
+ const n = data?.byteLength ?? 0;
249
+ total += n;
250
+ bytesByKind.set(kind, (bytesByKind.get(kind) ?? 0) + n);
251
+ if (n > largest.bytes)
252
+ largest = { kind, bytes: n };
253
+ }
254
+ const kb_by_kind = {};
255
+ let topKind = null;
256
+ let topBytes = -1;
257
+ for (const [kind, bytes] of bytesByKind) {
258
+ kb_by_kind[kind] = kb(bytes);
259
+ if (bytes > topBytes) {
260
+ topKind = kind;
261
+ topBytes = bytes;
262
+ }
263
+ }
264
+ return {
265
+ file_count: Object.keys(files).length,
266
+ total_kb: kb(total),
267
+ kb_by_kind,
268
+ largest_kind: topKind,
269
+ largest_file_kind: largest.kind,
270
+ largest_file_kb: Math.max(0, kb(largest.bytes))
271
+ };
272
+ }
273
+ var BUILD_DIRS = [
274
+ "dist",
275
+ "build",
276
+ "out",
277
+ "public",
278
+ "_site",
279
+ ".output",
280
+ ".next",
281
+ "www"
282
+ ];
283
+ function folderMarkers(paths) {
284
+ const top = new Set;
285
+ const topDirs = new Set;
286
+ for (const p of paths) {
287
+ const slash = p.indexOf("/");
288
+ if (slash === -1)
289
+ top.add(p);
290
+ else
291
+ topDirs.add(p.slice(0, slash));
292
+ }
293
+ const has_package_json = top.has("package.json");
294
+ const has_index_html = top.has("index.html") || top.has("index.htm");
295
+ const has_src_dir = topDirs.has("src");
296
+ const build_dirs = BUILD_DIRS.filter((d) => topDirs.has(d));
297
+ return {
298
+ has_package_json,
299
+ has_index_html,
300
+ has_src_dir,
301
+ build_dirs,
302
+ looks_like_project_root: has_package_json && !has_index_html
303
+ };
304
+ }
305
+ function shapeProps(shape, markers) {
306
+ const out = {
307
+ file_count: shape.file_count,
308
+ total_kb: shape.total_kb,
309
+ largest_kind: shape.largest_kind,
310
+ largest_file_kind: shape.largest_file_kind,
311
+ largest_file_kb: shape.largest_file_kb
312
+ };
313
+ for (const kind of BYTE_KINDS) {
314
+ const v = shape.kb_by_kind[kind];
315
+ if (v !== undefined)
316
+ out[`kb_${kind}`] = v;
317
+ }
318
+ if (markers) {
319
+ out.looks_like_project_root = markers.looks_like_project_root;
320
+ out.has_package_json = markers.has_package_json;
321
+ out.has_src_dir = markers.has_src_dir;
322
+ if (markers.build_dirs.length)
323
+ out.build_dirs = markers.build_dirs.join(",");
324
+ }
325
+ return out;
326
+ }
327
+ var fmtKb = (n) => n >= 1024 ? `${(n / 1024).toFixed(1)} MB` : `${n} KB`;
328
+ function sizeAdvice(shape, markers) {
329
+ if (markers?.looks_like_project_root) {
330
+ const dir = markers.build_dirs.find((d) => d !== "public") ?? markers.build_dirs[0];
331
+ return dir ? `This looks like the project folder, not its build output. Deploy the built files instead: \`flypod ./${dir}\`.` : "This looks like the project folder (it has a package.json and no index.html). Build the site, then deploy the output folder, e.g. `flypod ./dist`.";
332
+ }
333
+ const share = (k) => shape.total_kb > 0 ? (shape.kb_by_kind[k] ?? 0) / shape.total_kb : 0;
334
+ if (share("source_map") >= 0.2) {
335
+ return `${fmtKb(shape.kb_by_kind.source_map ?? 0)} of this is source maps, which a browser never needs to show the site. Add \`*.map\` to a .flypodignore and deploy again.`;
336
+ }
337
+ if (share("media") >= 0.3) {
338
+ return `${fmtKb(shape.kb_by_kind.media ?? 0)} of this is video or audio. Host large media elsewhere (a video platform or object storage) and link to it.`;
339
+ }
340
+ if (share("archive") >= 0.3) {
341
+ return `${fmtKb(shape.kb_by_kind.archive ?? 0)} of this is archives (.zip, .tar, …). Leave them out with a .flypodignore unless the site is meant to offer them as downloads.`;
342
+ }
343
+ if (share("image") >= 0.5) {
344
+ return `${fmtKb(shape.kb_by_kind.image ?? 0)} of this is images. Compress them (WebP or AVIF usually cuts size by more than half) or leave unused ones out with a .flypodignore.`;
345
+ }
346
+ return null;
347
+ }
348
+
405
349
  // src/cli/limits.ts
406
- function checkUploadSize(files, limits) {
350
+ function uploadReport(files, skippedCount) {
351
+ return {
352
+ ...shapeProps(uploadShape(files), folderMarkers(Object.keys(files))),
353
+ upload_kb: Math.round(storedZipBytes(files) / 1024),
354
+ ...skippedCount !== undefined ? { skipped_count: skippedCount } : {}
355
+ };
356
+ }
357
+ function checkUploadSize(files, limits, skippedCount) {
407
358
  if (!limits)
408
359
  return null;
409
360
  const names = Object.keys(files);
410
- const fix = "Remove or shrink the largest files (or list them in a .flypodignore), then deploy again.";
361
+ const advice = () => sizeAdvice(uploadShape(files), folderMarkers(names));
362
+ const report = (limit2) => ({ limit: limit2, ...uploadReport(files, skippedCount) });
411
363
  if (names.length > limits.maxFiles) {
412
364
  return {
413
365
  code: "too_large",
414
366
  error: `This build has ${names.length} files; flypod accepts at most ${limits.maxFiles} per deploy.`,
415
- fix: "Deploy only the build output, or list what the site does not need in a .flypodignore.",
416
- extra: { files: names.length, limit_files: limits.maxFiles }
367
+ fix: advice() ?? "Deploy only the build output, or list what the site does not need in a .flypodignore.",
368
+ extra: { limit: "files", files: names.length, limit_files: limits.maxFiles },
369
+ telemetry: report("files")
417
370
  };
418
371
  }
419
372
  const total = names.reduce((sum, n) => sum + (files[n]?.byteLength ?? 0), 0);
@@ -426,17 +379,52 @@ function checkUploadSize(files, limits) {
426
379
  const listed = largest.map((f) => `${f.path} (${fmtBytes(f.bytes)})`).join(", ");
427
380
  const limit = overZip ? limits.maxZipBytes : limits.maxTotalBytes;
428
381
  const what = overZip ? "upload" : "site";
382
+ const which = overZip ? "zip_bytes" : "total_bytes";
429
383
  return {
430
384
  code: "too_large",
431
385
  error: `This build is ${fmtBytes(overZip ? zipped : total)}; flypod accepts at most ${fmtBytes(limit)} per ${what}. Largest files: ${listed}.`,
432
- fix,
386
+ fix: advice() ?? "Remove or shrink the largest files (or list them in a .flypodignore), then deploy again.",
433
387
  extra: {
388
+ limit: which,
434
389
  bytes: total,
435
390
  upload_bytes: zipped,
436
391
  limit_bytes: limit,
437
392
  largest
438
- }
393
+ },
394
+ telemetry: report(which)
395
+ };
396
+ }
397
+ function buildDirIn(markers, exclude) {
398
+ const dir = markers.build_dirs.find((d) => d !== "public" && d !== ".next" && d !== exclude && BUILD_DIRS.includes(d));
399
+ if (!dir)
400
+ return null;
401
+ return dir === ".output" ? ".output/public" : dir;
402
+ }
403
+ async function markersOf(dir) {
404
+ try {
405
+ const entries = await readdir(dir, { withFileTypes: true });
406
+ return folderMarkers(entries.map((e) => e.isDirectory() ? `${e.name}/` : e.name));
407
+ } catch {
408
+ return null;
409
+ }
410
+ }
411
+ async function withFolderHint(err, cwd, deployed) {
412
+ const markers = await markersOf(cwd);
413
+ if (!markers)
414
+ return err;
415
+ const exclude = deployed && resolve(dirname(resolve(cwd, deployed))) === resolve(cwd) ? basename(resolve(cwd, deployed)) : undefined;
416
+ const telemetry = {
417
+ ...err.telemetry,
418
+ looks_like_project_root: markers.looks_like_project_root,
419
+ has_package_json: markers.has_package_json,
420
+ has_src_dir: markers.has_src_dir,
421
+ ...markers.build_dirs.length ? { build_dirs: markers.build_dirs.join(",") } : {}
439
422
  };
423
+ if (!markers.looks_like_project_root)
424
+ return { ...err, telemetry };
425
+ const dir = buildDirIn(markers, exclude);
426
+ const fix = dir ? `This looks like the project folder; its build output is in ${dir}. Deploy that: \`flypod ./${dir}\`.` : "This looks like the project folder, and it has no build output yet. Build the site (e.g. `npm run build`), then deploy the output folder.";
427
+ return { ...err, fix, telemetry };
440
428
  }
441
429
 
442
430
  // src/cli/projects.ts
@@ -1169,10 +1157,12 @@ function clientForTarget(target, args, io) {
1169
1157
  }
1170
1158
  });
1171
1159
  }
1172
- async function failSiteRequest(verb, res, target, args, io, env) {
1160
+ async function failSiteRequest(verb, res, target, args, io, env, upload) {
1173
1161
  if (res.status === 404 && target.dir)
1174
1162
  await forgetDir(target.dir, env);
1175
1163
  const err = await classifyResponse(res, { verb, siteId: target.site_id, siteScoped: true });
1164
+ if (err.code === "too_large" && upload)
1165
+ err.telemetry = { ...err.telemetry, ...upload() };
1176
1166
  return emitError(err, args, io, { prefix: verb });
1177
1167
  }
1178
1168
  async function fetchSite(verb, target, args, io, env) {
@@ -1202,7 +1192,7 @@ async function update(args, io) {
1202
1192
  try {
1203
1193
  dir = await resolveDeployDir({ cwd, explicit: args.path });
1204
1194
  } catch (e) {
1205
- return emitError(noBuildDir(e.message), args, io);
1195
+ return emitError(await withFolderHint(noBuildDir(e.message), cwd), args, io);
1206
1196
  }
1207
1197
  let files;
1208
1198
  let skipped;
@@ -1212,12 +1202,16 @@ async function update(args, io) {
1212
1202
  return fail("no_files", `Could not read ${dir}: ${e.message}`, args, io);
1213
1203
  }
1214
1204
  if (Object.keys(files).length === 0) {
1215
- return fail("no_files", `No files to deploy in ${dir}.`, args, io, {
1216
- fix: "Build the site first, then deploy the output folder."
1217
- });
1205
+ const empty = await withFolderHint({
1206
+ code: "no_files",
1207
+ error: `No files to deploy in ${dir}.`,
1208
+ fix: "Build the site first, then deploy the output folder.",
1209
+ telemetry: { file_count: 0, skipped_count: skipped.length }
1210
+ }, cwd, dir);
1211
+ return emitError(empty, args, io);
1218
1212
  }
1219
1213
  const client = await clientForTarget(target, args, io);
1220
- const tooLarge = checkUploadSize(files, uploadLimitsFor(client.baseUrl));
1214
+ const tooLarge = checkUploadSize(files, uploadLimitsFor(client.baseUrl), skipped.length);
1221
1215
  if (tooLarge)
1222
1216
  return emitError(tooLarge, args, io, { prefix: "flypod update" });
1223
1217
  let res;
@@ -1226,8 +1220,9 @@ async function update(args, io) {
1226
1220
  } catch (e) {
1227
1221
  return emitError(networkError(e, client.baseUrl), args, io, { prefix: "flypod update" });
1228
1222
  }
1229
- if (!res.ok)
1230
- return failSiteRequest("flypod update", res, target, args, io, env);
1223
+ if (!res.ok) {
1224
+ return failSiteRequest("flypod update", res, target, args, io, env, () => uploadReport(files, skipped.length));
1225
+ }
1231
1226
  const body = await res.json();
1232
1227
  await touchLink(target, body.version_id, env);
1233
1228
  const switched = args.timeline === undefined ? undefined : await switchTimeline(client, target.site_id, args.timeline);
@@ -1639,7 +1634,7 @@ function requireCommentWriteToken(verb, token2, args, io) {
1639
1634
  if (!token2)
1640
1635
  return emitError(NOT_SIGNED_IN, args, io, { prefix });
1641
1636
  if (token2.startsWith("fk_")) {
1642
- return fail("unauthorized", "Comments operations require an account session or agent token; a deploy key (fk_) only authorizes deploys.", args, io, { prefix, fix: "Run `flypod login`, or set FLYPOD_TOKEN to a session token." });
1637
+ return fail("unauthorized", "Comments operations require an account session; an fk_ token (a site's manage token or a retired API key) cannot write comments.", args, io, { prefix, fix: "Run `flypod login`, or set FLYPOD_TOKEN to a session token." });
1643
1638
  }
1644
1639
  return null;
1645
1640
  }
@@ -1943,7 +1938,7 @@ function multiselect(opts) {
1943
1938
  const output = opts.output ?? process.stderr;
1944
1939
  const { style } = opts;
1945
1940
  const choices = opts.choices.map((c) => ({ ...c }));
1946
- return new Promise((resolve) => {
1941
+ return new Promise((resolve2) => {
1947
1942
  let index = 0;
1948
1943
  let printed = 0;
1949
1944
  const footer = style.dim("↑/↓ move · space toggle · a all · enter confirm · esc cancel");
@@ -1984,7 +1979,7 @@ function multiselect(opts) {
1984
1979
  };
1985
1980
  const finish = (value) => {
1986
1981
  cleanup();
1987
- resolve(value);
1982
+ resolve2(value);
1988
1983
  };
1989
1984
  const onData = (buf) => {
1990
1985
  const key = buf.toString("utf8");
@@ -2030,6 +2025,17 @@ function multiselect(opts) {
2030
2025
  });
2031
2026
  }
2032
2027
 
2028
+ // src/ingest-error.ts
2029
+ var KB = 1024;
2030
+ var MB = 1024 * 1024;
2031
+ function formatBytes(n) {
2032
+ if (n >= MB)
2033
+ return `${Number((n / MB).toFixed(1))} MB`;
2034
+ if (n >= KB)
2035
+ return `${Math.ceil(n / KB)} KB`;
2036
+ return `${n} bytes`;
2037
+ }
2038
+
2033
2039
  // bin/deploy.ts
2034
2040
  var SUBCOMMANDS = new Set([
2035
2041
  "deploy",
@@ -2103,7 +2109,8 @@ var TOP_LEVEL_FLAG_SPEC = {
2103
2109
  };
2104
2110
  var COMMENT_MODES = ["anonymous", "passcode", "approved", "open", "review", "members"];
2105
2111
  function exitUsage(err, argv) {
2106
- if (argv.includes("--json")) {
2112
+ const json = argv.includes("--json");
2113
+ if (json) {
2107
2114
  process.stdout.write(`${JSON.stringify(errorEnvelope(err))}
2108
2115
  `);
2109
2116
  } else {
@@ -2112,7 +2119,16 @@ function exitUsage(err, argv) {
2112
2119
  `)}
2113
2120
  `);
2114
2121
  }
2115
- process.exit(exitCodeFor(err.code));
2122
+ reportFailure(err, { json });
2123
+ throw new CliExit(exitCodeFor(err.code));
2124
+ }
2125
+
2126
+ class CliExit extends Error {
2127
+ exitCode;
2128
+ constructor(exitCode) {
2129
+ super(`exit ${exitCode}`);
2130
+ this.exitCode = exitCode;
2131
+ }
2116
2132
  }
2117
2133
  function rejectFlagProblems(parsed, spec, argv, helpCmd) {
2118
2134
  const problem = flagProblem(parsed, spec, helpCmd);
@@ -2259,12 +2275,7 @@ async function runSubcommand(name, argv) {
2259
2275
  }
2260
2276
  }
2261
2277
  function emitCliError(err, json, io) {
2262
- if (json)
2263
- io.out(JSON.stringify(errorEnvelope(err)));
2264
- else
2265
- for (const line of failure(err.error, err.fix, io.style ?? PLAIN))
2266
- io.err(line);
2267
- return exitCodeFor(err.code);
2278
+ return emitError(err, { json }, io);
2268
2279
  }
2269
2280
  function shortHome(path) {
2270
2281
  const home = homedir();
@@ -2287,16 +2298,16 @@ async function runInstall(argv, io) {
2287
2298
  }
2288
2299
  rejectFlagProblems(parsed, INSTALL_FLAG_SPEC, argv, "flypod install --help");
2289
2300
  const targets = [];
2290
- for (const [flag, id2] of Object.entries(TARGET_FLAGS)) {
2291
- if (flags[flag] && !targets.includes(id2))
2292
- targets.push(id2);
2301
+ for (const [flag, id] of Object.entries(TARGET_FLAGS)) {
2302
+ if (flags[flag] && !targets.includes(id))
2303
+ targets.push(id);
2293
2304
  }
2294
2305
  const all = Boolean(flags["--all"]);
2295
2306
  const global = Boolean(flags["--global"]);
2296
2307
  const list2 = Boolean(flags["--list"]);
2297
2308
  const dryRun = Boolean(flags["--dry-run"] || flags["--print"]);
2298
2309
  const yes = Boolean(flags["--yes"] || flags["-y"]);
2299
- const interactive = !list2 && !dryRun && !all && !yes && targets.length === 0 && canPrompt(process.stdin);
2310
+ const interactive = !json && !list2 && !dryRun && !all && !yes && targets.length === 0 && canPrompt(process.stdin);
2300
2311
  const picker = interactive ? async (plan) => {
2301
2312
  const style = makeStyle(colorsEnabled(process.stderr));
2302
2313
  process.stderr.write(`
@@ -2316,7 +2327,7 @@ async function runInstall(argv, io) {
2316
2327
  err: (line) => io.err(shortHome(line)),
2317
2328
  env: io.env
2318
2329
  };
2319
- return installSkill({ targets, all: all || yes, global, list: list2, dryRun, picker }, io2);
2330
+ return installSkill({ targets, all: all || yes, global, list: list2, dryRun, picker, json }, io2);
2320
2331
  }
2321
2332
  async function readVersion() {
2322
2333
  const here = fileURLToPath(import.meta.url);
@@ -2456,6 +2467,8 @@ Environment:
2456
2467
  FLYPOD_SHOW_TOKEN Set to 1 to print the manage token inline on deploy
2457
2468
  NO_COLOR Disable ANSI colors
2458
2469
  FORCE_COLOR Force ANSI colors even when stderr is not a TTY
2470
+ DO_NOT_TRACK Set to 1 to stop the random install id and failure
2471
+ reports (FLYPOD_TELEMETRY=0 does the same)
2459
2472
 
2460
2473
  When no path is given, flypod looks for a build folder in the current directory:
2461
2474
  dist, build, out, .output/public, .vercel/output/static, public, _site
@@ -2465,8 +2478,9 @@ What is uploaded:
2465
2478
  Everything in the folder except .git, .hg, .svn, node_modules, .DS_Store,
2466
2479
  Thumbs.db, .env and .env.* — at any depth. Add gitignore-style patterns to
2467
2480
  a .flypodignore in the folder to leave out more. What was left out is
2468
- listed after the deploy ("skipped" in --json). A deploy may be at most
2469
- 100 MB of files and 50 MB as an upload; flypod checks before uploading.
2481
+ listed after the deploy ("skipped" in --json). On flypod.dev a deploy may be
2482
+ at most ${HOSTED_UPLOAD_LIMITS.maxFiles} files, ${formatBytes(HOSTED_UPLOAD_LIMITS.maxTotalBytes)} of files and ${formatBytes(HOSTED_UPLOAD_LIMITS.maxZipBytes)} as an upload; flypod checks
2483
+ before uploading.
2470
2484
 
2471
2485
  Docs: https://flypod.dev
2472
2486
  `;
@@ -2497,7 +2511,19 @@ function fail2(err, args, style) {
2497
2511
 
2498
2512
  `);
2499
2513
  }
2500
- process.exit(exitCodeFor(err.code));
2514
+ reportFailure(err, args);
2515
+ throw new CliExit(exitCodeFor(err.code));
2516
+ }
2517
+ async function firstRunNotice(argv) {
2518
+ const install = await installId(process.env);
2519
+ if (!install?.isNew || !process.stderr.isTTY)
2520
+ return;
2521
+ if (argv.some((a) => a === "--json" || a === "-q" || a === "--quiet"))
2522
+ return;
2523
+ const style = makeStyle(colorsEnabled(process.stderr));
2524
+ process.stderr.write(` ${style.dim(FIRST_RUN_NOTICE)}
2525
+
2526
+ `);
2501
2527
  }
2502
2528
  async function main() {
2503
2529
  const rawArgv = process.argv.slice(2);
@@ -2505,8 +2531,18 @@ async function main() {
2505
2531
  const at = firstPositionalIndex(rawArgv, ANY_VALUE_FLAG);
2506
2532
  const firstPositional = at === -1 ? undefined : rawArgv[at];
2507
2533
  const withoutVerb = at === -1 ? rawArgv : [...rawArgv.slice(0, at), ...rawArgv.slice(at + 1)];
2508
- if (firstPositional && SUBCOMMANDS.has(firstPositional) && firstPositional !== "deploy") {
2534
+ const isSubcommand = Boolean(firstPositional && SUBCOMMANDS.has(firstPositional) && firstPositional !== "deploy");
2535
+ const answersLocally = rawArgv.some((a) => ["-h", "--help", "-v", "--version"].includes(a));
2536
+ setCliVersion(version);
2537
+ startFailureReports({
2538
+ verb: isSubcommand ? firstPositional : "deploy",
2539
+ help: answersLocally
2540
+ });
2541
+ if (!answersLocally)
2542
+ await firstRunNotice(rawArgv);
2543
+ if (isSubcommand) {
2509
2544
  const code = await runSubcommand(firstPositional, withoutVerb);
2545
+ await flushFailureReports();
2510
2546
  process.exit(code);
2511
2547
  }
2512
2548
  const args = parseArgs(firstPositional === "deploy" ? withoutVerb : rawArgv);
@@ -2530,17 +2566,17 @@ async function main() {
2530
2566
  code: "unknown_command",
2531
2567
  error: `unknown command "${args.path}" — did you mean \`flypod ${verb}\`?`,
2532
2568
  fix: `flypod ${verb}`
2533
- } : {
2569
+ } : await withFolderHint({
2534
2570
  code: "no_build_dir",
2535
2571
  error: `Nothing to deploy at ${args.path}: no such file or folder.`,
2536
2572
  fix: "Pass the folder of built files, e.g. `flypod ./dist`, or build the site first."
2537
- }, args, style);
2573
+ }, process.cwd()), args, style);
2538
2574
  }
2539
2575
  let dir;
2540
2576
  try {
2541
2577
  dir = await resolveDeployDir({ explicit: args.path });
2542
2578
  } catch (error) {
2543
- fail2(noBuildDir(error.message), args, style);
2579
+ fail2(await withFolderHint(noBuildDir(error.message), process.cwd()), args, style);
2544
2580
  }
2545
2581
  let files;
2546
2582
  let skipped;
@@ -2556,13 +2592,14 @@ async function main() {
2556
2592
  const fileNames = Object.keys(files);
2557
2593
  const totalBytes = fileNames.reduce((sum, name) => sum + (files[name]?.byteLength ?? 0), 0);
2558
2594
  if (fileNames.length === 0) {
2559
- fail2({
2595
+ fail2(await withFolderHint({
2560
2596
  code: "no_files",
2561
2597
  error: `No files found in ${shortDir(dir)}.`,
2562
- fix: "Build the site first, then deploy the output folder."
2563
- }, args, style);
2598
+ fix: "Build the site first, then deploy the output folder.",
2599
+ telemetry: { file_count: 0, skipped_count: skipped.length }
2600
+ }, process.cwd(), dir), args, style);
2564
2601
  }
2565
- const tooLarge = checkUploadSize(files, uploadLimitsFor(baseUrl));
2602
+ const tooLarge = checkUploadSize(files, uploadLimitsFor(baseUrl), skipped.length);
2566
2603
  if (tooLarge)
2567
2604
  fail2(tooLarge, args, style);
2568
2605
  const priorLink = await projectForDir(process.cwd()).catch(() => null);
@@ -2582,10 +2619,16 @@ async function main() {
2582
2619
  const started = Date.now();
2583
2620
  let result;
2584
2621
  try {
2585
- result = await deploySite({ baseUrl, files, apiKey, source: client.source });
2622
+ const res = await client.createSite(packDeploy(files), { relink: Boolean(priorLink) });
2623
+ if (!res.ok)
2624
+ throw await DeployError.fromResponse(res);
2625
+ result = await res.json();
2586
2626
  } catch (error) {
2587
2627
  spinner.stop();
2588
2628
  const err = error instanceof DeployError ? await classifyResponse(error.toResponse(), { verb: "flypod" }) : networkError(error, baseUrl);
2629
+ if (err.code === "too_large") {
2630
+ err.telemetry = { ...err.telemetry, ...uploadReport(files, skipped.length) };
2631
+ }
2589
2632
  fail2(err, args, style);
2590
2633
  }
2591
2634
  const elapsed = Date.now() - started;
@@ -2729,9 +2772,14 @@ async function main() {
2729
2772
  process.stdout.write(`${result.url}
2730
2773
  `);
2731
2774
  }
2732
- main().catch((error) => {
2775
+ main().catch(async (error) => {
2776
+ if (error instanceof CliExit) {
2777
+ await flushFailureReports();
2778
+ process.exit(error.exitCode);
2779
+ }
2733
2780
  const err = unexpectedError(error);
2734
- if (process.argv.includes("--json")) {
2781
+ const json = process.argv.includes("--json");
2782
+ if (json) {
2735
2783
  process.stdout.write(`${JSON.stringify(errorEnvelope(err))}
2736
2784
  `);
2737
2785
  } else {
@@ -2739,5 +2787,7 @@ main().catch((error) => {
2739
2787
  `)}
2740
2788
  `);
2741
2789
  }
2790
+ reportFailure(err, { json });
2791
+ await flushFailureReports();
2742
2792
  process.exit(exitCodeFor(err.code));
2743
2793
  });