@farm.js/devtools 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +9 -6
- package/dist/modules.js +10 -5
- package/dist/server.d.ts +1 -0
- package/dist/server.js +29 -6
- package/dist/ui/panel.js +10 -10
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveFarmDevtoolsConfig } from "@farm.js/core";
|
|
1
2
|
import { definePlugin } from "@farm.js/core/plugin";
|
|
2
3
|
/** Add the development-only workspace inspector. No production runtime is registered. */
|
|
3
4
|
export function devtools(options = {}) {
|
|
@@ -32,22 +33,24 @@ export function devtools(options = {}) {
|
|
|
32
33
|
(typeof config.devtools === "object" && config.devtools.enabled === false)) {
|
|
33
34
|
throw new Error("[farm:devtools] Remove devtools: false (or enabled: false) when using the devtools() plugin");
|
|
34
35
|
}
|
|
36
|
+
const devtoolsConfig = {
|
|
37
|
+
...(typeof config.devtools === "object" ? config.devtools : {}),
|
|
38
|
+
enabled: true,
|
|
39
|
+
...(options.shortcut === undefined ? {} : { shortcut: options.shortcut }),
|
|
40
|
+
};
|
|
41
|
+
const { shortcut } = resolveFarmDevtoolsConfig(devtoolsConfig);
|
|
35
42
|
const vitePlugin = {
|
|
36
43
|
name: "farm:devtools-ui",
|
|
37
44
|
enforce: "pre",
|
|
38
45
|
apply: "serve",
|
|
39
46
|
async configureServer(server) {
|
|
40
47
|
const { installDevtoolsServer } = await import("./server.js");
|
|
41
|
-
installDevtoolsServer(server, { inspect });
|
|
48
|
+
installDevtoolsServer(server, { inspect, shortcut });
|
|
42
49
|
},
|
|
43
50
|
};
|
|
44
51
|
return {
|
|
45
52
|
...config,
|
|
46
|
-
devtools:
|
|
47
|
-
...(typeof config.devtools === "object" ? config.devtools : {}),
|
|
48
|
-
enabled: true,
|
|
49
|
-
...(options.shortcut === undefined ? {} : { shortcut: options.shortcut }),
|
|
50
|
-
},
|
|
53
|
+
devtools: devtoolsConfig,
|
|
51
54
|
vite: { ...config.vite, plugins: [vitePlugin, ...(config.vite?.plugins ?? [])] },
|
|
52
55
|
};
|
|
53
56
|
},
|
package/dist/modules.js
CHANGED
|
@@ -21,7 +21,8 @@ function contained(root, file) {
|
|
|
21
21
|
/** Only already-transformed browser modules are eligible. Never transform or execute on request. */
|
|
22
22
|
export function createModuleInspector(server) {
|
|
23
23
|
const root = path.resolve(server.config.root);
|
|
24
|
-
|
|
24
|
+
// Resolved on first inspection, so a missing root never rejects while nothing awaits it.
|
|
25
|
+
let rootReal;
|
|
25
26
|
function entries() {
|
|
26
27
|
return [...server.moduleGraph.idToModuleMap.values()]
|
|
27
28
|
.filter((module) => module.id &&
|
|
@@ -45,7 +46,10 @@ export function createModuleInspector(server) {
|
|
|
45
46
|
async function safe(module) {
|
|
46
47
|
try {
|
|
47
48
|
const canonical = await realpath(module.file);
|
|
48
|
-
const realRoot = await rootReal
|
|
49
|
+
const realRoot = await (rootReal ??= realpath(root).catch((error) => {
|
|
50
|
+
rootReal = undefined;
|
|
51
|
+
throw error;
|
|
52
|
+
}));
|
|
49
53
|
return contained(realRoot, canonical) &&
|
|
50
54
|
SOURCE_EXTENSION.test(canonical) &&
|
|
51
55
|
!path
|
|
@@ -90,7 +94,8 @@ export function createModuleInspector(server) {
|
|
|
90
94
|
const stat = await file.stat();
|
|
91
95
|
if (!stat.isFile() || stat.size > SOURCE_LIMIT)
|
|
92
96
|
throw new ModuleInspectionError("Source exceeds the 1 MiB inspection limit", 413);
|
|
93
|
-
|
|
97
|
+
// One spare byte detects a file that grew after stat.
|
|
98
|
+
const buffer = Buffer.alloc(stat.size + 1);
|
|
94
99
|
let bytesRead = 0;
|
|
95
100
|
while (bytesRead < buffer.length) {
|
|
96
101
|
const chunk = await file.read(buffer, bytesRead, buffer.length - bytesRead, bytesRead);
|
|
@@ -98,8 +103,8 @@ export function createModuleInspector(server) {
|
|
|
98
103
|
break;
|
|
99
104
|
bytesRead += chunk.bytesRead;
|
|
100
105
|
}
|
|
101
|
-
if (bytesRead >
|
|
102
|
-
throw new ModuleInspectionError("
|
|
106
|
+
if (bytesRead > stat.size)
|
|
107
|
+
throw new ModuleInspectionError("Module changed while it was read. Refresh Inspect and try again.", 409);
|
|
103
108
|
return {
|
|
104
109
|
...summary(module),
|
|
105
110
|
source: buffer.subarray(0, bytesRead).toString("utf8"),
|
package/dist/server.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import type { ViteDevServer } from "vite";
|
|
|
4
4
|
export declare function isTrustedRequest(req: IncomingMessage, server: ViteDevServer): boolean;
|
|
5
5
|
export declare function installDevtoolsServer(server: ViteDevServer, options: {
|
|
6
6
|
inspect: boolean;
|
|
7
|
+
shortcut?: string | false;
|
|
7
8
|
}): void;
|
package/dist/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
2
|
import { isIP } from "node:net";
|
|
3
3
|
import { createModuleInspector, ModuleInspectionError } from "./modules.js";
|
|
4
4
|
import { DEVTOOLS_PATH } from "./types.js";
|
|
@@ -33,14 +33,39 @@ export function isTrustedRequest(req, server) {
|
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
const escapeAttribute = (value) => value.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`);
|
|
36
37
|
export function installDevtoolsServer(server, options) {
|
|
37
38
|
const inspector = createModuleInspector(server);
|
|
38
39
|
const assetRoot = new URL("./ui/", import.meta.url);
|
|
39
40
|
const assets = new Map();
|
|
41
|
+
// Font file names are content hashed by the UI build; only serve the ones it shipped.
|
|
42
|
+
let shippedFonts;
|
|
43
|
+
const isShippedFont = async (name) => {
|
|
44
|
+
shippedFonts ??= readdir(assetRoot).then((names) => new Set(names.filter((entry) => entry.endsWith(".woff2"))), () => {
|
|
45
|
+
shippedFonts = undefined;
|
|
46
|
+
return new Set();
|
|
47
|
+
});
|
|
48
|
+
return (await shippedFonts).has(name);
|
|
49
|
+
};
|
|
50
|
+
const readAsset = (name) => {
|
|
51
|
+
let asset = assets.get(name);
|
|
52
|
+
if (!asset) {
|
|
53
|
+
const pending = readFile(new URL(name, assetRoot));
|
|
54
|
+
assets.set(name, pending);
|
|
55
|
+
// A failed read must not be served from the cache forever.
|
|
56
|
+
pending.catch(() => {
|
|
57
|
+
if (assets.get(name) === pending)
|
|
58
|
+
assets.delete(name);
|
|
59
|
+
});
|
|
60
|
+
asset = pending;
|
|
61
|
+
}
|
|
62
|
+
return asset;
|
|
63
|
+
};
|
|
40
64
|
let closed = false;
|
|
41
65
|
server.httpServer?.once("close", () => {
|
|
42
66
|
closed = true;
|
|
43
67
|
assets.clear();
|
|
68
|
+
shippedFonts = undefined;
|
|
44
69
|
});
|
|
45
70
|
server.middlewares.use(async (req, res, next) => {
|
|
46
71
|
let url;
|
|
@@ -82,7 +107,7 @@ export function installDevtoolsServer(server, options) {
|
|
|
82
107
|
if (url.searchParams.get("embedded") !== "1")
|
|
83
108
|
return next();
|
|
84
109
|
res.setHeader("Content-Security-Policy", "default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; font-src 'self'; img-src 'self'; connect-src 'self'; frame-ancestors 'self'; base-uri 'none'; form-action 'none'");
|
|
85
|
-
send(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="dark light"><title>Farm.js DevTools</title><link rel="stylesheet" href="${DEVTOOLS_PATH}/assets/panel.css"></head><body><div id="farm-devtools" data-inspect="${options.inspect}"></div><script type="module" src="${DEVTOOLS_PATH}/assets/panel.js"></script></body></html>`, "text/html; charset=utf-8");
|
|
110
|
+
send(`<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="color-scheme" content="dark light"><title>Farm.js DevTools</title><link rel="stylesheet" href="${DEVTOOLS_PATH}/assets/panel.css"></head><body><div id="farm-devtools" data-inspect="${options.inspect}" data-shortcut="${escapeAttribute(options.shortcut || "")}"></div><script type="module" src="${DEVTOOLS_PATH}/assets/panel.js"></script></body></html>`, "text/html; charset=utf-8");
|
|
86
111
|
return;
|
|
87
112
|
}
|
|
88
113
|
if (url.pathname === `${DEVTOOLS_PATH}/modules.json` && options.inspect) {
|
|
@@ -101,13 +126,11 @@ export function installDevtoolsServer(server, options) {
|
|
|
101
126
|
? "text/css; charset=utf-8"
|
|
102
127
|
: name === "logo.svg"
|
|
103
128
|
? "image/svg+xml"
|
|
104
|
-
: /^[a-zA-Z0-9_-]+\.woff2$/.test(name)
|
|
129
|
+
: /^[a-zA-Z0-9_-]+\.woff2$/.test(name) && (await isShippedFont(name))
|
|
105
130
|
? "font/woff2"
|
|
106
131
|
: undefined;
|
|
107
132
|
if (type) {
|
|
108
|
-
|
|
109
|
-
assets.set(name, readFile(new URL(name, assetRoot)));
|
|
110
|
-
send(await assets.get(name), type);
|
|
133
|
+
send(await readAsset(name), type);
|
|
111
134
|
return;
|
|
112
135
|
}
|
|
113
136
|
}
|
package/dist/ui/panel.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var Y="/__farm/devtools";var
|
|
2
|
-
`?1:0}function
|
|
3
|
-
`;if(
|
|
4
|
-
`,
|
|
5
|
-
`?
|
|
6
|
-
`)){let
|
|
7
|
-
`);for(let
|
|
8
|
-
`)}function
|
|
9
|
-
`),
|
|
10
|
-
`);return`<section class="fd-code-pane" aria-label="${c(a)}"><div class="fd-code-title"><span class="fd-label">${c(a)}</span><button type="button" class="fd-link-button" data-copy="${c(u)}" aria-label="Copy ${c(a)}">${k("copy")}<span class="fd-button-label">Copy</span></button></div><pre class="fd-source"><code>${Ue(l)}</code></pre>${v.length>1500?'<p class="fd-subtitle">Showing the first 1,500 lines. Copy includes the full bounded source.</p>':""}</section>`}function y(t,a){return`<div class="fd-property"><dt>${c(t)}</dt><dd>${c(a)}</dd></div>`}function O(t,a,u=""){return`<div class="fd-page-heading"><div><h2>${c(t)}</h2><p class="fd-subtitle">${c(a)}</p></div>${u?`<span class="fd-tag">${c(u)}</span>`:""}</div>`}function Ge(t){let a=t.ownerDocument.defaultView,u=t.ownerDocument,v=[["overview","Overview","overview"],["routes","Routes","route"],["api","API","api"],["systems","Systems","layers"],["runtime","Runtime","runtime"],...t.dataset.inspect==="true"?[["inspect","Inspect","search"]]:[],["diagnostics","Diagnostics","activity"],["raw","Snapshot","terminal"]],l=v.some(([e])=>e===a.location.hash.slice(1))?a.location.hash.slice(1):"overview",r,g=0,w=0,S="",A=[],M=0,p=0,$=!1,N,L,I=new Map,T="system";try{let e=a.localStorage.getItem("farm:devtools:theme");(e==="light"||e==="dark")&&(T=e)}catch{}let j=a.matchMedia("(prefers-color-scheme: dark)"),P=()=>T==="dark"||T==="system"&&j.matches,R=()=>{t.dataset.theme=T,t.style.colorScheme=T==="light"||T==="dark"?T:"light dark";let e=t.querySelector("[data-theme-toggle]");if(e){let o=P()?"Switch to light theme":"Switch to dark theme";e.innerHTML=k(P()?"sun":"moon"),e.setAttribute("aria-label",o),e.title=o}};R(),t.innerHTML=`<header class="fd-header"><img class="fd-logo" src="${Y}/assets/logo.svg" alt="Farm.js logo"><span class="fd-brand">FARM.JS</span><span class="fd-muted">/</span><span>DevTools</span><div class="fd-header-actions"><button type="button" class="fd-icon-button" data-refresh aria-label="Refresh DevTools">${k("refresh")}</button><button type="button" class="fd-icon-button" data-theme-toggle aria-label="Switch theme"></button><button type="button" class="fd-icon-button" data-close aria-label="Close DevTools">${k("close")}</button></div></header><div class="fd-error" role="alert" data-error hidden></div><div class="fd-body"><nav class="fd-sidebar" aria-label="DevTools navigation"><div class="fd-label fd-group-label">WORKSPACE</div>${v.map(([e,o,d])=>`<button type="button" class="fd-nav-button" data-view="${e}">${k(d)}<span class="fd-button-label">${o}</span><span class="fd-count" data-count="${e}"></span></button>`).join("")}</nav><main class="fd-main" data-main></main></div><footer class="fd-footer"><span class="fd-footer-label">Development only</span><div class="fd-footer-status"><span data-status role="status">Loading workspace\u2026</span><span data-feedback role="status"></span></div><span class="fd-footer-label">Esc to close</span></footer>`;let m=t.querySelector("[data-main]"),z=t.querySelector("[data-status]"),K=t.querySelector("[data-feedback]"),H=t.querySelector("[data-error]"),x=e=>`<div class="fd-empty">${c(e)}</div>`,U=e=>`<code>${c(e)}</code>`,X=e=>e?`${e.runtime}${e.regions?.length?" \xB7 "+e.regions.join(", "):""}${e.maxDuration?" \xB7 "+e.maxDuration+"s":""}`:"Inherited",i=()=>{a.parent!==a?a.parent.postMessage({type:"farm:devtools:close"},a.location.origin):a.location.assign("/")};function n(e){v.some(([o])=>o===e)&&(l=e,a.history.replaceState(null,"",`#${l}`),_())}async function s(e,o){let d=await a.fetch(e,{cache:"no-store",credentials:"same-origin",signal:o});if(!d.ok){let f=await d.json().catch(()=>null);throw new Error(typeof f?.error=="string"?f.error:`DevTools request failed (${d.status}).`)}return d.json()}async function F(){let e=++M;N?.abort(),N=new AbortController,t.setAttribute("aria-busy","true"),z.textContent="Refreshing workspace\u2026",H.hidden=!0,r||(m.innerHTML=x("Loading the current Farm workspace\u2026"));try{let o=await s(`${Y}.json`,N.signal);if($||e!==M)return;if(!o.project||!o.counts||!Array.isArray(o.routes))throw new Error("Unexpected DevTools snapshot. Check that core and the plugin are up to date.");r=o,g=Math.min(g,Math.max(0,o.routes.length-1)),w=Math.min(w,Math.max(0,o.apiRoutes.length-1)),z.textContent=`${o.project.name} \xB7 Updated ${new Date(o.generatedAt).toLocaleTimeString()}`,_()}catch(o){if($||e!==M)return;H.textContent=o.message,H.hidden=!1,z.textContent=r?"Showing the last snapshot":"Workspace unavailable",r||(m.innerHTML=x("Use Refresh to reconnect to the development server."))}finally{e===M&&t.removeAttribute("aria-busy")}}function b(){return r.diagnostics.map(e=>`<article class="fd-diagnostic" data-severity="${c(e.severity)}"><span class="${e.severity==="error"?"fd-danger":"fd-amber"}">${k("activity")}</span><div><div class="fd-diagnostic-head"><h3>${c(e.title)}</h3><span class="fd-tag" data-tone="${e.severity==="error"?"bad":e.severity==="warning"?"warn":"info"}">${c(e.severity)}</span></div><div class="fd-label">${c(e.code)}</div><p>${c(e.message)}</p>${e.action?`<p class="fd-diagnostic-action">${c(e.action)}</p>`:""}</div></article>`).join("")||`<div class="fd-diagnostic" data-severity="ok"><span class="fd-green">${k("shield")}</span><div><h3>Framework checks passed</h3><p>No runtime configuration diagnostics in this snapshot.</p></div></div>`}function Q(){let e=r;m.innerHTML=O("Overview",`${e.project.name} \xB7 ${e.project.srcDir}`,"Development")+`<div class="fd-stats">${[["Pages",e.counts.pages,"route"],["API routes",e.counts.apiRoutes,"api"],["Integrations",e.counts.integrations,"blocks"]].map(([o,d,f])=>`<div class="fd-stat"><span class="fd-label">${k(f)}${o}</span><span class="fd-stat-value">${d}</span></div>`).join("")}</div><section class="fd-section"><div class="fd-section-heading"><h3>Application routes</h3><button type="button" class="fd-link-button" data-go="routes"><span class="fd-button-label">View all routes</span>${k("external")}</button></div><div class="fd-route-preview">${e.routes.map((o,d)=>({route:o,index:d})).filter(({route:o})=>o.kind==="page").slice(0,5).map(({route:o,index:d})=>`<button type="button" class="fd-preview-row" data-route="${d}">${U(o.pattern)}<span class="fd-preview-meta">${c(X(o.runtime))}</span>${k("chevron")}</button>`).join("")||x("No page routes discovered.")}</div></section><section class="fd-section"><div class="fd-section-heading"><h3>Diagnostics</h3><button type="button" class="fd-link-button" data-go="diagnostics"><span class="fd-button-label">${e.counts.diagnostics} ${e.counts.diagnostics===1?"notice":"notices"}</span>${k("external")}</button></div>${b()}</section>`,m.querySelectorAll("[data-route]").forEach(o=>o.onclick=()=>{g=Number(o.dataset.route),n("routes")})}function E(e){let o=r;m.innerHTML=O(e?"API":"Routes",e?"Registered methods and effective server runtime controls.":"Pages, layouts, loading states, and error boundaries.")+`<div class="fd-filter-row"><label class="fd-search">${k("search")}<input type="search" aria-label="${e?"Filter APIs":"Filter routes"}" placeholder="Filter by path, ${e?"method":"kind"}, or source\u2026" data-filter><kbd>/</kbd></label></div><div class="fd-browser"><div class="fd-list" data-list></div><section class="fd-detail" data-detail aria-label="Selected ${e?"API":"route"}"></section></div>`;let d=e?o.apiRoutes.map((C,h)=>({index:h,path:C.path,kind:C.methods.join(" / "),file:C.filePath})):o.routes.map((C,h)=>({index:h,path:C.pattern,kind:C.kind,file:C.filePath})),f=m.querySelector("[data-filter]"),D=m.querySelector("[data-list]");function B(){let C=e?w:g,h=d[C],ge=m.querySelector("[data-detail]");if(!h){ge.innerHTML=x("Nothing selected.");return}let ee=e?o.apiRoutes[C]:o.routes[C];ge.innerHTML=`<div class="fd-detail-title">${k(e?"api":"route")}${U(h.path)}</div><dl class="fd-properties">${y("Source",h.file)}${y(e?"Methods":"Kind",h.kind)}${y("Runtime",X(ee.runtime))}${y("Regions",ee.runtime?.regions?.join(", ")||"Not overridden")}${y("Max duration",ee.runtime?.maxDuration?`${ee.runtime.maxDuration}s`:"Not overridden")}</dl><div class="fd-detail-sub"><button class="fd-link-button" type="button" data-copy="route-source">${k("copy")}<span class="fd-button-label">Copy source path</span></button></div>${e?'<p class="fd-subtitle">Read-only metadata. Inspecting an endpoint does not send a request.</p>':""}`,I.set("route-source",h.file),D.querySelectorAll("button").forEach(he=>he.setAttribute("aria-pressed",String(Number(he.dataset.select)===C)))}function ue(){let C=f.value.toLowerCase();D.innerHTML=d.filter(h=>(h.path+" "+h.kind+" "+h.file).toLowerCase().includes(C)).map(h=>`<button type="button" class="fd-list-button" data-select="${h.index}" aria-pressed="${h.index===(e?w:g)}">${U(h.path)}<span class="fd-preview-meta">${c(h.kind)}</span></button>`).join("")||x("No matches. Try another path, kind, or source."),D.querySelectorAll("button").forEach(h=>h.onclick=()=>{e?w=Number(h.dataset.select):g=Number(h.dataset.select),B()})}f.oninput=ue,ue(),B()}function ne(){let e=r;m.innerHTML=O("Systems","Configured integrations, middleware, and storage.")+`<section class="fd-section fd-flush-top"><div class="fd-section-heading"><h3>Integrations</h3><span class="fd-label">${e.integrations.length} REGISTERED</span></div>${e.integrations.map(o=>`<details><summary>${c(o.key)} <span class="fd-muted">/ ${c(o.type)}</span></summary><dl class="fd-properties">${y("Category",o.category)}${y("Runtime",o.serverRuntime?"Server":"Platform")}${y("Middleware",String(o.middlewareCount))}${y("Providers",String(o.providerCount))}${y("Schema models",String(o.schemaModelCount))}</dl>${o.routes.map(d=>`<div class="fd-tree-item">${U(d.methods.join(" / ")+" "+d.path)}</div>`).join("")}</details>`).join("")||x("No integrations configured.")}</section><section class="fd-section"><h3>Request middleware</h3>${e.middleware.map(o=>`<div class="fd-system-row">${k("shield")}<div>${U(o.path)}<p>${c(o.filePath||o.source)}</p></div><span class="fd-tag">${o.handlerCount} ${o.handlerCount===1?"handler":"handlers"}</span></div>`).join("")||x("No request middleware configured.")}</section><section class="fd-section"><h3>KV mounts</h3>${e.storage.map(o=>`<div class="fd-system-row">${k("database")}<div>${U(o.mount)}<p>${c(o.driver)}</p></div><span class="fd-tag">${o.default?"Default":"Configured"}</span></div>`).join("")||x("No storage mounts.")}</section>`}function ie(){let e=r;m.innerHTML=O("Runtime","Resolved deployment, schedules, layers, and environment.","Read only")+`<section class="fd-section fd-flush-top"><div class="fd-runtime-grid"><dl class="fd-properties">${y("Target",e.deployment.target)}${y("Nitro preset",e.deployment.preset)}${y("Output",e.deployment.outputDir||"Default")}</dl><dl class="fd-properties">${y("Project",e.project.name)}${y("Source",e.project.srcDir)}${y("Base path",e.project.basePath||"/")}</dl></div></section><section class="fd-section"><div class="fd-section-heading"><h3>Environment</h3><span class="fd-label">KEY NAMES ONLY</span></div><dl class="fd-properties">${y("Server",e.environment.server.join(", ")||"None declared")}${y("Public",e.environment.public.join(", ")||"None declared")}</dl><p class="fd-subtitle">Values and credentials are never included.</p></section><section class="fd-section"><h3>Schedules</h3>${e.cron.map(o=>`<div class="fd-system-row">${k("clock")}<div>${U(o.name)}<p>${c(o.path)}</p></div><span class="fd-mono">${c(o.schedule.join(" / "))} UTC</span></div>`).join("")||x("No cron schedules configured.")}<details><summary>Workflows (${e.workflows.length})</summary>${e.workflows.map(o=>`<div class="fd-tree-item">${U(o.id)} ${U(o.routePath)}</div>`).join("")||x("No workflows discovered.")}</details><details><summary>Layers (${e.layers.length})</summary>${e.layers.map(o=>`<div class="fd-tree-item">${U(o.name)} ${U(o.source)}</div>`).join("")||x("No layers configured.")}</details><details><summary>Framework features</summary><dl class="fd-properties">${Object.entries(e.features).map(([o,d])=>y(o,d?"On":"Off")).join("")}</dl></details></section>`}async function Z(){let e=++p;L?.abort(),L=new AbortController;let o=L.signal;m.innerHTML=O("Inspect","Browser source and the JavaScript Vite actually served.","Read only")+`<div class="fd-inspect-toolbar"><label class="fd-label" for="module-select">MODULE</label><select id="module-select" disabled><option>Loading browser modules\u2026</option></select></div><div data-inspected>${x("Loading module graph\u2026")}</div>`;let d=m.querySelector("[data-inspected]"),f=m.querySelector("select");try{let D=await s(`${Y}/modules.json`,o);if($||e!==p||l!=="inspect")return;if(A=D.modules,!A.length){f.replaceChildren(new Option("No browser modules yet","")),d.innerHTML=x("Visit an app page, then refresh DevTools. Only transformed browser modules inside this project are listed.");return}f.replaceChildren(...A.map(B=>new Option(B.path+(B.url.includes("?")?" "+B.url.slice(B.url.indexOf("?")):""),B.id))),f.disabled=!1,A.some(B=>B.id===S)||(S=A[0].id),f.value=S,f.onchange=()=>{S=f.value,W(S)},D.limited&&(K.textContent="Inspect lists the first 500 browser modules."),await W(S)}catch(D){if($||e!==p||l!=="inspect")return;d.innerHTML=x(D.message),f.replaceChildren(new Option("Module graph unavailable",""))}}async function W(e){let o=++p;L?.abort(),L=new AbortController;let d=m.querySelector("[data-inspected]");d.innerHTML=x("Reading module\u2026");try{let f=await s(`${Y}/module.json?id=${encodeURIComponent(e)}`,L.signal);if($||o!==p||l!=="inspect")return;I.set("module-source",f.source),I.set("module-output",f.transformed),d.innerHTML=`<div class="fd-pipeline"><span class="fd-label">SOURCE \u2192 VITE OUTPUT</span><p class="fd-subtitle">Current file on disk and the latest cached browser transform. Refresh the app after edits.</p></div><div class="fd-comparison">${se(f.source,"Source","module-source")}${se(f.transformed,"Served JavaScript","module-output")}</div><section class="fd-section"><details><summary>Imports (${f.imports.length})</summary>${f.imports.map(D=>`<div class="fd-tree-item">${U(D)}</div>`).join("")||x("No imports.")}</details><details><summary>Importers (${f.importers.length})</summary>${f.importers.map(D=>`<div class="fd-tree-item">${U(D)}</div>`).join("")||x("No importers.")}</details></section>`}catch(f){if($||o!==p||l!=="inspect")return;d.innerHTML=x(f.message)}}function _(){if(!r)return;L?.abort(),++p,I.clear(),K.textContent="",t.querySelectorAll("[data-view]").forEach(o=>{o.dataset.view===l?o.setAttribute("aria-current","page"):o.removeAttribute("aria-current")});let e={routes:r.routes.length,api:r.apiRoutes.length,diagnostics:r.diagnostics.length};switch(t.querySelectorAll("[data-count]").forEach(o=>o.textContent=e[o.dataset.count]===void 0?"":String(e[o.dataset.count])),l){case"overview":Q();break;case"routes":E(!1);break;case"api":E(!0);break;case"systems":ne();break;case"runtime":ie();break;case"diagnostics":m.innerHTML=O("Diagnostics","The same runtime checks used by farm doctor.")+`<section class="fd-section fd-flush-top">${b()}</section>`;break;case"raw":{let o=JSON.stringify(r,null,2);I.set("snapshot",o),m.innerHTML=O("Snapshot","Machine-readable workspace data. Environment values are excluded.")+se(o,"Runtime JSON","snapshot");break}case"inspect":Z();break}m.querySelectorAll("[data-go]").forEach(o=>o.onclick=()=>n(o.dataset.go))}let J=async e=>{let o=e.target.closest("[data-copy]");if(!o)return;let d=I.get(o.dataset.copy);if(d!==void 0)try{await a.navigator.clipboard.writeText(d),K.textContent="Copied to clipboard"}catch{K.textContent="Copy was blocked. Select the code and copy it manually."}},V=e=>{if(e.key==="Escape"){e.preventDefault(),i();return}if(e.key==="/"&&!["INPUT","SELECT","TEXTAREA"].includes(e.target.tagName)){let o=m.querySelector("[data-filter]");if(o){e.preventDefault(),o.focus();return}}if(e.key==="Tab"){let o=[...t.querySelectorAll("button,input,select,summary,a[href]")].filter(d=>!d.hasAttribute("disabled")&&d.getClientRects().length);e.shiftKey&&u.activeElement===o[0]?(e.preventDefault(),o.at(-1)?.focus()):!e.shiftKey&&u.activeElement===o.at(-1)&&(e.preventDefault(),o[0]?.focus())}a.parent!==a&&a.parent.postMessage({type:"farm:devtools:keydown",event:{key:e.key,code:e.code,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,repeat:e.repeat}},a.location.origin)};return t.querySelectorAll("[data-view]").forEach(e=>e.onclick=()=>n(e.dataset.view)),t.querySelector("[data-close]").onclick=i,t.querySelector("[data-refresh]").onclick=()=>{F()},t.querySelector("[data-theme-toggle]").onclick=()=>{T=P()?"light":"dark",R();try{a.localStorage.setItem("farm:devtools:theme",T)}catch{}K.textContent=T+" theme"},R(),j.addEventListener("change",R),t.addEventListener("click",J),u.addEventListener("keydown",V),t.querySelector("[data-close]").focus(),F(),{dispose(){$=!0,N?.abort(),L?.abort(),t.removeEventListener("click",J),u.removeEventListener("keydown",V),j.removeEventListener("change",R)}}}var Me=document.getElementById("farm-devtools");Me&&Ge(Me);export{Ge as startPanel};
|
|
1
|
+
var Y="/__farm/devtools";var ce=new Set(["<",">","{","}","[","]"]),Se=new Set(["for","do","while","if","else","return","function","var","let","const","true","false","undefined","this","new","delete","typeof","in","instanceof","void","break","continue","switch","case","default","throw","try","catch","finally","debugger","with","yield","async","await","class","extends","super","import","export","from","static"]),ye=new Set(["+","-","*","/","%","=","!","&","|","^","~","!","?",":",".",",",";","'",'"',".","(",")","[","]","#","@","\\",...ce]),Ce={keywords:Se,onCommentStart:Ue,onCommentEnd:Re},se=["identifier","keyword","string","class","property","entity","jsxliterals","sign","comment","break","space"],[le,Le,G,Ae,fe,Fe,De,q,be,pe,xe]=se.map((t,a)=>a);function ae(t){return/^[^\S\r\n]+$/g.test(t)}function je(t){return ye.has(t)}function He(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ne(t){return/^[\w_]+$/.test(t)||we(t)}function _e(t){let a=t[0];return ne(a)&&a===a.toUpperCase()||t==="null"}function we(t){return/[^\u0000-\u007f]/.test(t)}function ke(t){return/^[a-zA-Z]$/.test(t)}function $e(t){return ke(t)||we(t)}function re(t){return $e(t[0])&&(t.length===1||ne(t.slice(1)))}function me(t){return t==="`"}function ue(t){return t==='"'||t==="'"}function Be(t){return ue(t)||me(t)}function Ue(t,a){let l=t+a;return l==="/*"?2:l==="//"?1:0}function Re(t,a){return t+a==="*/"?2:a===`
|
|
2
|
+
`?1:0}function Ne(t){return t[0]==="/"&&!Ue(t[0],t[1])}function Ie(t,a){let{keywords:l,onCommentStart:x,onCommentEnd:p}={...Ce,...a},s="",c=-1,h=[-1,""],E=[-2,""],T=[],w=!1,d=0,U=!1,D=0,I=()=>w&&!U&&!d,B=()=>d&&!I(),j=()=>!d&&I()&&!U&&D>0,M=null,z=!1,P=0,H=0,v=()=>M!==null,Q=()=>z,A=()=>H>P,W=()=>H>0&&H===P,g=()=>v()||A();function S(i){let r=i===`
|
|
3
|
+
`;if(B()){if(v())return G;let[,y]=h;if(re(i)&&(y==="<"||y==="</"))return Fe}if(j())return De;if(v()||A())return G;if(l.has(i))return h[1]==="."?le:Le;if(r)return pe;if(ae(i))return xe;if(i.split("").every(je))return q;if(_e(i))return B()?le:Ae;if(re(i)){let y=h[1]==="."&&re(E[1]);if(!g()&&!y)return le;if(y)return fe}return G}let n=(i,r)=>{if(r&&(s=r),s){c=i||S(s);let F=[c,s];c!==xe&&c!==pe&&(E=h,h=F),T.push(F)}s=""};for(let i=0;i<t.length;i++){let r=t[i],F=t[i-1],y=t[i+1],J=F+r,C=r+y;if(ue(r)&&!j()&&!A()){n(),F!=="\\"&&(M&&r===M?M=null:M||(M=r)),n(G,r);continue}if(!A()&&F!=="\\n"&&me(r)){n(),n(G,r),H++;continue}if(A()){if(F!=="\\n"&&me(r)&&H>0){n(),H--,n(G,r);continue}if(C==="${"){P++,n(G),n(q,C),i++;continue}}if(W()&&r==="}"){n(),P--,n(q,r);continue}if(I()&&r==="{"){n(),n(q,r),U=!0;continue}if(w){if(!d&&r==="<"){n(),y==="/"?(d=2,s=C,i++):(d=1,s=r),n(q);continue}if(d){if(r===">"&&!"/=".includes(F)){n(),d===1?(d=0,D++):(d=0,w=!1),n(q,r);continue}if(C==="/>"||C==="</"){s!=="<"&&s!=="/"&&n(),C==="/>"?d=0:D--,D||(w=!1),s=C,i++,n(q);continue}if(r==="<"){n(),s=r,n(q);continue}if(y==="-"&&!g()&&!j()&&s){n(fe,s+r+y),i++;continue}if(y==="="&&!g()&&!ae(r)){ae(s)&&n();let R=s+r;if(re(R)){n(fe,R);continue}}}}!d&&(r==="<"&&$e(y)||C==="</")&&(d=y==="/"?2:1,r==="<"&&(y==="/"||ke(y))&&!g()&&!j()&&!Q()&&(w=!0));let X=Be(r),de=A(),Z=!w&&Ne(C),ee=j();if(X||de||ue(M))s+=r;else if(Z){n();let[R,K]=h;if(Z&&R!==-1&&!(R===q&&K!==")"||R===be)){s=r,n();continue}z=!0;let V=i++,te=()=>i>=t.length,e=()=>te()||t[i]===`
|
|
4
|
+
`,o=!1;for(;!e();i++)if(t[i]==="/"&&t[i-1]!=="\\"){for(o=!0;V!==i&&/^[a-z]$/.test(t[i+1])&&!e();)i++;break}z=!1,V!==i&&o?(s=t.slice(V,i+1),n(G)):(s=r,n(),i=V)}else if(x(r,y)){n();let R=i,K=x(r,y);if(K)for(;i<t.length&&p(t[i-1],t[i])!=K;i++);s=t.slice(R,i+1),n(be)}else r===" "||r===`
|
|
5
|
+
`?r===" "&&(ae(s)||!s||ee)?(s+=r,y==="<"&&n()):(n(),s=r,n()):U&&r==="}"?(n(),s=r,n(),U=!1):ee&&!ce.has(r)||A()||(ne(r)===ne(s[s.length-1])||I())&&!ye.has(r)?s+=r:(J==="</"&&(s=J),n(),J!=="</"&&(s=r),C==="</"||C==="/>"?(s=C,n(),i++):ce.has(r)&&n())}return n(),T}function qe(t){let a=[],l=c=>({type:"element",tagName:"span",children:c,properties:{className:"sh__line"}});function x(c){let h=c.map(([E,T])=>{let w=se[E];return{type:"element",tagName:"span",children:[{type:"text",value:T}],properties:{className:`sh__token--${w}`,style:{color:`var(--sh-${w})`}}}});a.push(l(h))}let p=[],s=!1;for(let c=0;c<t.length;c++){let h=t[c],[E,T]=h,w=c===t.length-1;if(E!==pe){if(T.includes(`
|
|
6
|
+
`)){let d=T.split(`
|
|
7
|
+
`);for(let U=0;U<d.length;U++)p.push([E,d[U]]),U<d.length-1&&(x(p),p.length=0)}else p.push(h);s=!1}else s?x([]):(x(p),p.length=0),w&&x([]),s=!0}return p.length&&x(p),a}var Pe=t=>{let a=`class="${t.className}"`;if(t.style){let l=Object.entries(t.style).map(([x,p])=>`${x}:${p}`).join(";");a+=` style="${l}"`}return a};function Ve(t){return t.map(a=>{let{tagName:l}=a,x=a.children.map(p=>{let{tagName:s,children:c,properties:h}=p;return`<${s} ${Pe(h)}>${He(c[0].value)}</${s}>`}).join("");return`<${l} class="${a.properties.className}">${x}</${l}>`}).join(`
|
|
8
|
+
`)}function Me(t,a){let l=Ie(t,a),x=qe(l);return Ve(x)}var Ze={TokenTypes:se,TokenMap:new Map(se.map((t,a)=>[t,a]))};var Ge={activity:'<path d="M22 12h-4l-3 9L9 3l-3 9H2"/>',api:'<path d="M8 3H7a2 2 0 0 0-2 2v4a2 2 0 0 1-2 2 2 2 0 0 1 2 2v4a2 2 0 0 0 2 2h1"/><path d="M16 3h1a2 2 0 0 1 2 2v4a2 2 0 0 0 2 2 2 2 0 0 0-2 2v4a2 2 0 0 1-2 2h-1"/>',app:'<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',blocks:'<rect width="7" height="7" x="3" y="3"/><rect width="7" height="7" x="14" y="3"/><rect width="7" height="7" x="14" y="14"/><rect width="7" height="7" x="3" y="14"/>',book:'<path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>',clock:'<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>',chevron:'<path d="m9 18 6-6-6-6"/>',close:'<path d="M18 6 6 18M6 6l12 12"/>',copy:'<rect width="14" height="14" x="8" y="8"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>',database:'<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M3 5v14c0 1.7 4 3 9 3s9-1.3 9-3V5"/><path d="M3 12c0 1.7 4 3 9 3s9-1.3 9-3"/>',external:'<path d="M15 3h6v6"/><path d="M10 14 21 3"/><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>',layers:'<path d="m12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z"/><path d="m22 12.5-9.17 4.17a2 2 0 0 1-1.66 0L2 12.5"/><path d="m22 17.5-9.17 4.17a2 2 0 0 1-1.66 0L2 17.5"/>',overview:'<rect width="7" height="9" x="3" y="3"/><rect width="7" height="5" x="14" y="3"/><rect width="7" height="9" x="14" y="12"/><rect width="7" height="5" x="3" y="16"/>',refresh:'<path d="M20 11a8.1 8.1 0 0 0-15.5-2M4 4v5h5"/><path d="M4 13a8.1 8.1 0 0 0 15.5 2M20 20v-5h-5"/>',route:'<circle cx="6" cy="19" r="3"/><path d="M9 19h5.5a3.5 3.5 0 0 0 0-7h-5a3.5 3.5 0 0 1 0-7H18"/><circle cx="18" cy="5" r="3"/>',runtime:'<rect width="20" height="14" x="2" y="3"/><line x1="8" x2="16" y1="21" y2="21"/><line x1="12" x2="12" y1="17" y2="21"/>',search:'<circle cx="11" cy="11" r="8"/><path d="m21 21-4.3-4.3"/>',sun:'<circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M2 12h2m16 0h2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42"/>',moon:'<path d="M20.9 13A9 9 0 0 1 11 3.1 9 9 0 1 0 20.9 13Z"/>',shield:'<path d="M20 13c0 5-3.5 7.5-8 9-4.5-1.5-8-4-8-9V5l8-3 8 3z"/><path d="m9 12 2 2 4-4"/>',terminal:'<polyline points="4 17 10 11 4 5"/><line x1="12" x2="20" y1="19" y2="19"/>'};function $(t,a=""){return`<svg class="icon ${a}" data-lucide="${t}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${Ge[t]}</svg>`}function u(t){return String(t??"").replace(/[&<>"']/g,a=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[a])}function ie(t,a,l){let x=t.split(`
|
|
9
|
+
`),p=x.slice(0,1500).join(`
|
|
10
|
+
`);return`<section class="fd-code-pane" aria-label="${u(a)}"><div class="fd-code-title"><span class="fd-label">${u(a)}</span><button type="button" class="fd-link-button" data-copy="${u(l)}" aria-label="Copy ${u(a)}">${$("copy")}<span class="fd-button-label">Copy</span></button></div><pre class="fd-source"><code>${Me(p)}</code></pre>${x.length>1500?'<p class="fd-subtitle">Showing the first 1,500 lines. Copy includes the full bounded source.</p>':""}</section>`}function Te(t,a){let l=t.toLowerCase().split("+").map(d=>d.trim()).filter(Boolean),x=["alt","ctrl","control","meta","cmd","command","mod","shift"],p=l.find(d=>!x.includes(d));if(!p)return()=>!1;let s=l.includes("mod"),c=l.includes("alt"),h=l.includes("shift"),E=l.includes("ctrl")||l.includes("control")||s&&!a,T=l.includes("meta")||l.includes("cmd")||l.includes("command")||s&&a,w=p==="."||p==="period"?"Period":p===","||p==="comma"?"Comma":p==="/"||p==="slash"?"Slash":void 0;return d=>!d.repeat&&d.altKey===c&&d.ctrlKey===E&&d.metaKey===T&&d.shiftKey===h&&(w?d.code===w:String(d.key||"").toLowerCase()===p)}function k(t,a){return`<div class="fd-property"><dt>${u(t)}</dt><dd>${u(a)}</dd></div>`}function O(t,a,l=""){return`<div class="fd-page-heading"><div><h2>${u(t)}</h2><p class="fd-subtitle">${u(a)}</p></div>${l?`<span class="fd-tag">${u(l)}</span>`:""}</div>`}function Oe(t){let a=t.ownerDocument.defaultView,l=t.ownerDocument,x=Te(t.dataset.shortcut??"",/Mac|iPhone|iPad|iPod/.test(a.navigator.platform)),p=[["overview","Overview","overview"],["routes","Routes","route"],["api","API","api"],["systems","Systems","layers"],["runtime","Runtime","runtime"],...t.dataset.inspect==="true"?[["inspect","Inspect","search"]]:[],["diagnostics","Diagnostics","activity"],["raw","Snapshot","terminal"]],s=p.some(([e])=>e===a.location.hash.slice(1))?a.location.hash.slice(1):"overview",c,h=0,E=0,T="",w=[],d=0,U=0,D=!1,I,B,j=new Map,M="system";try{let e=a.localStorage.getItem("farm:devtools:theme");(e==="light"||e==="dark")&&(M=e)}catch{}let z=a.matchMedia("(prefers-color-scheme: dark)"),P=()=>M==="dark"||M==="system"&&z.matches,H=()=>{t.dataset.theme=M,t.style.colorScheme=M==="light"||M==="dark"?M:"light dark";let e=t.querySelector("[data-theme-toggle]");if(e){let o=P()?"Switch to light theme":"Switch to dark theme";e.innerHTML=$(P()?"sun":"moon"),e.setAttribute("aria-label",o),e.title=o}};H(),t.innerHTML=`<header class="fd-header"><img class="fd-logo" src="${Y}/assets/logo.svg" alt="Farm.js logo"><span class="fd-brand">FARM.JS</span><span class="fd-muted">/</span><span>DevTools</span><div class="fd-header-actions"><button type="button" class="fd-icon-button" data-refresh aria-label="Refresh DevTools">${$("refresh")}</button><button type="button" class="fd-icon-button" data-theme-toggle aria-label="Switch theme"></button><button type="button" class="fd-icon-button" data-close aria-label="Close DevTools">${$("close")}</button></div></header><div class="fd-error" role="alert" data-error hidden></div><div class="fd-body"><nav class="fd-sidebar" aria-label="DevTools navigation"><div class="fd-label fd-group-label">WORKSPACE</div>${p.map(([e,o,f])=>`<button type="button" class="fd-nav-button" data-view="${e}">${$(f)}<span class="fd-button-label">${o}</span><span class="fd-count" data-count="${e}"></span></button>`).join("")}</nav><main class="fd-main" data-main></main></div><footer class="fd-footer"><span class="fd-footer-label">Development only</span><div class="fd-footer-status"><span data-status role="status">Loading workspace\u2026</span><span data-feedback role="status"></span></div><span class="fd-footer-label">Esc to close</span></footer>`;let v=t.querySelector("[data-main]"),Q=t.querySelector("[data-status]"),A=t.querySelector("[data-feedback]"),W=t.querySelector("[data-error]"),g=e=>`<div class="fd-empty">${u(e)}</div>`,S=e=>`<code>${u(e)}</code>`,n=e=>e?`${e.runtime}${e.regions?.length?" \xB7 "+e.regions.join(", "):""}${e.maxDuration?" \xB7 "+e.maxDuration+"s":""}`:"Inherited",i=()=>{a.parent!==a?a.parent.postMessage({type:"farm:devtools:close"},a.location.origin):a.location.assign("/")};function r(e){p.some(([o])=>o===e)&&(s=e,a.history.replaceState(null,"",`#${s}`),K())}async function F(e,o){let f=await a.fetch(e,{cache:"no-store",credentials:"same-origin",signal:o});if(!f.ok){let m=await f.json().catch(()=>null);throw new Error(typeof m?.error=="string"?m.error:`DevTools request failed (${f.status}).`)}return f.json()}async function y(){let e=++d;I?.abort(),I=new AbortController,t.setAttribute("aria-busy","true"),Q.textContent="Refreshing workspace\u2026",W.hidden=!0,c||(v.innerHTML=g("Loading the current Farm workspace\u2026"));try{let o=await F(`${Y}.json`,I.signal);if(D||e!==d)return;if(!o.project||!o.counts||!Array.isArray(o.routes))throw new Error("Unexpected DevTools snapshot. Check that core and the plugin are up to date.");c=o,h=Math.min(h,Math.max(0,o.routes.length-1)),E=Math.min(E,Math.max(0,o.apiRoutes.length-1)),Q.textContent=`${o.project.name} \xB7 Updated ${new Date(o.generatedAt).toLocaleTimeString()}`,K()}catch(o){if(D||e!==d)return;W.textContent=o.message,W.hidden=!1,Q.textContent=c?"Showing the last snapshot":"Workspace unavailable",c||(v.innerHTML=g("Use Refresh to reconnect to the development server."))}finally{e===d&&t.removeAttribute("aria-busy")}}function J(){return c.diagnostics.map(e=>`<article class="fd-diagnostic" data-severity="${u(e.severity)}"><span class="${e.severity==="error"?"fd-danger":"fd-amber"}">${$("activity")}</span><div><div class="fd-diagnostic-head"><h3>${u(e.title)}</h3><span class="fd-tag" data-tone="${e.severity==="error"?"bad":e.severity==="warning"?"warn":"info"}">${u(e.severity)}</span></div><div class="fd-label">${u(e.code)}</div><p>${u(e.message)}</p>${e.action?`<p class="fd-diagnostic-action">${u(e.action)}</p>`:""}</div></article>`).join("")||`<div class="fd-diagnostic" data-severity="ok"><span class="fd-green">${$("shield")}</span><div><h3>Framework checks passed</h3><p>No runtime configuration diagnostics in this snapshot.</p></div></div>`}function C(){let e=c;v.innerHTML=O("Overview",`${e.project.name} \xB7 ${e.project.srcDir}`,"Development")+`<div class="fd-stats">${[["Pages",e.counts.pages,"route"],["API routes",e.counts.apiRoutes,"api"],["Integrations",e.counts.integrations,"blocks"]].map(([o,f,m])=>`<div class="fd-stat"><span class="fd-label">${$(m)}${o}</span><span class="fd-stat-value">${f}</span></div>`).join("")}</div><section class="fd-section"><div class="fd-section-heading"><h3>Application routes</h3><button type="button" class="fd-link-button" data-go="routes"><span class="fd-button-label">View all routes</span>${$("external")}</button></div><div class="fd-route-preview">${e.routes.map((o,f)=>({route:o,index:f})).filter(({route:o})=>o.kind==="page").slice(0,5).map(({route:o,index:f})=>`<button type="button" class="fd-preview-row" data-route="${f}">${S(o.pattern)}<span class="fd-preview-meta">${u(n(o.runtime))}</span>${$("chevron")}</button>`).join("")||g("No page routes discovered.")}</div></section><section class="fd-section"><div class="fd-section-heading"><h3>Diagnostics</h3><button type="button" class="fd-link-button" data-go="diagnostics"><span class="fd-button-label">${e.counts.diagnostics} ${e.counts.diagnostics===1?"notice":"notices"}</span>${$("external")}</button></div>${J()}</section>`,v.querySelectorAll("[data-route]").forEach(o=>o.onclick=()=>{h=Number(o.dataset.route),r("routes")})}function X(e){let o=c;v.innerHTML=O(e?"API":"Routes",e?"Registered methods and effective server runtime controls.":"Pages, layouts, loading states, and error boundaries.")+`<div class="fd-filter-row"><label class="fd-search">${$("search")}<input type="search" aria-label="${e?"Filter APIs":"Filter routes"}" placeholder="Filter by path, ${e?"method":"kind"}, or source\u2026" data-filter><kbd>/</kbd></label></div><div class="fd-browser"><div class="fd-list" data-list></div><section class="fd-detail" data-detail aria-label="Selected ${e?"API":"route"}"></section></div>`;let f=e?o.apiRoutes.map((L,b)=>({index:b,path:L.path,kind:L.methods.join(" / "),file:L.filePath})):o.routes.map((L,b)=>({index:b,path:L.pattern,kind:L.kind,file:L.filePath})),m=v.querySelector("[data-filter]"),_=v.querySelector("[data-list]");function N(){let L=e?E:h,b=f[L],he=v.querySelector("[data-detail]");if(!b){he.innerHTML=g("Nothing selected.");return}let oe=e?o.apiRoutes[L]:o.routes[L];he.innerHTML=`<div class="fd-detail-title">${$(e?"api":"route")}${S(b.path)}</div><dl class="fd-properties">${k("Source",b.file)}${k(e?"Methods":"Kind",b.kind)}${k("Runtime",n(oe.runtime))}${k("Regions",oe.runtime?.regions?.join(", ")||"Not overridden")}${k("Max duration",oe.runtime?.maxDuration?`${oe.runtime.maxDuration}s`:"Not overridden")}</dl><div class="fd-detail-sub"><button class="fd-link-button" type="button" data-copy="route-source">${$("copy")}<span class="fd-button-label">Copy source path</span></button></div>${e?'<p class="fd-subtitle">Read-only metadata. Inspecting an endpoint does not send a request.</p>':""}`,j.set("route-source",b.file),_.querySelectorAll("button").forEach(ve=>ve.setAttribute("aria-pressed",String(Number(ve.dataset.select)===L)))}function ge(){let L=m.value.toLowerCase();_.innerHTML=f.filter(b=>(b.path+" "+b.kind+" "+b.file).toLowerCase().includes(L)).map(b=>`<button type="button" class="fd-list-button" data-select="${b.index}" aria-pressed="${b.index===(e?E:h)}">${S(b.path)}<span class="fd-preview-meta">${u(b.kind)}</span></button>`).join("")||g("No matches. Try another path, kind, or source."),_.querySelectorAll("button").forEach(b=>b.onclick=()=>{e?E=Number(b.dataset.select):h=Number(b.dataset.select),N()})}m.oninput=ge,ge(),N()}function de(){let e=c;v.innerHTML=O("Systems","Configured integrations, middleware, and storage.")+`<section class="fd-section fd-flush-top"><div class="fd-section-heading"><h3>Integrations</h3><span class="fd-label">${e.integrations.length} REGISTERED</span></div>${e.integrations.map(o=>`<details><summary>${u(o.key)} <span class="fd-muted">/ ${u(o.type)}</span></summary><dl class="fd-properties">${k("Category",o.category)}${k("Runtime",o.serverRuntime?"Server":"Platform")}${k("Middleware",String(o.middlewareCount))}${k("Providers",String(o.providerCount))}${k("Schema models",String(o.schemaModelCount))}</dl>${o.routes.map(f=>`<div class="fd-tree-item">${S(f.methods.join(" / ")+" "+f.path)}</div>`).join("")}</details>`).join("")||g("No integrations configured.")}</section><section class="fd-section"><h3>Request middleware</h3>${e.middleware.map(o=>`<div class="fd-system-row">${$("shield")}<div>${S(o.path)}<p>${u(o.filePath||o.source)}</p></div><span class="fd-tag">${o.handlerCount} ${o.handlerCount===1?"handler":"handlers"}</span></div>`).join("")||g("No request middleware configured.")}</section><section class="fd-section"><h3>KV mounts</h3>${e.storage.map(o=>`<div class="fd-system-row">${$("database")}<div>${S(o.mount)}<p>${u(o.driver)}</p></div><span class="fd-tag">${o.default?"Default":"Configured"}</span></div>`).join("")||g("No storage mounts.")}</section>`}function Z(){let e=c;v.innerHTML=O("Runtime","Resolved deployment, schedules, layers, and environment.","Read only")+`<section class="fd-section fd-flush-top"><div class="fd-runtime-grid"><dl class="fd-properties">${k("Target",e.deployment.target)}${k("Nitro preset",e.deployment.preset)}${k("Output",e.deployment.outputDir||"Default")}</dl><dl class="fd-properties">${k("Project",e.project.name)}${k("Source",e.project.srcDir)}${k("Base path",e.project.basePath||"/")}</dl></div></section><section class="fd-section"><div class="fd-section-heading"><h3>Environment</h3><span class="fd-label">KEY NAMES ONLY</span></div><dl class="fd-properties">${k("Server",e.environment.server.join(", ")||"None declared")}${k("Public",e.environment.public.join(", ")||"None declared")}</dl><p class="fd-subtitle">Values and credentials are never included.</p></section><section class="fd-section"><h3>Schedules</h3>${e.cron.map(o=>`<div class="fd-system-row">${$("clock")}<div>${S(o.name)}<p>${u(o.path)}</p></div><span class="fd-mono">${u(o.schedule.join(" / "))} UTC</span></div>`).join("")||g("No cron schedules configured.")}<details><summary>Workflows (${e.workflows.length})</summary>${e.workflows.map(o=>`<div class="fd-tree-item">${S(o.id)} ${S(o.routePath)}</div>`).join("")||g("No workflows discovered.")}</details><details><summary>Layers (${e.layers.length})</summary>${e.layers.map(o=>`<div class="fd-tree-item">${S(o.name)} ${S(o.source)}</div>`).join("")||g("No layers configured.")}</details><details><summary>Framework features</summary><dl class="fd-properties">${Object.entries(e.features).map(([o,f])=>k(o,f?"On":"Off")).join("")}</dl></details></section>`}async function ee(){let e=++U;B?.abort(),B=new AbortController;let o=B.signal;v.innerHTML=O("Inspect","Browser source and the JavaScript Vite actually served.","Read only")+`<div class="fd-inspect-toolbar"><label class="fd-label" for="module-select">MODULE</label><select id="module-select" disabled><option>Loading browser modules\u2026</option></select></div><div data-inspected>${g("Loading module graph\u2026")}</div>`;let f=v.querySelector("[data-inspected]"),m=v.querySelector("select");try{let _=await F(`${Y}/modules.json`,o);if(D||e!==U||s!=="inspect")return;if(w=_.modules,!w.length){m.replaceChildren(new Option("No browser modules yet","")),f.innerHTML=g("Visit an app page, then refresh DevTools. Only transformed browser modules inside this project are listed.");return}m.replaceChildren(...w.map(N=>new Option(N.path+(N.url.includes("?")?" "+N.url.slice(N.url.indexOf("?")):""),N.id))),m.disabled=!1,w.some(N=>N.id===T)||(T=w[0].id),m.value=T,m.onchange=()=>{T=m.value,R(T)},_.limited&&(A.textContent="Inspect lists the first 500 browser modules."),await R(T)}catch(_){if(D||e!==U||s!=="inspect")return;f.innerHTML=g(_.message),m.replaceChildren(new Option("Module graph unavailable",""))}}async function R(e){let o=++U;B?.abort(),B=new AbortController;let f=v.querySelector("[data-inspected]");f.innerHTML=g("Reading module\u2026");try{let m=await F(`${Y}/module.json?id=${encodeURIComponent(e)}`,B.signal);if(D||o!==U||s!=="inspect")return;j.set("module-source",m.source),j.set("module-output",m.transformed),f.innerHTML=`<div class="fd-pipeline"><span class="fd-label">SOURCE \u2192 VITE OUTPUT</span><p class="fd-subtitle">Current file on disk and the latest cached browser transform. Refresh the app after edits.</p></div><div class="fd-comparison">${ie(m.source,"Source","module-source")}${ie(m.transformed,"Served JavaScript","module-output")}</div><section class="fd-section"><details><summary>Imports (${m.imports.length})</summary>${m.imports.map(_=>`<div class="fd-tree-item">${S(_)}</div>`).join("")||g("No imports.")}</details><details><summary>Importers (${m.importers.length})</summary>${m.importers.map(_=>`<div class="fd-tree-item">${S(_)}</div>`).join("")||g("No importers.")}</details></section>`}catch(m){if(D||o!==U||s!=="inspect")return;f.innerHTML=g(m.message)}}function K(){if(!c)return;B?.abort(),++U,j.clear(),A.textContent="",t.querySelectorAll("[data-view]").forEach(o=>{o.dataset.view===s?o.setAttribute("aria-current","page"):o.removeAttribute("aria-current")});let e={routes:c.routes.length,api:c.apiRoutes.length,diagnostics:c.diagnostics.length};switch(t.querySelectorAll("[data-count]").forEach(o=>o.textContent=e[o.dataset.count]===void 0?"":String(e[o.dataset.count])),s){case"overview":C();break;case"routes":X(!1);break;case"api":X(!0);break;case"systems":de();break;case"runtime":Z();break;case"diagnostics":v.innerHTML=O("Diagnostics","The same runtime checks used by farm doctor.")+`<section class="fd-section fd-flush-top">${J()}</section>`;break;case"raw":{let o=JSON.stringify(c,null,2);j.set("snapshot",o),v.innerHTML=O("Snapshot","Machine-readable workspace data. Environment values are excluded.")+ie(o,"Runtime JSON","snapshot");break}case"inspect":ee();break}v.querySelectorAll("[data-go]").forEach(o=>o.onclick=()=>r(o.dataset.go))}let V=async e=>{let o=e.target.closest("[data-copy]");if(!o)return;let f=j.get(o.dataset.copy);if(f!==void 0)try{await a.navigator.clipboard.writeText(f),A.textContent="Copied to clipboard"}catch{A.textContent="Copy was blocked. Select the code and copy it manually."}},te=e=>{if(e.key==="Escape"){e.preventDefault(),i();return}if(e.key==="/"&&!["INPUT","SELECT","TEXTAREA"].includes(e.target.tagName)){let o=v.querySelector("[data-filter]");if(o){e.preventDefault(),o.focus();return}}if(e.key==="Tab"){let o=[...t.querySelectorAll("button,input,select,summary,a[href]")].filter(f=>!f.hasAttribute("disabled")&&f.getClientRects().length);e.shiftKey&&l.activeElement===o[0]?(e.preventDefault(),o.at(-1)?.focus()):!e.shiftKey&&l.activeElement===o.at(-1)&&(e.preventDefault(),o[0]?.focus())}a.parent!==a&&x(e)&&a.parent.postMessage({type:"farm:devtools:keydown",event:{key:e.key,code:e.code,altKey:e.altKey,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,repeat:e.repeat}},a.location.origin)};return t.querySelectorAll("[data-view]").forEach(e=>e.onclick=()=>r(e.dataset.view)),t.querySelector("[data-close]").onclick=i,t.querySelector("[data-refresh]").onclick=()=>{y()},t.querySelector("[data-theme-toggle]").onclick=()=>{M=P()?"light":"dark",H();try{a.localStorage.setItem("farm:devtools:theme",M)}catch{}A.textContent=M+" theme"},H(),z.addEventListener("change",H),t.addEventListener("click",V),l.addEventListener("keydown",te),t.querySelector("[data-close]").focus(),y(),{dispose(){D=!0,I?.abort(),B?.abort(),t.removeEventListener("click",V),l.removeEventListener("keydown",te),z.removeEventListener("change",H)}}}var Ee=document.getElementById("farm-devtools");Ee&&Oe(Ee);export{Oe as startPanel};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/devtools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "Development workspace inspector for Farm.js routes, runtime, and browser modules",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"devtools",
|
|
@@ -45,14 +45,14 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@fontsource-variable/geist": "5.3.0",
|
|
48
|
-
"@types/node": "^20.
|
|
48
|
+
"@types/node": "^22.20.5",
|
|
49
49
|
"esbuild": "^0.28.0",
|
|
50
50
|
"jsdom": "^25.0.0",
|
|
51
51
|
"sugar-high": "0.9.5",
|
|
52
52
|
"typescript": "^5.3.3",
|
|
53
|
-
"vite": "
|
|
54
|
-
"vitest": "
|
|
55
|
-
"@farm.js/core": "0.1.
|
|
53
|
+
"vite": "8.3.4",
|
|
54
|
+
"vitest": "5.0.5",
|
|
55
|
+
"@farm.js/core": "0.1.20"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@farm.js/core": ">=0.1.0-beta.96 <0.2.0"
|