@unbase-app/cli 0.6.0 → 0.6.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.
Files changed (2) hide show
  1. package/lib/readers.mjs +1050 -274
  2. package/package.json +1 -1
package/lib/readers.mjs CHANGED
@@ -92,15 +92,15 @@ async function textLocation(repo, app, files) {
92
92
  const g = groupOf(page);
93
93
  groups.set(g, [...groups.get(g) ?? [], page]);
94
94
  }
95
- const literal3 = /* @__PURE__ */ new Map();
95
+ const literal4 = /* @__PURE__ */ new Map();
96
96
  await Promise.all(
97
97
  spread(groups, PAGE_CAP).map(async (page) => {
98
98
  const source = await repo.read(join(app.path, `src/pages/${page}`));
99
- if (source !== null) literal3.set(page, literalText(source));
99
+ if (source !== null) literal4.set(page, literalText(source));
100
100
  })
101
101
  );
102
102
  const result = [...groups].map(([group, list]) => {
103
- const total = list.reduce((sum, p) => sum + (literal3.get(p) ?? 0), 0);
103
+ const total = list.reduce((sum, p) => sum + (literal4.get(p) ?? 0), 0);
104
104
  return { group, pages: list.length, literal: total, in: total > LITERAL_IN_CODE ? "code" : "content" };
105
105
  });
106
106
  const inCode = result.filter((g) => g.in === "code").length;
@@ -453,110 +453,6 @@ async function detect(repo, branch, truncated, appPath) {
453
453
  };
454
454
  }
455
455
 
456
- // supabase/functions/unbase-projects/settings-content.ts
457
- var PAGE_FIELDS = {
458
- title: { name: "titel", kind: "text" },
459
- description: { name: "beschrijving", kind: "text" },
460
- socialImage: { name: "ogImage", kind: "image" },
461
- noindex: { name: "noindex", kind: "boolean" },
462
- siteSearch: { name: "zoeken", kind: "boolean" }
463
- };
464
- var SITE_FIELDS = {
465
- name: { name: "naam", kind: "text" },
466
- description: { name: "beschrijving", kind: "text" },
467
- language: { name: "taal", kind: "text" },
468
- faviconLight: { name: "favicon", kind: "image" },
469
- faviconDark: { name: "faviconDonker", kind: "image" },
470
- socialImage: { name: "ogImage", kind: "image" },
471
- analyticsId: { name: "googleAnalytics", kind: "text" }
472
- };
473
- var CONTENT = "src/content";
474
- var SCHEMAS = `${CONTENT}/.schemas`;
475
- var ROUTE = /^\/([^/]+(\/[^/]+)*)?$/;
476
- var AT_ONCE2 = 8;
477
- var MAX_ROUTE_FILES = 300;
478
- async function inTurns(items, work) {
479
- const out = new Array(items.length);
480
- let next = 0;
481
- await Promise.all(
482
- Array.from({ length: Math.min(AT_ONCE2, items.length) }, async () => {
483
- while (next < items.length) {
484
- const i = next++;
485
- out[i] = await work(items[i]);
486
- }
487
- })
488
- );
489
- return out;
490
- }
491
- var parse = (text) => {
492
- if (text === null) return null;
493
- try {
494
- return JSON.parse(text);
495
- } catch {
496
- return null;
497
- }
498
- };
499
- function valueOf(v, kind) {
500
- if (kind === "boolean") return typeof v === "boolean" ? String(v) : null;
501
- return typeof v === "string" ? v : null;
502
- }
503
- function fieldsOf(names, data, allowed, file, base) {
504
- const fields = {};
505
- for (const [field2, { name, kind }] of Object.entries(names)) {
506
- const value = valueOf(data?.[name], kind);
507
- const there = data?.[name] !== void 0;
508
- if (there && value === null) continue;
509
- if (!there && !allowed[name]) continue;
510
- fields[field2] = { file, pointer: `${base}/${name}`, kind, exists: there, value };
511
- }
512
- return fields;
513
- }
514
- async function contentSettings(repo, appPath) {
515
- const at3 = (p) => join(appPath, p);
516
- const schemaPaths = repo.paths.filter((p) => p.startsWith(`${at3(SCHEMAS)}/`) && p.endsWith(".schema.json"));
517
- if (!schemaPaths.length) return null;
518
- const named = (p) => p.slice(at3(SCHEMAS).length + 1, -".schema.json".length);
519
- const schemas = /* @__PURE__ */ new Map();
520
- const [legacyMap, map, ...read] = await inTurns([at3(`${SCHEMAS}/collecties.json`), at3(`${SCHEMAS}/collections.json`), ...schemaPaths], (p) => repo.read(p));
521
- schemaPaths.forEach((p, i) => {
522
- const s = parse(read[i] ?? null);
523
- if (s && typeof s === "object") schemas.set(named(p), s);
524
- });
525
- const elsewhere = { ...parse(legacyMap ?? null) ?? {}, ...parse(map ?? null) ?? {} };
526
- const jsonFiles = repo.paths.filter((p) => p.startsWith(`${at3(CONTENT)}/`) && p.endsWith(".json") && !p.startsWith(`${at3(SCHEMAS)}/`));
527
- const collectionOf = (p) => elsewhere[p.slice(appPath ? appPath.length + 1 : 0)] ?? p.slice(at3(CONTENT).length + 1).split("/")[0].replace(/\.json$/, "");
528
- const filesOf = (collection) => jsonFiles.filter((p) => collectionOf(p) === collection);
529
- const routeCollection = [...schemas].find(([, s]) => s.properties?.pad && s.properties?.seo);
530
- const pages = {};
531
- let routes = null;
532
- if (routeCollection) {
533
- const [collection, schema] = routeCollection;
534
- const allowed = schema.properties.seo?.properties ?? {};
535
- const files = filesOf(collection).slice(0, MAX_ROUTE_FILES);
536
- const datas = await inTurns(files, async (p) => parse(await repo.read(p)));
537
- files.forEach((file, i) => {
538
- const data = datas[i];
539
- if (!data || typeof data.pad !== "string" || !ROUTE.test(data.pad)) return;
540
- const seo = data.seo && typeof data.seo === "object" && !Array.isArray(data.seo) ? data.seo : {};
541
- pages[data.pad] = fieldsOf(PAGE_FIELDS, seo, allowed, file.slice(appPath ? appPath.length + 1 : 0), "/seo");
542
- });
543
- const dir = files[0] ? files[0].slice(appPath ? appPath.length + 1 : 0).replace(/\/[^/]+$/, "") : `${CONTENT}/${collection}`;
544
- const fields = Object.entries(PAGE_FIELDS).filter(([, { name }]) => allowed[name]).map(([field2, { name, kind }]) => ({ field: field2, pointer: `/seo/${name}`, kind }));
545
- routes = { dir, fields, ...schema["x-item-fields"] === true ? { itemFields: true } : {} };
546
- }
547
- const siteCollection = [...schemas].find(([, s]) => (s["x-settings"] ?? s["x-instellingen"]) === "site");
548
- let site = null;
549
- const siteFile = siteCollection && filesOf(siteCollection[0])[0];
550
- if (siteCollection && siteFile) {
551
- const data = parse(await repo.read(siteFile));
552
- if (data && typeof data === "object" && !Array.isArray(data)) {
553
- site = fieldsOf(SITE_FIELDS, data, siteCollection[1].properties ?? {}, siteFile.slice(appPath ? appPath.length + 1 : 0), "");
554
- }
555
- }
556
- if (!Object.keys(pages).length && !routes && !site) return null;
557
- return { pages, routes, site };
558
- }
559
-
560
456
  // supabase/functions/_shared/pages-core.mjs
561
457
  var pages_core_exports = {};
