okno 1.0.0-beta.15 → 1.0.0-beta.16

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as a } from "./plugin-DmiwHDt_.js";
1
+ import { o as a } from "./plugin-DrRr35Ph.js";
2
2
  export {
3
3
  a as okno
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD,MAAM,WAAW,eAAe;IAC/B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IACvB;;+CAE2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAsBD;8EAC8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAE,CAAW,EAAE,OAAO,GAAE,eAAoB,GAAG,CAAC,CAkCrF"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/next/config.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAapD,MAAM,WAAW,eAAe;IAC/B,4EAA4E;IAC5E,GAAG,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IACvB;;+CAE2C;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAsBD;8EAC8E;AAC9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,GAAE,CAAW,EAAE,OAAO,GAAE,eAAoB,GAAG,CAAC,CAuCrF"}
@@ -1,16 +1,16 @@
1
- import { join as l, relative as E, sep as w, resolve as b } from "node:path";
2
- import { existsSync as S, watch as A } from "node:fs";
3
- import { s as g, b as M, a as C, c as R, d as N, e as P, g as F, I, f as L, h as T, i as $ } from "../dispatch-C34WXMSB.js";
4
- import { mkdir as B, writeFile as u } from "node:fs/promises";
5
- const G = (o) => o.replaceAll(I, "__oknoSetImages(undefined)"), U = (o) => {
1
+ import { join as c, relative as E, sep as w, resolve as h } from "node:path";
2
+ import { existsSync as k, watch as M, mkdirSync as A, cpSync as C } from "node:fs";
3
+ import { s as g, b as R, a as N, c as P, d as F, e as I, g as L, I as T, f as $, h as B, i as D } from "../dispatch-C34WXMSB.js";
4
+ import { mkdir as G, writeFile as u } from "node:fs/promises";
5
+ const U = (o) => o.replaceAll(T, "__oknoSetImages(undefined)"), x = (o) => {
6
6
  let n = o;
7
- for (const [t, e] of Object.entries(z))
7
+ for (const [t, e] of Object.entries(J))
8
8
  n = n.replaceAll(`"${t}"`, `"./${e}"`).replaceAll(`'${t}'`, `'./${e}'`);
9
9
  return n;
10
- }, x = (o, n, t) => {
10
+ }, z = (o, n, t) => {
11
11
  const e = E(t, n).split(w).join("/");
12
12
  return o.replaceAll(n.split(w).join("/"), e);
13
- }, z = {
13
+ }, J = {
14
14
  "okno:pages": "pages.js",
15
15
  "okno:collections": "collections.js",
16
16
  "okno:globals": "globals.js",
@@ -19,66 +19,77 @@ const G = (o) => o.replaceAll(I, "__oknoSetImages(undefined)"), U = (o) => {
19
19
  "okno:content": "content.js",
20
20
  "okno:runtime": "runtime.js"
21
21
  };
22
- async function D(o, n, t = {}) {
23
- const e = l(n, t.outDir ?? ".okno"), a = t.isBuild ?? process.env.NODE_ENV === "production";
24
- await B(e, { recursive: !0 });
25
- const [s, r, c] = await Promise.all([
22
+ async function H(o, n, t = {}) {
23
+ const e = c(n, t.outDir ?? ".okno"), a = t.isBuild ?? process.env.NODE_ENV === "production";
24
+ await G(e, { recursive: !0 });
25
+ const [s, r, l] = await Promise.all([
26
26
  g(n, "pages"),
27
27
  g(n, "collections"),
28
28
  g(n, "globals")
29
29
  ]), [i, p, f, m] = await Promise.all([
30
- M(o, s),
31
- C(o, r, a),
32
- R(o, c),
33
- N(o)
34
- ]), k = P(o), v = L(), O = F() ?? 'throw new Error("okno: runtime/wrap.js missing — run \\`bun run build:pkg\\`")', d = (_) => x(U(G(_)), o, e);
30
+ R(o, s),
31
+ N(o, r, a),
32
+ P(o, l),
33
+ F(o)
34
+ ]), v = I(o), O = $(), S = L() ?? 'throw new Error("okno: runtime/wrap.js missing — run \\`bun run build:pkg\\`")', d = (_) => z(x(U(_)), o, e);
35
35
  await Promise.all([
36
- u(l(e, "pages.js"), d(i)),
37
- u(l(e, "collections.js"), d(p)),
38
- u(l(e, "globals.js"), d(f)),
39
- u(l(e, "locales.js"), d(k)),
40
- u(l(e, "strings.js"), d(m)),
41
- u(l(e, "content.js"), d(v)),
42
- u(l(e, "runtime.js"), O)
36
+ u(c(e, "pages.js"), d(i)),
37
+ u(c(e, "collections.js"), d(p)),
38
+ u(c(e, "globals.js"), d(f)),
39
+ u(c(e, "locales.js"), d(v)),
40
+ u(c(e, "strings.js"), d(m)),
41
+ u(c(e, "content.js"), d(O)),
42
+ u(c(e, "runtime.js"), S)
43
43
  ]);
44
44
  }
45
- function J(o, n) {
45
+ function V(o, n) {
46
+ const t = c(o, "files");
47
+ if (!k(t)) return;
48
+ const e = c(n, "public", "okno", "files");
49
+ A(e, { recursive: !0 }), C(t, e, { recursive: !0, filter: (a) => !a.endsWith(".okno-tree.json") });
50
+ }
51
+ function K(o, n) {
46
52
  const t = { source: "/__okno/api/:path*", destination: `/${n}/:path*` };
47
53
  return async () => {
48
54
  const e = typeof o == "function" ? await o() : void 0;
49
55
  return e ? Array.isArray(e) ? [t, ...e] : { ...e, beforeFiles: [t, ...e.beforeFiles ?? []] } : [t];
50
56
  };
51
57
  }
52
- let j = !1;
53
- function Y(o = {}, n = {}) {
58
+ let y = !1;
59
+ function ee(o = {}, n = {}) {
54
60
  const t = n.apiMount ?? "oknoapi", e = o, a = {
55
61
  ...e,
56
- rewrites: J(e.rewrites, t)
62
+ rewrites: K(e.rewrites, t)
57
63
  };
58
- if (!j) {
59
- j = !0;
60
- const s = process.cwd(), r = b(s, n.dir ?? "okno");
61
- if (S(r)) {
62
- const c = () => {
63
- T(r, s).catch((i) => console.warn("[okno] type codegen failed:", i)), D(r, s).catch((i) => console.warn("[okno] module codegen failed:", i));
64
+ if (!y) {
65
+ y = !0;
66
+ const s = process.cwd(), r = h(s, n.dir ?? "okno");
67
+ if (k(r)) {
68
+ const l = () => {
69
+ B(r, s).catch((i) => console.warn("[okno] type codegen failed:", i)), H(r, s).catch((i) => console.warn("[okno] module codegen failed:", i));
70
+ try {
71
+ V(r, s);
72
+ } catch (i) {
73
+ console.warn("[okno] media copy failed:", i);
74
+ }
64
75
  };
65
- if (c(), process.env.NODE_ENV !== "production")
76
+ if (l(), process.env.NODE_ENV !== "production")
66
77
  try {
67
- A(r, { recursive: !0 }, () => c());
78
+ M(r, { recursive: !0 }, () => l());
68
79
  } catch {
69
80
  }
70
81
  }
71
82
  }
72
83
  return a;
73
84
  }
74
- const y = { "Content-Type": "application/json", "Cache-Control": "no-store" };
75
- function H(o) {
76
- return b(o?.root ?? process.cwd(), o?.dir ?? "okno");
85
+ const b = { "Content-Type": "application/json", "Cache-Control": "no-store" };
86
+ function W(o) {
87
+ return h(o?.root ?? process.cwd(), o?.dir ?? "okno");
77
88
  }
78
- function h() {
79
- return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: y });
89
+ function j() {
90
+ return new Response(JSON.stringify({ error: "Not found" }), { status: 404, headers: b });
80
91
  }
81
- async function V(o, n) {
92
+ async function Q(o, n) {
82
93
  const t = n?.params ? await n.params : void 0;
83
94
  if (t) {
84
95
  const s = t.okno ?? Object.values(t)[0];
@@ -88,17 +99,17 @@ async function V(o, n) {
88
99
  const e = "/__okno/api/", a = new URL(o.url).pathname.indexOf(e);
89
100
  return a === -1 ? null : new URL(o.url).pathname.slice(a + e.length);
90
101
  }
91
- function Z(o) {
92
- const n = H(o), t = async (e, a) => {
93
- const s = await V(e, a);
94
- if (s == null) return h();
95
- let r, c = !1, i;
102
+ function oe(o) {
103
+ const n = W(o), t = async (e, a) => {
104
+ const s = await Q(e, a);
105
+ if (s == null) return j();
106
+ let r, l = !1, i;
96
107
  const p = {
97
108
  method: e.method,
98
109
  route: s,
99
110
  json: async () => {
100
- if (!c) {
101
- c = !0;
111
+ if (!l) {
112
+ l = !0;
102
113
  try {
103
114
  r = await e.json();
104
115
  } catch {
@@ -109,12 +120,12 @@ function Z(o) {
109
120
  },
110
121
  binary: async () => (i === void 0 && (i = Buffer.from(await e.arrayBuffer())), i),
111
122
  header: (m) => e.headers.get(m) ?? void 0
112
- }, f = await $(n, p);
113
- return f ? new Response(JSON.stringify(f.body), { status: f.status, headers: y }) : h();
123
+ }, f = await D(n, p);
124
+ return f ? new Response(JSON.stringify(f.body), { status: f.status, headers: b }) : j();
114
125
  };
115
126
  return { GET: t, POST: t };
116
127
  }
117
128
  export {
118
- Z as createOknoRouteHandler,
119
- Y as withOkno
129
+ oe as createOknoRouteHandler,
130
+ ee as withOkno
120
131
  };
@@ -1,42 +1,42 @@
1
- import { extname as z, join as w, dirname as B, relative as N, sep as L, resolve as m } from "node:path";
2
- import { existsSync as E, readFileSync as U, mkdirSync as I, writeFileSync as R, cpSync as Y } from "node:fs";
1
+ import { extname as z, join as w, dirname as I, relative as N, sep as L, resolve as m } from "node:path";
2
+ import { existsSync as k, readFileSync as U, mkdirSync as M, writeFileSync as R, cpSync as Y } from "node:fs";
3
3
  import { execSync as Q } from "node:child_process";
4
4
  import { fileURLToPath as Z } from "node:url";
5
- import { i as x, g as q, s as v, b as tt, a as et, c as ot, e as nt, d as rt, f as it, h as M, j as $, k as st } from "./dispatch-C34WXMSB.js";
6
- import { simpleGit as H } from "simple-git";
5
+ import { i as x, g as q, s as E, b as tt, a as et, c as ot, e as nt, d as it, f as rt, h as H, j as $, k as st } from "./dispatch-C34WXMSB.js";
6
+ import { simpleGit as P } from "simple-git";
7
7
  import "./acorn-CZBJD705.js";
8
- function A(n, i, e) {
9
- n.statusCode = i, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(e));
8
+ function A(n, r, e) {
9
+ n.statusCode = r, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(e));
10
10
  }
11
11
  function at(n) {
12
- return new Promise((i) => {
12
+ return new Promise((r) => {
13
13
  let e = "";
14
14
  n.on("data", (t) => e += t), n.on("end", () => {
15
15
  try {
16
- i(e ? JSON.parse(e) : {});
16
+ r(e ? JSON.parse(e) : {});
17
17
  } catch {
18
- i({});
18
+ r({});
19
19
  }
20
- }), n.on("error", () => i({}));
20
+ }), n.on("error", () => r({}));
21
21
  });
22
22
  }
23
23
  function lt(n) {
24
- return new Promise((i, e) => {
24
+ return new Promise((r, e) => {
25
25
  const t = [];
26
- n.on("data", (a) => t.push(a)), n.on("end", () => i(Buffer.concat(t))), n.on("error", e);
26
+ n.on("data", (a) => t.push(a)), n.on("end", () => r(Buffer.concat(t))), n.on("error", e);
27
27
  });
28
28
  }
29
- function ct(n, i) {
30
- if (i) {
31
- for (const e of new Set(i.modules)) {
29
+ function ct(n, r) {
30
+ if (r) {
31
+ for (const e of new Set(r.modules)) {
32
32
  const t = n.moduleGraph.getModuleById("\0okno:" + e);
33
33
  t && n.moduleGraph.invalidateModule(t);
34
34
  }
35
- for (const e of new Set(i.files))
35
+ for (const e of new Set(r.files))
36
36
  n.moduleGraph.getModulesByFile(e)?.forEach((t) => n.moduleGraph.invalidateModule(t));
37
37
  }
38
38
  }
39
- function ut(n, i) {
39
+ function ut(n, r) {
40
40
  n.middlewares.use(async (e, t, a) => {
41
41
  if (!e.url?.startsWith("/__okno/api/")) return a();
42
42
  const h = e.url.slice(12).split("?")[0], o = {
@@ -44,24 +44,24 @@ function ut(n, i) {
44
44
  route: h,
45
45
  json: () => at(e),
46
46
  binary: () => lt(e),
47
- header: (r) => {
48
- const s = e.headers[r];
47
+ header: (i) => {
48
+ const s = e.headers[i];
49
49
  return Array.isArray(s) ? s[0] : s;
50
50
  }
51
51
  };
52
52
  try {
53
- const r = await x(i, o);
54
- if (!r) return a();
55
- ct(n, r.invalidation), A(t, r.status, r.body);
56
- } catch (r) {
57
- A(t, 500, { error: r instanceof Error ? r.message : String(r) });
53
+ const i = await x(r, o);
54
+ if (!i) return a();
55
+ ct(n, i.invalidation), A(t, i.status, i.body);
56
+ } catch (i) {
57
+ A(t, 500, { error: i instanceof Error ? i.message : String(i) });
58
58
  }
59
59
  });
60
60
  }
61
- function dt(n, i) {
61
+ function dt(n, r) {
62
62
  let e;
63
63
  try {
64
- e = decodeURIComponent(i);
64
+ e = decodeURIComponent(r);
65
65
  } catch {
66
66
  return null;
67
67
  }
@@ -69,7 +69,7 @@ function dt(n, i) {
69
69
  const t = m(n, "files"), a = m(t, e);
70
70
  return a === t || !a.startsWith(t + L) ? null : a;
71
71
  }
72
- const P = "okno", ft = {
72
+ const B = "okno", ft = {
73
73
  ".webp": "image/webp",
74
74
  ".png": "image/png",
75
75
  ".jpg": "image/jpeg",
@@ -90,18 +90,18 @@ const P = "okno", ft = {
90
90
  ".ttf": "font/ttf",
91
91
  ".otf": "font/otf"
92
92
  };
93
- function pt(n, i) {
94
- ut(n, i), n.middlewares.use((e, t, a) => {
93
+ function pt(n, r) {
94
+ ut(n, r), n.middlewares.use((e, t, a) => {
95
95
  if (e.method !== "GET" || !e.url?.startsWith("/okno/files/")) return a();
96
96
  const h = e.url.slice(12).split("?")[0];
97
97
  if (!h) return a();
98
- const o = dt(i, h);
98
+ const o = dt(r, h);
99
99
  if (!o)
100
100
  return t.statusCode = 403, t.end("Forbidden");
101
- if (!E(o))
101
+ if (!k(o))
102
102
  return t.statusCode = 404, t.end("Not found");
103
- const r = z(o).toLowerCase();
104
- t.setHeader("Content-Type", ft[r] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(U(o));
103
+ const i = z(o).toLowerCase();
104
+ t.setHeader("Content-Type", ft[i] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(U(o));
105
105
  }), n.middlewares.use(async (e, t, a) => {
106
106
  if (!e.url?.startsWith("/__okno/")) return a();
107
107
  const h = e.url.slice(8);
@@ -110,50 +110,50 @@ function pt(n, i) {
110
110
  if (e.method === "GET" && h === "repo") {
111
111
  t.setHeader("Content-Type", "application/json");
112
112
  try {
113
- const o = H(n.config.root), r = (await o.remote(["get-url", "origin"]))?.toString().trim(), s = (await o.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: p, repo: l } = gt(r);
113
+ const o = P(n.config.root), i = (await o.remote(["get-url", "origin"]))?.toString().trim(), s = (await o.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: p, repo: l } = gt(i);
114
114
  return t.end(
115
- JSON.stringify({ ok: !0, owner: p, repo: l, branch: s || null, remote: r || null })
115
+ JSON.stringify({ ok: !0, owner: p, repo: l, branch: s || null, remote: i || null })
116
116
  );
117
117
  } catch (o) {
118
118
  return t.end(JSON.stringify({ ok: !1, error: String(o) }));
119
119
  }
120
120
  }
121
121
  if (e.method === "POST" && h.startsWith("mirror")) {
122
- const r = new URL(e.url, "http://localhost").searchParams.get("path");
123
- if (!r || r.includes("..") || !r.startsWith("files/"))
122
+ const i = new URL(e.url, "http://localhost").searchParams.get("path");
123
+ if (!i || i.includes("..") || !i.startsWith("files/"))
124
124
  return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
125
- const s = w(i, r);
126
- if (E(s))
125
+ const s = w(r, i);
126
+ if (k(s))
127
127
  return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, skipped: !0 }));
128
128
  const p = await mt(e);
129
- return I(B(s), { recursive: !0 }), R(s, p), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: r, bytes: p.length }));
129
+ return M(I(s), { recursive: !0 }), R(s, p), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: i, bytes: p.length }));
130
130
  }
131
131
  if (e.method === "POST" && h === "sync") {
132
- const r = (await ht(e))?.path;
133
- if (r) {
134
- if (r.includes("..") || r.includes("\0"))
132
+ const i = (await ht(e))?.path;
133
+ if (i) {
134
+ if (i.includes("..") || i.includes("\0"))
135
135
  return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
136
- const u = w(i, r);
136
+ const u = w(r, i);
137
137
  try {
138
- const c = H(i);
139
- await c.fetch("origin", P);
140
- const g = (await c.revparse(["--show-toplevel"])).trim(), f = N(g, u).split(L).join("/"), y = await c.show([`origin/${P}:${f}`]);
141
- I(B(u), { recursive: !0 }), R(u, y);
138
+ const c = P(r);
139
+ await c.fetch("origin", B);
140
+ const g = (await c.revparse(["--show-toplevel"])).trim(), f = N(g, u).split(L).join("/"), y = await c.show([`origin/${B}:${f}`]);
141
+ M(I(u), { recursive: !0 }), R(u, y);
142
142
  } catch (c) {
143
143
  const g = c instanceof Error ? c.message : String(c);
144
144
  console.warn(
145
- `[okno] sync: could not materialize ${r} from origin/${P} — ${g.split(`
145
+ `[okno] sync: could not materialize ${i} from origin/${B} — ${g.split(`
146
146
  `)[0]}`
147
147
  );
148
148
  }
149
- return F(n, r, u), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, invalidated: r }));
149
+ return F(n, i, u), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, invalidated: i }));
150
150
  }
151
- const s = H(i), p = await s.revparse(["--show-toplevel"]), l = N(p.trim(), i);
151
+ const s = P(r), p = await s.revparse(["--show-toplevel"]), l = N(p.trim(), r);
152
152
  try {
153
153
  const u = await s.pull();
154
154
  for (const c of u.files)
155
155
  if (c.startsWith(`${l}/`)) {
156
- const g = c.slice(`${l}/`.length), f = w(i, g);
156
+ const g = c.slice(`${l}/`.length), f = w(r, g);
157
157
  F(n, g, f);
158
158
  }
159
159
  return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, files: u.files }));
@@ -171,53 +171,53 @@ function pt(n, i) {
171
171
  }
172
172
  function gt(n) {
173
173
  if (!n) return { owner: null, repo: null };
174
- const i = n.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
175
- return i ? { owner: i[1], repo: i[2] } : { owner: null, repo: null };
174
+ const r = n.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
175
+ return r ? { owner: r[1], repo: r[2] } : { owner: null, repo: null };
176
176
  }
177
177
  function mt(n) {
178
- return new Promise((i, e) => {
178
+ return new Promise((r, e) => {
179
179
  const t = [];
180
- n.on("data", (a) => t.push(a)), n.on("end", () => i(Buffer.concat(t))), n.on("error", e);
180
+ n.on("data", (a) => t.push(a)), n.on("end", () => r(Buffer.concat(t))), n.on("error", e);
181
181
  });
182
182
  }
183
183
  function ht(n) {
184
- return new Promise((i) => {
184
+ return new Promise((r) => {
185
185
  let e = "";
186
186
  n.on("data", (t) => {
187
187
  e += t;
188
188
  }), n.on("end", () => {
189
189
  try {
190
- i(e ? JSON.parse(e) : null);
190
+ r(e ? JSON.parse(e) : null);
191
191
  } catch {
192
- i(null);
192
+ r(null);
193
193
  }
194
- }), n.on("error", () => i(null));
194
+ }), n.on("error", () => r(null));
195
195
  });
196
196
  }
197
- function F(n, i, e) {
197
+ function F(n, r, e) {
198
198
  const t = "\0okno:";
199
199
  let a;
200
- if (i.startsWith("pages/") ? a = t + "pages" : i.startsWith("collections/") ? a = t + "collections" : i.startsWith("globals/") && (a = t + "globals"), a) {
200
+ if (r.startsWith("pages/") ? a = t + "pages" : r.startsWith("collections/") ? a = t + "collections" : r.startsWith("globals/") && (a = t + "globals"), a) {
201
201
  const h = n.moduleGraph.getModuleById(a);
202
202
  h && n.moduleGraph.invalidateModule(h);
203
203
  const o = n.moduleGraph.getModulesByFile(e);
204
- o && o.forEach((r) => {
205
- n.moduleGraph.invalidateModule(r);
204
+ o && o.forEach((i) => {
205
+ n.moduleGraph.invalidateModule(i);
206
206
  });
207
207
  }
208
208
  }
209
- function yt(n, i) {
210
- const e = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = i.replace(/\\/g, "/");
209
+ function yt(n, r) {
210
+ const e = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = r.replace(/\\/g, "/");
211
211
  return e === t || e.startsWith(t + "/");
212
212
  }
213
- function wt(n, i) {
214
- for (const [e, t] of Object.entries(i)) {
213
+ function wt(n, r) {
214
+ for (const [e, t] of Object.entries(r)) {
215
215
  if (n === e) return t;
216
216
  if (n.startsWith(e + "/")) return t + n.slice(e.length);
217
217
  }
218
218
  return null;
219
219
  }
220
- const bt = "okno:", _ = "\0okno:", St = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), K = B(Z(import.meta.url)), _t = JSON.parse(U(m(K, "../package.json"), "utf-8")).version, D = q(), b = m(K, "../editor"), T = m(b, "index.ts"), kt = E(T), Ot = {
220
+ const bt = "okno:", _ = "\0okno:", St = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), K = I(Z(import.meta.url)), _t = JSON.parse(U(m(K, "../package.json"), "utf-8")).version, D = q(), b = m(K, "../editor"), T = m(b, "index.ts"), kt = k(T), Ot = {
221
221
  "@modules": m(b, "modules"),
222
222
  "@lib": m(b, "lib"),
223
223
  "@logger": m(b, "lib/logger.svelte.ts"),
@@ -240,14 +240,14 @@ function vt() {
240
240
  }
241
241
  }
242
242
  function It(n = {}) {
243
- const i = n.dir ?? "okno";
243
+ const r = n.dir ?? "okno";
244
244
  let e, t, a = !1, h = !1;
245
245
  return n.isEditor, {
246
246
  name: "okno",
247
247
  enforce: "pre",
248
- config(o, r) {
249
- const s = r.command === "serve";
250
- return h = r.command === "build", a = s && kt, {
248
+ config(o, i) {
249
+ const s = i.command === "serve";
250
+ return h = i.command === "build", a = s && kt, {
251
251
  define: {
252
252
  __OKNO_API_URL__: JSON.stringify(n.apiUrl ?? "https://api.okno.build"),
253
253
  __OKNO_VERSION__: JSON.stringify(_t),
@@ -286,7 +286,7 @@ function It(n = {}) {
286
286
  // the backend mirrored saves to disk, causing spurious full
287
287
  // reloads. In production-mode the backend never touches local
288
288
  // FS so blocking those is pure harm — pulls go unseen.)
289
- ignored: [`**/${i}/files/**`, `**/${i}/.okno-tree.json`]
289
+ ignored: [`**/${r}/files/**`, `**/${r}/.okno-tree.json`]
290
290
  },
291
291
  // Source mode: the editor loads via a dynamic `import("okno/editor")`
292
292
  // from a separate package over `@fs`, so Vite's startup dep scan
@@ -302,25 +302,32 @@ function It(n = {}) {
302
302
  };
303
303
  },
304
304
  configResolved(o) {
305
- e = o.root, t = m(e, i);
305
+ e = o.root, t = m(e, r);
306
306
  },
307
307
  async buildStart() {
308
- if (E(t) && (await M(t, e), n.demo)) {
309
- const o = w(e, "public");
310
- E(o) || I(o, { recursive: !0 }), R(
311
- w(o, "okno-demo.json"),
312
- JSON.stringify(st(t))
313
- );
314
- const r = w(t, "files");
315
- E(r) && Y(r, w(o, "okno", "files"), {
316
- recursive: !0,
317
- filter: (s) => !s.endsWith(".okno-tree.json")
318
- });
308
+ if (k(t)) {
309
+ if (await H(t, e), h) {
310
+ const o = w(t, "files");
311
+ if (k(o)) {
312
+ const i = w(e, "public");
313
+ k(i) || M(i, { recursive: !0 }), Y(o, w(i, "okno", "files"), {
314
+ recursive: !0,
315
+ filter: (s) => !s.endsWith(".okno-tree.json")
316
+ });
317
+ }
318
+ }
319
+ if (n.demo) {
320
+ const o = w(e, "public");
321
+ k(o) || M(o, { recursive: !0 }), R(
322
+ w(o, "okno-demo.json"),
323
+ JSON.stringify(st(t))
324
+ );
325
+ }
319
326
  }
320
327
  },
321
328
  configureServer(o) {
322
329
  pt(o, t);
323
- const r = (p) => {
330
+ const i = (p) => {
324
331
  const l = N(t, p);
325
332
  if (l.startsWith("..") || !l.endsWith(".ts")) return;
326
333
  const u = l.split(/[\\/]/)[0];
@@ -328,13 +335,13 @@ function It(n = {}) {
328
335
  const c = o.moduleGraph.getModuleById(_ + u);
329
336
  c && o.moduleGraph.invalidateModule(c), o.moduleGraph.getModulesByFile(p)?.forEach((g) => o.moduleGraph.invalidateModule(g)), !$(p) && o.ws.send({ type: "full-reload" });
330
337
  };
331
- o.watcher.on("add", r), o.watcher.on("unlink", r), o.middlewares.use("/__okno/imports", async (p, l, u) => {
338
+ o.watcher.on("add", i), o.watcher.on("unlink", i), o.middlewares.use("/__okno/imports", async (p, l, u) => {
332
339
  if (p.method !== "GET") return u();
333
340
  try {
334
341
  const [c, g, f] = await Promise.all([
335
- v(e, "pages"),
336
- v(e, "globals"),
337
- v(e, "collections")
342
+ E(e, "pages"),
343
+ E(e, "globals"),
344
+ E(e, "collections")
338
345
  ]);
339
346
  l.setHeader("Content-Type", "application/json"), l.setHeader("Cache-Control", "no-store"), l.end(JSON.stringify({
340
347
  pages: Array.from(c),
@@ -359,17 +366,17 @@ function It(n = {}) {
359
366
  }
360
367
  }), o.middlewares.use((p, l, u) => {
361
368
  const c = "<script>window.__oknoDev=true<\/script>", g = n.demo ? "<script>window.__oknoDemo=true<\/script>" : "", f = `${c}${g}<script type="module" src="${s}"><\/script>`, y = [];
362
- let k = null;
369
+ let O = null;
363
370
  const V = l.write.bind(l), j = l.end.bind(l), X = l.setHeader.bind(l), G = () => {
364
371
  const d = l.getHeader("content-type");
365
372
  return typeof d == "string" && d.includes("text/html");
366
373
  }, W = (d, S) => Buffer.isBuffer(d) ? d : d instanceof Uint8Array ? Buffer.from(d.buffer, d.byteOffset, d.byteLength) : typeof d == "string" ? Buffer.from(d, S || "utf-8") : Buffer.from(String(d));
367
- l.write = (d, S, ...C) => (k === null && (k = G()), k ? (d && y.push(W(d, typeof S == "string" ? S : void 0)), !0) : V(d, S, ...C)), l.end = (d, S, ...C) => {
368
- if (k === null && (k = G()), !k) return j(d, S, ...C);
374
+ l.write = (d, S, ...C) => (O === null && (O = G()), O ? (d && y.push(W(d, typeof S == "string" ? S : void 0)), !0) : V(d, S, ...C)), l.end = (d, S, ...C) => {
375
+ if (O === null && (O = G()), !O) return j(d, S, ...C);
369
376
  d && y.push(W(d, typeof S == "string" ? S : void 0));
370
- let O = Buffer.concat(y).toString("utf-8");
371
- O.includes(f) || (O = O.includes("</body>") ? O.replace("</body>", `${f}</body>`) : O + f);
372
- const J = Buffer.from(O, "utf-8");
377
+ let v = Buffer.concat(y).toString("utf-8");
378
+ v.includes(f) || (v = v.includes("</body>") ? v.replace("</body>", `${f}</body>`) : v + f);
379
+ const J = Buffer.from(v, "utf-8");
373
380
  if (!l.headersSent)
374
381
  try {
375
382
  X("content-length", String(J.length));
@@ -380,9 +387,9 @@ function It(n = {}) {
380
387
  });
381
388
  },
382
389
  async handleHotUpdate(o) {
383
- const r = w(t, "schema.ts"), s = w(t, "users.json"), p = w(t, "permissions.ts"), l = w(t, "modules.d.ts");
384
- if (o.file === r) {
385
- await M(t, e);
390
+ const i = w(t, "schema.ts"), s = w(t, "users.json"), p = w(t, "permissions.ts"), l = w(t, "modules.d.ts");
391
+ if (o.file === i) {
392
+ await H(t, e);
386
393
  for (const f of ["pages", "collections", "globals", "locales", "content", "strings"]) {
387
394
  const y = o.server.moduleGraph.getModuleById(_ + f);
388
395
  y && o.server.moduleGraph.invalidateModule(y);
@@ -393,7 +400,7 @@ function It(n = {}) {
393
400
  return [];
394
401
  const u = w(t, "strings.ts"), c = N(w(t, "strings"), o.file);
395
402
  if (o.file === u || !c.startsWith("..") && c.endsWith(".ts")) {
396
- await M(t, e);
403
+ await H(t, e);
397
404
  for (const f of ["strings", "content"]) {
398
405
  const y = o.server.moduleGraph.getModuleById(_ + f);
399
406
  y && o.server.moduleGraph.invalidateModule(y);
@@ -408,7 +415,7 @@ function It(n = {}) {
408
415
  }
409
416
  }
410
417
  },
411
- async resolveId(o, r) {
418
+ async resolveId(o, i) {
412
419
  if (o.startsWith(bt))
413
420
  return "\0" + o;
414
421
  if (o.startsWith("okno/")) {
@@ -417,40 +424,40 @@ function It(n = {}) {
417
424
  }
418
425
  if (a && o === "okno/editor")
419
426
  return T;
420
- if (a && r && yt(r, b)) {
427
+ if (a && i && yt(i, b)) {
421
428
  const s = wt(o, Ot);
422
429
  if (s)
423
- return (await this.resolve(s, r, { skipSelf: !0 }))?.id;
430
+ return (await this.resolve(s, i, { skipSelf: !0 }))?.id;
424
431
  }
425
432
  },
426
433
  async load(o) {
427
434
  if (!o.startsWith(_)) return;
428
- const r = o.slice(_.length);
429
- if (r === "runtime") {
435
+ const i = o.slice(_.length);
436
+ if (i === "runtime") {
430
437
  if (!D)
431
438
  throw new Error("okno: runtime/wrap.js missing — run `bun run build:pkg`");
432
439
  return D;
433
440
  }
434
- if (r === "bootstrap")
441
+ if (i === "bootstrap")
435
442
  return 'import("okno/editor")';
436
- if (r === "pages") {
437
- const s = await v(e, "pages");
443
+ if (i === "pages") {
444
+ const s = await E(e, "pages");
438
445
  return await tt(t, s);
439
446
  }
440
- if (r === "collections") {
441
- const s = await v(e, "collections");
447
+ if (i === "collections") {
448
+ const s = await E(e, "collections");
442
449
  return await et(t, s, h);
443
450
  }
444
- if (r === "globals") {
445
- const s = await v(e, "globals");
451
+ if (i === "globals") {
452
+ const s = await E(e, "globals");
446
453
  return await ot(t, s);
447
454
  }
448
- if (r === "locales")
455
+ if (i === "locales")
449
456
  return nt(t);
450
- if (r === "strings")
451
- return await rt(t);
452
- if (r === "content")
453
- return it();
457
+ if (i === "strings")
458
+ return await it(t);
459
+ if (i === "content")
460
+ return rt();
454
461
  }
455
462
  };
456
463
  }
@@ -1,4 +1,4 @@
1
- import { o as a } from "../plugin-DmiwHDt_.js";
1
+ import { o as a } from "../plugin-DrRr35Ph.js";
2
2
  export {
3
3
  a as okno
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA+EpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,CAiYpD"}
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AA+EpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,CAwYpD"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "okno",
3
3
  "description": "Git-backed CMS with live editing for any Vite framework",
4
4
  "author": "Gabriel Uhlíř",
5
- "version": "1.0.0-beta.15",
5
+ "version": "1.0.0-beta.16",
6
6
  "homepage": "https://okno.build",
7
7
  "type": "module",
8
8
  "types": "./dist/index.d.ts",