flypod 0.17.0 → 0.18.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/README.md +55 -13
- package/dist/bin/deploy.js +545 -100
- package/dist/{cli-z3p9tds1.js → cli-tydvmnwj.js} +641 -204
- package/dist/src/api-error.d.ts +4 -0
- package/dist/src/cli/agent-env.d.ts +5 -0
- package/dist/src/cli/agent-guide.d.ts +16 -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 +84 -2
- package/dist/src/cli/install-id.d.ts +18 -4
- package/dist/src/cli/invoked-via.d.ts +6 -0
- 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 +28 -0
- package/dist/src/cli.d.ts +15 -3
- package/dist/src/cli.js +1 -1
- package/dist/src/client-meta.d.ts +83 -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-tydvmnwj.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
|
};
|
|
@@ -1130,11 +1398,11 @@ async function resolveTarget(args, io) {
|
|
|
1130
1398
|
const env = io.env ?? process.env;
|
|
1131
1399
|
if (args.site) {
|
|
1132
1400
|
const known = await projectForSite(args.site, env).catch(() => null);
|
|
1133
|
-
return { site_id: args.site, rec: known, dir: null };
|
|
1401
|
+
return { site_id: args.site, rec: known, dir: null, named: "flag" };
|
|
1134
1402
|
}
|
|
1135
1403
|
const cwd = io.cwd ?? process.cwd();
|
|
1136
1404
|
const rec = await projectForDir(cwd, env);
|
|
1137
|
-
return rec ? { site_id: rec.site_id, rec, dir: cwd } : null;
|
|
1405
|
+
return rec ? { site_id: rec.site_id, rec, dir: cwd, named: "link" } : null;
|
|
1138
1406
|
}
|
|
1139
1407
|
async function withTarget(name, args, io) {
|
|
1140
1408
|
if (args.help)
|
|
@@ -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,180 @@ 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
|
+
target: target.named,
|
|
1454
|
+
status: err.status
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1166
1457
|
return emitError(err, args, io, { prefix: verb });
|
|
1167
1458
|
}
|
|
1168
|
-
|
|
1459
|
+
function credentialSent(target, args, client) {
|
|
1460
|
+
if (args.token)
|
|
1461
|
+
return "flag";
|
|
1462
|
+
if (!client.token)
|
|
1463
|
+
return "none";
|
|
1464
|
+
if (target.rec?.manage_token && client.token === target.rec.manage_token)
|
|
1465
|
+
return "manage_token";
|
|
1466
|
+
return "account";
|
|
1467
|
+
}
|
|
1468
|
+
async function sendForTarget(target, args, io, env, call) {
|
|
1169
1469
|
const client = await clientForTarget(target, args, io);
|
|
1170
|
-
|
|
1470
|
+
const res = await call(client);
|
|
1471
|
+
if (res.status !== 401 || credentialSent(target, args, client) !== "manage_token") {
|
|
1472
|
+
return { res, client };
|
|
1473
|
+
}
|
|
1474
|
+
const account = await createClient({
|
|
1475
|
+
env,
|
|
1476
|
+
fetch: io.fetch,
|
|
1477
|
+
cwd: io.cwd,
|
|
1478
|
+
overrides: { baseUrl: target.rec?.base_url }
|
|
1479
|
+
});
|
|
1480
|
+
if (!account.token || account.token === client.token)
|
|
1481
|
+
return { res, client };
|
|
1482
|
+
const again = await call(account);
|
|
1483
|
+
if (again.status === 401) {
|
|
1484
|
+
await again.body?.cancel().catch(() => {});
|
|
1485
|
+
return { res, client };
|
|
1486
|
+
}
|
|
1487
|
+
await res.body?.cancel().catch(() => {});
|
|
1488
|
+
if (again.ok)
|
|
1489
|
+
await adoptForAccount(target, env).catch(() => {});
|
|
1490
|
+
return { res: again, client: account };
|
|
1491
|
+
}
|
|
1492
|
+
async function adoptForAccount(target, env) {
|
|
1493
|
+
const owned = (r) => {
|
|
1494
|
+
const { manage_token: _retired, ...rest } = r;
|
|
1495
|
+
return { ...rest, expires_at: null };
|
|
1496
|
+
};
|
|
1497
|
+
if (target.rec)
|
|
1498
|
+
target.rec = owned(target.rec);
|
|
1499
|
+
const projects = await loadProjects(env);
|
|
1500
|
+
let changed = false;
|
|
1501
|
+
for (const [key, rec] of Object.entries(projects)) {
|
|
1502
|
+
if (rec.site_id !== target.site_id)
|
|
1503
|
+
continue;
|
|
1504
|
+
projects[key] = owned(rec);
|
|
1505
|
+
changed = true;
|
|
1506
|
+
}
|
|
1507
|
+
if (changed)
|
|
1508
|
+
await saveProjects(projects, env);
|
|
1509
|
+
}
|
|
1510
|
+
async function fetchSite(verb, target, args, io, env) {
|
|
1511
|
+
let sent;
|
|
1171
1512
|
try {
|
|
1172
|
-
|
|
1513
|
+
sent = await sendForTarget(target, args, io, env, (c) => c.getSite(target.site_id));
|
|
1173
1514
|
} catch (e) {
|
|
1174
|
-
|
|
1515
|
+
const { baseUrl } = await clientForTarget(target, args, io);
|
|
1516
|
+
return { error: emitError(networkError(e, baseUrl), args, io, { prefix: verb }) };
|
|
1517
|
+
}
|
|
1518
|
+
const { res, client } = sent;
|
|
1519
|
+
if (!res.ok) {
|
|
1520
|
+
return { error: await failSiteRequest(verb, res, target, args, io, env, { client }) };
|
|
1175
1521
|
}
|
|
1176
|
-
if (!res.ok)
|
|
1177
|
-
return { error: await failSiteRequest(verb, res, target, args, io, env) };
|
|
1178
1522
|
return { data: await res.json() };
|
|
1179
1523
|
}
|
|
1180
|
-
async function touchLink(target, version_id, env) {
|
|
1524
|
+
async function touchLink(target, version_id, env, deployDir) {
|
|
1181
1525
|
if (target.dir && target.rec) {
|
|
1182
|
-
await linkProject(target.dir, {
|
|
1526
|
+
await linkProject(target.dir, {
|
|
1527
|
+
...target.rec,
|
|
1528
|
+
version_id,
|
|
1529
|
+
last_used: Date.now(),
|
|
1530
|
+
...deployDir ? { deploy_dir: deployDir } : {}
|
|
1531
|
+
}, env);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
var UPDATE_RETRY_MS = 2000;
|
|
1535
|
+
var delay = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
1536
|
+
async function sendUpdate(target, args, io, env, zip, baseUrl) {
|
|
1537
|
+
let sent;
|
|
1538
|
+
try {
|
|
1539
|
+
sent = await sendForTarget(target, args, io, env, (c) => c.redeploy(target.site_id, zip));
|
|
1540
|
+
} catch (e) {
|
|
1541
|
+
return { kind: "retry", err: networkError(e, baseUrl) };
|
|
1542
|
+
}
|
|
1543
|
+
const { res, client } = sent;
|
|
1544
|
+
if (res.status >= 500) {
|
|
1545
|
+
const err = await classifyResponse(res, {
|
|
1546
|
+
verb: "flypod update",
|
|
1547
|
+
siteId: target.site_id,
|
|
1548
|
+
siteScoped: true
|
|
1549
|
+
});
|
|
1550
|
+
return { kind: "retry", err };
|
|
1551
|
+
}
|
|
1552
|
+
if (!res.ok)
|
|
1553
|
+
return { kind: "refused", res, client };
|
|
1554
|
+
try {
|
|
1555
|
+
return { kind: "ok", body: await res.json(), client };
|
|
1556
|
+
} catch {
|
|
1557
|
+
return {
|
|
1558
|
+
kind: "retry",
|
|
1559
|
+
err: {
|
|
1560
|
+
code: "server_error",
|
|
1561
|
+
status: res.status,
|
|
1562
|
+
error: "flypod update: the server's answer was cut off, so whether the new version went live is unknown.",
|
|
1563
|
+
fix: "Run the same command again: repeating an update is safe.",
|
|
1564
|
+
telemetry: { origin: "unreadable" }
|
|
1565
|
+
}
|
|
1566
|
+
};
|
|
1183
1567
|
}
|
|
1184
1568
|
}
|
|
1569
|
+
async function pathExists(path) {
|
|
1570
|
+
try {
|
|
1571
|
+
await stat3(path);
|
|
1572
|
+
return true;
|
|
1573
|
+
} catch {
|
|
1574
|
+
return false;
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
function shortPath(path, cwd) {
|
|
1578
|
+
const rel = relative2(cwd, path);
|
|
1579
|
+
if (rel === "")
|
|
1580
|
+
return ".";
|
|
1581
|
+
if (rel.startsWith("..") && rel.split(sep2).filter((p) => p === "..").length > 1)
|
|
1582
|
+
return path;
|
|
1583
|
+
return rel.startsWith("..") ? rel : `./${rel}`;
|
|
1584
|
+
}
|
|
1185
1585
|
async function update(args, io) {
|
|
1186
1586
|
const pre = await withTarget("update", args, io);
|
|
1187
1587
|
if (typeof pre === "number")
|
|
1188
1588
|
return pre;
|
|
1189
1589
|
const { env, target } = pre;
|
|
1190
1590
|
const cwd = io.cwd ?? process.cwd();
|
|
1591
|
+
const hintOpts = { verb: "flypod update" };
|
|
1592
|
+
if (args.path !== undefined && !await pathExists(args.path)) {
|
|
1593
|
+
return emitError(await withFolderHint({
|
|
1594
|
+
code: "no_build_dir",
|
|
1595
|
+
error: `Nothing to deploy at ${args.path}: no such file or folder.`,
|
|
1596
|
+
fix: "Pass the folder of built files, e.g. `flypod update ./dist`, or build the site first."
|
|
1597
|
+
}, cwd, undefined, hintOpts), args, io);
|
|
1598
|
+
}
|
|
1599
|
+
const remembered = !args.path && target.dir ? target.rec?.deploy_dir : undefined;
|
|
1191
1600
|
let dir;
|
|
1192
|
-
|
|
1193
|
-
dir =
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1601
|
+
if (remembered && await pathExists(remembered)) {
|
|
1602
|
+
dir = remembered;
|
|
1603
|
+
} else {
|
|
1604
|
+
try {
|
|
1605
|
+
dir = await resolveDeployDir({ cwd, explicit: args.path });
|
|
1606
|
+
} catch (e) {
|
|
1607
|
+
const shown = remembered ? shortPath(remembered, cwd) : undefined;
|
|
1608
|
+
const err = shown ? {
|
|
1609
|
+
code: "no_build_dir",
|
|
1610
|
+
error: `This folder's site was last deployed from ${shown}, which is not there now.`,
|
|
1611
|
+
fix: `Build the site again, then run \`flypod update\`; or pass the folder: \`flypod update ${shown}\`.`
|
|
1612
|
+
} : noBuildDir(e.message);
|
|
1613
|
+
return emitError(await withFolderHint(err, cwd, undefined, { ...hintOpts, remembered: shown }), args, io);
|
|
1614
|
+
}
|
|
1196
1615
|
}
|
|
1197
1616
|
let files;
|
|
1198
1617
|
let skipped;
|
|
@@ -1207,24 +1626,34 @@ async function update(args, io) {
|
|
|
1207
1626
|
error: `No files to deploy in ${dir}.`,
|
|
1208
1627
|
fix: "Build the site first, then deploy the output folder.",
|
|
1209
1628
|
telemetry: { file_count: 0, skipped_count: skipped.length }
|
|
1210
|
-
}, cwd, dir);
|
|
1629
|
+
}, cwd, dir, hintOpts);
|
|
1211
1630
|
return emitError(empty, args, io);
|
|
1212
1631
|
}
|
|
1213
|
-
const
|
|
1214
|
-
const tooLarge = checkUploadSize(files, uploadLimitsFor(
|
|
1632
|
+
const first = await clientForTarget(target, args, io);
|
|
1633
|
+
const tooLarge = checkUploadSize(files, uploadLimitsFor(first.baseUrl), skipped.length, {
|
|
1634
|
+
ignoreFile: await ignoreFilePath(dir, cwd)
|
|
1635
|
+
});
|
|
1215
1636
|
if (tooLarge)
|
|
1216
1637
|
return emitError(tooLarge, args, io, { prefix: "flypod update" });
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1638
|
+
const zip = packDeploy(files);
|
|
1639
|
+
let sent = await sendUpdate(target, args, io, env, zip, first.baseUrl);
|
|
1640
|
+
if (sent.kind === "retry") {
|
|
1641
|
+
await (io.sleep ?? delay)(UPDATE_RETRY_MS);
|
|
1642
|
+
sent = await sendUpdate(target, args, io, env, zip, first.baseUrl);
|
|
1643
|
+
if (sent.kind === "retry")
|
|
1644
|
+
sent.err.telemetry = { ...sent.err.telemetry, attempts: 2 };
|
|
1645
|
+
}
|
|
1646
|
+
if (sent.kind === "retry")
|
|
1647
|
+
return emitError(sent.err, args, io, { prefix: "flypod update" });
|
|
1648
|
+
const { client } = sent;
|
|
1649
|
+
if (sent.kind === "refused") {
|
|
1650
|
+
return failSiteRequest("flypod update", sent.res, target, args, io, env, {
|
|
1651
|
+
upload: () => uploadReport(files, skipped.length),
|
|
1652
|
+
client
|
|
1653
|
+
});
|
|
1225
1654
|
}
|
|
1226
|
-
const body =
|
|
1227
|
-
await touchLink(target, body.version_id, env);
|
|
1655
|
+
const { body } = sent;
|
|
1656
|
+
await touchLink(target, body.version_id, env, resolve2(dir));
|
|
1228
1657
|
const switched = args.timeline === undefined ? undefined : await switchTimeline(client, target.site_id, args.timeline);
|
|
1229
1658
|
const timeline = switched?.timeline;
|
|
1230
1659
|
const expiresAt = body.expires_at !== undefined ? body.expires_at : target.rec?.expires_at ?? null;
|
|
@@ -1302,15 +1731,19 @@ async function versions(args, io) {
|
|
|
1302
1731
|
return pre;
|
|
1303
1732
|
const { env, target } = pre;
|
|
1304
1733
|
if (args.timeline !== undefined) {
|
|
1305
|
-
const
|
|
1306
|
-
let
|
|
1734
|
+
const enabled = args.timeline;
|
|
1735
|
+
let sent;
|
|
1307
1736
|
try {
|
|
1308
|
-
|
|
1737
|
+
sent = await sendForTarget(target, args, io, env, (c) => c.setTimeline(target.site_id, enabled));
|
|
1309
1738
|
} catch (e) {
|
|
1310
|
-
|
|
1739
|
+
const { baseUrl } = await clientForTarget(target, args, io);
|
|
1740
|
+
return emitError(networkError(e, baseUrl), args, io, { prefix: "flypod versions" });
|
|
1741
|
+
}
|
|
1742
|
+
if (!sent.res.ok) {
|
|
1743
|
+
return failSiteRequest("flypod versions", sent.res, target, args, io, env, {
|
|
1744
|
+
client: sent.client
|
|
1745
|
+
});
|
|
1311
1746
|
}
|
|
1312
|
-
if (!res.ok)
|
|
1313
|
-
return failSiteRequest("flypod versions", res, target, args, io, env);
|
|
1314
1747
|
}
|
|
1315
1748
|
const site = await fetchSite("flypod versions", target, args, io, env);
|
|
1316
1749
|
if ("error" in site)
|
|
@@ -1406,7 +1839,7 @@ async function rollback(args, io) {
|
|
|
1406
1839
|
return emitError(networkError(e, client.baseUrl), args, io, { prefix: "flypod rollback" });
|
|
1407
1840
|
}
|
|
1408
1841
|
if (!res.ok)
|
|
1409
|
-
return failSiteRequest("flypod rollback", res, target, args, io, env);
|
|
1842
|
+
return failSiteRequest("flypod rollback", res, target, args, io, env, { client });
|
|
1410
1843
|
const body = await res.json();
|
|
1411
1844
|
await touchLink(target, body.live_version_id, env);
|
|
1412
1845
|
const url = body.url ?? target.rec?.url ?? siteUrlFrom(target.site_id, client.baseUrl);
|
|
@@ -1938,7 +2371,7 @@ function multiselect(opts) {
|
|
|
1938
2371
|
const output = opts.output ?? process.stderr;
|
|
1939
2372
|
const { style } = opts;
|
|
1940
2373
|
const choices = opts.choices.map((c) => ({ ...c }));
|
|
1941
|
-
return new Promise((
|
|
2374
|
+
return new Promise((resolve3) => {
|
|
1942
2375
|
let index = 0;
|
|
1943
2376
|
let printed = 0;
|
|
1944
2377
|
const footer = style.dim("↑/↓ move · space toggle · a all · enter confirm · esc cancel");
|
|
@@ -1979,7 +2412,7 @@ function multiselect(opts) {
|
|
|
1979
2412
|
};
|
|
1980
2413
|
const finish = (value) => {
|
|
1981
2414
|
cleanup();
|
|
1982
|
-
|
|
2415
|
+
resolve3(value);
|
|
1983
2416
|
};
|
|
1984
2417
|
const onData = (buf) => {
|
|
1985
2418
|
const key = buf.toString("utf8");
|
|
@@ -2334,7 +2767,7 @@ async function readVersion() {
|
|
|
2334
2767
|
for (const rel of ["../../package.json", "../package.json"]) {
|
|
2335
2768
|
try {
|
|
2336
2769
|
const url = new URL(rel, `file://${here}`);
|
|
2337
|
-
const text = await
|
|
2770
|
+
const text = await readFile3(url, "utf8");
|
|
2338
2771
|
const version = JSON.parse(text).version;
|
|
2339
2772
|
if (version)
|
|
2340
2773
|
return version;
|
|
@@ -2472,7 +2905,9 @@ Environment:
|
|
|
2472
2905
|
|
|
2473
2906
|
When no path is given, flypod looks for a build folder in the current directory:
|
|
2474
2907
|
dist, build, out, .output/public, .vercel/output/static, public, _site
|
|
2475
|
-
(each must contain an index.html)
|
|
2908
|
+
(each must contain an index.html). A folder of plain pages (an index.html,
|
|
2909
|
+
no package.json) deploys as it is. 'update' with no path deploys the
|
|
2910
|
+
folder the site was last deployed from.
|
|
2476
2911
|
|
|
2477
2912
|
What is uploaded:
|
|
2478
2913
|
Everything in the folder except .git, .hg, .svn, node_modules, .DS_Store,
|
|
@@ -2491,14 +2926,14 @@ function showHelp(version, json) {
|
|
|
2491
2926
|
}
|
|
2492
2927
|
async function exists(path) {
|
|
2493
2928
|
try {
|
|
2494
|
-
await
|
|
2929
|
+
await stat4(path);
|
|
2495
2930
|
return true;
|
|
2496
2931
|
} catch {
|
|
2497
2932
|
return false;
|
|
2498
2933
|
}
|
|
2499
2934
|
}
|
|
2500
2935
|
function shortDir(dir) {
|
|
2501
|
-
const rel =
|
|
2936
|
+
const rel = relative3(process.cwd(), dir);
|
|
2502
2937
|
return rel === "" || rel.startsWith("..") ? dir : rel || ".";
|
|
2503
2938
|
}
|
|
2504
2939
|
function fail2(err, args, style) {
|
|
@@ -2572,9 +3007,11 @@ async function main() {
|
|
|
2572
3007
|
fix: "Pass the folder of built files, e.g. `flypod ./dist`, or build the site first."
|
|
2573
3008
|
}, process.cwd()), args, style);
|
|
2574
3009
|
}
|
|
3010
|
+
const priorLink = await projectForDir(process.cwd()).catch(() => null);
|
|
2575
3011
|
let dir;
|
|
2576
3012
|
try {
|
|
2577
|
-
|
|
3013
|
+
const remembered = args.path === undefined && priorLink?.deploy_dir && await exists(priorLink.deploy_dir) ? priorLink.deploy_dir : undefined;
|
|
3014
|
+
dir = remembered ?? await resolveDeployDir({ explicit: args.path });
|
|
2578
3015
|
} catch (error) {
|
|
2579
3016
|
fail2(await withFolderHint(noBuildDir(error.message), process.cwd()), args, style);
|
|
2580
3017
|
}
|
|
@@ -2599,15 +3036,19 @@ async function main() {
|
|
|
2599
3036
|
telemetry: { file_count: 0, skipped_count: skipped.length }
|
|
2600
3037
|
}, process.cwd(), dir), args, style);
|
|
2601
3038
|
}
|
|
2602
|
-
const tooLarge = checkUploadSize(files, uploadLimitsFor(baseUrl), skipped.length
|
|
3039
|
+
const tooLarge = checkUploadSize(files, uploadLimitsFor(baseUrl), skipped.length, {
|
|
3040
|
+
ignoreFile: await ignoreFilePath(dir, process.cwd())
|
|
3041
|
+
});
|
|
2603
3042
|
if (tooLarge)
|
|
2604
3043
|
fail2(tooLarge, args, style);
|
|
2605
|
-
const priorLink = await projectForDir(process.cwd()).catch(() => null);
|
|
2606
3044
|
if (priorLink && useUI) {
|
|
2607
3045
|
for (const line of relinkNotice(priorLink, style))
|
|
2608
3046
|
process.stderr.write(`${line}
|
|
2609
3047
|
`);
|
|
2610
3048
|
process.stderr.write(`
|
|
3049
|
+
`);
|
|
3050
|
+
} else if (priorLink && args.quiet) {
|
|
3051
|
+
process.stderr.write(`${relinkHint(priorLink)}
|
|
2611
3052
|
`);
|
|
2612
3053
|
}
|
|
2613
3054
|
if (useUI)
|
|
@@ -2643,7 +3084,8 @@ async function main() {
|
|
|
2643
3084
|
...owned ? {} : { manage_token: result.manage_token },
|
|
2644
3085
|
expires_at: result.expires_at,
|
|
2645
3086
|
last_used: Date.now(),
|
|
2646
|
-
version_id: result.version_id
|
|
3087
|
+
version_id: result.version_id,
|
|
3088
|
+
deploy_dir: resolve3(dir)
|
|
2647
3089
|
});
|
|
2648
3090
|
} catch {
|
|
2649
3091
|
linkSaved = false;
|
|
@@ -2683,7 +3125,10 @@ async function main() {
|
|
|
2683
3125
|
if (args.json) {
|
|
2684
3126
|
const shared = {
|
|
2685
3127
|
healed: result.healed ?? [],
|
|
2686
|
-
warnings:
|
|
3128
|
+
warnings: [
|
|
3129
|
+
...result.warnings ?? [],
|
|
3130
|
+
...priorLink && priorLink.site_id !== result.site_id ? [relinkWarning(priorLink, result.url)] : []
|
|
3131
|
+
],
|
|
2687
3132
|
link_saved: linkSaved,
|
|
2688
3133
|
...priorLink && priorLink.site_id !== result.site_id ? { replaced_link: { site_id: priorLink.site_id, url: priorLink.url } } : {},
|
|
2689
3134
|
...args.comments ? {
|