astralis-devtools 0.1.0 → 0.3.0
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/CHANGELOG.md +52 -1
- package/README.md +88 -82
- package/package.json +2 -2
- package/src/bridge/github.mjs +2 -2
- package/src/bridge/http.mjs +194 -194
- package/src/bridge/snapshot.mjs +70 -71
- package/src/client/icons.mjs +43 -44
- package/src/client/launcher.mjs +143 -142
- package/src/client/overlay.mjs +583 -525
- package/src/client/page.mjs +7 -0
- package/src/client/props.mjs +154 -0
- package/src/client/report.mjs +2 -42
- package/src/client/screens/component.mjs +158 -151
- package/src/client/screens/home.mjs +100 -100
- package/src/client/screens/props.mjs +192 -0
- package/src/client/screens/report.mjs +97 -85
- package/src/client/screens/shared.mjs +1 -1
- package/src/client/styles.mjs +34 -5
package/src/bridge/http.mjs
CHANGED
|
@@ -1,194 +1,194 @@
|
|
|
1
|
-
import { bridgeFor } from "./bridge.mjs";
|
|
2
|
-
import { githubSession } from "./github.mjs";
|
|
3
|
-
import { assembleSnapshot } from "./snapshot.mjs";
|
|
4
|
-
|
|
5
|
-
/* The bridge over HTTP, in web-standard Request/Response so the Next.js
|
|
6
|
-
route handler and the Vite middleware share it. Mounted at BASE_PATH:
|
|
7
|
-
|
|
8
|
-
GET info versions of astralis-ui (with the spec's SHA-256), the framework and React
|
|
9
|
-
GET spec the installed system spec, for the component pages
|
|
10
|
-
GET findings the validator's findings for the project
|
|
11
|
-
GET events the same findings as a server-sent event stream, re-sent on every change
|
|
12
|
-
GET route-files ?path=/about: the files that render that page (Next.js)
|
|
13
|
-
POST snapshot the page's part of an issue snapshot in; the complete snapshot out
|
|
14
|
-
POST submit a snapshot the reporter confirmed, opened as a GitHub issue;
|
|
15
|
-
?addTo=12 adds it to that existing issue instead
|
|
16
|
-
GET github the GitHub sign-in: set up or not, who, and a code to enter
|
|
17
|
-
POST github/sign-in start signing in with a code (the bridge polls GitHub)
|
|
18
|
-
POST github/sign-out forget the saved sign-in
|
|
19
|
-
GET github/issues the issues the signed-in user opened on the Astralis repository
|
|
20
|
-
POST github/similar a snapshot in; the issues that may already report it out
|
|
21
|
-
POST github/link a snapshot in; GitHub's own new-issue form, filled in, out
|
|
22
|
-
|
|
23
|
-
It answers the local machine only, and nothing at all in production. The
|
|
24
|
-
POST routes take JSON only: a page on another site cannot send that type
|
|
25
|
-
without a preflight the bridge never grants. The GitHub token never leaves
|
|
26
|
-
the bridge: the page sees the login, never the token. */
|
|
27
|
-
|
|
28
|
-
export const BASE_PATH = "/api/astralis-devtools";
|
|
29
|
-
|
|
30
|
-
const KEEPALIVE_MS = 15_000;
|
|
31
|
-
/** A snapshot is at most 256 kB; the page's part
|
|
32
|
-
const MAX_BODY_BYTES = 1024 * 1024;
|
|
33
|
-
const LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
34
|
-
|
|
35
|
-
const json = (body, status = 200) =>
|
|
36
|
-
new Response(JSON.stringify(body), {
|
|
37
|
-
status,
|
|
38
|
-
headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* A request from this machine: addressed to a loopback host and, when a page
|
|
43
|
-
* sent it, from a loopback page. A dev server opened to the network
|
|
44
|
-
* (`next dev -H 0.0.0.0`) still refuses the bridge to other machines, and a
|
|
45
|
-
* page on another site cannot read it by pointing a DNS name at 127.0.0.1.
|
|
46
|
-
*/
|
|
47
|
-
export function isLocal(request) {
|
|
48
|
-
const hostname = (value) => {
|
|
49
|
-
try {
|
|
50
|
-
return new URL(value).hostname;
|
|
51
|
-
} catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const host = request.headers.get("host");
|
|
56
|
-
if (!host || !LOOPBACK.has(hostname(`http://${host}`))) return false;
|
|
57
|
-
const origin = request.headers.get("origin");
|
|
58
|
-
return origin === null || LOOPBACK.has(hostname(origin));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** The path after BASE_PATH, e.g. "findings". */
|
|
62
|
-
function route(url) {
|
|
63
|
-
const at = url.pathname.indexOf(BASE_PATH);
|
|
64
|
-
const rest = at === -1 ? url.pathname : url.pathname.slice(at + BASE_PATH.length);
|
|
65
|
-
return rest.replace(/^\/+|\/+$/g, "");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function eventStream(bridge, signal) {
|
|
69
|
-
const encoder = new TextEncoder();
|
|
70
|
-
let stop = () => {};
|
|
71
|
-
const stream = new ReadableStream({
|
|
72
|
-
start(controller) {
|
|
73
|
-
const send = (text) => {
|
|
74
|
-
try {
|
|
75
|
-
controller.enqueue(encoder.encode(text));
|
|
76
|
-
} catch {
|
|
77
|
-
stop();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const publish = (findings) => send(`event: findings\ndata: ${JSON.stringify(findings)}\n\n`);
|
|
81
|
-
const unlisten = bridge.listen(publish);
|
|
82
|
-
const keepalive = setInterval(() => send(": keepalive\n\n"), KEEPALIVE_MS);
|
|
83
|
-
stop = () => {
|
|
84
|
-
unlisten();
|
|
85
|
-
clearInterval(keepalive);
|
|
86
|
-
try {
|
|
87
|
-
controller.close();
|
|
88
|
-
} catch {
|
|
89
|
-
// already closed by the client
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
signal?.addEventListener("abort", stop, { once: true });
|
|
93
|
-
publish(bridge.findings());
|
|
94
|
-
},
|
|
95
|
-
cancel() {
|
|
96
|
-
stop();
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
return new Response(stream, {
|
|
100
|
-
headers: {
|
|
101
|
-
"content-type": "text/event-stream; charset=utf-8",
|
|
102
|
-
"cache-control": "no-store, no-transform",
|
|
103
|
-
connection: "keep-alive",
|
|
104
|
-
"x-accel-buffering": "no",
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Answer one request. `root` is the project directory, `framework` "next" or
|
|
111
|
-
* "vite"; `watch` optionally replaces fs.watch (Vite passes its own watcher).
|
|
112
|
-
*/
|
|
113
|
-
/** The JSON body of a POST, or a Response explaining why it cannot be read. */
|
|
114
|
-
async function readJson(request) {
|
|
115
|
-
if (!/^application\/json\b/i.test(request.headers.get("content-type") ?? "")) {
|
|
116
|
-
return json({ error: "Send JSON (content-type: application/json)." }, 415);
|
|
117
|
-
}
|
|
118
|
-
const declared = Number(request.headers.get("content-length") ?? 0);
|
|
119
|
-
if (declared > MAX_BODY_BYTES) return json({ error: "The request is too large." }, 413);
|
|
120
|
-
const text = await request.text();
|
|
121
|
-
if (text.length > MAX_BODY_BYTES) return json({ error: "The request is too large." }, 413);
|
|
122
|
-
try {
|
|
123
|
-
return { body: JSON.parse(text) };
|
|
124
|
-
} catch {
|
|
125
|
-
return json({ error: "The request is not valid JSON." }, 400);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** A GitHub failure as a response: 401 when the reporter has to sign in (again). */
|
|
130
|
-
const githubFailure = (error) =>
|
|
131
|
-
json({ error: error.message, code: error.code ?? "github" }, error.code === "signed-out" ? 401 : error.code === "invalid" ? 400 : 502);
|
|
132
|
-
|
|
133
|
-
const POSTS = new Set(["snapshot", "submit", "github/sign-in", "github/sign-out", "github/similar", "github/link"]);
|
|
134
|
-
|
|
135
|
-
async function handlePost(bridge, path, request, github, url) {
|
|
136
|
-
if (!POSTS.has(path)) return json({ error: "Not found." }, 404);
|
|
137
|
-
const read = await readJson(request);
|
|
138
|
-
if (read instanceof Response) return read;
|
|
139
|
-
try {
|
|
140
|
-
if (path === "github/sign-in") return json(await github.signIn());
|
|
141
|
-
if (path === "github/sign-out") return json(github.signOut());
|
|
142
|
-
if (path === "github/similar") return json(await github.similar(read.body));
|
|
143
|
-
if (path === "github/link") return json(github.link(read.body));
|
|
144
|
-
} catch (error) {
|
|
145
|
-
return githubFailure(error);
|
|
146
|
-
}
|
|
147
|
-
if (bridge.problem) return json({ error: bridge.problem }, 409);
|
|
148
|
-
if (path === "snapshot") return json(assembleSnapshot(bridge, read.body));
|
|
149
|
-
const addTo = url.searchParams.has("addTo") ? Number(url.searchParams.get("addTo")) : null;
|
|
150
|
-
if (addTo !== null && !(Number.isInteger(addTo) && addTo > 0)) return json({ error: "addTo takes an issue number." }, 400);
|
|
151
|
-
try {
|
|
152
|
-
return json(await github.submit(read.body, { addTo }));
|
|
153
|
-
} catch (error) {
|
|
154
|
-
return githubFailure(error);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export async function handle(request, { root = process.cwd(), framework, watch, github = githubSession() } = {}) {
|
|
159
|
-
if (process.env.NODE_ENV === "production") return new Response(null, { status: 404 });
|
|
160
|
-
if (!isLocal(request)) return json({ error: "The Astralis DevTools bridge answers this machine only." }, 403);
|
|
161
|
-
if (request.method !== "GET" && request.method !== "POST") return json({ error: "Method not allowed." }, 405);
|
|
162
|
-
|
|
163
|
-
const bridge = bridgeFor(root, framework, { watch });
|
|
164
|
-
await bridge.start();
|
|
165
|
-
const url = new URL(request.url);
|
|
166
|
-
if (request.method === "POST") return handlePost(bridge, route(url), request, github, url);
|
|
167
|
-
|
|
168
|
-
switch (route(url)) {
|
|
169
|
-
case "info":
|
|
170
|
-
return bridge.problem ? json({ problem: bridge.problem }) : json(bridge.info);
|
|
171
|
-
case "spec":
|
|
172
|
-
return bridge.problem
|
|
173
|
-
? json({ problem: bridge.problem }, 404)
|
|
174
|
-
: new Response(bridge.specText, {
|
|
175
|
-
headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
|
|
176
|
-
});
|
|
177
|
-
case "findings":
|
|
178
|
-
return json(bridge.findings());
|
|
179
|
-
case "events":
|
|
180
|
-
return eventStream(bridge, request.signal);
|
|
181
|
-
case "github":
|
|
182
|
-
return json(github.status());
|
|
183
|
-
case "github/issues":
|
|
184
|
-
try {
|
|
185
|
-
return json({ issues: await github.issues() });
|
|
186
|
-
} catch (error) {
|
|
187
|
-
return githubFailure(error);
|
|
188
|
-
}
|
|
189
|
-
case "route-files":
|
|
190
|
-
return json({ path: url.searchParams.get("path") ?? "/", files: bridge.routeFiles(url.searchParams.get("path") ?? "/") });
|
|
191
|
-
default:
|
|
192
|
-
return json({ error: "Not found." }, 404);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
1
|
+
import { bridgeFor } from "./bridge.mjs";
|
|
2
|
+
import { githubSession } from "./github.mjs";
|
|
3
|
+
import { assembleSnapshot } from "./snapshot.mjs";
|
|
4
|
+
|
|
5
|
+
/* The bridge over HTTP, in web-standard Request/Response so the Next.js
|
|
6
|
+
route handler and the Vite middleware share it. Mounted at BASE_PATH:
|
|
7
|
+
|
|
8
|
+
GET info versions of astralis-ui (with the spec's SHA-256), the framework and React
|
|
9
|
+
GET spec the installed system spec, for the component pages
|
|
10
|
+
GET findings the validator's findings for the project
|
|
11
|
+
GET events the same findings as a server-sent event stream, re-sent on every change
|
|
12
|
+
GET route-files ?path=/about: the files that render that page (Next.js)
|
|
13
|
+
POST snapshot the page's part of an issue snapshot in; the complete snapshot out
|
|
14
|
+
POST submit a snapshot the reporter confirmed, opened as a GitHub issue;
|
|
15
|
+
?addTo=12 adds it to that existing issue instead
|
|
16
|
+
GET github the GitHub sign-in: set up or not, who, and a code to enter
|
|
17
|
+
POST github/sign-in start signing in with a code (the bridge polls GitHub)
|
|
18
|
+
POST github/sign-out forget the saved sign-in
|
|
19
|
+
GET github/issues the issues the signed-in user opened on the Astralis repository
|
|
20
|
+
POST github/similar a snapshot in; the issues that may already report it out
|
|
21
|
+
POST github/link a snapshot in; GitHub's own new-issue form, filled in, out
|
|
22
|
+
|
|
23
|
+
It answers the local machine only, and nothing at all in production. The
|
|
24
|
+
POST routes take JSON only: a page on another site cannot send that type
|
|
25
|
+
without a preflight the bridge never grants. The GitHub token never leaves
|
|
26
|
+
the bridge: the page sees the login, never the token. */
|
|
27
|
+
|
|
28
|
+
export const BASE_PATH = "/api/astralis-devtools";
|
|
29
|
+
|
|
30
|
+
const KEEPALIVE_MS = 15_000;
|
|
31
|
+
/** A snapshot is at most 256 kB; the page's part stays well under this. */
|
|
32
|
+
const MAX_BODY_BYTES = 1024 * 1024;
|
|
33
|
+
const LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]", "::1"]);
|
|
34
|
+
|
|
35
|
+
const json = (body, status = 200) =>
|
|
36
|
+
new Response(JSON.stringify(body), {
|
|
37
|
+
status,
|
|
38
|
+
headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A request from this machine: addressed to a loopback host and, when a page
|
|
43
|
+
* sent it, from a loopback page. A dev server opened to the network
|
|
44
|
+
* (`next dev -H 0.0.0.0`) still refuses the bridge to other machines, and a
|
|
45
|
+
* page on another site cannot read it by pointing a DNS name at 127.0.0.1.
|
|
46
|
+
*/
|
|
47
|
+
export function isLocal(request) {
|
|
48
|
+
const hostname = (value) => {
|
|
49
|
+
try {
|
|
50
|
+
return new URL(value).hostname;
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const host = request.headers.get("host");
|
|
56
|
+
if (!host || !LOOPBACK.has(hostname(`http://${host}`))) return false;
|
|
57
|
+
const origin = request.headers.get("origin");
|
|
58
|
+
return origin === null || LOOPBACK.has(hostname(origin));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The path after BASE_PATH, e.g. "findings". */
|
|
62
|
+
function route(url) {
|
|
63
|
+
const at = url.pathname.indexOf(BASE_PATH);
|
|
64
|
+
const rest = at === -1 ? url.pathname : url.pathname.slice(at + BASE_PATH.length);
|
|
65
|
+
return rest.replace(/^\/+|\/+$/g, "");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function eventStream(bridge, signal) {
|
|
69
|
+
const encoder = new TextEncoder();
|
|
70
|
+
let stop = () => {};
|
|
71
|
+
const stream = new ReadableStream({
|
|
72
|
+
start(controller) {
|
|
73
|
+
const send = (text) => {
|
|
74
|
+
try {
|
|
75
|
+
controller.enqueue(encoder.encode(text));
|
|
76
|
+
} catch {
|
|
77
|
+
stop();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const publish = (findings) => send(`event: findings\ndata: ${JSON.stringify(findings)}\n\n`);
|
|
81
|
+
const unlisten = bridge.listen(publish);
|
|
82
|
+
const keepalive = setInterval(() => send(": keepalive\n\n"), KEEPALIVE_MS);
|
|
83
|
+
stop = () => {
|
|
84
|
+
unlisten();
|
|
85
|
+
clearInterval(keepalive);
|
|
86
|
+
try {
|
|
87
|
+
controller.close();
|
|
88
|
+
} catch {
|
|
89
|
+
// already closed by the client
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
93
|
+
publish(bridge.findings());
|
|
94
|
+
},
|
|
95
|
+
cancel() {
|
|
96
|
+
stop();
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
return new Response(stream, {
|
|
100
|
+
headers: {
|
|
101
|
+
"content-type": "text/event-stream; charset=utf-8",
|
|
102
|
+
"cache-control": "no-store, no-transform",
|
|
103
|
+
connection: "keep-alive",
|
|
104
|
+
"x-accel-buffering": "no",
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Answer one request. `root` is the project directory, `framework` "next" or
|
|
111
|
+
* "vite"; `watch` optionally replaces fs.watch (Vite passes its own watcher).
|
|
112
|
+
*/
|
|
113
|
+
/** The JSON body of a POST, or a Response explaining why it cannot be read. */
|
|
114
|
+
async function readJson(request) {
|
|
115
|
+
if (!/^application\/json\b/i.test(request.headers.get("content-type") ?? "")) {
|
|
116
|
+
return json({ error: "Send JSON (content-type: application/json)." }, 415);
|
|
117
|
+
}
|
|
118
|
+
const declared = Number(request.headers.get("content-length") ?? 0);
|
|
119
|
+
if (declared > MAX_BODY_BYTES) return json({ error: "The request is too large." }, 413);
|
|
120
|
+
const text = await request.text();
|
|
121
|
+
if (text.length > MAX_BODY_BYTES) return json({ error: "The request is too large." }, 413);
|
|
122
|
+
try {
|
|
123
|
+
return { body: JSON.parse(text) };
|
|
124
|
+
} catch {
|
|
125
|
+
return json({ error: "The request is not valid JSON." }, 400);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A GitHub failure as a response: 401 when the reporter has to sign in (again). */
|
|
130
|
+
const githubFailure = (error) =>
|
|
131
|
+
json({ error: error.message, code: error.code ?? "github" }, error.code === "signed-out" ? 401 : error.code === "invalid" ? 400 : 502);
|
|
132
|
+
|
|
133
|
+
const POSTS = new Set(["snapshot", "submit", "github/sign-in", "github/sign-out", "github/similar", "github/link"]);
|
|
134
|
+
|
|
135
|
+
async function handlePost(bridge, path, request, github, url) {
|
|
136
|
+
if (!POSTS.has(path)) return json({ error: "Not found." }, 404);
|
|
137
|
+
const read = await readJson(request);
|
|
138
|
+
if (read instanceof Response) return read;
|
|
139
|
+
try {
|
|
140
|
+
if (path === "github/sign-in") return json(await github.signIn());
|
|
141
|
+
if (path === "github/sign-out") return json(github.signOut());
|
|
142
|
+
if (path === "github/similar") return json(await github.similar(read.body));
|
|
143
|
+
if (path === "github/link") return json(github.link(read.body));
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return githubFailure(error);
|
|
146
|
+
}
|
|
147
|
+
if (bridge.problem) return json({ error: bridge.problem }, 409);
|
|
148
|
+
if (path === "snapshot") return json(assembleSnapshot(bridge, read.body));
|
|
149
|
+
const addTo = url.searchParams.has("addTo") ? Number(url.searchParams.get("addTo")) : null;
|
|
150
|
+
if (addTo !== null && !(Number.isInteger(addTo) && addTo > 0)) return json({ error: "addTo takes an issue number." }, 400);
|
|
151
|
+
try {
|
|
152
|
+
return json(await github.submit(read.body, { addTo }));
|
|
153
|
+
} catch (error) {
|
|
154
|
+
return githubFailure(error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export async function handle(request, { root = process.cwd(), framework, watch, github = githubSession() } = {}) {
|
|
159
|
+
if (process.env.NODE_ENV === "production") return new Response(null, { status: 404 });
|
|
160
|
+
if (!isLocal(request)) return json({ error: "The Astralis DevTools bridge answers this machine only." }, 403);
|
|
161
|
+
if (request.method !== "GET" && request.method !== "POST") return json({ error: "Method not allowed." }, 405);
|
|
162
|
+
|
|
163
|
+
const bridge = bridgeFor(root, framework, { watch });
|
|
164
|
+
await bridge.start();
|
|
165
|
+
const url = new URL(request.url);
|
|
166
|
+
if (request.method === "POST") return handlePost(bridge, route(url), request, github, url);
|
|
167
|
+
|
|
168
|
+
switch (route(url)) {
|
|
169
|
+
case "info":
|
|
170
|
+
return bridge.problem ? json({ problem: bridge.problem }) : json(bridge.info);
|
|
171
|
+
case "spec":
|
|
172
|
+
return bridge.problem
|
|
173
|
+
? json({ problem: bridge.problem }, 404)
|
|
174
|
+
: new Response(bridge.specText, {
|
|
175
|
+
headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" },
|
|
176
|
+
});
|
|
177
|
+
case "findings":
|
|
178
|
+
return json(bridge.findings());
|
|
179
|
+
case "events":
|
|
180
|
+
return eventStream(bridge, request.signal);
|
|
181
|
+
case "github":
|
|
182
|
+
return json(github.status());
|
|
183
|
+
case "github/issues":
|
|
184
|
+
try {
|
|
185
|
+
return json({ issues: await github.issues() });
|
|
186
|
+
} catch (error) {
|
|
187
|
+
return githubFailure(error);
|
|
188
|
+
}
|
|
189
|
+
case "route-files":
|
|
190
|
+
return json({ path: url.searchParams.get("path") ?? "/", files: bridge.routeFiles(url.searchParams.get("path") ?? "/") });
|
|
191
|
+
default:
|
|
192
|
+
return json({ error: "Not found." }, 404);
|
|
193
|
+
}
|
|
194
|
+
}
|
package/src/bridge/snapshot.mjs
CHANGED
|
@@ -1,71 +1,70 @@
|
|
|
1
|
-
import {
|
|
2
|
-
LIMITS,
|
|
3
|
-
SNAPSHOT_FORMAT,
|
|
4
|
-
checkSnapshot,
|
|
5
|
-
cleanConsoleMessage,
|
|
6
|
-
cleanRoute,
|
|
7
|
-
narrowTree,
|
|
8
|
-
} from "astralis-cli/snapshot";
|
|
9
|
-
|
|
10
|
-
/* The bridge's half of an issue snapshot. The page sends what only the page
|
|
11
|
-
knows (the component tree, the browser, the reporter's words); the bridge
|
|
12
|
-
adds what only the dev server knows (versions, the spec's hash, the
|
|
13
|
-
validator's findings) and checks the whole. Nothing here makes a network
|
|
14
|
-
request; github.mjs sends a snapshot once the reporter confirms. */
|
|
15
|
-
|
|
16
|
-
const shortString = (value, max) => (typeof value === "string" && value.trim() ? value.trim().slice(0, max) : undefined);
|
|
17
|
-
|
|
18
|
-
/** Findings for the files that render `route` (Next.js), else for the whole project. */
|
|
19
|
-
function findingsFor(bridge, route) {
|
|
20
|
-
const { results = [] } = bridge.findings();
|
|
21
|
-
const files = route ? new Set(bridge.routeFiles(route)) : new Set();
|
|
22
|
-
const chosen = files.size ? results.filter((r) => files.has(r.file)) : results;
|
|
23
|
-
return chosen
|
|
24
|
-
.flatMap((r) => [...r.errors, ...r.warnings])
|
|
25
|
-
.map(({ code, file, line, column, message }) => ({ code, file, line, column, message }))
|
|
26
|
-
.slice(0, LIMITS.findings);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function environmentOf(info, input) {
|
|
30
|
-
const env = input && typeof input === "object" ? input : {};
|
|
31
|
-
const viewport = env.viewport;
|
|
32
|
-
return {
|
|
33
|
-
framework: { name: info.framework?.name ?? null, version: info.framework?.version ?? null },
|
|
34
|
-
react: info.react ?? null,
|
|
35
|
-
browser: shortString(env.browser, 60) ?? null,
|
|
36
|
-
viewport: viewport && Number.isInteger(viewport.width) && Number.isInteger(viewport.height)
|
|
37
|
-
? { width: viewport.width, height: viewport.height }
|
|
38
|
-
: null,
|
|
39
|
-
colorMode: env.colorMode === "light" || env.colorMode === "dark" ? env.colorMode : null,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The complete snapshot from the page's part. Returns { snapshot, problems }:
|
|
45
|
-
* the overlay shows `snapshot` as the exact JSON that would be sent.
|
|
46
|
-
*/
|
|
47
|
-
export function assembleSnapshot(bridge, input = {}) {
|
|
48
|
-
const include = input.include ?? {};
|
|
49
|
-
const route = cleanRoute(typeof input.route === "string" ? input.route : null);
|
|
50
|
-
const description = { title: shortString(input.description?.title, LIMITS.title) ?? "" };
|
|
51
|
-
const happened = shortString(input.description?.happened, LIMITS.body);
|
|
52
|
-
const expected = shortString(input.description?.expected, LIMITS.body);
|
|
53
|
-
if (happened) description.happened = happened;
|
|
54
|
-
if (expected) description.expected = expected;
|
|
55
|
-
|
|
56
|
-
const snapshot = {
|
|
57
|
-
format: SNAPSHOT_FORMAT,
|
|
58
|
-
source: "devtools",
|
|
59
|
-
library: { ...bridge.info.library },
|
|
60
|
-
environment: environmentOf(bridge.info, input.environment),
|
|
61
|
-
route,
|
|
62
|
-
tree: narrowTree(bridge.spec, input.tree),
|
|
63
|
-
...(include.findings === false ? {} : { findings: findingsFor(bridge, route) }),
|
|
64
|
-
...(include.console && Array.isArray(input.console)
|
|
65
|
-
? { console: input.console.slice(-LIMITS.console).map((m) => cleanConsoleMessage(m)) }
|
|
66
|
-
: {}),
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
LIMITS,
|
|
3
|
+
SNAPSHOT_FORMAT,
|
|
4
|
+
checkSnapshot,
|
|
5
|
+
cleanConsoleMessage,
|
|
6
|
+
cleanRoute,
|
|
7
|
+
narrowTree,
|
|
8
|
+
} from "astralis-cli/snapshot";
|
|
9
|
+
|
|
10
|
+
/* The bridge's half of an issue snapshot. The page sends what only the page
|
|
11
|
+
knows (the component tree, the browser, the reporter's words); the bridge
|
|
12
|
+
adds what only the dev server knows (versions, the spec's hash, the
|
|
13
|
+
validator's findings) and checks the whole. Nothing here makes a network
|
|
14
|
+
request; github.mjs sends a snapshot once the reporter confirms. */
|
|
15
|
+
|
|
16
|
+
const shortString = (value, max) => (typeof value === "string" && value.trim() ? value.trim().slice(0, max) : undefined);
|
|
17
|
+
|
|
18
|
+
/** Findings for the files that render `route` (Next.js), else for the whole project. */
|
|
19
|
+
function findingsFor(bridge, route) {
|
|
20
|
+
const { results = [] } = bridge.findings();
|
|
21
|
+
const files = route ? new Set(bridge.routeFiles(route)) : new Set();
|
|
22
|
+
const chosen = files.size ? results.filter((r) => files.has(r.file)) : results;
|
|
23
|
+
return chosen
|
|
24
|
+
.flatMap((r) => [...r.errors, ...r.warnings])
|
|
25
|
+
.map(({ code, file, line, column, message }) => ({ code, file, line, column, message }))
|
|
26
|
+
.slice(0, LIMITS.findings);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function environmentOf(info, input) {
|
|
30
|
+
const env = input && typeof input === "object" ? input : {};
|
|
31
|
+
const viewport = env.viewport;
|
|
32
|
+
return {
|
|
33
|
+
framework: { name: info.framework?.name ?? null, version: info.framework?.version ?? null },
|
|
34
|
+
react: info.react ?? null,
|
|
35
|
+
browser: shortString(env.browser, 60) ?? null,
|
|
36
|
+
viewport: viewport && Number.isInteger(viewport.width) && Number.isInteger(viewport.height)
|
|
37
|
+
? { width: viewport.width, height: viewport.height }
|
|
38
|
+
: null,
|
|
39
|
+
colorMode: env.colorMode === "light" || env.colorMode === "dark" ? env.colorMode : null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The complete snapshot from the page's part. Returns { snapshot, problems }:
|
|
45
|
+
* the overlay shows `snapshot` as the exact JSON that would be sent.
|
|
46
|
+
*/
|
|
47
|
+
export function assembleSnapshot(bridge, input = {}) {
|
|
48
|
+
const include = input.include ?? {};
|
|
49
|
+
const route = cleanRoute(typeof input.route === "string" ? input.route : null);
|
|
50
|
+
const description = { title: shortString(input.description?.title, LIMITS.title) ?? "" };
|
|
51
|
+
const happened = shortString(input.description?.happened, LIMITS.body);
|
|
52
|
+
const expected = shortString(input.description?.expected, LIMITS.body);
|
|
53
|
+
if (happened) description.happened = happened;
|
|
54
|
+
if (expected) description.expected = expected;
|
|
55
|
+
|
|
56
|
+
const snapshot = {
|
|
57
|
+
format: SNAPSHOT_FORMAT,
|
|
58
|
+
source: "devtools",
|
|
59
|
+
library: { ...bridge.info.library },
|
|
60
|
+
environment: environmentOf(bridge.info, input.environment),
|
|
61
|
+
route,
|
|
62
|
+
tree: narrowTree(bridge.spec, input.tree),
|
|
63
|
+
...(include.findings === false ? {} : { findings: findingsFor(bridge, route) }),
|
|
64
|
+
...(include.console && Array.isArray(input.console)
|
|
65
|
+
? { console: input.console.slice(-LIMITS.console).map((m) => cleanConsoleMessage(m)) }
|
|
66
|
+
: {}),
|
|
67
|
+
description,
|
|
68
|
+
};
|
|
69
|
+
return { snapshot, problems: checkSnapshot(snapshot) };
|
|
70
|
+
}
|
package/src/client/icons.mjs
CHANGED
|
@@ -1,44 +1,43 @@
|
|
|
1
|
-
/* The overlay's icons: 24px line icons, drawn in currentColor, and the
|
|
2
|
-
Astralis mark. */
|
|
3
|
-
|
|
4
|
-
const line = (paths) =>
|
|
5
|
-
`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${paths}</svg>`;
|
|
6
|
-
|
|
7
|
-
/** The Astralis mark: four blocks, the last one tipped. */
|
|
8
|
-
export const MARK = `<svg viewBox="0 0 32 32" fill="currentColor">
|
|
9
|
-
<rect class="b1" x="3" y="17" width="12" height="12" rx="3"/>
|
|
10
|
-
<rect class="b2" x="17" y="17" width="12" height="12" rx="3"/>
|
|
11
|
-
<rect class="b3" x="3" y="3" width="12" height="12" rx="3"/>
|
|
12
|
-
<rect class="b4" x="19" y="1" width="12" height="12" rx="3" opacity="0.6" transform="rotate(14 25 7)"/>
|
|
13
|
-
</svg>`;
|
|
14
|
-
|
|
15
|
-
export const ICONS = {
|
|
16
|
-
home: line('<path d="M3.5 10.2 12 3.5l8.5 6.7V19a1.5 1.5 0 0 1-1.5 1.5h-4v-6h-6v6H5A1.5 1.5 0 0 1 3.5 19z"/>'),
|
|
17
|
-
components: line('<path d="m12 3 8.5 4.5L12 12 3.5 7.5z"/><path d="m3.5 12 8.5 4.5 8.5-4.5"/><path d="m3.5 16.5 8.5 4.5 8.5-4.5"/>'),
|
|
18
|
-
findings: line('<path d="M8.2 3h7.6L21 8.2v7.6L15.8 21H8.2L3 15.8V8.2z"/><path d="M12 8v4.5"/><path d="M12 16h.01"/>'),
|
|
19
|
-
recommendations: line('<path d="M9 18h6"/><path d="M10 21h4"/><path d="M12 3a6 6 0 0 0-3.6 10.8c.7.5 1.1 1.3 1.1 2.2h5c0-.9.4-1.7 1.1-2.2A6 6 0 0 0 12 3z"/>'),
|
|
20
|
-
report: line('<path d="M5 21V4"/><path d="M5 4h11l-2 4 2 4H5"/>'),
|
|
21
|
-
pick: line('<circle cx="12" cy="12" r="7.5"/><path d="M12 2v4"/><path d="M12 18v4"/><path d="M2 12h4"/><path d="M18 12h4"/><circle cx="12" cy="12" r="1.2" fill="currentColor"/>'),
|
|
22
|
-
|
|
23
|
-
back: line('<path d="M15 5l-7 7 7 7"/>'),
|
|
24
|
-
chevron: line('<path d="m9 5 7 7-7 7"/>'),
|
|
25
|
-
arrow: line('<path d="M5 12h14"/><path d="m13 6 6 6-6 6"/>'),
|
|
26
|
-
external: line('<path d="M14 4h6v6"/><path d="M20 4 11 13"/><path d="M19 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1h5"/>'),
|
|
27
|
-
search: line('<circle cx="11" cy="11" r="6.5"/><path d="m16 16 4.5 4.5"/>'),
|
|
28
|
-
locate: line('<path d="M4 9V5a1 1 0 0 1 1-1h4"/><path d="M15 4h4a1 1 0 0 1 1 1v4"/><path d="M20 15v4a1 1 0 0 1-1 1h-4"/><path d="M9 20H5a1 1 0 0 1-1-1v-4"/><circle cx="12" cy="12" r="2.5"/>'),
|
|
29
|
-
check: line('<path d="m5 12.5 4.5 4.5L19 7.5"/>'),
|
|
30
|
-
copy: line('<rect x="8" y="8" width="12" height="12" rx="2"/><path d="M16 8V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h3"/>'),
|
|
31
|
-
download: line('<path d="M12 4v11"/><path d="m7 10 5 5 5-5"/><path d="M5 20h14"/>'),
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'<svg viewBox="0 0 16 16" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>';
|
|
1
|
+
/* The overlay's icons: 24px line icons, drawn in currentColor, and the
|
|
2
|
+
Astralis mark. */
|
|
3
|
+
|
|
4
|
+
const line = (paths) =>
|
|
5
|
+
`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">${paths}</svg>`;
|
|
6
|
+
|
|
7
|
+
/** The Astralis mark: four blocks, the last one tipped. */
|
|
8
|
+
export const MARK = `<svg viewBox="0 0 32 32" fill="currentColor">
|
|
9
|
+
<rect class="b1" x="3" y="17" width="12" height="12" rx="3"/>
|
|
10
|
+
<rect class="b2" x="17" y="17" width="12" height="12" rx="3"/>
|
|
11
|
+
<rect class="b3" x="3" y="3" width="12" height="12" rx="3"/>
|
|
12
|
+
<rect class="b4" x="19" y="1" width="12" height="12" rx="3" opacity="0.6" transform="rotate(14 25 7)"/>
|
|
13
|
+
</svg>`;
|
|
14
|
+
|
|
15
|
+
export const ICONS = {
|
|
16
|
+
home: line('<path d="M3.5 10.2 12 3.5l8.5 6.7V19a1.5 1.5 0 0 1-1.5 1.5h-4v-6h-6v6H5A1.5 1.5 0 0 1 3.5 19z"/>'),
|
|
17
|
+
components: line('<path d="m12 3 8.5 4.5L12 12 3.5 7.5z"/><path d="m3.5 12 8.5 4.5 8.5-4.5"/><path d="m3.5 16.5 8.5 4.5 8.5-4.5"/>'),
|
|
18
|
+
findings: line('<path d="M8.2 3h7.6L21 8.2v7.6L15.8 21H8.2L3 15.8V8.2z"/><path d="M12 8v4.5"/><path d="M12 16h.01"/>'),
|
|
19
|
+
recommendations: line('<path d="M9 18h6"/><path d="M10 21h4"/><path d="M12 3a6 6 0 0 0-3.6 10.8c.7.5 1.1 1.3 1.1 2.2h5c0-.9.4-1.7 1.1-2.2A6 6 0 0 0 12 3z"/>'),
|
|
20
|
+
report: line('<path d="M5 21V4"/><path d="M5 4h11l-2 4 2 4H5"/>'),
|
|
21
|
+
pick: line('<circle cx="12" cy="12" r="7.5"/><path d="M12 2v4"/><path d="M12 18v4"/><path d="M2 12h4"/><path d="M18 12h4"/><circle cx="12" cy="12" r="1.2" fill="currentColor"/>'),
|
|
22
|
+
minimize: line('<path d="M6 17.5h12"/>'),
|
|
23
|
+
back: line('<path d="M15 5l-7 7 7 7"/>'),
|
|
24
|
+
chevron: line('<path d="m9 5 7 7-7 7"/>'),
|
|
25
|
+
arrow: line('<path d="M5 12h14"/><path d="m13 6 6 6-6 6"/>'),
|
|
26
|
+
external: line('<path d="M14 4h6v6"/><path d="M20 4 11 13"/><path d="M19 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1h5"/>'),
|
|
27
|
+
search: line('<circle cx="11" cy="11" r="6.5"/><path d="m16 16 4.5 4.5"/>'),
|
|
28
|
+
locate: line('<path d="M4 9V5a1 1 0 0 1 1-1h4"/><path d="M15 4h4a1 1 0 0 1 1 1v4"/><path d="M20 15v4a1 1 0 0 1-1 1h-4"/><path d="M9 20H5a1 1 0 0 1-1-1v-4"/><circle cx="12" cy="12" r="2.5"/>'),
|
|
29
|
+
check: line('<path d="m5 12.5 4.5 4.5L19 7.5"/>'),
|
|
30
|
+
copy: line('<rect x="8" y="8" width="12" height="12" rx="2"/><path d="M16 8V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h3"/>'),
|
|
31
|
+
download: line('<path d="M12 4v11"/><path d="m7 10 5 5 5-5"/><path d="M5 20h14"/>'),
|
|
32
|
+
file: line('<path d="M14 3H7a1.5 1.5 0 0 0-1.5 1.5v15A1.5 1.5 0 0 0 7 21h10a1.5 1.5 0 0 0 1.5-1.5V7.5z"/><path d="M14 3v4.5h4.5"/>'),
|
|
33
|
+
sparkle: line('<path d="M12 3.5 13.8 10.2 20.5 12l-6.7 1.8L12 20.5l-1.8-6.7L3.5 12l6.7-1.8z"/>'),
|
|
34
|
+
refresh: line('<path d="M20 11a8 8 0 0 0-14.3-4.9L4 8"/><path d="M4 4v4h4"/><path d="M4 13a8 8 0 0 0 14.3 4.9L20 16"/><path d="M20 20v-4h-4"/>'),
|
|
35
|
+
issueOpen: line('<circle cx="12" cy="12" r="8.5"/><circle cx="12" cy="12" r="1.6" fill="currentColor"/>'),
|
|
36
|
+
issueClosed: line('<circle cx="12" cy="12" r="8.5"/><path d="m8.5 12.2 2.4 2.4 4.6-4.8"/>'),
|
|
37
|
+
signOut: line('<path d="M15 4h3a1.5 1.5 0 0 1 1.5 1.5v13A1.5 1.5 0 0 1 18 20h-3"/><path d="M10 16l-4-4 4-4"/><path d="M6 12h10"/>'),
|
|
38
|
+
send: line('<path d="M20.5 3.5 10 14"/><path d="m20.5 3.5-6.5 17-4-6.5-6.5-4z"/>'),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** GitHub's mark, for signing in with GitHub. */
|
|
42
|
+
export const GITHUB_MARK =
|
|
43
|
+
'<svg viewBox="0 0 16 16" fill="currentColor"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>';
|