miaoda-react-devkit 0.1.1-beta.21 → 0.1.1-beta.24

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.
@@ -0,0 +1,226 @@
1
+ // src/oxlint/astUtils.ts
2
+ function nodeName(node) {
3
+ if (!node) return void 0;
4
+ if (typeof node.name === "string") return node.name;
5
+ if (node.name?.type === "JSXIdentifier" || node.name?.type === "Identifier") return node.name.name;
6
+ return node.name?.property?.name ?? node.property?.name;
7
+ }
8
+ function openingElement(node) {
9
+ return node?.type === "JSXElement" ? node.openingElement : node?.type === "JSXOpeningElement" ? node : void 0;
10
+ }
11
+ function attributes(node) {
12
+ return openingElement(node)?.attributes ?? [];
13
+ }
14
+ function attribute(node, name) {
15
+ return attributes(node).find((item) => item.type === "JSXAttribute" && nodeName(item.name) === name);
16
+ }
17
+ function hasAttribute(node, name) {
18
+ return attribute(node, name) !== void 0;
19
+ }
20
+ function staticString(value) {
21
+ if (!value) return void 0;
22
+ if (value.type === "Literal" && typeof value.value === "string") return value.value;
23
+ if (value.type === "TemplateLiteral" && value.expressions?.length === 0) {
24
+ return value.quasis?.[0]?.value?.cooked ?? value.quasis?.[0]?.value?.raw;
25
+ }
26
+ if (value.type === "JSXExpressionContainer") return staticString(value.expression);
27
+ return void 0;
28
+ }
29
+ function attributeString(node, name) {
30
+ return staticString(attribute(node, name)?.value);
31
+ }
32
+ function hasClassToken(value, token) {
33
+ return value?.split(/\s+/).includes(token) ?? false;
34
+ }
35
+ function hasClassPrefix(value, pattern) {
36
+ return value?.split(/\s+/).some((token) => pattern.test(token)) ?? false;
37
+ }
38
+ function ancestors(node) {
39
+ const result = [];
40
+ let current = node.parent;
41
+ while (current) {
42
+ result.push(current);
43
+ current = current.parent;
44
+ }
45
+ return result;
46
+ }
47
+ function report(context, node, message) {
48
+ context.report({ node, message });
49
+ }
50
+ function spreadMayProvideInteraction(node) {
51
+ for (const attr of attributes(node)) {
52
+ if (attr.type !== "JSXSpreadAttribute") continue;
53
+ const argument = attr.argument;
54
+ if (!argument || argument.type !== "ObjectExpression") return true;
55
+ for (const prop of argument.properties ?? []) {
56
+ if (prop.type !== "Property") return true;
57
+ if (prop.computed && prop.key?.type !== "Literal") return true;
58
+ const name = propertyName(prop);
59
+ if (name === "onClick" || name === "asChild") return true;
60
+ const value = propertyString(prop);
61
+ if (name === "type" && (value === "submit" || value === "reset")) return true;
62
+ }
63
+ }
64
+ return false;
65
+ }
66
+ function isJsxElementNamed(node, pattern) {
67
+ const opening = openingElement(node);
68
+ return pattern.test(nodeName(opening?.name) ?? "");
69
+ }
70
+ function directChildNamed(node, name) {
71
+ return (node.children ?? []).some((child) => isJsxElementNamed(child, new RegExp(`^${name}$`)));
72
+ }
73
+ function propertyName(node) {
74
+ if (!node) return void 0;
75
+ if (node.key?.type === "Identifier" && !node.computed) return node.key.name;
76
+ if (node.key?.type === "Literal" && typeof node.key.value === "string") return node.key.value;
77
+ return void 0;
78
+ }
79
+ function propertyString(node) {
80
+ return staticString(node?.value);
81
+ }
82
+ function isSupabaseInvoke(node) {
83
+ const callee = node.callee;
84
+ return callee?.type === "MemberExpression" && !callee.computed && callee.property?.name === "invoke" && callee.object?.type === "MemberExpression" && !callee.object.computed && callee.object.property?.name === "functions" && callee.object.object?.type === "Identifier" && callee.object.object.name === "supabase";
85
+ }
86
+
87
+ // src/oxlint/rules/index.ts
88
+ var BUTTON = /^Button$/;
89
+ var TRIGGER = /^(Popover|Dialog|DropdownMenu|AlertDialog|HoverCard|Menubar|NavigationMenu|ContextMenu|Tooltip)Trigger$/;
90
+ var ANY_TRIGGER = /Trigger$/;
91
+ function jsxRule(visitor) {
92
+ return { create: () => visitor };
93
+ }
94
+ function selectItemRule(context) {
95
+ return jsxRule({
96
+ JSXElement(node) {
97
+ const opening = openingElement(node);
98
+ if (!isJsxElementNamed(opening, /^SelectItem$/)) return;
99
+ const value = attribute(opening, "value");
100
+ if (value && staticString(value.value) === "") {
101
+ report(context, value, "\u68C0\u6D4B\u5230 SelectItem \u7EC4\u4EF6\u4F7F\u7528\u7A7A\u5B57\u7B26\u4E32 value\uFF0C\u8FD9\u662F\u9519\u8BEF\u7528\u6CD5\uFF0C\u8FD0\u884C\u65F6\u4F1A\u62A5\u9519\uFF0C\u8BF7\u4FEE\u6539\uFF1B\u5982\u679C\u60F3\u5B9E\u73B0\u5168\u9009\uFF0C\u5EFA\u8BAE\u4F7F\u7528 all \u4EE3\u66FF\u7A7A\u5B57\u7B26\u4E32\u3002");
102
+ }
103
+ }
104
+ });
105
+ }
106
+ function contrastRule(kind, context) {
107
+ return jsxRule({
108
+ JSXElement(node) {
109
+ const opening = openingElement(node);
110
+ if (!opening || !isJsxElementNamed(opening, BUTTON)) return;
111
+ const variant = attributeString(opening, "variant");
112
+ const className = attributeString(opening, "className");
113
+ if (kind === "foreground" && variant === "outline" && hasClassToken(className, "text-foreground")) {
114
+ report(context, opening, "Outline \u6309\u94AE\u4F7F\u7528 text-foreground class \u4F1A\u5BFC\u81F4\u6587\u5B57\u4E0D\u53EF\u89C1\u3002\u8BE5\u53D8\u4F53\u80CC\u666F\u900F\u660E\uFF0Ctext-foreground \u4F1A\u4E0E\u80CC\u666F\u878D\u5408\u800C\u65E0\u6CD5\u9605\u8BFB\u3002\u8BF7\u6539\u7528 text-primary \u6216\u5176\u4ED6\u6709\u8DB3\u591F\u5BF9\u6BD4\u5EA6\u7684\u989C\u8272\u3002");
115
+ }
116
+ if (kind === "primary" && !hasAttribute(opening, "variant") && hasClassToken(className, "text-primary")) {
117
+ report(context, opening, "Default \u6309\u94AE\u4F7F\u7528 text-primary class \u4F1A\u5BFC\u81F4\u5BF9\u6BD4\u5EA6\u4E0D\u8DB3\u3002\u8BE5\u53D8\u4F53\u4F7F\u7528\u4E3B\u8272\u80CC\u666F\uFF0Ctext-primary \u4F1A\u4E0E\u80CC\u666F\u878D\u5408\u800C\u96BE\u4EE5\u9605\u8BFB\u3002\u8BF7\u79FB\u9664 text-primary\uFF0C\u6216\u6539\u7528 outline\u3001ghost \u7B49\u53D8\u4F53\u3002");
118
+ }
119
+ if (kind === "white-gray" && variant === "outline" && hasClassPrefix(className, /^text-(white|gray)(?:-[0-9]+)?$/)) {
120
+ report(context, opening, "Outline \u6309\u94AE\u4F7F\u7528\u767D\u8272\u6216\u7070\u8272\u6587\u5B57\u65F6\u5BF9\u6BD4\u5EA6\u4E0D\u8DB3\u3002\u8BF7\u79FB\u9664\u6587\u5B57\u989C\u8272 class\uFF0C\u4F7F\u7528\u6309\u94AE\u9ED8\u8BA4\u6587\u5B57\u989C\u8272\u3002");
121
+ }
122
+ }
123
+ });
124
+ }
125
+ function slotNestingRule(context) {
126
+ return jsxRule({
127
+ JSXElement(node) {
128
+ const opening = openingElement(node);
129
+ if (!opening || !isJsxElementNamed(opening, TRIGGER) || !hasAttribute(opening, "asChild")) return;
130
+ if (directChildNamed(node, "FormControl")) {
131
+ report(context, opening, "\u68C0\u6D4B\u5230\u5371\u9669\u7684 Slot \u5D4C\u5957\uFF1ARadix UI Trigger (asChild) \u5185\u5305\u88F9 FormControl\u3002FormControl \u548C Trigger \u90FD\u4F7F\u7528 Radix \u7684 Slot \u673A\u5236\uFF0C\u53CC\u5C42\u5D4C\u5957\u4F1A\u5BFC\u81F4 ref \u4F20\u9012\u94FE\u65AD\u88C2\u3001\u70B9\u51FB\u4E8B\u4EF6\u4E22\u5931\uFF0C\u5185\u90E8\u7EC4\u4EF6\u65E0\u6CD5\u4EA4\u4E92\u3002");
132
+ }
133
+ }
134
+ });
135
+ }
136
+ function requireButtonInteractionRule(context) {
137
+ return jsxRule({
138
+ JSXElement(node) {
139
+ const opening = openingElement(node);
140
+ if (!opening || !isJsxElementNamed(opening, BUTTON)) return;
141
+ if (hasAttribute(opening, "onClick") || hasAttribute(opening, "asChild")) return;
142
+ const type = attributeString(opening, "type");
143
+ if (type === "submit" || type === "reset") return;
144
+ if (spreadMayProvideInteraction(opening)) return;
145
+ const exempt = ancestors(node).some((parent) => {
146
+ if (parent.type !== "JSXElement") return false;
147
+ return isJsxElementNamed(parent, ANY_TRIGGER) || isJsxElementNamed(parent, /^(Link|a)$/);
148
+ });
149
+ if (!exempt) {
150
+ report(context, opening, '<Button> \u5FC5\u987B\u662F\u53EF\u70B9\u51FB\u7684\uFF0C\u8BF7\u786E\u4FDD\u5176\u70B9\u51FB\u540E\u7684\u903B\u8F91\u5DF2\u7F16\u5199\u3002\u8BF7\u6DFB\u52A0 onClick\u3001type="submit"\u3001type="reset"\u3001asChild \u5C5E\u6027\uFF0C\u6216\u5C06\u5176\u5305\u88F9\u5728 *Trigger \u7EC4\u4EF6\u4E2D\uFF0C\u6216 <Link> \u6216 <a> \u4E2D\u3002');
151
+ }
152
+ }
153
+ });
154
+ }
155
+ function toastImportRule(context) {
156
+ return {
157
+ create: () => ({
158
+ ImportDeclaration(node) {
159
+ if (staticString(node.source) !== "@/hooks/use-toast") return;
160
+ if (node.specifiers?.some((item) => item.type === "ImportSpecifier")) {
161
+ report(context, node, '\u8BF7\u4F7F\u7528 import { toast } from "sonner"\uFF0C\u4E0D\u8981\u5BFC\u5165 "@/hooks/use-toast"\u3002');
162
+ }
163
+ }
164
+ })
165
+ };
166
+ }
167
+ function googleSsoRule(context) {
168
+ return {
169
+ create: () => ({
170
+ CallExpression(node) {
171
+ const callee = node.callee;
172
+ if (callee?.type !== "MemberExpression" || callee.computed || callee.property?.name !== "signInWithOAuth") return;
173
+ const arg = node.arguments?.[0];
174
+ if (!arg || arg.type !== "ObjectExpression") return;
175
+ const provider = arg.properties?.find((item) => propertyName(item) === "provider");
176
+ if (propertyString(provider) === "google") {
177
+ report(context, node, "Supabase Google \u767B\u5F55\u8BF7\u5C06 `signInWithOAuth` \u66FF\u6362\u4E3A `signInWithSSO`\u3002\u8BF7\u4F7F\u7528 domain: 'miaoda-gg.com'\uFF0C\u5E76\u786E\u4FDD window.open \u4F7F\u7528 `_self` \u76EE\u6807\u3002");
178
+ }
179
+ }
180
+ })
181
+ };
182
+ }
183
+ function edgeGetBodyRule(context) {
184
+ return {
185
+ create: () => ({
186
+ CallExpression(node) {
187
+ if (!isSupabaseInvoke(node)) return;
188
+ const options = node.arguments?.find((arg) => arg.type === "ObjectExpression");
189
+ if (!options) return;
190
+ const method = options.properties?.find((item) => propertyName(item) === "method");
191
+ const body = options.properties?.find((item) => propertyName(item) === "body");
192
+ if (propertyString(method)?.toUpperCase() === "GET" && body) {
193
+ report(context, node, "GET \u8BF7\u6C42\u4E0D\u80FD\u643A\u5E26 body\uFF1Asupabase.functions.invoke \u4F7F\u7528 method: 'GET' \u65F6\u53C2\u6570\u5FC5\u987B\u62FC\u63A5\u5728 URL \u91CC\u3002");
194
+ }
195
+ }
196
+ })
197
+ };
198
+ }
199
+ function makeRule(factory) {
200
+ return {
201
+ create(context) {
202
+ return factory(context).create();
203
+ }
204
+ };
205
+ }
206
+ var rules = {
207
+ "select-item-with-empty-value": makeRule(selectItemRule),
208
+ "button-outline-text-foreground-contrast": makeRule((context) => contrastRule("foreground", context)),
209
+ "button-default-text-primary-contrast": makeRule((context) => contrastRule("primary", context)),
210
+ "button-outline-white-gray-contrast": makeRule((context) => contrastRule("white-gray", context)),
211
+ "radix-trigger-formcontrol-nesting": makeRule(slotNestingRule),
212
+ "require-button-interaction": makeRule(requireButtonInteractionRule),
213
+ "use-toast-import": makeRule(toastImportRule),
214
+ "supabase-google-sso": makeRule(googleSsoRule),
215
+ "supabase-edge-function-get-with-body": makeRule(edgeGetBodyRule)
216
+ };
217
+
218
+ // src/oxlint/index.ts
219
+ var plugin = {
220
+ meta: { name: "miaoda" },
221
+ rules
222
+ };
223
+ var oxlint_default = plugin;
224
+ export {
225
+ oxlint_default as default
226
+ };
@@ -0,0 +1,403 @@
1
+ // src/smoke/cli.ts
2
+ import { mkdir, mkdtemp, writeFile as writeFile2 } from "fs/promises";
3
+ import { join as join3, relative as relative2 } from "path";
4
+
5
+ // src/smoke/findEntry.ts
6
+ import { readFile, stat } from "fs/promises";
7
+ import { join } from "path";
8
+ var SCRIPT_TAG_RE = /<script\b[^>]*>/gi;
9
+ function readAttr(tag, name) {
10
+ const match = tag.match(new RegExp(`\\b${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s"'>]+))`, "i"));
11
+ if (match === null) {
12
+ return void 0;
13
+ }
14
+ return match[1] ?? match[2] ?? match[3];
15
+ }
16
+ function isLocalSrc(src) {
17
+ return src !== "" && !src.startsWith("//") && !/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(src);
18
+ }
19
+ async function classifyEntry(root) {
20
+ let html;
21
+ try {
22
+ html = await readFile(join(root, "index.html"), "utf8");
23
+ } catch (error) {
24
+ if (error.code === "ENOENT") {
25
+ return { skip: "index.html was not found in the application directory" };
26
+ }
27
+ throw error;
28
+ }
29
+ const missing = [];
30
+ let hasLocalEntry = false;
31
+ for (const tag of html.match(SCRIPT_TAG_RE) ?? []) {
32
+ if (readAttr(tag, "type")?.trim().toLowerCase() !== "module") {
33
+ continue;
34
+ }
35
+ const src = readAttr(tag, "src");
36
+ if (src === void 0) {
37
+ hasLocalEntry = true;
38
+ continue;
39
+ }
40
+ const value = src.trim();
41
+ if (!isLocalSrc(value)) {
42
+ continue;
43
+ }
44
+ hasLocalEntry = true;
45
+ const entryPath = join(root, value);
46
+ try {
47
+ if (!(await stat(entryPath)).isFile()) {
48
+ missing.push(entryPath);
49
+ }
50
+ } catch (error) {
51
+ const code = error.code;
52
+ if (code !== "ENOENT" && code !== "ENOTDIR") {
53
+ throw error;
54
+ }
55
+ missing.push(entryPath);
56
+ }
57
+ }
58
+ if (missing.length > 0) {
59
+ throw new Error(`index.html references missing module entries: ${missing.join(", ")}`);
60
+ }
61
+ return hasLocalEntry ? { entry: true } : { skip: "index.html does not declare a local module entry" };
62
+ }
63
+
64
+ // src/smoke/runStartupSmoke.ts
65
+ import { existsSync } from "fs";
66
+ import { writeFile } from "fs/promises";
67
+ import { createRequire } from "module";
68
+ import { join as join2, relative } from "path";
69
+ import { pathToFileURL } from "url";
70
+ import { chromium } from "playwright";
71
+
72
+ // src/smoke/inspectStartup.ts
73
+ import { setTimeout as delay } from "timers/promises";
74
+ var criticalResourceTypes = /* @__PURE__ */ new Set(["document", "script", "stylesheet", "fetch", "xhr"]);
75
+ var navigationTimeoutMs = 3e4;
76
+ var firstScreenTimeoutMs = 15e3;
77
+ var requestSettleTimeoutMs = 5e3;
78
+ function reportUrl(value) {
79
+ const url = new URL(value);
80
+ return url.protocol === "http:" || url.protocol === "https:" ? url.origin + url.pathname : url.protocol;
81
+ }
82
+ function describeRequest(request) {
83
+ return {
84
+ method: request.method(),
85
+ url: reportUrl(request.url()),
86
+ type: request.resourceType()
87
+ };
88
+ }
89
+ function hasVisibleContent() {
90
+ const inViewport = (rect) => rect.width > 0 && rect.height > 0 && rect.bottom > 0 && rect.right > 0 && rect.top < innerHeight && rect.left < innerWidth;
91
+ const visible = (element) => element.checkVisibility({ opacityProperty: true, visibilityProperty: true, contentVisibilityAuto: true });
92
+ const body = document.body;
93
+ if (body === null) {
94
+ return false;
95
+ }
96
+ const walker = document.createTreeWalker(body, NodeFilter.SHOW_TEXT);
97
+ const range = document.createRange();
98
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
99
+ const parent = node.parentElement;
100
+ if (parent === null || node.textContent?.trim() === "") {
101
+ continue;
102
+ }
103
+ if (parent.closest("script,style,template,noscript,svg") !== null) {
104
+ continue;
105
+ }
106
+ if (!visible(parent) && getComputedStyle(parent).display !== "contents") {
107
+ continue;
108
+ }
109
+ range.selectNodeContents(node);
110
+ if (Array.from(range.getClientRects()).some(inViewport)) {
111
+ return true;
112
+ }
113
+ }
114
+ return Array.from(body.querySelectorAll(
115
+ "img, svg, canvas, video, iframe, button, input, select, textarea, [contenteditable]"
116
+ )).some(
117
+ (element) => (!(element instanceof HTMLImageElement) || element.naturalWidth > 0) && visible(element) && inViewport(element.getBoundingClientRect())
118
+ );
119
+ }
120
+ async function inspectPixels(screenshot) {
121
+ const bytes = Uint8Array.from(atob(screenshot), (char) => char.charCodeAt(0));
122
+ const image = await createImageBitmap(new Blob([bytes], { type: "image/png" }));
123
+ const canvas = document.createElement("canvas");
124
+ canvas.width = image.width;
125
+ canvas.height = image.height;
126
+ const context = canvas.getContext("2d", { willReadFrequently: true });
127
+ if (context === null) {
128
+ throw new Error("Could not inspect screenshot pixels");
129
+ }
130
+ context.drawImage(image, 0, 0);
131
+ image.close();
132
+ const { data } = context.getImageData(0, 0, canvas.width, canvas.height);
133
+ const colors = new Uint32Array(4096);
134
+ let sampledPixels = 0;
135
+ let dominantPixels = 0;
136
+ for (let y = 0; y < canvas.height; y += 2) {
137
+ for (let x = 0; x < canvas.width; x += 2) {
138
+ const index = (y * canvas.width + x) * 4;
139
+ const bucket = (data[index] >> 4) * 256 + (data[index + 1] >> 4) * 16 + (data[index + 2] >> 4);
140
+ dominantPixels = Math.max(dominantPixels, ++colors[bucket]);
141
+ sampledPixels++;
142
+ }
143
+ }
144
+ const contrastingPixels = sampledPixels - dominantPixels;
145
+ return { sampledPixels, contrastingPixels, nearlyUniform: contrastingPixels < 12 };
146
+ }
147
+ async function inspectStartup(page, startUrl) {
148
+ const pending = /* @__PURE__ */ new Set();
149
+ const navigationErrors = [];
150
+ const pageErrors = [];
151
+ const consoleErrors = [];
152
+ const consoleWarnings = [];
153
+ const networkErrors = [];
154
+ const networkObservations = [];
155
+ const reviewNotes = [];
156
+ page.on("request", (request) => {
157
+ if (request.resourceType() === "fetch" || request.resourceType() === "xhr") {
158
+ pending.add(request);
159
+ }
160
+ });
161
+ page.on("response", (response) => {
162
+ if (response.status() < 400) {
163
+ return;
164
+ }
165
+ const request = response.request();
166
+ const issues = criticalResourceTypes.has(request.resourceType()) ? networkErrors : networkObservations;
167
+ issues.push({ ...describeRequest(request), status: response.status() });
168
+ });
169
+ page.on("requestfinished", (request) => {
170
+ pending.delete(request);
171
+ });
172
+ page.on("requestfailed", (request) => {
173
+ pending.delete(request);
174
+ const reason = request.failure()?.errorText ?? "request failed";
175
+ const issues = reason === "net::ERR_ABORTED" || !criticalResourceTypes.has(request.resourceType()) ? networkObservations : networkErrors;
176
+ issues.push({ ...describeRequest(request), reason });
177
+ });
178
+ page.on("pageerror", (error) => {
179
+ pageErrors.push(error.stack ?? error.message);
180
+ });
181
+ page.on("crash", () => {
182
+ pageErrors.push("The browser page crashed");
183
+ });
184
+ page.on("console", (message) => {
185
+ if (message.type() === "warning") {
186
+ consoleWarnings.push(message.text());
187
+ }
188
+ if (message.type() !== "error" || message.args().length === 0) {
189
+ return;
190
+ }
191
+ const { url, lineNumber, columnNumber } = message.location();
192
+ consoleErrors.push({
193
+ text: message.text(),
194
+ source: url ? `${reportUrl(url)}:${lineNumber + 1}:${columnNumber + 1}` : ""
195
+ });
196
+ });
197
+ let documentStatus = null;
198
+ const navigationStartedAt = performance.now();
199
+ try {
200
+ const response = await page.goto(startUrl, { waitUntil: "domcontentloaded", timeout: navigationTimeoutMs });
201
+ documentStatus = response?.status() ?? null;
202
+ } catch (error) {
203
+ navigationErrors.push(error instanceof Error ? error.message : String(error));
204
+ }
205
+ const navigationDurationMs = Math.round(performance.now() - navigationStartedAt);
206
+ if (documentStatus !== null && documentStatus < 400) {
207
+ await page.waitForFunction(hasVisibleContent, void 0, { timeout: firstScreenTimeoutMs }).catch(() => {
208
+ });
209
+ await delay(300);
210
+ const deadline = performance.now() + requestSettleTimeoutMs;
211
+ while (pending.size > 0 && performance.now() < deadline) {
212
+ await delay(50);
213
+ }
214
+ }
215
+ let visibleContent = false;
216
+ let pixels = null;
217
+ let screenshot;
218
+ try {
219
+ visibleContent = await page.evaluate(hasVisibleContent);
220
+ screenshot = await page.screenshot({ scale: "css", timeout: 1500 });
221
+ pixels = await page.evaluate(inspectPixels, screenshot.toString("base64"));
222
+ } catch (error) {
223
+ reviewNotes.push(`First-screen capture: ${error instanceof Error ? error.message : String(error)}`);
224
+ }
225
+ if (!visibleContent && pixels !== null && !pixels.nearlyUniform) {
226
+ reviewNotes.push("The screenshot contains visual detail, but no visible text, control or media was detected.");
227
+ }
228
+ const firstScreen = { looksBlank: pixels?.nearlyUniform ?? !visibleContent, visibleContent, pixels };
229
+ return {
230
+ screenshot,
231
+ diagnostics: {
232
+ startUrl: reportUrl(startUrl),
233
+ finalUrl: reportUrl(page.url()),
234
+ documentStatus,
235
+ navigationDurationMs,
236
+ firstScreen,
237
+ navigationErrors,
238
+ pageErrors,
239
+ consoleErrors,
240
+ networkErrors,
241
+ networkObservations,
242
+ pendingRequests: [...pending].map(describeRequest),
243
+ consoleWarnings,
244
+ reviewNotes
245
+ }
246
+ };
247
+ }
248
+
249
+ // src/smoke/runStartupSmoke.ts
250
+ var BROWSER_EXECUTABLE_CANDIDATES = [
251
+ "/usr/bin/chromium",
252
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
253
+ ];
254
+ function errorText(error) {
255
+ return error instanceof Error ? error.message : String(error);
256
+ }
257
+ function errorStack(error) {
258
+ return error instanceof Error ? error.stack ?? error.message : String(error);
259
+ }
260
+ async function resolveAppVite(root) {
261
+ let vitePath;
262
+ try {
263
+ vitePath = createRequire(join2(root, "package.json")).resolve("vite");
264
+ } catch {
265
+ throw new Error("\u672A\u80FD\u5728\u5E94\u7528\u76EE\u5F55\u89E3\u6790 vite\uFF0C\u8BF7\u786E\u8BA4\u5E94\u7528\u5DF2\u5B89\u88C5\u4F9D\u8D56\uFF08pnpm install\uFF09");
266
+ }
267
+ return import(pathToFileURL(vitePath).href);
268
+ }
269
+ async function launchChromium() {
270
+ const executablePath = process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH || BROWSER_EXECUTABLE_CANDIDATES.find((path) => existsSync(path));
271
+ return chromium.launch({
272
+ executablePath,
273
+ timeout: 15e3,
274
+ // 沙箱容器内常以 root 运行,Chromium 缺 --no-sandbox 会直接拒绝启动;
275
+ // --disable-dev-shm-usage 避开容器 /dev/shm 偏小的问题,--disable-gpu 免依赖 GPU。
276
+ args: ["--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"]
277
+ });
278
+ }
279
+ function collectStartupFailures(diagnostics) {
280
+ const failures = [];
281
+ if (diagnostics.documentStatus === null || diagnostics.documentStatus < 200 || diagnostics.documentStatus >= 300) {
282
+ failures.push({ check: "homepage document status", details: diagnostics.documentStatus });
283
+ }
284
+ if (diagnostics.firstScreen.looksBlank) {
285
+ failures.push({ check: "first screen appears blank" });
286
+ }
287
+ const collections = [
288
+ ["homepage navigation errors", diagnostics.navigationErrors],
289
+ ["uncaught page errors", diagnostics.pageErrors],
290
+ ["console.error during startup", diagnostics.consoleErrors],
291
+ ["failed startup network requests", diagnostics.networkErrors]
292
+ ];
293
+ for (const [check, details] of collections) {
294
+ if (details.length > 0) {
295
+ failures.push({ check, details });
296
+ }
297
+ }
298
+ return failures;
299
+ }
300
+ async function runStartupSmoke({ root, output }) {
301
+ const failures = [];
302
+ let server;
303
+ let browser;
304
+ let context;
305
+ let diagnostics = null;
306
+ let screenshot;
307
+ let trace;
308
+ try {
309
+ const { createServer } = await resolveAppVite(root);
310
+ server = await createServer({
311
+ root,
312
+ // 依赖预构建缓存指到本次运行目录,不污染应用自身的 node_modules/.vite。
313
+ cacheDir: join2(output, "vite-cache"),
314
+ server: { host: "127.0.0.1", port: 0, open: false, hmr: false }
315
+ });
316
+ await server.listen();
317
+ const url = server.resolvedUrls?.local[0];
318
+ if (url === void 0) {
319
+ throw new Error("Vite \u672A\u8FD4\u56DE\u672C\u5730\u8BBF\u95EE\u5730\u5740");
320
+ }
321
+ browser = await launchChromium();
322
+ context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
323
+ await context.tracing.start({ screenshots: true, snapshots: true, sources: true });
324
+ const result = await inspectStartup(await context.newPage(), url);
325
+ diagnostics = result.diagnostics;
326
+ failures.push(...collectStartupFailures(diagnostics));
327
+ if (result.screenshot !== void 0) {
328
+ await writeFile(join2(output, "startup.png"), result.screenshot);
329
+ screenshot = relative(root, join2(output, "startup.png"));
330
+ }
331
+ } catch (error) {
332
+ failures.push({ check: "smoke runner error", details: errorStack(error) });
333
+ } finally {
334
+ const contextRef = context;
335
+ const browserRef = browser;
336
+ const serverRef = server;
337
+ const cleanupSteps = [];
338
+ if (contextRef !== void 0) {
339
+ cleanupSteps.push(["save Playwright trace", async () => {
340
+ if (failures.length > 0) {
341
+ const tracePath = join2(output, "startup.trace.zip");
342
+ await contextRef.tracing.stop({ path: tracePath });
343
+ trace = relative(root, tracePath);
344
+ } else {
345
+ await contextRef.tracing.stop();
346
+ }
347
+ }]);
348
+ cleanupSteps.push(["close browser context", () => contextRef.close()]);
349
+ }
350
+ if (browserRef !== void 0) {
351
+ cleanupSteps.push(["close browser", () => browserRef.close()]);
352
+ }
353
+ if (serverRef !== void 0) {
354
+ cleanupSteps.push(["close Vite server", () => serverRef.close()]);
355
+ }
356
+ for (const [check, action] of cleanupSteps) {
357
+ try {
358
+ await action();
359
+ } catch (error) {
360
+ failures.push({ check, details: errorText(error) });
361
+ }
362
+ }
363
+ }
364
+ return { status: failures.length > 0 ? "failed" : "passed", failures, diagnostics, screenshot, trace };
365
+ }
366
+
367
+ // src/smoke/cli.ts
368
+ async function runStartupSmokeCli(root = process.cwd()) {
369
+ const entry = await classifyEntry(root);
370
+ if ("skip" in entry) {
371
+ console.log(`[startup-smoke] SKIP: ${entry.skip}`);
372
+ return;
373
+ }
374
+ const resultsDir = join3(root, "test-results");
375
+ await mkdir(resultsDir, { recursive: true });
376
+ const output = await mkdtemp(join3(resultsDir, "startup-"));
377
+ const result = await runStartupSmoke({ root, output });
378
+ const reportPath = join3(output, "startup.json");
379
+ const report = { checkedAt: (/* @__PURE__ */ new Date()).toISOString(), ...result };
380
+ await writeFile2(reportPath, `${JSON.stringify(report, null, 2)}
381
+ `);
382
+ if (result.status === "passed") {
383
+ console.log("[startup-smoke] PASS: homepage loaded, painted content, and started without errors");
384
+ return;
385
+ }
386
+ process.exitCode = 1;
387
+ console.error("[startup-smoke] FAIL");
388
+ for (const { check, details } of result.failures) {
389
+ const suffix = details === void 0 ? "" : `: ${typeof details === "string" ? details : JSON.stringify(details)}`;
390
+ console.error(`- ${check}${suffix}`);
391
+ }
392
+ console.log("Startup smoke diagnostics for this failure:");
393
+ console.log(`- app report (page errors, console errors, failed network requests): ${relative2(root, reportPath)}`);
394
+ if (result.screenshot !== void 0) {
395
+ console.log(`- first screen screenshot: ${result.screenshot}`);
396
+ }
397
+ if (result.trace !== void 0) {
398
+ console.log(`- Playwright trace: ${result.trace}`);
399
+ }
400
+ }
401
+ export {
402
+ runStartupSmokeCli
403
+ };
@@ -32,49 +32,27 @@ var vite_exports = {};
32
32
  __export(vite_exports, {
33
33
  extractRouterPlugin: () => extractRouterPlugin,
34
34
  hmrTogglePlugin: () => hmrTogglePlugin,
35
- withSentryBuild: () => withSentryBuild,
36
- withSentryStub: () => withSentryStub
35
+ withSentryBuild: () => withSentryBuild
37
36
  });
