flypod 0.17.0 → 0.18.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.
- package/README.md +39 -13
- package/dist/bin/deploy.js +542 -98
- package/dist/{cli-z3p9tds1.js → cli-4d5fkx95.js} +291 -37
- package/dist/src/api-error.d.ts +4 -0
- package/dist/src/cli/agent-env.d.ts +5 -0
- package/dist/src/cli/build-hint.d.ts +13 -0
- package/dist/src/cli/commands.d.ts +4 -0
- package/dist/src/cli/errors.d.ts +81 -2
- package/dist/src/cli/install-id.d.ts +7 -3
- package/dist/src/cli/limits.d.ts +30 -8
- package/dist/src/cli/projects.d.ts +51 -3
- package/dist/src/cli/receipt.d.ts +18 -0
- package/dist/src/cli/skill.d.ts +18 -4
- package/dist/src/cli/source.d.ts +3 -1
- package/dist/src/cli-error-codes.d.ts +20 -0
- package/dist/src/cli.d.ts +15 -3
- package/dist/src/cli.js +1 -1
- package/dist/src/client-meta.d.ts +50 -0
- package/dist/src/ingest-error.d.ts +18 -1
- package/dist/src/upload-shape.d.ts +5 -0
- package/package.json +1 -1
package/dist/bin/deploy.js
CHANGED
|
@@ -4,9 +4,11 @@ import {
|
|
|
4
4
|
DeployError,
|
|
5
5
|
FIRST_RUN_NOTICE,
|
|
6
6
|
HOSTED_UPLOAD_LIMITS,
|
|
7
|
+
IGNORE_FILE,
|
|
7
8
|
NOT_SIGNED_IN,
|
|
8
9
|
NO_SITE,
|
|
9
10
|
PLAIN,
|
|
11
|
+
UNAUTHORIZED_FIX,
|
|
10
12
|
atomicWriteFile,
|
|
11
13
|
classifyResponse,
|
|
12
14
|
clearSession,
|
|
@@ -23,32 +25,41 @@ import {
|
|
|
23
25
|
hero,
|
|
24
26
|
installId,
|
|
25
27
|
installSkill,
|
|
28
|
+
loadSession,
|
|
26
29
|
networkError,
|
|
27
30
|
noBuildDir,
|
|
31
|
+
noSite,
|
|
28
32
|
notice,
|
|
29
33
|
packDeploy,
|
|
30
34
|
projectsFilePath,
|
|
35
|
+
readServerMessage,
|
|
31
36
|
reportFailure,
|
|
32
37
|
resolveCredentials,
|
|
33
38
|
resolveDeployDir,
|
|
34
39
|
saveSession,
|
|
40
|
+
serverError,
|
|
35
41
|
setCliVersion,
|
|
36
42
|
shortVersion,
|
|
37
43
|
startFailureReports,
|
|
38
44
|
storedZipBytes,
|
|
45
|
+
unauthorizedFor,
|
|
39
46
|
unexpectedError,
|
|
40
47
|
uploadLimitsFor
|
|
41
|
-
} from "../cli-
|
|
48
|
+
} from "../cli-4d5fkx95.js";
|
|
42
49
|
|
|
43
50
|
// bin/deploy.ts
|
|
44
|
-
import { readFile as
|
|
51
|
+
import { readFile as readFile3, stat as stat4 } from "node:fs/promises";
|
|
45
52
|
import { homedir } from "node:os";
|
|
46
|
-
import { relative } from "node:path";
|
|
53
|
+
import { relative as relative3, resolve as resolve3 } from "node:path";
|
|
47
54
|
import { fileURLToPath } from "node:url";
|
|
48
55
|
|
|
56
|
+
// src/cli/commands.ts
|
|
57
|
+
import { stat as stat3 } from "node:fs/promises";
|
|
58
|
+
import { relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
59
|
+
|
|
49
60
|
// src/cli/limits.ts
|
|
50
|
-
import { readdir } from "node:fs/promises";
|
|
51
|
-
import { basename, dirname, resolve } from "node:path";
|
|
61
|
+
import { readdir as readdir2, stat as stat2 } from "node:fs/promises";
|
|
62
|
+
import { basename, dirname, join as join2, relative, resolve } from "node:path";
|
|
52
63
|
|
|
53
64
|
// src/ui.ts
|
|
54
65
|
var ESC = "\x1B[";
|
|
@@ -326,25 +337,162 @@ function shapeProps(shape, markers) {
|
|
|
326
337
|
}
|
|
327
338
|
var fmtKb = (n) => n >= 1024 ? `${(n / 1024).toFixed(1)} MB` : `${n} KB`;
|
|
328
339
|
function sizeAdvice(shape, markers) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
340
|
+
switch (sizeCause(shape, markers)) {
|
|
341
|
+
case "project_root": {
|
|
342
|
+
const dir = markers?.build_dirs.find((d) => d !== "public") ?? markers?.build_dirs[0];
|
|
343
|
+
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`.";
|
|
344
|
+
}
|
|
345
|
+
case "source_map":
|
|
346
|
+
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.`;
|
|
347
|
+
case "media":
|
|
348
|
+
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.`;
|
|
349
|
+
case "archive":
|
|
350
|
+
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.`;
|
|
351
|
+
case "image":
|
|
352
|
+
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.`;
|
|
353
|
+
default:
|
|
354
|
+
return null;
|
|
332
355
|
}
|
|
356
|
+
}
|
|
357
|
+
function sizeCause(shape, markers) {
|
|
358
|
+
if (markers?.looks_like_project_root)
|
|
359
|
+
return "project_root";
|
|
333
360
|
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
|
|
361
|
+
if (share("source_map") >= 0.2)
|
|
362
|
+
return "source_map";
|
|
363
|
+
if (share("media") >= 0.3)
|
|
364
|
+
return "media";
|
|
365
|
+
if (share("archive") >= 0.3)
|
|
366
|
+
return "archive";
|
|
367
|
+
if (share("image") >= 0.5)
|
|
368
|
+
return "image";
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// src/cli/build-hint.ts
|
|
373
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
374
|
+
import { join } from "node:path";
|
|
375
|
+
var FRAMEWORKS = [
|
|
376
|
+
["next", { label: "Next.js", out: "out" }],
|
|
377
|
+
["nuxt", { label: "Nuxt", out: ".output/public" }],
|
|
378
|
+
["astro", { label: "Astro", out: "dist" }],
|
|
379
|
+
["@sveltejs/kit", { label: "SvelteKit", out: "build" }],
|
|
380
|
+
["gatsby", { label: "Gatsby", out: "public" }],
|
|
381
|
+
["@docusaurus/core", { label: "Docusaurus", out: "build" }],
|
|
382
|
+
["@11ty/eleventy", { label: "Eleventy", out: "_site" }],
|
|
383
|
+
["vitepress", { label: "VitePress", out: ".vitepress/dist" }],
|
|
384
|
+
["@angular/core", { label: "Angular", out: "dist" }],
|
|
385
|
+
["react-scripts", { label: "Create React App", out: "build" }],
|
|
386
|
+
["@vue/cli-service", { label: "Vue CLI", out: "dist" }],
|
|
387
|
+
["vite", { label: "Vite", out: "dist" }],
|
|
388
|
+
["parcel", { label: "Parcel", out: "dist" }]
|
|
389
|
+
];
|
|
390
|
+
var GENERATORS = [
|
|
391
|
+
["_config.yml", "bundle exec jekyll build", "_site"],
|
|
392
|
+
["mkdocs.yml", "mkdocs build", "site"],
|
|
393
|
+
["hugo.toml", "hugo", "public"]
|
|
394
|
+
];
|
|
395
|
+
async function isFile(path) {
|
|
396
|
+
try {
|
|
397
|
+
return (await stat(path)).isFile();
|
|
398
|
+
} catch {
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
function runBuild(top) {
|
|
403
|
+
if (top.has("bun.lock") || top.has("bun.lockb"))
|
|
404
|
+
return "bun run build";
|
|
405
|
+
if (top.has("pnpm-lock.yaml"))
|
|
406
|
+
return "pnpm build";
|
|
407
|
+
if (top.has("yarn.lock"))
|
|
408
|
+
return "yarn build";
|
|
409
|
+
return "npm run build";
|
|
410
|
+
}
|
|
411
|
+
async function buildHint(cwd, opts) {
|
|
412
|
+
let entries;
|
|
413
|
+
try {
|
|
414
|
+
entries = (await readdir(cwd, { withFileTypes: true })).map((e) => ({
|
|
415
|
+
name: e.name,
|
|
416
|
+
dir: e.isDirectory()
|
|
417
|
+
}));
|
|
418
|
+
} catch {
|
|
419
|
+
return null;
|
|
336
420
|
}
|
|
337
|
-
|
|
338
|
-
|
|
421
|
+
const top = new Set(entries.map((e) => e.name));
|
|
422
|
+
const sites = [];
|
|
423
|
+
for (const e of entries) {
|
|
424
|
+
if (!e.dir || e.name === "node_modules" || e.name.startsWith("."))
|
|
425
|
+
continue;
|
|
426
|
+
if (e.name === opts.exclude)
|
|
427
|
+
continue;
|
|
428
|
+
if (await isFile(join(cwd, e.name, "index.html")))
|
|
429
|
+
sites.push(e.name);
|
|
339
430
|
}
|
|
340
|
-
|
|
341
|
-
|
|
431
|
+
const deploy = (dir) => `\`${opts.verb} ${/^(\/|\.\.?\/)/.test(dir) ? dir : `./${dir}`}\``;
|
|
432
|
+
const remembered = opts.remembered && opts.remembered !== opts.exclude ? opts.remembered : null;
|
|
433
|
+
let pkg = null;
|
|
434
|
+
if (top.has("package.json")) {
|
|
435
|
+
try {
|
|
436
|
+
pkg = JSON.parse(await readFile(join(cwd, "package.json"), "utf8"));
|
|
437
|
+
} catch {
|
|
438
|
+
pkg = {};
|
|
439
|
+
}
|
|
342
440
|
}
|
|
343
|
-
if (
|
|
344
|
-
|
|
441
|
+
if (pkg) {
|
|
442
|
+
const deps = { ...pkg.dependencies ?? {}, ...pkg.devDependencies ?? {} };
|
|
443
|
+
const fw = FRAMEWORKS.find(([dep]) => (dep in deps))?.[1];
|
|
444
|
+
const hasBuild = typeof pkg.scripts?.build === "string";
|
|
445
|
+
const run = runBuild(top);
|
|
446
|
+
const present = ["dist", "build", "out", "_site"].find((d) => top.has(d) && d !== opts.exclude);
|
|
447
|
+
const out = remembered ?? fw?.out ?? present ?? "dist";
|
|
448
|
+
if (fw?.label === "Next.js" && !top.has("out") && !await nextExports(cwd, top)) {
|
|
449
|
+
return `This is a Next.js project, and it builds a server app, not static files. Set \`output: "export"\` in next.config, run \`${run}\`, then ${deploy("out")}.`;
|
|
450
|
+
}
|
|
451
|
+
if (hasBuild) {
|
|
452
|
+
const what = fw ? `${fw.label} project` : "project";
|
|
453
|
+
const where = fw || remembered || present ? deploy(out) : `${deploy("dist")} (or the folder the build writes)`;
|
|
454
|
+
return `This ${what} has no build output yet. Run \`${run}\`, then ${where}.`;
|
|
455
|
+
}
|
|
456
|
+
if (sites.length > 0)
|
|
457
|
+
return namedSites(sites, deploy);
|
|
458
|
+
if (present && !top.has("index.html")) {
|
|
459
|
+
return `This looks like the project folder, and ${present}/ has no index.html yet. Build the site (e.g. \`${run}\`), then ${deploy(present)}.`;
|
|
460
|
+
}
|
|
461
|
+
if (top.has("index.html")) {
|
|
462
|
+
return `This folder has a package.json but no build script. If its index.html is the site, deploy it as it is (node_modules and .git are left out): \`${opts.verb} .\`.`;
|
|
463
|
+
}
|
|
464
|
+
return null;
|
|
465
|
+
}
|
|
466
|
+
if (sites.length > 0)
|
|
467
|
+
return namedSites(sites, deploy);
|
|
468
|
+
for (const [marker, build, out] of GENERATORS) {
|
|
469
|
+
if (top.has(marker)) {
|
|
470
|
+
return `This is a static-site generator's source folder. Run \`${build}\`, then ${deploy(out)}.`;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
const pages = entries.filter((e) => !e.dir && /\.html?$/i.test(e.name)).map((e) => e.name);
|
|
474
|
+
if (pages.length > 0) {
|
|
475
|
+
return `There is no index.html here. Deploy one page with ${deploy(pages[0])}, or rename the main page to index.html.`;
|
|
345
476
|
}
|
|
346
477
|
return null;
|
|
347
478
|
}
|
|
479
|
+
async function nextExports(cwd, top) {
|
|
480
|
+
for (const name of ["next.config.js", "next.config.mjs", "next.config.ts", "next.config.cjs"]) {
|
|
481
|
+
if (!top.has(name))
|
|
482
|
+
continue;
|
|
483
|
+
const text = await readFile(join(cwd, name), "utf8").catch(() => "");
|
|
484
|
+
if (/output\s*:\s*["'`]export["'`]/.test(text))
|
|
485
|
+
return true;
|
|
486
|
+
}
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
function namedSites(sites, deploy) {
|
|
490
|
+
const listed = sites.slice(0, 3);
|
|
491
|
+
if (listed.length === 1) {
|
|
492
|
+
return `${listed[0]}/ has an index.html. Deploy it: ${deploy(listed[0])}.`;
|
|
493
|
+
}
|
|
494
|
+
return `These folders have an index.html: ${listed.map((d) => `${d}/`).join(", ")}. Deploy the site's one, e.g. ${deploy(listed[0])}.`;
|
|
495
|
+
}
|
|
348
496
|
|
|
349
497
|
// src/cli/limits.ts
|
|
350
498
|
function uploadReport(files, skippedCount) {
|
|
@@ -354,17 +502,22 @@ function uploadReport(files, skippedCount) {
|
|
|
354
502
|
...skippedCount !== undefined ? { skipped_count: skippedCount } : {}
|
|
355
503
|
};
|
|
356
504
|
}
|
|
357
|
-
function checkUploadSize(files, limits, skippedCount) {
|
|
505
|
+
function checkUploadSize(files, limits, skippedCount, opts = {}) {
|
|
358
506
|
if (!limits)
|
|
359
507
|
return null;
|
|
360
508
|
const names = Object.keys(files);
|
|
361
|
-
const
|
|
509
|
+
const shape = () => uploadShape(files);
|
|
510
|
+
const markers = () => folderMarkers(names);
|
|
511
|
+
const advice = () => sizeAdvice(shape(), markers());
|
|
362
512
|
const report = (limit2) => ({ limit: limit2, ...uploadReport(files, skippedCount) });
|
|
363
513
|
if (names.length > limits.maxFiles) {
|
|
514
|
+
const generic = "Deploy only the build output, or list what the site does not need in a .flypodignore.";
|
|
515
|
+
const crowded = opts.ignoreFile ? crowdedFolder(names, names.length - limits.maxFiles) : null;
|
|
516
|
+
const tip2 = crowded ? ` ${crowded.dir}/ holds ${crowded.count} of the ${names.length} files; if the site does not need them, add \`/${crowded.dir}/\` to ${opts.ignoreFile}.` : "";
|
|
364
517
|
return {
|
|
365
518
|
code: "too_large",
|
|
366
519
|
error: `This build has ${names.length} files; flypod accepts at most ${limits.maxFiles} per deploy.`,
|
|
367
|
-
fix: advice() ??
|
|
520
|
+
fix: `${advice() ?? generic}${sizeCause(shape(), markers()) === "project_root" ? "" : tip2}`,
|
|
368
521
|
extra: { limit: "files", files: names.length, limit_files: limits.maxFiles },
|
|
369
522
|
telemetry: report("files")
|
|
370
523
|
};
|
|
@@ -380,10 +533,13 @@ function checkUploadSize(files, limits, skippedCount) {
|
|
|
380
533
|
const limit = overZip ? limits.maxZipBytes : limits.maxTotalBytes;
|
|
381
534
|
const what = overZip ? "upload" : "site";
|
|
382
535
|
const which = overZip ? "zip_bytes" : "total_bytes";
|
|
536
|
+
const cause = sizeCause(shape(), markers());
|
|
537
|
+
const lines = opts.ignoreFile && cause !== "project_root" && cause !== "source_map" ? ignoreLines(files, Math.max(total - limits.maxTotalBytes, zipped - limits.maxZipBytes), cause ?? undefined) : null;
|
|
538
|
+
const tip = lines ? ` Leaving out ${lines.length === 1 ? "this file" : `these ${lines.length} files`} brings it under the limit; add ${lines.length === 1 ? "it" : "them"} to ${opts.ignoreFile}: ${lines.map((l) => `\`${l}\``).join(", ")}.` : "";
|
|
383
539
|
return {
|
|
384
540
|
code: "too_large",
|
|
385
541
|
error: `This build is ${fmtBytes(overZip ? zipped : total)}; flypod accepts at most ${fmtBytes(limit)} per ${what}. Largest files: ${listed}.`,
|
|
386
|
-
fix: advice() ?? "Remove or shrink the largest files (or list them in a .flypodignore), then deploy again."
|
|
542
|
+
fix: `${advice() ?? "Remove or shrink the largest files (or list them in a .flypodignore), then deploy again."}${tip}`,
|
|
387
543
|
extra: {
|
|
388
544
|
limit: which,
|
|
389
545
|
bytes: total,
|
|
@@ -394,21 +550,58 @@ function checkUploadSize(files, limits, skippedCount) {
|
|
|
394
550
|
telemetry: report(which)
|
|
395
551
|
};
|
|
396
552
|
}
|
|
397
|
-
function
|
|
398
|
-
|
|
399
|
-
|
|
553
|
+
async function ignoreFilePath(dir, cwd) {
|
|
554
|
+
try {
|
|
555
|
+
if (!(await stat2(dir)).isDirectory())
|
|
556
|
+
return;
|
|
557
|
+
} catch {
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
const rel = relative(cwd, resolve(dir));
|
|
561
|
+
if (rel === "")
|
|
562
|
+
return IGNORE_FILE;
|
|
563
|
+
return rel.startsWith("..") ? join2(resolve(dir), IGNORE_FILE) : join2(rel, IGNORE_FILE);
|
|
564
|
+
}
|
|
565
|
+
var MAX_IGNORE_LINES = 5;
|
|
566
|
+
var NOT_A_LITERAL = /[*?[\]\\]|^\s|\s$/;
|
|
567
|
+
function ignoreLines(files, overBy, kind) {
|
|
568
|
+
const pool = Object.keys(files).filter((n) => n !== "index.html" && !NOT_A_LITERAL.test(n)).filter((n) => !kind || kindOf(n) === kind).map((n) => ({ path: n, bytes: files[n]?.byteLength ?? 0 })).sort((a, b) => b.bytes - a.bytes);
|
|
569
|
+
const out = [];
|
|
570
|
+
let removed = 0;
|
|
571
|
+
for (const f of pool) {
|
|
572
|
+
if (removed >= overBy)
|
|
573
|
+
break;
|
|
574
|
+
if (out.length === MAX_IGNORE_LINES)
|
|
575
|
+
return null;
|
|
576
|
+
out.push(`/${f.path}`);
|
|
577
|
+
removed += f.bytes + 2 * f.path.length + 76;
|
|
578
|
+
}
|
|
579
|
+
return removed >= overBy && out.length > 0 ? out : null;
|
|
580
|
+
}
|
|
581
|
+
function crowdedFolder(names, over) {
|
|
582
|
+
const counts = new Map;
|
|
583
|
+
for (const n of names) {
|
|
584
|
+
const slash = n.indexOf("/");
|
|
585
|
+
if (slash > 0)
|
|
586
|
+
counts.set(n.slice(0, slash), (counts.get(n.slice(0, slash)) ?? 0) + 1);
|
|
587
|
+
}
|
|
588
|
+
let best = null;
|
|
589
|
+
for (const [dir, count] of counts)
|
|
590
|
+
if (!best || count > best.count)
|
|
591
|
+
best = { dir, count };
|
|
592
|
+
if (!best || best.count < over || NOT_A_LITERAL.test(best.dir))
|
|
400
593
|
return null;
|
|
401
|
-
return
|
|
594
|
+
return best;
|
|
402
595
|
}
|
|
403
596
|
async function markersOf(dir) {
|
|
404
597
|
try {
|
|
405
|
-
const entries = await
|
|
598
|
+
const entries = await readdir2(dir, { withFileTypes: true });
|
|
406
599
|
return folderMarkers(entries.map((e) => e.isDirectory() ? `${e.name}/` : e.name));
|
|
407
600
|
} catch {
|
|
408
601
|
return null;
|
|
409
602
|
}
|
|
410
603
|
}
|
|
411
|
-
async function withFolderHint(err, cwd, deployed) {
|
|
604
|
+
async function withFolderHint(err, cwd, deployed, opts = {}) {
|
|
412
605
|
const markers = await markersOf(cwd);
|
|
413
606
|
if (!markers)
|
|
414
607
|
return err;
|
|
@@ -420,15 +613,22 @@ async function withFolderHint(err, cwd, deployed) {
|
|
|
420
613
|
has_src_dir: markers.has_src_dir,
|
|
421
614
|
...markers.build_dirs.length ? { build_dirs: markers.build_dirs.join(",") } : {}
|
|
422
615
|
};
|
|
616
|
+
const hint = await buildHint(cwd, {
|
|
617
|
+
verb: opts.verb ?? "flypod",
|
|
618
|
+
exclude,
|
|
619
|
+
remembered: opts.remembered
|
|
620
|
+
});
|
|
621
|
+
if (hint)
|
|
622
|
+
return { ...err, fix: hint, telemetry };
|
|
423
623
|
if (!markers.looks_like_project_root)
|
|
424
624
|
return { ...err, telemetry };
|
|
425
|
-
const
|
|
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.";
|
|
625
|
+
const fix = "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
626
|
return { ...err, fix, telemetry };
|
|
428
627
|
}
|
|
429
628
|
|
|
430
629
|
// src/cli/projects.ts
|
|
431
|
-
import { readFile } from "node:fs/promises";
|
|
630
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
631
|
+
import { sep } from "node:path";
|
|
432
632
|
var MAX_PROJECTS = 64;
|
|
433
633
|
function prune(projects, now) {
|
|
434
634
|
const out = {};
|
|
@@ -453,24 +653,56 @@ function cap(projects) {
|
|
|
453
653
|
return Object.fromEntries(keep);
|
|
454
654
|
}
|
|
455
655
|
async function loadProjects(env) {
|
|
656
|
+
const raw = await loadFile(env);
|
|
657
|
+
return raw ? prune(raw.projects, Date.now()) : {};
|
|
658
|
+
}
|
|
659
|
+
async function loadFile(env) {
|
|
456
660
|
try {
|
|
457
|
-
const text = await
|
|
661
|
+
const text = await readFile2(projectsFilePath(env), "utf8");
|
|
458
662
|
const parsed = JSON.parse(text);
|
|
459
663
|
if (!parsed || typeof parsed !== "object" || typeof parsed.projects !== "object")
|
|
460
|
-
return
|
|
461
|
-
return
|
|
664
|
+
return null;
|
|
665
|
+
return parsed;
|
|
462
666
|
} catch {
|
|
463
|
-
return
|
|
667
|
+
return null;
|
|
464
668
|
}
|
|
465
669
|
}
|
|
466
|
-
async function saveProjects(projects, env) {
|
|
467
|
-
const
|
|
468
|
-
const
|
|
670
|
+
async function saveProjects(projects, env, goneNow = {}) {
|
|
671
|
+
const now = Date.now();
|
|
672
|
+
const cleaned = cap(prune(projects, now));
|
|
673
|
+
const raw = await loadFile(env);
|
|
674
|
+
const gone = { ...raw?.gone ?? {} };
|
|
675
|
+
for (const [dir, rec] of [...Object.entries(raw?.projects ?? {}), ...Object.entries(projects)]) {
|
|
676
|
+
if (dir.startsWith(DETACHED_PREFIX) || rec.expires_at === null || rec.expires_at > now)
|
|
677
|
+
continue;
|
|
678
|
+
gone[dir] = { site_id: rec.site_id, url: rec.url, reason: "expired", at: rec.expires_at };
|
|
679
|
+
}
|
|
680
|
+
for (const [dir, rec] of Object.entries(goneNow)) {
|
|
681
|
+
gone[dir] = { site_id: rec.site_id, url: rec.url, reason: "gone", at: now };
|
|
682
|
+
}
|
|
683
|
+
for (const dir of Object.keys(cleaned))
|
|
684
|
+
delete gone[dir];
|
|
685
|
+
const kept = Object.entries(gone).sort(([, a], [, b]) => b.at - a.at).slice(0, MAX_PROJECTS);
|
|
686
|
+
const file = {
|
|
687
|
+
v: 1,
|
|
688
|
+
projects: cleaned,
|
|
689
|
+
...kept.length ? { gone: Object.fromEntries(kept) } : {}
|
|
690
|
+
};
|
|
469
691
|
const path = projectsFilePath(env);
|
|
470
692
|
await atomicWriteFile(path, `${JSON.stringify(file, null, 2)}
|
|
471
693
|
`);
|
|
472
694
|
return path;
|
|
473
695
|
}
|
|
696
|
+
async function goneForDir(dir, env) {
|
|
697
|
+
const raw = await loadFile(env);
|
|
698
|
+
if (!raw)
|
|
699
|
+
return null;
|
|
700
|
+
const rec = raw.projects[dir];
|
|
701
|
+
if (rec && rec.expires_at !== null && rec.expires_at <= Date.now()) {
|
|
702
|
+
return { site_id: rec.site_id, url: rec.url, reason: "expired", at: rec.expires_at };
|
|
703
|
+
}
|
|
704
|
+
return raw.gone?.[dir] ?? null;
|
|
705
|
+
}
|
|
474
706
|
var DETACHED_PREFIX = "detached:";
|
|
475
707
|
function holdsOnlyCredential(rec) {
|
|
476
708
|
return rec.expires_at !== null && typeof rec.manage_token === "string";
|
|
@@ -501,14 +733,25 @@ async function projectForSite(site_id, env) {
|
|
|
501
733
|
}
|
|
502
734
|
return detached;
|
|
503
735
|
}
|
|
504
|
-
async function forgetDir(dir, env) {
|
|
736
|
+
async function forgetDir(dir, env, opts = {}) {
|
|
505
737
|
const projects = await loadProjects(env);
|
|
506
|
-
|
|
738
|
+
const rec = projects[dir];
|
|
739
|
+
if (!rec)
|
|
507
740
|
return false;
|
|
508
741
|
delete projects[dir];
|
|
509
|
-
await saveProjects(projects, env);
|
|
742
|
+
await saveProjects(projects, env, opts.gone ? { [dir]: rec } : {});
|
|
510
743
|
return true;
|
|
511
744
|
}
|
|
745
|
+
async function nearbyLink(dir, env) {
|
|
746
|
+
const projects = await loadProjects(env);
|
|
747
|
+
const linked = Object.entries(projects).filter(([key]) => !key.startsWith(DETACHED_PREFIX));
|
|
748
|
+
const isUnder = (child, parent) => child.startsWith(parent.endsWith(sep) ? parent : `${parent}${sep}`);
|
|
749
|
+
const above = linked.filter(([key]) => isUnder(dir, key)).sort(([a], [b]) => b.length - a.length)[0];
|
|
750
|
+
if (above)
|
|
751
|
+
return { dir: above[0], rec: above[1] };
|
|
752
|
+
const below = linked.filter(([key]) => isUnder(key, dir));
|
|
753
|
+
return below.length === 1 ? { dir: below[0]?.[0], rec: below[0]?.[1] } : null;
|
|
754
|
+
}
|
|
512
755
|
async function forgetSite(site_id, env) {
|
|
513
756
|
const projects = await loadProjects(env);
|
|
514
757
|
let removed = 0;
|
|
@@ -623,6 +866,16 @@ function relinkNotice(prev, style) {
|
|
|
623
866
|
` ${s.bold("flypod update")}${s.dim(" ships there. This run makes a second site.")}`
|
|
624
867
|
];
|
|
625
868
|
}
|
|
869
|
+
var RELINK_WARNING = "new-site-in-linked-folder";
|
|
870
|
+
function relinkWarning(prev, newUrl) {
|
|
871
|
+
return {
|
|
872
|
+
code: RELINK_WARNING,
|
|
873
|
+
fix_recipe: `This folder already deployed to ${prev.url}, so \`flypod\` made a second site (${newUrl}, live now; nothing to redo). ` + "To ship changes to a site you already have, run `flypod update`, never `flypod` again. " + `To put this build on the earlier URL instead: \`flypod update --site ${prev.site_id}\`.`
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
function relinkHint(prev) {
|
|
877
|
+
return `flypod: this folder already deploys to ${prev.url}; this run makes a second site. Use \`flypod update\` to ship there.`;
|
|
878
|
+
}
|
|
626
879
|
function skippedRows(skipped, style) {
|
|
627
880
|
if (skipped.length === 0)
|
|
628
881
|
return [];
|
|
@@ -833,7 +1086,11 @@ async function pollDeviceToken(client, deviceCode) {
|
|
|
833
1086
|
const { access_token } = await res.json();
|
|
834
1087
|
return { state: "approved", access_token };
|
|
835
1088
|
}
|
|
836
|
-
const
|
|
1089
|
+
const text = await res.text().catch(() => "");
|
|
1090
|
+
let body = {};
|
|
1091
|
+
try {
|
|
1092
|
+
body = JSON.parse(text) ?? {};
|
|
1093
|
+
} catch {}
|
|
837
1094
|
if (body.error === "authorization_pending")
|
|
838
1095
|
return { state: "pending" };
|
|
839
1096
|
if (body.error === "slow_down")
|
|
@@ -842,7 +1099,9 @@ async function pollDeviceToken(client, deviceCode) {
|
|
|
842
1099
|
return { state: "denied" };
|
|
843
1100
|
if (body.error === "expired_token")
|
|
844
1101
|
return { state: "expired" };
|
|
845
|
-
|
|
1102
|
+
if (body.error === "invalid_grant")
|
|
1103
|
+
return { state: "invalid" };
|
|
1104
|
+
return { state: "error", res: new Response(text, { status: res.status, headers: res.headers }) };
|
|
846
1105
|
}
|
|
847
1106
|
async function verifyToken(accessToken, baseUrl, args, io, env) {
|
|
848
1107
|
const client = await createClient({
|
|
@@ -896,7 +1155,9 @@ async function login(args, io) {
|
|
|
896
1155
|
} catch (e) {
|
|
897
1156
|
return emitError(networkError(e, baseUrl), args, io, { prefix: "flypod login" });
|
|
898
1157
|
}
|
|
899
|
-
return poll.state === "approved" ? finishLogin(poll.access_token, baseUrl, args, io, env) : emitError(loginPollError(poll, args.deviceCode), args, io, {
|
|
1158
|
+
return poll.state === "approved" ? finishLogin(poll.access_token, baseUrl, args, io, env) : emitError(await loginPollError(poll, args.deviceCode, args), args, io, {
|
|
1159
|
+
prefix: "flypod login"
|
|
1160
|
+
});
|
|
900
1161
|
}
|
|
901
1162
|
let startRes;
|
|
902
1163
|
try {
|
|
@@ -914,7 +1175,7 @@ async function login(args, io) {
|
|
|
914
1175
|
return emitError({
|
|
915
1176
|
code: "interactive_login_required",
|
|
916
1177
|
error: "Sign-in needs a browser. Ask the user to open the URL and confirm the code.",
|
|
917
|
-
fix: `
|
|
1178
|
+
fix: `Ask the user to open ${openUrl} and confirm code ${start.user_code}. Then run \`flypod login --device-code ${start.device_code} --json\`; while it answers authorization_pending, wait ${start.interval ?? 5}s and run it again.`,
|
|
918
1179
|
extra: {
|
|
919
1180
|
verification_uri: start.verification_uri,
|
|
920
1181
|
verification_uri_complete: openUrl,
|
|
@@ -949,7 +1210,7 @@ async function login(args, io) {
|
|
|
949
1210
|
pollMs += 5000;
|
|
950
1211
|
continue;
|
|
951
1212
|
}
|
|
952
|
-
return emitError(loginPollError(poll, start.device_code), args, io, {
|
|
1213
|
+
return emitError(await loginPollError(poll, start.device_code, args), args, io, {
|
|
953
1214
|
prefix: "flypod login"
|
|
954
1215
|
});
|
|
955
1216
|
}
|
|
@@ -957,26 +1218,33 @@ async function login(args, io) {
|
|
|
957
1218
|
fix: "Run `flypod login` to try again."
|
|
958
1219
|
});
|
|
959
1220
|
}
|
|
960
|
-
function loginPollError(poll, deviceCode) {
|
|
1221
|
+
async function loginPollError(poll, deviceCode, args) {
|
|
1222
|
+
const json = args.json ? " --json" : "";
|
|
1223
|
+
const restart = `Run \`flypod login${json}\` to start again.`;
|
|
961
1224
|
switch (poll.state) {
|
|
962
1225
|
case "pending":
|
|
963
1226
|
case "slow_down":
|
|
964
1227
|
return {
|
|
965
1228
|
code: "authorization_pending",
|
|
966
1229
|
error: "The sign-in has not been confirmed in the browser yet.",
|
|
967
|
-
fix: `Wait for the user to confirm, then run \`flypod login --device-code ${deviceCode}\` again.`
|
|
1230
|
+
fix: `Wait for the user to confirm, then run \`flypod login --device-code ${deviceCode}${json}\` again.`
|
|
968
1231
|
};
|
|
969
1232
|
case "denied":
|
|
970
1233
|
return { code: "login_denied", error: "Authorization denied in browser." };
|
|
971
1234
|
case "expired":
|
|
1235
|
+
return { code: "login_expired", error: "The sign-in code expired.", fix: restart };
|
|
1236
|
+
case "invalid":
|
|
972
1237
|
return {
|
|
973
1238
|
code: "login_expired",
|
|
974
|
-
error: "
|
|
975
|
-
fix:
|
|
1239
|
+
error: "That sign-in code is no longer valid: it expired, was already used, or is not a device_code (the user_code is the one the person types).",
|
|
1240
|
+
fix: `If an earlier \`flypod login --device-code\` printed ok, you are already signed in. Otherwise: ${restart}`
|
|
976
1241
|
};
|
|
977
1242
|
case "error":
|
|
1243
|
+
if (poll.res.status >= 500) {
|
|
1244
|
+
return serverError(poll.res.status, await readServerMessage(poll.res), "flypod login");
|
|
1245
|
+
}
|
|
978
1246
|
return {
|
|
979
|
-
code:
|
|
1247
|
+
code: "bad_request",
|
|
980
1248
|
error: `unexpected response ${poll.res.status} while polling for approval.`,
|
|
981
1249
|
status: poll.res.status
|
|
982
1250
|
};
|
|
@@ -1142,9 +1410,22 @@ async function withTarget(name, args, io) {
|
|
|
1142
1410
|
const env = io.env ?? process.env;
|
|
1143
1411
|
const target = await resolveTarget(args, io);
|
|
1144
1412
|
if (!target)
|
|
1145
|
-
return emitError(
|
|
1413
|
+
return emitError(await whyNoSite(name, io, env), args, io);
|
|
1146
1414
|
return { env, target };
|
|
1147
1415
|
}
|
|
1416
|
+
async function whyNoSite(verb, io, env) {
|
|
1417
|
+
const cwd = io.cwd ?? process.cwd();
|
|
1418
|
+
const gone = await goneForDir(cwd, env).catch(() => null);
|
|
1419
|
+
const near = gone ? null : await nearbyLink(cwd, env).catch(() => null);
|
|
1420
|
+
const session = await loadSession(env).catch(() => null);
|
|
1421
|
+
const signedIn = Boolean(resolveCredentials(env, session).token);
|
|
1422
|
+
return noSite({
|
|
1423
|
+
verb,
|
|
1424
|
+
gone,
|
|
1425
|
+
nearby: near ? { dir: near.dir, site_id: near.rec.site_id } : null,
|
|
1426
|
+
signedIn
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1148
1429
|
function clientForTarget(target, args, io) {
|
|
1149
1430
|
return createClient({
|
|
1150
1431
|
env: io.env ?? process.env,
|
|
@@ -1157,42 +1438,179 @@ function clientForTarget(target, args, io) {
|
|
|
1157
1438
|
}
|
|
1158
1439
|
});
|
|
1159
1440
|
}
|
|
1160
|
-
async function failSiteRequest(verb, res, target, args, io, env,
|
|
1441
|
+
async function failSiteRequest(verb, res, target, args, io, env, opts = {}) {
|
|
1161
1442
|
if (res.status === 404 && target.dir)
|
|
1162
|
-
await forgetDir(target.dir, env);
|
|
1163
|
-
|
|
1164
|
-
if (err.code === "too_large" && upload)
|
|
1165
|
-
err.telemetry = { ...err.telemetry, ...upload() };
|
|
1443
|
+
await forgetDir(target.dir, env, { gone: true });
|
|
1444
|
+
let err = await classifyResponse(res, { verb, siteId: target.site_id, siteScoped: true });
|
|
1445
|
+
if (err.code === "too_large" && opts.upload) {
|
|
1446
|
+
err.telemetry = { ...err.telemetry, ...opts.upload() };
|
|
1447
|
+
}
|
|
1448
|
+
if (err.code === "unauthorized" && err.fix === UNAUTHORIZED_FIX && opts.client) {
|
|
1449
|
+
err = unauthorizedFor({
|
|
1450
|
+
siteId: target.site_id,
|
|
1451
|
+
sent: credentialSent(target, args, opts.client),
|
|
1452
|
+
known: target.rec !== null,
|
|
1453
|
+
status: err.status
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1166
1456
|
return emitError(err, args, io, { prefix: verb });
|
|
1167
1457
|
}
|
|
1168
|
-
|
|
1458
|
+
function credentialSent(target, args, client) {
|
|
1459
|
+
if (args.token)
|
|
1460
|
+
return "flag";
|
|
1461
|
+
if (!client.token)
|
|
1462
|
+
return "none";
|
|
1463
|
+
if (target.rec?.manage_token && client.token === target.rec.manage_token)
|
|
1464
|
+
return "manage_token";
|
|
1465
|
+
return "account";
|
|
1466
|
+
}
|
|
1467
|
+
async function sendForTarget(target, args, io, env, call) {
|
|
1169
1468
|
const client = await clientForTarget(target, args, io);
|
|
1170
|
-
|
|
1469
|
+
const res = await call(client);
|
|
1470
|
+
if (res.status !== 401 || credentialSent(target, args, client) !== "manage_token") {
|
|
1471
|
+
return { res, client };
|
|
1472
|
+
}
|
|
1473
|
+
const account = await createClient({
|
|
1474
|
+
env,
|
|
1475
|
+
fetch: io.fetch,
|
|
1476
|
+
cwd: io.cwd,
|
|
1477
|
+
overrides: { baseUrl: target.rec?.base_url }
|
|
1478
|
+
});
|
|
1479
|
+
if (!account.token || account.token === client.token)
|
|
1480
|
+
return { res, client };
|
|
1481
|
+
const again = await call(account);
|
|
1482
|
+
if (again.status === 401) {
|
|
1483
|
+
await again.body?.cancel().catch(() => {});
|
|
1484
|
+
return { res, client };
|
|
1485
|
+
}
|
|
1486
|
+
await res.body?.cancel().catch(() => {});
|
|
1487
|
+
if (again.ok)
|
|
1488
|
+
await adoptForAccount(target, env).catch(() => {});
|
|
1489
|
+
return { res: again, client: account };
|
|
1490
|
+
}
|
|
1491
|
+
async function adoptForAccount(target, env) {
|
|
1492
|
+
const owned = (r) => {
|
|
1493
|
+
const { manage_token: _retired, ...rest } = r;
|
|
1494
|
+
return { ...rest, expires_at: null };
|
|
1495
|
+
};
|
|
1496
|
+
if (target.rec)
|
|
1497
|
+
target.rec = owned(target.rec);
|
|
1498
|
+
const projects = await loadProjects(env);
|
|
1499
|
+
let changed = false;
|
|
1500
|
+
for (const [key, rec] of Object.entries(projects)) {
|
|
1501
|
+
if (rec.site_id !== target.site_id)
|
|
1502
|
+
continue;
|
|
1503
|
+
projects[key] = owned(rec);
|
|
1504
|
+
changed = true;
|
|
1505
|
+
}
|
|
1506
|
+
if (changed)
|
|
1507
|
+
await saveProjects(projects, env);
|
|
1508
|
+
}
|
|
1509
|
+
async function fetchSite(verb, target, args, io, env) {
|
|
1510
|
+
let sent;
|
|
1171
1511
|
try {
|
|
1172
|
-
|
|
1512
|
+
sent = await sendForTarget(target, args, io, env, (c) => c.getSite(target.site_id));
|
|
1173
1513
|
} catch (e) {
|
|
1174
|
-
|
|
1514
|
+
const { baseUrl } = await clientForTarget(target, args, io);
|
|
1515
|
+
return { error: emitError(networkError(e, baseUrl), args, io, { prefix: verb }) };
|
|
1516
|
+
}
|
|
1517
|
+
const { res, client } = sent;
|
|
1518
|
+
if (!res.ok) {
|
|
1519
|
+
return { error: await failSiteRequest(verb, res, target, args, io, env, { client }) };
|
|
1175
1520
|
}
|
|
1176
|
-
if (!res.ok)
|
|
1177
|
-
return { error: await failSiteRequest(verb, res, target, args, io, env) };
|
|
1178
1521
|
return { data: await res.json() };
|
|
1179
1522
|
}
|
|
1180
|
-
async function touchLink(target, version_id, env) {
|
|
1523
|
+
async function touchLink(target, version_id, env, deployDir) {
|
|
1181
1524
|
if (target.dir && target.rec) {
|
|
1182
|
-
await linkProject(target.dir, {
|
|
1525
|
+
await linkProject(target.dir, {
|
|
1526
|
+
...target.rec,
|
|
1527
|
+
version_id,
|
|
1528
|
+
last_used: Date.now(),
|
|
1529
|
+
...deployDir ? { deploy_dir: deployDir } : {}
|
|
1530
|
+
}, env);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
var UPDATE_RETRY_MS = 2000;
|
|
1534
|
+
var delay = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
1535
|
+
async function sendUpdate(target, args, io, env, zip, baseUrl) {
|
|
1536
|
+
let sent;
|
|
1537
|
+
try {
|
|
1538
|
+
sent = await sendForTarget(target, args, io, env, (c) => c.redeploy(target.site_id, zip));
|
|
1539
|
+
} catch (e) {
|
|
1540
|
+
return { kind: "retry", err: networkError(e, baseUrl) };
|
|
1541
|
+
}
|
|
1542
|
+
const { res, client } = sent;
|
|
1543
|
+
if (res.status >= 500) {
|
|
1544
|
+
const err = await classifyResponse(res, {
|
|
1545
|
+
verb: "flypod update",
|
|
1546
|
+
siteId: target.site_id,
|
|
1547
|
+
siteScoped: true
|
|
1548
|
+
});
|
|
1549
|
+
return { kind: "retry", err };
|
|
1550
|
+
}
|
|
1551
|
+
if (!res.ok)
|
|
1552
|
+
return { kind: "refused", res, client };
|
|
1553
|
+
try {
|
|
1554
|
+
return { kind: "ok", body: await res.json(), client };
|
|
1555
|
+
} catch {
|
|
1556
|
+
return {
|
|
1557
|
+
kind: "retry",
|
|
1558
|
+
err: {
|
|
1559
|
+
code: "server_error",
|
|
1560
|
+
status: res.status,
|
|
1561
|
+
error: "flypod update: the server's answer was cut off, so whether the new version went live is unknown.",
|
|
1562
|
+
fix: "Run the same command again: repeating an update is safe.",
|
|
1563
|
+
telemetry: { origin: "unreadable" }
|
|
1564
|
+
}
|
|
1565
|
+
};
|
|
1183
1566
|
}
|
|
1184
1567
|
}
|
|
1568
|
+
async function pathExists(path) {
|
|
1569
|
+
try {
|
|
1570
|
+
await stat3(path);
|
|
1571
|
+
return true;
|
|
1572
|
+
} catch {
|
|
1573
|
+
return false;
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
function shortPath(path, cwd) {
|
|
1577
|
+
const rel = relative2(cwd, path);
|
|
1578
|
+
if (rel === "")
|
|
1579
|
+
return ".";
|
|
1580
|
+
if (rel.startsWith("..") && rel.split(sep2).filter((p) => p === "..").length > 1)
|
|
1581
|
+
return path;
|
|
1582
|
+
return rel.startsWith("..") ? rel : `./${rel}`;
|
|
1583
|
+
}
|
|
1185
1584
|
async function update(args, io) {
|
|
1186
1585
|
const pre = await withTarget("update", args, io);
|
|
1187
1586
|
if (typeof pre === "number")
|
|
1188
1587
|
return pre;
|
|
1189
1588
|
const { env, target } = pre;
|
|
1190
1589
|
const cwd = io.cwd ?? process.cwd();
|
|
1590
|
+
const hintOpts = { verb: "flypod update" };
|
|
1591
|
+
if (args.path !== undefined && !await pathExists(args.path)) {
|
|
1592
|
+
return emitError(await withFolderHint({
|
|
1593
|
+
code: "no_build_dir",
|
|
1594
|
+
error: `Nothing to deploy at ${args.path}: no such file or folder.`,
|
|
1595
|
+
fix: "Pass the folder of built files, e.g. `flypod update ./dist`, or build the site first."
|
|
1596
|
+
}, cwd, undefined, hintOpts), args, io);
|
|
1597
|
+
}
|
|
1598
|
+
const remembered = !args.path && target.dir ? target.rec?.deploy_dir : undefined;
|
|
1191
1599
|
let dir;
|
|
1192
|
-
|
|
1193
|
-
dir =
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1600
|
+
if (remembered && await pathExists(remembered)) {
|
|
1601
|
+
dir = remembered;
|
|
1602
|
+
} else {
|
|
1603
|
+
try {
|
|
1604
|
+
dir = await resolveDeployDir({ cwd, explicit: args.path });
|
|
1605
|
+
} catch (e) {
|
|
1606
|
+
const shown = remembered ? shortPath(remembered, cwd) : undefined;
|
|
1607
|
+
const err = shown ? {
|
|
1608
|
+
code: "no_build_dir",
|
|
1609
|
+
error: `This folder's site was last deployed from ${shown}, which is not there now.`,
|
|
1610
|
+
fix: `Build the site again, then run \`flypod update\`; or pass the folder: \`flypod update ${shown}\`.`
|
|
1611
|
+
} : noBuildDir(e.message);
|
|
1612
|
+
return emitError(await withFolderHint(err, cwd, undefined, { ...hintOpts, remembered: shown }), args, io);
|
|
1613
|
+
}
|
|
1196
1614
|
}
|
|
1197
1615
|
let files;
|
|
1198
1616
|
let skipped;
|
|
@@ -1207,24 +1625,34 @@ async function update(args, io) {
|
|
|
1207
1625
|
error: `No files to deploy in ${dir}.`,
|
|
1208
1626
|
fix: "Build the site first, then deploy the output folder.",
|
|
1209
1627
|
telemetry: { file_count: 0, skipped_count: skipped.length }
|
|
1210
|
-
}, cwd, dir);
|
|
1628
|
+
}, cwd, dir, hintOpts);
|
|
1211
1629
|
return emitError(empty, args, io);
|
|
1212
1630
|
}
|
|
1213
|
-
const
|
|
1214
|
-
const tooLarge = checkUploadSize(files, uploadLimitsFor(
|
|
1631
|
+
const first = await clientForTarget(target, args, io);
|
|
1632
|
+
const tooLarge = checkUploadSize(files, uploadLimitsFor(first.baseUrl), skipped.length, {
|
|
1633
|
+
ignoreFile: await ignoreFilePath(dir, cwd)
|
|
1634
|
+
});
|
|
1215
1635
|
if (tooLarge)
|
|
1216
1636
|
return emitError(tooLarge, args, io, { prefix: "flypod update" });
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1637
|
+
const zip = packDeploy(files);
|
|
1638
|
+
let sent = await sendUpdate(target, args, io, env, zip, first.baseUrl);
|
|
1639
|
+
if (sent.kind === "retry") {
|
|
1640
|
+
await (io.sleep ?? delay)(UPDATE_RETRY_MS);
|
|
1641
|
+
sent = await sendUpdate(target, args, io, env, zip, first.baseUrl);
|
|
1642
|
+
if (sent.kind === "retry")
|
|
1643
|
+
sent.err.telemetry = { ...sent.err.telemetry, attempts: 2 };
|
|
1644
|
+
}
|
|
1645
|
+
if (sent.kind === "retry")
|
|
1646
|
+
return emitError(sent.err, args, io, { prefix: "flypod update" });
|
|
1647
|
+
const { client } = sent;
|
|
1648
|
+
if (sent.kind === "refused") {
|
|
1649
|
+
return failSiteRequest("flypod update", sent.res, target, args, io, env, {
|
|
1650
|
+
upload: () => uploadReport(files, skipped.length),
|
|
1651
|
+
client
|
|
1652
|
+
});
|
|
1225
1653
|
}
|
|
1226
|
-
const body =
|
|
1227
|
-
await touchLink(target, body.version_id, env);
|
|
1654
|
+
const { body } = sent;
|
|
1655
|
+
await touchLink(target, body.version_id, env, resolve2(dir));
|
|
1228
1656
|
const switched = args.timeline === undefined ? undefined : await switchTimeline(client, target.site_id, args.timeline);
|
|
1229
1657
|
const timeline = switched?.timeline;
|
|
1230
1658
|
const expiresAt = body.expires_at !== undefined ? body.expires_at : target.rec?.expires_at ?? null;
|
|
@@ -1302,15 +1730,19 @@ async function versions(args, io) {
|
|
|
1302
1730
|
return pre;
|
|
1303
1731
|
const { env, target } = pre;
|
|
1304
1732
|
if (args.timeline !== undefined) {
|
|
1305
|
-
const
|
|
1306
|
-
let
|
|
1733
|
+
const enabled = args.timeline;
|
|
1734
|
+
let sent;
|
|
1307
1735
|
try {
|
|
1308
|
-
|
|
1736
|
+
sent = await sendForTarget(target, args, io, env, (c) => c.setTimeline(target.site_id, enabled));
|
|
1309
1737
|
} catch (e) {
|
|
1310
|
-
|
|
1738
|
+
const { baseUrl } = await clientForTarget(target, args, io);
|
|
1739
|
+
return emitError(networkError(e, baseUrl), args, io, { prefix: "flypod versions" });
|
|
1740
|
+
}
|
|
1741
|
+
if (!sent.res.ok) {
|
|
1742
|
+
return failSiteRequest("flypod versions", sent.res, target, args, io, env, {
|
|
1743
|
+
client: sent.client
|
|
1744
|
+
});
|
|
1311
1745
|
}
|
|
1312
|
-
if (!res.ok)
|
|
1313
|
-
return failSiteRequest("flypod versions", res, target, args, io, env);
|
|
1314
1746
|
}
|
|
1315
1747
|
const site = await fetchSite("flypod versions", target, args, io, env);
|
|
1316
1748
|
if ("error" in site)
|
|
@@ -1406,7 +1838,7 @@ async function rollback(args, io) {
|
|
|
1406
1838
|
return emitError(networkError(e, client.baseUrl), args, io, { prefix: "flypod rollback" });
|
|
1407
1839
|
}
|
|
1408
1840
|
if (!res.ok)
|
|
1409
|
-
return failSiteRequest("flypod rollback", res, target, args, io, env);
|
|
1841
|
+
return failSiteRequest("flypod rollback", res, target, args, io, env, { client });
|
|
1410
1842
|
const body = await res.json();
|
|
1411
1843
|
await touchLink(target, body.live_version_id, env);
|
|
1412
1844
|
const url = body.url ?? target.rec?.url ?? siteUrlFrom(target.site_id, client.baseUrl);
|
|
@@ -1938,7 +2370,7 @@ function multiselect(opts) {
|
|
|
1938
2370
|
const output = opts.output ?? process.stderr;
|
|
1939
2371
|
const { style } = opts;
|
|
1940
2372
|
const choices = opts.choices.map((c) => ({ ...c }));
|
|
1941
|
-
return new Promise((
|
|
2373
|
+
return new Promise((resolve3) => {
|
|
1942
2374
|
let index = 0;
|
|
1943
2375
|
let printed = 0;
|
|
1944
2376
|
const footer = style.dim("↑/↓ move · space toggle · a all · enter confirm · esc cancel");
|
|
@@ -1979,7 +2411,7 @@ function multiselect(opts) {
|
|
|
1979
2411
|
};
|
|
1980
2412
|
const finish = (value) => {
|
|
1981
2413
|
cleanup();
|
|
1982
|
-
|
|
2414
|
+
resolve3(value);
|
|
1983
2415
|
};
|
|
1984
2416
|
const onData = (buf) => {
|
|
1985
2417
|
const key = buf.toString("utf8");
|
|
@@ -2334,7 +2766,7 @@ async function readVersion() {
|
|
|
2334
2766
|
for (const rel of ["../../package.json", "../package.json"]) {
|
|
2335
2767
|
try {
|
|
2336
2768
|
const url = new URL(rel, `file://${here}`);
|
|
2337
|
-
const text = await
|
|
2769
|
+
const text = await readFile3(url, "utf8");
|
|
2338
2770
|
const version = JSON.parse(text).version;
|
|
2339
2771
|
if (version)
|
|
2340
2772
|
return version;
|
|
@@ -2472,7 +2904,9 @@ Environment:
|
|
|
2472
2904
|
|
|
2473
2905
|
When no path is given, flypod looks for a build folder in the current directory:
|
|
2474
2906
|
dist, build, out, .output/public, .vercel/output/static, public, _site
|
|
2475
|
-
(each must contain an index.html)
|
|
2907
|
+
(each must contain an index.html). A folder of plain pages (an index.html,
|
|
2908
|
+
no package.json) deploys as it is. 'update' with no path deploys the
|
|
2909
|
+
folder the site was last deployed from.
|
|
2476
2910
|
|
|
2477
2911
|
What is uploaded:
|
|
2478
2912
|
Everything in the folder except .git, .hg, .svn, node_modules, .DS_Store,
|
|
@@ -2491,14 +2925,14 @@ function showHelp(version, json) {
|
|
|
2491
2925
|
}
|
|
2492
2926
|
async function exists(path) {
|
|
2493
2927
|
try {
|
|
2494
|
-
await
|
|
2928
|
+
await stat4(path);
|
|
2495
2929
|
return true;
|
|
2496
2930
|
} catch {
|
|
2497
2931
|
return false;
|
|
2498
2932
|
}
|
|
2499
2933
|
}
|
|
2500
2934
|
function shortDir(dir) {
|
|
2501
|
-
const rel =
|
|
2935
|
+
const rel = relative3(process.cwd(), dir);
|
|
2502
2936
|
return rel === "" || rel.startsWith("..") ? dir : rel || ".";
|
|
2503
2937
|
}
|
|
2504
2938
|
function fail2(err, args, style) {
|
|
@@ -2572,9 +3006,11 @@ async function main() {
|
|
|
2572
3006
|
fix: "Pass the folder of built files, e.g. `flypod ./dist`, or build the site first."
|
|
2573
3007
|
}, process.cwd()), args, style);
|
|
2574
3008
|
}
|
|
3009
|
+
const priorLink = await projectForDir(process.cwd()).catch(() => null);
|
|
2575
3010
|
let dir;
|
|
2576
3011
|
try {
|
|
2577
|
-
|
|
3012
|
+
const remembered = args.path === undefined && priorLink?.deploy_dir && await exists(priorLink.deploy_dir) ? priorLink.deploy_dir : undefined;
|
|
3013
|
+
dir = remembered ?? await resolveDeployDir({ explicit: args.path });
|
|
2578
3014
|
} catch (error) {
|
|
2579
3015
|
fail2(await withFolderHint(noBuildDir(error.message), process.cwd()), args, style);
|
|
2580
3016
|
}
|
|
@@ -2599,15 +3035,19 @@ async function main() {
|
|
|
2599
3035
|
telemetry: { file_count: 0, skipped_count: skipped.length }
|
|
2600
3036
|
}, process.cwd(), dir), args, style);
|
|
2601
3037
|
}
|
|
2602
|
-
const tooLarge = checkUploadSize(files, uploadLimitsFor(baseUrl), skipped.length
|
|
3038
|
+
const tooLarge = checkUploadSize(files, uploadLimitsFor(baseUrl), skipped.length, {
|
|
3039
|
+
ignoreFile: await ignoreFilePath(dir, process.cwd())
|
|
3040
|
+
});
|
|
2603
3041
|
if (tooLarge)
|
|
2604
3042
|
fail2(tooLarge, args, style);
|
|
2605
|
-
const priorLink = await projectForDir(process.cwd()).catch(() => null);
|
|
2606
3043
|
if (priorLink && useUI) {
|
|
2607
3044
|
for (const line of relinkNotice(priorLink, style))
|
|
2608
3045
|
process.stderr.write(`${line}
|
|
2609
3046
|
`);
|
|
2610
3047
|
process.stderr.write(`
|
|
3048
|
+
`);
|
|
3049
|
+
} else if (priorLink && args.quiet) {
|
|
3050
|
+
process.stderr.write(`${relinkHint(priorLink)}
|
|
2611
3051
|
`);
|
|
2612
3052
|
}
|
|
2613
3053
|
if (useUI)
|
|
@@ -2643,7 +3083,8 @@ async function main() {
|
|
|
2643
3083
|
...owned ? {} : { manage_token: result.manage_token },
|
|
2644
3084
|
expires_at: result.expires_at,
|
|
2645
3085
|
last_used: Date.now(),
|
|
2646
|
-
version_id: result.version_id
|
|
3086
|
+
version_id: result.version_id,
|
|
3087
|
+
deploy_dir: resolve3(dir)
|
|
2647
3088
|
});
|
|
2648
3089
|
} catch {
|
|
2649
3090
|
linkSaved = false;
|
|
@@ -2683,7 +3124,10 @@ async function main() {
|
|
|
2683
3124
|
if (args.json) {
|
|
2684
3125
|
const shared = {
|
|
2685
3126
|
healed: result.healed ?? [],
|
|
2686
|
-
warnings:
|
|
3127
|
+
warnings: [
|
|
3128
|
+
...result.warnings ?? [],
|
|
3129
|
+
...priorLink && priorLink.site_id !== result.site_id ? [relinkWarning(priorLink, result.url)] : []
|
|
3130
|
+
],
|
|
2687
3131
|
link_saved: linkSaved,
|
|
2688
3132
|
...priorLink && priorLink.site_id !== result.site_id ? { replaced_link: { site_id: priorLink.site_id, url: priorLink.url } } : {},
|
|
2689
3133
|
...args.comments ? {
|