okno 1.0.0-beta.18 → 1.0.0-beta.20

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.
@@ -1018,10 +1018,17 @@ let W9 = class extends St {
1018
1018
  const t = this.currentRepo;
1019
1019
  return t ? `${t.owner}/${t.repo}@${t.branch}` : null;
1020
1020
  }
1021
- /** X-Okno-Path header — the monorepo subdir. Null (header omitted) at the
1022
- * repo root so single-project repos send exactly what they did before. */
1021
+ /** X-Okno-Path header — the monorepo subdir. The baked path describes the
1022
+ * build's OWN project (bakedRepo), so it's only valid while the editor targets
1023
+ * that repo. If the user switched to (or the editor auto-picked) a DIFFERENT
1024
+ * repo, the baked path is meaningless there — send nothing (repo root), or a
1025
+ * request would read/scaffold `<baked-subdir>/okno` inside the wrong repo (the
1026
+ * bug that scaffolded a stray root `okno/` into okno-test). Null → header
1027
+ * omitted → backend treats it as the repo root. */
1023
1028
  get rootHeader() {
1024
- return this.bakedRoot || null;
1029
+ if (!this.bakedRoot) return null;
1030
+ const t = this.bakedRepo, r = this.currentRepo;
1031
+ return !t || !r ? null : t.owner === r.owner && t.repo === r.repo ? this.bakedRoot : null;
1025
1032
  }