38
37
  module.exports = __toCommonJS(vite_exports);
39
38
 
40
- // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.26_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
39
+ // node_modules/tsup/assets/cjs_shims.js
41
40
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
42
41
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
43
42
 
44
- // src/vite/withSentryStub.ts
43
+ // src/vite/withSentryBuild.ts
45
44
  var import_node_path = __toESM(require("path"), 1);
46
45
  var import_node_url = require("url");
47
46
  var SENTRY_MODULE = "@sentry/react";
48
47
  var _dirname = import_node_path.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
49
- var STUB_PATH = import_node_path.default.resolve(_dirname, "../stubs/sentry-react-stub.js");
50
- function withSentryStub() {
51
- return {
52
- name: "miaoda-devkit:sentry-stub",
53
- enforce: "pre",
54
- apply: "serve",
55
- resolveId(id, importer) {
56
- if (importer && importer.includes("sentry-react-stub")) return null;
57
- if (id === SENTRY_MODULE) {
58
- return STUB_PATH;
59
- }
60
- return null;
61
- }
62
- };
63
- }
64
-
65
- // src/vite/withSentryBuild.ts
66
- var import_node_path2 = __toESM(require("path"), 1);
67
- var import_node_url2 = require("url");
68
- var SENTRY_MODULE2 = "@sentry/react";
69
- var _dirname2 = import_node_path2.default.dirname((0, import_node_url2.fileURLToPath)(importMetaUrl));
70
- var STUB_PATH2 = import_node_path2.default.resolve(_dirname2, "../stubs/sentry-react-noop-stub.js");
48
+ var STUB_PATH = import_node_path.default.resolve(_dirname, "../stubs/sentry-react-noop-stub.js");
71
49
  function withSentryBuild() {
72
50
  return {
73
51
  name: "miaoda-devkit:sentry-build",
74
52
  enforce: "pre",
75
53
  apply: "build",
76
54
  resolveId(id) {
77
- if (id === SENTRY_MODULE2) return STUB_PATH2;
55
+ if (id === SENTRY_MODULE) return STUB_PATH;
78
56
  return null;
79
57
  }
80
58
  };
@@ -972,6 +950,5 @@ var extractRouterPlugin = () => {
972
950
  0 && (module.exports = {
973
951
  extractRouterPlugin,
974
952
  hmrTogglePlugin,
975
- withSentryBuild,
976
- withSentryStub
953
+ withSentryBuild
977
954
  });