okno 1.0.0-beta.57 → 1.0.0-beta.58
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/astro/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/integrations/vite/plugin.d.ts.map +1 -1
- package/dist/plugin-CCR685gH.js +580 -0
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/dist/plugin-BiIIWwGR.js +0 -573
package/dist/astro/index.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/integrations/vite/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAQ3D,OAAO,EAQN,KAAK,SAAS,EACd,MAAM,0BAA0B,CAAA;AAajC,KAAK,kBAAkB,GAAG,OAAO,GAAG,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;AAErF;8DAC8D;AAC9D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB,EAAE,GAAG,IAAI,CAQ9F;AAyFD,UAAU,0BAA0B;IACnC;qEACiE;IACjE,SAAS,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;+EAC+E;AAC/E,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,EAAE,WAAW,GAAE,0BAA+B,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/integrations/vite/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAA;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAQ3D,OAAO,EAQN,KAAK,SAAS,EACd,MAAM,0BAA0B,CAAA;AAajC,KAAK,kBAAkB,GAAG,OAAO,GAAG,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;AAErF;8DAC8D;AAC9D,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB,EAAE,GAAG,IAAI,CAQ9F;AAyFD,UAAU,0BAA0B;IACnC;qEACiE;IACjE,SAAS,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;+EAC+E;AAC/E,wBAAgB,IAAI,CAAC,MAAM,GAAE,UAAe,EAAE,WAAW,GAAE,0BAA+B,GAAG,MAAM,EAAE,CAsiBpG"}
|
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import { F as rt, b as St, C as D } from "./format-BLz4SuAo.js";
|
|
2
|
+
import { d as kt, r as _t, c as Ot, g as Nt, s as P, b as jt, f as Q, a as Et, e as Ct, h as Tt, i as Ht, j as vt, k as it, l as Y, m as Rt, n as Ft, o as It, p as Jt } from "./dispatch-DQ_4U5Df.js";
|
|
3
|
+
import { join as O, dirname as W, relative as J, sep as gt, resolve as b } from "node:path";
|
|
4
|
+
import { existsSync as I, statSync as Mt, readFileSync as U, mkdirSync as at, watch as Pt, readdirSync as Wt } from "node:fs";
|
|
5
|
+
import { fileURLToPath as $t } from "node:url";
|
|
6
|
+
import { w as Bt, a as At, s as lt, c as V } from "./store-CJ2sqOKN.js";
|
|
7
|
+
import { simpleGit as Z } from "simple-git";
|
|
8
|
+
import "node:crypto";
|
|
9
|
+
import "node:child_process";
|
|
10
|
+
import "./encode-EHnvycZZ.js";
|
|
11
|
+
import "./operations-BTS0mCeT.js";
|
|
12
|
+
import { e as Gt } from "./usage-CmeL5A64.js";
|
|
13
|
+
import "node:os";
|
|
14
|
+
function ct(t, r, o) {
|
|
15
|
+
t.statusCode = r, t.setHeader("Content-Type", "application/json"), t.setHeader("Cache-Control", "no-store"), t.end(JSON.stringify(o));
|
|
16
|
+
}
|
|
17
|
+
function Lt(t) {
|
|
18
|
+
return new Promise((r) => {
|
|
19
|
+
let o = "";
|
|
20
|
+
t.on("data", (s) => o += s), t.on("end", () => {
|
|
21
|
+
try {
|
|
22
|
+
r(o ? JSON.parse(o) : {});
|
|
23
|
+
} catch {
|
|
24
|
+
r({});
|
|
25
|
+
}
|
|
26
|
+
}), t.on("error", () => r({}));
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function Ut(t) {
|
|
30
|
+
return new Promise((r, o) => {
|
|
31
|
+
const s = [];
|
|
32
|
+
t.on("data", (e) => s.push(e)), t.on("end", () => r(Buffer.concat(s))), t.on("error", o);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function Kt(t, r) {
|
|
36
|
+
var o;
|
|
37
|
+
if (r) {
|
|
38
|
+
for (const s of new Set(r.modules)) {
|
|
39
|
+
const e = t.moduleGraph.getModuleById("\0okno:" + s);
|
|
40
|
+
e && t.moduleGraph.invalidateModule(e);
|
|
41
|
+
}
|
|
42
|
+
for (const s of new Set(r.files))
|
|
43
|
+
(o = t.moduleGraph.getModulesByFile(s)) == null || o.forEach((e) => t.moduleGraph.invalidateModule(e));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function Dt(t, r) {
|
|
47
|
+
t.middlewares.use(async (o, s, e) => {
|
|
48
|
+
var y;
|
|
49
|
+
if (!((y = o.url) != null && y.startsWith("/__okno/api/"))) return e();
|
|
50
|
+
const m = o.url.slice(12).split("?")[0], i = {
|
|
51
|
+
method: o.method || "GET",
|
|
52
|
+
route: m,
|
|
53
|
+
json: () => Lt(o),
|
|
54
|
+
binary: () => Ut(o),
|
|
55
|
+
header: (l) => {
|
|
56
|
+
const c = o.headers[l];
|
|
57
|
+
return Array.isArray(c) ? c[0] : c;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
const l = await kt(r, i);
|
|
62
|
+
if (!l) return e();
|
|
63
|
+
Kt(t, l.invalidation), ct(s, l.status, l.body);
|
|
64
|
+
} catch (l) {
|
|
65
|
+
ct(s, 500, { error: l instanceof Error ? l.message : String(l) });
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function Vt(t, r) {
|
|
70
|
+
let o;
|
|
71
|
+
try {
|
|
72
|
+
o = decodeURIComponent(r);
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if (!o || o.includes("\0")) return null;
|
|
77
|
+
const s = b(t, "files"), e = b(s, o);
|
|
78
|
+
return e === s || !e.startsWith(s + gt) ? null : e;
|
|
79
|
+
}
|
|
80
|
+
const x = "okno";
|
|
81
|
+
function zt(t, r, o = "/") {
|
|
82
|
+
Dt(t, r), t.middlewares.use((s, e, m) => {
|
|
83
|
+
var _;
|
|
84
|
+
const i = o.replace(/\/$/, ""), y = i && ((_ = s.url) != null && _.startsWith(i + "/okno/files/")) ? s.url.slice(i.length) : s.url;
|
|
85
|
+
if (s.method !== "GET" || !(y != null && y.startsWith("/okno/files/"))) return m();
|
|
86
|
+
const l = y.slice(12).split("?")[0];
|
|
87
|
+
if (!l) return m();
|
|
88
|
+
const c = Vt(r, l);
|
|
89
|
+
if (!c)
|
|
90
|
+
return e.statusCode = 403, e.end("Forbidden");
|
|
91
|
+
if (!I(c)) {
|
|
92
|
+
const H = _t(r)["/okno/files/" + l];
|
|
93
|
+
return H ? (e.statusCode = 302, e.setHeader("Location", H), e.setHeader("Cache-Control", "no-cache"), e.end()) : (e.statusCode = 404, e.end("Not found"));
|
|
94
|
+
}
|
|
95
|
+
const d = Mt(c), k = `W/"${d.size}-${Math.floor(d.mtimeMs)}"`;
|
|
96
|
+
if (e.setHeader("Content-Type", Gt(c) || "application/octet-stream"), e.setHeader("Cache-Control", "no-cache"), e.setHeader("ETag", k), s.headers["if-none-match"] === k)
|
|
97
|
+
return e.statusCode = 304, e.end();
|
|
98
|
+
e.end(U(c));
|
|
99
|
+
}), t.middlewares.use(async (s, e, m) => {
|
|
100
|
+
var y, l;
|
|
101
|
+
if (!((y = s.url) != null && y.startsWith("/__okno/"))) return m();
|
|
102
|
+
const i = s.url.slice(8);
|
|
103
|
+
if (Ot({ method: s.method || "GET", header: (c) => {
|
|
104
|
+
const d = s.headers[c];
|
|
105
|
+
return Array.isArray(d) ? d[0] : d;
|
|
106
|
+
} }))
|
|
107
|
+
return e.statusCode = 403, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ error: "Cross-site requests can't change local content" }));
|
|
108
|
+
e.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate"), e.setHeader("Pragma", "no-cache"), e.setHeader("Expires", "0");
|
|
109
|
+
try {
|
|
110
|
+
if (s.method === "GET" && i === "repo") {
|
|
111
|
+
e.setHeader("Content-Type", "application/json");
|
|
112
|
+
try {
|
|
113
|
+
const c = Z(t.config.root), d = (l = await c.remote(["get-url", "origin"])) == null ? void 0 : l.toString().trim(), k = (await c.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: _, repo: H } = Xt(d);
|
|
114
|
+
return e.end(
|
|
115
|
+
JSON.stringify({ ok: !0, owner: _, repo: H, branch: k || null, remote: d || null })
|
|
116
|
+
);
|
|
117
|
+
} catch (c) {
|
|
118
|
+
return e.end(JSON.stringify({ ok: !1, error: String(c) }));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (s.method === "POST" && i.startsWith("mirror")) {
|
|
122
|
+
const d = new URL(s.url, "http://localhost").searchParams.get("path");
|
|
123
|
+
if (!d || d.includes("..") || !d.startsWith("files/"))
|
|
124
|
+
return e.statusCode = 400, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ error: "Invalid path" }));
|
|
125
|
+
const k = O(r, d);
|
|
126
|
+
if (I(k))
|
|
127
|
+
return e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ ok: !0, skipped: !0 }));
|
|
128
|
+
const _ = await Qt(s);
|
|
129
|
+
return at(W(k), { recursive: !0 }), Bt(k, _), e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ ok: !0, written: d, bytes: _.length }));
|
|
130
|
+
}
|
|
131
|
+
if (s.method === "POST" && i === "sync") {
|
|
132
|
+
const c = await Yt(s), d = c == null ? void 0 : c.path;
|
|
133
|
+
if (d) {
|
|
134
|
+
if (d.includes("..") || d.includes("\0"))
|
|
135
|
+
return e.statusCode = 400, e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ error: "Invalid path" }));
|
|
136
|
+
const T = O(r, d);
|
|
137
|
+
try {
|
|
138
|
+
const j = Z(r);
|
|
139
|
+
await j.fetch("origin", x);
|
|
140
|
+
const n = (await j.revparse(["--show-toplevel"])).trim(), u = J(n, T).split(gt).join("/"), p = await j.show([`origin/${x}:${u}`]);
|
|
141
|
+
at(W(T), { recursive: !0 }), At(T, p);
|
|
142
|
+
} catch (j) {
|
|
143
|
+
const n = j instanceof Error ? j.message : String(j);
|
|
144
|
+
console.warn(
|
|
145
|
+
`[okno] sync: could not materialize ${d} from origin/${x} — ${n.split(`
|
|
146
|
+
`)[0]}`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
return ut(t, d, T), e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ ok: !0, invalidated: d }));
|
|
150
|
+
}
|
|
151
|
+
const k = Z(r), _ = await k.revparse(["--show-toplevel"]), H = J(_.trim(), r);
|
|
152
|
+
try {
|
|
153
|
+
const T = await k.pull();
|
|
154
|
+
for (const j of T.files)
|
|
155
|
+
if (j.startsWith(`${H}/`)) {
|
|
156
|
+
const n = j.slice(`${H}/`.length), u = O(r, n);
|
|
157
|
+
ut(t, n, u);
|
|
158
|
+
}
|
|
159
|
+
return e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ ok: !0, files: T.files }));
|
|
160
|
+
} catch (T) {
|
|
161
|
+
const j = T instanceof Error ? T.message : String(T);
|
|
162
|
+
return console.warn(`[okno] sync: git pull skipped — ${j.split(`
|
|
163
|
+
`)[0]}`), e.setHeader("Content-Type", "application/json"), e.end(JSON.stringify({ ok: !0, pullSkipped: !0, reason: j }));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
m();
|
|
167
|
+
} catch (c) {
|
|
168
|
+
e.statusCode = 500, e.end(JSON.stringify({ error: String(c) }));
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function Xt(t) {
|
|
173
|
+
if (!t) return { owner: null, repo: null };
|
|
174
|
+
const r = t.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
|
|
175
|
+
return r ? { owner: r[1], repo: r[2] } : { owner: null, repo: null };
|
|
176
|
+
}
|
|
177
|
+
function Qt(t) {
|
|
178
|
+
return new Promise((r, o) => {
|
|
179
|
+
const s = [];
|
|
180
|
+
t.on("data", (e) => s.push(e)), t.on("end", () => r(Buffer.concat(s))), t.on("error", o);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function Yt(t) {
|
|
184
|
+
return new Promise((r) => {
|
|
185
|
+
let o = "";
|
|
186
|
+
t.on("data", (s) => {
|
|
187
|
+
o += s;
|
|
188
|
+
}), t.on("end", () => {
|
|
189
|
+
try {
|
|
190
|
+
r(o ? JSON.parse(o) : null);
|
|
191
|
+
} catch {
|
|
192
|
+
r(null);
|
|
193
|
+
}
|
|
194
|
+
}), t.on("error", () => r(null));
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function ut(t, r, o) {
|
|
198
|
+
const s = "\0okno:";
|
|
199
|
+
let e;
|
|
200
|
+
if (r.startsWith("pages/") ? e = s + "pages" : r.startsWith("collections/") ? e = s + "collections" : r.startsWith("globals/") && (e = s + "globals"), e) {
|
|
201
|
+
const m = t.moduleGraph.getModuleById(e);
|
|
202
|
+
m && t.moduleGraph.invalidateModule(m);
|
|
203
|
+
const i = t.moduleGraph.getModulesByFile(o);
|
|
204
|
+
i && i.forEach((y) => {
|
|
205
|
+
t.moduleGraph.invalidateModule(y);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function Zt(t, r) {
|
|
210
|
+
const o = (t.split("?")[0] ?? "").replace(/\\/g, "/"), s = r.replace(/\\/g, "/");
|
|
211
|
+
return o === s || o.startsWith(s + "/");
|
|
212
|
+
}
|
|
213
|
+
function xt(t, r) {
|
|
214
|
+
for (const [o, s] of Object.entries(r)) {
|
|
215
|
+
if (t === o) return s;
|
|
216
|
+
if (t.startsWith(o + "/")) return s + t.slice(o.length);
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
const z = "\0okno:", qt = /* @__PURE__ */ new Set([
|
|
221
|
+
"runtime",
|
|
222
|
+
"bootstrap",
|
|
223
|
+
"pages",
|
|
224
|
+
"collections",
|
|
225
|
+
"globals",
|
|
226
|
+
"locales",
|
|
227
|
+
"strings",
|
|
228
|
+
"content"
|
|
229
|
+
]);
|
|
230
|
+
function dt(t, r) {
|
|
231
|
+
const o = J(t, r).split("\\").join("/");
|
|
232
|
+
if (o === "files/.okno-tree.json") return ["pages", "collections", "globals", "content"];
|
|
233
|
+
if (!o || o.startsWith("../") || !o.endsWith(".ts")) return null;
|
|
234
|
+
if (o === "strings.ts" || /^strings\/[^/]+\.ts$/.test(o)) return ["strings", "content"];
|
|
235
|
+
const s = o.split("/")[0];
|
|
236
|
+
return s === "pages" || s === "collections" || s === "globals" ? [s] : null;
|
|
237
|
+
}
|
|
238
|
+
function ft(t, r) {
|
|
239
|
+
const o = J(t, r);
|
|
240
|
+
return !!o && !o.startsWith("..") && V(r);
|
|
241
|
+
}
|
|
242
|
+
function L(t, r, o = []) {
|
|
243
|
+
var i, y;
|
|
244
|
+
const s = new Set(Object.values(t.environments ?? {}).map((l) => l.moduleGraph));
|
|
245
|
+
s.size || s.add(t.moduleGraph);
|
|
246
|
+
const e = new Set(r), m = new Set(o);
|
|
247
|
+
for (const l of s) {
|
|
248
|
+
for (const c of e) {
|
|
249
|
+
const d = l.getModuleById(z + c);
|
|
250
|
+
d && l.invalidateModule(d);
|
|
251
|
+
}
|
|
252
|
+
for (const c of m) (i = l.getModulesByFile(c)) == null || i.forEach((d) => l.invalidateModule(d));
|
|
253
|
+
}
|
|
254
|
+
for (const l of Object.values(t.environments ?? {}))
|
|
255
|
+
((y = l.config) == null ? void 0 : y.consumer) === "server" && "runner" in l && l.runner.clearCache();
|
|
256
|
+
}
|
|
257
|
+
const q = W($t(import.meta.url)), K = [b(q, "../package.json"), b(q, "../../package.json"), b(q, "../../../package.json")].find(I);
|
|
258
|
+
if (!K) throw new Error("okno: package.json not found");
|
|
259
|
+
function te(t) {
|
|
260
|
+
const r = O(t, rt);
|
|
261
|
+
try {
|
|
262
|
+
const o = St(I(r) ? { [rt]: U(r, "utf-8") } : {});
|
|
263
|
+
o < D ? console.warn(`[okno] okno/ uses format ${o}, this package uses ${D}. Run: npx okno upgrade`) : o > D && console.warn(`[okno] okno/ uses format ${o}, newer than this package understands (${D}). Update okno.`);
|
|
264
|
+
} catch (o) {
|
|
265
|
+
console.warn(`[okno] ${o instanceof Error ? o.message : o}`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const ee = JSON.parse(U(K, "utf-8")).version, pt = !W(K).split(/[\\/]/).includes("node_modules"), mt = [["dist/editor", "index.js"], ["dist", "boot.js"]].map(([t, r]) => [O(W(K), t), r]), ht = Nt(), C = b(W(K), "../editor"), tt = b(C, "index.ts"), ne = I(tt), oe = {
|
|
269
|
+
"@app": b(C, "app"),
|
|
270
|
+
"@state": b(C, "state"),
|
|
271
|
+
"@bindings": b(C, "bindings"),
|
|
272
|
+
"@lib": b(C, "lib"),
|
|
273
|
+
"@logger": b(C, "lib/logger.svelte.ts"),
|
|
274
|
+
"@utils": b(C, "lib/utils.ts"),
|
|
275
|
+
"@/types": b(C, "lib/types.ts"),
|
|
276
|
+
"@styles": b(C, "styles"),
|
|
277
|
+
"@components": b(C, "components"),
|
|
278
|
+
"@assets": b(C, "assets"),
|
|
279
|
+
"@pages": b(C, "pages"),
|
|
280
|
+
"@controllers": b(C, "controllers")
|
|
281
|
+
};
|
|
282
|
+
function ye(t = {}, r = {}) {
|
|
283
|
+
const o = t.dir ?? "okno", s = r.imageMode ?? "raw", e = s === "astro" ? "astro" : void 0;
|
|
284
|
+
let m, i, y = !1, l = !1, c = {}, d = !1, k = !1, _ = "/";
|
|
285
|
+
t.isEditor;
|
|
286
|
+
const H = async (n, u = !0) => {
|
|
287
|
+
const p = O(i, "schema.ts"), f = O(i, "users.json"), a = O(i, "permissions.ts"), w = O(i, "modules.d.ts"), h = O(i, "files", ".okno-tree.json");
|
|
288
|
+
if (n.file === p)
|
|
289
|
+
return u && await Y(i, m, k ? "development" : "strict", e), L(n.server, ["pages", "collections", "globals", "locales", "content", "strings"], [n.file]), [];
|
|
290
|
+
if (n.file === f || n.file === a || n.file === w) return [];
|
|
291
|
+
const S = dt(i, n.file);
|
|
292
|
+
return S ? (S[0] === "strings" && u && await Y(i, m, k ? "development" : "strict", e), V(n.file) ? (L(n.server, S, [n.file]), []) : n.file !== h ? void 0 : (u && (L(n.server, S, [n.file]), n.server.ws.send({ type: "full-reload" })), [])) : J(i, n.file).split("\\").join("/").startsWith("files/") && V(n.file) ? (L(n.server, ["pages", "collections", "globals", "content"], [n.file]), []) : void 0;
|
|
293
|
+
};
|
|
294
|
+
return [{
|
|
295
|
+
name: "okno",
|
|
296
|
+
enforce: "pre",
|
|
297
|
+
config(n, u) {
|
|
298
|
+
const p = u.command === "serve";
|
|
299
|
+
return l = u.command === "build", y = p && ne && t.builtEditor === !1, c = {
|
|
300
|
+
__OKNO_API_URL__: JSON.stringify(t.apiUrl ?? "https://api.okno.build"),
|
|
301
|
+
__OKNO_VERSION__: JSON.stringify(ee),
|
|
302
|
+
// True when the consumer is running `vite dev` / `astro dev` /
|
|
303
|
+
// `sveltekit dev` — anything that serves locally. Replaced at
|
|
304
|
+
// consumer build time so the prebuilt editor bundle can honor
|
|
305
|
+
// the consumer's actual environment.
|
|
306
|
+
__OKNO_IS_DEV__: JSON.stringify(p),
|
|
307
|
+
// Public demo build: editor boots login-less, reads a static
|
|
308
|
+
// `okno-demo.json` snapshot, no-ops writes. See docs/demo-mode.md.
|
|
309
|
+
__OKNO_DEMO__: JSON.stringify(t.demo ?? !1),
|
|
310
|
+
__OKNO_INTERNAL_TESTING__: JSON.stringify(t.internalTesting === !0),
|
|
311
|
+
// Repo identity (`owner/repo@branch`) baked from the app's git
|
|
312
|
+
// origin (or the host's variables, see identity.ts) at build time,
|
|
313
|
+
// so the deployed editor auto-targets its repo. Dev may be null and
|
|
314
|
+
// ignores it (runtime /__okno/repo derivation is more current).
|
|
315
|
+
// A production build that can't name its repo stops here: its
|
|
316
|
+
// editor would ship but never sign anyone in on the live site.
|
|
317
|
+
__OKNO_REPO__: JSON.stringify(l && !t.demo ? Ft(o) : It(o)),
|
|
318
|
+
// Monorepo root path: the build dir relative to the git root (e.g.
|
|
319
|
+
// "apps/site", or "" at the repo root). Sent as X-Okno-Path so the
|
|
320
|
+
// hosted backend reads/writes content under `<root>/okno` instead of
|
|
321
|
+
// the repo-root `okno` — one repo, many okno projects keyed (repo, path).
|
|
322
|
+
__OKNO_ROOT__: JSON.stringify(Rt())
|
|
323
|
+
}, {
|
|
324
|
+
define: c,
|
|
325
|
+
// Source mode (monorepo dev only): skip prebundling so saves to
|
|
326
|
+
// `editor/**` propagate via HMR instead of needing
|
|
327
|
+
// `bun run build:pkg`. The editor's internal @-aliases are NOT exposed
|
|
328
|
+
// as a global `resolve.alias` here — that shadowed a consumer's own
|
|
329
|
+
// identically-named tsconfig aliases (`@components`, `@lib`, …). They
|
|
330
|
+
// are instead resolved per-importer in `resolveId`, scoped to imports
|
|
331
|
+
// originating inside the editor source tree. See editor-aliases.ts.
|
|
332
|
+
...y && {
|
|
333
|
+
optimizeDeps: { exclude: ["okno", "okno/editor"] }
|
|
334
|
+
},
|
|
335
|
+
...!y && p && pt && { optimizeDeps: { force: !0 } },
|
|
336
|
+
server: {
|
|
337
|
+
watch: {
|
|
338
|
+
// External content/assets must remain observable. Only private
|
|
339
|
+
// editor metadata and atomic-write staging files are ignored.
|
|
340
|
+
ignored: (f) => {
|
|
341
|
+
const a = J(i, f).split("\\").join("/");
|
|
342
|
+
return a === ".okno-tree.json" || a.startsWith("files/") && /\/\.[^/]+\.okno-[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(a);
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
// Source mode: the editor loads via a dynamic `import("okno/editor")`
|
|
346
|
+
// from a separate package over `@fs`, so Vite's startup dep scan
|
|
347
|
+
// never crawls it — its transitive deps (bits-ui, tiptap, runed…)
|
|
348
|
+
// are discovered lazily on first import, triggering a mid-session
|
|
349
|
+
// re-optimize that 404s the now-stale prebundled chunks. Warming the
|
|
350
|
+
// editor entry forces that crawl at startup, so those deps land in
|
|
351
|
+
// the first optimize pass and never re-bundle under the user.
|
|
352
|
+
...y && {
|
|
353
|
+
warmup: { clientFiles: [tt] }
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
},
|
|
358
|
+
configResolved(n) {
|
|
359
|
+
var u;
|
|
360
|
+
k = n.command === "serve", _ = n.base ?? "/", m = n.root, i = b(m, o), d = !!((u = n.build) != null && u.ssr);
|
|
361
|
+
},
|
|
362
|
+
async buildStart() {
|
|
363
|
+
var a;
|
|
364
|
+
if (!I(i)) return;
|
|
365
|
+
te(i), await Y(i, m, k ? "development" : "strict", e), this.addWatchFile(O(i, "files", ".okno-tree.json"));
|
|
366
|
+
const n = (a = this.environment) == null ? void 0 : a.config.consumer;
|
|
367
|
+
if (!l || (n ? n !== "client" : d)) return;
|
|
368
|
+
this.addWatchFile(O(i, ".revision"));
|
|
369
|
+
const u = it(i);
|
|
370
|
+
u !== null && this.emitFile({ type: "asset", fileName: "okno/build.json", source: u });
|
|
371
|
+
const p = O(i, "files"), f = (w) => {
|
|
372
|
+
this.addWatchFile(w);
|
|
373
|
+
for (const h of Wt(w, { withFileTypes: !0 })) {
|
|
374
|
+
if (h.name === ".okno-tree.json" || w === p && h.name === ".trash") continue;
|
|
375
|
+
const S = O(w, h.name);
|
|
376
|
+
h.isDirectory() ? f(S) : h.isFile() && (this.addWatchFile(S), this.emitFile({
|
|
377
|
+
type: "asset",
|
|
378
|
+
fileName: `okno/files/${J(p, S).split("\\").join("/")}`,
|
|
379
|
+
source: U(S)
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
I(p) && f(p), Jt(i, _), t.demo && this.emitFile({ type: "asset", fileName: "okno-demo.json", source: JSON.stringify(lt(i)) });
|
|
384
|
+
},
|
|
385
|
+
configureServer(n) {
|
|
386
|
+
if (zt(n, i, _), !y && pt && n.httpServer) {
|
|
387
|
+
let f = null;
|
|
388
|
+
const a = (N) => {
|
|
389
|
+
try {
|
|
390
|
+
return U(N, "utf8");
|
|
391
|
+
} catch {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
}, w = new Map(mt.map(([N, $]) => [O(N, $), a(O(N, $))])), h = mt.filter(([N]) => I(N)).map(([N, $]) => Pt(N, (yt, B) => {
|
|
395
|
+
B === $ && (f && clearTimeout(f), f = setTimeout(() => {
|
|
396
|
+
f = null, [...w].some(([A, F]) => a(A) !== F) && n.config.logger.info("[okno] linked build changed; restart the dev server to load it");
|
|
397
|
+
}, 800));
|
|
398
|
+
})), S = () => {
|
|
399
|
+
f && clearTimeout(f);
|
|
400
|
+
for (const N of h) N.close();
|
|
401
|
+
};
|
|
402
|
+
n.httpServer.once("close", S);
|
|
403
|
+
}
|
|
404
|
+
n.middlewares.use((f, a, w) => {
|
|
405
|
+
var S;
|
|
406
|
+
if (f.method !== "GET") return w();
|
|
407
|
+
const h = (S = f.url) == null ? void 0 : S.split("?")[0];
|
|
408
|
+
if (h !== "/okno/build.json" && !(t.demo && h === "/okno-demo.json") || !I(i)) return w();
|
|
409
|
+
a.setHeader("Content-Type", "application/json"), a.setHeader("Cache-Control", "no-store"), a.end(h === "/okno/build.json" ? it(i) : JSON.stringify(lt(i)));
|
|
410
|
+
});
|
|
411
|
+
const u = (f) => {
|
|
412
|
+
const a = J(i, f).split("\\").join("/"), w = dt(i, f) ?? (a.startsWith("files/") && !a.startsWith("files/.trash/") ? ["pages", "collections", "globals", "content"] : null);
|
|
413
|
+
w && (L(n, w, [f]), !V(f) && n.ws.send({ type: "full-reload" }));
|
|
414
|
+
};
|
|
415
|
+
n.watcher.on("add", u), n.watcher.on("unlink", u), n.middlewares.use("/__okno/imports", async (f, a, w) => {
|
|
416
|
+
if (f.method !== "GET") return w();
|
|
417
|
+
try {
|
|
418
|
+
const [h, S, N] = await Promise.all([
|
|
419
|
+
P(m, "pages"),
|
|
420
|
+
P(m, "globals"),
|
|
421
|
+
P(m, "collections")
|
|
422
|
+
]);
|
|
423
|
+
a.setHeader("Content-Type", "application/json"), a.setHeader("Cache-Control", "no-store"), a.end(JSON.stringify({
|
|
424
|
+
pages: Array.from(h),
|
|
425
|
+
globals: Array.from(S),
|
|
426
|
+
collections: Array.from(N)
|
|
427
|
+
}));
|
|
428
|
+
} catch (h) {
|
|
429
|
+
w(h);
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
const p = "/__okno_bootstrap.js";
|
|
433
|
+
n.middlewares.use(p, async (f, a, w) => {
|
|
434
|
+
try {
|
|
435
|
+
const h = await n.transformRequest("\0okno:bootstrap");
|
|
436
|
+
if (!h) {
|
|
437
|
+
a.statusCode = 500, a.end("okno bootstrap transform failed");
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
a.setHeader("content-type", "text/javascript"), a.end(h.code);
|
|
441
|
+
} catch (h) {
|
|
442
|
+
w(h);
|
|
443
|
+
}
|
|
444
|
+
}), n.middlewares.use((f, a, w) => {
|
|
445
|
+
var st;
|
|
446
|
+
const h = "<script>window.__oknoDev=true<\/script>", S = t.demo ? "<script>window.__oknoDemo=true<\/script>" : "", N = t.internalTesting === !0 ? "<script>window.__oknoInternalTesting=true<\/script>" : "", B = `${`<script>Object.assign(globalThis,${JSON.stringify(Object.fromEntries(Object.entries(c).map(([g, E]) => [g, JSON.parse(E)]))).replace(/</g, "\\u003c")})<\/script>`}${h}${S}${N}<script type="module" src="${p}"><\/script>`, A = [];
|
|
447
|
+
let F = null;
|
|
448
|
+
const wt = a.write.bind(a), et = a.end.bind(a), bt = a.setHeader.bind(a), X = () => {
|
|
449
|
+
const g = a.getHeader("content-type");
|
|
450
|
+
return typeof g == "string" && g.includes("text/html");
|
|
451
|
+
}, nt = (g, E) => Buffer.isBuffer(g) ? g : g instanceof Uint8Array ? Buffer.from(g.buffer, g.byteOffset, g.byteLength) : typeof g == "string" ? Buffer.from(g, E || "utf-8") : Buffer.from(String(g)), ot = (st = a.writeHead) == null ? void 0 : st.bind(a);
|
|
452
|
+
ot && (a.writeHead = (g, ...E) => {
|
|
453
|
+
var G;
|
|
454
|
+
const v = E.find((M) => M && typeof M == "object"), R = v && ((G = Object.entries(v).find(([M]) => M.toLowerCase() === "content-type")) == null ? void 0 : G[1]);
|
|
455
|
+
if ((typeof R == "string" ? R.includes("text/html") : X()) && (F = !0, a.removeHeader("content-length"), v))
|
|
456
|
+
for (const M of Object.keys(v)) M.toLowerCase() === "content-length" && delete v[M];
|
|
457
|
+
return ot(g, ...E);
|
|
458
|
+
}), a.write = (g, E, ...v) => (F === null && (F = X()), F ? (g && A.push(nt(g, typeof E == "string" ? E : void 0)), !0) : wt(g, E, ...v)), a.end = (g, E, ...v) => {
|
|
459
|
+
if (F === null && (F = X()), !F) return et(g, E, ...v);
|
|
460
|
+
g && A.push(nt(g, typeof E == "string" ? E : void 0));
|
|
461
|
+
let R = Buffer.concat(A).toString("utf-8");
|
|
462
|
+
!R.includes(B) && !/<meta\s+name="okno"\s+content="off"/.test(R) && (R = R.includes("</body>") ? R.replace("</body>", `${B}</body>`) : R + B);
|
|
463
|
+
const G = Buffer.from(R, "utf-8");
|
|
464
|
+
if (!a.headersSent)
|
|
465
|
+
try {
|
|
466
|
+
bt("content-length", String(G.length));
|
|
467
|
+
} catch {
|
|
468
|
+
}
|
|
469
|
+
return et(G, ...v);
|
|
470
|
+
}, w();
|
|
471
|
+
});
|
|
472
|
+
},
|
|
473
|
+
// Vite 6+ calls this hook for create, update AND delete. The legacy
|
|
474
|
+
// handleHotUpdate hook was update-only there, which is why editor-created
|
|
475
|
+
// and editor-deleted content files still caused a localhost reload.
|
|
476
|
+
// `post`: later hooks can re-add modules (vite:import-glob returns the
|
|
477
|
+
// `import.meta.glob("/okno/files/**")` importers on every create), so the
|
|
478
|
+
// editor-write suppression must be the final filter or uploads reload.
|
|
479
|
+
hotUpdate: {
|
|
480
|
+
order: "post",
|
|
481
|
+
async handler(n) {
|
|
482
|
+
return H(n, this.environment.name === "client");
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
// Vite 5 compatibility. Its legacy hook remains the only HMR hook.
|
|
486
|
+
async handleHotUpdate(n) {
|
|
487
|
+
return H(n);
|
|
488
|
+
},
|
|
489
|
+
// PRODUCTION boot for index.html frameworks (plain Vite, Solid, …). In dev
|
|
490
|
+
// the `configureServer` middleware injects the editor; that middleware never
|
|
491
|
+
// runs in a build, so a deployed page would ship no editor. `transformIndexHtml`
|
|
492
|
+
// fires only for frameworks whose HTML goes through Vite's index.html pipeline
|
|
493
|
+
// — Astro/SvelteKit/Nuxt own their HTML and bypass this hook, so they wire boot
|
|
494
|
+
// their own way (an Astro integration, a +layout import, a Nuxt client plugin).
|
|
495
|
+
// The inline `import "okno/boot"` is a real module script, so Vite bundles it +
|
|
496
|
+
// code-splits the editor behind boot's press-`e`/`?okno` gate.
|
|
497
|
+
transformIndexHtml: {
|
|
498
|
+
// `pre`, so the inline module script is present BEFORE Vite's core HTML
|
|
499
|
+
// plugin collects + bundles page scripts — otherwise the bare
|
|
500
|
+
// `import "okno/boot"` survives unbundled and 404s in the browser.
|
|
501
|
+
order: "pre",
|
|
502
|
+
handler(n) {
|
|
503
|
+
if (l)
|
|
504
|
+
return {
|
|
505
|
+
html: n,
|
|
506
|
+
tags: [
|
|
507
|
+
{
|
|
508
|
+
tag: "script",
|
|
509
|
+
attrs: { type: "module" },
|
|
510
|
+
children: 'import "okno/boot"',
|
|
511
|
+
injectTo: "body"
|
|
512
|
+
}
|
|
513
|
+
]
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
async resolveId(n, u) {
|
|
518
|
+
if (n.startsWith("okno/")) {
|
|
519
|
+
const p = n.slice(5);
|
|
520
|
+
if (qt.has(p)) return z + p;
|
|
521
|
+
}
|
|
522
|
+
if (y && n === "okno/editor")
|
|
523
|
+
return tt;
|
|
524
|
+
if (y && u && Zt(u, C)) {
|
|
525
|
+
const p = xt(n, oe);
|
|
526
|
+
if (p) {
|
|
527
|
+
const f = await this.resolve(p, u, { skipSelf: !0 });
|
|
528
|
+
return f == null ? void 0 : f.id;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
async load(n) {
|
|
533
|
+
if (!n.startsWith(z)) return;
|
|
534
|
+
const u = n.slice(z.length);
|
|
535
|
+
if (u === "runtime") {
|
|
536
|
+
if (!ht)
|
|
537
|
+
throw new Error("okno: runtime/wrap.js missing — run `bun run build:pkg`");
|
|
538
|
+
return ht;
|
|
539
|
+
}
|
|
540
|
+
if (u === "bootstrap")
|
|
541
|
+
return 'import("okno/editor")';
|
|
542
|
+
if (u === "pages") {
|
|
543
|
+
const p = await P(m, "pages");
|
|
544
|
+
return jt(i, p, s, `__oknoSetAssets(${JSON.stringify(Q(i, _))})`);
|
|
545
|
+
}
|
|
546
|
+
if (u === "collections") {
|
|
547
|
+
const p = await P(m, "collections");
|
|
548
|
+
return Et(i, p, l, s, `__oknoSetAssets(${JSON.stringify(Q(i, _))})`);
|
|
549
|
+
}
|
|
550
|
+
if (u === "globals") {
|
|
551
|
+
const p = await P(m, "globals");
|
|
552
|
+
return Ct(i, p, s, `__oknoSetAssets(${JSON.stringify(Q(i, _))})`);
|
|
553
|
+
}
|
|
554
|
+
if (u === "locales")
|
|
555
|
+
return Tt(i);
|
|
556
|
+
if (u === "strings")
|
|
557
|
+
return Ht(i);
|
|
558
|
+
if (u === "content")
|
|
559
|
+
return vt();
|
|
560
|
+
}
|
|
561
|
+
}, {
|
|
562
|
+
name: "okno:writes",
|
|
563
|
+
enforce: "pre",
|
|
564
|
+
hotUpdate: {
|
|
565
|
+
order: "pre",
|
|
566
|
+
handler(n) {
|
|
567
|
+
if (i && ft(i, n.file)) return [];
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
handleHotUpdate: {
|
|
571
|
+
order: "pre",
|
|
572
|
+
handler(n) {
|
|
573
|
+
if (i && ft(i, n.file)) return [];
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}];
|
|
577
|
+
}
|
|
578
|
+
export {
|
|
579
|
+
ye as o
|
|
580
|
+
};
|
package/dist/vite/index.js
CHANGED
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.
|
|
5
|
+
"version": "1.0.0-beta.58",
|
|
6
6
|
"homepage": "https://okno.build",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
package/dist/plugin-BiIIWwGR.js
DELETED
|
@@ -1,573 +0,0 @@
|
|
|
1
|
-
import { F as et, b as mt, C as L } from "./format-BLz4SuAo.js";
|
|
2
|
-
import { d as ht, r as gt, c as yt, g as wt, s as P, b as St, f as V, a as _t, e as kt, h as bt, i as Ot, j as Nt, k as nt, l as z, m as Et, n as jt, o as Tt, p as Ct } from "./dispatch-DQ_4U5Df.js";
|
|
3
|
-
import { join as b, dirname as F, relative as I, sep as ft, resolve as S } from "node:path";
|
|
4
|
-
import { existsSync as C, statSync as Ht, readFileSync as J, mkdirSync as ot, watch as vt, readdirSync as Rt } from "node:fs";
|
|
5
|
-
import { fileURLToPath as It } from "node:url";
|
|
6
|
-
import { w as Mt, a as Pt, s as st, c as U } from "./store-CJ2sqOKN.js";
|
|
7
|
-
import { simpleGit as X } from "simple-git";
|
|
8
|
-
import "node:crypto";
|
|
9
|
-
import "node:child_process";
|
|
10
|
-
import "./encode-EHnvycZZ.js";
|
|
11
|
-
import "./operations-BTS0mCeT.js";
|
|
12
|
-
import { e as Ft } from "./usage-CmeL5A64.js";
|
|
13
|
-
import "node:os";
|
|
14
|
-
function rt(t, r, o) {
|
|
15
|
-
t.statusCode = r, t.setHeader("Content-Type", "application/json"), t.setHeader("Cache-Control", "no-store"), t.end(JSON.stringify(o));
|
|
16
|
-
}
|
|
17
|
-
function Wt(t) {
|
|
18
|
-
return new Promise((r) => {
|
|
19
|
-
let o = "";
|
|
20
|
-
t.on("data", (s) => o += s), t.on("end", () => {
|
|
21
|
-
try {
|
|
22
|
-
r(o ? JSON.parse(o) : {});
|
|
23
|
-
} catch {
|
|
24
|
-
r({});
|
|
25
|
-
}
|
|
26
|
-
}), t.on("error", () => r({}));
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
function Jt(t) {
|
|
30
|
-
return new Promise((r, o) => {
|
|
31
|
-
const s = [];
|
|
32
|
-
t.on("data", (n) => s.push(n)), t.on("end", () => r(Buffer.concat(s))), t.on("error", o);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function $t(t, r) {
|
|
36
|
-
var o;
|
|
37
|
-
if (r) {
|
|
38
|
-
for (const s of new Set(r.modules)) {
|
|
39
|
-
const n = t.moduleGraph.getModuleById("\0okno:" + s);
|
|
40
|
-
n && t.moduleGraph.invalidateModule(n);
|
|
41
|
-
}
|
|
42
|
-
for (const s of new Set(r.files))
|
|
43
|
-
(o = t.moduleGraph.getModulesByFile(s)) == null || o.forEach((n) => t.moduleGraph.invalidateModule(n));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function Bt(t, r) {
|
|
47
|
-
t.middlewares.use(async (o, s, n) => {
|
|
48
|
-
var g;
|
|
49
|
-
if (!((g = o.url) != null && g.startsWith("/__okno/api/"))) return n();
|
|
50
|
-
const m = o.url.slice(12).split("?")[0], i = {
|
|
51
|
-
method: o.method || "GET",
|
|
52
|
-
route: m,
|
|
53
|
-
json: () => Wt(o),
|
|
54
|
-
binary: () => Jt(o),
|
|
55
|
-
header: (c) => {
|
|
56
|
-
const d = o.headers[c];
|
|
57
|
-
return Array.isArray(d) ? d[0] : d;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
try {
|
|
61
|
-
const c = await ht(r, i);
|
|
62
|
-
if (!c) return n();
|
|
63
|
-
$t(t, c.invalidation), rt(s, c.status, c.body);
|
|
64
|
-
} catch (c) {
|
|
65
|
-
rt(s, 500, { error: c instanceof Error ? c.message : String(c) });
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
function At(t, r) {
|
|
70
|
-
let o;
|
|
71
|
-
try {
|
|
72
|
-
o = decodeURIComponent(r);
|
|
73
|
-
} catch {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
if (!o || o.includes("\0")) return null;
|
|
77
|
-
const s = S(t, "files"), n = S(s, o);
|
|
78
|
-
return n === s || !n.startsWith(s + ft) ? null : n;
|
|
79
|
-
}
|
|
80
|
-
const Q = "okno";
|
|
81
|
-
function Gt(t, r, o = "/") {
|
|
82
|
-
Bt(t, r), t.middlewares.use((s, n, m) => {
|
|
83
|
-
var E;
|
|
84
|
-
const i = o.replace(/\/$/, ""), g = i && ((E = s.url) != null && E.startsWith(i + "/okno/files/")) ? s.url.slice(i.length) : s.url;
|
|
85
|
-
if (s.method !== "GET" || !(g != null && g.startsWith("/okno/files/"))) return m();
|
|
86
|
-
const c = g.slice(12).split("?")[0];
|
|
87
|
-
if (!c) return m();
|
|
88
|
-
const d = At(r, c);
|
|
89
|
-
if (!d)
|
|
90
|
-
return n.statusCode = 403, n.end("Forbidden");
|
|
91
|
-
if (!C(d)) {
|
|
92
|
-
const H = gt(r)["/okno/files/" + c];
|
|
93
|
-
return H ? (n.statusCode = 302, n.setHeader("Location", H), n.setHeader("Cache-Control", "no-cache"), n.end()) : (n.statusCode = 404, n.end("Not found"));
|
|
94
|
-
}
|
|
95
|
-
const u = Ht(d), _ = `W/"${u.size}-${Math.floor(u.mtimeMs)}"`;
|
|
96
|
-
if (n.setHeader("Content-Type", Ft(d) || "application/octet-stream"), n.setHeader("Cache-Control", "no-cache"), n.setHeader("ETag", _), s.headers["if-none-match"] === _)
|
|
97
|
-
return n.statusCode = 304, n.end();
|
|
98
|
-
n.end(J(d));
|
|
99
|
-
}), t.middlewares.use(async (s, n, m) => {
|
|
100
|
-
var g, c;
|
|
101
|
-
if (!((g = s.url) != null && g.startsWith("/__okno/"))) return m();
|
|
102
|
-
const i = s.url.slice(8);
|
|
103
|
-
if (yt({ method: s.method || "GET", header: (d) => {
|
|
104
|
-
const u = s.headers[d];
|
|
105
|
-
return Array.isArray(u) ? u[0] : u;
|
|
106
|
-
} }))
|
|
107
|
-
return n.statusCode = 403, n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ error: "Cross-site requests can't change local content" }));
|
|
108
|
-
n.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, proxy-revalidate"), n.setHeader("Pragma", "no-cache"), n.setHeader("Expires", "0");
|
|
109
|
-
try {
|
|
110
|
-
if (s.method === "GET" && i === "repo") {
|
|
111
|
-
n.setHeader("Content-Type", "application/json");
|
|
112
|
-
try {
|
|
113
|
-
const d = X(t.config.root), u = (c = await d.remote(["get-url", "origin"])) == null ? void 0 : c.toString().trim(), _ = (await d.revparse(["--abbrev-ref", "HEAD"])).trim(), { owner: E, repo: H } = Lt(u);
|
|
114
|
-
return n.end(
|
|
115
|
-
JSON.stringify({ ok: !0, owner: E, repo: H, branch: _ || null, remote: u || null })
|
|
116
|
-
);
|
|
117
|
-
} catch (d) {
|
|
118
|
-
return n.end(JSON.stringify({ ok: !1, error: String(d) }));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (s.method === "POST" && i.startsWith("mirror")) {
|
|
122
|
-
const u = new URL(s.url, "http://localhost").searchParams.get("path");
|
|
123
|
-
if (!u || u.includes("..") || !u.startsWith("files/"))
|
|
124
|
-
return n.statusCode = 400, n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ error: "Invalid path" }));
|
|
125
|
-
const _ = b(r, u);
|
|
126
|
-
if (C(_))
|
|
127
|
-
return n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ ok: !0, skipped: !0 }));
|
|
128
|
-
const E = await Ut(s);
|
|
129
|
-
return ot(F(_), { recursive: !0 }), Mt(_, E), n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ ok: !0, written: u, bytes: E.length }));
|
|
130
|
-
}
|
|
131
|
-
if (s.method === "POST" && i === "sync") {
|
|
132
|
-
const d = await Kt(s), u = d == null ? void 0 : d.path;
|
|
133
|
-
if (u) {
|
|
134
|
-
if (u.includes("..") || u.includes("\0"))
|
|
135
|
-
return n.statusCode = 400, n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ error: "Invalid path" }));
|
|
136
|
-
const j = b(r, u);
|
|
137
|
-
try {
|
|
138
|
-
const e = X(r);
|
|
139
|
-
await e.fetch("origin", Q);
|
|
140
|
-
const l = (await e.revparse(["--show-toplevel"])).trim(), p = I(l, j).split(ft).join("/"), f = await e.show([`origin/${Q}:${p}`]);
|
|
141
|
-
ot(F(j), { recursive: !0 }), Pt(j, f);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
const l = e instanceof Error ? e.message : String(e);
|
|
144
|
-
console.warn(
|
|
145
|
-
`[okno] sync: could not materialize ${u} from origin/${Q} — ${l.split(`
|
|
146
|
-
`)[0]}`
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
return it(t, u, j), n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ ok: !0, invalidated: u }));
|
|
150
|
-
}
|
|
151
|
-
const _ = X(r), E = await _.revparse(["--show-toplevel"]), H = I(E.trim(), r);
|
|
152
|
-
try {
|
|
153
|
-
const j = await _.pull();
|
|
154
|
-
for (const e of j.files)
|
|
155
|
-
if (e.startsWith(`${H}/`)) {
|
|
156
|
-
const l = e.slice(`${H}/`.length), p = b(r, l);
|
|
157
|
-
it(t, l, p);
|
|
158
|
-
}
|
|
159
|
-
return n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ ok: !0, files: j.files }));
|
|
160
|
-
} catch (j) {
|
|
161
|
-
const e = j instanceof Error ? j.message : String(j);
|
|
162
|
-
return console.warn(`[okno] sync: git pull skipped — ${e.split(`
|
|
163
|
-
`)[0]}`), n.setHeader("Content-Type", "application/json"), n.end(JSON.stringify({ ok: !0, pullSkipped: !0, reason: e }));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
m();
|
|
167
|
-
} catch (d) {
|
|
168
|
-
n.statusCode = 500, n.end(JSON.stringify({ error: String(d) }));
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
function Lt(t) {
|
|
173
|
-
if (!t) return { owner: null, repo: null };
|
|
174
|
-
const r = t.match(/github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?\/?$/);
|
|
175
|
-
return r ? { owner: r[1], repo: r[2] } : { owner: null, repo: null };
|
|
176
|
-
}
|
|
177
|
-
function Ut(t) {
|
|
178
|
-
return new Promise((r, o) => {
|
|
179
|
-
const s = [];
|
|
180
|
-
t.on("data", (n) => s.push(n)), t.on("end", () => r(Buffer.concat(s))), t.on("error", o);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
function Kt(t) {
|
|
184
|
-
return new Promise((r) => {
|
|
185
|
-
let o = "";
|
|
186
|
-
t.on("data", (s) => {
|
|
187
|
-
o += s;
|
|
188
|
-
}), t.on("end", () => {
|
|
189
|
-
try {
|
|
190
|
-
r(o ? JSON.parse(o) : null);
|
|
191
|
-
} catch {
|
|
192
|
-
r(null);
|
|
193
|
-
}
|
|
194
|
-
}), t.on("error", () => r(null));
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
function it(t, r, o) {
|
|
198
|
-
const s = "\0okno:";
|
|
199
|
-
let n;
|
|
200
|
-
if (r.startsWith("pages/") ? n = s + "pages" : r.startsWith("collections/") ? n = s + "collections" : r.startsWith("globals/") && (n = s + "globals"), n) {
|
|
201
|
-
const m = t.moduleGraph.getModuleById(n);
|
|
202
|
-
m && t.moduleGraph.invalidateModule(m);
|
|
203
|
-
const i = t.moduleGraph.getModulesByFile(o);
|
|
204
|
-
i && i.forEach((g) => {
|
|
205
|
-
t.moduleGraph.invalidateModule(g);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
function Dt(t, r) {
|
|
210
|
-
const o = (t.split("?")[0] ?? "").replace(/\\/g, "/"), s = r.replace(/\\/g, "/");
|
|
211
|
-
return o === s || o.startsWith(s + "/");
|
|
212
|
-
}
|
|
213
|
-
function Vt(t, r) {
|
|
214
|
-
for (const [o, s] of Object.entries(r)) {
|
|
215
|
-
if (t === o) return s;
|
|
216
|
-
if (t.startsWith(o + "/")) return s + t.slice(o.length);
|
|
217
|
-
}
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
const K = "\0okno:", zt = /* @__PURE__ */ new Set([
|
|
221
|
-
"runtime",
|
|
222
|
-
"bootstrap",
|
|
223
|
-
"pages",
|
|
224
|
-
"collections",
|
|
225
|
-
"globals",
|
|
226
|
-
"locales",
|
|
227
|
-
"strings",
|
|
228
|
-
"content"
|
|
229
|
-
]);
|
|
230
|
-
function at(t, r) {
|
|
231
|
-
const o = I(t, r).split("\\").join("/");
|
|
232
|
-
if (o === "files/.okno-tree.json") return ["pages", "collections", "globals", "content"];
|
|
233
|
-
if (!o || o.startsWith("../") || !o.endsWith(".ts")) return null;
|
|
234
|
-
if (o === "strings.ts" || /^strings\/[^/]+\.ts$/.test(o)) return ["strings", "content"];
|
|
235
|
-
const s = o.split("/")[0];
|
|
236
|
-
return s === "pages" || s === "collections" || s === "globals" ? [s] : null;
|
|
237
|
-
}
|
|
238
|
-
function lt(t, r) {
|
|
239
|
-
const o = I(t, r);
|
|
240
|
-
return !!o && !o.startsWith("..") && U(r);
|
|
241
|
-
}
|
|
242
|
-
function W(t, r, o = []) {
|
|
243
|
-
var i, g;
|
|
244
|
-
const s = new Set(Object.values(t.environments ?? {}).map((c) => c.moduleGraph));
|
|
245
|
-
s.size || s.add(t.moduleGraph);
|
|
246
|
-
const n = new Set(r), m = new Set(o);
|
|
247
|
-
for (const c of s) {
|
|
248
|
-
for (const d of n) {
|
|
249
|
-
const u = c.getModuleById(K + d);
|
|
250
|
-
u && c.invalidateModule(u);
|
|
251
|
-
}
|
|
252
|
-
for (const d of m) (i = c.getModulesByFile(d)) == null || i.forEach((u) => c.invalidateModule(u));
|
|
253
|
-
}
|
|
254
|
-
for (const c of Object.values(t.environments ?? {}))
|
|
255
|
-
((g = c.config) == null ? void 0 : g.consumer) === "server" && "runner" in c && c.runner.clearCache();
|
|
256
|
-
}
|
|
257
|
-
const Y = F(It(import.meta.url)), $ = [S(Y, "../package.json"), S(Y, "../../package.json"), S(Y, "../../../package.json")].find(C);
|
|
258
|
-
if (!$) throw new Error("okno: package.json not found");
|
|
259
|
-
function Xt(t) {
|
|
260
|
-
const r = b(t, et);
|
|
261
|
-
try {
|
|
262
|
-
const o = mt(C(r) ? { [et]: J(r, "utf-8") } : {});
|
|
263
|
-
o < L ? console.warn(`[okno] okno/ uses format ${o}, this package uses ${L}. Run: npx okno upgrade`) : o > L && console.warn(`[okno] okno/ uses format ${o}, newer than this package understands (${L}). Update okno.`);
|
|
264
|
-
} catch (o) {
|
|
265
|
-
console.warn(`[okno] ${o instanceof Error ? o.message : o}`);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
const Qt = JSON.parse(J($, "utf-8")).version, ct = !F($).split(/[\\/]/).includes("node_modules"), ut = [["dist/editor", "index.js"], ["dist", "boot.js"]].map(([t, r]) => [b(F($), t), r]), dt = wt(), N = S(F($), "../editor"), Z = S(N, "index.ts"), Yt = C(Z), Zt = {
|
|
269
|
-
"@app": S(N, "app"),
|
|
270
|
-
"@state": S(N, "state"),
|
|
271
|
-
"@bindings": S(N, "bindings"),
|
|
272
|
-
"@lib": S(N, "lib"),
|
|
273
|
-
"@logger": S(N, "lib/logger.svelte.ts"),
|
|
274
|
-
"@utils": S(N, "lib/utils.ts"),
|
|
275
|
-
"@/types": S(N, "lib/types.ts"),
|
|
276
|
-
"@styles": S(N, "styles"),
|
|
277
|
-
"@components": S(N, "components"),
|
|
278
|
-
"@assets": S(N, "assets"),
|
|
279
|
-
"@pages": S(N, "pages"),
|
|
280
|
-
"@controllers": S(N, "controllers")
|
|
281
|
-
};
|
|
282
|
-
function de(t = {}, r = {}) {
|
|
283
|
-
const o = t.dir ?? "okno", s = r.imageMode ?? "raw", n = s === "astro" ? "astro" : void 0;
|
|
284
|
-
let m, i, g = !1, c = !1, d = !1, u = !1, _ = "/";
|
|
285
|
-
t.isEditor;
|
|
286
|
-
const E = async (e, l = !0) => {
|
|
287
|
-
const p = b(i, "schema.ts"), f = b(i, "users.json"), a = b(i, "permissions.ts"), y = b(i, "modules.d.ts"), h = b(i, "files", ".okno-tree.json");
|
|
288
|
-
if (e.file === p)
|
|
289
|
-
return l && await z(i, m, u ? "development" : "strict", n), W(e.server, ["pages", "collections", "globals", "locales", "content", "strings"], [e.file]), [];
|
|
290
|
-
if (e.file === f || e.file === a || e.file === y) return [];
|
|
291
|
-
const k = at(i, e.file);
|
|
292
|
-
return k ? (k[0] === "strings" && l && await z(i, m, u ? "development" : "strict", n), U(e.file) ? (W(e.server, k, [e.file]), []) : e.file !== h ? void 0 : (l && (W(e.server, k, [e.file]), e.server.ws.send({ type: "full-reload" })), [])) : I(i, e.file).split("\\").join("/").startsWith("files/") && U(e.file) ? (W(e.server, ["pages", "collections", "globals", "content"], [e.file]), []) : void 0;
|
|
293
|
-
};
|
|
294
|
-
return [{
|
|
295
|
-
name: "okno",
|
|
296
|
-
enforce: "pre",
|
|
297
|
-
config(e, l) {
|
|
298
|
-
const p = l.command === "serve";
|
|
299
|
-
return c = l.command === "build", g = p && Yt && t.builtEditor === !1, {
|
|
300
|
-
define: {
|
|
301
|
-
__OKNO_API_URL__: JSON.stringify(t.apiUrl ?? "https://api.okno.build"),
|
|
302
|
-
__OKNO_VERSION__: JSON.stringify(Qt),
|
|
303
|
-
// True when the consumer is running `vite dev` / `astro dev` /
|
|
304
|
-
// `sveltekit dev` — anything that serves locally. Replaced at
|
|
305
|
-
// consumer build time so the prebuilt editor bundle can honor
|
|
306
|
-
// the consumer's actual environment.
|
|
307
|
-
__OKNO_IS_DEV__: JSON.stringify(p),
|
|
308
|
-
// Public demo build: editor boots login-less, reads a static
|
|
309
|
-
// `okno-demo.json` snapshot, no-ops writes. See docs/demo-mode.md.
|
|
310
|
-
__OKNO_DEMO__: JSON.stringify(t.demo ?? !1),
|
|
311
|
-
__OKNO_INTERNAL_TESTING__: JSON.stringify(t.internalTesting === !0),
|
|
312
|
-
// Repo identity (`owner/repo@branch`) baked from the app's git
|
|
313
|
-
// origin (or the host's variables, see identity.ts) at build time,
|
|
314
|
-
// so the deployed editor auto-targets its repo. Dev may be null and
|
|
315
|
-
// ignores it (runtime /__okno/repo derivation is more current).
|
|
316
|
-
// A production build that can't name its repo stops here: its
|
|
317
|
-
// editor would ship but never sign anyone in on the live site.
|
|
318
|
-
__OKNO_REPO__: JSON.stringify(c && !t.demo ? jt(o) : Tt(o)),
|
|
319
|
-
// Monorepo root path: the build dir relative to the git root (e.g.
|
|
320
|
-
// "apps/site", or "" at the repo root). Sent as X-Okno-Path so the
|
|
321
|
-
// hosted backend reads/writes content under `<root>/okno` instead of
|
|
322
|
-
// the repo-root `okno` — one repo, many okno projects keyed (repo, path).
|
|
323
|
-
__OKNO_ROOT__: JSON.stringify(Et())
|
|
324
|
-
},
|
|
325
|
-
// Source mode (monorepo dev only): skip prebundling so saves to
|
|
326
|
-
// `editor/**` propagate via HMR instead of needing
|
|
327
|
-
// `bun run build:pkg`. The editor's internal @-aliases are NOT exposed
|
|
328
|
-
// as a global `resolve.alias` here — that shadowed a consumer's own
|
|
329
|
-
// identically-named tsconfig aliases (`@components`, `@lib`, …). They
|
|
330
|
-
// are instead resolved per-importer in `resolveId`, scoped to imports
|
|
331
|
-
// originating inside the editor source tree. See editor-aliases.ts.
|
|
332
|
-
...g && {
|
|
333
|
-
optimizeDeps: { exclude: ["okno", "okno/editor"] }
|
|
334
|
-
},
|
|
335
|
-
...!g && p && ct && { optimizeDeps: { force: !0 } },
|
|
336
|
-
server: {
|
|
337
|
-
watch: {
|
|
338
|
-
// External content/assets must remain observable. Only private
|
|
339
|
-
// editor metadata and atomic-write staging files are ignored.
|
|
340
|
-
ignored: (f) => {
|
|
341
|
-
const a = I(i, f).split("\\").join("/");
|
|
342
|
-
return a === ".okno-tree.json" || a.startsWith("files/") && /\/\.[^/]+\.okno-[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(a);
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
// Source mode: the editor loads via a dynamic `import("okno/editor")`
|
|
346
|
-
// from a separate package over `@fs`, so Vite's startup dep scan
|
|
347
|
-
// never crawls it — its transitive deps (bits-ui, tiptap, runed…)
|
|
348
|
-
// are discovered lazily on first import, triggering a mid-session
|
|
349
|
-
// re-optimize that 404s the now-stale prebundled chunks. Warming the
|
|
350
|
-
// editor entry forces that crawl at startup, so those deps land in
|
|
351
|
-
// the first optimize pass and never re-bundle under the user.
|
|
352
|
-
...g && {
|
|
353
|
-
warmup: { clientFiles: [Z] }
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
},
|
|
358
|
-
configResolved(e) {
|
|
359
|
-
var l;
|
|
360
|
-
u = e.command === "serve", _ = e.base ?? "/", m = e.root, i = S(m, o), d = !!((l = e.build) != null && l.ssr);
|
|
361
|
-
},
|
|
362
|
-
async buildStart() {
|
|
363
|
-
var a;
|
|
364
|
-
if (!C(i)) return;
|
|
365
|
-
Xt(i), await z(i, m, u ? "development" : "strict", n), this.addWatchFile(b(i, "files", ".okno-tree.json"));
|
|
366
|
-
const e = (a = this.environment) == null ? void 0 : a.config.consumer;
|
|
367
|
-
if (!c || (e ? e !== "client" : d)) return;
|
|
368
|
-
this.addWatchFile(b(i, ".revision"));
|
|
369
|
-
const l = nt(i);
|
|
370
|
-
l !== null && this.emitFile({ type: "asset", fileName: "okno/build.json", source: l });
|
|
371
|
-
const p = b(i, "files"), f = (y) => {
|
|
372
|
-
this.addWatchFile(y);
|
|
373
|
-
for (const h of Rt(y, { withFileTypes: !0 })) {
|
|
374
|
-
if (h.name === ".okno-tree.json" || y === p && h.name === ".trash") continue;
|
|
375
|
-
const k = b(y, h.name);
|
|
376
|
-
h.isDirectory() ? f(k) : h.isFile() && (this.addWatchFile(k), this.emitFile({
|
|
377
|
-
type: "asset",
|
|
378
|
-
fileName: `okno/files/${I(p, k).split("\\").join("/")}`,
|
|
379
|
-
source: J(k)
|
|
380
|
-
}));
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
C(p) && f(p), Ct(i, _), t.demo && this.emitFile({ type: "asset", fileName: "okno-demo.json", source: JSON.stringify(st(i)) });
|
|
384
|
-
},
|
|
385
|
-
configureServer(e) {
|
|
386
|
-
if (Gt(e, i, _), !g && ct && e.httpServer) {
|
|
387
|
-
let f = null;
|
|
388
|
-
const a = (O) => {
|
|
389
|
-
try {
|
|
390
|
-
return J(O, "utf8");
|
|
391
|
-
} catch {
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
}, y = new Map(ut.map(([O, v]) => [b(O, v), a(b(O, v))])), h = ut.filter(([O]) => C(O)).map(([O, v]) => vt(O, (B, R) => {
|
|
395
|
-
R === v && (f && clearTimeout(f), f = setTimeout(() => {
|
|
396
|
-
f = null, [...y].some(([D, A]) => a(D) !== A) && e.config.logger.info("[okno] linked build changed; restart the dev server to load it");
|
|
397
|
-
}, 800));
|
|
398
|
-
})), k = () => {
|
|
399
|
-
f && clearTimeout(f);
|
|
400
|
-
for (const O of h) O.close();
|
|
401
|
-
};
|
|
402
|
-
e.httpServer.once("close", k);
|
|
403
|
-
}
|
|
404
|
-
e.middlewares.use((f, a, y) => {
|
|
405
|
-
var k;
|
|
406
|
-
if (f.method !== "GET") return y();
|
|
407
|
-
const h = (k = f.url) == null ? void 0 : k.split("?")[0];
|
|
408
|
-
if (h !== "/okno/build.json" && !(t.demo && h === "/okno-demo.json") || !C(i)) return y();
|
|
409
|
-
a.setHeader("Content-Type", "application/json"), a.setHeader("Cache-Control", "no-store"), a.end(h === "/okno/build.json" ? nt(i) : JSON.stringify(st(i)));
|
|
410
|
-
});
|
|
411
|
-
const l = (f) => {
|
|
412
|
-
const a = I(i, f).split("\\").join("/"), y = at(i, f) ?? (a.startsWith("files/") && !a.startsWith("files/.trash/") ? ["pages", "collections", "globals", "content"] : null);
|
|
413
|
-
y && (W(e, y, [f]), !U(f) && e.ws.send({ type: "full-reload" }));
|
|
414
|
-
};
|
|
415
|
-
e.watcher.on("add", l), e.watcher.on("unlink", l), e.middlewares.use("/__okno/imports", async (f, a, y) => {
|
|
416
|
-
if (f.method !== "GET") return y();
|
|
417
|
-
try {
|
|
418
|
-
const [h, k, O] = await Promise.all([
|
|
419
|
-
P(m, "pages"),
|
|
420
|
-
P(m, "globals"),
|
|
421
|
-
P(m, "collections")
|
|
422
|
-
]);
|
|
423
|
-
a.setHeader("Content-Type", "application/json"), a.setHeader("Cache-Control", "no-store"), a.end(JSON.stringify({
|
|
424
|
-
pages: Array.from(h),
|
|
425
|
-
globals: Array.from(k),
|
|
426
|
-
collections: Array.from(O)
|
|
427
|
-
}));
|
|
428
|
-
} catch (h) {
|
|
429
|
-
y(h);
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
const p = "/__okno_bootstrap.js";
|
|
433
|
-
e.middlewares.use(p, async (f, a, y) => {
|
|
434
|
-
try {
|
|
435
|
-
const h = await e.transformRequest("\0okno:bootstrap");
|
|
436
|
-
if (!h) {
|
|
437
|
-
a.statusCode = 500, a.end("okno bootstrap transform failed");
|
|
438
|
-
return;
|
|
439
|
-
}
|
|
440
|
-
a.setHeader("content-type", "text/javascript"), a.end(h.code);
|
|
441
|
-
} catch (h) {
|
|
442
|
-
y(h);
|
|
443
|
-
}
|
|
444
|
-
}), e.middlewares.use((f, a, y) => {
|
|
445
|
-
const h = "<script>window.__oknoDev=true<\/script>", k = t.demo ? "<script>window.__oknoDemo=true<\/script>" : "", O = t.internalTesting === !0 ? "<script>window.__oknoInternalTesting=true<\/script>" : "", v = `${h}${k}${O}<script type="module" src="${p}"><\/script>`, B = [];
|
|
446
|
-
let R = null;
|
|
447
|
-
const D = a.write.bind(a), A = a.end.bind(a), pt = a.setHeader.bind(a), x = () => {
|
|
448
|
-
const w = a.getHeader("content-type");
|
|
449
|
-
return typeof w == "string" && w.includes("text/html");
|
|
450
|
-
}, q = (w, T) => Buffer.isBuffer(w) ? w : w instanceof Uint8Array ? Buffer.from(w.buffer, w.byteOffset, w.byteLength) : typeof w == "string" ? Buffer.from(w, T || "utf-8") : Buffer.from(String(w));
|
|
451
|
-
a.write = (w, T, ...G) => (R === null && (R = x()), R ? (w && B.push(q(w, typeof T == "string" ? T : void 0)), !0) : D(w, T, ...G)), a.end = (w, T, ...G) => {
|
|
452
|
-
if (R === null && (R = x()), !R) return A(w, T, ...G);
|
|
453
|
-
w && B.push(q(w, typeof T == "string" ? T : void 0));
|
|
454
|
-
let M = Buffer.concat(B).toString("utf-8");
|
|
455
|
-
!M.includes(v) && !/<meta\s+name="okno"\s+content="off"/.test(M) && (M = M.includes("</body>") ? M.replace("</body>", `${v}</body>`) : M + v);
|
|
456
|
-
const tt = Buffer.from(M, "utf-8");
|
|
457
|
-
if (!a.headersSent)
|
|
458
|
-
try {
|
|
459
|
-
pt("content-length", String(tt.length));
|
|
460
|
-
} catch {
|
|
461
|
-
}
|
|
462
|
-
return A(tt, ...G);
|
|
463
|
-
}, y();
|
|
464
|
-
});
|
|
465
|
-
},
|
|
466
|
-
// Vite 6+ calls this hook for create, update AND delete. The legacy
|
|
467
|
-
// handleHotUpdate hook was update-only there, which is why editor-created
|
|
468
|
-
// and editor-deleted content files still caused a localhost reload.
|
|
469
|
-
// `post`: later hooks can re-add modules (vite:import-glob returns the
|
|
470
|
-
// `import.meta.glob("/okno/files/**")` importers on every create), so the
|
|
471
|
-
// editor-write suppression must be the final filter or uploads reload.
|
|
472
|
-
hotUpdate: {
|
|
473
|
-
order: "post",
|
|
474
|
-
async handler(e) {
|
|
475
|
-
return E(e, this.environment.name === "client");
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
// Vite 5 compatibility. Its legacy hook remains the only HMR hook.
|
|
479
|
-
async handleHotUpdate(e) {
|
|
480
|
-
return E(e);
|
|
481
|
-
},
|
|
482
|
-
// PRODUCTION boot for index.html frameworks (plain Vite, Solid, …). In dev
|
|
483
|
-
// the `configureServer` middleware injects the editor; that middleware never
|
|
484
|
-
// runs in a build, so a deployed page would ship no editor. `transformIndexHtml`
|
|
485
|
-
// fires only for frameworks whose HTML goes through Vite's index.html pipeline
|
|
486
|
-
// — Astro/SvelteKit/Nuxt own their HTML and bypass this hook, so they wire boot
|
|
487
|
-
// their own way (an Astro integration, a +layout import, a Nuxt client plugin).
|
|
488
|
-
// The inline `import "okno/boot"` is a real module script, so Vite bundles it +
|
|
489
|
-
// code-splits the editor behind boot's press-`e`/`?okno` gate.
|
|
490
|
-
transformIndexHtml: {
|
|
491
|
-
// `pre`, so the inline module script is present BEFORE Vite's core HTML
|
|
492
|
-
// plugin collects + bundles page scripts — otherwise the bare
|
|
493
|
-
// `import "okno/boot"` survives unbundled and 404s in the browser.
|
|
494
|
-
order: "pre",
|
|
495
|
-
handler(e) {
|
|
496
|
-
if (c)
|
|
497
|
-
return {
|
|
498
|
-
html: e,
|
|
499
|
-
tags: [
|
|
500
|
-
{
|
|
501
|
-
tag: "script",
|
|
502
|
-
attrs: { type: "module" },
|
|
503
|
-
children: 'import "okno/boot"',
|
|
504
|
-
injectTo: "body"
|
|
505
|
-
}
|
|
506
|
-
]
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
},
|
|
510
|
-
async resolveId(e, l) {
|
|
511
|
-
if (e.startsWith("okno/")) {
|
|
512
|
-
const p = e.slice(5);
|
|
513
|
-
if (zt.has(p)) return K + p;
|
|
514
|
-
}
|
|
515
|
-
if (g && e === "okno/editor")
|
|
516
|
-
return Z;
|
|
517
|
-
if (g && l && Dt(l, N)) {
|
|
518
|
-
const p = Vt(e, Zt);
|
|
519
|
-
if (p) {
|
|
520
|
-
const f = await this.resolve(p, l, { skipSelf: !0 });
|
|
521
|
-
return f == null ? void 0 : f.id;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
async load(e) {
|
|
526
|
-
if (!e.startsWith(K)) return;
|
|
527
|
-
const l = e.slice(K.length);
|
|
528
|
-
if (l === "runtime") {
|
|
529
|
-
if (!dt)
|
|
530
|
-
throw new Error("okno: runtime/wrap.js missing — run `bun run build:pkg`");
|
|
531
|
-
return dt;
|
|
532
|
-
}
|
|
533
|
-
if (l === "bootstrap")
|
|
534
|
-
return 'import("okno/editor")';
|
|
535
|
-
if (l === "pages") {
|
|
536
|
-
const p = await P(m, "pages");
|
|
537
|
-
return St(i, p, s, `__oknoSetAssets(${JSON.stringify(V(i, _))})`);
|
|
538
|
-
}
|
|
539
|
-
if (l === "collections") {
|
|
540
|
-
const p = await P(m, "collections");
|
|
541
|
-
return _t(i, p, c, s, `__oknoSetAssets(${JSON.stringify(V(i, _))})`);
|
|
542
|
-
}
|
|
543
|
-
if (l === "globals") {
|
|
544
|
-
const p = await P(m, "globals");
|
|
545
|
-
return kt(i, p, s, `__oknoSetAssets(${JSON.stringify(V(i, _))})`);
|
|
546
|
-
}
|
|
547
|
-
if (l === "locales")
|
|
548
|
-
return bt(i);
|
|
549
|
-
if (l === "strings")
|
|
550
|
-
return Ot(i);
|
|
551
|
-
if (l === "content")
|
|
552
|
-
return Nt();
|
|
553
|
-
}
|
|
554
|
-
}, {
|
|
555
|
-
name: "okno:writes",
|
|
556
|
-
enforce: "pre",
|
|
557
|
-
hotUpdate: {
|
|
558
|
-
order: "pre",
|
|
559
|
-
handler(e) {
|
|
560
|
-
if (i && lt(i, e.file)) return [];
|
|
561
|
-
}
|
|
562
|
-
},
|
|
563
|
-
handleHotUpdate: {
|
|
564
|
-
order: "pre",
|
|
565
|
-
handler(e) {
|
|
566
|
-
if (i && lt(i, e.file)) return [];
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}];
|
|
570
|
-
}
|
|
571
|
-
export {
|
|
572
|
-
de as o
|
|
573
|
-
};
|