1026
1033
  /** Base URL for CONTENT-engine calls (content/schema/files/publish). In dev
1027
1034
  * these hit the Vite plugin's local engine (disk + git, no backend); in
@@ -41528,8 +41535,11 @@ class LT {
41528
41535
  try {
41529
41536
  if (this.project.isDev && await this.deriveDevRepo())
41530
41537
  return await this.refresh(), await this.dispatchAfterStatus();
41531
- if (this.project.currentRepo)
41532
- return await this.refresh(), await this.dispatchAfterStatus();
41538
+ if (this.project.currentRepo) {
41539
+ await this.refresh();
41540
+ const n = this.project.bakedRepo, i = this.project.currentRepo;
41541
+ return !this.setup.hasInstallation && n && !(n.owner === i.owner && n.repo === i.repo) && (this.project.setCurrentRepo(n), await this.refresh()), await this.dispatchAfterStatus();
41542
+ }
41533
41543
  if (this.project.bakedRepo)
41534
41544
  return this.project.setCurrentRepo(this.project.bakedRepo), await this.refresh(), await this.dispatchAfterStatus();
41535
41545
  await this.fetchInstallations();
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { o as a } from "./plugin-HRVyik1g.js";
1
+ import { o as a } from "./plugin-jvqdZWC0.js";
2
2
  export {
3
3
  a as okno
4
4
  };
@@ -1,75 +1,75 @@
1
- import { extname as Y, join as h, dirname as T, relative as N, sep as I, resolve as g } from "node:path";
2
- import { existsSync as O, readFileSync as U, mkdirSync as M, writeFileSync as j, cpSync as Q } from "node:fs";
1
+ import { extname as Y, join as h, dirname as P, relative as N, sep as G, resolve as g } from "node:path";
2
+ import { existsSync as O, readFileSync as U, mkdirSync as R, writeFileSync as T, cpSync as Q } from "node:fs";
3
3
  import { execSync as K } from "node:child_process";
4
4
  import { fileURLToPath as Z } from "node:url";
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 P, j as A, k as st } from "./dispatch-DKZB5I61.js";
6
- import { simpleGit as R } from "simple-git";
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-DKZB5I61.js";
6
+ import { simpleGit as H } from "simple-git";
7
7
  import "./acorn-CZBJD705.js";
8
- function F(n, r, e) {
9
- n.statusCode = r, n.setHeader("Content-Type", "application/json"), n.setHeader("Cache-Control", "no-store"), n.end(JSON.stringify(e));
8
+ function F(n, i, e) {
9
+ n.statusCode = i, 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((r) => {
12
+ return new Promise((i) => {
13
13
  let e = "";
14
14
  n.on("data", (t) => e += t), n.on("end", () => {
15
15
  try {
16
- r(e ? JSON.parse(e) : {});
16
+ i(e ? JSON.parse(e) : {});
17
17
  } catch {
18
- r({});
18
+ i({});
19
19
  }
20
- }), n.on("error", () => r({}));
20
+ }), n.on("error", () => i({}));
21
21
  });
22
22
  }
23
23
  function lt(n) {
24
- return new Promise((r, e) => {
24
+ return new Promise((i, e) => {
25
25
  const t = [];
26
- n.on("data", (a) => t.push(a)), n.on("end", () => r(Buffer.concat(t))), n.on("error", e);
26
+ n.on("data", (c) => t.push(c)), n.on("end", () => i(Buffer.concat(t))), n.on("error", e);
27
27
  });
28
28
  }
29
- function ct(n, r) {
30
- if (r) {
31
- for (const e of new Set(r.modules)) {
29
+ function ct(n, i) {
30
+ if (i) {
31
+ for (const e of new Set(i.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(r.files))
35
+ for (const e of new Set(i.files))
36
36
  n.moduleGraph.getModulesByFile(e)?.forEach((t) => n.moduleGraph.invalidateModule(t));
37
37
  }
38
38
  }
39
- function ut(n, r) {
40
- n.middlewares.use(async (e, t, a) => {
41
- if (!e.url?.startsWith("/__okno/api/")) return a();
39
+ function ut(n, i) {
40
+ n.middlewares.use(async (e, t, c) => {
41
+ if (!e.url?.startsWith("/__okno/api/")) return c();
42
42
  const y = e.url.slice(12).split("?")[0], o = {
43
43
  method: e.method || "GET",
44
44
  route: y,
45
45
  json: () => at(e),
46
46
  binary: () => lt(e),
47
- header: (i) => {
48
- const s = e.headers[i];
47
+ header: (r) => {
48
+ const s = e.headers[r];
49
49
  return Array.isArray(s) ? s[0] : s;
50
50
  }
51
51
  };
52
52
  try {
53
- const i = await x(r, o);
54
- if (!i) return a();
55
- ct(n, i.invalidation), F(t, i.status, i.body);
56
- } catch (i) {
57
- F(t, 500, { error: i instanceof Error ? i.message : String(i) });
53
+ const r = await x(i, o);
54
+ if (!r) return c();
55
+ ct(n, r.invalidation), F(t, r.status, r.body);
56
+ } catch (r) {
57
+ F(t, 500, { error: r instanceof Error ? r.message : String(r) });
58
58
  }
59
59
  });
60
60
  }
61
- function dt(n, r) {
61
+ function dt(n, i) {
62
62
  let e;
63
63
  try {
64
- e = decodeURIComponent(r);
64
+ e = decodeURIComponent(i);
65
65
  } catch {
66
66
  return null;
67
67
  }
68
68
  if (!e || e.includes("\0")) return null;
69
- const t = g(n, "files"), a = g(t, e);
70
- return a === t || !a.startsWith(t + I) ? null : a;
69
+ const t = g(n, "files"), c = g(t, e);
70
+ return c === t || !c.startsWith(t + G) ? null : c;
71
71
  }
72
- const H = "okno", ft = {
72
+ const B = "okno", ft = {
73
73
  ".webp": "image/webp",
74
74
  ".png": "image/png",
75
75
  ".jpg": "image/jpeg",
@@ -90,80 +90,80 @@ const H = "okno", ft = {
90
90
  ".ttf": "font/ttf",
91
91
  ".otf": "font/otf"
92
92
  };
93
- function pt(n, r) {
94
- ut(n, r), n.middlewares.use((e, t, a) => {
95
- if (e.method !== "GET" || !e.url?.startsWith("/okno/files/")) return a();
93
+ function pt(n, i) {
94
+ ut(n, i), n.middlewares.use((e, t, c) => {
95
+ if (e.method !== "GET" || !e.url?.startsWith("/okno/files/")) return c();
96
96
  const y = e.url.slice(12).split("?")[0];
97
- if (!y) return a();
98
- const o = dt(r, y);
97
+ if (!y) return c();
98
+ const o = dt(i, y);
99
99
  if (!o)
100
100
  return t.statusCode = 403, t.end("Forbidden");
101
101
  if (!O(o))
102
102
  return t.statusCode = 404, t.end("Not found");
103
- const i = Y(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
- }), n.middlewares.use(async (e, t, a) => {
106
- if (!e.url?.startsWith("/__okno/")) return a();
103
+ const r = Y(o).toLowerCase();
104
+ t.setHeader("Content-Type", ft[r] || "application/octet-stream"), t.setHeader("Cache-Control", "public, max-age=3600"), t.end(U(o));
105
+ }), n.middlewares.use(async (e, t, c) => {
106
+ if (!e.url?.startsWith("/__okno/")) return c();
107
107
  const y = e.url.slice(8);
108
108
  t.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate"), t.setHeader("Pragma", "no-cache"), t.setHeader("Expires", "0");
109
109
  try {
110
110
  if (e.method === "GET" && y === "repo") {
111
111
  t.setHeader("Content-Type", "application/json");
112
112
  try {
113
- const o = R(n.config.root), i = (await o.remote(["get-url", "origin"]))?.toString().trim(), s = (await o.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: f, repo: l } = gt(i);
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: f, repo: a } = gt(r);
114
114
  return t.end(
115
- JSON.stringify({ ok: !0, owner: f, repo: l, branch: s || null, remote: i || null })
115
+ JSON.stringify({ ok: !0, owner: f, repo: a, branch: s || null, remote: r || 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" && y.startsWith("mirror")) {
122
- const i = new URL(e.url, "http://localhost").searchParams.get("path");
123
- if (!i || i.includes("..") || !i.startsWith("files/"))
122
+ const r = new URL(e.url, "http://localhost").searchParams.get("path");
123
+ if (!r || r.includes("..") || !r.startsWith("files/"))
124
124
  return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
125
- const s = h(r, i);
125
+ const s = h(i, r);
126
126
  if (O(s))
127
127
  return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, skipped: !0 }));
128
128
  const f = await mt(e);
129
- return M(T(s), { recursive: !0 }), j(s, f), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: i, bytes: f.length }));
129
+ return R(P(s), { recursive: !0 }), T(s, f), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, written: r, bytes: f.length }));
130
130
  }
131
131
  if (e.method === "POST" && y === "sync") {
132
- const i = (await ht(e))?.path;
133
- if (i) {
134
- if (i.includes("..") || i.includes("\0"))
132
+ const r = (await ht(e))?.path;
133
+ if (r) {
134
+ if (r.includes("..") || r.includes("\0"))
135
135
  return t.statusCode = 400, t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ error: "Invalid path" }));
136
- const u = h(r, i);
136
+ const u = h(i, r);
137
137
  try {
138
- const c = R(r);
139
- await c.fetch("origin", H);
140
- const m = (await c.revparse(["--show-toplevel"])).trim(), p = N(m, u).split(I).join("/"), w = await c.show([`origin/${H}:${p}`]);
141
- M(T(u), { recursive: !0 }), j(u, w);
142
- } catch (c) {
143
- const m = c instanceof Error ? c.message : String(c);
138
+ const l = H(i);
139
+ await l.fetch("origin", B);
140
+ const m = (await l.revparse(["--show-toplevel"])).trim(), p = N(m, u).split(G).join("/"), w = await l.show([`origin/${B}:${p}`]);
141
+ R(P(u), { recursive: !0 }), T(u, w);
142
+ } catch (l) {
143
+ const m = l instanceof Error ? l.message : String(l);
144
144
  console.warn(
145
- `[okno] sync: could not materialize ${i} from origin/${H} — ${m.split(`
145
+ `[okno] sync: could not materialize ${r} from origin/${B} — ${m.split(`
146
146
  `)[0]}`
147
147
  );
148
148
  }
149
- return D(n, i, u), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, invalidated: i }));
149
+ return D(n, r, u), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, invalidated: r }));
150
150
  }
151
- const s = R(r), f = await s.revparse(["--show-toplevel"]), l = N(f.trim(), r);
151
+ const s = H(i), f = await s.revparse(["--show-toplevel"]), a = N(f.trim(), i);
152
152
  try {
153
153
  const u = await s.pull();
154
- for (const c of u.files)
155
- if (c.startsWith(`${l}/`)) {
156
- const m = c.slice(`${l}/`.length), p = h(r, m);
154
+ for (const l of u.files)
155
+ if (l.startsWith(`${a}/`)) {
156
+ const m = l.slice(`${a}/`.length), p = h(i, m);
157
157
  D(n, m, p);
158
158
  }
159
159
  return t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, files: u.files }));
160
160
  } catch (u) {
161
- const c = u instanceof Error ? u.message : String(u);
162
- return console.warn(`[okno] sync: git pull skipped — ${c.split(`
163
- `)[0]}`), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, pullSkipped: !0, reason: c }));
161
+ const l = u instanceof Error ? u.message : String(u);
162
+ return console.warn(`[okno] sync: git pull skipped — ${l.split(`
163
+ `)[0]}`), t.setHeader("Content-Type", "application/json"), t.end(JSON.stringify({ ok: !0, pullSkipped: !0, reason: l }));
164
164
  }
165
165
  }
166
- a();
166
+ c();
167
167
  } catch (o) {
168
168
  t.statusCode = 500, t.end(JSON.stringify({ error: String(o) }));
169
169
  }
@@ -171,53 +171,53 @@ function pt(n, r) {
171
171
  }
172
172
  function gt(n) {
173
173
  if (!n) return { 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 };
174
+ const i = n.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
175
+ return i ? { owner: i[1], repo: i[2] } : { owner: null, repo: null };
176
176
  }
177
177
  function mt(n) {
178
- return new Promise((r, e) => {
178
+ return new Promise((i, e) => {
179
179
  const t = [];
180
- n.on("data", (a) => t.push(a)), n.on("end", () => r(Buffer.concat(t))), n.on("error", e);
180
+ n.on("data", (c) => t.push(c)), n.on("end", () => i(Buffer.concat(t))), n.on("error", e);
181
181
  });
182
182
  }
183
183
  function ht(n) {
184
- return new Promise((r) => {
184
+ return new Promise((i) => {
185
185
  let e = "";
186
186
  n.on("data", (t) => {
187
187
  e += t;
188
188
  }), n.on("end", () => {
189
189
  try {
190
- r(e ? JSON.parse(e) : null);
190
+ i(e ? JSON.parse(e) : null);
191
191
  } catch {
192
- r(null);
192
+ i(null);
193
193
  }
194
- }), n.on("error", () => r(null));
194
+ }), n.on("error", () => i(null));
195
195
  });
196
196
  }
197
- function D(n, r, e) {
197
+ function D(n, i, e) {
198
198
  const t = "\0okno:";
199
- let a;
200
- if (r.startsWith("pages/") ? a = t + "pages" : r.startsWith("collections/") ? a = t + "collections" : r.startsWith("globals/") && (a = t + "globals"), a) {
201
- const y = n.moduleGraph.getModuleById(a);
199
+ let c;
200
+ if (i.startsWith("pages/") ? c = t + "pages" : i.startsWith("collections/") ? c = t + "collections" : i.startsWith("globals/") && (c = t + "globals"), c) {
201
+ const y = n.moduleGraph.getModuleById(c);
202
202
  y && n.moduleGraph.invalidateModule(y);
203
203
  const o = n.moduleGraph.getModulesByFile(e);
204
- o && o.forEach((i) => {
205
- n.moduleGraph.invalidateModule(i);
204
+ o && o.forEach((r) => {
205
+ n.moduleGraph.invalidateModule(r);
206
206
  });
207
207
  }
208
208
  }
209
- function yt(n, r) {
210
- const e = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = r.replace(/\\/g, "/");
209
+ function yt(n, i) {
210
+ const e = (n.split("?")[0] ?? "").replace(/\\/g, "/"), t = i.replace(/\\/g, "/");
211
211
  return e === t || e.startsWith(t + "/");
212
212
  }
213
- function wt(n, r) {
214
- for (const [e, t] of Object.entries(r)) {
213
+ function wt(n, i) {
214
+ for (const [e, t] of Object.entries(i)) {
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"]), V = T(Z(import.meta.url)), _t = JSON.parse(U(g(V, "../package.json"), "utf-8")).version, L = q(), b = g(V, "../editor"), B = g(b, "index.ts"), Ot = O(B), kt = {
220
+ const bt = "okno:", S = "\0okno:", _t = /* @__PURE__ */ new Set(["pages", "collections", "globals", "locales", "strings", "content"]), V = P(Z(import.meta.url)), St = JSON.parse(U(g(V, "../package.json"), "utf-8")).version, L = q(), b = g(V, "../editor"), I = g(b, "index.ts"), Ot = O(I), kt = {
221
221
  "@modules": g(b, "modules"),
222
222
  "@lib": g(b, "lib"),
223
223
  "@logger": g(b, "lib/logger.svelte.ts"),
@@ -229,39 +229,51 @@ const bt = "okno:", _ = "\0okno:", St = /* @__PURE__ */ new Set(["pages", "colle
229
229
  "@pages": g(b, "pages"),
230
230
  "@controllers": g(b, "controllers")
231
231
  };
232
- function vt() {
232
+ function Et() {
233
233
  try {
234
- const n = (a) => K(a, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim(), e = n("git remote get-url origin").match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
235
- if (!e) return null;
236
- const t = n("git rev-parse --abbrev-ref HEAD") || "main";
237
- return `${e[1]}/${e[2]}@${t}`;
234
+ const n = (t) => K(t, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] }).trim(), e = n("git remote get-url origin").match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
235
+ return e ? `${e[1]}/${e[2]}@${vt(n)}` : null;
238
236
  } catch {
239
237
  return null;
240
238
  }
241
239
  }
242
- function Et() {
240
+ function vt(n) {
241
+ let i = "";
242
+ try {
243
+ i = n("git rev-parse --abbrev-ref HEAD");
244
+ } catch {
245
+ }
246
+ if (i && i !== "HEAD") return i;
247
+ const e = process.env;
248
+ return e.CF_PAGES_BRANCH || // Cloudflare Pages
249
+ e.VERCEL_GIT_COMMIT_REF || // Vercel
250
+ e.BRANCH || // Netlify
251
+ e.GITHUB_REF_NAME || // GitHub Actions
252
+ "main";
253
+ }
254
+ function Nt() {
243
255
  try {
244
256
  const n = K("git rev-parse --show-toplevel", {
245
257
  encoding: "utf-8",
246
258
  stdio: ["ignore", "pipe", "ignore"]
247
259
  }).trim();
248
- return N(n, process.cwd()).split(I).join("/");
260
+ return N(n, process.cwd()).split(G).join("/");
249
261
  } catch {
250
262
  return "";
251
263
  }
252
264
  }
253
- function jt(n = {}) {
254
- const r = n.dir ?? "okno";
255
- let e, t, a = !1, y = !1;
265
+ function It(n = {}) {
266
+ const i = n.dir ?? "okno";
267
+ let e, t, c = !1, y = !1;
256
268
  return n.isEditor, {
257
269
  name: "okno",
258
270
  enforce: "pre",
259
- config(o, i) {
260
- const s = i.command === "serve";
261
- return y = i.command === "build", a = s && Ot, {
271
+ config(o, r) {
272
+ const s = r.command === "serve";
273
+ return y = r.command === "build", c = s && Ot, {
262
274
  define: {
263
275
  __OKNO_API_URL__: JSON.stringify(n.apiUrl ?? "https://api.okno.build"),
264
- __OKNO_VERSION__: JSON.stringify(_t),
276
+ __OKNO_VERSION__: JSON.stringify(St),
265
277
  // True when the consumer is running `vite dev` / `astro dev` /
266
278
  // `sveltekit dev` — anything that serves locally. Replaced at
267
279
  // consumer build time so the prebuilt editor bundle can honor
@@ -275,12 +287,12 @@ function jt(n = {}) {
275
287
  // auto-targets its repo with no picker. null outside a git
276
288
  // checkout → editor falls back to the picker. Dev ignores it
277
289
  // (runtime /__okno/repo derivation is more current).
278
- __OKNO_REPO__: JSON.stringify(vt()),
290
+ __OKNO_REPO__: JSON.stringify(Et()),
279
291
  // Monorepo root path: the build dir relative to the git root (e.g.
280
292
  // "apps/site", or "" at the repo root). Sent as X-Okno-Path so the
281
293
  // hosted backend reads/writes content under `<root>/okno` instead of
282
294
  // the repo-root `okno` — one repo, many okno projects keyed (repo, path).
283
- __OKNO_ROOT__: JSON.stringify(Et())
295
+ __OKNO_ROOT__: JSON.stringify(Nt())
284
296
  },
285
297
  // Source mode (monorepo dev only): skip prebundling so saves to
286
298
  // `package/editor/**` propagate via HMR instead of needing
@@ -289,7 +301,7 @@ function jt(n = {}) {
289
301
  // identically-named tsconfig aliases (`@components`, `@lib`, …). They
290
302
  // are instead resolved per-importer in `resolveId`, scoped to imports
291
303
  // originating inside the editor source tree. See editor-aliases.ts.
292
- ...a && {
304
+ ...c && {
293
305
  optimizeDeps: { exclude: ["okno", "okno/editor"] }
294
306
  },
295
307
  server: {
@@ -302,7 +314,7 @@ function jt(n = {}) {
302
314
  // the backend mirrored saves to disk, causing spurious full
303
315
  // reloads. In production-mode the backend never touches local
304
316
  // FS so blocking those is pure harm — pulls go unseen.)
305
- ignored: [`**/${r}/files/**`, `**/${r}/.okno-tree.json`]
317
+ ignored: [`**/${i}/files/**`, `**/${i}/.okno-tree.json`]
306
318
  },
307
319
  // Source mode: the editor loads via a dynamic `import("okno/editor")`
308
320
  // from a separate package over `@fs`, so Vite's startup dep scan
@@ -311,22 +323,22 @@ function jt(n = {}) {
311
323
  // re-optimize that 404s the now-stale prebundled chunks. Warming the
312
324
  // editor entry forces that crawl at startup, so those deps land in
313
325
  // the first optimize pass and never re-bundle under the user.
314
- ...a && {
315
- warmup: { clientFiles: [B] }
326
+ ...c && {
327
+ warmup: { clientFiles: [I] }
316
328
  }
317
329
  }
318
330
  };
319
331
  },
320
332
  configResolved(o) {
321
- e = o.root, t = g(e, r);
333
+ e = o.root, t = g(e, i);
322
334
  },
323
335
  async buildStart() {
324
336
  if (O(t)) {
325
- if (await P(t, e), y) {
337
+ if (await M(t, e), y) {
326
338
  const o = h(t, "files");
327
339
  if (O(o)) {
328
- const i = O(h(e, "static")) ? h(e, "static") : h(e, "public"), s = h(i, "okno", "files");
329
- g(s) !== g(o) && (M(s, { recursive: !0 }), Q(o, s, {
340
+ const r = O(h(e, "static")) ? h(e, "static") : h(e, "public"), s = h(r, "okno", "files");
341
+ g(s) !== g(o) && (R(s, { recursive: !0 }), Q(o, s, {
330
342
  recursive: !0,
331
343
  filter: (f) => !f.endsWith(".okno-tree.json")
332
344
  }));
@@ -334,7 +346,7 @@ function jt(n = {}) {
334
346
  }
335
347
  if (n.demo) {
336
348
  const o = h(e, "public");
337
- O(o) || M(o, { recursive: !0 }), j(
349
+ O(o) || R(o, { recursive: !0 }), T(
338
350
  h(o, "okno-demo.json"),
339
351
  JSON.stringify(st(t))
340
352
  );
@@ -343,140 +355,140 @@ function jt(n = {}) {
343
355
  },
344
356
  configureServer(o) {
345
357
  pt(o, t);
346
- const i = (f) => {
347
- const l = N(t, f);
348
- if (l.startsWith("..") || !l.endsWith(".ts")) return;
349
- const u = l.split(/[\\/]/)[0];
358
+ const r = (f) => {
359
+ const a = N(t, f);
360
+ if (a.startsWith("..") || !a.endsWith(".ts")) return;
361
+ const u = a.split(/[\\/]/)[0];
350
362
  if (u !== "pages" && u !== "collections" && u !== "globals") return;
351
- const c = o.moduleGraph.getModuleById(_ + u);
352
- c && o.moduleGraph.invalidateModule(c), o.moduleGraph.getModulesByFile(f)?.forEach((m) => o.moduleGraph.invalidateModule(m)), !A(f) && o.ws.send({ type: "full-reload" });
363
+ const l = o.moduleGraph.getModuleById(S + u);
364
+ l && o.moduleGraph.invalidateModule(l), o.moduleGraph.getModulesByFile(f)?.forEach((m) => o.moduleGraph.invalidateModule(m)), !$(f) && o.ws.send({ type: "full-reload" });
353
365
  };
354
- o.watcher.on("add", i), o.watcher.on("unlink", i), o.middlewares.use("/__okno/imports", async (f, l, u) => {
366
+ o.watcher.on("add", r), o.watcher.on("unlink", r), o.middlewares.use("/__okno/imports", async (f, a, u) => {
355
367
  if (f.method !== "GET") return u();
356
368
  try {
357
- const [c, m, p] = await Promise.all([
358
- E(e, "pages"),
359
- E(e, "globals"),
360
- E(e, "collections")
369
+ const [l, m, p] = await Promise.all([
370
+ v(e, "pages"),
371
+ v(e, "globals"),
372
+ v(e, "collections")
361
373
  ]);
362
- l.setHeader("Content-Type", "application/json"), l.setHeader("Cache-Control", "no-store"), l.end(JSON.stringify({
363
- pages: Array.from(c),
374
+ a.setHeader("Content-Type", "application/json"), a.setHeader("Cache-Control", "no-store"), a.end(JSON.stringify({
375
+ pages: Array.from(l),
364
376
  globals: Array.from(m),
365
377
  collections: Array.from(p)
366
378
  }));
367
- } catch (c) {
368
- u(c);
379
+ } catch (l) {
380
+ u(l);
369
381
  }
370
382
  });
371
383
  const s = "/__okno_bootstrap.js";
372
- o.middlewares.use(s, async (f, l, u) => {
384
+ o.middlewares.use(s, async (f, a, u) => {
373
385
  try {
374
- const c = await o.transformRequest("\0okno:bootstrap");
375
- if (!c) {
376
- l.statusCode = 500, l.end("okno bootstrap transform failed");
386
+ const l = await o.transformRequest("\0okno:bootstrap");
387
+ if (!l) {
388
+ a.statusCode = 500, a.end("okno bootstrap transform failed");
377
389
  return;
378
390
  }
379
- l.setHeader("content-type", "text/javascript"), l.end(c.code);
380
- } catch (c) {
381
- u(c);
391
+ a.setHeader("content-type", "text/javascript"), a.end(l.code);
392
+ } catch (l) {
393
+ u(l);
382
394
  }
383
- }), o.middlewares.use((f, l, u) => {
384
- const c = "<script>window.__oknoDev=true<\/script>", m = n.demo ? "<script>window.__oknoDemo=true<\/script>" : "", p = `${c}${m}<script type="module" src="${s}"><\/script>`, w = [];
395
+ }), o.middlewares.use((f, a, u) => {
396
+ const l = "<script>window.__oknoDev=true<\/script>", m = n.demo ? "<script>window.__oknoDemo=true<\/script>" : "", p = `${l}${m}<script type="module" src="${s}"><\/script>`, w = [];
385
397
  let k = null;
386
- const X = l.write.bind(l), G = l.end.bind(l), z = l.setHeader.bind(l), W = () => {
387
- const d = l.getHeader("content-type");
398
+ const X = a.write.bind(a), j = a.end.bind(a), z = a.setHeader.bind(a), W = () => {
399
+ const d = a.getHeader("content-type");
388
400
  return typeof d == "string" && d.includes("text/html");
389
- }, J = (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));
390
- l.write = (d, S, ...C) => (k === null && (k = W()), k ? (d && w.push(J(d, typeof S == "string" ? S : void 0)), !0) : X(d, S, ...C)), l.end = (d, S, ...C) => {
391
- if (k === null && (k = W()), !k) return G(d, S, ...C);
392
- d && w.push(J(d, typeof S == "string" ? S : void 0));
393
- let v = Buffer.concat(w).toString("utf-8");
394
- v.includes(p) || (v = v.includes("</body>") ? v.replace("</body>", `${p}</body>`) : v + p);
395
- const $ = Buffer.from(v, "utf-8");
396
- if (!l.headersSent)
401
+ }, J = (d, _) => Buffer.isBuffer(d) ? d : d instanceof Uint8Array ? Buffer.from(d.buffer, d.byteOffset, d.byteLength) : typeof d == "string" ? Buffer.from(d, _ || "utf-8") : Buffer.from(String(d));
402
+ a.write = (d, _, ...C) => (k === null && (k = W()), k ? (d && w.push(J(d, typeof _ == "string" ? _ : void 0)), !0) : X(d, _, ...C)), a.end = (d, _, ...C) => {
403
+ if (k === null && (k = W()), !k) return j(d, _, ...C);
404
+ d && w.push(J(d, typeof _ == "string" ? _ : void 0));
405
+ let E = Buffer.concat(w).toString("utf-8");
406
+ E.includes(p) || (E = E.includes("</body>") ? E.replace("</body>", `${p}</body>`) : E + p);
407
+ const A = Buffer.from(E, "utf-8");
408
+ if (!a.headersSent)
397
409
  try {
398
- z("content-length", String($.length));
410
+ z("content-length", String(A.length));
399
411
  } catch {
400
412
  }
401
- return G($, ...C);
413
+ return j(A, ...C);
402
414
  }, u();
403
415
  });
404
416
  },
405
417
  async handleHotUpdate(o) {
406
- const i = h(t, "schema.ts"), s = h(t, "users.json"), f = h(t, "permissions.ts"), l = h(t, "modules.d.ts");
407
- if (o.file === i) {
408
- await P(t, e);
418
+ const r = h(t, "schema.ts"), s = h(t, "users.json"), f = h(t, "permissions.ts"), a = h(t, "modules.d.ts");
419
+ if (o.file === r) {
420
+ await M(t, e);
409
421
  for (const p of ["pages", "collections", "globals", "locales", "content", "strings"]) {
410
- const w = o.server.moduleGraph.getModuleById(_ + p);
422
+ const w = o.server.moduleGraph.getModuleById(S + p);
411
423
  w && o.server.moduleGraph.invalidateModule(w);
412
424
  }
413
425
  return [];
414
426
  }
415
- if (o.file === s || o.file === f || o.file === l)
427
+ if (o.file === s || o.file === f || o.file === a)
416
428
  return [];
417
- const u = h(t, "strings.ts"), c = N(h(t, "strings"), o.file);
418
- if (o.file === u || !c.startsWith("..") && c.endsWith(".ts")) {
419
- await P(t, e);
429
+ const u = h(t, "strings.ts"), l = N(h(t, "strings"), o.file);
430
+ if (o.file === u || !l.startsWith("..") && l.endsWith(".ts")) {
431
+ await M(t, e);
420
432
  for (const p of ["strings", "content"]) {
421
- const w = o.server.moduleGraph.getModuleById(_ + p);
433
+ const w = o.server.moduleGraph.getModuleById(S + p);
422
434
  w && o.server.moduleGraph.invalidateModule(w);
423
435
  }
424
436
  }
425
437
  const m = N(t, o.file);
426
438
  if (!m.startsWith("..") && m.endsWith(".ts")) {
427
439
  const p = m.split(/[\\/]/)[0];
428
- if ((p === "pages" || p === "collections" || p === "globals") && A(o.file)) {
429
- const w = o.server.moduleGraph.getModuleById(_ + p);
440
+ if ((p === "pages" || p === "collections" || p === "globals") && $(o.file)) {
441
+ const w = o.server.moduleGraph.getModuleById(S + p);
430
442
  return w && o.server.moduleGraph.invalidateModule(w), [];
431
443
  }
432
444
  }
433
445
  },
434
- async resolveId(o, i) {
446
+ async resolveId(o, r) {
435
447
  if (o.startsWith(bt))
436
448
  return "\0" + o;
437
449
  if (o.startsWith("okno/")) {
438
450
  const s = o.slice(5);
439
- if (St.has(s)) return _ + s;
451
+ if (_t.has(s)) return S + s;
440
452
  }
441
- if (a && o === "okno/editor")
442
- return B;
443
- if (a && i && yt(i, b)) {
453
+ if (c && o === "okno/editor")
454
+ return I;
455
+ if (c && r && yt(r, b)) {
444
456
  const s = wt(o, kt);
445
457
  if (s)
446
- return (await this.resolve(s, i, { skipSelf: !0 }))?.id;
458
+ return (await this.resolve(s, r, { skipSelf: !0 }))?.id;
447
459
  }
448
460
  },
449
461
  async load(o) {
450
- if (!o.startsWith(_)) return;
451
- const i = o.slice(_.length);
452
- if (i === "runtime") {
462
+ if (!o.startsWith(S)) return;
463
+ const r = o.slice(S.length);
464
+ if (r === "runtime") {
453
465
  if (!L)
454
466
  throw new Error("okno: runtime/wrap.js missing — run `bun run build:pkg`");
455
467
  return L;
456
468
  }
457
- if (i === "bootstrap")
469
+ if (r === "bootstrap")
458
470
  return 'import("okno/editor")';
459
- if (i === "pages") {
460
- const s = await E(e, "pages");
471
+ if (r === "pages") {
472
+ const s = await v(e, "pages");
461
473
  return await tt(t, s);
462
474
  }
463
- if (i === "collections") {
464
- const s = await E(e, "collections");
475
+ if (r === "collections") {
476
+ const s = await v(e, "collections");
465
477
  return await et(t, s, y);
466
478
  }
467
- if (i === "globals") {
468
- const s = await E(e, "globals");
479
+ if (r === "globals") {
480
+ const s = await v(e, "globals");
469
481
  return await ot(t, s);
470
482
  }
471
- if (i === "locales")
483
+ if (r === "locales")
472
484
  return nt(t);
473
- if (i === "strings")
474
- return await it(t);
475
- if (i === "content")
476
- return rt();
485
+ if (r === "strings")
486
+ return await rt(t);
487
+ if (r === "content")
488
+ return it();
477
489
  }
478
490
  };
479
491
  }
480
492
  export {
481
- jt as o
493
+ It as o
482
494
  };
@@ -1,4 +1,4 @@
1
- import { o as a } from "../plugin-HRVyik1g.js";
1
+ import { o as a } from "../plugin-jvqdZWC0.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;AA8FpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,CAsZpD"}
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;AAoHpD,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,GAAG,MAAM,CAsZpD"}
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.18",
5
+ "version": "1.0.0-beta.20",
6
6
  "homepage": "https://okno.build",
7
7
  "type": "module",
8
8
  "types": "./dist/index.d.ts",