@kiln-js/cli 0.1.6 → 0.2.0-hotfix
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/LICENSE +21 -0
- package/dist/dashboard.d.ts +32 -0
- package/dist/engine.d.ts +7 -0
- package/dist/index.js +361 -152
- package/dist/versions.d.ts +7 -4
- package/package.json +7 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zxsty
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CacheStats } from "@kiln-js/vite-plugin";
|
|
2
|
+
interface RequestEntry {
|
|
3
|
+
at: number;
|
|
4
|
+
method: string;
|
|
5
|
+
path: string;
|
|
6
|
+
status: number;
|
|
7
|
+
ms: number;
|
|
8
|
+
}
|
|
9
|
+
interface ErrorEntry {
|
|
10
|
+
at: number;
|
|
11
|
+
method: string;
|
|
12
|
+
path: string;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class DevStats {
|
|
16
|
+
readonly startedAt: number;
|
|
17
|
+
private requests;
|
|
18
|
+
private errors;
|
|
19
|
+
private total;
|
|
20
|
+
private failed;
|
|
21
|
+
recordRequest(entry: Omit<RequestEntry, "at">): void;
|
|
22
|
+
recordError(entry: Omit<ErrorEntry, "at">): void;
|
|
23
|
+
snapshot(): {
|
|
24
|
+
startedAt: number;
|
|
25
|
+
total: number;
|
|
26
|
+
failed: number;
|
|
27
|
+
requests: RequestEntry[];
|
|
28
|
+
errors: ErrorEntry[];
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export declare function renderDashboard(stats: DevStats, cache: CacheStats, pathname: string): string;
|
|
32
|
+
export {};
|
package/dist/engine.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -5,10 +5,10 @@ import { cac } from "cac";
|
|
|
5
5
|
|
|
6
6
|
// packages/cli/src/dev.ts
|
|
7
7
|
import fs5 from "node:fs";
|
|
8
|
-
import
|
|
8
|
+
import path8 from "node:path";
|
|
9
9
|
import http from "node:http";
|
|
10
10
|
import { createServer as createViteServer } from "vite";
|
|
11
|
-
import { kiln } from "@kiln-js/vite-plugin";
|
|
11
|
+
import { kiln, buildCacheStats } from "@kiln-js/vite-plugin";
|
|
12
12
|
|
|
13
13
|
// packages/cli/src/paths.ts
|
|
14
14
|
import path from "node:path";
|
|
@@ -60,7 +60,8 @@ function findUserEntry(name) {
|
|
|
60
60
|
function writeGenerated(name, source) {
|
|
61
61
|
ensureKilnDir();
|
|
62
62
|
const target = path2.join(paths.kilnDir, name);
|
|
63
|
-
fs.
|
|
63
|
+
const current = fs.existsSync(target) ? fs.readFileSync(target, "utf8") : null;
|
|
64
|
+
if (current !== source) fs.writeFileSync(target, source);
|
|
64
65
|
return target;
|
|
65
66
|
}
|
|
66
67
|
function resolveEntries() {
|
|
@@ -140,10 +141,10 @@ var log = {
|
|
|
140
141
|
warn: (msg) => console.log(` ${colors.yellow("\u26A0")} ${colors.yellow(msg)}`),
|
|
141
142
|
error: (msg) => console.error(` ${colors.ember("\u2716")} ${colors.ember(msg)}`),
|
|
142
143
|
change: (file2) => console.log(` ${colors.violet("\u21BB")} ${colors.dim("changed")} ${file2}`),
|
|
143
|
-
request(method, pathname, status,
|
|
144
|
+
request(method, pathname, status, time2) {
|
|
144
145
|
const verb = methodColor(method)(method.padEnd(6));
|
|
145
146
|
console.log(
|
|
146
|
-
` ${colors.gray("\u203A")} ${verb}${colors.bold(pathname)} ${statusColor(status)(String(status))} ${colors.gray(
|
|
147
|
+
` ${colors.gray("\u203A")} ${verb}${colors.bold(pathname)} ${statusColor(status)(String(status))} ${colors.gray(time2)}`
|
|
147
148
|
);
|
|
148
149
|
}
|
|
149
150
|
};
|
|
@@ -167,8 +168,8 @@ function spinner(label) {
|
|
|
167
168
|
clearInterval(timer);
|
|
168
169
|
const icon = ok ? colors.mint("\u2714") : colors.ember("\u2716");
|
|
169
170
|
const text = ok ? label : colors.ember(label);
|
|
170
|
-
const
|
|
171
|
-
process.stdout.write(`\r\x1B[2K ${icon} ${text} ${
|
|
171
|
+
const time2 = colors.gray(formatDuration(performance.now() - start));
|
|
172
|
+
process.stdout.write(`\r\x1B[2K ${icon} ${text} ${time2}${note ? ` ${note}` : ""}
|
|
172
173
|
`);
|
|
173
174
|
}
|
|
174
175
|
};
|
|
@@ -494,7 +495,7 @@ function renderDevError(err, meta) {
|
|
|
494
495
|
const hints = diagnose(error, frames);
|
|
495
496
|
const appFrames = frames.filter(isAppFrame);
|
|
496
497
|
const internal = frames.filter((f) => !isAppFrame(f));
|
|
497
|
-
const
|
|
498
|
+
const time2 = (/* @__PURE__ */ new Date()).toLocaleTimeString();
|
|
498
499
|
const where = origin ? `<a class="where" href="${editorLink(origin)}">${esc(rel2(origin.file))}:${origin.line}:${origin.column}</a>` : "";
|
|
499
500
|
const internalBlock = internal.length ? `<details class="internal"><summary>${internal.length} internal frames</summary><ol class="frames">${internal.map(frameItem).join("")}</ol></details>` : "";
|
|
500
501
|
const appList = appFrames.length ? appFrames.map(frameItem).join("") : `<li class="none">No frames from your code</li>`;
|
|
@@ -511,7 +512,7 @@ function renderDevError(err, meta) {
|
|
|
511
512
|
<header class="bar">
|
|
512
513
|
<span class="brand">Kiln</span>
|
|
513
514
|
<span class="route"><span class="method">${esc(meta.method)}</span>${esc(meta.pathname)}</span>
|
|
514
|
-
<span class="route">${esc(
|
|
515
|
+
<span class="route">${esc(time2)}</span>
|
|
515
516
|
<div class="actions">
|
|
516
517
|
<button id="copy" type="button">Copy stack</button>
|
|
517
518
|
<button id="dismiss" type="button">Dismiss</button>
|
|
@@ -571,46 +572,54 @@ function renderProdError(requestId) {
|
|
|
571
572
|
// packages/cli/src/versions.ts
|
|
572
573
|
import fs3 from "node:fs";
|
|
573
574
|
import path5 from "node:path";
|
|
574
|
-
|
|
575
|
-
|
|
575
|
+
var KILN_PACKAGES = [
|
|
576
|
+
"@kiln-js/core",
|
|
577
|
+
"@kiln-js/server",
|
|
578
|
+
"@kiln-js/client",
|
|
579
|
+
"@kiln-js/vite-plugin",
|
|
580
|
+
"@kiln-js/md",
|
|
581
|
+
"@kiln-js/adapter-vercel",
|
|
582
|
+
"@kiln-js/auth"
|
|
583
|
+
];
|
|
576
584
|
function cliVersion() {
|
|
577
585
|
const file2 = new URL("../package.json", import.meta.url);
|
|
578
586
|
return JSON.parse(fs3.readFileSync(file2, "utf8")).version;
|
|
579
587
|
}
|
|
588
|
+
function findPackageDir(name) {
|
|
589
|
+
let dir = paths.root;
|
|
590
|
+
for (; ; ) {
|
|
591
|
+
const candidate = path5.join(dir, "node_modules", ...name.split("/"));
|
|
592
|
+
if (fs3.existsSync(path5.join(candidate, "package.json"))) return candidate;
|
|
593
|
+
const parent = path5.dirname(dir);
|
|
594
|
+
if (parent === dir) return null;
|
|
595
|
+
dir = parent;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function inspectPackages() {
|
|
599
|
+
return KILN_PACKAGES.map((name) => {
|
|
600
|
+
const dir = findPackageDir(name);
|
|
601
|
+
if (!dir) return { name, version: null, location: null, linked: false };
|
|
602
|
+
const real = fs3.realpathSync(dir);
|
|
603
|
+
const version = JSON.parse(fs3.readFileSync(path5.join(real, "package.json"), "utf8")).version;
|
|
604
|
+
const location = path5.relative(paths.root, real).replace(/\\/g, "/") || ".";
|
|
605
|
+
return { name, version, location, linked: real.includes(`${path5.sep}packages${path5.sep}`) };
|
|
606
|
+
});
|
|
607
|
+
}
|
|
580
608
|
function findVersionProblems() {
|
|
581
609
|
const expected = cliVersion();
|
|
582
|
-
|
|
583
|
-
const problems = [];
|
|
584
|
-
for (const short of PACKAGES) {
|
|
585
|
-
const name = `@kiln-js/${short}`;
|
|
586
|
-
let pkgPath;
|
|
587
|
-
try {
|
|
588
|
-
pkgPath = req.resolve(`${name}/package.json`);
|
|
589
|
-
} catch {
|
|
590
|
-
continue;
|
|
591
|
-
}
|
|
592
|
-
const found = JSON.parse(fs3.readFileSync(pkgPath, "utf8")).version;
|
|
593
|
-
if (found !== expected) {
|
|
594
|
-
problems.push({ name, found, location: path5.relative(paths.root, path5.dirname(pkgPath)) || "." });
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
return problems;
|
|
610
|
+
return inspectPackages().filter((p) => p.version !== null && p.version !== expected);
|
|
598
611
|
}
|
|
599
612
|
function assertVersionsMatch() {
|
|
600
613
|
const problems = findVersionProblems();
|
|
601
614
|
if (problems.length === 0) return;
|
|
602
615
|
const expected = cliVersion();
|
|
603
|
-
const list = problems.map((p) => ` ${p.name} ${p.
|
|
616
|
+
const list = problems.map((p) => ` ${p.name} ${p.version} at ${p.location}`).join("\n");
|
|
604
617
|
throw new Error(
|
|
605
618
|
`The Kiln packages in this app do not match the CLI (${expected}):
|
|
606
619
|
${list}
|
|
607
620
|
|
|
608
621
|
Mixed versions cause "does not provide an export named" errors.
|
|
609
|
-
|
|
610
|
-
Fix:
|
|
611
|
-
1. Delete the stray installs: Remove-Item -Recurse -Force node_modules (in the folder printed above)
|
|
612
|
-
2. Run bun install at the monorepo root, so packages link to packages/
|
|
613
|
-
3. Run bun run dev from inside the app folder (for example examples\\kiln-docs)`
|
|
622
|
+
Run kiln doctor for the full list.`
|
|
614
623
|
);
|
|
615
624
|
}
|
|
616
625
|
|
|
@@ -627,8 +636,8 @@ function resolvePackage(name) {
|
|
|
627
636
|
if (fs4.existsSync(pkgJson)) {
|
|
628
637
|
const json = JSON.parse(fs4.readFileSync(pkgJson, "utf8"));
|
|
629
638
|
const dot = json.exports?.["."];
|
|
630
|
-
const
|
|
631
|
-
return { file: path6.join(pkgDir,
|
|
639
|
+
const rel5 = (typeof dot === "string" ? dot : dot?.import) ?? json.module ?? json.main ?? "index.js";
|
|
640
|
+
return { file: path6.join(pkgDir, rel5) };
|
|
632
641
|
}
|
|
633
642
|
const parent = path6.dirname(dir);
|
|
634
643
|
if (parent === dir) return null;
|
|
@@ -670,21 +679,160 @@ Fix:
|
|
|
670
679
|
);
|
|
671
680
|
}
|
|
672
681
|
|
|
682
|
+
// packages/cli/src/dashboard.ts
|
|
683
|
+
import path7 from "node:path";
|
|
684
|
+
import { scanApi, scanRoutes } from "@kiln-js/core/scan";
|
|
685
|
+
var DevStats = class {
|
|
686
|
+
startedAt = Date.now();
|
|
687
|
+
requests = [];
|
|
688
|
+
errors = [];
|
|
689
|
+
total = 0;
|
|
690
|
+
failed = 0;
|
|
691
|
+
recordRequest(entry) {
|
|
692
|
+
this.total++;
|
|
693
|
+
if (entry.status >= 500) this.failed++;
|
|
694
|
+
this.requests.unshift({ ...entry, at: Date.now() });
|
|
695
|
+
if (this.requests.length > 100) this.requests.length = 100;
|
|
696
|
+
}
|
|
697
|
+
recordError(entry) {
|
|
698
|
+
this.errors.unshift({ ...entry, at: Date.now() });
|
|
699
|
+
if (this.errors.length > 20) this.errors.length = 20;
|
|
700
|
+
}
|
|
701
|
+
snapshot() {
|
|
702
|
+
return {
|
|
703
|
+
startedAt: this.startedAt,
|
|
704
|
+
total: this.total,
|
|
705
|
+
failed: this.failed,
|
|
706
|
+
requests: this.requests,
|
|
707
|
+
errors: this.errors
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
var esc2 = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
712
|
+
var time = (ms) => new Date(ms).toLocaleTimeString();
|
|
713
|
+
var rel3 = (file2) => path7.relative(paths.root, file2).replace(/\\/g, "/");
|
|
714
|
+
function routeRows() {
|
|
715
|
+
try {
|
|
716
|
+
const pages = scanRoutes(paths.pagesDir).map(
|
|
717
|
+
(r) => `<tr><td><code>${esc2(r.pattern)}</code></td><td>${esc2(r.mode)}</td><td>${esc2(rel3(r.file))}</td></tr>`
|
|
718
|
+
);
|
|
719
|
+
const apis = scanApi(paths.apiDir).map(
|
|
720
|
+
(r) => `<tr><td><code>${esc2(r.pattern)}</code></td><td>api</td><td>${esc2(rel3(r.file))}</td></tr>`
|
|
721
|
+
);
|
|
722
|
+
return [...pages, ...apis].join("") || `<tr><td colspan="3">No routes</td></tr>`;
|
|
723
|
+
} catch (err) {
|
|
724
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
725
|
+
return `<tr><td colspan="3">${esc2(message)}</td></tr>`;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
var CSS = `
|
|
729
|
+
:root { color-scheme: dark; --bg:#0e1116; --panel:#161b22; --line:#262d38; --text:#e6edf3; --muted:#8b949e; --ok:#3fb950; --warn:#d29922; --bad:#f85149; --link:#79c0ff; }
|
|
730
|
+
* { box-sizing: border-box; }
|
|
731
|
+
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 ui-sans-serif, system-ui, sans-serif; }
|
|
732
|
+
header { display: flex; gap: 16px; align-items: baseline; padding: 16px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
|
|
733
|
+
header h1 { margin: 0; font-size: 16px; }
|
|
734
|
+
header span { color: var(--muted); font-size: 13px; }
|
|
735
|
+
main { padding: 20px 24px 48px; display: grid; gap: 16px; max-width: 1200px; margin: 0 auto; }
|
|
736
|
+
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
|
|
737
|
+
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
|
|
738
|
+
.stat b { display: block; font-size: 22px; margin-top: 4px; }
|
|
739
|
+
section { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
|
|
740
|
+
section h2 { margin: 0; font-size: 13px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
|
|
741
|
+
table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
742
|
+
th, td { text-align: left; padding: 7px 14px; border-bottom: 1px solid var(--line); }
|
|
743
|
+
th { color: var(--muted); font-weight: 500; }
|
|
744
|
+
code { font: 13px ui-monospace, Consolas, monospace; color: var(--link); }
|
|
745
|
+
.s2 { color: var(--ok); } .s3 { color: var(--link); } .s4 { color: var(--warn); } .s5 { color: var(--bad); }
|
|
746
|
+
.err { padding: 10px 14px; border-bottom: 1px solid var(--line); }
|
|
747
|
+
.err pre { margin: 6px 0 0; white-space: pre-wrap; color: var(--bad); font: 12px ui-monospace, Consolas, monospace; }
|
|
748
|
+
.empty { padding: 14px; color: var(--muted); }
|
|
749
|
+
@media (max-width: 800px) { .grid { grid-template-columns: repeat(2, 1fr); } }
|
|
750
|
+
`;
|
|
751
|
+
function renderDashboard(stats, cache, pathname) {
|
|
752
|
+
const snap = stats.snapshot();
|
|
753
|
+
const uptime = Math.floor((Date.now() - snap.startedAt) / 1e3);
|
|
754
|
+
const lookups = cache.hits + cache.misses;
|
|
755
|
+
const hitRate = lookups === 0 ? 0 : Math.round(cache.hits / lookups * 100);
|
|
756
|
+
const requests = snap.requests.length ? snap.requests.map(
|
|
757
|
+
(r) => `<tr>
|
|
758
|
+
<td>${time(r.at)}</td><td>${esc2(r.method)}</td><td><code>${esc2(r.path)}</code></td>
|
|
759
|
+
<td class="s${Math.floor(r.status / 100)}">${r.status}</td><td>${r.ms.toFixed(0)} ms</td>
|
|
760
|
+
</tr>`
|
|
761
|
+
).join("") : `<tr><td colspan="5" class="empty">No requests yet. Open a page in the browser.</td></tr>`;
|
|
762
|
+
const errors = snap.errors.length ? snap.errors.map(
|
|
763
|
+
(e) => `<div class="err">
|
|
764
|
+
<div>${time(e.at)} \xB7 ${esc2(e.method)} <code>${esc2(e.path)}</code></div>
|
|
765
|
+
<pre>${esc2(e.message)}</pre>
|
|
766
|
+
</div>`
|
|
767
|
+
).join("") : `<div class="empty">No errors</div>`;
|
|
768
|
+
return `<!doctype html>
|
|
769
|
+
<html lang="en">
|
|
770
|
+
<head>
|
|
771
|
+
<meta charset="utf-8" />
|
|
772
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
773
|
+
<meta http-equiv="refresh" content="2" />
|
|
774
|
+
<title>Kiln dashboard</title>
|
|
775
|
+
<style>${CSS}</style>
|
|
776
|
+
</head>
|
|
777
|
+
<body>
|
|
778
|
+
<header>
|
|
779
|
+
<h1>Kiln dashboard</h1>
|
|
780
|
+
<span>development only \xB7 ${esc2(pathname)} \xB7 up ${uptime}s</span>
|
|
781
|
+
</header>
|
|
782
|
+
<main>
|
|
783
|
+
<div class="grid">
|
|
784
|
+
<div class="stat">Requests<b>${snap.total}</b></div>
|
|
785
|
+
<div class="stat">Failed (5xx)<b>${snap.failed}</b></div>
|
|
786
|
+
<div class="stat">Cache hit rate<b>${hitRate}%</b></div>
|
|
787
|
+
<div class="stat">Cache invalidations<b>${cache.invalidations}</b></div>
|
|
788
|
+
</div>
|
|
789
|
+
|
|
790
|
+
<section>
|
|
791
|
+
<h2>Routes</h2>
|
|
792
|
+
<table><thead><tr><th>Pattern</th><th>Mode</th><th>File</th></tr></thead><tbody>${routeRows()}</tbody></table>
|
|
793
|
+
</section>
|
|
794
|
+
|
|
795
|
+
<section>
|
|
796
|
+
<h2>Recent requests</h2>
|
|
797
|
+
<table><thead><tr><th>Time</th><th>Method</th><th>Path</th><th>Status</th><th>Duration</th></tr></thead><tbody>${requests}</tbody></table>
|
|
798
|
+
</section>
|
|
799
|
+
|
|
800
|
+
<section>
|
|
801
|
+
<h2>Recent errors</h2>
|
|
802
|
+
${errors}
|
|
803
|
+
</section>
|
|
804
|
+
</main>
|
|
805
|
+
</body>
|
|
806
|
+
</html>`;
|
|
807
|
+
}
|
|
808
|
+
|
|
673
809
|
// packages/cli/src/dev.ts
|
|
674
810
|
function findAppFolders(base) {
|
|
675
811
|
try {
|
|
676
|
-
return fs5.readdirSync(base, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "node_modules").map((e) =>
|
|
812
|
+
return fs5.readdirSync(base, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "node_modules").map((e) => path8.join(base, e.name)).filter((dir) => fs5.existsSync(path8.join(dir, "app", "pages")));
|
|
677
813
|
} catch {
|
|
678
814
|
return [];
|
|
679
815
|
}
|
|
680
816
|
}
|
|
681
817
|
function assertAppFolder() {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
818
|
+
const pkgPath = path8.join(paths.root, "package.json");
|
|
819
|
+
if (!fs5.existsSync(pkgPath)) {
|
|
820
|
+
throw new Error(`No package.json in ${paths.root}. Run kiln dev inside an app folder.`);
|
|
821
|
+
}
|
|
822
|
+
const pkg2 = JSON.parse(fs5.readFileSync(pkgPath, "utf8"));
|
|
823
|
+
if (pkg2.workspaces) {
|
|
824
|
+
throw new Error(
|
|
825
|
+
`${paths.root} is a monorepo root, not an app. Run kiln dev inside an app, for example:
|
|
826
|
+
cd examples\\kiln-docs && bun run dev`
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
if (!fs5.existsSync(paths.pagesDir)) {
|
|
830
|
+
const found = findAppFolders(paths.root);
|
|
831
|
+
const hint = found.length > 0 ? `Found app folder(s) below this one:
|
|
832
|
+
` + found.map((d) => ` cd ${path8.relative(process.cwd(), d)} && bun run dev`).join("\n") : "Create app/pages in this folder, or run kiln dev in your app folder.";
|
|
833
|
+
throw new Error(`No app/pages folder in ${paths.root}.
|
|
687
834
|
${hint}`);
|
|
835
|
+
}
|
|
688
836
|
}
|
|
689
837
|
function toError2(err) {
|
|
690
838
|
if (err instanceof Error) return err;
|
|
@@ -725,25 +873,39 @@ async function toWebRequest(req, origin) {
|
|
|
725
873
|
return new Request(new URL(req.url ?? "/", origin), init);
|
|
726
874
|
}
|
|
727
875
|
async function startDev(port) {
|
|
728
|
-
assertVersionsMatch();
|
|
729
|
-
await preflightImports();
|
|
730
876
|
assertAppFolder();
|
|
877
|
+
await preflightImports();
|
|
878
|
+
assertVersionsMatch();
|
|
731
879
|
const startedAt = performance.now();
|
|
732
880
|
globalThis.__KILN_DEV__ = true;
|
|
733
881
|
loadEnvFiles("development");
|
|
734
882
|
const entries = resolveEntries();
|
|
735
883
|
const origin = `http://localhost:${port}`;
|
|
884
|
+
const stats = new DevStats();
|
|
736
885
|
let vite;
|
|
737
886
|
let lastRenderFailed = false;
|
|
887
|
+
let handler = null;
|
|
888
|
+
async function currentHandler() {
|
|
889
|
+
if (handler) return handler;
|
|
890
|
+
const mod = await vite.ssrLoadModule(entries.server);
|
|
891
|
+
const createHandler = getHandlerFactory(mod, entries.server);
|
|
892
|
+
handler = createHandler({ head: "", entry: `/${entries.clientRel}` });
|
|
893
|
+
return handler;
|
|
894
|
+
}
|
|
738
895
|
async function handleSsr(req, res) {
|
|
739
896
|
const url = req.url ?? "/";
|
|
740
897
|
const pathname = new URL(url, origin).pathname;
|
|
898
|
+
const method = req.method ?? "GET";
|
|
741
899
|
const start = performance.now();
|
|
900
|
+
if (pathname === "/__kiln" || pathname === "/__kiln/") {
|
|
901
|
+
res.statusCode = 200;
|
|
902
|
+
res.setHeader("content-type", "text/html; charset=utf-8");
|
|
903
|
+
res.end(renderDashboard(stats, buildCacheStats(), pathname));
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
742
906
|
try {
|
|
743
|
-
const
|
|
744
|
-
const
|
|
745
|
-
const handler = createHandler({ head: "", entry: `/${entries.clientRel}` });
|
|
746
|
-
const response = await handler(await toWebRequest(req, origin));
|
|
907
|
+
const current = await currentHandler();
|
|
908
|
+
const response = await current(await toWebRequest(req, origin));
|
|
747
909
|
const isHtml = (response.headers.get("content-type") ?? "").includes("text/html");
|
|
748
910
|
const body = isHtml ? await vite.transformIndexHtml(url, await response.text()) : Buffer.from(await response.arrayBuffer());
|
|
749
911
|
res.statusCode = response.status;
|
|
@@ -754,20 +916,25 @@ async function startDev(port) {
|
|
|
754
916
|
if (cookies.length) res.setHeader("set-cookie", cookies);
|
|
755
917
|
res.end(body);
|
|
756
918
|
lastRenderFailed = false;
|
|
757
|
-
|
|
919
|
+
const ms = performance.now() - start;
|
|
920
|
+
stats.recordRequest({ method, path: pathname, status: response.status, ms });
|
|
921
|
+
log.request(method, pathname, response.status, formatDuration(ms));
|
|
758
922
|
} catch (err) {
|
|
759
923
|
const error = toError2(err);
|
|
760
924
|
fixStack(vite, error);
|
|
761
925
|
lastRenderFailed = true;
|
|
762
|
-
|
|
763
|
-
|
|
926
|
+
const ms = performance.now() - start;
|
|
927
|
+
stats.recordRequest({ method, path: pathname, status: 500, ms });
|
|
928
|
+
stats.recordError({ method, path: pathname, message: `${error.name}: ${error.message}` });
|
|
929
|
+
log.error(`${method} ${pathname} 500 ${formatDuration(ms)}`);
|
|
930
|
+
printError(error, `${method} ${pathname}`);
|
|
764
931
|
if (pathname.startsWith("/api/")) {
|
|
765
932
|
res.statusCode = 500;
|
|
766
933
|
res.setHeader("content-type", "application/json");
|
|
767
934
|
res.end(JSON.stringify({ error: error.message }));
|
|
768
935
|
return;
|
|
769
936
|
}
|
|
770
|
-
const page = renderDevError(error, { method
|
|
937
|
+
const page = renderDevError(error, { method, pathname });
|
|
771
938
|
const html = await vite.transformIndexHtml(url, page).catch(() => page);
|
|
772
939
|
res.statusCode = 500;
|
|
773
940
|
res.setHeader("content-type", "text/html; charset=utf-8");
|
|
@@ -785,11 +952,15 @@ async function startDev(port) {
|
|
|
785
952
|
plugins: kiln({
|
|
786
953
|
pagesDir: paths.pagesDir,
|
|
787
954
|
apiDir: paths.apiDir,
|
|
788
|
-
appDir:
|
|
955
|
+
appDir: path8.join(paths.root, "app")
|
|
789
956
|
}),
|
|
790
957
|
logLevel: "warn",
|
|
791
958
|
server: { middlewareMode: true, hmr: { server } }
|
|
792
959
|
});
|
|
960
|
+
vite.watcher.on("all", (_event, file2) => {
|
|
961
|
+
const f = file2.replace(/\\/g, "/");
|
|
962
|
+
if (f.includes("/app/") || f.includes("/packages/")) handler = null;
|
|
963
|
+
});
|
|
793
964
|
vite.watcher.on("change", (file2) => {
|
|
794
965
|
const shown = file2.replace(paths.root, "").replace(/\\/g, "/");
|
|
795
966
|
log.change(shown);
|
|
@@ -803,6 +974,7 @@ async function startDev(port) {
|
|
|
803
974
|
[
|
|
804
975
|
colors.bold("Kiln dev server"),
|
|
805
976
|
`${colors.sky(origin)} ${colors.gray(`ready in ${formatDuration(performance.now() - startedAt)}`)}`,
|
|
977
|
+
`${colors.sky(`${origin}/__kiln`)} ${colors.gray("dashboard (dev only)")}`,
|
|
806
978
|
colors.dim("press Ctrl+C to stop")
|
|
807
979
|
],
|
|
808
980
|
colors.fire
|
|
@@ -818,15 +990,31 @@ async function startDev(port) {
|
|
|
818
990
|
|
|
819
991
|
// packages/cli/src/build.ts
|
|
820
992
|
import fs6 from "node:fs";
|
|
821
|
-
import
|
|
993
|
+
import path9 from "node:path";
|
|
822
994
|
import { build } from "vite";
|
|
823
|
-
import { adaptVercel } from "@kiln-js/adapter-vercel";
|
|
824
995
|
import { kiln as kiln2 } from "@kiln-js/vite-plugin";
|
|
996
|
+
import { adaptVercel } from "@kiln-js/adapter-vercel";
|
|
997
|
+
|
|
998
|
+
// packages/cli/src/engine.ts
|
|
999
|
+
function detectEngine() {
|
|
1000
|
+
const bun = globalThis.Bun;
|
|
1001
|
+
if (bun) {
|
|
1002
|
+
return { runtime: "bun", version: bun.version, bundler: "bun", label: `bun ${bun.version} \xB7 Bun.build` };
|
|
1003
|
+
}
|
|
1004
|
+
return {
|
|
1005
|
+
runtime: "node",
|
|
1006
|
+
version: process.versions.node,
|
|
1007
|
+
bundler: "esbuild",
|
|
1008
|
+
label: `node ${process.versions.node} \xB7 esbuild`
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
// packages/cli/src/build.ts
|
|
825
1013
|
var TARGETS = ["none", "vercel"];
|
|
826
1014
|
function dirSize(dir) {
|
|
827
1015
|
if (!fs6.existsSync(dir)) return 0;
|
|
828
1016
|
return fs6.readdirSync(dir, { withFileTypes: true }).reduce((sum, entry) => {
|
|
829
|
-
const full =
|
|
1017
|
+
const full = path9.join(dir, entry.name);
|
|
830
1018
|
return sum + (entry.isDirectory() ? dirSize(full) : fs6.statSync(full).size);
|
|
831
1019
|
}, 0);
|
|
832
1020
|
}
|
|
@@ -836,9 +1024,14 @@ async function runBuild(target = "none") {
|
|
|
836
1024
|
}
|
|
837
1025
|
const total = performance.now();
|
|
838
1026
|
loadEnvFiles("production");
|
|
1027
|
+
const engine = detectEngine();
|
|
839
1028
|
const entries = resolveEntries();
|
|
840
|
-
const plugins = kiln2({
|
|
841
|
-
|
|
1029
|
+
const plugins = kiln2({
|
|
1030
|
+
pagesDir: paths.pagesDir,
|
|
1031
|
+
apiDir: paths.apiDir,
|
|
1032
|
+
appDir: path9.join(paths.root, "app")
|
|
1033
|
+
});
|
|
1034
|
+
log.info(`Building for production ${colors.gray(`\xB7 target ${target} \xB7 ${engine.label}`)}`);
|
|
842
1035
|
await task(
|
|
843
1036
|
"client bundle",
|
|
844
1037
|
() => build({
|
|
@@ -869,19 +1062,21 @@ async function runBuild(target = "none") {
|
|
|
869
1062
|
);
|
|
870
1063
|
if (target === "vercel") {
|
|
871
1064
|
await task(
|
|
872
|
-
|
|
1065
|
+
`vercel output (${engine.bundler})`,
|
|
873
1066
|
() => adaptVercel({
|
|
874
1067
|
root: paths.root,
|
|
875
1068
|
clientOut: paths.clientOut,
|
|
876
1069
|
serverOut: paths.serverOut,
|
|
877
|
-
clientRel: entries.clientRel
|
|
1070
|
+
clientRel: entries.clientRel,
|
|
1071
|
+
bundler: engine.bundler
|
|
878
1072
|
})
|
|
879
1073
|
);
|
|
880
1074
|
}
|
|
881
1075
|
const lines = [
|
|
882
1076
|
`${colors.bold("Build complete")} ${colors.gray(formatDuration(performance.now() - total))}`,
|
|
883
1077
|
`${colors.sky("client")} ${formatBytes(dirSize(paths.clientOut))}`,
|
|
884
|
-
`${colors.violet("server")} ${formatBytes(dirSize(paths.serverOut))}
|
|
1078
|
+
`${colors.violet("server")} ${formatBytes(dirSize(paths.serverOut))}`,
|
|
1079
|
+
`${colors.gray("engine")} ${engine.label}`
|
|
885
1080
|
];
|
|
886
1081
|
if (target === "vercel") {
|
|
887
1082
|
lines.push(`${colors.fire("vercel")} .vercel/output ${colors.dim("\u2192 vercel deploy --prebuilt")}`);
|
|
@@ -891,13 +1086,13 @@ async function runBuild(target = "none") {
|
|
|
891
1086
|
|
|
892
1087
|
// packages/cli/src/start.ts
|
|
893
1088
|
import fs8 from "node:fs";
|
|
894
|
-
import
|
|
1089
|
+
import path11 from "node:path";
|
|
895
1090
|
import { randomUUID } from "node:crypto";
|
|
896
1091
|
import { pathToFileURL as pathToFileURL2 } from "node:url";
|
|
897
1092
|
|
|
898
1093
|
// packages/cli/src/compress.ts
|
|
899
1094
|
import fs7 from "node:fs";
|
|
900
|
-
import
|
|
1095
|
+
import path10 from "node:path";
|
|
901
1096
|
import { brotliCompressSync, gzipSync, constants } from "node:zlib";
|
|
902
1097
|
var COMPRESSIBLE = /^(text\/|application\/(javascript|json|xml|xhtml\+xml|wasm)|image\/svg\+xml)/;
|
|
903
1098
|
var MIN_SIZE = 1024;
|
|
@@ -959,7 +1154,7 @@ async function serveStatic(req, filePath) {
|
|
|
959
1154
|
return null;
|
|
960
1155
|
}
|
|
961
1156
|
if (!stat.isFile()) return null;
|
|
962
|
-
const type = MIME[
|
|
1157
|
+
const type = MIME[path10.extname(filePath).toLowerCase()] ?? "application/octet-stream";
|
|
963
1158
|
const etag = `W/"${stat.size}-${stat.mtimeMs}"`;
|
|
964
1159
|
const isHashed = /[\\/]assets[\\/]/.test(filePath);
|
|
965
1160
|
const headers = new Headers({
|
|
@@ -1057,14 +1252,14 @@ async function runStart(port) {
|
|
|
1057
1252
|
const startedAt = performance.now();
|
|
1058
1253
|
loadEnvFiles("production");
|
|
1059
1254
|
const { clientRel } = resolveEntries();
|
|
1060
|
-
const manifest = JSON.parse(fs8.readFileSync(
|
|
1255
|
+
const manifest = JSON.parse(fs8.readFileSync(path11.join(paths.clientOut, ".vite", "manifest.json"), "utf8"));
|
|
1061
1256
|
const entry = manifest[clientRel];
|
|
1062
1257
|
if (!entry) throw new Error(`No manifest entry for ${clientRel}. Run "kiln build" first.`);
|
|
1063
1258
|
const assets = {
|
|
1064
1259
|
head: (entry.css ?? []).map((href) => `<link rel="stylesheet" href="/${href}">`).join("\n"),
|
|
1065
1260
|
entry: `/${entry.file}`
|
|
1066
1261
|
};
|
|
1067
|
-
const serverEntry = await import(pathToFileURL2(
|
|
1262
|
+
const serverEntry = await import(pathToFileURL2(path11.join(paths.serverOut, "server.js")).href);
|
|
1068
1263
|
const handler = serverEntry.createHandler(assets);
|
|
1069
1264
|
const server = serve(port, async (req) => {
|
|
1070
1265
|
const started = performance.now();
|
|
@@ -1074,8 +1269,8 @@ async function runStart(port) {
|
|
|
1074
1269
|
if (pathname !== "/") {
|
|
1075
1270
|
const decoded = safeDecode(pathname);
|
|
1076
1271
|
if (decoded === null) return new Response("Bad Request", { status: 400 });
|
|
1077
|
-
const filePath =
|
|
1078
|
-
if (filePath.startsWith(paths.clientOut +
|
|
1272
|
+
const filePath = path11.join(paths.clientOut, decoded);
|
|
1273
|
+
if (filePath.startsWith(paths.clientOut + path11.sep)) {
|
|
1079
1274
|
const asset = await serveStatic(req, filePath);
|
|
1080
1275
|
if (asset) return asset;
|
|
1081
1276
|
}
|
|
@@ -1113,28 +1308,28 @@ async function runStart(port) {
|
|
|
1113
1308
|
|
|
1114
1309
|
// packages/cli/src/routes.ts
|
|
1115
1310
|
import fs9 from "node:fs";
|
|
1116
|
-
import
|
|
1117
|
-
import { scanRoutes, scanApi } from "@kiln-js/core/scan";
|
|
1311
|
+
import path12 from "node:path";
|
|
1312
|
+
import { scanRoutes as scanRoutes2, scanApi as scanApi2 } from "@kiln-js/core/scan";
|
|
1118
1313
|
var METHOD_RE = /export\s+(?:async\s+)?(?:function|const)\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\b/g;
|
|
1119
1314
|
var MODE_COLORS = {
|
|
1120
1315
|
universal: colors.mint,
|
|
1121
1316
|
server: colors.sky,
|
|
1122
1317
|
client: colors.violet
|
|
1123
1318
|
};
|
|
1124
|
-
var
|
|
1319
|
+
var rel4 = (file2) => path12.relative(paths.root, file2).split(path12.sep).join("/");
|
|
1125
1320
|
function methodsOf(file2) {
|
|
1126
1321
|
const src = fs9.readFileSync(file2, "utf8");
|
|
1127
1322
|
return [...src.matchAll(METHOD_RE)].map((m) => m[1]);
|
|
1128
1323
|
}
|
|
1129
1324
|
function printRoutes() {
|
|
1130
|
-
const pages =
|
|
1131
|
-
const apis =
|
|
1325
|
+
const pages = scanRoutes2(paths.pagesDir);
|
|
1326
|
+
const apis = scanApi2(paths.apiDir);
|
|
1132
1327
|
const rows = [
|
|
1133
1328
|
...pages.map((r) => [
|
|
1134
1329
|
colors.bold(r.pattern),
|
|
1135
1330
|
colors.gray("page"),
|
|
1136
1331
|
MODE_COLORS[r.mode](r.mode),
|
|
1137
|
-
colors.dim(
|
|
1332
|
+
colors.dim(rel4(r.file))
|
|
1138
1333
|
]),
|
|
1139
1334
|
...apis.map((r) => {
|
|
1140
1335
|
const methods = methodsOf(r.file);
|
|
@@ -1142,7 +1337,7 @@ function printRoutes() {
|
|
|
1142
1337
|
colors.bold(r.pattern),
|
|
1143
1338
|
colors.fire("api"),
|
|
1144
1339
|
methods.map((m) => methodColor(m)(m)).join(" ") || colors.gray("none"),
|
|
1145
|
-
colors.dim(
|
|
1340
|
+
colors.dim(rel4(r.file))
|
|
1146
1341
|
];
|
|
1147
1342
|
})
|
|
1148
1343
|
];
|
|
@@ -1152,7 +1347,7 @@ function printRoutes() {
|
|
|
1152
1347
|
|
|
1153
1348
|
// packages/cli/src/create.ts
|
|
1154
1349
|
import fs10 from "node:fs";
|
|
1155
|
-
import
|
|
1350
|
+
import path13 from "node:path";
|
|
1156
1351
|
import inquirer from "inquirer";
|
|
1157
1352
|
|
|
1158
1353
|
// packages/cli/src/templates.ts
|
|
@@ -1249,7 +1444,7 @@ export function GET(_ctx: ApiContext) {
|
|
|
1249
1444
|
return Response.json({ ok: true, time: new Date().toISOString() });
|
|
1250
1445
|
}
|
|
1251
1446
|
`;
|
|
1252
|
-
var
|
|
1447
|
+
var CSS2 = `body { font-family: system-ui, sans-serif; max-width: 640px; margin: 2rem auto; padding: 0 1rem; }
|
|
1253
1448
|
nav a { margin-right: 1rem; }
|
|
1254
1449
|
`;
|
|
1255
1450
|
var TSCONFIG = `{
|
|
@@ -1302,7 +1497,7 @@ function projectFiles(o) {
|
|
|
1302
1497
|
files["package.json"] = JSON.stringify(pkgJson, null, 2) + "\n";
|
|
1303
1498
|
files["tsconfig.json"] = TSCONFIG;
|
|
1304
1499
|
files[".gitignore"] = "node_modules\ndist\n.kiln\n.env.local\n.vercel\n";
|
|
1305
|
-
files["app/index.css"] =
|
|
1500
|
+
files["app/index.css"] = CSS2;
|
|
1306
1501
|
files["app/pages/_layout.tsx"] = LAYOUT(withBlog);
|
|
1307
1502
|
files[`app/pages/index${SUFFIX[o.defaultMode]}.tsx`] = homePage(o.name, o.defaultMode);
|
|
1308
1503
|
if (o.template !== "minimal") {
|
|
@@ -1402,7 +1597,7 @@ async function runCreate(nameArg) {
|
|
|
1402
1597
|
customEntries: extras.includes("entries"),
|
|
1403
1598
|
linked: answers.linked
|
|
1404
1599
|
};
|
|
1405
|
-
const dir =
|
|
1600
|
+
const dir = path13.resolve(process.cwd(), options.name);
|
|
1406
1601
|
if (fs10.existsSync(dir) && fs10.readdirSync(dir).length > 0) {
|
|
1407
1602
|
const { overwrite } = await inquirer.prompt([
|
|
1408
1603
|
{
|
|
@@ -1418,9 +1613,9 @@ async function runCreate(nameArg) {
|
|
|
1418
1613
|
}
|
|
1419
1614
|
}
|
|
1420
1615
|
log.step(`Writing project to ${dir}`);
|
|
1421
|
-
for (const [
|
|
1422
|
-
const target =
|
|
1423
|
-
fs10.mkdirSync(
|
|
1616
|
+
for (const [rel5, content] of Object.entries(projectFiles(options))) {
|
|
1617
|
+
const target = path13.join(dir, rel5);
|
|
1618
|
+
fs10.mkdirSync(path13.dirname(target), { recursive: true });
|
|
1424
1619
|
fs10.writeFileSync(target, content);
|
|
1425
1620
|
}
|
|
1426
1621
|
log.success(`Created ${options.name}`);
|
|
@@ -1436,7 +1631,7 @@ async function runCreate(nameArg) {
|
|
|
1436
1631
|
|
|
1437
1632
|
// packages/cli/src/generate.ts
|
|
1438
1633
|
import fs11 from "node:fs";
|
|
1439
|
-
import
|
|
1634
|
+
import path14 from "node:path";
|
|
1440
1635
|
import inquirer2 from "inquirer";
|
|
1441
1636
|
var SUFFIX2 = { universal: "", server: ".server", client: ".client" };
|
|
1442
1637
|
var ALL_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
@@ -1492,9 +1687,9 @@ export default function Layout({ children }: { children: ReactNode }) {
|
|
|
1492
1687
|
}
|
|
1493
1688
|
`;
|
|
1494
1689
|
function targetFor(kind, name, mode) {
|
|
1495
|
-
if (kind === "page") return
|
|
1496
|
-
if (kind === "api") return
|
|
1497
|
-
return
|
|
1690
|
+
if (kind === "page") return path14.join(paths.pagesDir, `${name}${SUFFIX2[mode]}.tsx`);
|
|
1691
|
+
if (kind === "api") return path14.join(paths.apiDir, `${name}.ts`);
|
|
1692
|
+
return path14.join(paths.pagesDir, name, "_layout.tsx");
|
|
1498
1693
|
}
|
|
1499
1694
|
async function runGenerate(kindArg, nameArg, opts = {}) {
|
|
1500
1695
|
resolveEntries();
|
|
@@ -1561,23 +1756,23 @@ async function runGenerate(kindArg, nameArg, opts = {}) {
|
|
|
1561
1756
|
}
|
|
1562
1757
|
const file2 = targetFor(kind, name, mode);
|
|
1563
1758
|
if (fs11.existsSync(file2)) {
|
|
1564
|
-
throw new Error(`${
|
|
1759
|
+
throw new Error(`${path14.relative(paths.root, file2)} already exists`);
|
|
1565
1760
|
}
|
|
1566
1761
|
const content = kind === "page" ? pageTemplate(name, loader) : kind === "api" ? apiTemplate(methods) : LAYOUT_TEMPLATE;
|
|
1567
|
-
fs11.mkdirSync(
|
|
1762
|
+
fs11.mkdirSync(path14.dirname(file2), { recursive: true });
|
|
1568
1763
|
fs11.writeFileSync(file2, content);
|
|
1569
|
-
log.success(`Created ${
|
|
1764
|
+
log.success(`Created ${path14.relative(paths.root, file2).replace(/\\/g, "/")}`);
|
|
1570
1765
|
log.info("Run `kiln routes` to see the new route.");
|
|
1571
1766
|
}
|
|
1572
1767
|
|
|
1573
1768
|
// packages/cli/src/typecheck.ts
|
|
1574
1769
|
import { spawn as spawn2 } from "node:child_process";
|
|
1575
|
-
import { createRequire
|
|
1576
|
-
import
|
|
1770
|
+
import { createRequire } from "node:module";
|
|
1771
|
+
import path15 from "node:path";
|
|
1577
1772
|
var LINE = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.*)$/;
|
|
1578
1773
|
function tscPath() {
|
|
1579
|
-
const req =
|
|
1580
|
-
return
|
|
1774
|
+
const req = createRequire(path15.join(paths.root, "package.json"));
|
|
1775
|
+
return path15.join(path15.dirname(req.resolve("typescript/package.json")), "bin", "tsc");
|
|
1581
1776
|
}
|
|
1582
1777
|
function runTsc() {
|
|
1583
1778
|
return new Promise((resolve) => {
|
|
@@ -1597,30 +1792,30 @@ async function runTypecheck() {
|
|
|
1597
1792
|
const output = await runTsc();
|
|
1598
1793
|
const errors = output.split(/\r?\n/).map((line) => line.match(LINE)).filter((m) => m !== null);
|
|
1599
1794
|
for (const [, file2, line, col, code, message] of errors) {
|
|
1600
|
-
const shown =
|
|
1795
|
+
const shown = path15.relative(paths.root, path15.resolve(paths.root, file2)).replace(/\\/g, "/");
|
|
1601
1796
|
console.log(` ${colors.red("\u2716")} ${colors.cyan(`${shown}:${line}:${col}`)} ${colors.gray(code)}`);
|
|
1602
1797
|
console.log(` ${message}`);
|
|
1603
1798
|
}
|
|
1604
|
-
const
|
|
1799
|
+
const time2 = formatDuration(performance.now() - started);
|
|
1605
1800
|
if (errors.length === 0 && /error/i.test(output) === false) {
|
|
1606
|
-
log.success(`No type errors ${colors.gray(`(${
|
|
1801
|
+
log.success(`No type errors ${colors.gray(`(${time2})`)}`);
|
|
1607
1802
|
return 0;
|
|
1608
1803
|
}
|
|
1609
1804
|
if (errors.length === 0) {
|
|
1610
1805
|
console.log(output.trim());
|
|
1611
1806
|
return 1;
|
|
1612
1807
|
}
|
|
1613
|
-
log.error(`${errors.length} type error${errors.length === 1 ? "" : "s"} ${colors.gray(`(${
|
|
1808
|
+
log.error(`${errors.length} type error${errors.length === 1 ? "" : "s"} ${colors.gray(`(${time2})`)}`);
|
|
1614
1809
|
return errors.length;
|
|
1615
1810
|
}
|
|
1616
1811
|
|
|
1617
1812
|
// packages/cli/src/doctor.ts
|
|
1618
1813
|
import fs12 from "node:fs";
|
|
1619
|
-
import
|
|
1620
|
-
import { scanRoutes as
|
|
1621
|
-
var file = (
|
|
1622
|
-
var exists = (
|
|
1623
|
-
var read = (
|
|
1814
|
+
import path16 from "node:path";
|
|
1815
|
+
import { scanRoutes as scanRoutes3 } from "@kiln-js/core/scan";
|
|
1816
|
+
var file = (rel5) => path16.join(paths.root, rel5);
|
|
1817
|
+
var exists = (rel5) => fs12.existsSync(file(rel5));
|
|
1818
|
+
var read = (rel5) => exists(rel5) ? fs12.readFileSync(file(rel5), "utf8") : "";
|
|
1624
1819
|
function atLeast(version, min) {
|
|
1625
1820
|
const a = version.split(".").map(Number);
|
|
1626
1821
|
const b = min.split(".").map(Number);
|
|
@@ -1634,7 +1829,7 @@ function appSourceContains(needle) {
|
|
|
1634
1829
|
if (!fs12.existsSync(dir)) return false;
|
|
1635
1830
|
for (const entry of fs12.readdirSync(dir, { withFileTypes: true })) {
|
|
1636
1831
|
if (entry.name === "node_modules") continue;
|
|
1637
|
-
const full =
|
|
1832
|
+
const full = path16.join(dir, entry.name);
|
|
1638
1833
|
if (entry.isDirectory()) {
|
|
1639
1834
|
if (walk(full)) return true;
|
|
1640
1835
|
} else if (/\.(tsx?|jsx?|mdx?)$/.test(entry.name) && fs12.readFileSync(full, "utf8").includes(needle)) {
|
|
@@ -1645,95 +1840,109 @@ function appSourceContains(needle) {
|
|
|
1645
1840
|
};
|
|
1646
1841
|
return walk(file("app"));
|
|
1647
1842
|
}
|
|
1648
|
-
function
|
|
1649
|
-
const
|
|
1843
|
+
function runtimeSection() {
|
|
1844
|
+
const checks = [];
|
|
1650
1845
|
if (runtime === "bun") {
|
|
1651
1846
|
const version = globalThis.Bun.version;
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
status: atLeast(version, "1.1.0") ? "ok" : "warn",
|
|
1655
|
-
detail: `Bun ${version}${atLeast(version, "1.1.0") ? "" : " (1.1 or later recommended)"}`
|
|
1656
|
-
});
|
|
1847
|
+
const ok = atLeast(version, "1.1.0");
|
|
1848
|
+
checks.push({ name: "Runtime", status: ok ? "ok" : "warn", detail: `Bun ${version}${ok ? "" : " (1.1 or later recommended)"}` });
|
|
1657
1849
|
} else {
|
|
1658
1850
|
const ok = Number(nodeVersion.split(".")[0]) >= 18;
|
|
1659
|
-
|
|
1660
|
-
name: "Runtime",
|
|
1661
|
-
status: ok ? "ok" : "fail",
|
|
1662
|
-
detail: `Node ${nodeVersion}${ok ? "" : " (18 or later required)"}`
|
|
1663
|
-
});
|
|
1851
|
+
checks.push({ name: "Runtime", status: ok ? "ok" : "fail", detail: `Node ${nodeVersion}${ok ? "" : " (18 or later required)"}` });
|
|
1664
1852
|
}
|
|
1665
|
-
|
|
1853
|
+
checks.push({ name: "Kiln CLI", status: "ok", detail: `kiln ${cliVersion()}` });
|
|
1854
|
+
return { title: "Runtime", checks };
|
|
1855
|
+
}
|
|
1856
|
+
function projectSection() {
|
|
1857
|
+
const checks = [];
|
|
1858
|
+
checks.push({
|
|
1666
1859
|
name: "package.json",
|
|
1667
1860
|
status: exists("package.json") ? "ok" : "fail",
|
|
1668
|
-
detail: exists("package.json") ? "found" : "missing. Run
|
|
1861
|
+
detail: exists("package.json") ? "found" : "missing. Run kiln doctor inside an app folder."
|
|
1669
1862
|
});
|
|
1670
|
-
|
|
1863
|
+
checks.push({
|
|
1671
1864
|
name: "node_modules",
|
|
1672
1865
|
status: exists("node_modules") ? "ok" : "fail",
|
|
1673
1866
|
detail: exists("node_modules") ? "installed" : "missing. Run bun install."
|
|
1674
1867
|
});
|
|
1675
|
-
|
|
1868
|
+
checks.push({
|
|
1676
1869
|
name: "tsconfig.json",
|
|
1677
1870
|
status: exists("tsconfig.json") ? "ok" : "warn",
|
|
1678
1871
|
detail: exists("tsconfig.json") ? "found" : "missing. kiln typecheck needs it."
|
|
1679
1872
|
});
|
|
1680
1873
|
try {
|
|
1681
|
-
const routes =
|
|
1682
|
-
|
|
1874
|
+
const routes = scanRoutes3(paths.pagesDir);
|
|
1875
|
+
checks.push({
|
|
1683
1876
|
name: "Routes",
|
|
1684
1877
|
status: routes.length > 0 ? "ok" : "fail",
|
|
1685
1878
|
detail: routes.length > 0 ? `${routes.length} page routes, no conflicts` : "no pages in app/pages"
|
|
1686
1879
|
});
|
|
1687
1880
|
} catch (err) {
|
|
1688
|
-
|
|
1881
|
+
checks.push({ name: "Routes", status: "fail", detail: err instanceof Error ? err.message : String(err) });
|
|
1689
1882
|
}
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1883
|
+
return { title: "Project", checks };
|
|
1884
|
+
}
|
|
1885
|
+
function packagesSection() {
|
|
1886
|
+
const expected = cliVersion();
|
|
1887
|
+
const checks = inspectPackages().map((p) => {
|
|
1888
|
+
const used = appSourceContains(`"${p.name}"`);
|
|
1889
|
+
if (p.version === null) {
|
|
1890
|
+
return used ? { name: p.name, status: "fail", detail: "imported by the app but not installed. Run bun install." } : { name: p.name, status: "warn", detail: "not installed (optional)" };
|
|
1891
|
+
}
|
|
1892
|
+
if (p.version !== expected) {
|
|
1893
|
+
return { name: p.name, status: "fail", detail: `${p.version}, but the CLI is ${expected}. Run bun install at the monorepo root.` };
|
|
1894
|
+
}
|
|
1895
|
+
return {
|
|
1896
|
+
name: p.name,
|
|
1897
|
+
status: "ok",
|
|
1898
|
+
detail: `${p.version} \xB7 ${p.linked ? "linked to the monorepo" : "installed"} \xB7 ${p.location}`
|
|
1899
|
+
};
|
|
1700
1900
|
});
|
|
1901
|
+
return { title: "Packages", checks };
|
|
1902
|
+
}
|
|
1903
|
+
function configSection() {
|
|
1904
|
+
const checks = [];
|
|
1701
1905
|
const usesDb = appSourceContains("DATABASE_URL");
|
|
1702
1906
|
const envDefines = /^DATABASE_URL=/m.test(read(".env.local") + read(".env"));
|
|
1703
|
-
|
|
1907
|
+
checks.push({
|
|
1704
1908
|
name: "DATABASE_URL",
|
|
1705
1909
|
status: !usesDb || envDefines ? "ok" : "warn",
|
|
1706
1910
|
detail: !usesDb ? "not used" : envDefines ? "set in .env files" : "used in code but not in .env.local"
|
|
1707
1911
|
});
|
|
1708
1912
|
const usesMd = appSourceContains("@kiln-js/md");
|
|
1709
1913
|
const configHasMd = /\bmd\s*\(/.test(read("vite.config.ts") + read("vite.config.js"));
|
|
1710
|
-
|
|
1914
|
+
checks.push({
|
|
1711
1915
|
name: "Markdown plugin",
|
|
1712
1916
|
status: !usesMd || configHasMd ? "ok" : "warn",
|
|
1713
1917
|
detail: !usesMd ? "not used" : configHasMd ? "registered in vite.config" : "imported but md() is not in vite.config"
|
|
1714
1918
|
});
|
|
1715
|
-
const
|
|
1716
|
-
|
|
1717
|
-
name: "
|
|
1718
|
-
status:
|
|
1719
|
-
detail:
|
|
1919
|
+
const reactCopy = exists("node_modules/react-dom/node_modules/react");
|
|
1920
|
+
checks.push({
|
|
1921
|
+
name: "React copies",
|
|
1922
|
+
status: reactCopy ? "warn" : "ok",
|
|
1923
|
+
detail: reactCopy ? "two copies installed. Hooks can break. Pin one version." : "one copy"
|
|
1720
1924
|
});
|
|
1721
|
-
return
|
|
1925
|
+
return { title: "Configuration", checks };
|
|
1722
1926
|
}
|
|
1927
|
+
var ICON = {
|
|
1928
|
+
ok: colors.mint("\u2714"),
|
|
1929
|
+
warn: colors.yellow("!"),
|
|
1930
|
+
fail: colors.red("\u2716")
|
|
1931
|
+
};
|
|
1723
1932
|
function runDoctor() {
|
|
1724
1933
|
log.info("Checking this project");
|
|
1725
|
-
const
|
|
1726
|
-
const
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
};
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1934
|
+
const sections = [runtimeSection(), projectSection(), packagesSection(), configSection()];
|
|
1935
|
+
const all = sections.flatMap((s) => s.checks);
|
|
1936
|
+
const width = Math.max(...all.map((c) => c.name.length)) + 2;
|
|
1937
|
+
for (const section of sections) {
|
|
1938
|
+
console.log(`
|
|
1939
|
+
${colors.bold(section.title)}`);
|
|
1940
|
+
for (const c of section.checks) {
|
|
1941
|
+
console.log(` ${ICON[c.status]} ${c.name.padEnd(width)} ${colors.gray(c.detail)}`);
|
|
1942
|
+
}
|
|
1734
1943
|
}
|
|
1735
|
-
const fails =
|
|
1736
|
-
const warns =
|
|
1944
|
+
const fails = all.filter((c) => c.status === "fail").length;
|
|
1945
|
+
const warns = all.filter((c) => c.status === "warn").length;
|
|
1737
1946
|
console.log("");
|
|
1738
1947
|
if (fails) log.error(`${fails} problem${fails === 1 ? "" : "s"} to fix${warns ? `, ${warns} warning${warns === 1 ? "" : "s"}` : ""}`);
|
|
1739
1948
|
else if (warns) log.warn(`No blocking problems, ${warns} warning${warns === 1 ? "" : "s"}`);
|
|
@@ -1744,7 +1953,7 @@ function runDoctor() {
|
|
|
1744
1953
|
// packages/cli/src/test.ts
|
|
1745
1954
|
import { createServer as createViteServer2 } from "vite";
|
|
1746
1955
|
import { kiln as kiln3 } from "@kiln-js/vite-plugin";
|
|
1747
|
-
import { scanRoutes as
|
|
1956
|
+
import { scanRoutes as scanRoutes4 } from "@kiln-js/core/scan";
|
|
1748
1957
|
function samplePath(pattern) {
|
|
1749
1958
|
const parts = pattern.split("/").filter(Boolean).map((seg) => seg.startsWith(":") ? "example" : seg.startsWith("*") ? "a/b" : seg);
|
|
1750
1959
|
return "/" + parts.join("/");
|
|
@@ -1767,7 +1976,7 @@ async function runTests(filters) {
|
|
|
1767
1976
|
head: "",
|
|
1768
1977
|
entry: `/${entries.clientRel}`
|
|
1769
1978
|
});
|
|
1770
|
-
const routes =
|
|
1979
|
+
const routes = scanRoutes4(paths.pagesDir).filter((r) => r.mode !== "client");
|
|
1771
1980
|
const selected = routes.filter((r) => {
|
|
1772
1981
|
const url = samplePath(r.pattern);
|
|
1773
1982
|
return filters.length === 0 || filters.some((f) => url.startsWith(f));
|
package/dist/versions.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const KILN_PACKAGES: readonly ["@kiln-js/core", "@kiln-js/server", "@kiln-js/client", "@kiln-js/vite-plugin", "@kiln-js/md", "@kiln-js/adapter-vercel", "@kiln-js/auth"];
|
|
2
|
+
export interface InstalledPackage {
|
|
2
3
|
name: string;
|
|
3
|
-
|
|
4
|
-
location: string;
|
|
4
|
+
version: string | null;
|
|
5
|
+
location: string | null;
|
|
6
|
+
linked: boolean;
|
|
5
7
|
}
|
|
6
8
|
export declare function cliVersion(): string;
|
|
7
|
-
export declare function
|
|
9
|
+
export declare function inspectPackages(): InstalledPackage[];
|
|
10
|
+
export declare function findVersionProblems(): InstalledPackage[];
|
|
8
11
|
export declare function assertVersionsMatch(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiln-js/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-hotfix",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"kiln": "./dist/index.js"
|
|
@@ -12,11 +12,13 @@
|
|
|
12
12
|
"build": "bun build ./src/index.ts --outdir ./dist --target node --packages external --banner \u0027#!/usr/bin/env node\u0027 \u0026\u0026 tsc -p tsconfig.json --emitDeclarationOnly",
|
|
13
13
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
14
14
|
},
|
|
15
|
+
"repository": "github:kiln-js/cli",
|
|
16
|
+
"homepage": "https://kiln-js.vercel.app",
|
|
15
17
|
"dependencies": {
|
|
16
|
-
"@kiln-js/adapter-vercel": "^0.
|
|
17
|
-
"@kiln-js/core": "^0.
|
|
18
|
-
"@kiln-js/server": "^0.
|
|
19
|
-
"@kiln-js/vite-plugin": "^0.
|
|
18
|
+
"@kiln-js/adapter-vercel": "^0.2.0-hotfix",
|
|
19
|
+
"@kiln-js/core": "^0.2.0-hotfix",
|
|
20
|
+
"@kiln-js/server": "^0.2.0-hotfix",
|
|
21
|
+
"@kiln-js/vite-plugin": "^0.2.0-hotfix",
|
|
20
22
|
"cac": "^6.7.14",
|
|
21
23
|
"inquirer": "^9.3.7",
|
|
22
24
|
"vite": "5.4.21"
|