562
458
  __export(pages_core_exports, {
@@ -568,6 +464,7 @@ __export(pages_core_exports, {
568
464
  PAGE_FILE: () => PAGE_FILE,
569
465
  PAGE_OPERATIONS: () => PAGE_OPERATIONS,
570
466
  REDIRECTS_SINCE: () => REDIRECTS_SINCE,
467
+ VERCEL_JSON: () => VERCEL_JSON,
571
468
  adapterOf: () => adapterOf,
572
469
  createCapability: () => createCapability,
573
470
  createdAddress: () => createdAddress,
@@ -578,6 +475,7 @@ __export(pages_core_exports, {
578
475
  draftPlan: () => draftPlan,
579
476
  dynamicSegment: () => dynamicSegment,
580
477
  folderPaths: () => folderPaths,
478
+ hostedVercelJson: () => hostedVercelJson,
581
479
  importGraph: () => importGraph,
582
480
  isPattern: () => isPattern,
583
481
  kitFiles: () => kitFiles,
@@ -589,12 +487,14 @@ __export(pages_core_exports, {
589
487
  listTools: () => listTools,
590
488
  lowestVersion: () => lowestVersion,
591
489
  mediaGenerators: () => mediaGenerators,
490
+ noRedirects: () => noRedirects,
592
491
  normalisePath: () => normalisePath,
593
492
  ownedContent: () => ownedContent,
594
493
  pageActions: () => pageActions,
595
494
  parsePageFile: () => parsePageFile,
596
495
  planPage: () => planPage,
597
496
  planRedirect: () => planRedirect,
497
+ redirectMode: () => redirectMode,
598
498
  redirectsFor: () => redirectsFor,
599
499
  removeRoutes: () => removeRoutes,
600
500
  requestOf: () => requestOf,
@@ -746,14 +646,14 @@ var SKIP2 = /(^|\/)(node_modules|dist|build|\.git|\.astro|\.next|\.vercel|\.outp
746
646
  var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
747
647
  var escape2 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
748
648
  function parsePageFile(text) {
749
- if (text == null) return { ok: true, exists: false, pages: {}, folders: {}, redirects: {} };
649
+ if (text == null) return { ok: true, exists: false, pages: {}, folders: {}, redirects: {}, hosted: {} };
750
650
  const fail = (error) => ({ ok: (
751
651
  /** @type {const} */
752
652
  false
753
653
  ), exists: (
754
654
  /** @type {const} */
755
655
  true
756
- ), error, pages: {}, folders: {}, redirects: {} });
656
+ ), error, pages: {}, folders: {}, redirects: {}, hosted: {} });
757
657
  let data;
758
658
  try {
759
659
  data = JSON.parse(text);
@@ -779,16 +679,20 @@ function parsePageFile(text) {
779
679
  if (!isObject(entry) || entry.name !== void 0 && typeof entry.name !== "string") return fail(`folders: ${address2}: name is text`);
780
680
  if (entry.name) folders[normalisePath(address2)] = { name: entry.name };
781
681
  }
782
- const redirects = data.redirects ?? {};
783
- if (!isObject(redirects)) return fail("`redirects` is not an object");
784
- const sends2 = {};
785
- for (const [from, to] of Object.entries(redirects)) {
786
- if (!from.startsWith("/")) return fail(`redirects: ${from}: an address starts with /`);
787
- if (typeof to !== "string" || !to.startsWith("/")) return fail(`redirects: ${from}: goes to an address that starts with /`);
788
- if (REST.test(from) !== REST.test(to)) return fail(`redirects: ${from}: both ends end in /[...path], or neither`);
789
- sends2[normalisePath(from)] = normalisePath(to);
682
+ const maps = [];
683
+ for (const key of ["redirects", "hosted"]) {
684
+ const given = data[key] ?? {};
685
+ if (!isObject(given)) return fail(`\`${key}\` is not an object`);
686
+ const sends2 = {};
687
+ for (const [from, to] of Object.entries(given)) {
688
+ if (!from.startsWith("/")) return fail(`${key}: ${from}: an address starts with /`);
689
+ if (typeof to !== "string" || !to.startsWith("/")) return fail(`${key}: ${from}: goes to an address that starts with /`);
690
+ if (REST.test(from) !== REST.test(to)) return fail(`${key}: ${from}: both ends end in /[...path], or neither`);
691
+ sends2[normalisePath(from)] = normalisePath(to);
692
+ }
693
+ maps.push(sends2);
790
694
  }
791
- return { ok: true, exists: true, pages: out, folders, redirects: sends2 };
695
+ return { ok: true, exists: true, pages: out, folders, redirects: maps[0], hosted: maps[1] };
792
696
  }
793
697
  var REST = /\/\[\.\.\.[A-Za-z_]\w*\]$/;
794
698
  var draftPaths = (file) => Object.keys(file.pages).filter((p) => file.pages[p].draft === true).sort();
@@ -1832,6 +1736,65 @@ function kitAtLeast({ framework, text }, since) {
1832
1736
  return !!want && !!have && configs.some((c) => c.includes(name)) && atLeast(have, lowestVersion(want));
1833
1737
  });
1834
1738
  }
1739
+ var VERCEL_JSON = "vercel.json";
1740
+ function redirectMode({ framework, text, host = null, found, paths }) {
1741
+ const adapter = adapterOf(framework);
1742
+ if (!adapter?.acts) return null;
1743
+ const pages = (found ?? (paths ? discover({ framework, paths, text }) : { pages: [] })).pages;
1744
+ const objects = pages.some((p) => p.router?.object);
1745
+ if (!objects && kitRedirects({ framework, text })) return "package";
1746
+ const noPackage = !(KITS[String(framework)] ?? []).length;
1747
+ return host === "vercel" && (noPackage || objects) ? "host" : null;
1748
+ }
1749
+ function noRedirects({ framework, objects = false }) {
1750
+ const noPackage = !(KITS[String(framework)] ?? []).length;
1751
+ return noPackage || objects ? "host_redirects" : "no_redirects";
1752
+ }
1753
+ function vercelRedirectOf(from, to) {
1754
+ const side = (p) => {
1755
+ if (!REST.test(p)) return p;
1756
+ const base = normalisePath(p.replace(REST, ""));
1757
+ return `${base === "/" ? "" : base}/:path*`;
1758
+ };
1759
+ return { source: side(from), destination: side(to), permanent: true };
1760
+ }
1761
+ var vercelKey = (r) => `${r?.source}\0${r?.destination}`;
1762
+ function hostedMirrors(text) {
1763
+ const file = parsePageFile(text(PAGE_FILE));
1764
+ return new Set(Object.entries(file.ok ? file.hosted : {}).map(([f, t]) => vercelKey(vercelRedirectOf(f, t))));
1765
+ }
1766
+ function hostedVercelJson(before, was, now) {
1767
+ if (JSON.stringify(Object.entries(was)) === JSON.stringify(Object.entries(now))) return { content: null };
1768
+ let data = {};
1769
+ if (before != null) {
1770
+ try {
1771
+ data = JSON.parse(before);
1772
+ } catch {
1773
+ return { error: "vercel.json is not valid JSON" };
1774
+ }
1775
+ if (!isObject(data)) return { error: "vercel.json is not an object" };
1776
+ }
1777
+ const mine = new Set(Object.entries(was).map(([f, t]) => vercelKey(vercelRedirectOf(f, t))));
1778
+ const list = Array.isArray(data.redirects) ? data.redirects : [];
1779
+ const kept = list.filter((r) => !(isObject(r) && mine.has(vercelKey(r))));
1780
+ const added = Object.entries(now).map(([f, t]) => vercelRedirectOf(f, t));
1781
+ const next = { ...data };
1782
+ if (kept.length || added.length) next.redirects = [...kept, ...added];
1783
+ else delete next.redirects;
1784
+ if (before == null && !Object.keys(next).length) return { content: null };
1785
+ const indent = before?.match(/\n(\t| +)"/)?.[1] ?? " ";
1786
+ const after = `${JSON.stringify(next, null, indent)}
1787
+ `;
1788
+ return { content: after === before ? null : after };
1789
+ }
1790
+ function hostedWrite(text, pageBefore, pageAfter) {
1791
+ const was = parsePageFile(pageBefore).hosted ?? {};
1792
+ const now = pageAfter == null ? was : parsePageFile(pageAfter).hosted ?? {};
1793
+ if (JSON.stringify(was) === JSON.stringify(now)) return null;
1794
+ const out = hostedVercelJson(text(VERCEL_JSON), was, now);
1795
+ if ("error" in out) return out;
1796
+ return out.content === null ? null : { path: VERCEL_JSON, content: out.content };
1797
+ }
1835
1798
  var under = (path, at3) => at3 === "/" ? path !== "/" : path.startsWith(`${at3}/`);
1836
1799
  var within2 = (path, at3) => path === at3 || under(path, at3);
1837
1800
  var moveAddress = (path, from, to) => path === from ? to : normalisePath(`${to}${path.slice(from === "/" ? 0 : from.length)}`);
@@ -1840,8 +1803,9 @@ var lastOf = (p) => p.slice(p.lastIndexOf("/") + 1);
1840
1803
  function siteRedirects({ framework, text }) {
1841
1804
  const out = /* @__PURE__ */ new Set();
1842
1805
  try {
1843
- const v = JSON.parse(text("vercel.json") ?? "null");
1844
- for (const r of Array.isArray(v?.redirects) ? v.redirects : []) if (typeof r?.source === "string") out.add(normalisePath(r.source));
1806
+ const v = JSON.parse(text(VERCEL_JSON) ?? "null");
1807
+ const mine = hostedMirrors(text);
1808
+ for (const r of Array.isArray(v?.redirects) ? v.redirects : []) if (typeof r?.source === "string" && !mine.has(vercelKey(r))) out.add(normalisePath(r.source));
1845
1809
  } catch {
1846
1810
  }
1847
1811
  const adapter = adapterOf(framework);
@@ -1867,7 +1831,7 @@ function sends(source, path) {
1867
1831
  }
1868
1832
  return source === path || redirectMatches(source, path);
1869
1833
  }
1870
- function changedPageFile(before, change) {
1834
+ function changedPageFile(before, change, key = "redirects") {
1871
1835
  let data = {};
1872
1836
  try {
1873
1837
  data = before == null ? {} : JSON.parse(before) ?? {};
@@ -1876,16 +1840,16 @@ function changedPageFile(before, change) {
1876
1840
  }
1877
1841
  if (!isObject(data)) data = {};
1878
1842
  if (!isObject(data.pages)) data.pages = {};
1879
- const redirects = isObject(data.redirects) ? { ...data.redirects } : {};
1843
+ const redirects = isObject(data[key]) ? { ...data[key] } : {};
1880
1844
  const folders = isObject(data.folders) ? { ...data.folders } : {};
1881
1845
  change(data.pages, redirects, folders);
1882
1846
  for (const [k, v] of Object.entries(data.pages)) if (isObject(v) && !Object.keys(v).length) delete data.pages[k];
1883
1847
  for (const [k, v] of Object.entries(folders)) if (!isObject(v) || !v.name) delete folders[k];
1884
1848
  if (Object.keys(folders).length) data.folders = folders;
1885
1849
  else delete data.folders;
1886
- if (Object.keys(redirects).length) data.redirects = redirects;
1887
- else delete data.redirects;
1888
- const empty = !Object.keys(data.pages).length && !data.redirects && !data.folders && Object.keys(data).length === 1;
1850
+ if (Object.keys(redirects).length) data[key] = redirects;
1851
+ else delete data[key];
1852
+ const empty = !Object.keys(data.pages).length && !data.redirects && !data.hosted && !data.folders && Object.keys(data).length === 1;
1889
1853
  if (before == null && empty) return null;
1890
1854
  const after = `${JSON.stringify(data, null, 2)}
1891
1855
  `;
@@ -2189,7 +2153,7 @@ function planPage(request, input) {
2189
2153
  const discovered = input.found ?? discover({ framework, paths, text });
2190
2154
  if (action === "create") return planCreate(request, { framework, paths, text, discovered });
2191
2155
  const page = discovered.pages.find((p) => p.path === at3);
2192
- if (!page && action === "rename" && discovered.pages.some((p) => under(p.path, at3))) return planFolder(request, { framework, paths, text, discovered, importers: input.importers });
2156
+ if (!page && action === "rename" && discovered.pages.some((p) => under(p.path, at3))) return planFolder(request, { framework, paths, text, discovered, importers: input.importers, host: input.host ?? null });
2193
2157
  if (!page) {
2194
2158
  const template = discovered.pages.find((p) => p.kind === "template" && templateMatches(p.path, at3));
2195
2159
  return template ? no("template", template.path) : no("missing");
@@ -2203,7 +2167,19 @@ function planPage(request, input) {
2203
2167
  const have = new Set(paths);
2204
2168
  const importers = input.importers ?? importGraph(paths, text);
2205
2169
  const live = request.live === true;
2206
- const redirects = live ? kitRedirects({ framework, text }) : false;
2170
+ const mode = redirectMode({ framework, text, host: input.host ?? null, found: discovered });
2171
+ const redirects = live ? mode !== null : false;
2172
+ const sendKey = mode === "host" ? "hosted" : "redirects";
2173
+ const cannotMove = () => no(noRedirects({ framework, objects: discovered.pages.some((p) => p.router?.object) }), page.router?.object ? "route objects" : void 0);
2174
+ const writePageFile = (content) => {
2175
+ if (content === null) return null;
2176
+ write({ path: PAGE_FILE, content });
2177
+ if (sendKey !== "hosted") return null;
2178
+ const mirror = hostedWrite(text, text(PAGE_FILE), content);
2179
+ if (mirror && "error" in mirror) return no("invalid", mirror.error);
2180
+ if (mirror) write(mirror);
2181
+ return null;
2182
+ };
2207
2183
  const ownRedirects = siteRedirects({ framework, text });
2208
2184
  const taken = (p) => discovered.pages.some((q) => q.path === p) || [...ownRedirects].some((s) => sends(s, p));
2209
2185
  const writes = /* @__PURE__ */ new Map();
@@ -2229,7 +2205,7 @@ function planPage(request, input) {
2229
2205
  if (!validAddress(target) || target === "/") return no("address", target);
2230
2206
  if (target !== at3 && within2(target, at3)) return no("address", target);
2231
2207
  if (target !== at3 && taken(target)) return no("taken", target);
2232
- if (target !== at3 && live && (!redirects || page.router?.object)) return no("no_redirects", page.router?.object ? "route objects" : void 0);
2208
+ if (target !== at3 && live && !redirects) return cannotMove();
2233
2209
  to = target;
2234
2210
  const moved = /* @__PURE__ */ new Map();
2235
2211
  if (target !== at3) {
@@ -2299,8 +2275,9 @@ function planPage(request, input) {
2299
2275
  else delete entry.name;
2300
2276
  pages[target] = entry;
2301
2277
  }
2302
- });
2303
- if (pageFileText !== null) write({ path: PAGE_FILE, content: pageFileText });
2278
+ }, sendKey);
2279
+ const refused = writePageFile(pageFileText);
2280
+ if (refused) return refused;
2304
2281
  if (!writes.size) return no("same");
2305
2282
  }
2306
2283
  if (action === "duplicate") {
@@ -2438,7 +2415,7 @@ function planPage(request, input) {
2438
2415
  for (let p = parentOf(at3); p !== null && target === null; p = parentOf(p)) if (discovered.pages.some((q) => q.path === p && q.kind !== "template")) target = p;
2439
2416
  target = target ?? "/";
2440
2417
  }
2441
- if (!redirects || page.router?.object) return no("no_redirects", page.router?.object ? "route objects" : void 0);
2418
+ if (!redirects) return cannotMove();
2442
2419
  }
2443
2420
  to = target;
2444
2421
  if (adapter?.routeLines) {
@@ -2490,8 +2467,9 @@ function planPage(request, input) {
2490
2467
  }
2491
2468
  } else for (const [s, d] of Object.entries(sendsOn)) if (was(d)) delete sendsOn[s];
2492
2469
  for (const k of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(sendsOn)])) if (before[k] !== sendsOn[k]) redirectChanges[k] = sendsOn[k] ?? null;
2493
- });
2494
- if (pageFileText !== null) write({ path: PAGE_FILE, content: pageFileText });
2470
+ }, sendKey);
2471
+ const refused = writePageFile(pageFileText);
2472
+ if (refused) return refused;
2495
2473
  }
2496
2474
  if (collectionsAfter && JSON.stringify(collectionsAfter) !== JSON.stringify(collections)) {
2497
2475
  const sorted = Object.fromEntries(Object.entries(collectionsAfter).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0));
@@ -2796,7 +2774,7 @@ function folderDirs(at3, below) {
2796
2774
  }
2797
2775
  return dirs.size ? [...dirs].sort() : null;
2798
2776
  }
2799
- function planFolder(request, { framework, paths, text, discovered, importers: given }) {
2777
+ function planFolder(request, { framework, paths, text, discovered, importers: given, host = null }) {
2800
2778
  const adapter = adapterOf(framework);
2801
2779
  const no = (reason, detail) => ({ ok: (
2802
2780
  /** @type {const} */
@@ -2813,7 +2791,9 @@ function planFolder(request, { framework, paths, text, discovered, importers: gi
2813
2791
  const ownRedirects = siteRedirects({ framework, text });
2814
2792
  if (target !== at3 && (discovered.pages.some((p) => within2(p.path, target)) || [...ownRedirects].some((s) => sends(s, target)))) return no("taken", target);
2815
2793
  const live = request.live === true;
2816
- if (target !== at3 && live && (!kitRedirects({ framework, text }) || below.some((p) => p.router?.object))) return no("no_redirects");
2794
+ const mode = redirectMode({ framework, text, host, found: discovered });
2795
+ const sendKey = mode === "host" ? "hosted" : "redirects";
2796
+ if (target !== at3 && live && mode === null) return no(noRedirects({ framework, objects: below.some((p) => p.router?.object) }));
2817
2797
  const have = new Set(paths);
2818
2798
  const writes = /* @__PURE__ */ new Map();
2819
2799
  const write = (w) => writes.set(w.path, w);
@@ -2903,8 +2883,13 @@ function planFolder(request, { framework, paths, text, discovered, importers: gi
2903
2883
  if (name) folders[target] = { name };
2904
2884
  else delete folders[target];
2905
2885
  }
2906
- });
2907
- if (pageFileText !== null) write({ path: PAGE_FILE, content: pageFileText });
2886
+ }, sendKey);
2887
+ if (pageFileText !== null) {
2888
+ write({ path: PAGE_FILE, content: pageFileText });
2889
+ const mirror = sendKey === "hosted" ? hostedWrite(text, text(PAGE_FILE), pageFileText) : null;
2890
+ if (mirror && "error" in mirror) return no("invalid", mirror.error);
2891
+ if (mirror) write(mirror);
2892
+ }
2908
2893
  if (!writes.size) return no("same");
2909
2894
  const files = [...writes.values()].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
2910
2895
  const moves = target === at3 ? [] : [{ from: at3, to: target }, ...below.map((p) => ({ from: p.path, to: moveAddress(p.path, at3, target) }))];
@@ -2912,13 +2897,14 @@ function planFolder(request, { framework, paths, text, discovered, importers: gi
2912
2897
  const message = target === at3 ? `Unbase: rename ${at3}` : `Unbase: move ${at3} to ${target}`;
2913
2898
  return { ok: true, action: "rename", path: at3, to: target, files, redirects: redirectChanges, links: [...links].sort(), unlinked: [], moves, renamed, message, folder: true };
2914
2899
  }
2915
- function pageActions({ framework, paths, text, live = /* @__PURE__ */ new Set(), found, importers, details = {} }) {
2900
+ function pageActions({ framework, paths, text, live = /* @__PURE__ */ new Set(), found, importers, details = {}, host = null }) {
2916
2901
  const adapter = adapterOf(framework);
2917
2902
  const kept = paths.filter((p) => !SKIP2.test(p));
2918
2903
  const discovered = found ?? discover({ framework, paths: kept, text });
2919
2904
  const graph = importers ?? importGraph(kept, text);
2920
2905
  const pageFile = parsePageFile(text(PAGE_FILE));
2921
- const redirects = kitRedirects({ framework, text });
2906
+ const redirects = redirectMode({ framework, text, host, found: discovered }) !== null;
2907
+ const cannotMove = (objects) => noRedirects({ framework, objects: objects || discovered.pages.some((p) => p.router?.object) });
2922
2908
  const reads2 = siteReads(kept, text, graph);
2923
2909
  const out = {};
2924
2910
  const no = (reason, detail) => ({ ok: (
@@ -2951,7 +2937,7 @@ function pageActions({ framework, paths, text, live = /* @__PURE__ */ new Set(),
2951
2937
  continue;
2952
2938
  }
2953
2939
  const onLive = live.has(page.path);
2954
- let rename = page.path === "/" ? no("home") : onLive && (!redirects || page.router?.object) ? no("no_redirects", page.router?.object ? "route objects" : void 0) : yes;
2940
+ let rename = page.path === "/" ? no("home") : onLive && !redirects ? no(cannotMove(!!page.router?.object), page.router?.object ? "route objects" : void 0) : yes;
2955
2941
  if (rename.ok && adapter?.routeLines && !routePathAttr(text(page.router.file) ?? "", page.router)) rename = no("unparsed", "index route");
2956
2942
  const remove = page.path === "/" ? no("home") : below.length || page.reason === "nested" ? no("nested", below.map((p) => p.path).join(", ")) : yes;
2957
2943
  let duplicate = adapter?.routeLines && page.reason === "nested" ? no("nested") : yes;
@@ -2991,12 +2977,13 @@ function pageActions({ framework, paths, text, live = /* @__PURE__ */ new Set(),
2991
2977
  for (const at3 of folderPaths(discovered.pages)) {
2992
2978
  const below = discovered.pages.filter((p) => under(p.path, at3));
2993
2979
  let rename = !adapter?.acts ? no("framework") : !pageFile.ok ? no("invalid") : yes;
2994
- if (rename.ok && below.some((p) => live.has(p.path) || p.kind === "template") && (!redirects || below.some((p) => p.router?.object))) rename = no("no_redirects");
2980
+ if (rename.ok && below.some((p) => live.has(p.path) || p.kind === "template") && !redirects) rename = no(cannotMove(below.some((p) => p.router?.object)));
2995
2981
  if (rename.ok && adapter?.routeLines && below.some((p) => !p.router || !routePathAttr(text(p.router.file) ?? "", p.router))) rename = no("unparsed", "index route");
2996
2982
  if (rename.ok && !adapter?.routeLines && !(adapter?.folderDirs ?? folderDirs)(at3, below)) rename = no("unparsed", at3);
2997
2983
  folders[at3] = { rename, under: below.length };
2998
2984
  }
2999
- return { redirects, actions: out, folders, create: createCapability({ framework, paths: kept, text, found: discovered }) };
2985
+ const redirectsWhy = redirects ? null : cannotMove(false);
2986
+ return { redirects, redirectsWhy, actions: out, folders, create: createCapability({ framework, paths: kept, text, found: discovered }) };
3000
2987
  }
3001
2988
  function redirectsFor(framework, pageFile, pagePaths = []) {
3002
2989
  const pages = new Set(pagePaths.map(normalisePath));
@@ -3018,9 +3005,10 @@ function redirectsFor(framework, pageFile, pagePaths = []) {
3018
3005
  function siteRedirectList({ framework, text }) {
3019
3006
  const out = [];
3020
3007
  try {
3021
- const v = JSON.parse(text("vercel.json") ?? "null");
3008
+ const v = JSON.parse(text(VERCEL_JSON) ?? "null");
3009
+ const mine = hostedMirrors(text);
3022
3010
  for (const r of Array.isArray(v?.redirects) ? v.redirects : []) {
3023
- if (typeof r?.source === "string" && typeof r?.destination === "string") out.push({ from: r.source, to: r.destination, file: "vercel.json" });
3011
+ if (typeof r?.source === "string" && typeof r?.destination === "string" && !mine.has(vercelKey(r))) out.push({ from: r.source, to: r.destination, file: VERCEL_JSON });
3024
3012
  }
3025
3013
  } catch {
3026
3014
  }
@@ -3052,7 +3040,7 @@ function redirectEnd(p) {
3052
3040
  const base = normalisePath(prefix ? s.replace(REST, "").replace(/\/(…|\.\.\.|\*)$/, "") : s);
3053
3041
  return { base, prefix, key: prefix ? `${base === "/" ? "" : base}/[...path]` : base };
3054
3042
  }
3055
- function planRedirect(request, { framework, paths, text, found }) {
3043
+ function planRedirect(request, { framework, paths, text, found, host = null }) {
3056
3044
  const adapter = adapterOf(framework);
3057
3045
  const no = (reason, detail) => ({ ok: (
3058
3046
  /** @type {const} */
@@ -3065,23 +3053,27 @@ function planRedirect(request, { framework, paths, text, found }) {
3065
3053
  if (!pageFile.ok) return no("invalid", pageFile.error);
3066
3054
  const from = redirectEnd(request.from);
3067
3055
  const was = request.was != null ? redirectEnd(request.was) : from;
3068
- if (action !== "add" && !(was.key in pageFile.redirects)) return no("missing", was.key);
3056
+ const discoveredAll = found ?? discover({ framework, paths: paths.filter((p) => !SKIP2.test(p)), text });
3057
+ const mode = redirectMode({ framework, text, host, found: discoveredAll });
3058
+ const key = action !== "add" && was.key in pageFile.hosted ? "hosted" : action !== "add" && was.key in pageFile.redirects ? "redirects" : mode === "host" ? "hosted" : "redirects";
3059
+ const all = { ...pageFile.redirects, ...pageFile.hosted };
3060
+ if (action !== "add" && !(was.key in all)) return no("missing", was.key);
3069
3061
  const changes = {};
3070
3062
  let to = null;
3071
3063
  if (action !== "remove") {
3072
- if (!kitRedirects({ framework, text })) return no("no_redirects");
3064
+ if (mode === null || key === "hosted" !== (mode === "host")) return no(noRedirects({ framework, objects: discoveredAll.pages.some((p) => p.router?.object) }));
3073
3065
  if (from.base === "/" || !validAddress(from.base)) return no("address", request.from);
3074
3066
  const end = redirectEnd(request.to);
3075
3067
  if (!validAddress(end.base)) return no("address", request.to);
3076
- const discovered = found ?? discover({ framework, paths: paths.filter((p) => !SKIP2.test(p)), text });
3068
+ const discovered = discoveredAll;
3077
3069
  const isPage = (p) => discovered.pages.some((q) => q.kind === "template" ? templateMatches(q.path, p) : q.path === p);
3078
3070
  if (from.prefix ? discovered.pages.some((q) => within2(q.path, from.base)) : isPage(from.base)) return no("page", from.base);
3079
- if (from.key !== was.key && from.key in pageFile.redirects) return no("exists", from.key);
3080
- if (action === "add" && from.key in pageFile.redirects) return no("exists", from.key);
3071
+ if (from.key !== was.key && from.key in all) return no("exists", from.key);
3072
+ if (action === "add" && from.key in all) return no("exists", from.key);
3081
3073
  const own = [...siteRedirects({ framework, text })].find((s) => sends(s, from.base));
3082
3074
  if (own) return no("redirect_conflict", own);
3083
3075
  let dest = end.base;
3084
- const others = { ...pageFile.redirects };
3076
+ const others = { ...pageFile[key] };
3085
3077
  delete others[was.key];
3086
3078
  for (let hops = 0; hops < 20; hops++) {
3087
3079
  const next = Object.entries(others).find(([s]) => !REST.test(s) && s === dest);
@@ -3102,14 +3094,20 @@ function planRedirect(request, { framework, paths, text, found }) {
3102
3094
  }
3103
3095
  }
3104
3096
  for (const k of /* @__PURE__ */ new Set([...Object.keys(before), ...Object.keys(sendsOn)])) if (before[k] !== sendsOn[k]) changes[k] = sendsOn[k] ?? null;
3105
- });
3097
+ }, key);
3106
3098
  if (content === null) return no("same");
3099
+ const files = [{ path: PAGE_FILE, content }];
3100
+ if (key === "hosted") {
3101
+ const mirror = hostedWrite(text, text(PAGE_FILE), content);
3102
+ if (mirror && "error" in mirror) return no("invalid", mirror.error);
3103
+ if (mirror) files.push(mirror);
3104
+ }
3107
3105
  const shown2 = (k) => k.replace(REST, "/\u2026");
3108
3106
  const message = action === "remove" ? `Unbase: remove redirect ${shown2(was.key)}` : `Unbase: redirect ${shown2(from.key)} to ${shown2(to)}`;
3109
3107
  return { ok: (
3110
3108
  /** @type {const} */
3111
3109
  true
3112
- ), action, from: from.key, to, was: was.key, files: [{ path: PAGE_FILE, content }], redirects: changes, message };
3110
+ ), action, from: from.key, to, was: was.key, files, redirects: changes, message };
3113
3111
  }
3114
3112
 
3115
3113
  // supabase/functions/_shared/next-metadata.ts
@@ -3364,6 +3362,14 @@ function imageField(object) {
3364
3362
  if (url?.type === "string") return { pointer: `/metadata/${path}/url`, kind: "image", exists: true, value: url.value };
3365
3363
  return null;
3366
3364
  }
3365
+ function iconField(object) {
3366
+ const icons = object ? prop(object, "icons")?.value : void 0;
3367
+ if (icons === void 0) return { pointer: "/metadata/icons", kind: "image", exists: false, value: null };
3368
+ if (icons?.type === "string") return { pointer: "/metadata/icons", kind: "image", exists: true, value: icons.value };
3369
+ const icon = icons?.type === "object" ? prop(icons, "icon")?.value : void 0;
3370
+ if (icon?.type === "string") return { pointer: "/metadata/icons/icon", kind: "image", exists: true, value: icon.value };
3371
+ return null;
3372
+ }
3367
3373
  function noindexField(object) {
3368
3374
  const robots = object ? prop(object, "robots")?.value : void 0;
3369
3375
  if (robots === void 0) return { pointer: NOINDEX, kind: "boolean", exists: false, value: null };
@@ -3403,21 +3409,26 @@ function pageMetaFields(src) {
3403
3409
  }
3404
3410
  return { fields, refused: null, computed };
3405
3411
  }
3412
+ var TITLE_DEFAULT = "title/default";
3413
+ var SITE_NAME_PATHS = ["applicationName", "openGraph/siteName", TITLE_DEFAULT, "title"];
3406
3414
  function siteMetaFields(src) {
3407
3415
  const read = readMetadata(src);
3408
3416
  const lang = langOf(src);
3409
3417
  if (read.kind === "refused") return { fields: lang ? { language: lang.field } : {}, refused: read.reason, computed: {} };
3410
3418
  const object = read.kind === "literal" ? read.object : null;
3411
3419
  const wanted = {
3412
- // The name only where the code has it: a new one would change no title.
3413
- name: textField(object, ["applicationName", "openGraph/siteName"], null),
3420
+ // The name only where the code has it: a new one would change no title. Its application name or
3421
+ // share name first; else the layout's title, the one every page without its own shows: a string,
3422
+ // or `title.default` (whose `title.template` a new name follows: writeMetadata).
3423
+ name: textField(object, SITE_NAME_PATHS, null),
3414
3424
  description: textField(object, ["description"], "description"),
3415
3425
  socialImage: imageField(object),
3416
- language: lang?.field ?? null
3426
+ language: lang?.field ?? null,
3427
+ favicon: iconField(object)
3417
3428
  };
3418
3429
  const fields = {};
3419
3430
  const computed = {};
3420
- const named = !!object && ["applicationName", "openGraph/siteName"].some((p) => at(object, p.split("/")) !== void 0);
3431
+ const named = !!object && SITE_NAME_PATHS.some((p) => at(object, p.split("/")) !== void 0);
3421
3432
  for (const [k, f] of Object.entries(wanted)) {
3422
3433
  if (f) fields[k] = f;
3423
3434
  else if (k !== "name" || named) computed[k] = "computed";
@@ -3425,116 +3436,351 @@ function siteMetaFields(src) {
3425
3436
  return { fields, refused: null, computed };
3426
3437
  }
3427
3438
 
3428
- // supabase/functions/unbase-projects/settings-next.ts
3429
- var NEXT_AT_ONCE = 16;
3430
- function limited(n) {
3431
- let running = 0;
3432
- const waiting = [];
3433
- return async (work) => {
3434
- if (running < n) running++;
3435
- else await new Promise((go) => waiting.push(go));
3436
- try {
3437
- return await work();
3438
- } finally {
3439
- const next = waiting.shift();
3440
- if (next) next();
3441
- else running--;
3442
- }
3443
- };
3439
+ // supabase/functions/_shared/astro-meta.ts
3440
+ var PROP_OF = { socialImage: "image", noindex: "noindex" };
3441
+ var prop2 = (o, key) => [...o.props].reverse().find((p) => p.key === key);
3442
+ function frontmatter(src) {
3443
+ const open = /^\s*---[ \t]*\r?\n/.exec(src);
3444
+ if (!open) return null;
3445
+ const close = src.indexOf("\n---", open[0].length - 1);
3446
+ if (close < 0) return null;
3447
+ return { start: open[0].length, end: close + 1 };
3448
+ }
3449
+ function objectConst(src, name, from, to) {
3450
+ const code = codeOnly(src.slice(0, to));
3451
+ const re = new RegExp(`\\b(?:export\\s+)?(?:const|let|var)\\s+${name}\\b\\s*(?::[^=;]+?)?\\s*=`, "g");
3452
+ re.lastIndex = from;
3453
+ const m = re.exec(code);
3454
+ if (!m || m.index >= to) return null;
3455
+ const node = parseValue(src, m.index + m[0].length);
3456
+ return node.type === "object" ? node : "computed";
3457
+ }
3458
+ function fieldOf(o, key, pointer, add) {
3459
+ const p = prop2(o, key);
3460
+ if (!p) return add && !o.spread ? { pointer, exists: false, value: null } : null;
3461
+ return p.value?.type === "string" ? { pointer, exists: true, value: p.value.value } : "computed";
3462
+ }
3463
+ function layoutElement(src) {
3464
+ const fm = frontmatter(src);
3465
+ if (!fm) return null;
3466
+ const head = src.slice(fm.start, fm.end);
3467
+ const imports = /* @__PURE__ */ new Map();
3468
+ for (const m of head.matchAll(/import\s+([A-Z][\w$]*)\s+from\s*["']([^"']+\.astro)["']/g)) imports.set(m[1], m[2]);
3469
+ const body = fm.end + src.slice(fm.end).indexOf("---") + 3;
3470
+ const tag = /<([A-Z][\w$.]*)(?=[\s/>])/g;
3471
+ tag.lastIndex = body;
3472
+ for (let m = tag.exec(src); m; m = tag.exec(src)) {
3473
+ if (!imports.has(m[1])) continue;
3474
+ const parsed = attrsOf(src, m.index + m[0].length);
3475
+ if (!parsed) return null;
3476
+ return { name: m[1], file: imports.get(m[1]), start: m.index, end: parsed.end, attrs: parsed.attrs };
3477
+ }
3478
+ return null;
3444
3479
  }
3445
- var NEXT_PAGE = /^(src\/)?app\/(.*\/)?page\.(tsx|ts|jsx|js)$/;
3446
- var NEXT_ROOT_LAYOUT = /^(src\/)?app\/layout\.(tsx|ts|jsx|js)$/;
3447
- var CMS_DEPTH = 2;
3448
- var NEXT_PAGE_FIELDS = { title: "title", description: "description", socialImage: "socialImage", noindex: "noindex" };
3449
- var NEXT_SITE_FIELDS = { name: "name", description: "description", socialImage: "socialImage", language: "language" };
3450
- var settingOf = (file, f) => ({ file, pointer: f.pointer, kind: f.kind, exists: f.exists, value: f.value });
3451
- var drawnImage = (file, have) => {
3452
- const dir = file.replace(/[^/]*$/, "");
3453
- return [...have].some((p) => p.startsWith(dir) && /^opengraph-image\d*\.[a-z]+$/.test(p.slice(dir.length)));
3454
- };
3455
- var resolveIn = (from, spec, have) => resolveImport(from, spec, have) ?? (spec.startsWith("@/") ? resolveImport("", `./${spec.slice(2)}`, have) : null);
3456
- async function nextSettings(repo, appPath) {
3457
- const root = appPath ? `${appPath}/` : "";
3458
- const paths = repo.paths.filter((p) => p.startsWith(root)).map((p) => p.slice(root.length));
3459
- const have = new Set(paths);
3460
- const texts = /* @__PURE__ */ new Map();
3461
- const turn = limited(NEXT_AT_ONCE);
3462
- const read = (p) => {
3463
- if (!texts.has(p)) texts.set(p, turn(() => repo.read(join(appPath, p))));
3464
- return texts.get(p);
3465
- };
3466
- const { pages: found } = discover({ framework: "next", paths, text: () => null });
3467
- const pages = found.filter((p) => p.kind === "file" && p.file).slice(0, MAX_ROUTE_FILES);
3468
- const layout = paths.find((p) => NEXT_ROOT_LAYOUT.test(p)) ?? null;
3469
- if (!pages.some((p) => NEXT_PAGE.test(p.file)) && !layout) return null;
3470
- const readsCms = async (file, depth = CMS_DEPTH, seen = /* @__PURE__ */ new Set()) => {
3471
- if (seen.has(file)) return false;
3472
- seen.add(file);
3473
- const src = await read(file);
3474
- if (!src) return false;
3475
- const specs = importsOf(src);
3476
- if (specs.some(isCmsModule)) return true;
3477
- if (!depth) return false;
3478
- const targets = specs.map((s) => resolveIn(file, s, have)).filter((t) => t !== null);
3479
- return (await Promise.all(targets.map((t) => readsCms(t, depth - 1, seen)))).some(Boolean);
3480
- };
3481
- const reasonOf = async (file, reason) => reason === "computed" && /\bgenerateMetadata\b/.test(await read(file) ?? "") && await readsCms(file) ? "cms" : reason;
3482
- const out = {};
3483
- const refused = {};
3484
- const [answers, layoutRead] = await Promise.all([
3485
- Promise.all(
3486
- pages.map(async (p) => {
3487
- const file = p.file;
3488
- if (!NEXT_PAGE.test(file)) return { p, file, read: null, reason: null };
3489
- const src = await read(file);
3490
- const r = src === null ? null : pageMetaFields(src);
3491
- return { p, file, read: r, reason: r?.refused ? await reasonOf(file, r.refused) : null };
3492
- })
3493
- ),
3494
- layout ? read(layout).then(async (src) => {
3495
- const r = src === null ? null : siteMetaFields(src);
3496
- return { read: r, reason: r?.refused ? await reasonOf(layout, r.refused) : null };
3497
- }) : null
3498
- ]);
3499
- for (const { p, file, read: r, reason } of answers) {
3500
- if (!r) {
3501
- refused[p.path] = { file, reason: "unsupported" };
3480
+ function attrsOf(src, i) {
3481
+ const attrs = [];
3482
+ for (; ; ) {
3483
+ i = skip(src, i);
3484
+ if (src[i] === ">") return { attrs, end: i, selfClosing: false };
3485
+ if (src.startsWith("/>", i)) return { attrs, end: i, selfClosing: true };
3486
+ if (src[i] === "{") {
3487
+ const close = braceEnd(src, i);
3488
+ if (close < 0) return null;
3489
+ i = close + 1;
3502
3490
  continue;
3503
3491
  }
3504
- if (r.refused) {
3505
- refused[p.path] = { file, reason: reason ?? r.refused };
3492
+ const name = /^[A-Za-z_:@][\w:.-]*/.exec(src.slice(i, i + 128))?.[0];
3493
+ if (!name) return null;
3494
+ const start = i;
3495
+ i += name.length;
3496
+ let j = skip(src, i);
3497
+ if (src[j] !== "=") {
3498
+ attrs.push({ name, start, end: i, value: null });
3506
3499
  continue;
3507
3500
  }
3508
- if (r.fields.socialImage && drawnImage(file, have)) {
3509
- delete r.fields.socialImage;
3510
- r.computed.socialImage = "computed";
3501
+ j = skip(src, j + 1);
3502
+ const q = src[j];
3503
+ if (q === '"' || q === "'" || q === "`") {
3504
+ const close = src.indexOf(q, j + 1);
3505
+ if (close < 0) return null;
3506
+ attrs.push({ name, start, end: close + 1, value: { kind: "string", inner: { start: j + 1, end: close }, quote: q, text: src.slice(j + 1, close) } });
3507
+ i = close + 1;
3508
+ } else if (q === "{") {
3509
+ const close = braceEnd(src, j);
3510
+ if (close < 0) return null;
3511
+ const node = parseValue(src, j + 1);
3512
+ const literalValue2 = node.type === "string" && node.quote !== "`" && skip(src, node.end) === close ? node.value : null;
3513
+ attrs.push({ name, start, end: close + 1, value: { kind: "expr", literal: literalValue2, start: j, end: close + 1 } });
3514
+ i = close + 1;
3515
+ } else return null;
3516
+ }
3517
+ }
3518
+ function braceEnd(src, i) {
3519
+ let depth = 0;
3520
+ for (let j = i; j < src.length; j++) {
3521
+ const c = src[j];
3522
+ if (c === '"' || c === "'" || c === "`") {
3523
+ const close = src.indexOf(c, j + 1);
3524
+ if (close < 0) return -1;
3525
+ j = close;
3526
+ } else if (c === "{") depth++;
3527
+ else if (c === "}" && --depth === 0) return j;
3528
+ }
3529
+ return -1;
3530
+ }
3531
+ function layoutProps(src) {
3532
+ const fm = frontmatter(src);
3533
+ if (!fm) return null;
3534
+ const code = codeOnly(src.slice(0, fm.end));
3535
+ const m = /\b(?:const|let|var)\s*\{/g;
3536
+ m.lastIndex = fm.start;
3537
+ for (let hit = m.exec(code); hit; hit = m.exec(code)) {
3538
+ const open = hit.index + hit[0].length - 1;
3539
+ const close = braceEnd(src, open);
3540
+ if (close < 0 || !/^\s*\}\s*=\s*Astro\.props\b/.test(src.slice(close))) continue;
3541
+ const out = /* @__PURE__ */ new Map();
3542
+ let i = open + 1;
3543
+ while (i < close) {
3544
+ i = skip(src, i);
3545
+ const key = /^(?:\.\.\.)?[A-Za-z_$][\w$]*/.exec(src.slice(i, close))?.[0];
3546
+ if (!key) break;
3547
+ i += key.length;
3548
+ i = skip(src, i);
3549
+ if (src[i] === ":") {
3550
+ i = skip(src, i + 1);
3551
+ if (src[i] === "{" || src[i] === "[") i = braceEnd(src.replace(/\[/g, "{").replace(/\]/g, "}"), i) + 1;
3552
+ else i += /^[A-Za-z_$][\w$]*/.exec(src.slice(i))?.[0].length ?? 0;
3553
+ i = skip(src, i);
3554
+ }
3555
+ let def = { default: null };
3556
+ if (src[i] === "=") {
3557
+ i = skip(src, i + 1);
3558
+ const value = parseValue(src, i);
3559
+ if (value.type === "string") def = { default: value.value, start: value.inner.start, end: value.inner.end, quote: value.quote };
3560
+ i = value.end;
3561
+ }
3562
+ if (!key.startsWith("...")) out.set(key, def);
3563
+ i = skip(src, i);
3564
+ if (src[i] === ",") i++;
3511
3565
  }
3512
- const fields = {};
3513
- for (const [k, f] of Object.entries(r.fields)) if (f) fields[NEXT_PAGE_FIELDS[k]] = settingOf(file, f);
3514
- out[p.path] = fields;
3515
- const computed = Object.entries(r.computed).map(([k, why]) => [NEXT_PAGE_FIELDS[k], why]);
3516
- if (computed.length) refused[p.path] = { file, reason: "computed", fields: Object.fromEntries(computed) };
3566
+ return out;
3517
3567
  }
3518
- let site = null;
3519
- if (layout && layoutRead) {
3520
- const r = layoutRead.read;
3521
- if (r?.fields.socialImage && drawnImage(layout, have)) {
3522
- delete r.fields.socialImage;
3523
- r.computed.socialImage = "computed";
3568
+ return null;
3569
+ }
3570
+ function astroPageFields(src, accepts) {
3571
+ const fields = {};
3572
+ const computed = {};
3573
+ const fm = frontmatter(src);
3574
+ const el = layoutElement(src);
3575
+ const meta = fm ? objectConst(src, "metadata", fm.start, fm.end) : null;
3576
+ const handed = !!el && el.attrs.some((a) => a.name === "metadata" && a.value?.kind === "expr" && /^\s*\{\s*metadata\s*\}\s*$/.test(src.slice(a.value.start, a.value.end)));
3577
+ for (const f of ["title", "description"]) {
3578
+ if (meta && meta !== "computed" && handed) {
3579
+ const got = fieldOf(meta, f, `/astro/metadata/${f}`, true);
3580
+ if (got === "computed") computed[f] = "computed";
3581
+ else if (got) fields[f] = got;
3582
+ continue;
3524
3583
  }
3525
- if (r) {
3526
- const fields = {};
3527
- for (const [k, f] of Object.entries(r.fields)) if (f) fields[NEXT_SITE_FIELDS[k]] = settingOf(layout, f);
3528
- if (Object.keys(fields).length) site = fields;
3529
- const computed = Object.entries(r.computed).map(([k, why]) => [NEXT_SITE_FIELDS[k], why]);
3530
- if (r.refused) refused.site = { file: layout, reason: layoutRead.reason ?? r.refused };
3531
- else if (computed.length) refused.site = { file: layout, reason: "computed", fields: Object.fromEntries(computed) };
3584
+ const attr = el?.attrs.find((a) => a.name === f);
3585
+ if (attr?.value?.kind === "string") fields[f] = { pointer: `/astro/props/${f}`, exists: true, value: attr.value.text };
3586
+ else if (attr?.value?.kind === "expr") {
3587
+ if (attr.value.literal !== null) fields[f] = { pointer: `/astro/props/${f}`, exists: true, value: attr.value.literal };
3588
+ else computed[f] = "computed";
3589
+ } else if (el && accepts?.has(f)) fields[f] = { pointer: `/astro/props/${f}`, exists: false, value: null };
3590
+ }
3591
+ if (!(meta && meta !== "computed" && handed)) {
3592
+ const image = el?.attrs.find((a) => a.name === PROP_OF.socialImage);
3593
+ const pointer = `/astro/props/${PROP_OF.socialImage}`;
3594
+ if (image?.value?.kind === "string") fields.socialImage = { pointer, exists: true, value: image.value.text };
3595
+ else if (image?.value?.kind === "expr") {
3596
+ if (image.value.literal !== null) fields.socialImage = { pointer, exists: true, value: image.value.literal };
3597
+ else computed.socialImage = "computed";
3598
+ } else if (el && !image && accepts?.has(PROP_OF.socialImage)) fields.socialImage = { pointer, exists: false, value: null };
3599
+ const flag = el?.attrs.find((a) => a.name === PROP_OF.noindex);
3600
+ const at3 = `/astro/props/${PROP_OF.noindex}`;
3601
+ const said = flag?.value?.kind === "expr" ? src.slice(flag.value.start + 1, flag.value.end - 1).trim() : null;
3602
+ if (flag && flag.value === null) fields.noindex = { pointer: at3, exists: true, value: "true" };
3603
+ else if (said === "true" || said === "false") fields.noindex = { pointer: at3, exists: true, value: said };
3604
+ else if (flag) computed.noindex = "computed";
3605
+ else if (el && accepts?.has(PROP_OF.noindex)) fields.noindex = { pointer: at3, exists: false, value: null };
3606
+ }
3607
+ return { fields, computed, layout: el?.file ?? null };
3608
+ }
3609
+ function layoutDefaults(src) {
3610
+ const props = layoutProps(src);
3611
+ const out = {};
3612
+ const title = props?.get("title");
3613
+ const description = props?.get("description");
3614
+ if (title?.default != null) out.name = { pointer: "/astro/default/title", exists: true, value: title.default };
3615
+ if (description?.default != null) out.description = { pointer: "/astro/default/description", exists: true, value: description.default };
3616
+ return out;
3617
+ }
3618
+ function layoutModuleRefs(src) {
3619
+ const fm = frontmatter(src);
3620
+ if (!fm) return [];
3621
+ const head = src.slice(fm.start, fm.end);
3622
+ const out = [];
3623
+ for (const m of head.matchAll(/import\s*\{([^}]+)\}\s*from\s*["'](\.{1,2}\/[^"']+|~\/[^"']+|@\/[^"']+)["']/g)) {
3624
+ for (const part of m[1].split(",")) {
3625
+ const [orig, alias] = part.trim().split(/\s+as\s+/);
3626
+ const local = (alias ?? orig ?? "").trim();
3627
+ if (!local) continue;
3628
+ const used = (k) => new RegExp(`\\b${local}\\.${k}\\b`).test(src);
3629
+ const name = ["name", "title", "siteName"].find(used) ?? null;
3630
+ const description = used("description") ? "description" : null;
3631
+ if (name || description) out.push({ exportName: (orig ?? local).trim(), spec: m[2], name, description });
3532
3632
  }
3533
3633
  }
3534
- return { pages: out, routes: null, site, refused };
3634
+ return out;
3635
+ }
3636
+ function moduleField(src, exportName, key) {
3637
+ const o = objectConst(src, exportName, 0, src.length);
3638
+ if (!o) return null;
3639
+ if (o === "computed") return "computed";
3640
+ const exported = new RegExp(`\\bexport\\s+(?:const|let|var)\\s+${exportName}\\b|\\bexport\\s*\\{[^}]*\\b${exportName}\\b`).test(codeOnly(src));
3641
+ if (!exported) return null;
3642
+ return fieldOf(o, key, `/module/${exportName}/${key}`, false);
3643
+ }
3644
+ function yamlScalar(src, parent, key) {
3645
+ const lines = src.split("\n");
3646
+ let offset = 0;
3647
+ let inside = false;
3648
+ for (const line of lines) {
3649
+ const start = offset;
3650
+ offset += line.length + 1;
3651
+ if (/^\S/.test(line)) {
3652
+ inside = new RegExp(`^${parent}:\\s*(#.*)?$`).test(line);
3653
+ continue;
3654
+ }
3655
+ if (!inside) continue;
3656
+ const m = new RegExp(`^(\\s+)${key}:[ \\t]*`).exec(line);
3657
+ if (!m) continue;
3658
+ const at3 = start + m[0].length;
3659
+ const rest = line.slice(m[0].length);
3660
+ if (!rest.trim() || /^[|>&*!\[{]/.test(rest)) return "computed";
3661
+ const q = rest[0];
3662
+ if (q === '"' || q === "'") {
3663
+ const close = q === '"' ? /^"((?:\\.|[^"\\])*)"/.exec(rest) : /^'((?:''|[^'])*)'/.exec(rest);
3664
+ if (!close) return "computed";
3665
+ const value = q === '"' ? JSON.parse(`"${close[1]}"`) : close[1].replace(/''/g, "'");
3666
+ return { start: at3, end: at3 + close[0].length, value, style: q };
3667
+ }
3668
+ const plain2 = rest.replace(/\s+#.*$/, "").trimEnd();
3669
+ return { start: at3, end: at3 + plain2.length, value: plain2, style: "plain" };
3670
+ }
3671
+ return null;
3672
+ }
3673
+ function yamlField(src, parent, key) {
3674
+ const s = yamlScalar(src, parent, key);
3675
+ if (s === null || s === "computed") return s;
3676
+ return { pointer: `/yaml/${parent}/${key}`, exists: true, value: s.value };
3535
3677
  }
3536
3678
 
3537
- // supabase/functions/_shared/html-head.ts
3679
+ // supabase/functions/unbase-projects/settings-content.ts
3680
+ var PAGE_FIELDS = {
3681
+ title: { name: "titel", kind: "text" },
3682
+ description: { name: "beschrijving", kind: "text" },
3683
+ socialImage: { name: "ogImage", kind: "image" },
3684
+ noindex: { name: "noindex", kind: "boolean" },
3685
+ siteSearch: { name: "zoeken", kind: "boolean" }
3686
+ };
3687
+ var SITE_FIELDS = {
3688
+ name: { name: "naam", kind: "text" },
3689
+ description: { name: "beschrijving", kind: "text" },
3690
+ language: { name: "taal", kind: "text" },
3691
+ faviconLight: { name: "favicon", kind: "image" },
3692
+ faviconDark: { name: "faviconDonker", kind: "image" },
3693
+ socialImage: { name: "ogImage", kind: "image" },
3694
+ analyticsId: { name: "googleAnalytics", kind: "text" }
3695
+ };
3696
+ var CONTENT = "src/content";
3697
+ var SCHEMAS = `${CONTENT}/.schemas`;
3698
+ var ROUTE = /^\/([^/]+(\/[^/]+)*)?$/;
3699
+ var AT_ONCE2 = 8;
3700
+ var MAX_ROUTE_FILES = 300;
3701
+ async function inTurns(items, work) {
3702
+ const out = new Array(items.length);
3703
+ let next = 0;
3704
+ await Promise.all(
3705
+ Array.from({ length: Math.min(AT_ONCE2, items.length) }, async () => {
3706
+ while (next < items.length) {
3707
+ const i = next++;
3708
+ out[i] = await work(items[i]);
3709
+ }
3710
+ })
3711
+ );
3712
+ return out;
3713
+ }
3714
+ var parse = (text) => {
3715
+ if (text === null) return null;
3716
+ try {
3717
+ return JSON.parse(text);
3718
+ } catch {
3719
+ return null;
3720
+ }
3721
+ };
3722
+ function valueOf(v, kind) {
3723
+ if (kind === "boolean") return typeof v === "boolean" ? String(v) : null;
3724
+ return typeof v === "string" ? v : null;
3725
+ }
3726
+ function fieldsOf(names, data, allowed, file, base) {
3727
+ const fields = {};
3728
+ for (const [field2, { name, kind }] of Object.entries(names)) {
3729
+ const value = valueOf(data?.[name], kind);
3730
+ const there = data?.[name] !== void 0;
3731
+ if (there && value === null) continue;
3732
+ if (!there && !allowed[name]) continue;
3733
+ fields[field2] = { file, pointer: `${base}/${name}`, kind, exists: there, value };
3734
+ }
3735
+ return fields;
3736
+ }
3737
+ async function contentSettings(repo, appPath) {
3738
+ const at3 = (p) => join(appPath, p);
3739
+ const schemaPaths = repo.paths.filter((p) => p.startsWith(`${at3(SCHEMAS)}/`) && p.endsWith(".schema.json"));
3740
+ if (!schemaPaths.length) return null;
3741
+ const named = (p) => p.slice(at3(SCHEMAS).length + 1, -".schema.json".length);
3742
+ const schemas = /* @__PURE__ */ new Map();
3743
+ const [legacyMap, map, ...read] = await inTurns([at3(`${SCHEMAS}/collecties.json`), at3(`${SCHEMAS}/collections.json`), ...schemaPaths], (p) => repo.read(p));
3744
+ schemaPaths.forEach((p, i) => {
3745
+ const s = parse(read[i] ?? null);
3746
+ if (s && typeof s === "object") schemas.set(named(p), s);
3747
+ });
3748
+ const elsewhere = { ...parse(legacyMap ?? null) ?? {}, ...parse(map ?? null) ?? {} };
3749
+ const jsonFiles = repo.paths.filter((p) => p.startsWith(`${at3(CONTENT)}/`) && p.endsWith(".json") && !p.startsWith(`${at3(SCHEMAS)}/`));
3750
+ const collectionOf = (p) => elsewhere[p.slice(appPath ? appPath.length + 1 : 0)] ?? p.slice(at3(CONTENT).length + 1).split("/")[0].replace(/\.json$/, "");
3751
+ const filesOf = (collection) => jsonFiles.filter((p) => collectionOf(p) === collection);
3752
+ const routeCollection = [...schemas].find(([, s]) => s.properties?.pad && s.properties?.seo);
3753
+ const pages = {};
3754
+ let routes = null;
3755
+ if (routeCollection) {
3756
+ const [collection, schema] = routeCollection;
3757
+ const allowed = schema.properties.seo?.properties ?? {};
3758
+ const files = filesOf(collection).slice(0, MAX_ROUTE_FILES);
3759
+ const datas = await inTurns(files, async (p) => parse(await repo.read(p)));
3760
+ files.forEach((file, i) => {
3761
+ const data = datas[i];
3762
+ if (!data || typeof data.pad !== "string" || !ROUTE.test(data.pad)) return;
3763
+ const seo = data.seo && typeof data.seo === "object" && !Array.isArray(data.seo) ? data.seo : {};
3764
+ pages[data.pad] = fieldsOf(PAGE_FIELDS, seo, allowed, file.slice(appPath ? appPath.length + 1 : 0), "/seo");
3765
+ });
3766
+ const dir = files[0] ? files[0].slice(appPath ? appPath.length + 1 : 0).replace(/\/[^/]+$/, "") : `${CONTENT}/${collection}`;
3767
+ const fields = Object.entries(PAGE_FIELDS).filter(([, { name }]) => allowed[name]).map(([field2, { name, kind }]) => ({ field: field2, pointer: `/seo/${name}`, kind }));
3768
+ routes = { dir, fields, ...schema["x-item-fields"] === true ? { itemFields: true } : {} };
3769
+ }
3770
+ const siteCollection = [...schemas].find(([, s]) => (s["x-settings"] ?? s["x-instellingen"]) === "site");
3771
+ let site = null;
3772
+ const siteFile = siteCollection && filesOf(siteCollection[0])[0];
3773
+ if (siteCollection && siteFile) {
3774
+ const data = parse(await repo.read(siteFile));
3775
+ if (data && typeof data === "object" && !Array.isArray(data)) {
3776
+ site = fieldsOf(SITE_FIELDS, data, siteCollection[1].properties ?? {}, siteFile.slice(appPath ? appPath.length + 1 : 0), "");
3777
+ }
3778
+ }
3779
+ if (!Object.keys(pages).length && !routes && !site) return null;
3780
+ return { pages, routes, site };
3781
+ }
3782
+
3783
+ // supabase/functions/_shared/html-head.ts
3538
3784
  var headPointer = (field2) => `/head/${field2}`;
3539
3785
  var ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: " " };
3540
3786
  function decodeValue(raw) {
@@ -3604,15 +3850,15 @@ function tagsIn(html, from, until) {
3604
3850
  var attrOf = (tag, name) => tag.attrs.find((a) => a.name === name);
3605
3851
  var spanOf = (a) => ({ start: a.start, end: a.end, mode: "attr", quote: a.quote });
3606
3852
  var plain = (raw) => !/[{}]|<%|%>/.test(raw);
3607
- function readHead(html) {
3853
+ function readHead(html, opts = {}) {
3608
3854
  const out = {};
3609
3855
  const lower = html.toLowerCase();
3610
- const headAt = lower.search(/<head[\s>]/);
3856
+ const headAt = opts.anywhere ? 0 : lower.search(/<head[\s>]/);
3611
3857
  const bodyAt = lower.search(/<body[\s>]/);
3612
3858
  const headEnd = lower.indexOf("</head");
3613
- const until = headEnd >= 0 ? headEnd : bodyAt >= 0 ? bodyAt : html.length;
3859
+ const until = opts.anywhere ? html.length : headEnd >= 0 ? headEnd : bodyAt >= 0 ? bodyAt : html.length;
3614
3860
  if (headAt < 0) return out;
3615
- const htmlTag = tagsIn(html, 0, headAt).find((t) => t.name === "html");
3861
+ const htmlTag = opts.anywhere ? void 0 : tagsIn(html, 0, headAt).find((t) => t.name === "html");
3616
3862
  const lang = htmlTag && attrOf(htmlTag, "lang");
3617
3863
  if (lang && lang.value.trim() && plain(lang.value)) out.language = { value: decodeValue(lang.value), spans: [spanOf(lang)] };
3618
3864
  const tags = tagsIn(html, headAt, until);
@@ -3637,6 +3883,12 @@ function readHead(html) {
3637
3883
  }
3638
3884
  const description = fromMeta("description", ["og:description", "twitter:description"]);
3639
3885
  if (description) out.description = description;
3886
+ const robots = meta("robots");
3887
+ if (robots.length === 1 && plain(robots[0].value)) {
3888
+ const raw = decodeValue(robots[0].value);
3889
+ out.noindex = { value: String(robotsWords(raw).includes("noindex")), spans: [spanOf(robots[0])], raw };
3890
+ }
3891
+ if (opts.anywhere) return out;
3640
3892
  const image = fromMeta("og:image", ["twitter:image"]);
3641
3893
  if (image) out.image = image;
3642
3894
  const icons = tags.filter((t) => t.name === "link" && (attrOf(t, "rel")?.value ?? "").toLowerCase().split(/\s+/).includes("icon"));
@@ -3648,10 +3900,469 @@ function readHead(html) {
3648
3900
  }
3649
3901
  return out;
3650
3902
  }
3903
+ var robotsWords = (content) => content.split(",").map((w) => w.trim().toLowerCase()).filter(Boolean);
3904
+ function skipCode(src, i) {
3905
+ const c = src[i];
3906
+ if (c === "/" && src[i + 1] === "/") {
3907
+ const e = src.indexOf("\n", i);
3908
+ return e < 0 ? src.length : e + 1;
3909
+ }
3910
+ if (c === "/" && src[i + 1] === "*") {
3911
+ const e = src.indexOf("*/", i + 2);
3912
+ return e < 0 ? -1 : e + 2;
3913
+ }
3914
+ for (let j = i + 1; j < src.length; j++) {
3915
+ const d = src[j];
3916
+ if (d === "\\") j++;
3917
+ else if (d === c) return j + 1;
3918
+ else if (d === "\n" && c !== "`") return -1;
3919
+ else if (c === "`" && d === "$" && src[j + 1] === "{") {
3920
+ let depth = 0;
3921
+ for (j += 1; j < src.length; j++) {
3922
+ if (src[j] === "{") depth++;
3923
+ else if (src[j] === "}" && --depth === 0) break;
3924
+ }
3925
+ }
3926
+ }
3927
+ return -1;
3928
+ }
3929
+ function closing2(src, open) {
3930
+ const pair = src[open] === "(" ? ["(", ")"] : ["{", "}"];
3931
+ let depth = 0;
3932
+ for (let i = open; i < src.length; i++) {
3933
+ const c = src[i];
3934
+ if (c === '"' || c === "'" || c === "`" || c === "/" && (src[i + 1] === "/" || src[i + 1] === "*")) {
3935
+ const e = skipCode(src, i);
3936
+ if (e < 0) return -1;
3937
+ i = e - 1;
3938
+ continue;
3939
+ }
3940
+ if (c === pair[0]) depth++;
3941
+ else if (c === pair[1] && --depth === 0) return i;
3942
+ }
3943
+ return -1;
3944
+ }
3945
+ var skipSpace = (src, i) => {
3946
+ while (i < src.length && /\s/.test(src[i])) i++;
3947
+ return i;
3948
+ };
3949
+ function insideRoot(src, i) {
3950
+ i = skipSpace(src, i);
3951
+ if (src[i] === "(") i = skipSpace(src, i + 1);
3952
+ if (src[i] !== "<") return null;
3953
+ const lineStart = src.lastIndexOf("\n", i) + 1;
3954
+ const own = /^[ \t]*/.exec(src.slice(lineStart))[0];
3955
+ if (src[i + 1] === ">") return { at: i + 2, indent: `${own} ` };
3956
+ if (!/^<[A-Za-z][\w.:-]*/.test(src.slice(i, i + 64))) return null;
3957
+ for (let j = i + 1; j < src.length; j++) {
3958
+ const c = src[j];
3959
+ if (c === '"' || c === "'") {
3960
+ const e = src.indexOf(c, j + 1);
3961
+ if (e < 0) return null;
3962
+ j = e;
3963
+ } else if (c === "{") {
3964
+ const e = closing2(src, j);
3965
+ if (e < 0) return null;
3966
+ j = e;
3967
+ } else if (c === "/" && src[j + 1] === ">") return null;
3968
+ else if (c === ">") return { at: j + 1, indent: `${own} ` };
3969
+ }
3970
+ return null;
3971
+ }
3972
+ function topReturn(src, open) {
3973
+ let depth = 0;
3974
+ for (let i = open; i < src.length; i++) {
3975
+ const c = src[i];
3976
+ if (c === '"' || c === "'" || c === "`" || c === "/" && (src[i + 1] === "/" || src[i + 1] === "*")) {
3977
+ const e = skipCode(src, i);
3978
+ if (e < 0) return null;
3979
+ i = e - 1;
3980
+ continue;
3981
+ }
3982
+ if (c === "{") depth++;
3983
+ else if (c === "}" && --depth === 0) return null;
3984
+ else if (depth === 1 && src.startsWith("return", i) && !/[\w$]/.test(src[i - 1] ?? "") && !/[\w$]/.test(src[i + 6] ?? "")) {
3985
+ const j = skipSpace(src, i + 6);
3986
+ if (src[j] === "(" || src[j] === "<") return j;
3987
+ }
3988
+ }
3989
+ return null;
3990
+ }
3991
+ function bodyAfter(src, paren, arrow) {
3992
+ const close = closing2(src, paren);
3993
+ if (close < 0) return null;
3994
+ let i = close + 1;
3995
+ const brace = src.indexOf(arrow ? "=>" : "{", i);
3996
+ if (brace < 0) return null;
3997
+ if (!arrow) return { block: brace };
3998
+ i = skipSpace(src, brace + 2);
3999
+ return src[i] === "{" ? { block: i } : { concise: i };
4000
+ }
4001
+ function componentRootAt(src) {
4002
+ let fn = null;
4003
+ const direct = /\bexport\s+default\s+(?:async\s+)?function\b\s*[A-Za-z_$]?[\w$]*\s*\(/.exec(src);
4004
+ if (direct) fn = bodyAfter(src, direct.index + direct[0].length - 1, false);
4005
+ else {
4006
+ const ref = /\bexport\s+default\s+([A-Za-z_$][\w$]*)\s*;?\s*$/m.exec(src)?.[1];
4007
+ if (!ref) return null;
4008
+ const decl = new RegExp(`\\bfunction\\s+${ref}\\s*\\(`).exec(src);
4009
+ if (decl) fn = bodyAfter(src, decl.index + decl[0].length - 1, false);
4010
+ else {
4011
+ const arrow = new RegExp(`\\b(?:const|let|var)\\s+${ref}\\s*(?::[^=]+)?=\\s*(?:async\\s*)?\\(`).exec(src);
4012
+ if (!arrow) return null;
4013
+ fn = bodyAfter(src, arrow.index + arrow[0].length - 1, true);
4014
+ }
4015
+ }
4016
+ if (!fn) return null;
4017
+ if ("concise" in fn) return insideRoot(src, fn.concise);
4018
+ const jsx = topReturn(src, fn.block);
4019
+ return jsx === null ? null : insideRoot(src, jsx);
4020
+ }
4021
+ var addable = (field2, opts) => field2 === "title" || field2 === "description" || field2 === "noindex" || field2 === "image" && !opts.anywhere;
3651
4022
 
3652
- // supabase/functions/unbase-projects/settings-vite.ts
3653
- var VITE_DOCUMENT = "index.html";
4023
+ // supabase/functions/_shared/settings-documents.ts
4024
+ var VITE_DOCUMENT = /(^|\/)index\.html$/;
4025
+ var COMPONENT = /^(src\/)?(?!.*(^|\/)\.)[A-Za-z0-9_@()[\] ./-]*\.(jsx|tsx)$/;
4026
+ var PAGES_ROUTER = /^(src\/)?pages\/(?!api\/)(?!.*(^|\/)\.)[A-Za-z0-9_@()[\] ./-]*\.(jsx|tsx|js|ts)$/;
4027
+ var HTML2 = /^(?!.*(^|\/)\.)[A-Za-z0-9_@()[\] ./-]*\.html?$/;
4028
+ var ASTRO_FILE = /^(src\/)?(?!.*(^|\/)\.)[A-Za-z0-9_@()[\] ./-]*\.astro$/;
4029
+ var HEAD_DOCUMENTS = {
4030
+ "vite-react": (file) => VITE_DOCUMENT.test(file) ? {} : COMPONENT.test(file) ? { anywhere: true, jsx: true, add: true } : null,
4031
+ html: (file) => HTML2.test(file) ? { add: true } : null,
4032
+ next: (file) => PAGES_ROUTER.test(file) ? { jsx: true, add: true } : null,
4033
+ astro: (file) => ASTRO_FILE.test(file) ? {} : null
4034
+ };
4035
+ function headOptionsOf(framework, file) {
4036
+ if (!framework || !Object.hasOwn(HEAD_DOCUMENTS, framework) || file.split("/").includes("..")) return null;
4037
+ return HEAD_DOCUMENTS[framework](file);
4038
+ }
4039
+
4040
+ // supabase/functions/unbase-projects/settings-astro.ts
4041
+ var READ_AT_ONCE = 16;
4042
+ var YAML_CONFIGS = ["src/config.yaml", "src/config.yml", "config.yaml"];
4043
+ var KIND = { title: "text", description: "text", socialImage: "image", noindex: "boolean", siteSearch: "boolean" };
4044
+ var settingOf = (file, f, kind = "text") => ({ file, pointer: f.pointer, kind, exists: f.exists, value: f.value });
3654
4045
  var HEAD_SETTINGS = [
4046
+ ["faviconLight", "favicon"],
4047
+ ["faviconDark", "faviconDark"],
4048
+ ["socialImage", "image"]
4049
+ ];
4050
+ function resolve(from, spec, have) {
4051
+ if (/^[~@]\//.test(spec)) return resolveImport("", `./src/${spec.slice(2)}`, have);
4052
+ return resolveImport(from, spec, have);
4053
+ }
4054
+ async function astroSettings(repo, appPath) {
4055
+ const content = await contentSettings(repo, appPath);
4056
+ if (content) return content;
4057
+ const root = appPath ? `${appPath}/` : "";
4058
+ const paths = repo.paths.filter((p) => p.startsWith(root)).map((p) => p.slice(root.length));
4059
+ const have = new Set(paths);
4060
+ const texts = /* @__PURE__ */ new Map();
4061
+ const readAll = async (list) => {
4062
+ const todo = [...new Set(list)].filter((p) => !texts.has(p));
4063
+ for (let i = 0; i < todo.length; i += READ_AT_ONCE) {
4064
+ const batch = todo.slice(i, i + READ_AT_ONCE);
4065
+ const got = await Promise.all(batch.map((p) => repo.read(join(appPath, p))));
4066
+ batch.forEach((p, j) => texts.set(p, got[j] ?? null));
4067
+ }
4068
+ };
4069
+ const { pages: found } = discover({ framework: "astro", paths, text: () => null });
4070
+ const pages = found.filter((p) => p.kind === "file" && /\.astro$/.test(p.file ?? "")).slice(0, MAX_ROUTE_FILES).map((p) => ({ path: p.path, file: p.file }));
4071
+ if (!pages.length) return null;
4072
+ await readAll(pages.map((p) => p.file));
4073
+ const layoutOf = /* @__PURE__ */ new Map();
4074
+ for (const p of pages) {
4075
+ const src = texts.get(p.file);
4076
+ const spec = src ? astroPageFields(src, null).layout : null;
4077
+ layoutOf.set(p.file, spec ? resolve(p.file, spec, have) : null);
4078
+ }
4079
+ await readAll([...layoutOf.values()].filter((l) => !!l));
4080
+ const accepts = (layout) => {
4081
+ const props = layout ? layoutProps(texts.get(layout) ?? "") : null;
4082
+ return props ? new Set(props.keys()) : null;
4083
+ };
4084
+ const out = {};
4085
+ const refused = {};
4086
+ for (const p of pages) {
4087
+ const src = texts.get(p.file);
4088
+ if (!src) continue;
4089
+ const r = astroPageFields(src, accepts(layoutOf.get(p.file) ?? null));
4090
+ const fields = {};
4091
+ for (const [k, f] of Object.entries(r.fields)) if (f) fields[k] = settingOf(p.file, f, KIND[k]);
4092
+ if (Object.keys(fields).length) out[p.path] = fields;
4093
+ if (Object.keys(r.computed).length) refused[p.path] = { file: p.file, reason: "computed", fields: r.computed };
4094
+ else if (!Object.keys(fields).length) refused[p.path] = { file: p.file, reason: "unsupported" };
4095
+ }
4096
+ const counts = /* @__PURE__ */ new Map();
4097
+ for (const l of layoutOf.values()) if (l) counts.set(l, (counts.get(l) ?? 0) + 1);
4098
+ const main = [...counts].sort((a, b) => b[1] - a[1])[0]?.[0] ?? null;
4099
+ const yaml = YAML_CONFIGS.find((p) => have.has(p)) ?? null;
4100
+ await readAll([...yaml ? [yaml] : []]);
4101
+ const site = {};
4102
+ const take = (field2, file, f) => {
4103
+ if (!site[field2] && f && f !== "computed") site[field2] = settingOf(file, f);
4104
+ };
4105
+ const yamlSrc = yaml ? texts.get(yaml) : null;
4106
+ if (yaml && yamlSrc) {
4107
+ take("name", yaml, yamlField(yamlSrc, "site", "name"));
4108
+ take("description", yaml, yamlField(yamlSrc, "metadata", "description"));
4109
+ }
4110
+ const layoutSrc = main ? texts.get(main) : null;
4111
+ if (main && layoutSrc && (!site.name || !site.description)) {
4112
+ const refs = layoutModuleRefs(layoutSrc);
4113
+ const files = refs.map((r) => ({ r, file: resolve(main, r.spec, have) })).filter((x) => !!x.file);
4114
+ await readAll(files.map((x) => x.file));
4115
+ for (const { r, file } of files) {
4116
+ const src = texts.get(file);
4117
+ if (!src) continue;
4118
+ if (r.name) take("name", file, moduleField(src, r.exportName, r.name));
4119
+ if (r.description) take("description", file, moduleField(src, r.exportName, r.description));
4120
+ }
4121
+ const defaults = layoutDefaults(layoutSrc);
4122
+ if (defaults.name) take("name", main, defaults.name);
4123
+ if (defaults.description) take("description", main, defaults.description);
4124
+ }
4125
+ const opts = main ? headOptionsOf("astro", main) : null;
4126
+ if (main && layoutSrc && opts) {
4127
+ const head = readHead(layoutSrc, opts);
4128
+ for (const [field2, at3] of HEAD_SETTINGS) {
4129
+ const found2 = head[at3];
4130
+ if (found2 && !site[field2]) site[field2] = { file: main, pointer: headPointer(at3), kind: "image", exists: true, value: found2.value };
4131
+ }
4132
+ }
4133
+ return { pages: out, routes: null, site: Object.keys(site).length ? site : null, refused };
4134
+ }
4135
+
4136
+ // supabase/functions/unbase-projects/settings-html.ts
4137
+ var HOME = "index.html";
4138
+ var PAGE_SETTINGS = [
4139
+ ["title", "title", "text"],
4140
+ ["description", "description", "text"],
4141
+ ["socialImage", "image", "image"],
4142
+ ["noindex", "noindex", "boolean"]
4143
+ ];
4144
+ var SITE_SETTINGS = [
4145
+ ["name", "title", "text"],
4146
+ ["description", "description", "text"],
4147
+ ["language", "language", "text"],
4148
+ ["faviconLight", "favicon", "image"],
4149
+ ["faviconDark", "faviconDark", "image"],
4150
+ ["socialImage", "image", "image"]
4151
+ ];
4152
+ var TAGGED = {
4153
+ title: /<title[\s>]/i,
4154
+ description: /<meta[^>]*name\s*=\s*["']?description/i,
4155
+ image: /<meta[^>]*property\s*=\s*["']?og:image["'\s>]/i,
4156
+ noindex: /<meta[^>]*name\s*=\s*["']?robots/i
4157
+ };
4158
+ function fieldsOf2(file, text, wanted) {
4159
+ const opts = headOptionsOf("html", file) ?? {};
4160
+ const head = readHead(text, opts);
4161
+ const hasHead = /<head[\s>]/i.test(text) && /<\/head/i.test(text);
4162
+ const out = {};
4163
+ for (const [field2, at3, kind] of wanted) {
4164
+ const found = head[at3];
4165
+ if (found) out[field2] = { file, pointer: headPointer(at3), kind, exists: true, value: found.value };
4166
+ else if (opts.add && hasHead && addable(at3, opts) && TAGGED[at3] && !TAGGED[at3].test(text)) out[field2] = { file, pointer: headPointer(at3), kind, exists: false, value: null };
4167
+ }
4168
+ return out;
4169
+ }
4170
+ async function htmlSettings(repo, appPath) {
4171
+ const root = appPath ? `${appPath}/` : "";
4172
+ const paths = repo.paths.filter((p) => p.startsWith(root)).map((p) => p.slice(root.length));
4173
+ const { pages: found } = discover({ framework: "html", paths, text: () => null });
4174
+ const pages = found.filter((p) => p.kind !== "template" && p.file).slice(0, MAX_ROUTE_FILES);
4175
+ if (!pages.length) return null;
4176
+ const texts = await Promise.all(pages.map((p) => repo.read(join(appPath, p.file))));
4177
+ const out = {};
4178
+ const refused = {};
4179
+ let site = null;
4180
+ pages.forEach((p, i) => {
4181
+ const text = texts[i];
4182
+ if (text === null) return;
4183
+ const fields = fieldsOf2(p.file, text, PAGE_SETTINGS);
4184
+ if (Object.keys(fields).length) out[p.path] = fields;
4185
+ else refused[p.path] = { file: p.file, reason: "unsupported" };
4186
+ if (p.file === HOME) {
4187
+ const own = fieldsOf2(p.file, text, SITE_SETTINGS);
4188
+ const there = Object.fromEntries(Object.entries(own).filter(([, f]) => f.exists));
4189
+ if (Object.keys(there).length) site = there;
4190
+ }
4191
+ });
4192
+ return { pages: out, routes: null, site, refused };
4193
+ }
4194
+
4195
+ // supabase/functions/unbase-projects/settings-next.ts
4196
+ var PAGES_APP = /^(src\/)?pages\/_app\.(jsx|tsx|js|ts)$/;
4197
+ var PAGES_DOCUMENT = /^(src\/)?pages\/_document\.(jsx|tsx|js|ts)$/;
4198
+ var TAGGED2 = {
4199
+ title: /<title[\s>]/,
4200
+ description: /name=["']description["']/,
4201
+ language: /<Html[^>]*\slang=/,
4202
+ favicon: /<link[^>]*rel=["'][^"']*\bicon\b/,
4203
+ faviconDark: /<link[^>]*rel=["'][^"']*\bicon\b[^>]*prefers-color-scheme/,
4204
+ image: /property=["']og:image["']/,
4205
+ noindex: /name=["']robots["']/
4206
+ };
4207
+ function headFields(file, src, wanted) {
4208
+ const opts = headOptionsOf("next", file);
4209
+ if (!opts || !/<Head[\s>]/.test(src) || !/<\/Head\s*>/.test(src)) return null;
4210
+ const head = readHead(src, opts);
4211
+ const fields = {};
4212
+ const computed = {};
4213
+ for (const [field2, at3, kind] of wanted) {
4214
+ const there = head[at3];
4215
+ if (there) fields[field2] = { file, pointer: headPointer(at3), kind, exists: true, value: there.value };
4216
+ else if (TAGGED2[at3].test(src)) computed[field2] = "computed";
4217
+ else if (opts.add && (at3 === "title" || at3 === "description" || at3 === "image" || at3 === "noindex")) fields[field2] = { file, pointer: headPointer(at3), kind, exists: false, value: null };
4218
+ }
4219
+ return { fields, computed };
4220
+ }
4221
+ var ICON_FILE = /^(src\/)?app\/(favicon\.ico|icon\d*\.(ico|png|jpe?g|svg|gif|webp|avif)|icon\.(js|jsx|ts|tsx))$/;
4222
+ var NEXT_AT_ONCE = 16;
4223
+ function limited(n) {
4224
+ let running = 0;
4225
+ const waiting = [];
4226
+ return async (work) => {
4227
+ if (running < n) running++;
4228
+ else await new Promise((go) => waiting.push(go));
4229
+ try {
4230
+ return await work();
4231
+ } finally {
4232
+ const next = waiting.shift();
4233
+ if (next) next();
4234
+ else running--;
4235
+ }
4236
+ };
4237
+ }
4238
+ var NEXT_PAGE = /^(src\/)?app\/(.*\/)?page\.(tsx|ts|jsx|js)$/;
4239
+ var NEXT_ROOT_LAYOUT = /^(src\/)?app\/layout\.(tsx|ts|jsx|js)$/;
4240
+ var CMS_DEPTH = 2;
4241
+ var NEXT_PAGE_FIELDS = { title: "title", description: "description", socialImage: "socialImage", noindex: "noindex" };
4242
+ var NEXT_SITE_FIELDS = { name: "name", description: "description", socialImage: "socialImage", language: "language", favicon: "faviconLight" };
4243
+ var settingOf2 = (file, f) => ({ file, pointer: f.pointer, kind: f.kind, exists: f.exists, value: f.value });
4244
+ var drawnImage = (file, have) => {
4245
+ const dir = file.replace(/[^/]*$/, "");
4246
+ return [...have].some((p) => p.startsWith(dir) && /^opengraph-image\d*\.[a-z]+$/.test(p.slice(dir.length)));
4247
+ };
4248
+ var resolveIn = (from, spec, have) => resolveImport(from, spec, have) ?? (spec.startsWith("@/") ? resolveImport("", `./${spec.slice(2)}`, have) : null);
4249
+ async function nextSettings(repo, appPath) {
4250
+ const root = appPath ? `${appPath}/` : "";
4251
+ const paths = repo.paths.filter((p) => p.startsWith(root)).map((p) => p.slice(root.length));
4252
+ const have = new Set(paths);
4253
+ const texts = /* @__PURE__ */ new Map();
4254
+ const turn = limited(NEXT_AT_ONCE);
4255
+ const read = (p) => {
4256
+ if (!texts.has(p)) texts.set(p, turn(() => repo.read(join(appPath, p))));
4257
+ return texts.get(p);
4258
+ };
4259
+ const { pages: found } = discover({ framework: "next", paths, text: () => null });
4260
+ const pages = found.filter((p) => p.kind === "file" && p.file).slice(0, MAX_ROUTE_FILES);
4261
+ const layout = paths.find((p) => NEXT_ROOT_LAYOUT.test(p)) ?? null;
4262
+ if (!pages.length && !layout) return null;
4263
+ const readsCms = async (file, depth = CMS_DEPTH, seen = /* @__PURE__ */ new Set()) => {
4264
+ if (seen.has(file)) return false;
4265
+ seen.add(file);
4266
+ const src = await read(file);
4267
+ if (!src) return false;
4268
+ const specs = importsOf(src);
4269
+ if (specs.some(isCmsModule)) return true;
4270
+ if (!depth) return false;
4271
+ const targets = specs.map((s) => resolveIn(file, s, have)).filter((t) => t !== null);
4272
+ return (await Promise.all(targets.map((t) => readsCms(t, depth - 1, seen)))).some(Boolean);
4273
+ };
4274
+ const reasonOf = async (file, reason) => reason === "computed" && /\bgenerateMetadata\b/.test(await read(file) ?? "") && await readsCms(file) ? "cms" : reason;
4275
+ const out = {};
4276
+ const refused = {};
4277
+ const pagesRouter = pages.filter((p) => !NEXT_PAGE.test(p.file));
4278
+ const routerPages = await Promise.all(pagesRouter.map(async (p) => ({ p, src: await read(p.file) })));
4279
+ for (const { p, src } of routerPages) {
4280
+ const r = src === null ? null : headFields(p.file, src, [
4281
+ ["title", "title", "text"],
4282
+ ["description", "description", "text"],
4283
+ ["socialImage", "image", "image"],
4284
+ ["noindex", "noindex", "boolean"]
4285
+ ]);
4286
+ if (!r || !Object.keys(r.fields).length) {
4287
+ refused[p.path] = { file: p.file, reason: r && Object.keys(r.computed).length ? "computed" : "unsupported" };
4288
+ continue;
4289
+ }
4290
+ out[p.path] = r.fields;
4291
+ if (Object.keys(r.computed).length) refused[p.path] = { file: p.file, reason: "computed", fields: r.computed };
4292
+ }
4293
+ const [answers, layoutRead] = await Promise.all([
4294
+ Promise.all(
4295
+ pages.filter((p) => NEXT_PAGE.test(p.file)).map(async (p) => {
4296
+ const file = p.file;
4297
+ const src = await read(file);
4298
+ const r = src === null ? null : pageMetaFields(src);
4299
+ return { p, file, read: r, reason: r?.refused ? await reasonOf(file, r.refused) : null };
4300
+ })
4301
+ ),
4302
+ layout ? read(layout).then(async (src) => {
4303
+ const r = src === null ? null : siteMetaFields(src);
4304
+ return { read: r, reason: r?.refused ? await reasonOf(layout, r.refused) : null };
4305
+ }) : null
4306
+ ]);
4307
+ for (const { p, file, read: r, reason } of answers) {
4308
+ if (!r) {
4309
+ refused[p.path] = { file, reason: "unsupported" };
4310
+ continue;
4311
+ }
4312
+ if (r.refused) {
4313
+ refused[p.path] = { file, reason: reason ?? r.refused };
4314
+ continue;
4315
+ }
4316
+ if (r.fields.socialImage && drawnImage(file, have)) {
4317
+ delete r.fields.socialImage;
4318
+ r.computed.socialImage = "computed";
4319
+ }
4320
+ const fields = {};
4321
+ for (const [k, f] of Object.entries(r.fields)) if (f) fields[NEXT_PAGE_FIELDS[k]] = settingOf2(file, f);
4322
+ out[p.path] = fields;
4323
+ const computed = Object.entries(r.computed).map(([k, why]) => [NEXT_PAGE_FIELDS[k], why]);
4324
+ if (computed.length) refused[p.path] = { file, reason: "computed", fields: Object.fromEntries(computed) };
4325
+ }
4326
+ let site = null;
4327
+ if (layout && layoutRead) {
4328
+ const r = layoutRead.read;
4329
+ if (r?.fields.socialImage && drawnImage(layout, have)) {
4330
+ delete r.fields.socialImage;
4331
+ r.computed.socialImage = "computed";
4332
+ }
4333
+ const iconFile = paths.some((p) => ICON_FILE.test(p));
4334
+ if (r && iconFile) delete r.fields.favicon;
4335
+ if (r) {
4336
+ const fields = {};
4337
+ for (const [k, f] of Object.entries(r.fields)) if (f) fields[NEXT_SITE_FIELDS[k]] = settingOf2(layout, f);
4338
+ if (Object.keys(fields).length) site = fields;
4339
+ const computed = Object.entries(r.computed).map(([k, why]) => [NEXT_SITE_FIELDS[k], why]);
4340
+ if (iconFile) computed.push(["faviconLight", "file"]);
4341
+ if (r.refused) refused.site = { file: layout, reason: layoutRead.reason ?? r.refused };
4342
+ else if (computed.length) refused.site = { file: layout, reason: "computed", fields: Object.fromEntries(computed) };
4343
+ }
4344
+ }
4345
+ if (!layout) {
4346
+ const app = paths.find((p) => PAGES_APP.test(p));
4347
+ const doc = paths.find((p) => PAGES_DOCUMENT.test(p));
4348
+ const [appSrc, docSrc] = await Promise.all([app ? read(app) : null, doc ? read(doc) : null]);
4349
+ const SITE_HEAD = [
4350
+ ["faviconLight", "favicon", "image"],
4351
+ ["faviconDark", "faviconDark", "image"],
4352
+ ["socialImage", "image", "image"]
4353
+ ];
4354
+ const fromApp = app && appSrc ? headFields(app, appSrc, [["name", "title", "text"], ["description", "description", "text"], ...SITE_HEAD]) : null;
4355
+ const fromDoc = doc && docSrc ? headFields(doc, docSrc, [["description", "description", "text"], ["language", "language", "text"], ...SITE_HEAD]) : null;
4356
+ const fields = {};
4357
+ for (const r of [fromApp, fromDoc]) for (const [k, f] of Object.entries(r?.fields ?? {})) if (f.exists && !fields[k]) fields[k] = f;
4358
+ if (Object.keys(fields).length) site = fields;
4359
+ }
4360
+ return { pages: out, routes: null, site, refused };
4361
+ }
4362
+
4363
+ // supabase/functions/unbase-projects/settings-vite.ts
4364
+ var VITE_DOCUMENT2 = "index.html";
4365
+ var HEAD_SETTINGS2 = [
3655
4366
  ["name", "title", "text"],
3656
4367
  ["description", "description", "text"],
3657
4368
  ["language", "language", "text"],
@@ -3659,22 +4370,87 @@ var HEAD_SETTINGS = [
3659
4370
  ["faviconDark", "faviconDark", "image"],
3660
4371
  ["socialImage", "image", "image"]
3661
4372
  ];
4373
+ var PAGE_SETTINGS2 = [
4374
+ ["title", "title", "text"],
4375
+ ["description", "description", "text"],
4376
+ ["noindex", "noindex", "boolean"]
4377
+ ];
4378
+ var IN_CODE = {
4379
+ title: /<title[\s>]/i,
4380
+ description: /<meta[^>]*name=["']description/i,
4381
+ noindex: /<meta[^>]*name=["']robots/i
4382
+ };
4383
+ var ROUTER_FILE = /^(src\/)?((App|app|main|index|router|routes|Router|Routes|AppRoutes)\.(jsx|tsx|js|ts)|(routes|router)\/[^/]+\.(jsx|tsx|js|ts))$/;
4384
+ var MAX_ROUTER_FILES = 24;
4385
+ var READ_AT_ONCE2 = 16;
4386
+ function reactMajor(pkg) {
4387
+ if (!pkg) return null;
4388
+ try {
4389
+ const json = JSON.parse(pkg);
4390
+ const spec = json?.dependencies?.react ?? json?.devDependencies?.react ?? json?.peerDependencies?.react;
4391
+ const m = typeof spec === "string" ? /(\d+)(?:\.\d+)?/.exec(spec.replace(/^npm:react@/, "")) : null;
4392
+ return m ? Number(m[1]) : null;
4393
+ } catch {
4394
+ return null;
4395
+ }
4396
+ }
3662
4397
  async function viteSettings(repo, appPath) {
3663
- const text = await repo.read(join(appPath, VITE_DOCUMENT));
3664
- if (text === null) return null;
3665
- const head = readHead(text);
4398
+ const root = appPath ? `${appPath}/` : "";
4399
+ const paths = repo.paths.filter((p) => p.startsWith(root)).map((p) => p.slice(root.length));
4400
+ const [text, pkg] = await Promise.all([repo.read(join(appPath, VITE_DOCUMENT2)), repo.read(join(appPath, "package.json"))]);
3666
4401
  const site = {};
3667
- for (const [field2, at3, kind] of HEAD_SETTINGS) {
3668
- const found = head[at3];
3669
- if (found) site[field2] = { file: VITE_DOCUMENT, pointer: headPointer(at3), kind, exists: true, value: found.value };
4402
+ if (text !== null) {
4403
+ const head = readHead(text);
4404
+ for (const [field2, at3, kind] of HEAD_SETTINGS2) {
4405
+ const found2 = head[at3];
4406
+ if (found2) site[field2] = { file: VITE_DOCUMENT2, pointer: headPointer(at3), kind, exists: true, value: found2.value };
4407
+ }
4408
+ }
4409
+ const files = /* @__PURE__ */ new Map();
4410
+ const readAll = async (list) => {
4411
+ for (let i = 0; i < list.length; i += READ_AT_ONCE2) {
4412
+ const batch = list.slice(i, i + READ_AT_ONCE2).filter((p) => !files.has(p));
4413
+ const got = await Promise.all(batch.map((p) => repo.read(join(appPath, p))));
4414
+ batch.forEach((p, j) => files.set(p, got[j] ?? null));
4415
+ }
4416
+ };
4417
+ const textOf2 = (p) => files.get(p) ?? null;
4418
+ await readAll(paths.filter((x) => ROUTER_FILE.test(x)).slice(0, MAX_ROUTER_FILES));
4419
+ const { pages: found } = discover({ framework: "vite-react", paths, text: textOf2 });
4420
+ const routes = found.filter((p) => p.kind === "route" && p.file && !p.reason).slice(0, MAX_ROUTE_FILES).map((p) => ({ path: p.path, file: p.file }));
4421
+ await readAll([...new Set(routes.map((r) => r.file))]);
4422
+ const react19 = (reactMajor(pkg) ?? 0) >= 19;
4423
+ const pages = {};
4424
+ const refused = {};
4425
+ for (const r of routes) {
4426
+ const src = textOf2(r.file);
4427
+ const opts = headOptionsOf("vite-react", r.file);
4428
+ if (src === null || !opts) continue;
4429
+ const head = readHead(src, opts);
4430
+ const addable2 = react19 && componentRootAt(src) !== null;
4431
+ const fields = {};
4432
+ const why = {};
4433
+ for (const [field2, at3, kind] of PAGE_SETTINGS2) {
4434
+ const there = head[at3];
4435
+ if (there) fields[field2] = { file: r.file, pointer: headPointer(at3), kind, exists: true, value: there.value };
4436
+ else if (IN_CODE[at3].test(src)) why[field2] = "computed";
4437
+ else if (addable2) fields[field2] = { file: r.file, pointer: headPointer(at3), kind, exists: false, value: null };
4438
+ else why[field2] = "unsupported";
4439
+ }
4440
+ why.socialImage = "site";
4441
+ if (Object.keys(fields).length) pages[r.path] = fields;
4442
+ if (Object.keys(why).length) refused[r.path] = { file: r.file, reason: Object.keys(fields).length ? "computed" : Object.values(why)[0] ?? "unsupported", fields: why };
3670
4443
  }
3671
- return Object.keys(site).length ? { pages: {}, routes: null, site } : null;
4444
+ if (!Object.keys(site).length && !Object.keys(pages).length) return null;
4445
+ return { pages, routes: null, site: Object.keys(site).length ? site : null, refused, previews: "site" };
3672
4446
  }
3673
4447
 
3674
4448
  // supabase/functions/unbase-projects/settings.ts
3675
4449
  var SETTINGS_READERS = {
4450
+ astro: astroSettings,
3676
4451
  "vite-react": viteSettings,
3677
- next: nextSettings
4452
+ next: nextSettings,
4453
+ html: htmlSettings
3678
4454
  };
3679
4455
  async function readSettings(repo, appPath, framework = null) {
3680
4456
  const reader = framework && Object.hasOwn(SETTINGS_READERS, framework) ? SETTINGS_READERS[framework] : contentSettings;
@@ -3916,8 +4692,8 @@ function edited(file, text, change) {
3916
4692
  for (const p of [...policies].sort((a, b) => b.start - a.start)) {
3917
4693
  const next = change(p.value);
3918
4694
  if (next === p.value) continue;
3919
- const literal3 = file.endsWith("vercel.json") ? JSON.stringify(next) : next;
3920
- out = `${out.slice(0, p.start)}${literal3}${out.slice(p.end)}`;
4695
+ const literal4 = file.endsWith("vercel.json") ? JSON.stringify(next) : next;
4696
+ out = `${out.slice(0, p.start)}${literal4}${out.slice(p.end)}`;
3921
4697
  }
3922
4698
  return out;
3923
4699
  }
@@ -4048,13 +4824,13 @@ function balanced(code, open) {
4048
4824
  }
4049
4825
  return null;
4050
4826
  }
4051
- var literal2 = (s) => {
4827
+ var literal3 = (s) => {
4052
4828
  const t = s.trim();
4053
4829
  const m = t.match(/^(["'`])([\s\S]*)\1$/);
4054
4830
  return m && (m[1] === "`" || !m[2].includes(m[1])) ? m[2] : null;
4055
4831
  };
4056
4832
  var fixed = (s) => {
4057
- const v = literal2(s);
4833
+ const v = literal3(s);
4058
4834
  return v !== null && !v.includes("${") ? v : null;
4059
4835
  };
4060
4836
  function argumentsOf(inner) {
@@ -4104,7 +4880,7 @@ function readerFunctions({ files, adapter, root = "" }) {
4104
4880
  const call = body.match(calls);
4105
4881
  if (!call) continue;
4106
4882
  const which = (arg) => {
4107
- const lit = literal2(arg);
4883
+ const lit = literal3(arg);
4108
4884
  if (lit !== null) return { name: lit };
4109
4885
  const i = params.indexOf(arg.trim());
4110
4886
  return i >= 0 ? { arg: i } : null;